Search in sources :

Example 1 with ServiceDeleted

use of cz.metacentrum.perun.audit.events.ServicesManagerEvents.ServiceDeleted 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)

Aggregations

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 DestinationAddedToServiceAndFacility (cz.metacentrum.perun.audit.events.ServicesManagerEvents.DestinationAddedToServiceAndFacility)1 ServiceDeleted (cz.metacentrum.perun.audit.events.ServicesManagerEvents.ServiceDeleted)1 Facility (cz.metacentrum.perun.core.api.Facility)1 Resource (cz.metacentrum.perun.core.api.Resource)1 FacilityNotExistsException (cz.metacentrum.perun.core.api.exceptions.FacilityNotExistsException)1 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)1 RelationExistsException (cz.metacentrum.perun.core.api.exceptions.RelationExistsException)1 ServiceNotAssignedException (cz.metacentrum.perun.core.api.exceptions.ServiceNotAssignedException)1 ResourcesManagerBl (cz.metacentrum.perun.core.bl.ResourcesManagerBl)1