Search in sources :

Example 1 with ContentProvider

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();
}
Also used : HttpRequest(io.cdap.common.http.HttpRequest) ContentProvider(io.cdap.common.ContentProvider) InputStream(java.io.InputStream) Location(org.apache.twill.filesystem.Location)

Example 2 with ContentProvider

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());
}
Also used : ContentProvider(io.cdap.common.ContentProvider) InputStream(java.io.InputStream) HttpResponse(io.cdap.common.http.HttpResponse) HttpRequestConfig(io.cdap.common.http.HttpRequestConfig) URL(java.net.URL)

Example 3 with ContentProvider

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);
}
Also used : ArtifactId(io.cdap.cdap.api.artifact.ArtifactId) ContentProvider(io.cdap.common.ContentProvider) InputStream(java.io.InputStream) PreviewTestAppWithPlugin(io.cdap.cdap.master.environment.app.PreviewTestAppWithPlugin) HttpResponse(io.cdap.common.http.HttpResponse) Manifest(java.util.jar.Manifest) URL(java.net.URL) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) LocationFactory(org.apache.twill.filesystem.LocationFactory) AppRequest(io.cdap.cdap.proto.artifact.AppRequest) ArtifactVersion(io.cdap.cdap.api.artifact.ArtifactVersion) ArtifactSummary(io.cdap.cdap.api.artifact.ArtifactSummary) TypeToken(com.google.common.reflect.TypeToken) ConstantCallable(io.cdap.cdap.master.environment.plugin.ConstantCallable) List(java.util.List) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) PreviewConfig(io.cdap.cdap.proto.artifact.preview.PreviewConfig) Location(org.apache.twill.filesystem.Location) Test(org.junit.Test)

Example 4 with ContentProvider

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())));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) ApplicationDetail(io.cdap.cdap.proto.ApplicationDetail) Location(org.apache.twill.filesystem.Location) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) URL(java.net.URL) HttpResponse(io.cdap.common.http.HttpResponse) Test(org.junit.Test) DefaultHttpRequestConfig(io.cdap.cdap.common.http.DefaultHttpRequestConfig) LocationFactory(org.apache.twill.filesystem.LocationFactory) ProgramType(io.cdap.cdap.proto.ProgramType) HttpRequestConfig(io.cdap.common.http.HttpRequestConfig) AppJarHelper(io.cdap.cdap.common.test.AppJarHelper) Gson(com.google.gson.Gson) ContentProvider(io.cdap.common.ContentProvider) HttpRequests(io.cdap.common.http.HttpRequests) URI(java.net.URI) AllProgramsApp(io.cdap.cdap.AllProgramsApp) Assert(org.junit.Assert) HttpRequest(io.cdap.common.http.HttpRequest) InputStream(java.io.InputStream) ApplicationDetail(io.cdap.cdap.proto.ApplicationDetail) DefaultHttpRequestConfig(io.cdap.cdap.common.http.DefaultHttpRequestConfig) HttpResponse(io.cdap.common.http.HttpResponse) Gson(com.google.gson.Gson) DefaultHttpRequestConfig(io.cdap.cdap.common.http.DefaultHttpRequestConfig) HttpRequestConfig(io.cdap.common.http.HttpRequestConfig) AllProgramsApp(io.cdap.cdap.AllProgramsApp) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) URI(java.net.URI) URL(java.net.URL) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) LocationFactory(org.apache.twill.filesystem.LocationFactory) Location(org.apache.twill.filesystem.Location) Test(org.junit.Test)

Example 5 with ContentProvider

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);
}
Also used : HttpRequest(io.cdap.common.http.HttpRequest) ContentProvider(io.cdap.common.ContentProvider) InputStream(java.io.InputStream) Location(org.apache.twill.filesystem.Location)

Aggregations

ContentProvider (io.cdap.common.ContentProvider)5 InputStream (java.io.InputStream)5 Location (org.apache.twill.filesystem.Location)4 HttpRequest (io.cdap.common.http.HttpRequest)3 HttpResponse (io.cdap.common.http.HttpResponse)3 URL (java.net.URL)3 HttpRequestConfig (io.cdap.common.http.HttpRequestConfig)2 LocalLocationFactory (org.apache.twill.filesystem.LocalLocationFactory)2 LocationFactory (org.apache.twill.filesystem.LocationFactory)2 Test (org.junit.Test)2 TypeToken (com.google.common.reflect.TypeToken)1 Gson (com.google.gson.Gson)1 AllProgramsApp (io.cdap.cdap.AllProgramsApp)1 ArtifactId (io.cdap.cdap.api.artifact.ArtifactId)1 ArtifactSummary (io.cdap.cdap.api.artifact.ArtifactSummary)1 ArtifactVersion (io.cdap.cdap.api.artifact.ArtifactVersion)1 DefaultHttpRequestConfig (io.cdap.cdap.common.http.DefaultHttpRequestConfig)1 AppJarHelper (io.cdap.cdap.common.test.AppJarHelper)1 PreviewTestAppWithPlugin (io.cdap.cdap.master.environment.app.PreviewTestAppWithPlugin)1 ConstantCallable (io.cdap.cdap.master.environment.plugin.ConstantCallable)1