Search in sources :

Example 1 with HostAddedToFacility

use of cz.metacentrum.perun.audit.events.FacilityManagerEvents.HostAddedToFacility in project perun by CESNET.

the class FacilitiesManagerBlImpl method addHosts.

@Override
public List<Host> addHosts(PerunSession sess, List<Host> hosts, Facility facility) throws HostExistsException {
    // check if hosts not exist in cluster
    List<Host> alreadyAssignedHosts = getHosts(sess, facility);
    Set<String> alreadyAssignedHostnames = new HashSet<>();
    Set<String> newHostnames = new HashSet<>();
    for (Host h : alreadyAssignedHosts) alreadyAssignedHostnames.add(h.getHostname());
    for (Host h : hosts) newHostnames.add(h.getHostname());
    newHostnames.retainAll(alreadyAssignedHostnames);
    if (!newHostnames.isEmpty())
        throw new HostExistsException(newHostnames.toString());
    for (Host host : hosts) {
        getFacilitiesManagerImpl().addHost(sess, host, facility);
        getPerunBl().getAuditer().log(sess, new HostAddedToFacility(host, facility));
    }
    return hosts;
}
Also used : HostExistsException(cz.metacentrum.perun.core.api.exceptions.HostExistsException) HostAddedToFacility(cz.metacentrum.perun.audit.events.FacilityManagerEvents.HostAddedToFacility) Host(cz.metacentrum.perun.core.api.Host) HashSet(java.util.HashSet)

Aggregations

HostAddedToFacility (cz.metacentrum.perun.audit.events.FacilityManagerEvents.HostAddedToFacility)1 Host (cz.metacentrum.perun.core.api.Host)1 HostExistsException (cz.metacentrum.perun.core.api.exceptions.HostExistsException)1 HashSet (java.util.HashSet)1