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));
}
Aggregations