use of io.cdap.cdap.common.http.CommonNettyHttpServiceBuilder in project cdap by cdapio.
the class AppFabricServer method startUp.
/**
* Configures the AppFabricService pre-start.
*/
@Override
protected void startUp() throws Exception {
LoggingContextAccessor.setLoggingContext(new ServiceLoggingContext(NamespaceId.SYSTEM.getNamespace(), Constants.Logging.COMPONENT_NAME, Constants.Service.APP_FABRIC_HTTP));
Futures.allAsList(ImmutableList.of(provisioningService.start(), applicationLifecycleService.start(), bootstrapService.start(), programRuntimeService.start(), programNotificationSubscriberService.start(), runRecordCorrectorService.start(), coreSchedulerService.start(), eventPublishManager.start(), runRecordCounterService.start())).get();
// Create handler hooks
List<MetricsReporterHook> handlerHooks = handlerHookNames.stream().map(name -> new MetricsReporterHook(metricsCollectionService, name)).collect(Collectors.toList());
// Run http service on random port
NettyHttpService.Builder httpServiceBuilder = new CommonNettyHttpServiceBuilder(cConf, Constants.Service.APP_FABRIC_HTTP).setHost(hostname.getCanonicalHostName()).setHandlerHooks(handlerHooks).setHttpHandlers(handlers).setConnectionBacklog(cConf.getInt(Constants.AppFabric.BACKLOG_CONNECTIONS, Constants.AppFabric.DEFAULT_BACKLOG)).setExecThreadPoolSize(cConf.getInt(Constants.AppFabric.EXEC_THREADS, Constants.AppFabric.DEFAULT_EXEC_THREADS)).setBossThreadPoolSize(cConf.getInt(Constants.AppFabric.BOSS_THREADS, Constants.AppFabric.DEFAULT_BOSS_THREADS)).setWorkerThreadPoolSize(cConf.getInt(Constants.AppFabric.WORKER_THREADS, Constants.AppFabric.DEFAULT_WORKER_THREADS)).setPort(cConf.getInt(Constants.AppFabric.SERVER_PORT));
if (sslEnabled) {
new HttpsEnabler().configureKeyStore(cConf, sConf).enable(httpServiceBuilder);
}
cancelHttpService = startHttpService(httpServiceBuilder.build());
long applicationCount = TransactionRunners.run(transactionRunner, (TxCallable<Long>) context -> AppMetadataStore.create(context).getApplicationCount());
long namespaceCount = new DefaultNamespaceStore(transactionRunner).getNamespaceCount();
metricsCollectionService.getContext(Collections.emptyMap()).gauge(Constants.Metrics.Program.APPLICATION_COUNT, applicationCount);
metricsCollectionService.getContext(Collections.emptyMap()).gauge(Constants.Metrics.Program.NAMESPACE_COUNT, namespaceCount);
}
use of io.cdap.cdap.common.http.CommonNettyHttpServiceBuilder in project cdap by caskdata.
the class AppFabricServer method startUp.
/**
* Configures the AppFabricService pre-start.
*/
@Override
protected void startUp() throws Exception {
LoggingContextAccessor.setLoggingContext(new ServiceLoggingContext(NamespaceId.SYSTEM.getNamespace(), Constants.Logging.COMPONENT_NAME, Constants.Service.APP_FABRIC_HTTP));
Futures.allAsList(ImmutableList.of(provisioningService.start(), applicationLifecycleService.start(), bootstrapService.start(), programRuntimeService.start(), programNotificationSubscriberService.start(), runRecordCorrectorService.start(), coreSchedulerService.start(), eventPublishManager.start(), runRecordCounterService.start())).get();
// Create handler hooks
List<MetricsReporterHook> handlerHooks = handlerHookNames.stream().map(name -> new MetricsReporterHook(metricsCollectionService, name)).collect(Collectors.toList());
// Run http service on random port
NettyHttpService.Builder httpServiceBuilder = new CommonNettyHttpServiceBuilder(cConf, Constants.Service.APP_FABRIC_HTTP).setHost(hostname.getCanonicalHostName()).setHandlerHooks(handlerHooks).setHttpHandlers(handlers).setConnectionBacklog(cConf.getInt(Constants.AppFabric.BACKLOG_CONNECTIONS, Constants.AppFabric.DEFAULT_BACKLOG)).setExecThreadPoolSize(cConf.getInt(Constants.AppFabric.EXEC_THREADS, Constants.AppFabric.DEFAULT_EXEC_THREADS)).setBossThreadPoolSize(cConf.getInt(Constants.AppFabric.BOSS_THREADS, Constants.AppFabric.DEFAULT_BOSS_THREADS)).setWorkerThreadPoolSize(cConf.getInt(Constants.AppFabric.WORKER_THREADS, Constants.AppFabric.DEFAULT_WORKER_THREADS)).setPort(cConf.getInt(Constants.AppFabric.SERVER_PORT));
if (sslEnabled) {
new HttpsEnabler().configureKeyStore(cConf, sConf).enable(httpServiceBuilder);
}
cancelHttpService = startHttpService(httpServiceBuilder.build());
long applicationCount = TransactionRunners.run(transactionRunner, (TxCallable<Long>) context -> AppMetadataStore.create(context).getApplicationCount());
long namespaceCount = new DefaultNamespaceStore(transactionRunner).getNamespaceCount();
metricsCollectionService.getContext(Collections.emptyMap()).gauge(Constants.Metrics.Program.APPLICATION_COUNT, applicationCount);
metricsCollectionService.getContext(Collections.emptyMap()).gauge(Constants.Metrics.Program.NAMESPACE_COUNT, namespaceCount);
}
use of io.cdap.cdap.common.http.CommonNettyHttpServiceBuilder in project cdap by caskdata.
the class HealthCheckService method initiate.
public void initiate(String host, int port, String serviceName) {
this.serviceName = serviceName;
NettyHttpService.Builder builder = new CommonNettyHttpServiceBuilder(cConf, serviceName).setHttpHandlers(handlers).setHost(host).setPort(port);
if (cConf.getBoolean(Constants.Security.SSL.INTERNAL_ENABLED)) {
new HttpsEnabler().configureKeyStore(cConf, sConf).enable(builder);
}
httpService = builder.build();
}
use of io.cdap.cdap.common.http.CommonNettyHttpServiceBuilder in project cdap by caskdata.
the class AuthorizationHandlerTest method testDisabled.
private void testDisabled(CConfiguration cConf, FeatureDisabledException.Feature feature, String configSetting) throws Exception {
final InMemoryAccessController accessController = new InMemoryAccessController();
NettyHttpService service = new CommonNettyHttpServiceBuilder(cConf, getClass().getSimpleName()).setHttpHandlers(new AuthorizationHandler(accessController, new AccessControllerInstantiator(cConf, FACTORY) {
@Override
public AccessController get() {
return accessController;
}
}, cConf, new MasterAuthenticationContext())).build();
service.start();
try {
final AuthorizationClient client = new AuthorizationClient(ClientConfig.builder().setConnectionConfig(ConnectionConfig.builder().setHostname(service.getBindAddress().getHostName()).setPort(service.getBindAddress().getPort()).setSSLEnabled(false).build()).build());
final NamespaceId ns1 = Ids.namespace("ns1");
final Role admins = new Role("admins");
// Test that the right exception is thrown when any Authorization REST API is called with authorization disabled
verifyFeatureDisabled(new DisabledFeatureCaller() {
@Override
public void call() throws Exception {
client.grant(Authorizable.fromEntityId(ns1), admin, ImmutableSet.of(StandardPermission.GET));
}
}, feature, configSetting);
verifyFeatureDisabled(new DisabledFeatureCaller() {
@Override
public void call() throws Exception {
client.revoke(Authorizable.fromEntityId(ns1), admin, ImmutableSet.of(StandardPermission.GET));
}
}, feature, configSetting);
verifyFeatureDisabled(new DisabledFeatureCaller() {
@Override
public void call() throws Exception {
client.revoke(Authorizable.fromEntityId(ns1));
}
}, feature, configSetting);
verifyFeatureDisabled(new DisabledFeatureCaller() {
@Override
public void call() throws Exception {
client.listGrants(admin);
}
}, feature, configSetting);
verifyFeatureDisabled(new DisabledFeatureCaller() {
@Override
public void call() throws Exception {
client.addRoleToPrincipal(admins, admin);
}
}, feature, configSetting);
verifyFeatureDisabled(new DisabledFeatureCaller() {
@Override
public void call() throws Exception {
client.removeRoleFromPrincipal(admins, admin);
}
}, feature, configSetting);
verifyFeatureDisabled(new DisabledFeatureCaller() {
@Override
public void call() throws Exception {
client.createRole(admins);
}
}, feature, configSetting);
verifyFeatureDisabled(new DisabledFeatureCaller() {
@Override
public void call() throws Exception {
client.dropRole(admins);
}
}, feature, configSetting);
verifyFeatureDisabled(new DisabledFeatureCaller() {
@Override
public void call() throws Exception {
client.listAllRoles();
}
}, feature, configSetting);
} finally {
service.stop();
}
}
use of io.cdap.cdap.common.http.CommonNettyHttpServiceBuilder in project cdap by caskdata.
the class RemoteTaskExecutorTest method init.
@BeforeClass
public static void init() throws Exception {
cConf = CConfiguration.create();
discoveryService = new InMemoryDiscoveryService();
remoteClientFactory = new RemoteClientFactory(discoveryService, new DefaultInternalAuthenticator(new AuthenticationTestContext()));
httpService = new CommonNettyHttpServiceBuilder(cConf, "test").setHttpHandlers(new TaskWorkerHttpHandlerInternal(cConf, className -> {
}, new NoOpMetricsCollectionService())).setChannelPipelineModifier(new ChannelPipelineModifier() {
@Override
public void modify(ChannelPipeline pipeline) {
pipeline.addAfter("compressor", "decompressor", new HttpContentDecompressor());
}
}).build();
httpService.start();
}
Aggregations