Search in sources :

Example 71 with ArtifactId

use of io.cdap.cdap.proto.id.ArtifactId in project cdap by cdapio.

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.getResponseCode());
    response = deploy(appId, new AppRequest<>(ArtifactSummary.from(artifactId.toArtifactId()), new ExtraConfig()));
    Assert.assertEquals(200, response.getResponseCode());
    deleteApp(appId, 200);
    deleteArtifact(artifactId, 200);
}
Also used : HttpResponse(io.cdap.common.http.HttpResponse) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Id(io.cdap.cdap.common.id.Id) ProfileId(io.cdap.cdap.proto.id.ProfileId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) ProgramId(io.cdap.cdap.proto.id.ProgramId) AppRequest(io.cdap.cdap.proto.artifact.AppRequest) Test(org.junit.Test)

Example 72 with ArtifactId

use of io.cdap.cdap.proto.id.ArtifactId in project cdap by cdapio.

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).getResponseCode());
    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())).getResponseCode());
}
Also used : ArtifactSummary(io.cdap.cdap.api.artifact.ArtifactSummary) JsonObject(com.google.gson.JsonObject) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Id(io.cdap.cdap.common.id.Id) ProfileId(io.cdap.cdap.proto.id.ProfileId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) ProgramId(io.cdap.cdap.proto.id.ProgramId) ConfigTestApp(io.cdap.cdap.ConfigTestApp) AppRequest(io.cdap.cdap.proto.artifact.AppRequest) Test(org.junit.Test)

Example 73 with ArtifactId

use of io.cdap.cdap.proto.id.ArtifactId in project cdap by cdapio.

the class AppLifecycleHttpHandlerTest method testAppWithConfig.

@Test
public void testAppWithConfig() throws Exception {
    Id.Application appId = Id.Application.from(Id.Namespace.DEFAULT, "ConfigApp");
    Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.DEFAULT, "appWithConfig", "1.0.0-SNAPSHOT");
    HttpResponse response = addAppArtifact(artifactId, ConfigTestApp.class);
    Assert.assertEquals(200, response.getResponseCode());
    ConfigTestApp.ConfigClass config = new ConfigTestApp.ConfigClass("abc", "def");
    response = deploy(appId, new AppRequest<>(ArtifactSummary.from(artifactId.toArtifactId()), config));
    Assert.assertEquals(200, response.getResponseCode());
    JsonObject appDetails = getAppDetails(Id.Namespace.DEFAULT.getId(), "ConfigApp");
    Assert.assertEquals(GSON.toJson(config), appDetails.get("configuration").getAsString());
    deleteApp(appId, 200);
    deleteArtifact(artifactId, 200);
}
Also used : HttpResponse(io.cdap.common.http.HttpResponse) JsonObject(com.google.gson.JsonObject) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Id(io.cdap.cdap.common.id.Id) ProfileId(io.cdap.cdap.proto.id.ProfileId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) ProgramId(io.cdap.cdap.proto.id.ProgramId) ConfigTestApp(io.cdap.cdap.ConfigTestApp) AppRequest(io.cdap.cdap.proto.artifact.AppRequest) Test(org.junit.Test)

Example 74 with ArtifactId

use of io.cdap.cdap.proto.id.ArtifactId in project cdap by cdapio.

the class ArtifactHttpHandlerInternalTest method testListArtifacts.

@Test
public void testListArtifacts() throws Exception {
    List<ArtifactInfo> artifactInfoList = null;
    ArtifactInfo artifactInfo = null;
    // Add a system artifact
    String systemArtfiactName = "sysApp";
    String systemArtifactVeresion = "1.0.0";
    ArtifactId systemArtifactId = NamespaceId.SYSTEM.artifact(systemArtfiactName, systemArtifactVeresion);
    addAppAsSystemArtifacts(systemArtifactId);
    // Listing all artifacts in default namespace, should include system artifacts
    artifactInfoList = listArtifactsInternal(NamespaceId.DEFAULT.getNamespace());
    Assert.assertEquals(1, artifactInfoList.size());
    artifactInfo = artifactInfoList.stream().filter(info -> info.getScope().equals(ArtifactScope.SYSTEM)).findAny().orElse(null);
    Assert.assertNotNull(artifactInfo);
    Assert.assertEquals(ArtifactScope.SYSTEM, artifactInfo.getScope());
    Assert.assertEquals(systemArtfiactName, artifactInfo.getName());
    Assert.assertEquals(systemArtifactVeresion, artifactInfo.getVersion());
    Assert.assertTrue(artifactInfo.getClasses().getApps().size() > 0);
    // Add a user artifact, in addition to the above system artifact
    String userArtifactName = "userApp";
    String userArtifactVersion = "2.0.0";
    ArtifactId userArtifactId = NamespaceId.DEFAULT.artifact(userArtifactName, userArtifactVersion);
    addAppAsUserArtifacts(userArtifactId);
    // Listing all artifacts in default namespace, should include both user and system artifacts
    artifactInfoList = listArtifactsInternal(NamespaceId.DEFAULT.getNamespace());
    Assert.assertEquals(2, artifactInfoList.size());
    artifactInfo = artifactInfoList.stream().filter(info -> info.getScope().equals(ArtifactScope.USER)).findAny().orElse(null);
    Assert.assertNotNull(artifactInfo);
    Assert.assertEquals(ArtifactScope.USER, artifactInfo.getScope());
    Assert.assertEquals(userArtifactName, artifactInfo.getName());
    Assert.assertEquals(userArtifactVersion, artifactInfo.getVersion());
    Assert.assertTrue(artifactInfo.getClasses().getApps().size() > 0);
    artifactInfo = artifactInfoList.stream().filter(info -> info.getScope().equals(ArtifactScope.SYSTEM)).findAny().orElse(null);
    Assert.assertNotNull(artifactInfo);
    Assert.assertEquals(ArtifactScope.SYSTEM, artifactInfo.getScope());
    Assert.assertEquals(systemArtfiactName, artifactInfo.getName());
    Assert.assertEquals(systemArtifactVeresion, artifactInfo.getVersion());
    Assert.assertTrue(artifactInfo.getClasses().getApps().size() > 0);
}
Also used : ArtifactRepositoryReader(io.cdap.cdap.internal.app.runtime.artifact.ArtifactRepositoryReader) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ArtifactRange(io.cdap.cdap.api.artifact.ArtifactRange) Test(org.junit.Test) Id(io.cdap.cdap.common.id.Id) ArrayList(java.util.ArrayList) List(java.util.List) ArtifactVersion(io.cdap.cdap.api.artifact.ArtifactVersion) ArtifactSortOrder(io.cdap.cdap.proto.artifact.ArtifactSortOrder) ArtifactInfo(io.cdap.cdap.api.artifact.ArtifactInfo) RemoteArtifactRepositoryReader(io.cdap.cdap.internal.app.runtime.artifact.RemoteArtifactRepositoryReader) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) Assert(org.junit.Assert) ArtifactScope(io.cdap.cdap.api.artifact.ArtifactScope) ArtifactDetail(io.cdap.cdap.internal.app.runtime.artifact.ArtifactDetail) ArtifactInfo(io.cdap.cdap.api.artifact.ArtifactInfo) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) Test(org.junit.Test)

Example 75 with ArtifactId

use of io.cdap.cdap.proto.id.ArtifactId in project cdap by cdapio.

the class ApplicationLifecycleServiceTest method testMissingDependency.

@Test
public void testMissingDependency() throws Exception {
    // tests the fix for CDAP-2543, by having programs which fail to start up due to missing dependency jars
    ArtifactId artifactId = NamespaceId.DEFAULT.artifact("missing-guava-dependency", "1.0.0-SNAPSHOT");
    Location appJar = createDeploymentJar(locationFactory, AppWithProgramsUsingGuava.class);
    File appJarFile = new File(tmpFolder.newFolder(), String.format("%s-%s.jar", artifactId.getArtifact(), artifactId.getVersion()));
    Locations.linkOrCopyOverwrite(appJar, appJarFile);
    appJar.delete();
    applicationLifecycleService.deployAppAndArtifact(NamespaceId.DEFAULT, "appName", Id.Artifact.fromEntityId(artifactId), appJarFile, null, null, new ProgramTerminator() {

        @Override
        public void stop(ProgramId programId) throws Exception {
        // no-op
        }
    }, true);
    ApplicationId appId = NamespaceId.DEFAULT.app("appName");
    // run records for programs that have missing dependencies should be FAILED, instead of hanging in RUNNING
    // fail the Worker#initialize
    ProgramId worker = appId.worker(AppWithProgramsUsingGuava.NoOpWorker.NAME);
    startProgram(Id.Program.fromEntityId(worker));
    waitForRuns(1, worker, ProgramRunStatus.FAILED);
    // fail the MapReduce#initialize
    ProgramId mapreduce = appId.mr(AppWithProgramsUsingGuava.NoOpMR.NAME);
    startProgram(Id.Program.fromEntityId(mapreduce));
    waitForRuns(1, mapreduce, ProgramRunStatus.FAILED);
    // fail the CustomAction#initialize
    ProgramId workflow = appId.workflow(AppWithProgramsUsingGuava.NoOpWorkflow.NAME);
    startProgram(Id.Program.fromEntityId(workflow));
    waitForRuns(1, workflow, ProgramRunStatus.FAILED);
    // fail the Workflow#initialize
    appId.workflow(AppWithProgramsUsingGuava.NoOpWorkflow.NAME);
    startProgram(Id.Program.fromEntityId(workflow), ImmutableMap.of("fail.in.workflow.initialize", "true"));
    waitForRuns(1, workflow, ProgramRunStatus.FAILED);
}
Also used : ArtifactId(io.cdap.cdap.proto.id.ArtifactId) ProgramTerminator(io.cdap.cdap.internal.app.deploy.ProgramTerminator) ProgramId(io.cdap.cdap.proto.id.ProgramId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) File(java.io.File) CapabilityNotAvailableException(io.cdap.cdap.internal.capability.CapabilityNotAvailableException) IOException(java.io.IOException) ArtifactNotFoundException(io.cdap.cdap.common.ArtifactNotFoundException) Location(org.apache.twill.filesystem.Location) Test(org.junit.Test)

Aggregations

ArtifactId (io.cdap.cdap.proto.id.ArtifactId)214 Test (org.junit.Test)118 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)94 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)68 IOException (java.io.IOException)50 ArtifactSummary (io.cdap.cdap.api.artifact.ArtifactSummary)42 ProgramId (io.cdap.cdap.proto.id.ProgramId)42 Id (io.cdap.cdap.common.id.Id)40 AppRequest (io.cdap.cdap.proto.artifact.AppRequest)40 File (java.io.File)34 PluginClass (io.cdap.cdap.api.plugin.PluginClass)32 Path (javax.ws.rs.Path)32 ArtifactVersion (io.cdap.cdap.api.artifact.ArtifactVersion)30 Set (java.util.Set)30 ImmutableSet (com.google.common.collect.ImmutableSet)28 Location (org.apache.twill.filesystem.Location)28 ArtifactRange (io.cdap.cdap.api.artifact.ArtifactRange)26 ArtifactDetail (io.cdap.cdap.internal.app.runtime.artifact.ArtifactDetail)26 ArtifactNotFoundException (io.cdap.cdap.common.ArtifactNotFoundException)22 EntityId (io.cdap.cdap.proto.id.EntityId)20