use of co.cask.cdap.api.flow.FlowSpecification in project cdap by caskdata.
the class DistributedFlowProgramRunner method setupLaunchConfig.
@Override
protected void setupLaunchConfig(LaunchConfig launchConfig, Program program, ProgramOptions options, CConfiguration cConf, Configuration hConf, File tempDir) {
// Add runnables
Map<String, String> args = options.getUserArguments().asMap();
FlowSpecification flowSpec = getFlowSpecification(program);
for (Map.Entry<String, FlowletDefinition> entry : flowSpec.getFlowlets().entrySet()) {
FlowletDefinition flowletDefinition = entry.getValue();
FlowletSpecification flowletSpec = flowletDefinition.getFlowletSpec();
String flowletName = entry.getKey();
Map<String, String> flowletArgs = RuntimeArguments.extractScope(FlowUtils.FLOWLET_SCOPE, flowletName, args);
launchConfig.addRunnable(flowletName, new FlowletTwillRunnable(flowletName), flowletDefinition.getInstances(), flowletArgs, flowletSpec.getResources());
}
}
use of co.cask.cdap.api.flow.FlowSpecification 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.flow.FlowSpecification in project cdap by caskdata.
the class DefaultStore method setFlowletInstances.
@Override
public FlowSpecification setFlowletInstances(ProgramId id, String flowletId, int count) {
Preconditions.checkArgument(count > 0, "Cannot change number of flowlet instances to %s", count);
LOG.trace("Setting flowlet instances: namespace: {}, application: {}, flow: {}, flowlet: {}, " + "new instances count: {}", id.getNamespace(), id.getApplication(), id.getProgram(), flowletId, count);
FlowSpecification flowSpec = Transactionals.execute(transactional, context -> {
AppMetadataStore metaStore = getAppMetadataStore(context);
ApplicationSpecification appSpec = getAppSpecOrFail(metaStore, id);
ApplicationSpecification newAppSpec = updateFlowletInstancesInAppSpec(appSpec, id, flowletId, count);
metaStore.updateAppSpec(id.getNamespace(), id.getApplication(), id.getVersion(), newAppSpec);
return appSpec.getFlows().get(id.getProgram());
});
LOG.trace("Set flowlet instances: namespace: {}, application: {}, flow: {}, flowlet: {}, instances now: {}", id.getNamespaceId(), id.getApplication(), id.getProgram(), flowletId, count);
return flowSpec;
}
use of co.cask.cdap.api.flow.FlowSpecification in project cdap by caskdata.
the class DefaultAppConfigurer method addFlow.
@Override
public void addFlow(Flow flow) {
Preconditions.checkArgument(flow != null, "Flow cannot be null.");
DefaultFlowConfigurer configurer = new DefaultFlowConfigurer(flow);
flow.configure(configurer);
FlowSpecification spec = configurer.createSpecification();
addDatasets(configurer);
flows.put(spec.getName(), spec);
}
use of co.cask.cdap.api.flow.FlowSpecification in project cdap by caskdata.
the class ProgramLifecycleHttpHandler method getProgramInstances.
/**
* Get requested and provisioned instances for a program type.
* The program type passed here should be one that can have instances (flows, services, ...)
* Requires caller to do this validation.
*/
private BatchRunnableInstances getProgramInstances(BatchRunnable runnable, ApplicationSpecification spec, ProgramId programId) {
int requested;
String programName = programId.getProgram();
String runnableId = programName;
ProgramType programType = programId.getType();
if (programType == ProgramType.WORKER) {
if (!spec.getWorkers().containsKey(programName)) {
return new BatchRunnableInstances(runnable, HttpResponseStatus.NOT_FOUND.code(), "Worker: " + programName + " not found");
}
requested = spec.getWorkers().get(programName).getInstances();
} else if (programType == ProgramType.SERVICE) {
if (!spec.getServices().containsKey(programName)) {
return new BatchRunnableInstances(runnable, HttpResponseStatus.NOT_FOUND.code(), "Service: " + programName + " not found");
}
requested = spec.getServices().get(programName).getInstances();
} else if (programType == ProgramType.FLOW) {
// flows must have runnable id
runnableId = runnable.getRunnableId();
if (runnableId == null) {
return new BatchRunnableInstances(runnable, HttpResponseStatus.BAD_REQUEST.code(), "Must provide the flowlet id as the runnableId for flows");
}
FlowSpecification flowSpec = spec.getFlows().get(programName);
if (flowSpec == null) {
return new BatchRunnableInstances(runnable, HttpResponseStatus.NOT_FOUND.code(), "Flow: " + programName + " not found");
}
FlowletDefinition flowletDefinition = flowSpec.getFlowlets().get(runnableId);
if (flowletDefinition == null) {
return new BatchRunnableInstances(runnable, HttpResponseStatus.NOT_FOUND.code(), "Flowlet: " + runnableId + " not found");
}
requested = flowletDefinition.getInstances();
} else {
return new BatchRunnableInstances(runnable, HttpResponseStatus.BAD_REQUEST.code(), "Instances not supported for program type + " + programType);
}
int provisioned = getInstanceCount(programId, runnableId);
// use the pretty name of program types to be consistent
return new BatchRunnableInstances(runnable, HttpResponseStatus.OK.code(), provisioned, requested);
}
Aggregations