use of co.cask.cdap.api.workflow.WorkflowSpecification in project cdap by caskdata.
the class ApplicationLifecycleService method deleteAppVersion.
/**
* Delete the specified application version without performing checks that its programs are stopped.
*
* @param appId the id of the application to delete
* @param spec the spec of the application to delete
* @throws Exception
*/
private void deleteAppVersion(final ApplicationId appId, ApplicationSpecification spec) throws Exception {
// Delete the schedules
scheduler.deleteSchedules(appId);
for (WorkflowSpecification workflowSpec : spec.getWorkflows().values()) {
scheduler.modifySchedulesTriggeredByDeletedProgram(appId.workflow(workflowSpec.getName()));
}
store.removeApplication(appId);
}
use of co.cask.cdap.api.workflow.WorkflowSpecification in project cdap by caskdata.
the class ApplicationLifecycleService method deleteApp.
// deletes without performs checks that no programs are running
/**
* Delete the specified application without performing checks that its programs are stopped.
*
* @param appId the id of the application to delete
* @param spec the spec of the application to delete
* @throws Exception
*/
private void deleteApp(final ApplicationId appId, ApplicationSpecification spec) throws Exception {
// Delete the schedules
scheduler.deleteSchedules(appId);
for (WorkflowSpecification workflowSpec : spec.getWorkflows().values()) {
scheduler.modifySchedulesTriggeredByDeletedProgram(appId.workflow(workflowSpec.getName()));
}
deleteMetrics(appId);
// Delete all preferences of the application and of all its programs
deletePreferences(appId);
// Delete all streams and queues state of each flow
for (final FlowSpecification flowSpecification : spec.getFlows().values()) {
FlowUtils.clearDeletedFlow(impersonator, queueAdmin, streamConsumerFactory, appId.flow(flowSpecification.getName()), flowSpecification);
}
ApplicationSpecification appSpec = store.getApplication(appId);
deleteAppMetadata(appId, appSpec);
deleteRouteConfig(appId, appSpec);
store.deleteWorkflowStats(appId);
store.removeApplication(appId);
try {
// delete the owner as it has already been determined that this is the only version of the app
ownerAdmin.delete(appId);
} catch (Exception e) {
LOG.warn("Failed to delete app owner principal for application {} if one existed while deleting the " + "application.", appId);
}
try {
usageRegistry.unregister(appId);
} catch (Exception e) {
LOG.warn("Failed to unregister usage of app: {}", appId, e);
}
}
use of co.cask.cdap.api.workflow.WorkflowSpecification in project cdap by caskdata.
the class WorkflowHttpHandler method deleteWorkflowLocalDatasets.
@DELETE
@Path("/apps/{app-id}/workflows/{workflow-id}/runs/{run-id}/localdatasets")
public void deleteWorkflowLocalDatasets(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 {
WorkflowSpecification workflowSpec = getWorkflowSpecForValidRun(namespaceId, applicationId, workflowId, runId);
Set<String> errorOnDelete = new HashSet<>();
for (Map.Entry<String, DatasetCreationSpec> localDatasetEntry : workflowSpec.getLocalDatasetSpecs().entrySet()) {
String mappedDatasetName = localDatasetEntry.getKey() + "." + runId;
// try best to delete the local datasets.
try {
datasetFramework.deleteInstance(new DatasetId(namespaceId, mappedDatasetName));
} catch (InstanceNotFoundException e) {
// Dataset instance is already deleted. so its no-op.
} catch (Throwable t) {
errorOnDelete.add(mappedDatasetName);
LOG.error("Failed to delete the Workflow local dataset {}. Reason - {}", mappedDatasetName, t.getMessage());
}
}
if (errorOnDelete.isEmpty()) {
responder.sendStatus(HttpResponseStatus.OK);
return;
}
String errorMessage = "Failed to delete Workflow local datasets - " + Joiner.on(",").join(errorOnDelete);
throw new RuntimeException(errorMessage);
}
use of co.cask.cdap.api.workflow.WorkflowSpecification in project cdap by caskdata.
the class WorkflowHttpHandler method getWorkflowLocalDatasets.
@GET
@Path("/apps/{app-id}/workflows/{workflow-id}/runs/{run-id}/localdatasets")
public void getWorkflowLocalDatasets(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, DatasetManagementException {
WorkflowSpecification workflowSpec = getWorkflowSpecForValidRun(namespaceId, applicationId, workflowId, runId);
Map<String, DatasetSpecificationSummary> localDatasetSummaries = new HashMap<>();
for (Map.Entry<String, DatasetCreationSpec> localDatasetEntry : workflowSpec.getLocalDatasetSpecs().entrySet()) {
String mappedDatasetName = localDatasetEntry.getKey() + "." + runId;
String datasetType = localDatasetEntry.getValue().getTypeName();
Map<String, String> datasetProperties = localDatasetEntry.getValue().getProperties().getProperties();
if (datasetFramework.hasInstance(new DatasetId(namespaceId, mappedDatasetName))) {
localDatasetSummaries.put(localDatasetEntry.getKey(), new DatasetSpecificationSummary(mappedDatasetName, datasetType, datasetProperties));
}
}
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(localDatasetSummaries));
}
use of co.cask.cdap.api.workflow.WorkflowSpecification in project cdap by caskdata.
the class DefaultAppConfigurer method addWorkflow.
@Override
public void addWorkflow(Workflow workflow) {
Preconditions.checkArgument(workflow != null, "Workflow cannot be null.");
DefaultWorkflowConfigurer configurer = new DefaultWorkflowConfigurer(workflow, this, deployNamespace, artifactId, artifactRepository, pluginInstantiator);
workflow.configure(configurer);
WorkflowSpecification spec = configurer.createSpecification();
addDatasetsAndPlugins(configurer);
workflows.put(spec.getName(), spec);
}
Aggregations