use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.
the class ComputeUtils method deactivateHosts.
/**
* Deactivate a list of hosts.
*
* @param hosts hosts to deactivate
* @return list of hosts that were successfully deactivated
*/
public static List<Host> deactivateHosts(List<Host> hosts) {
List<Host> hostsDeactivated = new ArrayList<>();
Map<URI, String> hostURIMap = new HashMap<URI, String>();
for (Host host : hosts) {
hostURIMap.put(host.getId(), host.getLabel());
}
List<URI> deactivatedHostURIs = deactivateHostURIs(hostURIMap);
ListIterator<Host> hostItr = nonNull(hosts).listIterator();
while (hostItr.hasNext()) {
Host host = hostItr.next();
if (deactivatedHostURIs.contains(host.getId())) {
hostsDeactivated.add(host);
}
}
return hostsDeactivated;
}
use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.
the class ComputeUtils method deactivateHostsWithNoOS.
/**
* Deactivate hosts which failed the OS install process
* @param hosts {@link List} hosts that need to be verified for OS install
* @return {@link List} hostsWithOS
*/
public static List<Host> deactivateHostsWithNoOS(List<Host> hosts) {
if (nonNull(hosts).isEmpty()) {
return Collections.emptyList();
}
List<Host> hostsWithOS = Lists.newArrayList();
Map<URI, String> hostDeactivateMap = new HashMap<URI, String>();
for (Host osHost : hosts) {
Host host = execute(new GetHost(osHost.getId()));
if (host.getType() != null && host.getType().equalsIgnoreCase(Host.HostType.No_OS.name())) {
hostDeactivateMap.put(host.getId(), host.getLabel());
} else {
hostsWithOS.add(host);
}
}
// Deactivate hosts which failed the OS install step
if (MapUtils.isNotEmpty(hostDeactivateMap)) {
ExecutionUtils.currentContext().logError("computeutils.installOs.installing.failure.task.deactivate.failedinstallOSHost", hostDeactivateMap.values());
deactivateHostURIs(hostDeactivateMap);
}
return hostsWithOS;
}
use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.
the class ComputeUtils method createHosts.
/**
* Creates tasks to provision specified hosts to the given cluster.
* @param Cluster
* @param URI of computeVirtualPool to pick blades from
* @param List of hostNames
* @param URI of varray
* @return list of successfully created hosts
*/
public static List<Host> createHosts(Cluster cluster, URI vcp, List<String> hostNamesIn, URI varray) throws Exception {
// new hosts will be created with lower case hostNames. force it here so we can find host afterwards
List<String> hostNames = Lists.newArrayList();
for (String hostNameIn : hostNamesIn) {
hostNames.add(hostNameIn != null ? hostNameIn.toLowerCase() : null);
}
List<Host> createdHosts = new ArrayList<>();
Tasks<HostRestRep> tasks = null;
try {
tasks = execute(new CreateHosts(vcp, cluster.getId(), hostNames, varray));
} catch (Exception e) {
ExecutionUtils.currentContext().logError("computeutils.createhosts.failure", hostNames, e.getMessage());
}
// Some tasks could succeed while others could error out.
Map<URI, String> hostDeactivateMap = new HashMap<URI, String>();
if ((tasks != null) && (tasks.getTasks() != null)) {
List<Task<HostRestRep>> tasklist = tasks.getTasks();
List<Task<HostRestRep>> oritasklist = tasks.getTasks();
while (!tasklist.isEmpty()) {
tasklist = waitAndRefresh(tasklist);
for (Task<HostRestRep> successfulTask : getSuccessfulTasks(tasklist)) {
URI hostUri = successfulTask.getResourceId();
addAffectedResource(hostUri);
Host host = execute(new GetHost(hostUri));
createdHosts.add(host);
tasklist.remove(successfulTask);
oritasklist.remove(successfulTask);
}
for (Task<HostRestRep> failedTask : getFailedTasks(tasklist)) {
ExecutionUtils.currentContext().logError("computeutils.createhosts.failure.task", failedTask.getResource().getName(), failedTask.getMessage());
hostDeactivateMap.put(failedTask.getResourceId(), failedTask.getResource().getName());
tasklist.remove(failedTask);
oritasklist.remove(failedTask);
}
}
for (Task<HostRestRep> hostToRemove : oritasklist) {
hostDeactivateMap.put(hostToRemove.getResourceId(), hostToRemove.getResource().getName());
}
} else {
ExecutionUtils.currentContext().logError("computeutils.createhosts.noTasks,created", hostNames);
}
// Deactivate hosts that failed in the create step
if (MapUtils.isNotEmpty(hostDeactivateMap)) {
deactivateHostURIs(hostDeactivateMap);
}
return createdHosts;
}
use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.
the class CreateBareMetalClusterService method execute.
@Override
public void execute() throws Exception {
if (cluster == null) {
cluster = ComputeUtils.createCluster(name);
logInfo("compute.cluster.created", name);
} else {
// If the hostName already exists, we remove it from the hostnames
// list.
hostNames = ComputeUtils.removeExistingHosts(hostNames, cluster);
}
acquireClusterLock(cluster);
List<Host> hosts = ComputeUtils.createHosts(cluster, computeVirtualPool, hostNames, virtualArray);
for (Host host : hosts) {
acquireHostLock(host, cluster);
}
logInfo("compute.cluster.hosts.created", ComputeUtils.nonNull(hosts).size());
Map<Host, URI> hostToBootVolumeIdMap = ComputeUtils.makeBootVolumes(project, virtualArray, virtualPool, size, hosts, getClient(), portGroup);
logInfo("compute.cluster.boot.volumes.created", hostToBootVolumeIdMap != null ? ComputeUtils.nonNull(hostToBootVolumeIdMap.values()).size() : 0);
// Deactivate hosts with no boot volume, return list of hosts remaining.
hostToBootVolumeIdMap = ComputeUtils.deactivateHostsWithNoBootVolume(hostToBootVolumeIdMap, cluster);
// Export the boot volume, return a map of hosts and their EG IDs
Map<Host, URI> hostToEgIdMap = ComputeUtils.exportBootVols(hostToBootVolumeIdMap, project, virtualArray, hlu, portGroup);
logInfo("compute.cluster.exports.created", hostToEgIdMap != null ? ComputeUtils.nonNull(hostToEgIdMap.values()).size() : 0);
// Deactivate any hosts where the export failed, return list of hosts remaining
hostToBootVolumeIdMap = ComputeUtils.deactivateHostsWithNoExport(hostToBootVolumeIdMap, hostToEgIdMap, cluster);
// Set host boot volume ids and set san boot targets.
hosts = ComputeUtils.setHostBootVolumes(hostToBootVolumeIdMap, true);
ComputeUtils.addHostsToCluster(hosts, cluster);
hosts = ComputeUtils.deactivateHostsNotAddedToCluster(hosts, cluster);
if (ComputeUtils.findHostNamesInCluster(cluster).isEmpty()) {
logInfo("compute.cluster.removing.empty.cluster");
ComputeUtils.deactivateCluster(cluster);
}
String orderErrors = ComputeUtils.getOrderErrors(cluster, copyOfHostNames, null, null);
if (orderErrors.length() > 0) {
// fail order so user can resubmit
if (ComputeUtils.nonNull(hosts).isEmpty()) {
throw new IllegalStateException(ExecutionUtils.getMessage("compute.cluster.order.incomplete", orderErrors));
} else {
logError("compute.cluster.order.incomplete", orderErrors);
setPartialSuccess();
}
}
}
use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.
the class CreateComputeClusterService method installOSForHosts.
private void installOSForHosts(Map<String, String> hostToIps, Map<String, URI> hostNameToBootVolumeMap, List<Host> createdHosts) {
Map<Host, OsInstallParam> osInstallParamMap = new HashMap<Host, OsInstallParam>();
for (Host host : createdHosts) {
if ((host != null) && ((host.getType() == null) || host.getType().isEmpty() || host.getType().equals(Host.HostType.No_OS.name()))) {
OsInstallParam param = new OsInstallParam();
String hostIp = hostToIps.get(host.getHostName());
param.setComputeImage(computeImage);
param.setHostName(host.getHostName());
param.setDnsServers(dnsServers);
param.setGateway(gateway);
param.setNetmask(netmask);
param.setHostIp(hostIp);
param.setVolume(hostNameToBootVolumeMap.get(host.getHostName()));
param.setManagementNetwork(managementNetwork);
param.setNtpServer(ntpServer);
param.setRootPassword(rootPassword);
osInstallParamMap.put(host, param);
} else {
osInstallParamMap.put(host, null);
}
}
try {
ComputeUtils.installOsOnHosts(osInstallParamMap);
} catch (Exception e) {
logError(e.getMessage());
}
}
Aggregations