Search in sources :

Example 1 with ServiceNotAssignedException

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

the class ServicesManagerBlImpl method deleteService.

/*
	 * Tables with reference to service:
	 *   - service_required_attrs
	 *   - service_denials
	 *   - resource_services
	 *   - facility_service_destinations
	 *   - service_service_packages
	 *   - tasks
	 *   - authz
	 */
@Override
public void deleteService(PerunSession perunSession, Service service, boolean forceFlag) throws RelationExistsException, ServiceAlreadyRemovedException {
    List<Resource> assignedResources = this.getAssignedResources(perunSession, service);
    if (forceFlag) {
        // Remove all denials for this service
        getServicesManagerImpl().unblockService(service.getId());
        // Remove from assigned resources
        ResourcesManagerBl resourcesManager = getPerunBl().getResourcesManagerBl();
        for (Resource resource : assignedResources) {
            try {
                resourcesManager.removeService(perunSession, resource, service);
                // Remove from facility_service_destinations
                Facility facility = getPerunBl().getFacilitiesManagerBl().getFacilityById(perunSession, resource.getFacilityId());
                removeAllDestinations(perunSession, service, facility);
            } catch (ServiceNotAssignedException | FacilityNotExistsException e) {
                // should not happen
                throw new InternalErrorException("Error removing service", e);
            }
        }
        // Remove from service packages
        getServicesManagerImpl().removeServiceFromAllServicesPackages(perunSession, service);
        // Remove all related tasks
        getPerunBl().getTasksManagerBl().removeAllTasksForService(perunSession, service);
    } else {
        if (assignedResources.size() > 0) {
            throw new RelationExistsException("Service is defined on some resource");
        }
    }
    getServicesManagerImpl().removeAllRequiredAttributes(perunSession, service);
    getServicesManagerImpl().deleteService(perunSession, service);
    getPerunBl().getAuditer().log(perunSession, new ServiceDeleted(service));
}
Also used : ResourcesManagerBl(cz.metacentrum.perun.core.bl.ResourcesManagerBl) RelationExistsException(cz.metacentrum.perun.core.api.exceptions.RelationExistsException) Resource(cz.metacentrum.perun.core.api.Resource) FacilityNotExistsException(cz.metacentrum.perun.core.api.exceptions.FacilityNotExistsException) DestinationAddedToServiceAndFacility(cz.metacentrum.perun.audit.events.ServicesManagerEvents.DestinationAddedToServiceAndFacility) Facility(cz.metacentrum.perun.core.api.Facility) BanServiceOnFacility(cz.metacentrum.perun.audit.events.GeneralServiceManagerEvents.BanServiceOnFacility) FreeAllDenialsOnFacility(cz.metacentrum.perun.audit.events.GeneralServiceManagerEvents.FreeAllDenialsOnFacility) FreeDenialServiceOnFacility(cz.metacentrum.perun.audit.events.GeneralServiceManagerEvents.FreeDenialServiceOnFacility) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) ServiceDeleted(cz.metacentrum.perun.audit.events.ServicesManagerEvents.ServiceDeleted) ServiceNotAssignedException(cz.metacentrum.perun.core.api.exceptions.ServiceNotAssignedException)

Example 2 with ServiceNotAssignedException

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

the class ResourcesManagerBlImpl method deleteResource.

@Override
public void deleteResource(PerunSession sess, Resource resource) throws ResourceAlreadyRemovedException, GroupAlreadyRemovedFromResourceException {
    // Get facility for audit messages
    Facility facility = this.getFacility(sess, resource);
    // remove admins of this resource
    List<Group> adminGroups = getResourcesManagerImpl().getAdminGroups(sess, resource);
    for (Group adminGroup : adminGroups) {
        try {
            AuthzResolverBlImpl.unsetRole(sess, adminGroup, resource, Role.RESOURCEADMIN);
        } catch (GroupNotAdminException e) {
            log.warn("When trying to unsetRole ResourceAdmin for group {} in the resource {} the exception was thrown {}", adminGroup, resource, e);
        // skip and log as warning
        } catch (RoleCannotBeManagedException e) {
            throw new InternalErrorException(e);
        }
    }
    List<User> adminUsers = getResourcesManagerImpl().getAdmins(sess, resource);
    for (User adminUser : adminUsers) {
        try {
            AuthzResolverBlImpl.unsetRole(sess, adminUser, resource, Role.RESOURCEADMIN);
        } catch (UserNotAdminException e) {
            log.warn("When trying to unsetRole ResourceAdmin for user {} in the resource {} the exception was thrown {}", adminUser, resource, e);
        // skip and log as warning
        } catch (RoleCannotBeManagedException e) {
            throw new InternalErrorException(e);
        }
    }
    // Remove binding between resource and service
    List<Service> services = getAssignedServices(sess, resource);
    for (Service service : services) {
        try {
            this.removeService(sess, resource, service);
        } catch (ServiceNotAssignedException e) {
            throw new ConsistencyErrorException(e);
        }
    }
    List<AssignedGroup> assignedGroups = getGroupAssignments(sess, resource, List.of());
    for (AssignedGroup assignedGroup : assignedGroups) {
        if (assignedGroup.getSourceGroupId() == null) {
            try {
                removeGroupFromResource(sess, assignedGroup.getEnrichedGroup().getGroup(), resource);
            } catch (GroupNotDefinedOnResourceException ex) {
                throw new GroupAlreadyRemovedFromResourceException(ex);
            }
        }
    }
    // Remove attr values for the resource
    try {
        perunBl.getAttributesManagerBl().removeAllAttributes(sess, resource);
    } catch (AttributeValueException ex) {
        throw new ConsistencyErrorException("All services are removed from this resource. There is no required attribute. So all attribtes for this resource can be removed withou problem.", ex);
    }
    // Remove group-resource attr values for all group and resource
    try {
        this.perunBl.getAttributesManagerBl().removeAllGroupResourceAttributes(sess, resource);
    } catch (WrongAttributeValueException | GroupResourceMismatchException | WrongReferenceAttributeValueException ex) {
        throw new InternalErrorException(ex);
    }
    // Remove all resources tags
    this.removeAllResourcesTagFromResource(sess, resource);
    // Remove all resource bans
    List<BanOnResource> bansOnResource = this.getBansForResource(sess, resource.getId());
    for (BanOnResource banOnResource : bansOnResource) {
        try {
            this.removeBan(sess, banOnResource.getId());
        } catch (BanNotExistsException ex) {
        // it is ok, we just want to remove it anyway
        }
    }
    // Because resource will be tottaly deleted, we can also delete all member-resource attributes
    this.perunBl.getAttributesManagerBl().removeAllMemberResourceAttributes(sess, resource);
    // Get the resource VO
    Vo vo = this.getVo(sess, resource);
    getResourcesManagerImpl().deleteResource(sess, vo, resource);
    getPerunBl().getAuditer().log(sess, new ResourceDeleted(resource, facility));
}
Also used : AssignedGroup(cz.metacentrum.perun.core.api.AssignedGroup) Group(cz.metacentrum.perun.core.api.Group) ResourceSelfServiceAddedForGroup(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceSelfServiceAddedForGroup) ResourceSelfServiceRemovedForGroup(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceSelfServiceRemovedForGroup) User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) ResourceSelfServiceRemovedForUser(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceSelfServiceRemovedForUser) AttributeValueException(cz.metacentrum.perun.core.api.exceptions.AttributeValueException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) GroupResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException) UserNotAdminException(cz.metacentrum.perun.core.api.exceptions.UserNotAdminException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) GroupNotDefinedOnResourceException(cz.metacentrum.perun.core.api.exceptions.GroupNotDefinedOnResourceException) Vo(cz.metacentrum.perun.core.api.Vo) ResourceDeleted(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceDeleted) ServiceNotAssignedException(cz.metacentrum.perun.core.api.exceptions.ServiceNotAssignedException) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Service(cz.metacentrum.perun.core.api.Service) GroupNotAdminException(cz.metacentrum.perun.core.api.exceptions.GroupNotAdminException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) BanOnResource(cz.metacentrum.perun.core.api.BanOnResource) Facility(cz.metacentrum.perun.core.api.Facility) RoleCannotBeManagedException(cz.metacentrum.perun.core.api.exceptions.RoleCannotBeManagedException) GroupAlreadyRemovedFromResourceException(cz.metacentrum.perun.core.api.exceptions.GroupAlreadyRemovedFromResourceException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) AssignedGroup(cz.metacentrum.perun.core.api.AssignedGroup) BanNotExistsException(cz.metacentrum.perun.core.api.exceptions.BanNotExistsException)

Aggregations

Facility (cz.metacentrum.perun.core.api.Facility)2 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)2 ServiceNotAssignedException (cz.metacentrum.perun.core.api.exceptions.ServiceNotAssignedException)2 BanServiceOnFacility (cz.metacentrum.perun.audit.events.GeneralServiceManagerEvents.BanServiceOnFacility)1 FreeAllDenialsOnFacility (cz.metacentrum.perun.audit.events.GeneralServiceManagerEvents.FreeAllDenialsOnFacility)1 FreeDenialServiceOnFacility (cz.metacentrum.perun.audit.events.GeneralServiceManagerEvents.FreeDenialServiceOnFacility)1 ResourceDeleted (cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceDeleted)1 ResourceSelfServiceAddedForGroup (cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceSelfServiceAddedForGroup)1 ResourceSelfServiceRemovedForGroup (cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceSelfServiceRemovedForGroup)1 ResourceSelfServiceRemovedForUser (cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceSelfServiceRemovedForUser)1 DestinationAddedToServiceAndFacility (cz.metacentrum.perun.audit.events.ServicesManagerEvents.DestinationAddedToServiceAndFacility)1 ServiceDeleted (cz.metacentrum.perun.audit.events.ServicesManagerEvents.ServiceDeleted)1 AssignedGroup (cz.metacentrum.perun.core.api.AssignedGroup)1 BanOnResource (cz.metacentrum.perun.core.api.BanOnResource)1 Group (cz.metacentrum.perun.core.api.Group)1 Resource (cz.metacentrum.perun.core.api.Resource)1 RichUser (cz.metacentrum.perun.core.api.RichUser)1 Service (cz.metacentrum.perun.core.api.Service)1 User (cz.metacentrum.perun.core.api.User)1 Vo (cz.metacentrum.perun.core.api.Vo)1