Search in sources :

Example 1 with RandomEndpointStrategy

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

the class LogHttpHandlerTest method doGet.

/**
 * Performs a get call on the given path from the log query server.
 */
private HttpResponse doGet(String path) throws IOException {
    Discoverable discoverable = new RandomEndpointStrategy(() -> discoveryServiceClient.discover(Constants.Service.LOG_QUERY)).pick(10, TimeUnit.SECONDS);
    Assert.assertNotNull(discoverable);
    // Path is literal, hence replacing the "%" with "%%" for formatter
    URL url = URIScheme.createURI(discoverable, path.replace("%", "%%")).toURL();
    return HttpRequests.execute(HttpRequest.get(url).build(), new DefaultHttpRequestConfig(false));
}
Also used : Discoverable(org.apache.twill.discovery.Discoverable) DefaultHttpRequestConfig(io.cdap.cdap.common.http.DefaultHttpRequestConfig) URL(java.net.URL) RandomEndpointStrategy(io.cdap.cdap.common.discovery.RandomEndpointStrategy)

Example 2 with RandomEndpointStrategy

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

the class HiveExploreServiceTestRun method exploreDriverTest.

@Test
public void exploreDriverTest() throws Exception {
    // Register explore jdbc driver
    Class.forName(ExploreDriver.class.getName());
    DiscoveryServiceClient discoveryServiceClient = injector.getInstance(DiscoveryServiceClient.class);
    Discoverable discoverable = new RandomEndpointStrategy(() -> discoveryServiceClient.discover(Constants.Service.EXPLORE_HTTP_USER_SERVICE)).pick();
    Assert.assertNotNull(discoverable);
    InetSocketAddress addr = discoverable.getSocketAddress();
    Map<String, String> params = new HashMap<>();
    params.put(ExploreConnectionParams.Info.NAMESPACE.getName(), NAMESPACE_ID.getNamespace());
    params.put(ExploreConnectionParams.Info.SSL_ENABLED.getName(), Boolean.toString(URIScheme.HTTPS.isMatch(discoverable)));
    params.put(ExploreConnectionParams.Info.VERIFY_SSL_CERT.getName(), Boolean.toString(false));
    String serviceUrl = String.format("%s%s:%d?%s", Constants.Explore.Jdbc.URL_PREFIX, addr.getHostName(), addr.getPort(), Joiner.on('&').withKeyValueSeparator("=").join(params));
    Connection connection = DriverManager.getConnection(serviceUrl);
    PreparedStatement stmt;
    ResultSet rowSet;
    stmt = connection.prepareStatement("show tables");
    rowSet = stmt.executeQuery();
    Assert.assertTrue(rowSet.next());
    Assert.assertEquals(MY_TABLE_NAME, rowSet.getString(1));
    stmt.close();
    stmt = connection.prepareStatement("select key, value from " + MY_TABLE_NAME);
    rowSet = stmt.executeQuery();
    Assert.assertTrue(rowSet.next());
    Assert.assertEquals(1, rowSet.getInt(1));
    Assert.assertEquals("{\"name\":\"first\",\"ints\":[1,2,3,4,5]}", rowSet.getString(2));
    Assert.assertTrue(rowSet.next());
    Assert.assertEquals(2, rowSet.getInt(1));
    Assert.assertEquals("{\"name\":\"two\",\"ints\":[10,11,12,13,14]}", rowSet.getString(2));
    stmt.close();
    connection.close();
}
Also used : ExploreDriver(io.cdap.cdap.explore.jdbc.ExploreDriver) Discoverable(org.apache.twill.discovery.Discoverable) DiscoveryServiceClient(org.apache.twill.discovery.DiscoveryServiceClient) HashMap(java.util.HashMap) InetSocketAddress(java.net.InetSocketAddress) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) RandomEndpointStrategy(io.cdap.cdap.common.discovery.RandomEndpointStrategy) Test(org.junit.Test)

Example 3 with RandomEndpointStrategy

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

the class RemoteExecutionDiscoveryServiceTest method testAppDisabled.

@Test
public void testAppDisabled() {
    CConfiguration cConf = CConfiguration.create();
    RemoteExecutionDiscoveryService discoveryService = new RemoteExecutionDiscoveryService(cConf, RuntimeMonitorType.SSH);
    // Discovery of app is disabled. It always return a ServiceDiscovered without endpoint in it
    String name = ServiceDiscoverable.getName(NamespaceId.DEFAULT.app("test").service("service"));
    Discoverable discoverable = new RandomEndpointStrategy(() -> discoveryService.discover(name)).pick(1, TimeUnit.SECONDS);
    Assert.assertNull(discoverable);
}
Also used : Discoverable(org.apache.twill.discovery.Discoverable) ServiceDiscoverable(io.cdap.cdap.common.service.ServiceDiscoverable) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) RandomEndpointStrategy(io.cdap.cdap.common.discovery.RandomEndpointStrategy) Test(org.junit.Test)

Example 4 with RandomEndpointStrategy

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

the class AbstractMasterServiceManager method isServiceAvailable.

@Override
public boolean isServiceAvailable() {
    // Try to ping the endpoint. If any one of them is available, we treat the service as available.
    ServiceDiscovered serviceDiscovered = discoveryClient.discover(serviceName);
    // Block to wait for some endpoint to be available. This is just to compensate initialization.
    // Calls after the first discovery will return immediately.
    new RandomEndpointStrategy(() -> serviceDiscovered).pick(serviceTimeoutSeconds, TimeUnit.SECONDS);
    return StreamSupport.stream(serviceDiscovered.spliterator(), false).anyMatch(this::isEndpointAlive);
}
Also used : ServiceDiscovered(org.apache.twill.discovery.ServiceDiscovered) RandomEndpointStrategy(io.cdap.cdap.common.discovery.RandomEndpointStrategy)

Example 5 with RandomEndpointStrategy

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

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)

Aggregations

RandomEndpointStrategy (io.cdap.cdap.common.discovery.RandomEndpointStrategy)31 Discoverable (org.apache.twill.discovery.Discoverable)17 DiscoveryServiceClient (org.apache.twill.discovery.DiscoveryServiceClient)17 EndpointStrategy (io.cdap.cdap.common.discovery.EndpointStrategy)13 Test (org.junit.Test)11 Injector (com.google.inject.Injector)10 MetricsCollectionService (io.cdap.cdap.api.metrics.MetricsCollectionService)6 DatasetService (io.cdap.cdap.data2.datafabric.dataset.service.DatasetService)6 InetSocketAddress (java.net.InetSocketAddress)6 ConnectionConfig (io.cdap.cdap.client.config.ConnectionConfig)5 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)5 DatasetOpExecutorService (io.cdap.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutorService)5 StructuredTableAdmin (io.cdap.cdap.spi.data.StructuredTableAdmin)5 TransactionManager (org.apache.tephra.TransactionManager)5 Service (com.google.common.util.concurrent.Service)4 AbstractModule (com.google.inject.AbstractModule)4 ConfigModule (io.cdap.cdap.common.guice.ConfigModule)4 InMemoryDiscoveryModule (io.cdap.cdap.common.guice.InMemoryDiscoveryModule)4 MetadataClient (io.cdap.cdap.client.MetadataClient)3 SConfiguration (io.cdap.cdap.common.conf.SConfiguration)3