use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class WorkflowHttpHandler method getWorkflowToken.
private WorkflowToken getWorkflowToken(String namespaceId, String appName, String workflow, String runId) throws NotFoundException {
ApplicationId appId = new ApplicationId(namespaceId, appName);
ApplicationSpecification appSpec = store.getApplication(appId);
if (appSpec == null) {
throw new NotFoundException(appId);
}
WorkflowId workflowId = appId.workflow(workflow);
if (!appSpec.getWorkflows().containsKey(workflow)) {
throw new NotFoundException(workflowId);
}
if (store.getRun(workflowId.run(runId)) == null) {
throw new NotFoundException(workflowId.run(runId));
}
return store.getWorkflowToken(workflowId, runId);
}
use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class Programs method create.
/**
* Creates a new {@link Program} using information from an existing program. The new program has the same
* runtime dependencies and must be from the same application as the original program.
*
* @param cConf the CDAP configuration
* @param originalProgram the original program
* @param programId the new program id
* @param programRunner the {@link ProgramRunner} for executing the new program. If provided and if it implements
* {@link ProgramClassLoaderProvider}, then the
* {@link ClassLoader} created for the {@link Program} will be determined based on it.
* Otherwise, the {@link ClassLoader} will only have visibility
* to cdap-api and hadoop classes.
* @return a new {@link Program} instance for the given programId
* @throws IOException If failed to create the program
*/
public static Program create(CConfiguration cConf, Program originalProgram, ProgramId programId, @Nullable ProgramRunner programRunner) throws IOException {
ClassLoader classLoader = originalProgram.getClassLoader();
// The classloader should be ProgramClassLoader
Preconditions.checkArgument(classLoader instanceof ProgramClassLoader, "Program %s doesn't use ProgramClassLoader", originalProgram);
// The new program should be in the same namespace and app
ProgramId originalId = originalProgram.getId();
Preconditions.checkArgument(originalId.getNamespaceId().equals(programId.getNamespaceId()), "Program %s is not in the same namespace as %s", programId, originalId);
Preconditions.checkArgument(originalId.getParent().equals(programId.getParent()), "Program %s is not in the same application as %s", programId, originalId);
// Make sure the program is defined in the app
ApplicationSpecification appSpec = originalProgram.getApplicationSpecification();
ensureProgramInApplication(appSpec, programId);
return Programs.create(cConf, programRunner, new ProgramDescriptor(programId, appSpec), originalProgram.getJarLocation(), ((ProgramClassLoader) classLoader).getDir());
}
use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class CreateStreamsStage method process.
/**
* Receives an input containing application specification and location
* and verifies both.
*
* @param input An instance of {@link ApplicationDeployable}
*/
@Override
public void process(ApplicationDeployable input) throws Exception {
// create stream instances
ApplicationSpecification specification = input.getSpecification();
NamespaceId namespaceId = input.getApplicationId().getParent();
KerberosPrincipalId ownerPrincipal = input.getOwnerPrincipal();
// get the authorizing user
String authorizingUser = AuthorizationUtil.getAppAuthorizingUser(ownerAdmin, authenticationContext, input.getApplicationId(), ownerPrincipal);
streamCreator.createStreams(namespaceId, specification.getStreams().values(), ownerPrincipal, authorizingUser);
// Emit the input to next stage.
emit(input);
}
use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class CreateDatasetInstancesStage method process.
/**
* Receives an input containing application specification and location
* and verifies both.
*
* @param input An instance of {@link ApplicationDeployable}
*/
@Override
public void process(ApplicationDeployable input) throws Exception {
// create dataset instances
ApplicationSpecification specification = input.getSpecification();
NamespaceId namespaceId = input.getApplicationId().getParent();
KerberosPrincipalId ownerPrincipal = input.getOwnerPrincipal();
// get the authorizing user
String authorizingUser = AuthorizationUtil.getAppAuthorizingUser(ownerAdmin, authenticationContext, input.getApplicationId(), ownerPrincipal);
datasetInstanceCreator.createInstances(namespaceId, specification.getDatasets(), ownerPrincipal, authorizingUser);
// Emit the input to next stage.
emit(input);
}
use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class ProgramGenerationStage method process.
@Override
public void process(final ApplicationDeployable input) throws Exception {
List<ProgramDescriptor> programDescriptors = new ArrayList<>();
final ApplicationSpecification appSpec = input.getSpecification();
// Now, we iterate through all ProgramSpecification and generate programs
Iterable<ProgramSpecification> specifications = Iterables.concat(appSpec.getMapReduce().values(), appSpec.getFlows().values(), appSpec.getWorkflows().values(), appSpec.getServices().values(), appSpec.getSpark().values(), appSpec.getWorkers().values());
for (ProgramSpecification spec : specifications) {
ProgramType type = ProgramTypes.fromSpecification(spec);
ProgramId programId = input.getApplicationId().program(type, spec.getName());
programDescriptors.add(new ProgramDescriptor(programId, appSpec));
}
emit(new ApplicationWithPrograms(input, programDescriptors));
}
Aggregations