Search in sources :

Example 51 with ArtifactSummary

use of co.cask.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).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) ProgramId(co.cask.cdap.proto.id.ProgramId) ArtifactId(co.cask.cdap.proto.id.ArtifactId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) Id(co.cask.cdap.common.id.Id) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ConfigTestApp(co.cask.cdap.ConfigTestApp) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 52 with ArtifactSummary

use of co.cask.cdap.api.artifact.ArtifactSummary 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) ProgramId(co.cask.cdap.proto.id.ProgramId) ArtifactId(co.cask.cdap.proto.id.ArtifactId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) Id(co.cask.cdap.common.id.Id) ConfigTestApp(co.cask.cdap.ConfigTestApp) AppRequest(co.cask.cdap.proto.artifact.AppRequest) Test(org.junit.Test)

Example 53 with ArtifactSummary

use of co.cask.cdap.api.artifact.ArtifactSummary 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());
}
Also used : ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) Config(co.cask.cdap.api.Config) HttpResponse(org.apache.http.HttpResponse) NamespaceId(co.cask.cdap.proto.id.NamespaceId) ProgramId(co.cask.cdap.proto.id.ProgramId) ArtifactId(co.cask.cdap.proto.id.ArtifactId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) Id(co.cask.cdap.common.id.Id) AppRequest(co.cask.cdap.proto.artifact.AppRequest) Test(org.junit.Test)

Example 54 with ArtifactSummary

use of co.cask.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.

the class ArtifactHttpHandlerTest method testAddAndGet.

@Test
public void testAddAndGet() throws Exception {
    File wordCountArtifact = buildAppArtifact(WordCountApp.class, "wordcount.jar");
    File configTestArtifact = buildAppArtifact(ConfigTestApp.class, "cfgtest.jar");
    // add 2 versions of the same app that doesn't use config
    ArtifactId wordcountId1 = NamespaceId.DEFAULT.artifact("wordcount", "1.0.0");
    ArtifactId wordcountId2 = NamespaceId.DEFAULT.artifact("wordcount", "2.0.0");
    Assert.assertEquals(HttpResponseStatus.OK.code(), addArtifact(Id.Artifact.fromEntityId(wordcountId1), Files.newInputStreamSupplier(wordCountArtifact), null).getStatusLine().getStatusCode());
    Assert.assertEquals(HttpResponseStatus.OK.code(), addArtifact(Id.Artifact.fromEntityId(wordcountId2), Files.newInputStreamSupplier(wordCountArtifact), null).getStatusLine().getStatusCode());
    // and 1 version of another app that uses a config
    ArtifactId configTestAppId = NamespaceId.DEFAULT.artifact("cfgtest", "1.0.0");
    Assert.assertEquals(HttpResponseStatus.OK.code(), addArtifact(Id.Artifact.fromEntityId(configTestAppId), Files.newInputStreamSupplier(configTestArtifact), null).getStatusLine().getStatusCode());
    // test get /artifacts endpoint
    Set<ArtifactSummary> expectedArtifacts = Sets.newHashSet(new ArtifactSummary("wordcount", "1.0.0"), new ArtifactSummary("wordcount", "2.0.0"), new ArtifactSummary("cfgtest", "1.0.0"));
    Set<ArtifactSummary> actualArtifacts = getArtifacts(NamespaceId.DEFAULT);
    Assert.assertEquals(expectedArtifacts, actualArtifacts);
    // test get /artifacts/wordcount endpoint
    expectedArtifacts = Sets.newHashSet(new ArtifactSummary("wordcount", "1.0.0"), new ArtifactSummary("wordcount", "2.0.0"));
    actualArtifacts = getArtifacts(NamespaceId.DEFAULT, "wordcount");
    Assert.assertEquals(expectedArtifacts, actualArtifacts);
    // test get /artifacts/cfgtest/versions/1.0.0 endpoint
    Schema appConfigSchema = schemaGenerator.generate(ConfigTestApp.ConfigClass.class);
    ArtifactInfo actualInfo = getArtifact(configTestAppId);
    Assert.assertEquals("cfgtest", actualInfo.getName());
    Assert.assertEquals("1.0.0", actualInfo.getVersion());
    ApplicationClass appClass = new ApplicationClass(ConfigTestApp.class.getName(), "", appConfigSchema);
    Assert.assertTrue(actualInfo.getClasses().getApps().contains(appClass));
}
Also used : ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) ArtifactId(co.cask.cdap.proto.id.ArtifactId) ArtifactInfo(co.cask.cdap.api.artifact.ArtifactInfo) Schema(co.cask.cdap.api.data.schema.Schema) ApplicationClass(co.cask.cdap.api.artifact.ApplicationClass) File(java.io.File) ConfigTestApp(co.cask.cdap.ConfigTestApp) Test(org.junit.Test)

Example 55 with ArtifactSummary

use of co.cask.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.

the class ArtifactHttpHandlerTest method testSystemArtifacts.

@Test
public void testSystemArtifacts() throws Exception {
    // add the app in the default namespace
    File systemArtifact = buildAppArtifact(WordCountApp.class, "wordcount-1.0.0.jar");
    ArtifactId defaultId = NamespaceId.DEFAULT.artifact("wordcount", "1.0.0");
    Assert.assertEquals(HttpResponseStatus.OK.code(), addArtifact(Id.Artifact.fromEntityId(defaultId), Files.newInputStreamSupplier(systemArtifact), null).getStatusLine().getStatusCode());
    // add system artifact
    addSystemArtifacts();
    // test get /artifacts
    Set<ArtifactSummary> expectedArtifacts = Sets.newHashSet(new ArtifactSummary("wordcount", "1.0.0", ArtifactScope.USER), new ArtifactSummary("wordcount", "1.0.0", ArtifactScope.SYSTEM));
    Set<ArtifactSummary> actualArtifacts = getArtifacts(NamespaceId.DEFAULT);
    Assert.assertEquals(expectedArtifacts, actualArtifacts);
    // test get /artifacts?scope=system
    expectedArtifacts = Sets.newHashSet(new ArtifactSummary("wordcount", "1.0.0", ArtifactScope.SYSTEM));
    actualArtifacts = getArtifacts(NamespaceId.DEFAULT, ArtifactScope.SYSTEM);
    Assert.assertEquals(expectedArtifacts, actualArtifacts);
    // test get /artifacts?scope=user
    expectedArtifacts = Sets.newHashSet(new ArtifactSummary("wordcount", "1.0.0", ArtifactScope.USER));
    actualArtifacts = getArtifacts(NamespaceId.DEFAULT, ArtifactScope.USER);
    Assert.assertEquals(expectedArtifacts, actualArtifacts);
    // test get /artifacts/wordcount?scope=user
    expectedArtifacts = Sets.newHashSet(new ArtifactSummary("wordcount", "1.0.0", ArtifactScope.USER));
    actualArtifacts = getArtifacts(NamespaceId.DEFAULT, "wordcount", ArtifactScope.USER);
    Assert.assertEquals(expectedArtifacts, actualArtifacts);
    // test get /artifacts/wordcount?scope=system
    expectedArtifacts = Sets.newHashSet(new ArtifactSummary("wordcount", "1.0.0", ArtifactScope.SYSTEM));
    actualArtifacts = getArtifacts(NamespaceId.DEFAULT, "wordcount", ArtifactScope.SYSTEM);
    Assert.assertEquals(expectedArtifacts, actualArtifacts);
    // test get /artifacts/wordcount/versions/1.0.0?scope=user
    ArtifactInfo actualInfo = getArtifact(defaultId, ArtifactScope.USER);
    Assert.assertEquals("wordcount", actualInfo.getName());
    Assert.assertEquals("1.0.0", actualInfo.getVersion());
    // test get /artifacts/wordcount/versions/1.0.0?scope=system
    actualInfo = getArtifact(defaultId, ArtifactScope.SYSTEM);
    Assert.assertEquals("wordcount", actualInfo.getName());
    Assert.assertEquals("1.0.0", actualInfo.getVersion());
    try {
        ArtifactId systemId = NamespaceId.SYSTEM.artifact("wordcount", "1.0.0");
        artifactRepository.addArtifact(Id.Artifact.fromEntityId(systemId), systemArtifact, new HashSet<ArtifactRange>(), null);
        Assert.fail();
    } catch (Exception e) {
    // no-op - expected exception while adding artifact in system namespace
    }
    cleanupSystemArtifactsDirectory();
}
Also used : ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) ArtifactId(co.cask.cdap.proto.id.ArtifactId) ArtifactInfo(co.cask.cdap.api.artifact.ArtifactInfo) ArtifactRange(co.cask.cdap.api.artifact.ArtifactRange) File(java.io.File) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) NotFoundException(co.cask.cdap.common.NotFoundException) Test(org.junit.Test)

Aggregations

ArtifactSummary (co.cask.cdap.api.artifact.ArtifactSummary)64 Test (org.junit.Test)33 ApplicationId (co.cask.cdap.proto.id.ApplicationId)32 AppRequest (co.cask.cdap.proto.artifact.AppRequest)31 ArtifactId (co.cask.cdap.proto.id.ArtifactId)25 NamespaceId (co.cask.cdap.proto.id.NamespaceId)17 Id (co.cask.cdap.common.id.Id)13 IOException (java.io.IOException)13 ProgramId (co.cask.cdap.proto.id.ProgramId)12 HashMap (java.util.HashMap)10 ArtifactVersion (co.cask.cdap.api.artifact.ArtifactVersion)9 NotFoundException (co.cask.cdap.common.NotFoundException)8 HashSet (java.util.HashSet)8 PluginInfo (co.cask.cdap.proto.artifact.PluginInfo)7 Map (java.util.Map)7 Set (java.util.Set)7 JsonObject (com.google.gson.JsonObject)6 URL (java.net.URL)6 ConfigTestApp (co.cask.cdap.ConfigTestApp)5 ArtifactRange (co.cask.cdap.api.artifact.ArtifactRange)5