Search in sources :

Example 1 with HostExistsException

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

the class FacilitiesManagerBlImpl method addHosts.

public List<Host> addHosts(PerunSession sess, List<Host> hosts, Facility facility) throws InternalErrorException, HostExistsException {
    //check if hosts not exist in cluster
    List<Host> alreadyAssignedHosts = getHosts(sess, facility);
    Set<String> alreadyAssignedHostnames = new HashSet<String>();
    Set<String> newHostnames = new HashSet<String>();
    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) {
        host = getFacilitiesManagerImpl().addHost(sess, host, facility);
    }
    getPerunBl().getAuditer().log(sess, "Hosts {} added to cluster {}", hosts, facility);
    return hosts;
}
Also used : HostExistsException(cz.metacentrum.perun.core.api.exceptions.HostExistsException) Host(cz.metacentrum.perun.core.api.Host) HashSet(java.util.HashSet)

Aggregations

Host (cz.metacentrum.perun.core.api.Host)1 HostExistsException (cz.metacentrum.perun.core.api.exceptions.HostExistsException)1 HashSet (java.util.HashSet)1