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);
}
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);
}
}
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);
}
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));
}
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.");
}
Aggregations