PakhomovAlexander commented on code in PR #816:
URL: https://github.com/apache/ignite-3/pull/816#discussion_r887825449
##########
modules/rest/src/main/java/org/apache/ignite/internal/rest/RestComponent.java:
##########
@@ -17,151 +17,161 @@
package org.apache.ignite.internal.rest;
-import io.netty.bootstrap.ServerBootstrap;
-import io.netty.channel.Channel;
-import io.netty.channel.ChannelFuture;
-import io.netty.handler.logging.LogLevel;
-import io.netty.handler.logging.LoggingHandler;
+import io.micronaut.context.ApplicationContext;
+import io.micronaut.http.server.exceptions.ServerStartupException;
+import io.micronaut.openapi.annotation.OpenAPIInclude;
+import io.micronaut.runtime.Micronaut;
+import io.micronaut.runtime.exceptions.ApplicationStartupException;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.info.Contact;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.info.License;
import java.net.BindException;
-import java.net.InetSocketAddress;
-import java.util.function.Consumer;
+import java.util.List;
+import java.util.Map;
import org.apache.ignite.configuration.schemas.rest.RestConfiguration;
import org.apache.ignite.configuration.schemas.rest.RestView;
-import org.apache.ignite.internal.configuration.ConfigurationManager;
-import org.apache.ignite.internal.configuration.ConfigurationRegistry;
+import
org.apache.ignite.internal.cluster.management.rest.ClusterManagementController;
import org.apache.ignite.internal.manager.IgniteComponent;
-import org.apache.ignite.internal.rest.api.RestHandlersRegister;
-import org.apache.ignite.internal.rest.api.Routes;
-import org.apache.ignite.internal.rest.netty.RestApiInitializer;
-import org.apache.ignite.internal.rest.routes.Router;
-import org.apache.ignite.internal.rest.routes.SimpleRouter;
-import org.apache.ignite.lang.IgniteException;
+import org.apache.ignite.internal.rest.api.RestFactory;
+import
org.apache.ignite.internal.rest.configuration.ClusterConfigurationController;
+import
org.apache.ignite.internal.rest.configuration.NodeConfigurationController;
import org.apache.ignite.lang.IgniteInternalException;
import org.apache.ignite.lang.IgniteLogger;
-import org.apache.ignite.network.NettyBootstrapFactory;
/**
- * Rest component is responsible for starting REST endpoints.
+ * Rest module is responsible for starting REST endpoints for accessing and
managing configuration.
*
- * <p>It is started on port 10300 by default, but it is possible to change
this in configuration itself. Refer to default config file in
+ * <p>It is started on port 10300 by default but it is possible to change this
in configuration itself. Refer to default config file in
* resources for the example.
*/
-public class RestComponent implements RestHandlersRegister, IgniteComponent {
+@OpenAPIDefinition(info = @Info(title = "Ignite REST module", version =
"3.0.0-alpha", license = @License(name = "Apache 2.0", url =
"https://ignite.apache.org"), contact = @Contact(email =
"[email protected]")))
+@OpenAPIInclude(classes = {ClusterConfigurationController.class,
NodeConfigurationController.class, ClusterManagementController.class})
+public class RestComponent implements IgniteComponent {
+ /** Default port. */
+ public static final int DFLT_PORT = 10300;
+
+ /** Server host. */
+ private static final String LOCALHOST = "localhost";
+
/** Ignite logger. */
private final IgniteLogger log =
IgniteLogger.forClass(RestComponent.class);
- /** Node configuration register. */
- private final ConfigurationRegistry nodeCfgRegistry;
+ /** Factories that produce beans needed for REST controllers. */
+ private final List<RestFactory> restFactories;
- /** Netty bootstrap factory. */
- private final NettyBootstrapFactory bootstrapFactory;
+ private final RestConfiguration restConfiguration;
- private final SimpleRouter router = new SimpleRouter();
+ /** Micronaut application context. */
+ private volatile ApplicationContext context;
- /** Netty channel. */
- private volatile Channel channel;
+ /** Server port. */
+ private int port;
/**
* Creates a new instance of REST module.
- *
- * @param nodeCfgMgr Node configuration manager.
- * @param bootstrapFactory Netty bootstrap factory.
*/
- public RestComponent(ConfigurationManager nodeCfgMgr,
NettyBootstrapFactory bootstrapFactory) {
- nodeCfgRegistry = nodeCfgMgr.configurationRegistry();
-
- this.bootstrapFactory = bootstrapFactory;
- }
-
- /** {@inheritDoc} */
- @Override
- public void registerHandlers(Consumer<Routes> registerAction) {
- registerAction.accept(router);
+ public RestComponent(List<RestFactory> restFactories, RestConfiguration
restConfiguration) {
+ this.restFactories = restFactories;
+ this.restConfiguration = restConfiguration;
}
/** {@inheritDoc} */
@Override
public void start() {
- if (channel != null) {
- throw new IgniteException("RestModule is already started.");
- }
-
- channel = startRestEndpoint(router).channel();
- }
-
- /**
- * Start endpoint.
- *
- * @param router Dispatcher of http requests.
- * @return Future which will be notified when this channel is closed.
- * @throws RuntimeException if this module cannot be bound to a port.
- */
- private ChannelFuture startRestEndpoint(Router router) {
- RestView restConfigurationView =
nodeCfgRegistry.getConfiguration(RestConfiguration.KEY).value();
+ RestView restConfigurationView = restConfiguration.value();
int desiredPort = restConfigurationView.port();
int portRange = restConfigurationView.portRange();
- int port = 0;
- Channel ch = null;
-
- ServerBootstrap bootstrap = bootstrapFactory.createServerBootstrap()
- .handler(new LoggingHandler(LogLevel.INFO))
- .childHandler(new RestApiInitializer(router));
-
for (int portCandidate = desiredPort; portCandidate <= desiredPort +
portRange; portCandidate++) {
- ChannelFuture bindRes =
bootstrap.bind(portCandidate).awaitUninterruptibly();
-
- if (bindRes.isSuccess()) {
- ch = bindRes.channel();
+ try {
+ context = buildMicronautContext(portCandidate).start();
port = portCandidate;
Review Comment:
Thanks, you are absolutelly right.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]