use of co.cask.cdap.common.CannotBeDeletedException 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));
}
}
Aggregations