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/08/13 14:39:38 UTC

[GitHub] [ignite-3] tkalkirill commented on a change in pull request #273: IGNITE-15285 Splitting into ConfigurationManager managers (node and cluster)

tkalkirill commented on a change in pull request #273:
URL: https://github.com/apache/ignite-3/pull/273#discussion_r688565842



##########
File path: modules/rest/src/main/java/org/apache/ignite/rest/RestModule.java
##########
@@ -53,90 +55,88 @@
  * Refer to default config file in resources for the example.
  */
 public class RestModule implements IgniteComponent {
-    /** */
+    /** Default port. */
     public static final int DFLT_PORT = 10300;
 
-    /** */
-    private static final String CONF_URL = "/management/v1/configuration/";
+    /** Node configuration route. */
+    private static final String NODE_CFG_URL = "/management/v1/configuration/node/";
 
-    /** */
+    /** Cluster configuration route. */
+    private static final String CLUSTER_CFG_URL = "/management/v1/configuration/cluster/";
+
+    /** Path parameter. */
     private static final String PATH_PARAM = "selector";
 
     /** Ignite logger. */
     private final IgniteLogger LOG = IgniteLogger.forClass(RestModule.class);
 
-    /** */
-    private final ConfigurationRegistry sysConf;
+    /** Node configuration register. */
+    private final ConfigurationRegistry nodeCfgRegistry;
+
+    /** Presentation of node configuration. */
+    private final ConfigurationPresentation<String> nodeCfgPresentation;
 
-    /** */
-    private volatile ConfigurationPresentation<String> presentation;
+    /** Presentation of cluster configuration. */
+    private final ConfigurationPresentation<String> clusterCfgPresentation;
 
     /**
      * Creates a new instance of REST module.
      *
      * @param nodeCfgMgr Node configuration manager.
+     * @param clusterCfgMgr Cluster configuration manager.
      */
-    public RestModule(ConfigurationManager nodeCfgMgr) {
-        sysConf = nodeCfgMgr.configurationRegistry();
+    public RestModule(
+        ConfigurationManager nodeCfgMgr,
+        ConfigurationManager clusterCfgMgr
+    ) {
+        nodeCfgRegistry = nodeCfgMgr.registry();
+
+        nodeCfgPresentation = new HoconPresentation(nodeCfgMgr.registry());
+        clusterCfgPresentation = new HoconPresentation(clusterCfgMgr.registry());
     }
 
     /** {@inheritDoc} */
     @Override public void start() {
-        presentation = new HoconPresentation(sysConf);
-
         var router = new Router();
 
         router
-            .get(CONF_URL, (req, resp) -> {
-                resp.json(presentation.represent());
-            })
-            .get(CONF_URL + ":" + PATH_PARAM, (req, resp) -> {
-                String cfgPath = req.queryParams().get(PATH_PARAM);
-                try {
-                    resp.json(presentation.representByPath(cfgPath));
-                }
-                catch (IllegalArgumentException pathE) {
-                    ErrorResult eRes = new ErrorResult("CONFIG_PATH_UNRECOGNIZED", pathE.getMessage());
-
-                    resp.status(BAD_REQUEST);
-                    resp.json(Map.of("error", eRes));
-                }
-            })
-            .put(CONF_URL, HttpHeaderValues.APPLICATION_JSON, (req, resp) -> {
-                try {
-                    presentation.update(
-                        req
-                            .request()
-                            .content()
-                            .readCharSequence(req.request().content().readableBytes(), StandardCharsets.UTF_8)
-                            .toString());
-                }
-                catch (IllegalArgumentException e) {
-                    ErrorResult eRes = new ErrorResult("INVALID_CONFIG_FORMAT", e.getMessage());
-
-                    resp.status(BAD_REQUEST);
-                    resp.json(Map.of("error", eRes));
-                }
-                catch (ConfigurationValidationException e) {
-                    ErrorResult eRes = new ErrorResult("VALIDATION_EXCEPTION", e.getMessage());
-
-                    resp.status(BAD_REQUEST);
-                    resp.json(Map.of("error", eRes));
-                }
-                catch (IgniteException e) {
-                    ErrorResult eRes = new ErrorResult("APPLICATION_EXCEPTION", e.getMessage());
-
-                    resp.status(BAD_REQUEST);
-                    resp.json(Map.of("error", eRes));
-                }
-            });
+            .get(
+                NODE_CFG_URL,
+                (req, resp) -> resp.json(nodeCfgPresentation.represent())
+            )
+            .get(
+                CLUSTER_CFG_URL,
+                (req, resp) -> resp.json(clusterCfgPresentation.represent())
+            )
+            .get(
+                NODE_CFG_URL + ":" + PATH_PARAM,
+                (req, resp) -> handleRepresentByPath(req, resp, nodeCfgPresentation)
+            )
+            .get(
+                CLUSTER_CFG_URL + ":" + PATH_PARAM,
+                (req, resp) -> handleRepresentByPath(req, resp, clusterCfgPresentation)
+            )
+            .put(
+                NODE_CFG_URL,
+                APPLICATION_JSON,
+                (req, resp) -> handleUpdate(req, resp, nodeCfgPresentation)
+            )
+            .put(
+                CLUSTER_CFG_URL,
+                APPLICATION_JSON,
+                (req, resp) -> handleUpdate(req, resp, clusterCfgPresentation)
+            );
 
         startRestEndpoint(router);
     }
 
-    /** */
-    private ChannelFuture startRestEndpoint(Router router) {
-        RestView restConfigurationView = sysConf.getConfiguration(RestConfiguration.KEY).value();
+    /**
+     * Start endpoint.
+     *
+     * @param router Dispatcher of http requests.
+     */
+    private void startRestEndpoint(Router router) {

Review comment:
       It is not used, why is it needed?




-- 
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: notifications-unsubscribe@ignite.apache.org

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