Search in sources :

Example 6 with RelationExistsException

use of cz.metacentrum.perun.core.api.exceptions.RelationExistsException in project perun by CESNET.

the class ServicesManagerBlImpl method removeAllDestinations.

@Override
public void removeAllDestinations(PerunSession sess, Service service, Facility facility) {
    List<Destination> destinations = getDestinations(sess, service, facility);
    getServicesManagerImpl().removeAllDestinations(sess, service, facility);
    // remove destinations from destination table if they are not used anymore
    for (Destination destination : destinations) {
        try {
            this.deleteDestination(sess, destination);
        } catch (RelationExistsException | DestinationAlreadyRemovedException ex) {
        // destination is used by some services and facilities or it is already removed, skip the destination
        }
    }
    getPerunBl().getAuditer().log(sess, new DestinationsRemovedFromService(service, facility));
}
Also used : FreeDenialServiceOnDestination(cz.metacentrum.perun.audit.events.GeneralServiceManagerEvents.FreeDenialServiceOnDestination) BanServiceOnDestination(cz.metacentrum.perun.audit.events.GeneralServiceManagerEvents.BanServiceOnDestination) RichDestination(cz.metacentrum.perun.core.api.RichDestination) Destination(cz.metacentrum.perun.core.api.Destination) FreeAllDenialsOnDestination(cz.metacentrum.perun.audit.events.GeneralServiceManagerEvents.FreeAllDenialsOnDestination) RelationExistsException(cz.metacentrum.perun.core.api.exceptions.RelationExistsException) DestinationAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.DestinationAlreadyRemovedException) DestinationsRemovedFromService(cz.metacentrum.perun.audit.events.ServicesManagerEvents.DestinationsRemovedFromService)

Example 7 with RelationExistsException

use of cz.metacentrum.perun.core.api.exceptions.RelationExistsException in project perun by CESNET.

the class ServicesManagerBlImpl method removeAllDestinations.

@Override
public void removeAllDestinations(PerunSession perunSession, Facility facility) {
    List<Destination> destinations = getDestinations(perunSession, facility);
    getServicesManagerImpl().removeAllDestinations(perunSession, facility);
    // remove destinations from destination table if they are not used anymore
    for (Destination destination : destinations) {
        try {
            this.deleteDestination(perunSession, destination);
        } catch (RelationExistsException | DestinationAlreadyRemovedException ex) {
        // destination is used by some services and facilities or it is already removed, skip the destination
        }
    }
    getPerunBl().getAuditer().log(perunSession, new DestinationsRemovedFromAllServices(facility));
}
Also used : FreeDenialServiceOnDestination(cz.metacentrum.perun.audit.events.GeneralServiceManagerEvents.FreeDenialServiceOnDestination) BanServiceOnDestination(cz.metacentrum.perun.audit.events.GeneralServiceManagerEvents.BanServiceOnDestination) RichDestination(cz.metacentrum.perun.core.api.RichDestination) Destination(cz.metacentrum.perun.core.api.Destination) FreeAllDenialsOnDestination(cz.metacentrum.perun.audit.events.GeneralServiceManagerEvents.FreeAllDenialsOnDestination) DestinationsRemovedFromAllServices(cz.metacentrum.perun.audit.events.ServicesManagerEvents.DestinationsRemovedFromAllServices) RelationExistsException(cz.metacentrum.perun.core.api.exceptions.RelationExistsException) DestinationAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.DestinationAlreadyRemovedException)

Example 8 with RelationExistsException

use of cz.metacentrum.perun.core.api.exceptions.RelationExistsException in project perun by CESNET.

the class ServicesManagerBlImpl method deleteServicesPackage.

@Override
public void deleteServicesPackage(PerunSession sess, ServicesPackage servicesPackage) throws RelationExistsException {
    if (getServicesFromServicesPackage(sess, servicesPackage).isEmpty()) {
        getServicesManagerImpl().deleteServicesPackage(sess, servicesPackage);
        getPerunBl().getAuditer().log(sess, new ServicesPackageDeleted(servicesPackage));
    } else {
        throw new RelationExistsException("There is one or more services in the services package. ServicesPackage=\"" + servicesPackage + "\"");
    }
}
Also used : RelationExistsException(cz.metacentrum.perun.core.api.exceptions.RelationExistsException) ServicesPackageDeleted(cz.metacentrum.perun.audit.events.ServicesManagerEvents.ServicesPackageDeleted)

Example 9 with RelationExistsException

use of cz.metacentrum.perun.core.api.exceptions.RelationExistsException in project perun by CESNET.

the class FacilitiesManagerBlImpl method deleteFacility.

public void deleteFacility(PerunSession sess, Facility facility) throws InternalErrorException, RelationExistsException, FacilityAlreadyRemovedException, HostAlreadyRemovedException, GroupAlreadyRemovedException, ResourceAlreadyRemovedException, GroupAlreadyRemovedFromResourceException {
    if (getFacilitiesManagerImpl().getAssignedResources(sess, facility).size() > 0) {
        throw new RelationExistsException("Facility is still used as a resource");
    }
    //remove hosts
    List<Host> hosts = this.getHosts(sess, facility);
    for (Host host : hosts) {
        this.removeHost(sess, host);
    }
    //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 assigned facility contacts
    List<ContactGroup> contacts = getFacilityContactGroups(sess, facility);
    if (contacts != null && !contacts.isEmpty()) {
        removeFacilityContacts(sess, contacts);
    }
    // remove associated attributes
    try {
        getPerunBl().getAttributesManagerBl().removeAllAttributes(sess, facility);
    } catch (WrongAttributeValueException e) {
        throw new InternalErrorException(e);
    } catch (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
        }
    }
    // delete facility
    getFacilitiesManagerImpl().deleteFacilityOwners(sess, facility);
    getFacilitiesManagerImpl().deleteFacility(sess, facility);
    getPerunBl().getAuditer().log(sess, "Facility deleted {}.", facility);
}
Also used : Host(cz.metacentrum.perun.core.api.Host) SecurityTeam(cz.metacentrum.perun.core.api.SecurityTeam) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) RelationExistsException(cz.metacentrum.perun.core.api.exceptions.RelationExistsException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) BanOnFacility(cz.metacentrum.perun.core.api.BanOnFacility) ContactGroup(cz.metacentrum.perun.core.api.ContactGroup) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) BanNotExistsException(cz.metacentrum.perun.core.api.exceptions.BanNotExistsException)

Example 10 with RelationExistsException

use of cz.metacentrum.perun.core.api.exceptions.RelationExistsException 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

RelationExistsException (cz.metacentrum.perun.core.api.exceptions.RelationExistsException)18 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)12 User (cz.metacentrum.perun.core.api.User)8 RichUser (cz.metacentrum.perun.core.api.RichUser)6 Group (cz.metacentrum.perun.core.api.Group)5 Member (cz.metacentrum.perun.core.api.Member)5 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)5 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)5 Facility (cz.metacentrum.perun.core.api.Facility)4 Resource (cz.metacentrum.perun.core.api.Resource)4 GroupNotAdminException (cz.metacentrum.perun.core.api.exceptions.GroupNotAdminException)4 RoleCannotBeManagedException (cz.metacentrum.perun.core.api.exceptions.RoleCannotBeManagedException)4 UserNotAdminException (cz.metacentrum.perun.core.api.exceptions.UserNotAdminException)4 AllUserExtSourcesDeletedForUser (cz.metacentrum.perun.audit.events.UserManagerEvents.AllUserExtSourcesDeletedForUser)3 Attribute (cz.metacentrum.perun.core.api.Attribute)3 BanOnFacility (cz.metacentrum.perun.core.api.BanOnFacility)3 RichGroup (cz.metacentrum.perun.core.api.RichGroup)3 RichMember (cz.metacentrum.perun.core.api.RichMember)3 SecurityTeam (cz.metacentrum.perun.core.api.SecurityTeam)3 BanNotExistsException (cz.metacentrum.perun.core.api.exceptions.BanNotExistsException)3