use of io.cdap.common.http.HttpRequestConfig in project cdap by caskdata.
the class AppFabricServiceMainTest method testAppFabricService.
@Test
public void testAppFabricService() throws Exception {
// Query the system services endpoint
URL url = getRouterBaseURI().resolve("/v3/system/services").toURL();
HttpResponse response = HttpRequests.execute(HttpRequest.get(url).build(), new DefaultHttpRequestConfig(false));
Assert.assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
// Deploy an app
LocationFactory locationFactory = new LocalLocationFactory(TEMP_FOLDER.newFolder());
Location deploymentJar = AppJarHelper.createDeploymentJar(locationFactory, AllProgramsApp.class);
URI baseURI = getRouterBaseURI().resolve("/v3/namespaces/default/");
url = baseURI.resolve("apps").toURL();
HttpRequestConfig requestConfig = new HttpRequestConfig(0, 0, false);
response = HttpRequests.execute(HttpRequest.post(url).withBody((ContentProvider<? extends InputStream>) deploymentJar::getInputStream).addHeader("X-Archive-Name", AllProgramsApp.class.getSimpleName() + "-1.0-SNAPSHOT.jar").build(), requestConfig);
Assert.assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
// Get the application
url = baseURI.resolve("apps/" + AllProgramsApp.NAME).toURL();
response = HttpRequests.execute(HttpRequest.get(url).build(), requestConfig);
Assert.assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
ApplicationDetail appDetail = new Gson().fromJson(response.getResponseBodyAsString(), ApplicationDetail.class);
// Do some basic validation only.
Assert.assertEquals(AllProgramsApp.NAME, appDetail.getName());
Assert.assertTrue(appDetail.getPrograms().stream().filter(r -> r.getType() == ProgramType.WORKFLOW).anyMatch(r -> AllProgramsApp.NoOpWorkflow.NAME.equals(r.getName())));
}
use of io.cdap.common.http.HttpRequestConfig in project cdap by caskdata.
the class AppFabricTestBase method initializeAndStartServices.
protected static void initializeAndStartServices(CConfiguration cConf, Module overrides) throws Exception {
injector = Guice.createInjector(Modules.override(new AppFabricTestModule(cConf, null)).with(overrides));
int connectionTimeout = cConf.getInt(Constants.HTTP_CLIENT_CONNECTION_TIMEOUT_MS);
int readTimeout = cConf.getInt(Constants.HTTP_CLIENT_READ_TIMEOUT_MS);
httpRequestConfig = new HttpRequestConfig(connectionTimeout, readTimeout, false);
messagingService = injector.getInstance(MessagingService.class);
if (messagingService instanceof Service) {
((Service) messagingService).startAndWait();
}
txManager = injector.getInstance(TransactionManager.class);
txManager.startAndWait();
// Define all StructuredTable before starting any services that need StructuredTable
StoreDefinition.createAllTables(injector.getInstance(StructuredTableAdmin.class));
metadataStorage = injector.getInstance(MetadataStorage.class);
metadataStorage.createIndex();
dsOpService = injector.getInstance(DatasetOpExecutorService.class);
dsOpService.startAndWait();
datasetService = injector.getInstance(DatasetService.class);
datasetService.startAndWait();
appFabricServer = injector.getInstance(AppFabricServer.class);
appFabricServer.startAndWait();
DiscoveryServiceClient discoveryClient = injector.getInstance(DiscoveryServiceClient.class);
appFabricEndpointStrategy = new RandomEndpointStrategy(() -> discoveryClient.discover(Constants.Service.APP_FABRIC_HTTP));
txClient = injector.getInstance(TransactionSystemClient.class);
metricsCollectionService = injector.getInstance(MetricsCollectionService.class);
metricsCollectionService.startAndWait();
serviceStore = injector.getInstance(ServiceStore.class);
serviceStore.startAndWait();
metadataService = injector.getInstance(MetadataService.class);
metadataService.startAndWait();
metadataSubscriberService = injector.getInstance(MetadataSubscriberService.class);
metadataSubscriberService.startAndWait();
logQueryService = injector.getInstance(LogQueryService.class);
logQueryService.startAndWait();
locationFactory = getInjector().getInstance(LocationFactory.class);
datasetClient = new DatasetClient(getClientConfig(discoveryClient, Constants.Service.DATASET_MANAGER));
remoteClientFactory = new RemoteClientFactory(discoveryClient, new DefaultInternalAuthenticator(new AuthenticationTestContext()));
metadataClient = new MetadataClient(getClientConfig(discoveryClient, Constants.Service.METADATA_SERVICE));
metadataServiceClient = new DefaultMetadataServiceClient(remoteClientFactory);
metricStore = injector.getInstance(MetricStore.class);
Scheduler programScheduler = injector.getInstance(Scheduler.class);
// Wait for the scheduler to be functional.
if (programScheduler instanceof CoreSchedulerService) {
try {
((CoreSchedulerService) programScheduler).waitUntilFunctional(10, TimeUnit.SECONDS);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
createNamespaces();
}
use of io.cdap.common.http.HttpRequestConfig in project cdap by caskdata.
the class ArtifactCacheTest method testArtifactCache.
@Test
public void testArtifactCache() throws Exception {
LocationFactory locationFactory = getInjector().getInstance(LocationFactory.class);
ArtifactRepository artifactRepository = getInjector().getInstance(ArtifactRepository.class);
Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.DEFAULT, "some-task", "1.0.0-SNAPSHOT");
Location appJar = AppJarHelper.createDeploymentJar(locationFactory, TaskWorkerServiceTest.TestRunnableClass.class);
File appJarFile = new File(tmpFolder.newFolder(), String.format("%s-%s.jar", artifactId.getName(), artifactId.getVersion().getVersion()));
Locations.linkOrCopy(appJar, appJarFile);
artifactRepository.addArtifact(artifactId, appJarFile);
CConfiguration cConf = CConfiguration.create();
String cacheDir = tmpFolder.toString();
cConf.set(Constants.ArtifactCache.LOCAL_DATA_DIR, cacheDir);
TetheringStore store = getInjector().getInstance(TetheringStore.class);
ArtifactCache cache = new ArtifactCache(cConf);
// Add a couple of tethered peers
addPeer(store, "peer1");
addPeer(store, "peer2");
RemoteClientFactory factory = new RemoteClientFactory(new NoOpDiscoveryServiceClient(getEndPoint("").toString()), new NoOpInternalAuthenticator());
HttpRequestConfig config = new DefaultHttpRequestConfig(true);
RemoteClient remoteClient = factory.createRemoteClient("", config, Constants.Gateway.INTERNAL_API_VERSION_3);
// Get artifact from first peer
File peer1ArtifactPath = cache.getArtifact(artifactId.toEntityId(), "peer1", remoteClient);
// Get the artifact again. The same path was returned
Assert.assertEquals(peer1ArtifactPath, cache.getArtifact(artifactId.toEntityId(), "peer1", remoteClient));
// Get artifact from another peer. It should be cached in a different path
File peer2ArtifactPath = cache.getArtifact(artifactId.toEntityId(), "peer2", remoteClient);
Assert.assertNotEquals(peer1ArtifactPath, peer2ArtifactPath);
// Delete and recreate the artifact to update the last modified date
artifactRepository.deleteArtifact(artifactId);
// This sleep is needed to delay the file copy so that the lastModified time on the file is different
Thread.sleep(1000);
artifactRepository.addArtifact(artifactId, appJarFile);
// Artifact should be cached in a different path
File newPeer1ArtifactPath = cache.getArtifact(artifactId.toEntityId(), "peer1", remoteClient);
Assert.assertNotEquals(peer1ArtifactPath, newPeer1ArtifactPath);
// Run the artifact cleaner
ArtifactLocalizerCleaner cleaner = new ArtifactLocalizerCleaner(Paths.get(cacheDir).resolve("peers"), 1);
cleaner.run();
// Older artifact should been deleted
Assert.assertFalse(peer1ArtifactPath.exists());
// Latest artifact should still be cached
Assert.assertTrue(newPeer1ArtifactPath.exists());
}
use of io.cdap.common.http.HttpRequestConfig in project cdap by caskdata.
the class SpillableBodyConsumerTest method testPost.
private void testPost(String body, int bufferLimit) throws Exception {
NettyHttpService httpService = NettyHttpService.builder("test").setHttpHandlers(new TestHandler(bufferLimit)).build();
httpService.start();
try {
InetSocketAddress addr = httpService.getBindAddress();
URL url = new URL(String.format("http://%s:%d/post", addr.getHostName(), addr.getPort()));
HttpResponse response = HttpRequests.execute(io.cdap.common.http.HttpRequest.post(url).withBody(body).build(), new HttpRequestConfig(1000, 10000000));
Assert.assertEquals(200, response.getResponseCode());
Assert.assertEquals(body, response.getResponseBodyAsString());
} finally {
httpService.stop();
}
}
use of io.cdap.common.http.HttpRequestConfig in project cdap by caskdata.
the class SupportBundleTestBase method initializeAndStartServices.
protected static void initializeAndStartServices(CConfiguration cConf, Module overrides) throws Exception {
injector = Guice.createInjector(Modules.override(new AppFabricTestModule(cConf, null)).with(overrides));
int connectionTimeout = cConf.getInt(Constants.HTTP_CLIENT_CONNECTION_TIMEOUT_MS);
int readTimeout = cConf.getInt(Constants.HTTP_CLIENT_READ_TIMEOUT_MS);
httpRequestConfig = new HttpRequestConfig(connectionTimeout, readTimeout, false);
messagingService = injector.getInstance(MessagingService.class);
if (messagingService instanceof Service) {
((Service) messagingService).startAndWait();
}
txManager = injector.getInstance(TransactionManager.class);
txManager.startAndWait();
// Define all StructuredTable before starting any services that need StructuredTable
StoreDefinition.createAllTables(injector.getInstance(StructuredTableAdmin.class));
metadataStorage = injector.getInstance(MetadataStorage.class);
metadataStorage.createIndex();
dsOpService = injector.getInstance(DatasetOpExecutorService.class);
dsOpService.startAndWait();
datasetService = injector.getInstance(DatasetService.class);
datasetService.startAndWait();
appFabricServer = injector.getInstance(AppFabricServer.class);
appFabricServer.startAndWait();
DiscoveryServiceClient discoveryClient = injector.getInstance(DiscoveryServiceClient.class);
appFabricEndpointStrategy = new RandomEndpointStrategy(() -> discoveryClient.discover(Constants.Service.APP_FABRIC_HTTP));
metricsCollectionService = injector.getInstance(MetricsCollectionService.class);
metricsCollectionService.startAndWait();
serviceStore = injector.getInstance(ServiceStore.class);
serviceStore.startAndWait();
metadataService = injector.getInstance(MetadataService.class);
metadataService.startAndWait();
metadataSubscriberService = injector.getInstance(MetadataSubscriberService.class);
metadataSubscriberService.startAndWait();
logQueryService = injector.getInstance(LogQueryService.class);
logQueryService.startAndWait();
locationFactory = getInjector().getInstance(LocationFactory.class);
datasetClient = new DatasetClient(getClientConfig(discoveryClient, Constants.Service.DATASET_MANAGER));
remoteClientFactory = new RemoteClientFactory(discoveryClient, new DefaultInternalAuthenticator(new AuthenticationTestContext()));
metadataClient = new MetadataClient(getClientConfig(discoveryClient, Constants.Service.METADATA_SERVICE));
appFabricHealthCheckService = injector.getInstance(HealthCheckService.class);
appFabricHealthCheckService.helper(Constants.AppFabricHealthCheck.APP_FABRIC_HEALTH_CHECK_SERVICE, cConf, Constants.Service.MASTER_SERVICES_BIND_ADDRESS);
appFabricHealthCheckService.startAndWait();
supportBundleInternalService = injector.getInstance(SupportBundleInternalService.class);
supportBundleInternalService.startAndWait();
Scheduler programScheduler = injector.getInstance(Scheduler.class);
// Wait for the scheduler to be functional.
if (programScheduler instanceof CoreSchedulerService) {
try {
((CoreSchedulerService) programScheduler).waitUntilFunctional(10, TimeUnit.SECONDS);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
Aggregations