Search in sources :

Example 61 with ArtifactId

use of co.cask.cdap.proto.id.ArtifactId in project cdap by caskdata.

the class HydratorTestBase method setupRealtimeArtifacts.

protected static void setupRealtimeArtifacts(ArtifactId artifactId, Class<?> appClass) throws Exception {
    addAppArtifact(artifactId, appClass, RealtimeSource.class.getPackage().getName(), PipelineConfigurable.class.getPackage().getName());
    addPluginArtifact(new ArtifactId(artifactId.getNamespace(), artifactId.getArtifact() + "-mocks", "1.0.0"), artifactId, REALTIME_MOCK_PLUGINS, MockSink.class, MockSource.class, LookupSource.class, DoubleTransform.class, AllErrorTransform.class, IdentityTransform.class, IntValueFilterTransform.class, StringValueFilterTransform.class);
}
Also used : ArtifactId(co.cask.cdap.proto.id.ArtifactId)

Example 62 with ArtifactId

use of co.cask.cdap.proto.id.ArtifactId in project cdap by caskdata.

the class AppLifecycleHttpHandlerTest method testDeployUsingArtifact.

@Test
public void testDeployUsingArtifact() throws Exception {
    Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.DEFAULT, "configapp", "1.0.0");
    addAppArtifact(artifactId, ConfigTestApp.class);
    Id.Application appId = Id.Application.from(Id.Namespace.DEFAULT, "cfgApp");
    ConfigTestApp.ConfigClass config = new ConfigTestApp.ConfigClass("abc", "def");
    AppRequest<ConfigTestApp.ConfigClass> request = new AppRequest<>(new ArtifactSummary(artifactId.getName(), artifactId.getVersion().getVersion()), config);
    Assert.assertEquals(200, deploy(appId, request).getStatusLine().getStatusCode());
    JsonObject appDetails = getAppDetails(Id.Namespace.DEFAULT.getId(), appId.getId());
    Assert.assertEquals(GSON.toJson(config), appDetails.get("configuration").getAsString());
    Assert.assertEquals(200, doDelete(getVersionedAPIPath("apps/" + appId.getId(), appId.getNamespaceId())).getStatusLine().getStatusCode());
}
Also used : ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) JsonObject(com.google.gson.JsonObject) NamespaceId(co.cask.cdap.proto.id.NamespaceId) Id(co.cask.cdap.proto.Id) ProgramId(co.cask.cdap.proto.id.ProgramId) ArtifactId(co.cask.cdap.proto.id.ArtifactId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ConfigTestApp(co.cask.cdap.ConfigTestApp) AppRequest(co.cask.cdap.proto.artifact.AppRequest) Test(org.junit.Test)

Example 63 with ArtifactId

use of co.cask.cdap.proto.id.ArtifactId in project cdap by caskdata.

the class AppLifecycleHttpHandlerTest method testOwnerUsingArtifact.

@Test
public void testOwnerUsingArtifact() throws Exception {
    ArtifactId artifactId = new ArtifactId(NamespaceId.DEFAULT.getNamespace(), "wordCountArtifact", "1.0.0");
    addAppArtifact(artifactId.toId(), WordCountApp.class);
    ApplicationId applicationId = new ApplicationId(NamespaceId.DEFAULT.getNamespace(), "WordCountApp");
    // deploy an app with a owner
    String ownerPrincipal = "alice/somehost.net@somekdc.net";
    AppRequest<ConfigTestApp.ConfigClass> appRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()), null, ownerPrincipal);
    Assert.assertEquals(HttpResponseCodes.SC_OK, deploy(applicationId, appRequest).getStatusLine().getStatusCode());
    // should be able to retrieve the owner information of the app
    JsonObject appDetails = getAppDetails(NamespaceId.DEFAULT.getNamespace(), applicationId.getApplication());
    Assert.assertEquals(ownerPrincipal, appDetails.get(Constants.Security.PRINCIPAL).getAsString());
    // the stream created by the app should have the app owner too
    Assert.assertEquals(ownerPrincipal, getStreamConfig(applicationId.getNamespaceId().stream("text")).getOwnerPrincipal());
    // the dataset created by the app should have the app owner too
    Assert.assertEquals(ownerPrincipal, getDatasetMeta(applicationId.getNamespaceId().dataset("mydataset")).getOwnerPrincipal());
    // trying to deploy the same app with another owner should fail
    String bobPrincipal = "bob/somehost.net@somekdc.net";
    appRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()), null, bobPrincipal);
    Assert.assertEquals(HttpResponseCodes.SC_FORBIDDEN, deploy(applicationId, appRequest).getStatusLine().getStatusCode());
    // trying to deploy the same app with different version and another owner should fail too
    appRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()), null, bobPrincipal);
    Assert.assertEquals(HttpResponseCodes.SC_FORBIDDEN, deploy(new ApplicationId(applicationId.getNamespace(), applicationId.getApplication(), "1.0"), appRequest).getStatusLine().getStatusCode());
    // trying to re-deploy the same app with same owner should pass
    appRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()), null, ownerPrincipal);
    Assert.assertEquals(HttpResponseCodes.SC_OK, deploy(applicationId, appRequest).getStatusLine().getStatusCode());
    // trying to re-deploy the same app with different version but same owner should pass
    appRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()), null, ownerPrincipal);
    Assert.assertEquals(HttpResponseCodes.SC_OK, deploy(new ApplicationId(applicationId.getNamespace(), applicationId.getApplication(), "1.0"), appRequest).getStatusLine().getStatusCode());
    // clean up the app
    Assert.assertEquals(200, doDelete(getVersionedAPIPath("apps/" + applicationId.getApplication(), applicationId.getNamespace())).getStatusLine().getStatusCode());
    // deletion of app should delete the stream/dataset owner information as they themselves are not deleted
    Assert.assertEquals(ownerPrincipal, getStreamConfig(applicationId.getNamespaceId().stream("text")).getOwnerPrincipal());
    Assert.assertEquals(ownerPrincipal, getDatasetMeta(applicationId.getNamespaceId().dataset("mydataset")).getOwnerPrincipal());
    // cleanup
    deleteNamespace(NamespaceId.DEFAULT.getNamespace());
}
Also used : ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) ArtifactId(co.cask.cdap.proto.id.ArtifactId) JsonObject(com.google.gson.JsonObject) ApplicationId(co.cask.cdap.proto.id.ApplicationId) AppRequest(co.cask.cdap.proto.artifact.AppRequest) Test(org.junit.Test)

Example 64 with ArtifactId

use of co.cask.cdap.proto.id.ArtifactId in project cdap by caskdata.

the class AppLifecycleHttpHandlerTest method testDeployWithExtraConfig.

@Test
public void testDeployWithExtraConfig() throws Exception {
    Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.DEFAULT, "extraConfig", "1.0.0-SNAPSHOT");
    Id.Application appId = Id.Application.from(Id.Namespace.DEFAULT, "ExtraConfigApp");
    HttpResponse response = addAppArtifact(artifactId, AppWithNoServices.class);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    response = deploy(appId, new AppRequest<>(ArtifactSummary.from(artifactId.toArtifactId()), new ExtraConfig()));
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    deleteApp(appId, 200);
    deleteArtifact(artifactId, 200);
}
Also used : HttpResponse(org.apache.http.HttpResponse) NamespaceId(co.cask.cdap.proto.id.NamespaceId) Id(co.cask.cdap.proto.Id) ProgramId(co.cask.cdap.proto.id.ProgramId) ArtifactId(co.cask.cdap.proto.id.ArtifactId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) AppRequest(co.cask.cdap.proto.artifact.AppRequest) Test(org.junit.Test)

Example 65 with ArtifactId

use of co.cask.cdap.proto.id.ArtifactId in project cdap by caskdata.

the class AppLifecycleHttpHandlerTest method testDeployVersionedAndNonVersionedApp.

@Test
public void testDeployVersionedAndNonVersionedApp() throws Exception {
    Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.DEFAULT, "configapp", "1.0.0");
    addAppArtifact(artifactId, ConfigTestApp.class);
    ApplicationId appId = new ApplicationId(Id.Namespace.DEFAULT.getId(), "cfgAppWithVersion", "1.0.0");
    ConfigTestApp.ConfigClass config = new ConfigTestApp.ConfigClass("abc", "def");
    AppRequest<ConfigTestApp.ConfigClass> request = new AppRequest<>(new ArtifactSummary(artifactId.getName(), artifactId.getVersion().getVersion()), config);
    Assert.assertEquals(200, deploy(appId, request).getStatusLine().getStatusCode());
    // Cannot update the app created by versioned API with versionId not ending with "-SNAPSHOT"
    Assert.assertEquals(409, deploy(appId, request).getStatusLine().getStatusCode());
    Assert.assertEquals(404, getAppResponse(Id.Namespace.DEFAULT.getId(), appId.getApplication(), "non_existing_version").getStatusLine().getStatusCode());
    Assert.assertEquals(404, getAppResponse(Id.Namespace.DEFAULT.getId(), appId.getApplication()).getStatusLine().getStatusCode());
    // Deploy app with default versionId by non-versioned API
    Id.Application appIdDefault = Id.Application.from(Id.Namespace.DEFAULT, appId.getApplication());
    ConfigTestApp.ConfigClass configDefault = new ConfigTestApp.ConfigClass("uvw", "xyz");
    AppRequest<ConfigTestApp.ConfigClass> requestDefault = new AppRequest<>(new ArtifactSummary(artifactId.getName(), artifactId.getVersion().getVersion()), configDefault);
    Assert.assertEquals(200, deploy(appIdDefault, requestDefault).getStatusLine().getStatusCode());
    // Deploy app with versionId "version_2" by versioned API
    ApplicationId appIdV2 = new ApplicationId(appId.getNamespace(), appId.getApplication(), "2.0.0");
    ConfigTestApp.ConfigClass configV2 = new ConfigTestApp.ConfigClass("ghi", "jkl");
    AppRequest<ConfigTestApp.ConfigClass> requestV2 = new AppRequest<>(new ArtifactSummary(artifactId.getName(), artifactId.getVersion().getVersion()), configV2);
    Assert.assertEquals(200, deploy(appIdV2, requestV2).getStatusLine().getStatusCode());
    Set<String> versions = ImmutableSet.of("-SNAPSHOT", "2.0.0", "1.0.0");
    Assert.assertEquals(versions, getAppVersions(appId.getNamespace(), appId.getApplication()));
    List<JsonObject> appList = getAppList(appId.getNamespace());
    Set<String> receivedVersions = new HashSet<>();
    for (JsonObject appRecord : appList) {
        receivedVersions.add(appRecord.getAsJsonPrimitive("version").getAsString());
    }
    Assert.assertEquals(versions, receivedVersions);
    JsonObject appDetails = getAppDetails(appId.getNamespace(), appId.getApplication(), appId.getVersion());
    Assert.assertEquals(GSON.toJson(config), appDetails.get("configuration").getAsString());
    Assert.assertEquals(appId.getVersion(), appDetails.get("appVersion").getAsString());
    // Get app info for the app with default versionId by versioned API
    JsonObject appDetailsDefault = getAppDetails(appId.getNamespace(), appId.getApplication(), ApplicationId.DEFAULT_VERSION);
    Assert.assertEquals(GSON.toJson(configDefault), appDetailsDefault.get("configuration").getAsString());
    Assert.assertEquals(ApplicationId.DEFAULT_VERSION, appDetailsDefault.get("appVersion").getAsString());
    // Get app info for the app with versionId "version_2" by versioned API
    JsonObject appDetailsV2 = getAppDetails(appId.getNamespace(), appId.getApplication(), appIdV2.getVersion());
    Assert.assertEquals(GSON.toJson(configV2), appDetailsV2.get("configuration").getAsString());
    // Update app with default versionId by versioned API
    ConfigTestApp.ConfigClass configDefault2 = new ConfigTestApp.ConfigClass("mno", "pqr");
    AppRequest<ConfigTestApp.ConfigClass> requestDefault2 = new AppRequest<>(new ArtifactSummary(artifactId.getName(), artifactId.getVersion().getVersion()), configDefault2);
    Assert.assertEquals(200, deploy(appIdDefault.toEntityId(), requestDefault2).getStatusLine().getStatusCode());
    JsonObject appDetailsDefault2 = getAppDetails(appIdDefault.getNamespaceId(), appIdDefault.getId());
    Assert.assertEquals(GSON.toJson(configDefault2), appDetailsDefault2.get("configuration").getAsString());
    // Get updated app info for the app with default versionId by versioned API
    JsonObject appDetailsDefault2WithVersion = getAppDetails(appIdDefault.getNamespaceId(), appIdDefault.getId(), ApplicationId.DEFAULT_VERSION);
    Assert.assertEquals(GSON.toJson(configDefault2), appDetailsDefault2WithVersion.get("configuration").getAsString());
    Assert.assertEquals(ApplicationId.DEFAULT_VERSION, appDetailsDefault.get("appVersion").getAsString());
    deleteApp(appId, 200);
    deleteApp(appIdDefault, 200);
    deleteApp(appIdV2, 200);
}
Also used : JsonObject(com.google.gson.JsonObject) AppRequest(co.cask.cdap.proto.artifact.AppRequest) ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) NamespaceId(co.cask.cdap.proto.id.NamespaceId) Id(co.cask.cdap.proto.Id) ProgramId(co.cask.cdap.proto.id.ProgramId) ArtifactId(co.cask.cdap.proto.id.ArtifactId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ConfigTestApp(co.cask.cdap.ConfigTestApp) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ArtifactId (co.cask.cdap.proto.id.ArtifactId)82 Test (org.junit.Test)35 NamespaceId (co.cask.cdap.proto.id.NamespaceId)31 Id (co.cask.cdap.proto.Id)24 IOException (java.io.IOException)24 Path (javax.ws.rs.Path)24 ApplicationId (co.cask.cdap.proto.id.ApplicationId)23 ArtifactSummary (co.cask.cdap.api.artifact.ArtifactSummary)16 ProgramId (co.cask.cdap.proto.id.ProgramId)16 AppRequest (co.cask.cdap.proto.artifact.AppRequest)13 PluginClass (co.cask.cdap.api.plugin.PluginClass)11 ArtifactNotFoundException (co.cask.cdap.common.ArtifactNotFoundException)11 File (java.io.File)10 ArtifactVersion (co.cask.cdap.api.artifact.ArtifactVersion)9 ArtifactDetail (co.cask.cdap.internal.app.runtime.artifact.ArtifactDetail)8 DELETE (javax.ws.rs.DELETE)8 GET (javax.ws.rs.GET)8 ArtifactRange (co.cask.cdap.api.artifact.ArtifactRange)7 BadRequestException (co.cask.cdap.common.BadRequestException)7 AuditPolicy (co.cask.cdap.common.security.AuditPolicy)6