Search in sources :

Example 86 with ArtifactId

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

the class MetadataHttpHandler method removeArtifactTags.

@DELETE
@Path("/namespaces/{namespace-id}/artifacts/{artifact-name}/versions/{artifact-version}/metadata/tags")
public void removeArtifactTags(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.removeTags(artifactId);
    responder.sendString(HttpResponseStatus.OK, String.format("Tags 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)

Example 87 with ArtifactId

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

the class MetadataHttpHandler method removeArtifactProperty.

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

Example 88 with ArtifactId

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

the class MetadataHttpHandler method getArtifactMetadata.

@GET
@Path("/namespaces/{namespace-id}/artifacts/{artifact-name}/versions/{artifact-version}/metadata")
public void getArtifactMetadata(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("artifact-name") String artifactName, @PathParam("artifact-version") String artifactVersionStr, @QueryParam("scope") String scope) throws NotFoundException, BadRequestException {
    ArtifactId artifactId = new ArtifactId(namespaceId, artifactName, artifactVersionStr);
    responder.sendJson(HttpResponseStatus.OK, GSON.toJson(getMetadata(artifactId, scope), SET_METADATA_RECORD_TYPE));
}
Also used : ArtifactId(co.cask.cdap.proto.id.ArtifactId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 89 with ArtifactId

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

the class SystemMetadataWriterStageTest method testWorkflowTags.

@Test
public void testWorkflowTags() throws Exception {
    String appName = WorkflowAppWithFork.class.getSimpleName();
    ApplicationId appId = NamespaceId.DEFAULT.app(appName);
    String workflowName = WorkflowAppWithFork.WorkflowWithFork.class.getSimpleName();
    ArtifactId artifactId = NamespaceId.DEFAULT.artifact(appId.getApplication(), "1.0");
    ApplicationWithPrograms appWithPrograms = createAppWithWorkflow(artifactId, appId, workflowName);
    WorkflowSpecification workflowSpec = appWithPrograms.getSpecification().getWorkflows().get(workflowName);
    SystemMetadataWriterStage systemMetadataWriterStage = new SystemMetadataWriterStage(metadataStore);
    StageContext stageContext = new StageContext(Object.class);
    systemMetadataWriterStage.process(stageContext);
    systemMetadataWriterStage.process(appWithPrograms);
    // verify that the workflow is not tagged with the fork node name
    Set<String> workflowSystemTags = metadataStore.getTags(MetadataScope.SYSTEM, appId.workflow(workflowName));
    Sets.SetView<String> intersection = Sets.intersection(workflowSystemTags, getWorkflowForkNodes(workflowSpec));
    Assert.assertTrue("Workflows should not be tagged with fork node names, but found the following fork nodes " + "in the workflow's system tags: " + intersection, intersection.isEmpty());
    // verify that metadata was added for the workflow's schedule
    Map<String, String> metadataProperties = metadataStore.getMetadata(MetadataScope.SYSTEM, appId).getProperties();
    Assert.assertEquals(WorkflowAppWithFork.SCHED_NAME + ":testDescription", metadataProperties.get("schedule:" + WorkflowAppWithFork.SCHED_NAME));
}
Also used : WorkflowAppWithFork(co.cask.cdap.WorkflowAppWithFork) ArtifactId(co.cask.cdap.proto.id.ArtifactId) Sets(com.google.common.collect.Sets) WorkflowSpecification(co.cask.cdap.api.workflow.WorkflowSpecification) ApplicationId(co.cask.cdap.proto.id.ApplicationId) StageContext(co.cask.cdap.internal.pipeline.StageContext) Test(org.junit.Test)

Example 90 with ArtifactId

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

the class AbstractProgramRuntimeServiceTest method testDeadlock.

@Test(timeout = 5000)
public void testDeadlock() throws IOException, ExecutionException, InterruptedException, TimeoutException {
    // This test is for testing condition in (CDAP-3579)
    // The race condition is if a program finished very fast such that inside the AbstractProgramRuntimeService is
    // still in the run method, it holds the object lock, making the callback from the listener block forever.
    ProgramRunnerFactory runnerFactory = createProgramRunnerFactory();
    final Program program = createDummyProgram();
    final ProgramRuntimeService runtimeService = new AbstractProgramRuntimeService(CConfiguration.create(), runnerFactory, null, new NoOpProgramStateWriter()) {

        @Override
        public ProgramLiveInfo getLiveInfo(ProgramId programId) {
            return new ProgramLiveInfo(programId, "runtime") {
            };
        }

        @Override
        protected Program createProgram(CConfiguration cConf, ProgramRunner programRunner, ProgramDescriptor programDescriptor, ArtifactDetail artifactDetail, File tempDir) throws IOException {
            return program;
        }

        @Override
        protected ArtifactDetail getArtifactDetail(ArtifactId artifactId) throws IOException, ArtifactNotFoundException {
            co.cask.cdap.api.artifact.ArtifactId id = new co.cask.cdap.api.artifact.ArtifactId("dummy", new ArtifactVersion("1.0"), ArtifactScope.USER);
            return new ArtifactDetail(new ArtifactDescriptor(id, Locations.toLocation(TEMP_FOLDER.newFile())), new ArtifactMeta(ArtifactClasses.builder().build()));
        }
    };
    runtimeService.startAndWait();
    try {
        ProgramDescriptor descriptor = new ProgramDescriptor(program.getId(), null, NamespaceId.DEFAULT.artifact("test", "1.0"));
        final ProgramController controller = runtimeService.run(descriptor, new SimpleProgramOptions(program.getId())).getController();
        Tasks.waitFor(ProgramController.State.COMPLETED, new Callable<ProgramController.State>() {

            @Override
            public ProgramController.State call() throws Exception {
                return controller.getState();
            }
        }, 5, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS);
        Tasks.waitFor(true, new Callable<Boolean>() {

            @Override
            public Boolean call() throws Exception {
                return runtimeService.list(ProgramType.WORKER).isEmpty();
            }
        }, 5, TimeUnit.SECONDS, 100, TimeUnit.MICROSECONDS);
    } finally {
        runtimeService.stopAndWait();
    }
}
Also used : ArtifactId(co.cask.cdap.proto.id.ArtifactId) ArtifactVersion(co.cask.cdap.api.artifact.ArtifactVersion) ArtifactDescriptor(co.cask.cdap.internal.app.runtime.artifact.ArtifactDescriptor) ProgramDescriptor(co.cask.cdap.app.program.ProgramDescriptor) ArtifactMeta(co.cask.cdap.internal.app.runtime.artifact.ArtifactMeta) Program(co.cask.cdap.app.program.Program) ProgramId(co.cask.cdap.proto.id.ProgramId) CConfiguration(co.cask.cdap.common.conf.CConfiguration) TimeoutException(java.util.concurrent.TimeoutException) ArtifactNotFoundException(co.cask.cdap.common.ArtifactNotFoundException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) SimpleProgramOptions(co.cask.cdap.internal.app.runtime.SimpleProgramOptions) ProgramLiveInfo(co.cask.cdap.proto.ProgramLiveInfo) File(java.io.File) ArtifactDetail(co.cask.cdap.internal.app.runtime.artifact.ArtifactDetail) Test(org.junit.Test)

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