tihom88 commented on code in PR #557:
URL: https://github.com/apache/jackrabbit-oak/pull/557#discussion_r865707540


##########
oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticConnectionRule.java:
##########
@@ -83,33 +128,62 @@ public ElasticConnection getElasticConnectionFromString() {
             int port = uri.getPort();
             String query = uri.getQuery();
 
-            String api_key = null;
-            String api_secret = null;
+            String apiKey = null;
+            String apiSecret = null;
             if (query != null) {
-                api_key = query.split(",")[0].split("=")[1];
-                api_secret = query.split(",")[1].split("=")[1];
+                apiKey = query.split(",")[0].split("=")[1];
+                apiSecret = query.split(",")[1].split("=")[1];
             }
             return ElasticConnection.newBuilder()
                     .withIndexPrefix(indexPrefix + System.currentTimeMillis())
                     .withConnectionParameters(scheme, host, port)
-                    .withApiKeys(api_key, api_secret)
+                    .withApiKeys(apiKey, apiSecret)
                     .build();
         } catch (URISyntaxException e) {
+            LOG.error("Provided elastic connection string  is not valid ", e);
             return null;
         }
     }
 
+    private boolean isValidUri(String connectionString) {
+        if (connectionString == null) {
+            return false;
+        }
+        try {
+            new URI(connectionString);
+            return true;
+        } catch (URISyntaxException e) {
+            LOG.debug("Provided elastic connection string  is not valid ", e);

Review Comment:
   Exception also logs the malformed uri. So didn't logged it again in message.



##########
oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticConnectionRule.java:
##########
@@ -75,6 +80,46 @@ protected void after() {
         }
     }
 
+    public ElasticConnectionModel getElasticConnectionModel() {
+        return elasticConnectionModel;
+    }
+
+    private void initializeElasticConnectionModel(String 
elasticConnectionString) {
+        try {
+            URI uri = new URI(elasticConnectionString);
+            String host = uri.getHost();
+            String scheme = uri.getScheme();
+            int port = uri.getPort();
+            String query = uri.getQuery();
+
+            String apiKey = null;
+            String apiSecret = null;
+            if (query != null) {
+                apiKey = query.split(",")[0].split("=")[1];
+                apiSecret = query.split(",")[1].split("=")[1];
+            }
+            this.elasticConnectionModel = new ElasticConnectionModel();
+            elasticConnectionModel.scheme = scheme;
+            elasticConnectionModel.elasticHost = host;
+            elasticConnectionModel.elasticPort = port;
+            elasticConnectionModel.elasticApiKey = apiKey;
+            elasticConnectionModel.elasticApiSecret = apiSecret;
+            elasticConnectionModel.indexPrefix = indexPrefix + 
System.currentTimeMillis();
+        } catch (URISyntaxException e) {
+            LOG.error("Provided elastic connection string  is not valid ", e);
+        }
+    }
+
+    private void initializeElasticConnectionModel(ElasticsearchContainer 
elastic) {
+        this.elasticConnectionModel = new ElasticConnectionModel();
+        elasticConnectionModel.scheme = ElasticConnection.DEFAULT_SCHEME;
+        elasticConnectionModel.elasticHost = elastic.getContainerIpAddress();

Review Comment:
   Done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@jackrabbit.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to