use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class FlowQueuePendingCorrector method run.
/**
* Corrects queue.pending metric for all flowlets in a namespace.
*/
public void run(NamespaceId namespaceId) throws Exception {
System.out.println("Running queue.pending correction on namespace " + namespaceId);
Collection<ApplicationSpecification> apps = store.getAllApplications(namespaceId);
for (ApplicationSpecification app : apps) {
ApplicationId appId = namespaceId.app(app.getName(), app.getAppVersion());
run(appId, app);
}
}
use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class FlowQueuePendingCorrector method run.
/**
* Corrects queue.pending metric for a flow.
*/
public void run(final FlowId flowId) throws Exception {
ApplicationSpecification app = store.getApplication(flowId.getParent());
Preconditions.checkArgument(app != null);
Preconditions.checkArgument(app.getFlows().containsKey(flowId.getProgram()));
FlowSpecification flow = app.getFlows().get(flowId.getProgram());
run(flowId, flow);
}
use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class WorkflowHttpHandler method getWorkflowSpecForValidRun.
/**
* Get the {@link WorkflowSpecification} if valid application id, workflow id, and runid are provided.
* @param namespaceId the namespace id
* @param applicationId the application id
* @param workflowId the workflow id
* @param runId the runid of the workflow
* @return the specifications for the Workflow
* @throws NotFoundException is thrown when the application, workflow, or runid is not found
*/
private WorkflowSpecification getWorkflowSpecForValidRun(String namespaceId, String applicationId, String workflowId, String runId) throws NotFoundException {
ApplicationId appId = new ApplicationId(namespaceId, applicationId);
ApplicationSpecification appSpec = store.getApplication(appId);
if (appSpec == null) {
throw new ApplicationNotFoundException(appId);
}
WorkflowSpecification workflowSpec = appSpec.getWorkflows().get(workflowId);
ProgramId programId = new ProgramId(namespaceId, applicationId, ProgramType.WORKFLOW, workflowId);
if (workflowSpec == null) {
throw new ProgramNotFoundException(programId);
}
if (store.getRun(programId.run(runId)) == null) {
throw new NotFoundException(new ProgramRunId(programId.getNamespace(), programId.getApplication(), programId.getType(), programId.getProgram(), runId));
}
return workflowSpec;
}
use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class WorkflowHttpHandler method getWorkflowNodeStates.
@GET
@Path("/apps/{app-id}/workflows/{workflow-id}/runs/{run-id}/nodes/state")
public void getWorkflowNodeStates(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String applicationId, @PathParam("workflow-id") String workflowId, @PathParam("run-id") String runId) throws NotFoundException {
ApplicationId appId = Ids.namespace(namespaceId).app(applicationId);
ApplicationSpecification appSpec = store.getApplication(appId);
if (appSpec == null) {
throw new ApplicationNotFoundException(appId);
}
ProgramId workflowProgramId = appId.workflow(workflowId);
WorkflowSpecification workflowSpec = appSpec.getWorkflows().get(workflowProgramId.getProgram());
if (workflowSpec == null) {
throw new ProgramNotFoundException(workflowProgramId);
}
ProgramRunId workflowRunId = workflowProgramId.run(runId);
if (store.getRun(workflowRunId) == null) {
throw new NotFoundException(workflowRunId);
}
List<WorkflowNodeStateDetail> nodeStateDetails = store.getWorkflowNodeStates(workflowRunId);
Map<String, WorkflowNodeStateDetail> nodeStates = new HashMap<>();
for (WorkflowNodeStateDetail nodeStateDetail : nodeStateDetails) {
nodeStates.put(nodeStateDetail.getNodeId(), nodeStateDetail);
}
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(nodeStates, STRING_TO_NODESTATEDETAIL_MAP_TYPE));
}
use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class WorkflowHttpHandler method getScheduledRuntime.
private void getScheduledRuntime(HttpResponder responder, String namespaceId, String appName, String workflowName, boolean previousRuntimeRequested) throws SchedulerException, NotFoundException {
try {
ApplicationId appId = new ApplicationId(namespaceId, appName);
WorkflowId workflowId = new WorkflowId(appId, workflowName);
ApplicationSpecification appSpec = store.getApplication(appId);
if (appSpec == null) {
throw new ApplicationNotFoundException(appId);
}
if (appSpec.getWorkflows().get(workflowName) == null) {
throw new ProgramNotFoundException(workflowId);
}
List<ScheduledRuntime> runtimes;
if (previousRuntimeRequested) {
runtimes = timeScheduler.previousScheduledRuntime(workflowId, SchedulableProgramType.WORKFLOW);
} else {
runtimes = timeScheduler.nextScheduledRuntime(workflowId, SchedulableProgramType.WORKFLOW);
}
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(runtimes));
} catch (SecurityException e) {
responder.sendStatus(HttpResponseStatus.UNAUTHORIZED);
}
}
Aggregations