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);
}
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());
}
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());
}
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);
}
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);
}
Aggregations