use of co.cask.cdap.api.ProgramSpecification in project cdap by caskdata.
the class ApplicationDetail method fromSpec.
public static ApplicationDetail fromSpec(ApplicationSpecification spec, @Nullable String ownerPrincipal) {
List<ProgramRecord> programs = new ArrayList<>();
for (ProgramSpecification programSpec : spec.getFlows().values()) {
programs.add(new ProgramRecord(ProgramType.FLOW, spec.getName(), programSpec.getName(), programSpec.getDescription()));
}
for (ProgramSpecification programSpec : spec.getMapReduce().values()) {
programs.add(new ProgramRecord(ProgramType.MAPREDUCE, spec.getName(), programSpec.getName(), programSpec.getDescription()));
}
for (ProgramSpecification programSpec : spec.getServices().values()) {
programs.add(new ProgramRecord(ProgramType.SERVICE, spec.getName(), programSpec.getName(), programSpec.getDescription()));
}
for (ProgramSpecification programSpec : spec.getSpark().values()) {
programs.add(new ProgramRecord(ProgramType.SPARK, spec.getName(), programSpec.getName(), programSpec.getDescription()));
}
for (ProgramSpecification programSpec : spec.getWorkers().values()) {
programs.add(new ProgramRecord(ProgramType.WORKER, spec.getName(), programSpec.getName(), programSpec.getDescription()));
}
for (ProgramSpecification programSpec : spec.getWorkflows().values()) {
programs.add(new ProgramRecord(ProgramType.WORKFLOW, spec.getName(), programSpec.getName(), programSpec.getDescription()));
}
List<StreamDetail> streams = new ArrayList<>();
for (StreamSpecification streamSpec : spec.getStreams().values()) {
streams.add(new StreamDetail(streamSpec.getName()));
}
List<DatasetDetail> datasets = new ArrayList<>();
for (DatasetCreationSpec datasetSpec : spec.getDatasets().values()) {
datasets.add(new DatasetDetail(datasetSpec.getInstanceName(), datasetSpec.getTypeName()));
}
List<PluginDetail> plugins = new ArrayList<>();
for (Map.Entry<String, Plugin> pluginEnty : spec.getPlugins().entrySet()) {
plugins.add(new PluginDetail(pluginEnty.getKey(), pluginEnty.getValue().getPluginClass().getName(), pluginEnty.getValue().getPluginClass().getType()));
}
// this is only required if there are old apps lying around that failed to get upgrading during
// the upgrade to v3.2 for some reason. In those cases artifact id will be null until they re-deploy the app.
// in the meantime, we don't want this api call to null pointer exception.
ArtifactSummary summary = spec.getArtifactId() == null ? new ArtifactSummary(spec.getName(), null) : ArtifactSummary.from(spec.getArtifactId());
return new ApplicationDetail(spec.getName(), spec.getAppVersion(), spec.getDescription(), spec.getConfiguration(), streams, datasets, programs, plugins, summary, ownerPrincipal);
}
use of co.cask.cdap.api.ProgramSpecification in project cdap by caskdata.
the class DefaultStoreTest method testCheckDeletedWorkflow.
@Test
public void testCheckDeletedWorkflow() throws Exception {
//Deploy program with all types of programs.
ApplicationSpecification spec = Specifications.from(new AllProgramsApp());
ApplicationId appId = NamespaceId.DEFAULT.app(spec.getName());
store.addApplication(appId, spec);
Set<String> specsToBeDeleted = Sets.newHashSet();
specsToBeDeleted.addAll(spec.getWorkflows().keySet());
Assert.assertEquals(1, specsToBeDeleted.size());
//Get the spec for app that contains only flow and mapreduce - removing workflows.
spec = Specifications.from(new FlowMapReduceApp());
//Get the deleted program specs by sending a spec with same name as AllProgramsApp but with no programs
List<ProgramSpecification> deletedSpecs = store.getDeletedProgramSpecifications(appId, spec);
Assert.assertEquals(2, deletedSpecs.size());
for (ProgramSpecification specification : deletedSpecs) {
//Remove the spec that is verified, to check the count later.
specsToBeDeleted.remove(specification.getName());
}
//2 specs should have been deleted and 0 should be remaining.
Assert.assertEquals(0, specsToBeDeleted.size());
}
use of co.cask.cdap.api.ProgramSpecification in project cdap by caskdata.
the class ApplicationVerificationStage method verifyPrograms.
protected void verifyPrograms(ApplicationId appId, ApplicationSpecification specification) {
Iterable<ProgramSpecification> programSpecs = Iterables.concat(specification.getFlows().values(), specification.getMapReduce().values(), specification.getWorkflows().values());
VerifyResult result;
for (ProgramSpecification programSpec : programSpecs) {
result = getVerifier(programSpec.getClass()).verify(appId, programSpec);
if (!result.isSuccess()) {
throw new RuntimeException(result.getMessage());
}
}
for (Map.Entry<String, WorkflowSpecification> entry : specification.getWorkflows().entrySet()) {
verifyWorkflowSpecifications(specification, entry.getValue());
}
for (Map.Entry<String, ScheduleCreationSpec> entry : specification.getProgramSchedules().entrySet()) {
String programName = entry.getValue().getProgramName();
if (!specification.getWorkflows().containsKey(programName)) {
throw new RuntimeException(String.format("Schedule '%s' is invalid: Workflow '%s' is not configured " + "in application '%s'", entry.getValue().getName(), programName, specification.getName()));
}
// TODO StreamSizeSchedules should be resilient to stream inexistence [CDAP-1446]
Trigger trigger = entry.getValue().getTrigger();
if (trigger instanceof StreamSizeTrigger) {
StreamId streamId = ((StreamSizeTrigger) trigger).getStreamId();
if (!specification.getStreams().containsKey(streamId.getStream()) && store.getStream(streamId.getParent(), streamId.getStream()) == null) {
throw new RuntimeException(String.format("Schedule '%s' uses a Stream '%s' that does not exit", entry.getValue().getName(), streamId));
}
}
}
}
use of co.cask.cdap.api.ProgramSpecification in project cdap by caskdata.
the class ProgramLifecycleService method getExistingAppProgramStatus.
/**
* Returns the program status with no need of application existence check.
* @param appSpec the ApplicationSpecification of the existing application
* @param programId the id of the program for which the status call is made
* @return the status of the program
* @throws NotFoundException if the application to which this program belongs was not found
*/
private ProgramStatus getExistingAppProgramStatus(ApplicationSpecification appSpec, ProgramId programId) throws Exception {
ProgramRuntimeService.RuntimeInfo runtimeInfo = findRuntimeInfo(programId);
if (runtimeInfo == null) {
if (programId.getType() != ProgramType.WEBAPP) {
//Runtime info not found. Check to see if the program exists.
ProgramSpecification spec = getExistingAppProgramSpecification(appSpec, programId);
if (spec == null) {
// program doesn't exist
throw new NotFoundException(programId);
}
ensureAccess(programId);
if ((programId.getType() == ProgramType.MAPREDUCE || programId.getType() == ProgramType.SPARK) && !store.getRuns(programId, ProgramRunStatus.RUNNING, 0, Long.MAX_VALUE, 1).isEmpty()) {
// MapReduce program exists and running as a part of Workflow
return ProgramStatus.RUNNING;
}
return ProgramStatus.STOPPED;
}
throw new IllegalStateException("Webapp status is not supported");
}
return runtimeInfo.getController().getState().getProgramStatus();
}
use of co.cask.cdap.api.ProgramSpecification in project cdap by caskdata.
the class ProgramLifecycleHttpHandler method programSpecification.
@GET
@Path("/apps/{app-name}/versions/{app-version}/{program-type}/{program-name}")
public void programSpecification(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-name") String appName, @PathParam("app-version") String appVersion, @PathParam("program-type") String type, @PathParam("program-name") String programName) throws Exception {
ProgramType programType = getProgramType(type);
if (programType == null) {
throw new MethodNotAllowedException(request.getMethod(), request.getUri());
}
ApplicationId application = new ApplicationId(namespaceId, appName, appVersion);
ProgramId programId = application.program(programType, programName);
ProgramSpecification specification = lifecycleService.getProgramSpecification(programId);
if (specification == null) {
throw new NotFoundException(programId);
}
responder.sendJson(HttpResponseStatus.OK, specification);
}
Aggregations