use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class ApplicationLifecycleService method removeAll.
/**
* Remove all the applications inside the given {@link Id.Namespace}
*
* @param namespaceId the {@link NamespaceId} under which all application should be deleted
* @throws Exception
*/
public void removeAll(final NamespaceId namespaceId) throws Exception {
Map<ProgramRunId, RunRecordMeta> runningPrograms = store.getActiveRuns(namespaceId);
List<ApplicationSpecification> allSpecs = new ArrayList<>(store.getAllApplications(namespaceId));
Map<ApplicationId, ApplicationSpecification> apps = new HashMap<>();
for (ApplicationSpecification appSpec : allSpecs) {
ApplicationId applicationId = namespaceId.app(appSpec.getName(), appSpec.getAppVersion());
authorizationEnforcer.enforce(applicationId, authenticationContext.getPrincipal(), Action.ADMIN);
apps.put(applicationId, appSpec);
}
if (!runningPrograms.isEmpty()) {
Set<String> activePrograms = new HashSet<>();
for (Map.Entry<ProgramRunId, RunRecordMeta> runningProgram : runningPrograms.entrySet()) {
activePrograms.add(runningProgram.getKey().getApplication() + ": " + runningProgram.getKey().getProgram());
}
String appAllRunningPrograms = Joiner.on(',').join(activePrograms);
throw new CannotBeDeletedException(namespaceId, "The following programs are still running: " + appAllRunningPrograms);
}
// All Apps are STOPPED, delete them
for (ApplicationId appId : apps.keySet()) {
removeAppInternal(appId, apps.get(appId));
}
}
use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class DefaultStore method getDeletedProgramSpecifications.
// todo: this method should be moved into DeletedProgramHandlerState, bad design otherwise
@Override
public List<ProgramSpecification> getDeletedProgramSpecifications(ApplicationId id, ApplicationSpecification appSpec) {
ApplicationMeta existing = Transactionals.execute(transactional, context -> {
return getAppMetadataStore(context).getApplication(id.getNamespace(), id.getApplication(), id.getVersion());
});
List<ProgramSpecification> deletedProgramSpecs = Lists.newArrayList();
if (existing != null) {
ApplicationSpecification existingAppSpec = existing.getSpec();
Map<String, ProgramSpecification> existingSpec = ImmutableMap.<String, ProgramSpecification>builder().putAll(existingAppSpec.getMapReduce()).putAll(existingAppSpec.getSpark()).putAll(existingAppSpec.getWorkflows()).putAll(existingAppSpec.getFlows()).putAll(existingAppSpec.getServices()).putAll(existingAppSpec.getWorkers()).build();
Map<String, ProgramSpecification> newSpec = ImmutableMap.<String, ProgramSpecification>builder().putAll(appSpec.getMapReduce()).putAll(appSpec.getSpark()).putAll(appSpec.getWorkflows()).putAll(appSpec.getFlows()).putAll(appSpec.getServices()).putAll(appSpec.getWorkers()).build();
MapDifference<String, ProgramSpecification> mapDiff = Maps.difference(existingSpec, newSpec);
deletedProgramSpecs.addAll(mapDiff.entriesOnlyOnLeft().values());
}
return deletedProgramSpecs;
}
use of co.cask.cdap.api.app.ApplicationSpecification 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.app.ApplicationSpecification in project cdap by caskdata.
the class ProgramLifecycleService method getProgramStatus.
/**
* Returns the program status.
* @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
*/
public ProgramStatus getProgramStatus(ProgramId programId) throws Exception {
// check that app exists
ApplicationId appId = programId.getParent();
ApplicationSpecification appSpec = store.getApplication(appId);
if (appSpec == null) {
throw new NotFoundException(appId);
}
return getExistingAppProgramStatus(appSpec, programId);
}
use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class ExistingEntitySystemMetadataWriter method writeSystemMetadataForApps.
private void writeSystemMetadataForApps(NamespaceId namespace) {
for (ApplicationSpecification appSpec : store.getAllApplications(namespace)) {
ApplicationId app = namespace.app(appSpec.getName());
SystemMetadataWriter writer = new AppSystemMetadataWriter(metadataStore, app, appSpec);
writer.write();
writeSystemMetadataForPrograms(app, appSpec);
}
}
Aggregations