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