use of io.cdap.cdap.client.config.ConnectionConfig in project cdap by caskdata.
the class MetadataServiceMainTest method testMetadataService.
@Test
public void testMetadataService() throws Exception {
Injector injector = getServiceMainInstance(MetadataServiceMain.class).getInjector();
DatasetId datasetId = NamespaceId.DEFAULT.dataset("testds");
// Create a dataset, a metadata should get published.
DatasetFramework datasetFramework = injector.getInstance(DatasetFramework.class);
long beforeCreation = System.currentTimeMillis();
datasetFramework.addInstance(KeyValueTable.class.getName(), datasetId, DatasetProperties.EMPTY);
// Query the metadata
DiscoveryServiceClient discoveryServiceClient = injector.getInstance(DiscoveryServiceClient.class);
Discoverable metadataEndpoint = new RandomEndpointStrategy(() -> discoveryServiceClient.discover(Constants.Service.METADATA_SERVICE)).pick(5, TimeUnit.SECONDS);
Assert.assertNotNull(metadataEndpoint);
// Try to query the metadata
InetSocketAddress metadataAddr = metadataEndpoint.getSocketAddress();
ConnectionConfig connConfig = ConnectionConfig.builder().setSSLEnabled(URIScheme.HTTPS.isMatch(metadataEndpoint)).setHostname(metadataAddr.getHostName()).setPort(metadataAddr.getPort()).build();
MetadataClient metadataClient = new MetadataClient(ClientConfig.builder().setVerifySSLCert(false).setConnectionConfig(connConfig).build());
MetadataSearchResponse response = metadataClient.searchMetadata(datasetId.getNamespaceId(), "*", (String) null);
Set<MetadataSearchResultRecord> results = response.getResults();
Assert.assertFalse(results.isEmpty());
long creationTime = results.stream().filter(r -> datasetId.equals(r.getEntityId())).map(MetadataSearchResultRecord::getMetadata).map(metadata -> metadata.get(MetadataScope.SYSTEM).getProperties().get(MetadataConstants.CREATION_TIME_KEY)).map(Long::parseLong).findFirst().orElse(-1L);
// The creation time should be between the beforeCreation time and the current time
Assert.assertTrue(creationTime >= beforeCreation);
Assert.assertTrue(creationTime <= System.currentTimeMillis());
}
use of io.cdap.cdap.client.config.ConnectionConfig in project cdap by caskdata.
the class UpgradeJobMain method main.
public static void main(String[] args) {
if (args.length != 2) {
throw new RuntimeException(String.format("Invalid number of arguments to UpgradeJobMain. Needed 2, found %d", args.length));
}
// TODO(CDAP-18299): Refactor to use internal service discovery mechanism instead of making calls via the router.
ConnectionConfig connectionConfig = ConnectionConfig.builder().setHostname(args[0]).setPort(Integer.parseInt(args[1])).setSSLEnabled(false).build();
ClientConfig.Builder clientConfigBuilder = ClientConfig.builder().setDefaultReadTimeout(DEFAULT_READ_TIMEOUT_MILLIS).setConnectionConfig(connectionConfig);
// If used in proxy mode, attach a user ID header to upgrade jobs.
CConfiguration cConf = CConfiguration.create();
if (SecurityUtil.isProxySecurity(cConf)) {
String proxyUserID = cConf.get(Constants.Security.Authentication.PROXY_USER_ID_HEADER);
if (proxyUserID == null) {
throw new RuntimeException("Invalid proxy user ID header");
}
clientConfigBuilder.addAdditionalHeader(proxyUserID, UpgradeUserIDProvider.getUserID());
}
ClientConfig clientConfig = clientConfigBuilder.build();
RetryStrategy retryStrategy = RetryStrategies.timeLimit(120, TimeUnit.SECONDS, RetryStrategies.exponentialDelay(500, 5000, TimeUnit.MILLISECONDS));
try {
Retries.callWithRetries(() -> {
suspendSchedulesAndStopPipelines(clientConfig);
return null;
}, retryStrategy, e -> e instanceof IOException || e instanceof NotFoundException);
} catch (Exception e) {
throw new RuntimeException("Failed to prepare instance for upgrade.", e);
}
}
use of io.cdap.cdap.client.config.ConnectionConfig in project cdap by caskdata.
the class MetricsServiceMainTest method testMetricsService.
@Test
public void testMetricsService() throws Exception {
Injector injector = getServiceMainInstance(MetricsServiceMain.class).getInjector();
// make sure the metrics clean up service is running
MetricsCleanUpService service = injector.getInstance(MetricsCleanUpService.class);
Assert.assertTrue(service.isRunning());
// Publish some metrics via the MetricsCollectionService
MetricsCollectionService metricsCollectionService = injector.getInstance(MetricsCollectionService.class);
MetricsContext context = metricsCollectionService.getContext(ImmutableMap.of(Constants.Metrics.Tag.NAMESPACE, NamespaceId.SYSTEM.getNamespace(), Constants.Metrics.Tag.APP, "test"));
context.increment("name", 10);
// Discovery the location of metrics query service
DiscoveryServiceClient discoveryServiceClient = injector.getInstance(DiscoveryServiceClient.class);
Discoverable metricsEndpoint = new RandomEndpointStrategy(() -> discoveryServiceClient.discover(Constants.Service.METRICS)).pick(5, TimeUnit.SECONDS);
Assert.assertNotNull(metricsEndpoint);
// Try to query the metrics
InetSocketAddress metricsAddr = metricsEndpoint.getSocketAddress();
ConnectionConfig connConfig = ConnectionConfig.builder().setSSLEnabled(URIScheme.HTTPS.isMatch(metricsEndpoint)).setHostname(metricsAddr.getHostName()).setPort(metricsAddr.getPort()).build();
MetricsClient metricsClient = new MetricsClient(ClientConfig.builder().setVerifySSLCert(false).setConnectionConfig(connConfig).build());
// Need to poll because metrics processing is async.
Tasks.waitFor(10L, () -> {
MetricQueryResult result = metricsClient.query(context.getTags(), "system.name");
MetricQueryResult.TimeSeries[] series = result.getSeries();
if (series.length == 0) {
return 0L;
}
return series[0].getData()[0].getValue();
}, 10, TimeUnit.SECONDS, 1, TimeUnit.SECONDS);
MetricsSystemClient metricsSystemClient = injector.getInstance(RemoteMetricsSystemClient.class);
metricsSystemClient.delete(new MetricDeleteQuery(0, Integer.MAX_VALUE, Collections.emptySet(), context.getTags(), new ArrayList<>(context.getTags().keySet())));
Tasks.waitFor(0L, () -> {
MetricQueryResult result = metricsClient.query(context.getTags(), "system.name");
MetricQueryResult.TimeSeries[] series = result.getSeries();
if (series.length == 0) {
return 0L;
}
return series[0].getData()[0].getValue();
}, 10, TimeUnit.SECONDS, 1, TimeUnit.SECONDS);
}
use of io.cdap.cdap.client.config.ConnectionConfig in project cdap by caskdata.
the class AbstractClientTest method setUp.
@Before
public void setUp() throws Throwable {
StandaloneTester standalone = getStandaloneTester();
ConnectionConfig connectionConfig = InstanceURIParser.DEFAULT.parse(standalone.getBaseURI().toString());
clientConfig = new ClientConfig.Builder().setVerifySSLCert(false).setDefaultReadTimeout(60 * 1000).setUploadReadTimeout(120 * 1000).setConnectionConfig(connectionConfig).build();
}
use of io.cdap.cdap.client.config.ConnectionConfig in project cdap by caskdata.
the class QueryClientTest method setUp.
@Before
public void setUp() throws Throwable {
super.setUp();
appClient = new ApplicationClient(clientConfig);
queryClient = new QueryClient(clientConfig);
programClient = new ProgramClient(clientConfig);
serviceClient = new ServiceClient(clientConfig);
String accessToken = (clientConfig.getAccessToken() == null) ? null : clientConfig.getAccessToken().getValue();
ConnectionConfig connectionConfig = clientConfig.getConnectionConfig();
exploreClient = new FixedAddressExploreClient(connectionConfig.getHostname(), connectionConfig.getPort(), accessToken, connectionConfig.isSSLEnabled(), clientConfig.isVerifySSLCert());
namespaceClient = new NamespaceClient(clientConfig);
}
Aggregations