Search in sources :

Example 1 with NotFoundException

use of co.cask.cdap.common.NotFoundException in project cdap by caskdata.

the class MetadataHttpHandlerTestRun method testDeleteApplication.

@Test
public void testDeleteApplication() throws Exception {
    namespaceClient.create(new NamespaceMeta.Builder().setName(TEST_NAMESPACE1.toId()).build());
    appClient.deploy(TEST_NAMESPACE1, createAppJarFile(WordCountApp.class));
    ProgramId programId = TEST_NAMESPACE1.app("WordCountApp").flow("WordCountFlow");
    // Set some properties metadata
    Map<String, String> flowProperties = ImmutableMap.of("sKey", "sValue", "sK", "sV");
    addProperties(programId, flowProperties);
    // Get properties
    Map<String, String> properties = getProperties(programId, MetadataScope.USER);
    Assert.assertEquals(2, properties.size());
    // Delete the App after stopping the flow
    appClient.delete(TEST_NAMESPACE1.app(programId.getApplication()));
    // Delete again should throw not found exception
    try {
        appClient.delete(TEST_NAMESPACE1.app(programId.getApplication()));
        Assert.fail("Expected NotFoundException");
    } catch (NotFoundException e) {
    // expected
    }
    // Now try to get from invalid entity should throw 404.
    getPropertiesFromInvalidEntity(programId);
}
Also used : NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) WordCountApp(co.cask.cdap.WordCountApp) NotFoundException(co.cask.cdap.common.NotFoundException) ProgramId(co.cask.cdap.proto.id.ProgramId) Test(org.junit.Test)

Example 2 with NotFoundException

use of co.cask.cdap.common.NotFoundException 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 3 with NotFoundException

use of co.cask.cdap.common.NotFoundException in project cdap by caskdata.

the class WorkflowHttpHandler method getWorkflowToken.

@GET
@Path("/apps/{app-id}/workflows/{workflow-id}/runs/{run-id}/token")
public void getWorkflowToken(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("workflow-id") String workflowId, @PathParam("run-id") String runId, @QueryParam("scope") @DefaultValue("user") String scope, @QueryParam("key") @DefaultValue("") String key) throws NotFoundException {
    WorkflowToken workflowToken = getWorkflowToken(namespaceId, appId, workflowId, runId);
    WorkflowToken.Scope tokenScope = WorkflowToken.Scope.valueOf(scope.toUpperCase());
    WorkflowTokenDetail workflowTokenDetail = WorkflowTokenDetail.of(workflowToken.getAll(tokenScope));
    Type workflowTokenDetailType = new TypeToken<WorkflowTokenDetail>() {
    }.getType();
    if (key.isEmpty()) {
        responder.sendJson(HttpResponseStatus.OK, workflowTokenDetail, workflowTokenDetailType, GSON);
        return;
    }
    List<NodeValue> nodeValueEntries = workflowToken.getAll(key, tokenScope);
    if (nodeValueEntries.isEmpty()) {
        throw new NotFoundException(key);
    }
    responder.sendJson(HttpResponseStatus.OK, WorkflowTokenDetail.of(ImmutableMap.of(key, nodeValueEntries)), workflowTokenDetailType, GSON);
}
Also used : NodeValue(co.cask.cdap.api.workflow.NodeValue) ProgramType(co.cask.cdap.proto.ProgramType) Type(java.lang.reflect.Type) SchedulableProgramType(co.cask.cdap.api.schedule.SchedulableProgramType) WorkflowToken(co.cask.cdap.api.workflow.WorkflowToken) ProgramNotFoundException(co.cask.cdap.common.ProgramNotFoundException) ApplicationNotFoundException(co.cask.cdap.common.ApplicationNotFoundException) InstanceNotFoundException(co.cask.cdap.api.dataset.InstanceNotFoundException) NotFoundException(co.cask.cdap.common.NotFoundException) WorkflowTokenDetail(co.cask.cdap.proto.WorkflowTokenDetail) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 4 with NotFoundException

use of co.cask.cdap.common.NotFoundException in project cdap by caskdata.

the class WorkflowStatsSLAHttpHandler method compare.

/**
   * Compare the metrics of 2 runs of a workflow
   *
   * @param request The request
   * @param responder The responder
   * @param namespaceId The namespace the application is in
   * @param appId The application the workflow is in
   * @param workflowId The workflow that needs to have it stats shown
   * @param runId The run id of the Workflow that the user wants to see
   * @param otherRunId The other run id of the same workflow that the user wants to compare against
   */
@GET
@Path("apps/{app-id}/workflows/{workflow-id}/runs/{run-id}/compare")
public void compare(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("workflow-id") String workflowId, @PathParam("run-id") String runId, @QueryParam("other-run-id") String otherRunId) throws Exception {
    WorkflowId workflow = new WorkflowId(namespaceId, appId, workflowId);
    WorkflowRunMetrics detailedStatistics = getDetailedRecord(workflow, runId);
    WorkflowRunMetrics otherDetailedStatistics = getDetailedRecord(workflow, otherRunId);
    if (detailedStatistics == null) {
        throw new NotFoundException("The run-id provided was not found : " + runId);
    }
    if (otherDetailedStatistics == null) {
        throw new NotFoundException("The other run-id provided was not found : " + otherRunId);
    }
    List<WorkflowRunMetrics> workflowRunMetricsList = new ArrayList<>();
    workflowRunMetricsList.add(detailedStatistics);
    workflowRunMetricsList.add(otherDetailedStatistics);
    responder.sendJson(HttpResponseStatus.OK, format(workflowRunMetricsList));
}
Also used : ArrayList(java.util.ArrayList) NotFoundException(co.cask.cdap.common.NotFoundException) WorkflowId(co.cask.cdap.proto.id.WorkflowId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 5 with NotFoundException

use of co.cask.cdap.common.NotFoundException in project cdap by caskdata.

the class WorkflowHttpHandler method suspendWorkflowRun.

@POST
@Path("/apps/{app-id}/workflows/{workflow-name}/runs/{run-id}/suspend")
public void suspendWorkflowRun(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("workflow-name") String workflowName, @PathParam("run-id") String runId) throws Exception {
    ProgramId id = new ProgramId(namespaceId, appId, ProgramType.WORKFLOW, workflowName);
    ProgramRuntimeService.RuntimeInfo runtimeInfo = runtimeService.list(id).get(RunIds.fromString(runId));
    if (runtimeInfo == null) {
        throw new NotFoundException(id.run(runId));
    }
    ProgramController controller = runtimeInfo.getController();
    if (controller.getState() == ProgramController.State.SUSPENDED) {
        throw new ConflictException("Program run already suspended");
    }
    controller.suspend().get();
    responder.sendString(HttpResponseStatus.OK, "Program run suspended.");
}
Also used : ProgramController(co.cask.cdap.app.runtime.ProgramController) ConflictException(co.cask.cdap.common.ConflictException) ProgramNotFoundException(co.cask.cdap.common.ProgramNotFoundException) ApplicationNotFoundException(co.cask.cdap.common.ApplicationNotFoundException) InstanceNotFoundException(co.cask.cdap.api.dataset.InstanceNotFoundException) NotFoundException(co.cask.cdap.common.NotFoundException) ProgramId(co.cask.cdap.proto.id.ProgramId) ProgramRuntimeService(co.cask.cdap.app.runtime.ProgramRuntimeService) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Aggregations

NotFoundException (co.cask.cdap.common.NotFoundException)122 URL (java.net.URL)42 HttpResponse (co.cask.common.http.HttpResponse)41 ApplicationNotFoundException (co.cask.cdap.common.ApplicationNotFoundException)28 NamespaceNotFoundException (co.cask.cdap.common.NamespaceNotFoundException)26 ProgramNotFoundException (co.cask.cdap.common.ProgramNotFoundException)25 Path (javax.ws.rs.Path)25 BadRequestException (co.cask.cdap.common.BadRequestException)22 ProgramId (co.cask.cdap.proto.id.ProgramId)19 ApplicationId (co.cask.cdap.proto.id.ApplicationId)17 NamespaceId (co.cask.cdap.proto.id.NamespaceId)14 Test (org.junit.Test)14 POST (javax.ws.rs.POST)12 HttpRequest (co.cask.common.http.HttpRequest)10 IOException (java.io.IOException)10 GET (javax.ws.rs.GET)10 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)9 ArtifactNotFoundException (co.cask.cdap.common.ArtifactNotFoundException)8 DatasetTypeNotFoundException (co.cask.cdap.common.DatasetTypeNotFoundException)8 TypeToken (com.google.common.reflect.TypeToken)8