Search in sources :

Example 1 with FacilityDeleted

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));
}
Also used : Group(cz.metacentrum.perun.core.api.Group) RichGroup(cz.metacentrum.perun.core.api.RichGroup) Task(cz.metacentrum.perun.taskslib.model.Task) User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) Resource(cz.metacentrum.perun.core.api.Resource) RichResource(cz.metacentrum.perun.core.api.RichResource) FacilityDeleted(cz.metacentrum.perun.audit.events.FacilityManagerEvents.FacilityDeleted) GroupNotAdminException(cz.metacentrum.perun.core.api.exceptions.GroupNotAdminException) Host(cz.metacentrum.perun.core.api.Host) SecurityTeam(cz.metacentrum.perun.core.api.SecurityTeam) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) UserNotAdminException(cz.metacentrum.perun.core.api.exceptions.UserNotAdminException) RelationExistsException(cz.metacentrum.perun.core.api.exceptions.RelationExistsException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) BanOnFacility(cz.metacentrum.perun.core.api.BanOnFacility) RoleCannotBeManagedException(cz.metacentrum.perun.core.api.exceptions.RoleCannotBeManagedException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) BanNotExistsException(cz.metacentrum.perun.core.api.exceptions.BanNotExistsException)

Aggregations

FacilityDeleted (cz.metacentrum.perun.audit.events.FacilityManagerEvents.FacilityDeleted)1 BanOnFacility (cz.metacentrum.perun.core.api.BanOnFacility)1 Group (cz.metacentrum.perun.core.api.Group)1 Host (cz.metacentrum.perun.core.api.Host)1 Resource (cz.metacentrum.perun.core.api.Resource)1 RichGroup (cz.metacentrum.perun.core.api.RichGroup)1 RichResource (cz.metacentrum.perun.core.api.RichResource)1 RichUser (cz.metacentrum.perun.core.api.RichUser)1 SecurityTeam (cz.metacentrum.perun.core.api.SecurityTeam)1 User (cz.metacentrum.perun.core.api.User)1 BanNotExistsException (cz.metacentrum.perun.core.api.exceptions.BanNotExistsException)1 GroupNotAdminException (cz.metacentrum.perun.core.api.exceptions.GroupNotAdminException)1 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)1 RelationExistsException (cz.metacentrum.perun.core.api.exceptions.RelationExistsException)1 RoleCannotBeManagedException (cz.metacentrum.perun.core.api.exceptions.RoleCannotBeManagedException)1 UserNotAdminException (cz.metacentrum.perun.core.api.exceptions.UserNotAdminException)1 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)1 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)1 Task (cz.metacentrum.perun.taskslib.model.Task)1