This is an automated email from the ASF dual-hosted git repository.

shuber pushed a commit to branch opensearch-persistence
in repository https://gitbox.apache.org/repos/asf/unomi.git

commit d3f3d528a716d541f2bb6e242cea5840a77d4d5f
Merge: 9a2a6c45d 5947ed04e
Author: Serge Huber <shu...@jahia.com>
AuthorDate: Thu Dec 5 10:47:45 2024 +0100

    Merge remote-tracking branch 'origin/master' into opensearch-persistence
    
    # Conflicts:
    #       graphql/graphql-playground/yarn.lock
    #       itests/src/test/java/org/apache/unomi/itests/BaseIT.java
    #       manual/src/main/asciidoc/graphql.adoc
    #       
persistence-elasticsearch/core/src/test/java/org/apache/unomi/persistence/elasticsearch/ElasticsearchPersistenceTest.java
    #       
persistence-spi/src/main/java/org/apache/unomi/persistence/spi/conditions/ConditionContextHelper.java
    #       
persistence-spi/src/main/java/org/apache/unomi/persistence/spi/conditions/ConditionEvaluatorDispatcherImpl.java
    #       
tools/shell-commands/src/main/java/org/apache/unomi/shell/services/internal/UnomiManagementServiceImpl.java

 .../graphql-playground/src/main/webapp/index.css   |   45 -
 graphql/graphql-playground/yarn.lock               | 5506 --------------------
 .../{graphql-playground => graphql-ui}/.babelrc    |    0
 .../package.json                                   |   30 +-
 graphql/{graphql-playground => graphql-ui}/pom.xml |    8 +-
 .../src/main/resources/assets/js}/index.jsx        |   34 +-
 .../src/main/webapp/index.html                     |   41 +-
 .../webpack.config.js                              |   41 +-
 .../test/java/org/apache/unomi/itests/BaseIT.java  |   23 -
 .../ElasticsearchPersistenceTest.java              |  175 +
 .../spi/conditions/ConditionContextHelper.java     |    2 +-
 .../ConditionEvaluatorDispatcherImpl.java          |    2 +-
 .../unomi/rest/endpoints/RulesServiceEndPoint.java |    2 +-
 .../services/impl/rules/RulesServiceImpl.java      |    2 +-
 .../internal/UnomiManagementServiceImpl.java       |   24 +-
 15 files changed, 272 insertions(+), 5663 deletions(-)

diff --cc 
persistence-elasticsearch/core/src/test/java/org/apache/unomi/persistence/elasticsearch/ElasticsearchPersistenceTest.java
index 000000000,9c65328d8..c80734f94
mode 000000,100644..100644
--- 
a/persistence-elasticsearch/core/src/test/java/org/apache/unomi/persistence/elasticsearch/ElasticsearchPersistenceTest.java
+++ 
b/persistence-elasticsearch/core/src/test/java/org/apache/unomi/persistence/elasticsearch/ElasticsearchPersistenceTest.java
@@@ -1,0 -1,175 +1,175 @@@
+ /*
+  * Licensed to the Apache Software Foundation (ASF) under one or more
+  * contributor license agreements.  See the NOTICE file distributed with
+  * this work for additional information regarding copyright ownership.
+  * The ASF licenses this file to You under the Apache License, Version 2.0
+  * (the "License"); you may not use this file except in compliance with
+  * the License.  You may obtain a copy of the License at
+  *
+  *      http://www.apache.org/licenses/LICENSE-2.0
+  *
+  * Unless required by applicable law or agreed to in writing, software
+  * distributed under the License is distributed on an "AS IS" BASIS,
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  */
+ package org.apache.unomi.persistence.elasticsearch;
+ 
+ import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
+ import org.apache.http.HttpHost;
+ import org.elasticsearch.action.ActionRequestValidationException;
+ import org.elasticsearch.action.index.IndexRequest;
+ import org.elasticsearch.action.index.IndexResponse;
+ import org.elasticsearch.client.RequestOptions;
+ import org.elasticsearch.client.RestClient;
+ import org.elasticsearch.client.RestHighLevelClient;
+ import org.elasticsearch.client.core.MainResponse;
+ import org.elasticsearch.client.indices.CreateIndexRequest;
+ import org.elasticsearch.client.indices.CreateIndexResponse;
+ import org.elasticsearch.cluster.ClusterName;
+ import org.elasticsearch.common.network.NetworkModule;
+ import org.elasticsearch.common.settings.Settings;
+ import org.elasticsearch.common.xcontent.XContentType;
+ import org.elasticsearch.core.internal.io.IOUtils;
+ import org.elasticsearch.env.Environment;
+ import org.elasticsearch.node.MockNode;
+ import org.elasticsearch.node.Node;
+ import org.elasticsearch.rest.RestStatus;
+ import org.elasticsearch.transport.Netty4Plugin;
+ import org.junit.AfterClass;
+ import org.junit.Assert;
+ import org.junit.BeforeClass;
+ import org.junit.Test;
+ import org.junit.runner.RunWith;
+ 
+ import java.util.Arrays;
+ import java.util.Collection;
+ import java.util.Date;
+ import java.util.UUID;
+ import java.util.logging.Logger;
+ 
+ @RunWith(com.carrotsearch.randomizedtesting.RandomizedRunner.class)
+ @ThreadLeakScope(value = ThreadLeakScope.Scope.NONE)
+ public class ElasticsearchPersistenceTest {
+ 
 -    private static final Logger LOGGER = 
Logger.getLogger(ElasticsearchPersistenceTest.class.getName());
++    private static final Logger logger = 
Logger.getLogger(ElasticsearchPersistenceTest.class.getName());
+ 
+     private static final String CLUSTER_NAME = "unomi-cluster-test";
+     private static final String NODE_NAME = "unomi-node-test";
+     private static final String HOST = "127.0.0.1";
+     private static final int HTTP_PORT_NODE_1 = 9200+10;
+     private static final int HTTP_PORT_NODE_2 = 9201+10;
+     private static final int TRANSPORT_PORT_NODE_1 = 9300+10;
+     private static final int TRANSPORT_PORT_NODE_2 = 9301+10;
+ 
+     private static RestHighLevelClient restHighLevelClient;
+ 
+     private static Node node1;
+     private static Node node2;
+ 
+     @BeforeClass
+     public static void setup() throws Exception {
+         Collection plugins = Arrays.asList(Netty4Plugin.class);
+ 
+         Settings settingsNode1 = Settings.builder()
+                 .put(ClusterName.CLUSTER_NAME_SETTING.getKey(), CLUSTER_NAME)
+                 .put(Node.NODE_NAME_SETTING.getKey(), NODE_NAME + "-1")
+                 .put(NetworkModule.HTTP_TYPE_KEY, 
Netty4Plugin.NETTY_HTTP_TRANSPORT_NAME)
+                 .put(Environment.PATH_HOME_SETTING.getKey(), "target/data-1")
+                 .put(Environment.PATH_DATA_SETTING.getKey(), "target/data-1")
+                 .put("network.host", HOST)
+                 .put("http.port", HTTP_PORT_NODE_1)
+                 .put(NetworkModule.TRANSPORT_TYPE_KEY, 
Netty4Plugin.NETTY_TRANSPORT_NAME)
+                 .put("transport.port", TRANSPORT_PORT_NODE_1)
+                 .build();
+         node1 = new MockNode(settingsNode1, plugins);
+         node1.start();
+ 
+         Settings settingsNode2 = Settings.builder()
+                 .put(ClusterName.CLUSTER_NAME_SETTING.getKey(), CLUSTER_NAME)
+                 .put(Node.NODE_NAME_SETTING.getKey(), NODE_NAME + "-2")
+                 .put(NetworkModule.HTTP_TYPE_KEY, 
Netty4Plugin.NETTY_HTTP_TRANSPORT_NAME)
+                 .put(Environment.PATH_HOME_SETTING.getKey(), "target/data-2")
+                 .put(Environment.PATH_DATA_SETTING.getKey(), "target/data-2")
+                 .put("network.host", HOST)
+                 .put("http.port", HTTP_PORT_NODE_2)
+                 .put(NetworkModule.TRANSPORT_TYPE_KEY, 
Netty4Plugin.NETTY_TRANSPORT_NAME)
+                 .put("transport.port", TRANSPORT_PORT_NODE_2)
+                 .build();
+         node2 = new MockNode(settingsNode2, plugins);
+         node2.start();
+ 
+         restHighLevelClient = new RestHighLevelClient(RestClient.builder(
+                 new HttpHost(HOST, HTTP_PORT_NODE_1, "http"),
+                 new HttpHost(HOST, HTTP_PORT_NODE_2, "http")));
+     }
+ 
+     @AfterClass
+     public static void teardown() throws Exception {
+         IOUtils.close(restHighLevelClient);
+         if (node1 != null) {
+             node1.close();
+         }
+         if (node2 != null) {
+             node2.close();
+         }
+     }
+ 
+     @Test
+     public void testGetClusterInfo() throws Exception {
+         MainResponse response = 
restHighLevelClient.info(RequestOptions.DEFAULT);
 -        LOGGER.info("Cluster getMinimumIndexCompatibilityVersion: " + 
response.getVersion().getMinimumIndexCompatibilityVersion());
 -        LOGGER.info("Cluster getMinimumWireCompatibilityVersion: " + 
response.getVersion().getMinimumWireCompatibilityVersion());
 -        LOGGER.info("Cluster number: " + response.getVersion().getNumber());
++        logger.info("Cluster getMinimumIndexCompatibilityVersion: " + 
response.getVersion().getMinimumIndexCompatibilityVersion());
++        logger.info("Cluster getMinimumWireCompatibilityVersion: " + 
response.getVersion().getMinimumWireCompatibilityVersion());
++        logger.info("Cluster number: " + response.getVersion().getNumber());
+     }
+ 
+     @Test
+     public void testCreateIndex() throws Exception {
+         
restHighLevelClient.info(RequestOptions.DEFAULT.toBuilder().addHeader("name", 
"value").build());
+         final String indexName = "unomi-index-" + new Date().getTime();
+         CreateIndexRequest request = new CreateIndexRequest(indexName);
+         CreateIndexResponse response = 
restHighLevelClient.indices().create(request, RequestOptions.DEFAULT);
+         if (response.isAcknowledged()) {
 -            LOGGER.info(">>> Create index :: ok :: name = " + 
response.index());
++            logger.info(">>> Create index :: ok :: name = " + 
response.index());
+         } else {
 -            LOGGER.info(">>> Create index :: not acknowledged");
++            logger.info(">>> Create index :: not acknowledged");
+         }
+ 
+ //        ClusterHealthResponse actionGet = restHighLevelClient.cluster()
+ //                
.health(Requests.clusterHealthRequest("unomi-index-1").waitForGreenStatus().waitForEvents(Priority.LANGUID)
+ //                .waitForNoRelocatingShards(true), RequestOptions.DEFAULT);
+ //        Assert.assertNotNull(actionGet);
+ //
+ //        switch (actionGet.getStatus()) {
+ //            case GREEN:
+ //                logger.info(">>> Cluster State :: GREEN");
+ //                break;
+ //            case YELLOW:
+ //                logger.info(">>> Cluster State :: YELLOW");
+ //                break;
+ //            case RED:
+ //                logger.info(">>> Cluster State :: RED");
+ //                break;
+ //        }
+ //        Assert.assertNotEquals(actionGet.getStatus(), 
ClusterHealthStatus.RED);
+ 
+         IndexRequest indexRequest = new IndexRequest(indexName);
+         indexRequest.id(UUID.randomUUID().toString());
+         String type = "{\"type\":\"unomi-type\"}";
+         String source = "{\"name\":\"unomi-name\"}";
+         indexRequest.source(XContentType.JSON, type, source);
+         ActionRequestValidationException exception = indexRequest.validate();
+         Assert.assertNull(exception);
+ 
+         IndexResponse indexResponse = restHighLevelClient.index(indexRequest, 
RequestOptions.DEFAULT);
+         Assert.assertNotNull(indexResponse);
+         if (indexResponse.status() == RestStatus.CREATED) {
 -            LOGGER.info(">>> Insert data created");
++            logger.info(">>> Insert data created");
+         } else {
 -            LOGGER.info(">>> Insert data ko :: " + 
indexResponse.status().name());
++            logger.info(">>> Insert data ko :: " + 
indexResponse.status().name());
+         }
+         Assert.assertEquals(indexResponse.status(), RestStatus.CREATED);
+     }
+ 
+ }
diff --cc 
tools/shell-commands/src/main/java/org/apache/unomi/shell/services/internal/UnomiManagementServiceImpl.java
index ad6d9d355,fbab16cd3..fa95a8d9d
--- 
a/tools/shell-commands/src/main/java/org/apache/unomi/shell/services/internal/UnomiManagementServiceImpl.java
+++ 
b/tools/shell-commands/src/main/java/org/apache/unomi/shell/services/internal/UnomiManagementServiceImpl.java
@@@ -27,12 -27,14 +27,14 @@@ import org.osgi.service.component.annot
  import org.osgi.service.component.annotations.Component;
  import org.osgi.service.component.annotations.Reference;
  import org.osgi.service.component.annotations.ReferenceCardinality;
+ import org.slf4j.Logger;
+ import org.slf4j.LoggerFactory;
  
 -import java.util.ArrayList;
 -import java.util.Collections;
 -import java.util.List;
 +import java.util.*;
  
  /**
 + * TODO We really should replace this with Karaf Features that we activate. 
We could still keep the starting mechanism
 + * to work properly with the migration process but we should remove the 
hardcoded list of packages in this class.
   * @author dgaillard
   */
  @Component(service = UnomiManagementService.class, immediate = true)
@@@ -51,16 -52,20 +55,20 @@@ public class UnomiManagementServiceImp
  
      @Activate
      public void init(ComponentContext componentContext) throws Exception {
-         this.bundleContext = componentContext.getBundleContext();
-         initReversedBundleSymbolicNames();
+         try {
+             this.bundleContext = componentContext.getBundleContext();
+             initReversedBundleSymbolicNames();
  
-         if 
(StringUtils.isNotBlank(bundleContext.getProperty("unomi.autoMigrate"))) {
-             
migrationService.migrateUnomi(bundleContext.getProperty("unomi.autoMigrate"), 
true, null);
-         }
+             if 
(StringUtils.isNotBlank(bundleContext.getProperty("unomi.autoMigrate"))) {
+                 
migrationService.migrateUnomi(bundleContext.getProperty("unomi.autoMigrate"), 
true, null);
+             }
  
-         if 
(StringUtils.isNotBlank(bundleContext.getProperty("unomi.autoStart")) &&
-                 bundleContext.getProperty("unomi.autoStart").equals("true")) {
-             startUnomi(selectedPersistenceImplementation);
+             if 
(StringUtils.isNotBlank(bundleContext.getProperty("unomi.autoStart")) &&
+                     
bundleContext.getProperty("unomi.autoStart").equals("true")) {
 -                startUnomi();
++                startUnomi(selectedPersistenceImplementation);
+             }
+         } catch (Exception e) {
+             LOGGER.error("Error during Unomi startup when processing 
'unomi.autoMigrate' or 'unomi.autoStart' properties:", e);
          }
      }
  

Reply via email to