use of org.apache.twill.discovery.DiscoveryServiceClient in project cdap by caskdata.
the class AppFabricServerTest method startStopServer.
@Test
public void startStopServer() throws Exception {
Injector injector = AppFabricTestHelper.getInjector();
AppFabricServer server = injector.getInstance(AppFabricServer.class);
DiscoveryServiceClient discoveryServiceClient = injector.getInstance(DiscoveryServiceClient.class);
Service.State state = server.startAndWait();
Assert.assertTrue(state == Service.State.RUNNING);
final EndpointStrategy endpointStrategy = new RandomEndpointStrategy(discoveryServiceClient.discover(Constants.Service.APP_FABRIC_HTTP));
Assert.assertNotNull(endpointStrategy.pick(5, TimeUnit.SECONDS));
state = server.stopAndWait();
Assert.assertTrue(state == Service.State.TERMINATED);
Tasks.waitFor(true, new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return endpointStrategy.pick() == null;
}
}, 5, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS);
}
use of org.apache.twill.discovery.DiscoveryServiceClient in project cdap by caskdata.
the class RemoteDatasetFrameworkTest method before.
@Before
public void before() throws Exception {
cConf.set(Constants.Service.MASTER_SERVICES_BIND_ADDRESS, "localhost");
cConf.setBoolean(Constants.Dangerous.UNRECOVERABLE_RESET, true);
Configuration txConf = HBaseConfiguration.create();
CConfigurationUtil.copyTxProperties(cConf, txConf);
// ok to pass null, since the impersonator won't actually be called, if kerberos security is not enabled
Impersonator impersonator = new DefaultImpersonator(cConf, null);
// TODO: Refactor to use injector for everything
Injector injector = Guice.createInjector(new ConfigModule(cConf, txConf), new DiscoveryRuntimeModule().getInMemoryModules(), new AuthorizationTestModule(), new AuthorizationEnforcementModule().getInMemoryModules(), new AuthenticationContextModules().getMasterModule(), new TransactionInMemoryModule(), new AbstractModule() {
@Override
protected void configure() {
bind(MetricsCollectionService.class).to(NoOpMetricsCollectionService.class).in(Singleton.class);
install(new FactoryModuleBuilder().implement(DatasetDefinitionRegistry.class, DefaultDatasetDefinitionRegistry.class).build(DatasetDefinitionRegistryFactory.class));
// through the injector, we only need RemoteDatasetFramework in these tests
bind(RemoteDatasetFramework.class);
}
});
// Tx Manager to support working with datasets
txManager = new TransactionManager(txConf);
txManager.startAndWait();
InMemoryTxSystemClient txSystemClient = new InMemoryTxSystemClient(txManager);
TransactionSystemClientService txSystemClientService = new DelegatingTransactionSystemClientService(txSystemClient);
DiscoveryService discoveryService = injector.getInstance(DiscoveryService.class);
DiscoveryServiceClient discoveryServiceClient = injector.getInstance(DiscoveryServiceClient.class);
MetricsCollectionService metricsCollectionService = injector.getInstance(MetricsCollectionService.class);
AuthenticationContext authenticationContext = injector.getInstance(AuthenticationContext.class);
framework = new RemoteDatasetFramework(cConf, discoveryServiceClient, registryFactory, authenticationContext);
SystemDatasetInstantiatorFactory datasetInstantiatorFactory = new SystemDatasetInstantiatorFactory(locationFactory, framework, cConf);
DatasetAdminService datasetAdminService = new DatasetAdminService(framework, cConf, locationFactory, datasetInstantiatorFactory, new NoOpMetadataStore(), impersonator);
ImmutableSet<HttpHandler> handlers = ImmutableSet.<HttpHandler>of(new DatasetAdminOpHTTPHandler(datasetAdminService));
opExecutorService = new DatasetOpExecutorService(cConf, discoveryService, metricsCollectionService, handlers);
opExecutorService.startAndWait();
ImmutableMap<String, DatasetModule> modules = ImmutableMap.<String, DatasetModule>builder().put("memoryTable", new InMemoryTableModule()).put("core", new CoreDatasetsModule()).putAll(DatasetMetaTableUtil.getModules()).build();
InMemoryDatasetFramework mdsFramework = new InMemoryDatasetFramework(registryFactory, modules);
DiscoveryExploreClient exploreClient = new DiscoveryExploreClient(discoveryServiceClient, authenticationContext);
ExploreFacade exploreFacade = new ExploreFacade(exploreClient, cConf);
TransactionExecutorFactory txExecutorFactory = new DynamicTransactionExecutorFactory(txSystemClient);
AuthorizationEnforcer authorizationEnforcer = injector.getInstance(AuthorizationEnforcer.class);
DatasetTypeManager typeManager = new DatasetTypeManager(cConf, locationFactory, txSystemClientService, txExecutorFactory, mdsFramework, impersonator);
DatasetInstanceManager instanceManager = new DatasetInstanceManager(txSystemClientService, txExecutorFactory, mdsFramework);
PrivilegesManager privilegesManager = injector.getInstance(PrivilegesManager.class);
DatasetTypeService typeService = new DatasetTypeService(typeManager, namespaceQueryAdmin, namespacedLocationFactory, authorizationEnforcer, privilegesManager, authenticationContext, cConf, impersonator, txSystemClientService, mdsFramework, txExecutorFactory, DEFAULT_MODULES);
DatasetOpExecutor opExecutor = new LocalDatasetOpExecutor(cConf, discoveryServiceClient, opExecutorService, authenticationContext);
DatasetInstanceService instanceService = new DatasetInstanceService(typeService, instanceManager, opExecutor, exploreFacade, namespaceQueryAdmin, ownerAdmin, authorizationEnforcer, privilegesManager, authenticationContext);
instanceService.setAuditPublisher(inMemoryAuditPublisher);
service = new DatasetService(cConf, discoveryService, discoveryServiceClient, metricsCollectionService, new InMemoryDatasetOpExecutor(framework), new HashSet<DatasetMetricsReporter>(), typeService, instanceService);
// Start dataset service, wait for it to be discoverable
service.startAndWait();
EndpointStrategy endpointStrategy = new RandomEndpointStrategy(discoveryServiceClient.discover(Constants.Service.DATASET_MANAGER));
Preconditions.checkNotNull(endpointStrategy.pick(5, TimeUnit.SECONDS), "%s service is not up after 5 seconds", service);
createNamespace(NamespaceId.SYSTEM);
createNamespace(NAMESPACE_ID);
}
use of org.apache.twill.discovery.DiscoveryServiceClient in project cdap by caskdata.
the class RouterResource method before.
@Override
protected void before() throws Throwable {
CConfiguration cConf = CConfiguration.create();
Injector injector = Guice.createInjector(new SecurityModules().getInMemoryModules(), new DiscoveryRuntimeModule().getInMemoryModules(), new AppFabricTestModule(cConf));
DiscoveryServiceClient discoveryServiceClient = injector.getInstance(DiscoveryServiceClient.class);
AccessTokenTransformer accessTokenTransformer = new MockAccessTokenTransfomer();
RouteStore routeStore = injector.getInstance(RouteStore.class);
SConfiguration sConf = injector.getInstance(SConfiguration.class);
cConf.set(Constants.Router.ADDRESS, hostname);
cConf.setInt(Constants.Router.ROUTER_PORT, 0);
for (Map.Entry<String, String> entry : additionalConfig.entrySet()) {
cConf.set(entry.getKey(), entry.getValue());
}
router = new NettyRouter(cConf, sConf, InetAddresses.forString(hostname), new RouterServiceLookup(cConf, (DiscoveryServiceClient) discoveryService, new RouterPathLookup(), routeStore), new MockTokenValidator("failme"), accessTokenTransformer, discoveryServiceClient);
router.startAndWait();
for (Map.Entry<Integer, String> entry : router.getServiceLookup().getServiceMap().entrySet()) {
serviceMap.put(entry.getValue(), entry.getKey());
}
}
use of org.apache.twill.discovery.DiscoveryServiceClient in project cdap by caskdata.
the class RoutingToDataSetsTest method before.
@BeforeClass
public static void before() throws Exception {
CConfiguration cConf = CConfiguration.create();
Injector injector = Guice.createInjector(new SecurityModules().getInMemoryModules(), new DiscoveryRuntimeModule().getInMemoryModules(), new AppFabricTestModule(cConf));
// Starting router
DiscoveryServiceClient discoveryServiceClient = injector.getInstance(DiscoveryServiceClient.class);
AccessTokenTransformer accessTokenTransformer = injector.getInstance(AccessTokenTransformer.class);
RouteStore routeStore = injector.getInstance(RouteStore.class);
SConfiguration sConf = SConfiguration.create();
cConf.set(Constants.Router.ADDRESS, "localhost");
port = Networks.getRandomPort();
cConf.setInt(Constants.Router.ROUTER_PORT, port);
nettyRouter = new NettyRouter(cConf, sConf, InetAddresses.forString("127.0.0.1"), new RouterServiceLookup(cConf, discoveryServiceClient, new RouterPathLookup(), routeStore), new SuccessTokenValidator(), accessTokenTransformer, discoveryServiceClient);
nettyRouter.startAndWait();
// Starting mock DataSet service
DiscoveryService discoveryService = injector.getInstance(DiscoveryService.class);
mockService = new MockHttpService(discoveryService, Constants.Service.DATASET_MANAGER, new MockDatasetTypeHandler(), new MockDatasetInstanceHandler());
mockService.startAndWait();
}
use of org.apache.twill.discovery.DiscoveryServiceClient in project cdap by caskdata.
the class ExternalAuthenticationServerTestBase method setup.
protected void setup() throws Exception {
Assert.assertNotNull("CConfiguration needs to be set by derived classes", configuration);
// Intentionally set "security.auth.server.announce.address" and "security.auth.server.announce.address" to invalid
// values verify that they are not used by external authentication server
configuration.set(Constants.Security.AUTH_SERVER_ANNOUNCE_ADDRESS_DEPRECATED, "invalid.address");
configuration.set(Constants.Security.AUTH_SERVER_ANNOUNCE_URLS, "invalid.urls");
Module securityModule = Modules.override(new SecurityModules().getInMemoryModules()).with(new AbstractModule() {
@Override
protected void configure() {
bind(AuditLogHandler.class).annotatedWith(Names.named(ExternalAuthenticationServer.NAMED_EXTERNAL_AUTH)).toInstance(new AuditLogHandler(TEST_AUDIT_LOGGER));
}
});
Injector injector = Guice.createInjector(new IOModule(), securityModule, new ConfigModule(getConfiguration(configuration), HBaseConfiguration.create(), sConfiguration), new DiscoveryRuntimeModule().getInMemoryModules());
server = injector.getInstance(ExternalAuthenticationServer.class);
tokenCodec = injector.getInstance(AccessTokenCodec.class);
discoveryServiceClient = injector.getInstance(DiscoveryServiceClient.class);
if (configuration.getBoolean(Constants.Security.SSL.EXTERNAL_ENABLED)) {
port = configuration.getInt(Constants.Security.AuthenticationServer.SSL_PORT);
} else {
port = configuration.getInt(Constants.Security.AUTH_SERVER_BIND_PORT);
}
startExternalAuthenticationServer();
server.startAndWait();
LOG.info("Auth server running on port {}", port);
TimeUnit.SECONDS.sleep(3);
}
Aggregations