use of io.cdap.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(NamespaceId namespaceId) throws Exception {
Map<ProgramRunId, RunRecordDetail> 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());
accessEnforcer.enforce(applicationId, authenticationContext.getPrincipal(), StandardPermission.DELETE);
apps.put(applicationId, appSpec);
}
if (!runningPrograms.isEmpty()) {
Set<String> activePrograms = new HashSet<>();
for (Map.Entry<ProgramRunId, RunRecordDetail> 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