use of co.cask.cdap.proto.artifact.AppRequest in project cdap by caskdata.
the class TestFrameworkTestRun method testInvalidAppWithDuplicateDatasets.
@Test
public void testInvalidAppWithDuplicateDatasets() throws Exception {
ArtifactId artifactId = NamespaceId.DEFAULT.artifact("invalid-app", "1.0.0-SNAPSHOT");
addAppArtifact(artifactId, AppWithDuplicateData.class);
ArtifactId pluginArtifactId = NamespaceId.DEFAULT.artifact("test-plugin", "1.0.0-SNAPSHOT");
addPluginArtifact(pluginArtifactId, artifactId, ToStringPlugin.class);
ApplicationId appId = NamespaceId.DEFAULT.app("InvalidApp");
for (int choice = 4; choice > 0; choice /= 2) {
try {
AppRequest<AppWithDuplicateData.ConfigClass> createRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()), new AppWithDuplicateData.ConfigClass((choice == 4), (choice == 2), (choice == 1)));
deployApplication(appId, createRequest);
// fail if we succeed with application deployment
Assert.fail();
} catch (Exception e) {
// expected
}
}
AppRequest<AppWithDuplicateData.ConfigClass> createRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()), new AppWithDuplicateData.ConfigClass(false, false, false));
deployApplication(appId, createRequest);
}
use of co.cask.cdap.proto.artifact.AppRequest in project cdap by caskdata.
the class PreviewHttpHandler method start.
@POST
@Path("/previews")
public void start(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId) throws Exception {
NamespaceId namespace = new NamespaceId(namespaceId);
AppRequest appRequest;
try (Reader reader = new InputStreamReader(new ChannelBufferInputStream(request.getContent()), Charsets.UTF_8)) {
appRequest = GSON.fromJson(reader, AppRequest.class);
} catch (JsonSyntaxException e) {
throw new BadRequestException("Request body is invalid json: " + e.getMessage());
}
responder.sendString(HttpResponseStatus.OK, GSON.toJson(previewManager.start(namespace, appRequest)));
}
use of co.cask.cdap.proto.artifact.AppRequest 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.artifact.AppRequest 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.artifact.AppRequest in project cdap by caskdata.
the class AppLifecycleHttpHandlerTest method testDeployUsingNonexistantArtifact404.
@Test
public void testDeployUsingNonexistantArtifact404() throws Exception {
Id.Application appId = Id.Application.from(Id.Namespace.DEFAULT, "badapp");
AppRequest<Config> appRequest = new AppRequest<>(new ArtifactSummary("something", "1.0.0"), null);
HttpResponse response = deploy(appId, appRequest);
Assert.assertEquals(404, response.getStatusLine().getStatusCode());
}
Aggregations