use of cz.metacentrum.perun.audit.events.VoManagerEvents.VoDeleted in project perun by CESNET.
the class VosManagerBlImpl method deleteVo.
@Override
public void deleteVo(PerunSession sess, Vo vo, boolean forceDelete) {
log.debug("Deleting vo {}", vo);
try {
// remove admins of this vo
List<Group> adminGroups = getVosManagerImpl().getAdminGroups(sess, vo);
for (Group adminGroup : adminGroups) {
try {
AuthzResolverBlImpl.unsetRole(sess, adminGroup, vo, Role.VOADMIN);
} catch (GroupNotAdminException e) {
log.warn("When trying to unsetRole VoAdmin for group {} in the vo {} the exception was thrown {}", adminGroup, vo, e);
// skip and log as warning
}
}
List<User> adminUsers = getVosManagerImpl().getAdmins(sess, vo);
for (User adminUser : adminUsers) {
try {
AuthzResolverBlImpl.unsetRole(sess, adminUser, vo, Role.VOADMIN);
} catch (UserNotAdminException e) {
log.warn("When trying to unsetRole VoAdmin for user {} in the vo {} the exception was thrown {}", adminUser, vo, e);
// skip and log as warning
}
}
List<Member> members = getPerunBl().getMembersManagerBl().getMembers(sess, vo);
log.debug("Deleting vo {} members", vo);
// Check if there are some members left
if (members != null && members.size() > 0) {
if (forceDelete) {
getPerunBl().getMembersManagerBl().deleteAllMembers(sess, vo);
} else
throw new RelationExistsException("Vo vo=" + vo + " contains members");
}
log.debug("Removing vo {} resources and theirs attributes", vo);
// Delete resources
List<Resource> resources = getPerunBl().getResourcesManagerBl().getResources(sess, vo);
if ((resources.size() == 0) || forceDelete) {
for (Resource resource : resources) {
getPerunBl().getAttributesManagerBl().removeAllAttributes(sess, resource);
// Remove binding between service and resource
List<Service> services = getPerunBl().getResourcesManagerBl().getAssignedServices(sess, resource);
for (Service service : services) {
getPerunBl().getResourcesManagerBl().removeService(sess, resource, service);
}
getPerunBl().getResourcesManagerBl().deleteResource(sess, resource);
}
} else {
throw new RelationExistsException("Vo vo=" + vo + " contains resources");
}
log.debug("Removing vo {} groups", vo);
// Delete all groups
List<Group> groups = getPerunBl().getGroupsManagerBl().getGroups(sess, vo);
if (groups.size() != 1) {
if (groups.size() < 1)
throw new ConsistencyErrorException("'members' group is missing");
if (forceDelete) {
getPerunBl().getGroupsManagerBl().deleteAllGroups(sess, vo);
} else {
throw new RelationExistsException("Vo vo=" + vo + " contains groups");
}
}
// Finally delete binding between Vo and external source
List<ExtSource> ess = getPerunBl().getExtSourcesManagerBl().getVoExtSources(sess, vo);
log.debug("Deleting {} external sources binded to the vo {}", ess.size(), vo);
for (ExtSource es : ess) {
getPerunBl().getExtSourcesManagerBl().removeExtSource(sess, vo, es);
}
// Delete members group
log.debug("Removing an administrators' group from the vo {}", vo);
getPerunBl().getGroupsManagerBl().deleteMembersGroup(sess, vo);
// delete all VO reserved logins from KDC
List<Integer> list = getVosManagerImpl().getVoApplicationIds(sess, vo);
for (Integer appId : list) {
// for each application
for (Pair<String, String> login : getVosManagerImpl().getApplicationReservedLogins(appId)) {
// for all reserved logins - delete them in ext. system (e.g. KDC)
try {
// !!! left = namespace / right = login !!!
getPerunBl().getUsersManagerBl().deletePassword(sess, login.getRight(), login.getLeft());
} catch (LoginNotExistsException ex) {
log.error("Login: {} not exists in namespace {} while deleting passwords", login.getRight(), login.getLeft());
}
}
}
// delete all VO reserved logins from DB
getVosManagerImpl().deleteVoReservedLogins(sess, vo);
// VO applications, submitted data and app_form are deleted on cascade with "deleteVo()"
// Delete VO attributes
getPerunBl().getAttributesManagerBl().removeAllAttributes(sess, vo);
// Delete all Vo tags (for resources in Vo)
getPerunBl().getResourcesManagerBl().deleteAllResourcesTagsForVo(sess, vo);
} catch (Exception ex) {
throw new InternalErrorException(ex);
}
// Finally delete the VO
Vo deletedVo = getVosManagerImpl().deleteVo(sess, vo);
getPerunBl().getAuditer().log(sess, new VoDeleted(deletedVo));
}
Aggregations