You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2021/06/18 20:51:39 UTC

[GitHub] [ignite-3] vldpyatkov commented on a change in pull request #181: IGNITE-14599 Added generic way to bootstrap configuration from Hocon files.

vldpyatkov commented on a change in pull request #181:
URL: https://github.com/apache/ignite-3/pull/181#discussion_r654031739



##########
File path: modules/api/src/main/java/org/apache/ignite/app/IgnitionManager.java
##########
@@ -29,38 +35,48 @@
     private static Ignition ignition;
 
     /**
-     * Starts Ignite node with optional bootstrap configuration in json format.
+     * Starts Ignite node with optional bootstrap configuration in hocon format.
      *
      * @param nodeName Name of the node.
-     * @param jsonStrBootstrapCfg Node configuration in json format.
+     * @param configStr Node configuration in hocon format.
      * @return Started Ignite node.
      */
     // TODO IGNITE-14580 Add exception handling logic to IgnitionProcessor.
-    public static synchronized Ignite start(@NotNull String nodeName, @Nullable String jsonStrBootstrapCfg) {
+    public static synchronized Ignite start(@NotNull String nodeName, @Nullable String configStr) {
         if (ignition == null) {
             ServiceLoader<Ignition> ldr = ServiceLoader.load(Ignition.class);
             ignition = ldr.iterator().next();
         }
 
-        return ignition.start(nodeName, jsonStrBootstrapCfg);
+        if (configStr == null)
+            return ignition.start(nodeName);
+        else {
+            try (InputStream inputStream = new ByteArrayInputStream(configStr.getBytes(StandardCharsets.UTF_8))) {
+                return ignition.start(nodeName, inputStream);
+            }
+            catch (IOException e) {
+                throw new IgniteException("Couldn't close the stream with node config.", e);

Review comment:
       Here we can react only warning.

##########
File path: modules/runner/src/main/java/org/apache/ignite/internal/app/IgnitionImpl.java
##########
@@ -81,7 +86,40 @@
     private static final String VER_KEY = "version";
 
     /** {@inheritDoc} */
-    @Override public synchronized Ignite start(@NotNull String nodeName, @Nullable String jsonStrBootstrapCfg) {
+    @Override public synchronized Ignite start(@NotNull String nodeName, @Nullable Path cfgPath) {
+        try {
+            return doStart(nodeName, Files.readString(cfgPath));
+        }
+        catch (IOException e) {
+            LOG.warn("Unable to read user specific configuration, default configuration will be used: " + e.getMessage());
+            return start(nodeName);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public Ignite start(@NotNull String name, @Nullable InputStream config) {
+        try {
+            return doStart(name, new String(config.readAllBytes(), StandardCharsets.UTF_8));
+        }
+        catch (IOException e) {
+            LOG.warn("Unable to read user specific configuration, default configuration will be used: " + e.getMessage());
+            return start(name);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public Ignite start(@NotNull String name) {
+        return doStart(name, null);
+    }
+
+    /**
+     * Starts Ignite node with optional bootstrap configuration in hocon format.
+     *
+     * @param nodeName Name of the node. Couldn't be {@code null}.
+     * @param cfgContent Node configuration in hocon format. Could be {@code null}.
+     * @return Started Ignite node.
+     */
+    private Ignite doStart(@NotNull String nodeName, @Nullable String cfgContent) {
         assert !StringUtil.isNullOrEmpty(nodeName) : "Node local name is empty";

Review comment:
       I have a suspicion for using netty to check null or empty string.




-- 
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.

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