use of io.cdap.cdap.common.discovery.RandomEndpointStrategy in project cdap by caskdata.
the class SupportBundleHttpHandlerTest method requestExportBundle.
/**
* Requests zip and download support bundle.
*
* @param bundleId String
* @return HTTPResponse
* @throws IOException if failed to request bundle download
*/
private HttpResponse requestExportBundle(String bundleId) throws IOException {
DiscoveryServiceClient discoveryServiceClient = getInjector().getInstance(DiscoveryServiceClient.class);
Discoverable discoverable = new RandomEndpointStrategy(() -> discoveryServiceClient.discover(Constants.Service.SUPPORT_BUNDLE_SERVICE)).pick(5, TimeUnit.SECONDS);
Assert.assertNotNull("No service for support bundle", discoverable);
String path = String.format("%s/support/bundles/%s", Constants.Gateway.API_VERSION_3, bundleId);
HttpRequest request = HttpRequest.post(URIScheme.createURI(discoverable, path).toURL()).build();
return HttpRequests.execute(request, new DefaultHttpRequestConfig(false));
}
use of io.cdap.cdap.common.discovery.RandomEndpointStrategy in project cdap by cdapio.
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));
}
use of io.cdap.cdap.common.discovery.RandomEndpointStrategy in project cdap by cdapio.
the class MetricsSuiteTestBase method startMetricsService.
public static Injector startMetricsService(CConfiguration conf) throws Exception {
Injector injector = Guice.createInjector(Modules.override(new ConfigModule(conf), RemoteAuthenticatorModules.getNoOpModule(), new NonCustomLocationUnitTestModule(), new InMemoryDiscoveryModule(), new MetricsHandlerModule(), new MetricsClientRuntimeModule().getInMemoryModules(), new DataFabricModules().getInMemoryModules(), new DataSetsModules().getStandaloneModules(), new DataSetServiceModules().getInMemoryModules(), new ExploreClientModule(), new NamespaceAdminTestModule(), new AuthorizationTestModule(), new AuthorizationEnforcementModule().getInMemoryModules(), new AuthenticationContextModules().getMasterModule()).with(new AbstractModule() {
@Override
protected void configure() {
bind(Store.class).to(DefaultStore.class);
bind(UGIProvider.class).to(UnsupportedUGIProvider.class);
bind(OwnerAdmin.class).to(NoOpOwnerAdmin.class);
// TODO (CDAP-14677): find a better way to inject metadata publisher
bind(MetadataServiceClient.class).to(NoOpMetadataServiceClient.class);
}
}));
transactionManager = injector.getInstance(TransactionManager.class);
transactionManager.startAndWait();
StoreDefinition.createAllTables(injector.getInstance(StructuredTableAdmin.class));
dsOpService = injector.getInstance(DatasetOpExecutorService.class);
dsOpService.startAndWait();
datasetService = injector.getInstance(DatasetService.class);
datasetService.startAndWait();
metrics = injector.getInstance(MetricsQueryService.class);
metrics.startAndWait();
collectionService = injector.getInstance(MetricsCollectionService.class);
collectionService.startAndWait();
// initialize the dataset instantiator
DiscoveryServiceClient discoveryClient = injector.getInstance(DiscoveryServiceClient.class);
EndpointStrategy metricsEndPoints = new RandomEndpointStrategy(() -> discoveryClient.discover(Constants.Service.METRICS));
discoverable = metricsEndPoints.pick(1L, TimeUnit.SECONDS);
Assert.assertNotNull("Could not discover metrics service", discoverable);
return injector;
}
use of io.cdap.cdap.common.discovery.RandomEndpointStrategy in project cdap by cdapio.
the class NettyRouterTestBase method testConnectionClose2.
@Test
public void testConnectionClose2() throws Exception {
// turn off retry on POST request
String oldValue = System.getProperty("sun.net.http.retryPost");
System.setProperty("sun.net.http.retryPost", "false");
try {
URL url = new URL(resolveURI("/v1/sleep"));
// Disable the server 2 from discovery
defaultServer2.cancelRegistration();
HttpURLConnection urlConn = openURL(url);
urlConn.setDoOutput(true);
urlConn.setRequestMethod("POST");
// Sleep for 50 ms
urlConn.getOutputStream().write("50".getBytes(StandardCharsets.UTF_8));
Assert.assertEquals(200, urlConn.getResponseCode());
urlConn.getInputStream().close();
urlConn.disconnect();
// Now disable server1 and enable server2 from discovery
defaultServer1.cancelRegistration();
defaultServer2.registerServer();
// Make sure the discovery change is in effect
Assert.assertNotNull(new RandomEndpointStrategy(() -> ((DiscoveryServiceClient) discoveryService).discover(APP_FABRIC_SERVICE)).pick(5, TimeUnit.SECONDS));
// Make a call to sleep for couple seconds
urlConn = openURL(url);
urlConn.setDoOutput(true);
urlConn.setRequestMethod("POST");
urlConn.getOutputStream().write("3000".getBytes(StandardCharsets.UTF_8));
// Wait for the result asynchronously, while at the same time shutdown server1.
// Shutting down server1 shouldn't affect the connection.
CompletableFuture<Integer> result = new CompletableFuture<>();
HttpURLConnection finalUrlConn = urlConn;
Thread t = new Thread(() -> {
try {
result.complete(finalUrlConn.getResponseCode());
} catch (Exception e) {
result.completeExceptionally(e);
} finally {
try {
finalUrlConn.getInputStream().close();
finalUrlConn.disconnect();
} catch (IOException e) {
LOG.error("Exception when closing url connection", e);
}
}
});
t.start();
defaultServer1.stopAndWait();
Assert.assertEquals(200, result.get().intValue());
Assert.assertEquals(1, defaultServer1.getNumRequests());
Assert.assertEquals(1, defaultServer2.getNumRequests());
} finally {
if (oldValue == null) {
System.clearProperty("sun.net.http.retryPost");
} else {
System.setProperty("sun.net.http.retryPost", oldValue);
}
}
}
use of io.cdap.cdap.common.discovery.RandomEndpointStrategy in project cdap by cdapio.
the class AuthenticationServiceMainTest method testBasicAuthenticationEnabled.
@Test
public void testBasicAuthenticationEnabled() throws IOException {
HttpResponse response = HttpRequests.execute(HttpRequest.get(getAuthenticationBaseURI().toURL()).build(), new HttpRequestConfig(0, 0, false));
Assert.assertEquals("basic realm=\"null\"", response.getHeaders().get("WWW-Authenticate").stream().findFirst().orElse(null));
Assert.assertEquals(HttpURLConnection.HTTP_UNAUTHORIZED, response.getResponseCode());
Injector injector = getServiceMainInstance(AuthenticationServiceMain.class).getInjector();
DiscoveryServiceClient discoveryServiceClient = injector.getInstance(DiscoveryServiceClient.class);
Discoverable authenticationEndpoint = new RandomEndpointStrategy(() -> discoveryServiceClient.discover(Service.EXTERNAL_AUTHENTICATION)).pick(5, TimeUnit.SECONDS);
Assert.assertNotNull(authenticationEndpoint);
}
Aggregations