Search in sources :

Example 6 with WorkflowSpecification

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);
}
Also used : WorkflowSpecification(co.cask.cdap.api.workflow.WorkflowSpecification)

Example 7 with WorkflowSpecification

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);
    }
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) FlowSpecification(co.cask.cdap.api.flow.FlowSpecification) WorkflowSpecification(co.cask.cdap.api.workflow.WorkflowSpecification) CannotBeDeletedException(co.cask.cdap.common.CannotBeDeletedException) ApplicationNotFoundException(co.cask.cdap.common.ApplicationNotFoundException) ArtifactNotFoundException(co.cask.cdap.common.ArtifactNotFoundException) ArtifactAlreadyExistsException(co.cask.cdap.common.ArtifactAlreadyExistsException) IOException(java.io.IOException) InvalidArtifactException(co.cask.cdap.common.InvalidArtifactException) ExecutionException(java.util.concurrent.ExecutionException) NotFoundException(co.cask.cdap.common.NotFoundException)

Example 8 with WorkflowSpecification

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);
}
Also used : InstanceNotFoundException(co.cask.cdap.api.dataset.InstanceNotFoundException) DatasetCreationSpec(co.cask.cdap.internal.dataset.DatasetCreationSpec) WorkflowSpecification(co.cask.cdap.api.workflow.WorkflowSpecification) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet) DatasetId(co.cask.cdap.proto.id.DatasetId) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 9 with WorkflowSpecification

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));
}
Also used : HashMap(java.util.HashMap) DatasetCreationSpec(co.cask.cdap.internal.dataset.DatasetCreationSpec) WorkflowSpecification(co.cask.cdap.api.workflow.WorkflowSpecification) DatasetSpecificationSummary(co.cask.cdap.proto.DatasetSpecificationSummary) Map(java.util.Map) HashMap(java.util.HashMap) DatasetId(co.cask.cdap.proto.id.DatasetId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 10 with WorkflowSpecification

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);
}
Also used : DefaultWorkflowConfigurer(co.cask.cdap.internal.app.workflow.DefaultWorkflowConfigurer) WorkflowSpecification(co.cask.cdap.api.workflow.WorkflowSpecification)

Aggregations

WorkflowSpecification (co.cask.cdap.api.workflow.WorkflowSpecification)19 WorkflowNode (co.cask.cdap.api.workflow.WorkflowNode)7 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)6 WorkflowActionNode (co.cask.cdap.api.workflow.WorkflowActionNode)5 DatasetCreationSpec (co.cask.cdap.internal.dataset.DatasetCreationSpec)5 ProgramId (co.cask.cdap.proto.id.ProgramId)5 Map (java.util.Map)5 ScheduleProgramInfo (co.cask.cdap.api.workflow.ScheduleProgramInfo)4 ProgramType (co.cask.cdap.proto.ProgramType)4 ApplicationId (co.cask.cdap.proto.id.ApplicationId)4 InstanceNotFoundException (co.cask.cdap.api.dataset.InstanceNotFoundException)3 ApplicationNotFoundException (co.cask.cdap.common.ApplicationNotFoundException)3 NotFoundException (co.cask.cdap.common.NotFoundException)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 FlowSpecification (co.cask.cdap.api.flow.FlowSpecification)2 SchedulableProgramType (co.cask.cdap.api.schedule.SchedulableProgramType)2 WorkflowForkNode (co.cask.cdap.api.workflow.WorkflowForkNode)2 ProgramNotFoundException (co.cask.cdap.common.ProgramNotFoundException)2 ScheduleCreationSpec (co.cask.cdap.internal.schedule.ScheduleCreationSpec)2