use of cz.metacentrum.perun.audit.events.FacilityManagerEvents.FacilityDeleted in project perun by CESNET.
the class FacilitiesManagerBlImpl method deleteFacility.
@Override
public void deleteFacility(PerunSession sess, Facility facility, Boolean force) throws RelationExistsException, FacilityAlreadyRemovedException, HostAlreadyRemovedException, ResourceAlreadyRemovedException, GroupAlreadyRemovedFromResourceException {
if (force) {
List<Resource> resources = this.getAssignedResources(sess, facility);
for (Resource resource : resources) {
getPerunBl().getResourcesManagerBl().deleteResource(sess, resource);
}
List<Task> tasks = perunBl.getTasksManagerBl().listAllTasksForFacility(sess, facility.getId());
for (Task task : tasks) {
perunBl.getTasksManagerBl().deleteTaskResults(sess, task.getId());
perunBl.getTasksManagerBl().removeTask(sess, task.getId());
}
} else {
if (getFacilitiesManagerImpl().getAssignedResources(sess, facility).size() > 0) {
throw new RelationExistsException("Facility is still used as a resource");
}
}
// remove admins of this facility
List<Group> adminGroups = getFacilitiesManagerImpl().getAdminGroups(sess, facility);
for (Group adminGroup : adminGroups) {
try {
AuthzResolverBlImpl.unsetRole(sess, adminGroup, facility, Role.FACILITYADMIN);
} catch (GroupNotAdminException e) {
log.warn("When trying to unsetRole FacilityAdmin for group {} in the facility {} the exception was thrown {}", adminGroup, facility, e);
// skip and log as warning
} catch (RoleCannotBeManagedException e) {
throw new InternalErrorException(e);
}
}
List<User> adminUsers = getFacilitiesManagerImpl().getAdmins(sess, facility);
for (User adminUser : adminUsers) {
try {
AuthzResolverBlImpl.unsetRole(sess, adminUser, facility, Role.FACILITYADMIN);
} catch (UserNotAdminException e) {
log.warn("When trying to unsetRole FacilityAdmin for user {} in the facility {} the exception was thrown {}", adminUser, facility, e);
// skip and log as warning
} catch (RoleCannotBeManagedException e) {
throw new InternalErrorException(e);
}
}
// remove hosts
List<Host> hosts = this.getHosts(sess, facility);
for (Host host : hosts) {
this.removeHost(sess, host, facility);
}
// remove destinations
getPerunBl().getServicesManagerBl().removeAllDestinations(sess, facility);
// remove assigned security teams
List<SecurityTeam> teams = getAssignedSecurityTeams(sess, facility);
for (SecurityTeam team : teams) {
removeSecurityTeam(sess, facility, team);
}
// remove associated attributes
try {
getPerunBl().getAttributesManagerBl().removeAllAttributes(sess, facility);
} catch (WrongAttributeValueException | WrongReferenceAttributeValueException e) {
throw new InternalErrorException(e);
}
// Remove all facility bans
List<BanOnFacility> bansOnFacility = this.getBansForFacility(sess, facility.getId());
for (BanOnFacility banOnFacility : bansOnFacility) {
try {
this.removeBan(sess, banOnFacility.getId());
} catch (BanNotExistsException ex) {
// it is ok, we just want to remove it anyway
}
}
// Remove all service denials
getFacilitiesManagerImpl().removeAllServiceDenials(facility.getId());
// delete facility
getFacilitiesManagerImpl().deleteFacilityOwners(sess, facility);
getFacilitiesManagerImpl().deleteFacility(sess, facility);
getPerunBl().getAuditer().log(sess, new FacilityDeleted(facility));
}
Aggregations