Search in sources :

Example 31 with ArtifactId

use of co.cask.cdap.proto.id.ArtifactId in project cdap by caskdata.

the class ApplicationClientTestRun method testAppUpdate.

@Test
public void testAppUpdate() throws Exception {
    String artifactName = "cfg-programs";
    ArtifactId artifactIdV1 = NamespaceId.DEFAULT.artifact(artifactName, "1.0.0");
    ArtifactId artifactIdV2 = NamespaceId.DEFAULT.artifact(artifactName, "2.0.0");
    ApplicationId appId = NamespaceId.DEFAULT.app("ProgramsApp");
    artifactClient.add(NamespaceId.DEFAULT, artifactName, Files.newInputStreamSupplier(createAppJarFile(ConfigurableProgramsApp.class)), "1.0.0");
    artifactClient.add(NamespaceId.DEFAULT, artifactName, Files.newInputStreamSupplier(createAppJarFile(ConfigurableProgramsApp2.class)), "2.0.0");
    try {
        // deploy the app with just the worker
        ConfigurableProgramsApp.Programs conf = new ConfigurableProgramsApp.Programs(null, "worker1", "stream1", "dataset1");
        AppRequest<ConfigurableProgramsApp.Programs> request = new AppRequest<>(new ArtifactSummary(artifactIdV1.getArtifact(), artifactIdV1.getVersion()), conf);
        appClient.deploy(appId, request);
        // should only have the worker
        Assert.assertTrue(appClient.listPrograms(appId, ProgramType.FLOW).isEmpty());
        Assert.assertEquals(1, appClient.listPrograms(appId, ProgramType.WORKER).size());
        // update to use just the flow
        conf = new ConfigurableProgramsApp.Programs("flow1", null, "stream1", "dataset1");
        request = new AppRequest<>(new ArtifactSummary(artifactIdV1.getArtifact(), artifactIdV1.getVersion()), conf);
        appClient.update(appId, request);
        // should only have the flow
        Assert.assertTrue(appClient.listPrograms(appId, ProgramType.WORKER).isEmpty());
        Assert.assertEquals(1, appClient.listPrograms(appId, ProgramType.FLOW).size());
        // check nonexistent app is not found
        try {
            appClient.update(NamespaceId.DEFAULT.app("ghost"), request);
            Assert.fail();
        } catch (NotFoundException e) {
        // expected
        }
        // check different artifact name is invalid
        request = new AppRequest<>(new ArtifactSummary("ghost", artifactIdV1.getVersion()), conf);
        try {
            appClient.update(appId, request);
            Assert.fail();
        } catch (BadRequestException e) {
        // expected
        }
        // check nonexistent artifact is not found
        request = new AppRequest<>(new ArtifactSummary(artifactIdV1.getArtifact(), "0.0.1"), conf);
        try {
            appClient.update(appId, request);
            Assert.fail();
        } catch (NotFoundException e) {
        // expected
        }
        // update artifact version. This version uses a different app class with that can add a service
        ConfigurableProgramsApp2.Programs conf2 = new ConfigurableProgramsApp2.Programs(null, null, "stream1", "dataset1", "service2");
        AppRequest<ConfigurableProgramsApp2.Programs> request2 = new AppRequest<>(new ArtifactSummary(artifactIdV2.getArtifact(), artifactIdV2.getVersion()), conf2);
        appClient.update(appId, request2);
        // should only have a single service
        Assert.assertTrue(appClient.listPrograms(appId, ProgramType.WORKER).isEmpty());
        Assert.assertTrue(appClient.listPrograms(appId, ProgramType.FLOW).isEmpty());
        Assert.assertEquals(1, appClient.listPrograms(appId, ProgramType.SERVICE).size());
    } finally {
        appClient.delete(appId);
        appClient.waitForDeleted(appId, 30, TimeUnit.SECONDS);
        artifactClient.delete(artifactIdV1);
        artifactClient.delete(artifactIdV2);
    }
}
Also used : ArtifactId(co.cask.cdap.proto.id.ArtifactId) ConfigurableProgramsApp(co.cask.cdap.client.app.ConfigurableProgramsApp) DatasetModuleNotFoundException(co.cask.cdap.common.DatasetModuleNotFoundException) DatasetNotFoundException(co.cask.cdap.common.DatasetNotFoundException) NotFoundException(co.cask.cdap.common.NotFoundException) AppRequest(co.cask.cdap.proto.artifact.AppRequest) ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) ConfigurableProgramsApp2(co.cask.cdap.client.app.ConfigurableProgramsApp2) BadRequestException(co.cask.cdap.common.BadRequestException) ApplicationId(co.cask.cdap.proto.id.ApplicationId) Test(org.junit.Test)

Example 32 with ArtifactId

use of co.cask.cdap.proto.id.ArtifactId in project cdap by caskdata.

the class ExistingEntitySystemMetadataWriter method writeSystemMetadataForArtifacts.

private void writeSystemMetadataForArtifacts(NamespaceId namespace) throws IOException {
    for (ArtifactDetail artifactDetail : artifactStore.getArtifacts(namespace)) {
        co.cask.cdap.api.artifact.ArtifactId artifact = artifactDetail.getDescriptor().getArtifactId();
        ArtifactInfo artifactInfo = new ArtifactInfo(artifact, artifactDetail.getMeta().getClasses(), artifactDetail.getMeta().getProperties());
        ArtifactId artifactId = namespace.artifact(artifact.getName(), artifact.getVersion().getVersion());
        SystemMetadataWriter writer = new ArtifactSystemMetadataWriter(metadataStore, artifactId, artifactInfo);
        writer.write();
    }
}
Also used : ArtifactInfo(co.cask.cdap.api.artifact.ArtifactInfo) ArtifactId(co.cask.cdap.proto.id.ArtifactId) DatasetSystemMetadataWriter(co.cask.cdap.data2.metadata.system.DatasetSystemMetadataWriter) ProgramSystemMetadataWriter(co.cask.cdap.data2.metadata.system.ProgramSystemMetadataWriter) ViewSystemMetadataWriter(co.cask.cdap.data2.metadata.system.ViewSystemMetadataWriter) SystemMetadataWriter(co.cask.cdap.data2.metadata.system.SystemMetadataWriter) AppSystemMetadataWriter(co.cask.cdap.data2.metadata.system.AppSystemMetadataWriter) ArtifactSystemMetadataWriter(co.cask.cdap.data2.metadata.system.ArtifactSystemMetadataWriter) StreamSystemMetadataWriter(co.cask.cdap.data2.metadata.system.StreamSystemMetadataWriter) ArtifactSystemMetadataWriter(co.cask.cdap.data2.metadata.system.ArtifactSystemMetadataWriter) ArtifactDetail(co.cask.cdap.internal.app.runtime.artifact.ArtifactDetail)

Example 33 with ArtifactId

use of co.cask.cdap.proto.id.ArtifactId in project cdap by caskdata.

the class MetadataHttpHandler method removeArtifactTag.

@DELETE
@Path("/namespaces/{namespace-id}/artifacts/{artifact-name}/versions/{artifact-version}/metadata/tags/{tag}")
public void removeArtifactTag(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("artifact-name") String artifactName, @PathParam("artifact-version") String artifactVersionStr, @PathParam("tag") String tag) throws NotFoundException {
    ArtifactId artifactId = new ArtifactId(namespaceId, artifactName, artifactVersionStr);
    metadataAdmin.removeTags(artifactId, tag);
    responder.sendString(HttpResponseStatus.OK, String.format("Tags %s for artifact %s deleted successfully.", tag, artifactId));
}
Also used : ArtifactId(co.cask.cdap.proto.id.ArtifactId) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 34 with ArtifactId

use of co.cask.cdap.proto.id.ArtifactId in project cdap by caskdata.

the class MetadataHttpHandler method addArtifactTags.

@POST
@Path("/namespaces/{namespace-id}/artifacts/{artifact-name}/versions/{artifact-version}/metadata/tags")
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void addArtifactTags(FullHttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("artifact-name") String artifactName, @PathParam("artifact-version") String artifactVersionStr) throws BadRequestException, NotFoundException {
    ArtifactId artifactId = new ArtifactId(namespaceId, artifactName, artifactVersionStr);
    metadataAdmin.addTags(artifactId, readArray(request));
    responder.sendJson(HttpResponseStatus.OK, String.format("Added tags to artifact %s successfully.", artifactId));
}
Also used : ArtifactId(co.cask.cdap.proto.id.ArtifactId) Path(javax.ws.rs.Path) AuditPolicy(co.cask.cdap.common.security.AuditPolicy) POST(javax.ws.rs.POST)

Example 35 with ArtifactId

use of co.cask.cdap.proto.id.ArtifactId in project cdap by caskdata.

the class MetadataHttpHandler method removeArtifactMetadata.

@DELETE
@Path("/namespaces/{namespace-id}/artifacts/{artifact-name}/versions/{artifact-version}/metadata")
public void removeArtifactMetadata(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("artifact-name") String artifactName, @PathParam("artifact-version") String artifactVersionStr) throws NotFoundException {
    ArtifactId artifactId = new ArtifactId(namespaceId, artifactName, artifactVersionStr);
    metadataAdmin.removeMetadata(artifactId);
    responder.sendJson(HttpResponseStatus.OK, String.format("Metadata for artifact %s deleted successfully.", artifactId));
}
Also used : ArtifactId(co.cask.cdap.proto.id.ArtifactId) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Aggregations

ArtifactId (co.cask.cdap.proto.id.ArtifactId)105 Test (org.junit.Test)45 NamespaceId (co.cask.cdap.proto.id.NamespaceId)40 IOException (java.io.IOException)29 Path (javax.ws.rs.Path)29 ArtifactSummary (co.cask.cdap.api.artifact.ArtifactSummary)24 ApplicationId (co.cask.cdap.proto.id.ApplicationId)22 ArtifactVersion (co.cask.cdap.api.artifact.ArtifactVersion)15 PluginClass (co.cask.cdap.api.plugin.PluginClass)15 ArtifactRange (co.cask.cdap.api.artifact.ArtifactRange)14 AppRequest (co.cask.cdap.proto.artifact.AppRequest)14 ProgramId (co.cask.cdap.proto.id.ProgramId)14 ArtifactNotFoundException (co.cask.cdap.common.ArtifactNotFoundException)13 File (java.io.File)13 Id (co.cask.cdap.common.id.Id)11 AuditPolicy (co.cask.cdap.common.security.AuditPolicy)11 Map (java.util.Map)10 BadRequestException (co.cask.cdap.common.BadRequestException)9 ArtifactInfo (co.cask.cdap.api.artifact.ArtifactInfo)8 ArtifactDetail (co.cask.cdap.internal.app.runtime.artifact.ArtifactDetail)8