use of org.infinispan.server.core.configuration.ProtocolServerConfiguration in project infinispan by infinispan.
the class Server method run.
public synchronized CompletableFuture<ExitStatus> run() {
CompletableFuture<ExitStatus> r = exitHandler.getExitFuture();
if (status == ComponentStatus.RUNNING) {
return r;
}
protocolServers = new ConcurrentHashMap<>(4);
try {
// Load any server extensions
extensions = new Extensions();
extensions.load(classLoader);
// Create the cache manager
cacheManager = new DefaultCacheManager(configurationBuilderHolder, false);
// Retrieve the server configuration
serverConfiguration = SecurityActions.getCacheManagerConfiguration(cacheManager).module(ServerConfiguration.class);
serverConfiguration.setServer(this);
// Initialize the data sources
dataSources = new HashMap<>();
InitialContext initialContext = new InitialContext();
for (DataSourceConfiguration dataSourceConfiguration : serverConfiguration.dataSources().values()) {
DataSource dataSource = DataSourceFactory.create(dataSourceConfiguration);
dataSources.put(dataSourceConfiguration.name(), dataSource);
initialContext.bind(dataSourceConfiguration.jndiName(), dataSource);
}
// Start the cache manager
SecurityActions.startCacheManager(cacheManager);
BasicComponentRegistry bcr = SecurityActions.getGlobalComponentRegistry(cacheManager).getComponent(BasicComponentRegistry.class.getName());
blockingManager = bcr.getComponent(BlockingManager.class).running();
serverStateManager = new ServerStateManagerImpl(this, cacheManager, bcr.getComponent(GlobalConfigurationManager.class).running());
bcr.registerComponent(ServerStateManager.class, serverStateManager, false);
ScheduledExecutorService timeoutExecutor = bcr.getComponent(KnownComponentNames.TIMEOUT_SCHEDULE_EXECUTOR, ScheduledExecutorService.class).running();
// BlockingManager of single container used for writing the global manifest, but this will need to change
// when multiple containers are supported by the server. Similarly, the default cache manager is used to create
// the clustered locks.
Path dataRoot = serverRoot.toPath().resolve(properties.getProperty(INFINISPAN_SERVER_DATA_PATH));
backupManager = new BackupManagerImpl(blockingManager, cacheManager, dataRoot);
backupManager.init();
// Register the task manager
taskManager = bcr.getComponent(TaskManager.class).running();
taskManager.registerTaskEngine(extensions.getServerTaskEngine(cacheManager));
// Initialize the OpenTracing integration
RequestTracer.start();
for (EndpointConfiguration endpoint : serverConfiguration.endpoints().endpoints()) {
// Start the protocol servers
SinglePortRouteSource routeSource = new SinglePortRouteSource();
Set<Route<? extends RouteSource, ? extends RouteDestination>> routes = ConcurrentHashMap.newKeySet();
endpoint.connectors().parallelStream().forEach(configuration -> {
try {
Class<? extends ProtocolServer> protocolServerClass = configuration.getClass().getAnnotation(ConfigurationFor.class).value().asSubclass(ProtocolServer.class);
ProtocolServer protocolServer = Util.getInstance(protocolServerClass);
protocolServer.setServerManagement(this, endpoint.admin());
if (configuration instanceof HotRodServerConfiguration) {
ElytronSASLAuthenticationProvider.init((HotRodServerConfiguration) configuration, serverConfiguration, timeoutExecutor);
} else if (configuration instanceof RestServerConfiguration) {
ElytronHTTPAuthenticator.init((RestServerConfiguration) configuration, serverConfiguration);
} else if (configuration instanceof RespServerConfiguration) {
ElytronRESPAuthenticator.init((RespServerConfiguration) configuration, serverConfiguration, blockingManager);
}
protocolServers.put(protocolServer.getName() + "-" + configuration.name(), protocolServer);
SecurityActions.startProtocolServer(protocolServer, configuration, cacheManager);
ProtocolServerConfiguration protocolConfig = protocolServer.getConfiguration();
if (protocolConfig.startTransport()) {
log.protocolStarted(protocolServer.getName(), configuration.socketBinding(), protocolConfig.host(), protocolConfig.port());
} else {
if (protocolServer instanceof HotRodServer) {
routes.add(new Route<>(routeSource, new HotRodServerRouteDestination(protocolServer.getName(), (HotRodServer) protocolServer)));
extensions.apply((HotRodServer) protocolServer);
} else if (protocolServer instanceof RestServer) {
routes.add(new Route<>(routeSource, new RestServerRouteDestination(protocolServer.getName(), (RestServer) protocolServer)));
} else if (protocolServer instanceof RespServer) {
routes.add(new Route<>(routeSource, new RespServerRouteDestination(protocolServer.getName(), (RespServer) protocolServer)));
}
log.protocolStarted(protocolServer.getName());
}
} catch (Throwable t) {
throw t instanceof RuntimeException ? (RuntimeException) t : new RuntimeException(t);
}
});
// Next we start the single-port endpoints
SinglePortRouterConfiguration singlePortRouter = endpoint.singlePortRouter();
SinglePortEndpointRouter endpointServer = new SinglePortEndpointRouter(singlePortRouter);
endpointServer.start(new RoutingTable(routes), cacheManager);
protocolServers.put("endpoint-" + endpoint.socketBinding(), endpointServer);
log.protocolStarted(endpointServer.getName(), singlePortRouter.socketBinding(), singlePortRouter.host(), singlePortRouter.port());
log.endpointUrl(Util.requireNonNullElse(cacheManager.getAddress(), "local"), singlePortRouter.ssl().enabled() ? "https" : "http", singlePortRouter.host(), singlePortRouter.port());
}
serverStateManager.start();
// Change status
this.status = ComponentStatus.RUNNING;
log.serverStarted(Version.getBrandName(), Version.getBrandVersion(), timeService.timeDuration(startTime, TimeUnit.MILLISECONDS));
} catch (Exception e) {
r.completeExceptionally(e);
}
r = r.handle((status, t) -> {
if (t != null) {
Server.log.serverFailedToStart(Version.getBrandName(), t);
}
localShutdown(status);
return null;
});
return r;
}
use of org.infinispan.server.core.configuration.ProtocolServerConfiguration in project infinispan by infinispan.
the class ServerConfigurationSerializer method writeEndpoints.
private void writeEndpoints(ConfigurationWriter writer, EndpointsConfiguration endpoints) {
writer.writeStartElement(Element.ENDPOINTS);
for (EndpointConfiguration endpoint : endpoints.endpoints()) {
writer.writeStartElement(Element.ENDPOINT);
endpoint.attributes().write(writer);
for (ProtocolServerConfiguration connector : endpoint.connectors()) {
if (connector instanceof HotRodServerConfiguration) {
writeConnector(writer, (HotRodServerConfiguration) connector);
} else if (connector instanceof RestServerConfiguration) {
writeConnector(writer, (RestServerConfiguration) connector);
} else if (connector instanceof MemcachedServerConfiguration) {
writeConnector(writer, (MemcachedServerConfiguration) connector);
}
}
writer.writeEndElement();
}
writer.writeEndElement();
}
use of org.infinispan.server.core.configuration.ProtocolServerConfiguration in project infinispan by infinispan.
the class EndpointConfigurationBuilder method create.
public EndpointConfiguration create(SocketBindingsConfiguration bindingsConfiguration, SecurityConfiguration securityConfiguration) {
boolean implicitSecurity = implicitConnectorSecurity && securityRealm() != null;
bindingsConfiguration.applySocketBinding(attributes.attribute(EndpointConfiguration.SOCKET_BINDING).get(), singlePortBuilder, singlePortBuilder);
List<ProtocolServerConfiguration> connectors = new ArrayList<>(connectorBuilders.size());
for (ProtocolServerConfigurationBuilder<?, ?> builder : connectorBuilders) {
bindingsConfiguration.applySocketBinding(builder.socketBinding(), builder, singlePortBuilder);
if (implicitSecurity) {
if (builder instanceof HotRodServerConfigurationBuilder) {
enableImplicitAuthentication(securityConfiguration, securityRealm(), (HotRodServerConfigurationBuilder) builder);
} else if (builder instanceof RestServerConfigurationBuilder) {
enableImplicitAuthentication(securityConfiguration, securityRealm(), (RestServerConfigurationBuilder) builder);
} else if (builder instanceof RespServerConfigurationBuilder) {
enableImplicitAuthentication(securityConfiguration, securityRealm(), (RespServerConfigurationBuilder) builder);
}
}
connectors.add(builder.create());
}
if (implicitSecurity) {
RealmConfiguration realm = securityConfiguration.realms().getRealm(securityRealm());
if (realm.hasFeature(ServerSecurityRealm.Feature.ENCRYPT)) {
singlePortBuilder.ssl().enable().sslContext(realm.serverSSLContext());
}
}
return new EndpointConfiguration(attributes.protect(), connectors, singlePortBuilder.create());
}
use of org.infinispan.server.core.configuration.ProtocolServerConfiguration in project infinispan by infinispan.
the class ServerConfigurationParserTest method validateConfiguration.
private void validateConfiguration(ServerConfiguration configuration) {
// Interfaces
assertEquals(2, configuration.networkInterfaces().size());
NetworkAddress defaultInterface = configuration.networkInterfaces().get("default").getNetworkAddress();
assertNotNull(defaultInterface);
assertTrue(defaultInterface.getAddress().isLoopbackAddress());
// Socket bindings
Map<String, SocketBindingConfiguration> socketBindings = configuration.socketBindings();
assertEquals(5, socketBindings.size());
assertEquals(11221, socketBindings.get("memcached").port());
assertEquals(12221, socketBindings.get("memcached-2").port());
assertEquals(11222, socketBindings.get("default").port());
assertEquals(11223, socketBindings.get("hotrod").port());
assertEquals(8080, socketBindings.get("rest").port());
// Security realms
Map<String, RealmConfiguration> realms = configuration.security().realms().realms();
assertEquals(3, realms.size());
RealmConfiguration realmConfiguration = realms.get("default");
assertEquals("default", realmConfiguration.name());
realmConfiguration = realms.get("using-credentials");
assertEquals("using-credentials", realmConfiguration.name());
// Data Sources
Map<String, DataSourceConfiguration> dataSources = configuration.dataSources();
assertEquals(2, dataSources.size());
DataSourceConfiguration dataSource = dataSources.get("database");
assertEquals("jdbc/database", dataSource.jndiName());
assertEquals("jdbc:h2:tcp://${org.infinispan.test.host.address}:1521/test", dataSource.url());
assertEquals("test", dataSource.username());
assertEquals("test", new String(dataSource.password()));
assertEquals("SELECT 1", dataSource.initialSql());
assertEquals("org.h2.Driver", dataSource.driver());
assertEquals(10, dataSource.maxSize());
assertEquals(1, dataSource.minSize());
assertEquals(1, dataSource.initialSize());
assertEquals(1, dataSource.connectionProperties().size());
assertEquals(10000, dataSource.leakDetection());
assertEquals(1000, dataSource.backgroundValidation());
assertEquals(500, dataSource.validateOnAcquisition());
assertEquals("somevalue", dataSource.connectionProperties().get("someproperty"));
dataSource = dataSources.get("database-with-credential");
assertEquals("test", new String(dataSource.password()));
// Connectors
List<ProtocolServerConfiguration> connectors = configuration.endpoints().endpoints().get(0).connectors();
assertEquals(3, connectors.size());
assertTrue(connectors.get(0) instanceof HotRodServerConfiguration);
assertTrue(connectors.get(1) instanceof RestServerConfiguration);
assertTrue(connectors.get(2) instanceof MemcachedServerConfiguration);
// Ensure endpoints are bound to the interfaces
SinglePortRouterConfiguration singlePortRouter = configuration.endpoints().endpoints().get(0).singlePortRouter();
assertEquals(socketBindings.get("default").interfaceConfiguration().getNetworkAddress().getAddress().getHostAddress(), singlePortRouter.host());
assertEquals(socketBindings.get("default").port(), singlePortRouter.port());
assertEquals(socketBindings.get("memcached").port(), configuration.endpoints().endpoints().get(0).connectors().get(2).port());
assertEquals("strongPassword", new String(((Supplier<char[]>) realmProvider(realmConfiguration, LdapRealmConfiguration.class).attributes().attribute(Attribute.CREDENTIAL).get()).get()));
assertEquals("secret", new String(((Supplier<char[]>) realmConfiguration.serverIdentitiesConfiguration().sslConfiguration().trustStore().attributes().attribute(Attribute.PASSWORD).get()).get()));
assertEquals("1fdca4ec-c416-47e0-867a-3d471af7050f", new String(((Supplier<char[]>) realmProvider(realmConfiguration, TokenRealmConfiguration.class).oauth2Configuration().attributes().attribute(Attribute.CLIENT_SECRET).get()).get()));
}
Aggregations