use of io.cdap.common.ContentProvider in project cdap by caskdata.
the class DatasetServiceTestBase method deployModuleBundled.
// creates a bundled jar with moduleClass and list of bundleEmbeddedJar files, moduleName and moduleClassName are
// used to make request for deploying module.
protected int deployModuleBundled(String moduleName, String moduleClassName, Class moduleClass, Location... bundleEmbeddedJars) throws IOException {
Location moduleJar = createModuleJar(moduleClass, bundleEmbeddedJars);
HttpRequest request = HttpRequest.put(getUrl("/data/modules/" + moduleName)).addHeader("X-Class-Name", moduleClassName).withBody((ContentProvider<? extends InputStream>) moduleJar::getInputStream).build();
return HttpRequests.execute(request, REQUEST_CONFIG).getResponseCode();
}
use of io.cdap.common.ContentProvider in project cdap by caskdata.
the class PreviewServiceMainTest method deployArtifact.
/**
* Deploy the given application in default namespace
*/
private void deployArtifact(Location artifactLocation, String artifactName, String artifactVersion) throws IOException {
HttpRequestConfig requestConfig = getHttpRequestConfig();
URL url = getRouterBaseURI().resolve(String.format("/v3/namespaces/default/artifacts/%s", artifactName)).toURL();
HttpResponse response = HttpRequests.execute(HttpRequest.post(url).withBody((ContentProvider<? extends InputStream>) artifactLocation::getInputStream).addHeader("Artifact-Version", artifactVersion).build(), requestConfig);
Assert.assertEquals(response.getResponseBodyAsString(), HttpURLConnection.HTTP_OK, response.getResponseCode());
}
use of io.cdap.common.ContentProvider in project cdap by caskdata.
the class PreviewServiceMainTest method testPreviewAppWithPlugin.
@Test
public void testPreviewAppWithPlugin() throws Exception {
// Build the app
LocationFactory locationFactory = new LocalLocationFactory(TEMP_FOLDER.newFolder());
Location appJar = AppJarHelper.createDeploymentJar(locationFactory, PreviewTestAppWithPlugin.class);
String appArtifactName = PreviewTestAppWithPlugin.class.getSimpleName() + "_artifact";
String artifactVersion = "1.0.0-SNAPSHOT";
// Deploy the app
deployArtifact(appJar, appArtifactName, artifactVersion);
HttpResponse response;
// Build plugin artifact
Manifest manifest = new Manifest();
manifest.getMainAttributes().put(ManifestFields.EXPORT_PACKAGE, ConstantCallable.class.getPackage().getName());
Location pluginJar = PluginJarHelper.createPluginJar(locationFactory, manifest, ConstantCallable.class);
// Deploy plug artifact
String pluginArtifactName = ConstantCallable.class.getSimpleName() + "_artifact";
URL pluginArtifactUrl = getRouterBaseURI().resolve(String.format("/v3/namespaces/default/artifacts/%s", pluginArtifactName)).toURL();
response = HttpRequests.execute(HttpRequest.post(pluginArtifactUrl).withBody((ContentProvider<? extends InputStream>) pluginJar::getInputStream).addHeader("Artifact-Extends", String.format("%s[1.0.0-SNAPSHOT,10.0.0]", appArtifactName)).addHeader("Artifact-Version", artifactVersion).build(), getHttpRequestConfig());
Assert.assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
// Run a preview
String expectedOutput = "output_value";
ArtifactId appArtifactId = new ArtifactId(appArtifactName, new ArtifactVersion(artifactVersion), ArtifactScope.USER);
ArtifactSummary artifactSummary = ArtifactSummary.from(appArtifactId);
PreviewConfig previewConfig = new PreviewConfig(PreviewTestAppWithPlugin.TestWorkflow.NAME, ProgramType.WORKFLOW, Collections.emptyMap(), 2);
PreviewTestAppWithPlugin.Conf appConf = new PreviewTestAppWithPlugin.Conf(ConstantCallable.NAME, Collections.singletonMap("val", expectedOutput));
AppRequest appRequest = new AppRequest<>(artifactSummary, appConf, previewConfig);
ApplicationId previewId = runPreview(appRequest);
// Wait for preview to complete
waitForPreview(previewId);
// Verify the result of preview run
URL url = getRouterBaseURI().resolve(String.format("/v3/namespaces/default/previews/%s/tracers/%s", previewId.getApplication(), PreviewTestApp.TRACER_NAME)).toURL();
response = HttpRequests.execute(HttpRequest.get(url).build(), getHttpRequestConfig());
Assert.assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
Map<String, List<String>> tracerData = GSON.fromJson(response.getResponseBodyAsString(), new TypeToken<Map<String, List<String>>>() {
}.getType());
Assert.assertEquals(Collections.singletonMap(PreviewTestAppWithPlugin.TRACER_KEY, Collections.singletonList(expectedOutput)), tracerData);
}
use of io.cdap.common.ContentProvider 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.ContentProvider in project cdap by caskdata.
the class DatasetServiceTestBase method deployModule.
protected HttpResponse deployModule(DatasetModuleId module, Class moduleClass, boolean force) throws Exception {
Location moduleJar = createModuleJar(moduleClass);
String urlPath = "/data/modules/" + module.getEntityName();
urlPath = force ? urlPath + "?force=true" : urlPath;
HttpRequest request = HttpRequest.put(getUrl(module.getNamespace(), urlPath)).addHeader("X-Class-Name", moduleClass.getName()).withBody((ContentProvider<? extends InputStream>) moduleJar::getInputStream).build();
return HttpRequests.execute(request, REQUEST_CONFIG);
}
Aggregations