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