use of io.cdap.cdap.api.artifact.ArtifactSummary 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).getResponseCode());
// Cannot update the app created by versioned API with versionId not ending with "-SNAPSHOT"
Assert.assertEquals(409, deploy(appId, request).getResponseCode());
Assert.assertEquals(404, getAppResponse(Id.Namespace.DEFAULT.getId(), appId.getApplication(), "non_existing_version").getResponseCode());
Assert.assertEquals(404, getAppResponse(Id.Namespace.DEFAULT.getId(), appId.getApplication()).getResponseCode());
// 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).getResponseCode());
// 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).getResponseCode());
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).getResponseCode());
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);
}
use of io.cdap.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.
the class AppLifecycleHttpHandlerTest method testDelete.
/**
* Tests deleting applications with versioned and non-versioned API.
*/
@Test
public void testDelete() throws Exception {
// Delete an non-existing app
HttpResponse response = doDelete(getVersionedAPIPath("apps/XYZ", Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1));
Assert.assertEquals(404, response.getResponseCode());
// Start a service from the App
deploy(AllProgramsApp.class, 200, Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1);
Id.Program program = Id.Program.from(TEST_NAMESPACE1, AllProgramsApp.NAME, ProgramType.SERVICE, AllProgramsApp.NoOpService.NAME);
startProgram(program);
waitState(program, "RUNNING");
// Try to delete an App while its service is running
response = doDelete(getVersionedAPIPath("apps/" + AllProgramsApp.NAME, Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1));
Assert.assertEquals(409, response.getResponseCode());
Assert.assertEquals("'" + program.getApplication() + "' could not be deleted. Reason: The following programs are still running: " + program.getId(), response.getResponseBodyAsString());
stopProgram(program);
waitState(program, "STOPPED");
startProgram(program);
waitState(program, "RUNNING");
// Try to delete all Apps while service is running
response = doDelete(getVersionedAPIPath("apps", Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1));
Assert.assertEquals(409, response.getResponseCode());
Assert.assertEquals("'" + program.getNamespace() + "' could not be deleted. Reason: The following programs are still running: " + program.getApplicationId() + ": " + program.getId(), response.getResponseBodyAsString());
stopProgram(program);
waitState(program, "STOPPED");
// Delete the app in the wrong namespace
response = doDelete(getVersionedAPIPath("apps/" + AllProgramsApp.NAME, Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE2));
Assert.assertEquals(404, response.getResponseCode());
// Delete an non-existing app with version
response = doDelete(getVersionedAPIPath("apps/XYZ/versions/" + VERSION1, Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1));
Assert.assertEquals(404, response.getResponseCode());
// Deploy an app with version
Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.DEFAULT, AllProgramsApp.class.getSimpleName(), VERSION1);
addAppArtifact(artifactId, AllProgramsApp.class);
AppRequest<? extends Config> appRequest = new AppRequest<>(new ArtifactSummary(artifactId.getName(), artifactId.getVersion().getVersion()));
ApplicationId appId = NamespaceId.DEFAULT.app(AllProgramsApp.NAME, VERSION1);
Assert.assertEquals(200, deploy(appId, appRequest).getResponseCode());
// Start a service for the App
ProgramId program1 = appId.program(ProgramType.SERVICE, AllProgramsApp.NoOpService.NAME);
startProgram(program1, 200);
waitState(program1, "RUNNING");
// Try to delete an App while its service is running
response = doDelete(getVersionedAPIPath(String.format("apps/%s/versions/%s", appId.getApplication(), appId.getVersion()), Constants.Gateway.API_VERSION_3_TOKEN, appId.getNamespace()));
Assert.assertEquals(409, response.getResponseCode());
Assert.assertEquals("'" + program1.getParent() + "' could not be deleted. Reason: The following programs" + " are still running: " + program1.getProgram(), response.getResponseBodyAsString());
stopProgram(program1, null, 200, null);
waitState(program1, "STOPPED");
// Delete the app with version in the wrong namespace
response = doDelete(getVersionedAPIPath(String.format("apps/%s/versions/%s", appId.getApplication(), appId.getVersion()), Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE2));
Assert.assertEquals(404, response.getResponseCode());
// Delete the app with version after stopping the service
response = doDelete(getVersionedAPIPath(String.format("apps/%s/versions/%s", appId.getApplication(), appId.getVersion()), Constants.Gateway.API_VERSION_3_TOKEN, appId.getNamespace()));
Assert.assertEquals(200, response.getResponseCode());
response = doDelete(getVersionedAPIPath(String.format("apps/%s/versions/%s", appId.getApplication(), appId.getVersion()), Constants.Gateway.API_VERSION_3_TOKEN, appId.getNamespace()));
Assert.assertEquals(404, response.getResponseCode());
// Delete the App after stopping the service
response = doDelete(getVersionedAPIPath("apps/" + AllProgramsApp.NAME, Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1));
Assert.assertEquals(200, response.getResponseCode());
response = doDelete(getVersionedAPIPath("apps/" + AllProgramsApp.NAME, Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1));
Assert.assertEquals(404, response.getResponseCode());
// deleting the app should not delete the artifact
response = doGet(getVersionedAPIPath("artifacts/" + artifactId.getName(), Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1));
Assert.assertEquals(200, response.getResponseCode());
List<ArtifactSummary> summaries = readResponse(response, new TypeToken<List<ArtifactSummary>>() {
}.getType());
Assert.assertFalse(summaries.isEmpty());
// cleanup
deleteNamespace(NamespaceId.DEFAULT.getNamespace());
}
use of io.cdap.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.
the class AppLifecycleHttpHandlerTest method testDeployAppWithDisabledProfileInSchedule.
@Test
public void testDeployAppWithDisabledProfileInSchedule() throws Exception {
// put my profile and disable it
ProfileId profileId = new NamespaceId(TEST_NAMESPACE1).profile("MyProfile");
Profile profile = new Profile("MyProfile", Profile.NATIVE.getLabel(), Profile.NATIVE.getDescription(), Profile.NATIVE.getScope(), Profile.NATIVE.getProvisioner());
putProfile(profileId, profile, 200);
disableProfile(profileId, 200);
// deploy an app with schedule with some disabled profile in the schedule property
AppWithSchedule.AppConfig config = new AppWithSchedule.AppConfig(true, true, true, ImmutableMap.of(SystemArguments.PROFILE_NAME, "USER:MyProfile"));
Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.fromEntityId(TEST_NAMESPACE_META1.getNamespaceId()), AppWithSchedule.NAME, VERSION1);
addAppArtifact(artifactId, AppWithSchedule.class);
AppRequest<? extends Config> request = new AppRequest<>(new ArtifactSummary(artifactId.getName(), artifactId.getVersion().getVersion()), config, null, null, true);
// deploy should fail with a 409
ApplicationId defaultAppId = TEST_NAMESPACE_META1.getNamespaceId().app(AppWithSchedule.NAME);
Assert.assertEquals(409, deploy(defaultAppId, request).getResponseCode());
// enable
enableProfile(profileId, 200);
Assert.assertEquals(200, deploy(defaultAppId, request).getResponseCode());
// disable again so that we can delete it at namespace deletion
disableProfile(profileId, 200);
// clean up
deleteApp(defaultAppId, 200);
deleteArtifact(artifactId, 200);
}
use of io.cdap.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.
the class AppLifecycleHttpHandlerTest method testOwnerUsingArtifact.
@Test
public void testOwnerUsingArtifact() throws Exception {
ArtifactId artifactId = new ArtifactId(NamespaceId.DEFAULT.getNamespace(), "artifact", "1.0.0");
addAppArtifact(Id.Artifact.fromEntityId(artifactId), AllProgramsApp.class);
ApplicationId applicationId = new ApplicationId(NamespaceId.DEFAULT.getNamespace(), AllProgramsApp.NAME);
// 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).getResponseCode());
// 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 dataset created by the app should have the app owner too
Assert.assertEquals(ownerPrincipal, getDatasetMeta(applicationId.getNamespaceId().dataset(AllProgramsApp.DATASET_NAME)).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).getResponseCode());
// 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).getResponseCode());
// 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).getResponseCode());
// 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).getResponseCode());
// clean up the app
Assert.assertEquals(200, doDelete(getVersionedAPIPath("apps/" + applicationId.getApplication(), applicationId.getNamespace())).getResponseCode());
// deletion of app should delete the dataset owner information as they themselves are not deleted
Assert.assertEquals(ownerPrincipal, getDatasetMeta(applicationId.getNamespaceId().dataset(AllProgramsApp.DATASET_NAME)).getOwnerPrincipal());
// cleanup
deleteNamespace(NamespaceId.DEFAULT.getNamespace());
}
use of io.cdap.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.
the class AppScheduleUpdateTest method testUpdateSchedulesFlag.
@Test
public void testUpdateSchedulesFlag() throws Exception {
// deploy an app with schedule
AppWithSchedule.AppConfig config = new AppWithSchedule.AppConfig(true, true, true);
Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.fromEntityId(TEST_NAMESPACE_META2.getNamespaceId()), AppWithSchedule.NAME, VERSION1);
addAppArtifact(artifactId, AppWithSchedule.class);
AppRequest<? extends Config> request = new AppRequest<>(new ArtifactSummary(artifactId.getName(), artifactId.getVersion().getVersion()), config);
ApplicationId defaultAppId = TEST_NAMESPACE_META2.getNamespaceId().app(AppWithSchedule.NAME);
Assert.assertEquals(200, deploy(defaultAppId, request).getResponseCode());
List<ScheduleDetail> actualSchSpecs = listSchedules(TEST_NAMESPACE_META2.getNamespaceId().getNamespace(), defaultAppId.getApplication(), defaultAppId.getVersion());
// none of the schedules will be added - by default we have set update schedules to be false as system property.
Assert.assertEquals(0, actualSchSpecs.size());
request = new AppRequest<>(new ArtifactSummary(artifactId.getName(), artifactId.getVersion().getVersion()), config, null, null, true);
Assert.assertEquals(200, deploy(defaultAppId, request).getResponseCode());
actualSchSpecs = listSchedules(TEST_NAMESPACE_META2.getNamespaceId().getNamespace(), defaultAppId.getApplication(), defaultAppId.getVersion());
// both the schedules will be added as now,
// we have provided update schedules property to be true manually in appRequest
Assert.assertEquals(2, actualSchSpecs.size());
config = new AppWithSchedule.AppConfig(true, true, false);
request = new AppRequest<>(new ArtifactSummary(artifactId.getName(), artifactId.getVersion().getVersion()), config);
Assert.assertEquals(200, deploy(defaultAppId, request).getResponseCode());
actualSchSpecs = listSchedules(TEST_NAMESPACE_META2.getNamespaceId().getNamespace(), defaultAppId.getApplication(), defaultAppId.getVersion());
// no changes will be made, as default behavior is dont update schedules, so both the schedules should be there
Assert.assertEquals(2, actualSchSpecs.size());
config = new AppWithSchedule.AppConfig(false, false, false);
request = new AppRequest<>(new ArtifactSummary(artifactId.getName(), artifactId.getVersion().getVersion()), config);
Assert.assertEquals(200, deploy(defaultAppId, request).getResponseCode());
actualSchSpecs = listSchedules(TEST_NAMESPACE_META2.getNamespaceId().getNamespace(), defaultAppId.getApplication(), defaultAppId.getVersion());
// workflow is deleted, so the schedules will be deleted now
Assert.assertEquals(0, actualSchSpecs.size());
}
Aggregations