Search in sources :

Example 31 with RandomEndpointStrategy

use of io.cdap.cdap.common.discovery.RandomEndpointStrategy in project cdap by cdapio.

the class DatasetServiceTestBase method getDiscoverable.

@Nullable
private synchronized Discoverable getDiscoverable() {
    Discoverable discoverable = new RandomEndpointStrategy(() -> discoveryServiceClient.discover(Constants.Service.DATASET_MANAGER)).pick(10, TimeUnit.SECONDS);
    Preconditions.checkNotNull(discoverable, "No endpoint discovered for service %s", Constants.Service.DATASET_MANAGER);
    return discoverable;
}
Also used : Discoverable(org.apache.twill.discovery.Discoverable) RandomEndpointStrategy(io.cdap.cdap.common.discovery.RandomEndpointStrategy) Nullable(javax.annotation.Nullable)

Example 32 with RandomEndpointStrategy

use of io.cdap.cdap.common.discovery.RandomEndpointStrategy in project cdap by cdapio.

the class DatasetServiceTestBase method waitForService.

private static void waitForService(String service) {
    EndpointStrategy endpointStrategy = new RandomEndpointStrategy(() -> discoveryServiceClient.discover(service));
    Preconditions.checkNotNull(endpointStrategy.pick(5, TimeUnit.SECONDS), "%s service is not up after 5 seconds", service);
}
Also used : RandomEndpointStrategy(io.cdap.cdap.common.discovery.RandomEndpointStrategy) EndpointStrategy(io.cdap.cdap.common.discovery.EndpointStrategy) RandomEndpointStrategy(io.cdap.cdap.common.discovery.RandomEndpointStrategy)

Example 33 with RandomEndpointStrategy

use of io.cdap.cdap.common.discovery.RandomEndpointStrategy in project cdap by cdapio.

the class DatasetOpExecutorServiceTest method setUp.

@Before
public void setUp() throws Exception {
    Configuration hConf = new Configuration();
    CConfiguration cConf = CConfiguration.create();
    File datasetDir = new File(TMP_FOLDER.newFolder(), "datasetUser");
    Assert.assertTrue(datasetDir.mkdirs());
    cConf.set(Constants.Dataset.Manager.OUTPUT_DIR, datasetDir.getAbsolutePath());
    cConf.set(Constants.Service.MASTER_SERVICES_BIND_ADDRESS, "localhost");
    cConf.set(Constants.Dataset.Executor.ADDRESS, "localhost");
    cConf.setInt(Constants.Dataset.Executor.PORT, Networks.getRandomPort());
    Injector injector = Guice.createInjector(new ConfigModule(cConf, hConf), RemoteAuthenticatorModules.getNoOpModule(), new IOModule(), new ZKClientModule(), new KafkaClientModule(), new InMemoryDiscoveryModule(), new NonCustomLocationUnitTestModule(), new DataFabricModules().getInMemoryModules(), new DataSetsModules().getStandaloneModules(), new DataSetServiceModules().getInMemoryModules(), new TransactionMetricsModule(), new ExploreClientModule(), new NamespaceAdminTestModule(), new AuthenticationContextModules().getMasterModule(), new AuthorizationTestModule(), new AuthorizationEnforcementModule().getInMemoryModules(), new AbstractModule() {

        @Override
        protected void configure() {
            bind(UGIProvider.class).to(UnsupportedUGIProvider.class);
            bind(OwnerAdmin.class).to(DefaultOwnerAdmin.class);
            bind(MetadataServiceClient.class).to(NoOpMetadataServiceClient.class);
        }
    });
    txManager = injector.getInstance(TransactionManager.class);
    txManager.startAndWait();
    StoreDefinition.createAllTables(injector.getInstance(StructuredTableAdmin.class));
    dsOpExecService = injector.getInstance(DatasetOpExecutorService.class);
    dsOpExecService.startAndWait();
    managerService = injector.getInstance(DatasetService.class);
    managerService.startAndWait();
    dsFramework = injector.getInstance(DatasetFramework.class);
    // find host
    DiscoveryServiceClient discoveryClient = injector.getInstance(DiscoveryServiceClient.class);
    endpointStrategy = new RandomEndpointStrategy(() -> discoveryClient.discover(Constants.Service.DATASET_MANAGER));
    namespaceAdmin = injector.getInstance(NamespaceAdmin.class);
    namespaceAdmin.create(NamespaceMeta.DEFAULT);
    namespaceAdmin.create(new NamespaceMeta.Builder().setName(bob.getParent()).build());
}
Also used : IOModule(io.cdap.cdap.common.guice.IOModule) InMemoryDiscoveryModule(io.cdap.cdap.common.guice.InMemoryDiscoveryModule) DataSetServiceModules(io.cdap.cdap.data.runtime.DataSetServiceModules) DiscoveryServiceClient(org.apache.twill.discovery.DiscoveryServiceClient) Configuration(org.apache.hadoop.conf.Configuration) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) NamespaceAdminTestModule(io.cdap.cdap.common.guice.NamespaceAdminTestModule) ConfigModule(io.cdap.cdap.common.guice.ConfigModule) StructuredTableAdmin(io.cdap.cdap.spi.data.StructuredTableAdmin) DatasetService(io.cdap.cdap.data2.datafabric.dataset.service.DatasetService) TransactionMetricsModule(io.cdap.cdap.data.runtime.TransactionMetricsModule) DatasetFramework(io.cdap.cdap.data2.dataset2.DatasetFramework) ZKClientModule(io.cdap.cdap.common.guice.ZKClientModule) Injector(com.google.inject.Injector) KafkaClientModule(io.cdap.cdap.common.guice.KafkaClientModule) NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) UnsupportedUGIProvider(io.cdap.cdap.security.impersonation.UnsupportedUGIProvider) AuthenticationContextModules(io.cdap.cdap.security.auth.context.AuthenticationContextModules) DataSetsModules(io.cdap.cdap.data.runtime.DataSetsModules) NamespaceAdmin(io.cdap.cdap.common.namespace.NamespaceAdmin) NonCustomLocationUnitTestModule(io.cdap.cdap.common.guice.NonCustomLocationUnitTestModule) DefaultOwnerAdmin(io.cdap.cdap.security.impersonation.DefaultOwnerAdmin) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) AuthorizationTestModule(io.cdap.cdap.security.authorization.AuthorizationTestModule) AbstractModule(com.google.inject.AbstractModule) ExploreClientModule(io.cdap.cdap.explore.guice.ExploreClientModule) TransactionManager(org.apache.tephra.TransactionManager) NoOpMetadataServiceClient(io.cdap.cdap.data2.metadata.writer.NoOpMetadataServiceClient) File(java.io.File) DataFabricModules(io.cdap.cdap.data.runtime.DataFabricModules) AuthorizationEnforcementModule(io.cdap.cdap.security.authorization.AuthorizationEnforcementModule) RandomEndpointStrategy(io.cdap.cdap.common.discovery.RandomEndpointStrategy) Before(org.junit.Before)

Example 34 with RandomEndpointStrategy

use of io.cdap.cdap.common.discovery.RandomEndpointStrategy in project cdap by cdapio.

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), RemoteAuthenticatorModules.getNoOpModule(), new InMemoryDiscoveryModule(), new AuthorizationTestModule(), new StorageModule(), new SystemDatasetRuntimeModule().getInMemoryModules(), new AuthorizationEnforcementModule().getInMemoryModules(), new AuthenticationContextModules().getMasterModule(), new TransactionInMemoryModule(), new AbstractModule() {

        @Override
        protected void configure() {
            bind(MetricsCollectionService.class).to(NoOpMetricsCollectionService.class).in(Singleton.class);
            bind(DatasetDefinitionRegistryFactory.class).to(DefaultDatasetDefinitionRegistryFactory.class).in(Scopes.SINGLETON);
            // through the injector, we only need RemoteDatasetFramework in these tests
            bind(RemoteDatasetFramework.class);
        }
    });
    // Tx Manager to support working with datasets
    txManager = injector.getInstance(TransactionManager.class);
    txManager.startAndWait();
    TransactionRunner transactionRunner = injector.getInstance(TransactionRunner.class);
    StructuredTableAdmin structuredTableAdmin = injector.getInstance(StructuredTableAdmin.class);
    StoreDefinition.createAllTables(structuredTableAdmin);
    InMemoryTxSystemClient txSystemClient = new InMemoryTxSystemClient(txManager);
    TransactionSystemClientService txSystemClientService = new DelegatingTransactionSystemClientService(txSystemClient);
    DiscoveryService discoveryService = injector.getInstance(DiscoveryService.class);
    DiscoveryServiceClient discoveryServiceClient = injector.getInstance(DiscoveryServiceClient.class);
    CommonNettyHttpServiceFactory commonNettyHttpServiceFactory = injector.getInstance(CommonNettyHttpServiceFactory.class);
    AuthenticationContext authenticationContext = injector.getInstance(AuthenticationContext.class);
    RemoteClientFactory remoteClientFactory = injector.getInstance(RemoteClientFactory.class);
    framework = createFramework(authenticationContext, remoteClientFactory);
    SystemDatasetInstantiatorFactory datasetInstantiatorFactory = new SystemDatasetInstantiatorFactory(locationFactory, framework, cConf);
    DatasetAdminService datasetAdminService = new DatasetAdminService(framework, cConf, locationFactory, datasetInstantiatorFactory, impersonator);
    ImmutableSet<HttpHandler> handlers = ImmutableSet.of(new DatasetAdminOpHTTPHandler(datasetAdminService));
    opExecutorService = new DatasetOpExecutorService(cConf, SConfiguration.create(), discoveryService, commonNettyHttpServiceFactory, handlers);
    opExecutorService.startAndWait();
    DiscoveryExploreClient exploreClient = new DiscoveryExploreClient(discoveryServiceClient, authenticationContext);
    ExploreFacade exploreFacade = new ExploreFacade(exploreClient, cConf);
    AccessEnforcer accessEnforcer = injector.getInstance(AccessEnforcer.class);
    DatasetTypeManager typeManager = new DatasetTypeManager(cConf, locationFactory, impersonator, transactionRunner);
    DatasetInstanceManager instanceManager = new DatasetInstanceManager(transactionRunner);
    DatasetTypeService noAuthTypeService = new DefaultDatasetTypeService(typeManager, namespaceQueryAdmin, namespacePathLocator, cConf, impersonator, txSystemClientService, transactionRunner, DEFAULT_MODULES);
    DatasetTypeService typeService = new AuthorizationDatasetTypeService(noAuthTypeService, accessEnforcer, authenticationContext);
    DatasetOpExecutor opExecutor = new RemoteDatasetOpExecutor(authenticationContext, remoteClientFactory);
    DatasetInstanceService instanceService = new DatasetInstanceService(typeService, noAuthTypeService, instanceManager, opExecutor, exploreFacade, namespaceQueryAdmin, ownerAdmin, accessEnforcer, authenticationContext, new NoOpMetadataServiceClient());
    instanceService.setAuditPublisher(inMemoryAuditPublisher);
    service = new DatasetService(cConf, SConfiguration.create(), discoveryService, discoveryServiceClient, commonNettyHttpServiceFactory, new HashSet<>(), 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);
}
Also used : DiscoveryServiceClient(org.apache.twill.discovery.DiscoveryServiceClient) AuthenticationContext(io.cdap.cdap.security.spi.authentication.AuthenticationContext) DatasetAdminOpHTTPHandler(io.cdap.cdap.data2.datafabric.dataset.service.executor.DatasetAdminOpHTTPHandler) Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) SConfiguration(io.cdap.cdap.common.conf.SConfiguration) TransactionInMemoryModule(org.apache.tephra.runtime.TransactionInMemoryModule) DatasetService(io.cdap.cdap.data2.datafabric.dataset.service.DatasetService) DefaultDatasetTypeService(io.cdap.cdap.data2.datafabric.dataset.service.DefaultDatasetTypeService) DatasetTypeService(io.cdap.cdap.data2.datafabric.dataset.service.DatasetTypeService) AuthorizationDatasetTypeService(io.cdap.cdap.data2.datafabric.dataset.service.AuthorizationDatasetTypeService) ExploreFacade(io.cdap.cdap.explore.client.ExploreFacade) DatasetDefinitionRegistryFactory(io.cdap.cdap.data2.dataset2.DatasetDefinitionRegistryFactory) DefaultDatasetDefinitionRegistryFactory(io.cdap.cdap.data2.dataset2.DefaultDatasetDefinitionRegistryFactory) RandomEndpointStrategy(io.cdap.cdap.common.discovery.RandomEndpointStrategy) EndpointStrategy(io.cdap.cdap.common.discovery.EndpointStrategy) Injector(com.google.inject.Injector) SystemDatasetRuntimeModule(io.cdap.cdap.data.runtime.SystemDatasetRuntimeModule) HashSet(java.util.HashSet) HttpHandler(io.cdap.http.HttpHandler) DatasetInstanceManager(io.cdap.cdap.data2.datafabric.dataset.instance.DatasetInstanceManager) NoOpMetricsCollectionService(io.cdap.cdap.common.metrics.NoOpMetricsCollectionService) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) AuthenticationContextModules(io.cdap.cdap.security.auth.context.AuthenticationContextModules) InMemoryTxSystemClient(org.apache.tephra.inmemory.InMemoryTxSystemClient) DatasetTypeManager(io.cdap.cdap.data2.datafabric.dataset.type.DatasetTypeManager) Singleton(com.google.inject.Singleton) TransactionManager(org.apache.tephra.TransactionManager) TransactionRunner(io.cdap.cdap.spi.data.transaction.TransactionRunner) NoOpMetadataServiceClient(io.cdap.cdap.data2.metadata.writer.NoOpMetadataServiceClient) CommonNettyHttpServiceFactory(io.cdap.cdap.common.http.CommonNettyHttpServiceFactory) AuthorizationEnforcementModule(io.cdap.cdap.security.authorization.AuthorizationEnforcementModule) DelegatingTransactionSystemClientService(io.cdap.cdap.data2.transaction.DelegatingTransactionSystemClientService) RemoteClientFactory(io.cdap.cdap.common.internal.remote.RemoteClientFactory) InMemoryDiscoveryModule(io.cdap.cdap.common.guice.InMemoryDiscoveryModule) StorageModule(io.cdap.cdap.data.runtime.StorageModule) ConfigModule(io.cdap.cdap.common.guice.ConfigModule) StructuredTableAdmin(io.cdap.cdap.spi.data.StructuredTableAdmin) DiscoveryExploreClient(io.cdap.cdap.explore.client.DiscoveryExploreClient) SystemDatasetInstantiatorFactory(io.cdap.cdap.data.dataset.SystemDatasetInstantiatorFactory) DatasetInstanceService(io.cdap.cdap.data2.datafabric.dataset.service.DatasetInstanceService) AccessEnforcer(io.cdap.cdap.security.spi.authorization.AccessEnforcer) TransactionSystemClientService(io.cdap.cdap.data2.transaction.TransactionSystemClientService) DelegatingTransactionSystemClientService(io.cdap.cdap.data2.transaction.DelegatingTransactionSystemClientService) DiscoveryService(org.apache.twill.discovery.DiscoveryService) DatasetAdminService(io.cdap.cdap.data2.datafabric.dataset.service.executor.DatasetAdminService) DatasetOpExecutor(io.cdap.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutor) RemoteDatasetOpExecutor(io.cdap.cdap.data2.datafabric.dataset.service.executor.RemoteDatasetOpExecutor) AuthorizationDatasetTypeService(io.cdap.cdap.data2.datafabric.dataset.service.AuthorizationDatasetTypeService) DefaultImpersonator(io.cdap.cdap.security.impersonation.DefaultImpersonator) Impersonator(io.cdap.cdap.security.impersonation.Impersonator) DefaultImpersonator(io.cdap.cdap.security.impersonation.DefaultImpersonator) AuthorizationTestModule(io.cdap.cdap.security.authorization.AuthorizationTestModule) AbstractModule(com.google.inject.AbstractModule) DatasetOpExecutorService(io.cdap.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutorService) DefaultDatasetTypeService(io.cdap.cdap.data2.datafabric.dataset.service.DefaultDatasetTypeService) RemoteDatasetOpExecutor(io.cdap.cdap.data2.datafabric.dataset.service.executor.RemoteDatasetOpExecutor) RandomEndpointStrategy(io.cdap.cdap.common.discovery.RandomEndpointStrategy) Before(org.junit.Before)

Example 35 with RandomEndpointStrategy

use of io.cdap.cdap.common.discovery.RandomEndpointStrategy in project cdap by caskdata.

the class SupportBundleTestBase method getClientConfig.

private static ClientConfig getClientConfig(DiscoveryServiceClient discoveryClient, String service) {
    EndpointStrategy endpointStrategy = new RandomEndpointStrategy(() -> discoveryClient.discover(service));
    Discoverable discoverable = endpointStrategy.pick(1, TimeUnit.SECONDS);
    Assert.assertNotNull(discoverable);
    ConnectionConfig connectionConfig = ConnectionConfig.builder().setHostname(discoverable.getSocketAddress().getHostName()).setPort(discoverable.getSocketAddress().getPort()).setSSLEnabled(URIScheme.HTTPS.isMatch(discoverable)).build();
    return ClientConfig.builder().setVerifySSLCert(false).setConnectionConfig(connectionConfig).build();
}
Also used : Discoverable(org.apache.twill.discovery.Discoverable) RandomEndpointStrategy(io.cdap.cdap.common.discovery.RandomEndpointStrategy) EndpointStrategy(io.cdap.cdap.common.discovery.EndpointStrategy) ConnectionConfig(io.cdap.cdap.client.config.ConnectionConfig) RandomEndpointStrategy(io.cdap.cdap.common.discovery.RandomEndpointStrategy)

Aggregations

RandomEndpointStrategy (io.cdap.cdap.common.discovery.RandomEndpointStrategy)66 Discoverable (org.apache.twill.discovery.Discoverable)38 DiscoveryServiceClient (org.apache.twill.discovery.DiscoveryServiceClient)38 EndpointStrategy (io.cdap.cdap.common.discovery.EndpointStrategy)26 Test (org.junit.Test)22 Injector (com.google.inject.Injector)20 MetricsCollectionService (io.cdap.cdap.api.metrics.MetricsCollectionService)12 DefaultHttpRequestConfig (io.cdap.cdap.common.http.DefaultHttpRequestConfig)12 DatasetService (io.cdap.cdap.data2.datafabric.dataset.service.DatasetService)12 StructuredTableAdmin (io.cdap.cdap.spi.data.StructuredTableAdmin)12 InetSocketAddress (java.net.InetSocketAddress)12 TransactionManager (org.apache.tephra.TransactionManager)12 ConnectionConfig (io.cdap.cdap.client.config.ConnectionConfig)10 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)10 DatasetOpExecutorService (io.cdap.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutorService)10 URL (java.net.URL)10 Service (com.google.common.util.concurrent.Service)8 AbstractModule (com.google.inject.AbstractModule)8 ConfigModule (io.cdap.cdap.common.guice.ConfigModule)8 InMemoryDiscoveryModule (io.cdap.cdap.common.guice.InMemoryDiscoveryModule)8