use of com.emc.sa.engine.ExecutionException in project coprhd-controller by CoprHD.
the class ComputeUtils method exportBootVols.
/**
* Exports all boot volumes to respective hosts.
*
* Since exporting to boot volumes requires only one volume be exported for OS install, we have extra checks
* in here:
* - If there is an existing EG with the same name, we need to make additional checks:
* - If the EG has no initiators and volumes, re-use it. Add the host and volume.
* - If the EG has our initiators and a volume (or more), error out.
* - If the EG has different initiators, create an EG with a different name.
* - If the EG has our initiators and no volumes, re-use it. Add the volume only.
*
* @param hostToVolumeIdMap host to boot volume ID map
* @param project project
* @param virtualArray virtual array
* @param hlu HLU
* @param portGroup port group URI
* @return returns a map of hosts to Export Group URIs
*/
public static Map<Host, URI> exportBootVols(Map<Host, URI> hostToVolumeIdMap, URI project, URI virtualArray, Integer hlu, URI portGroup) {
if (hostToVolumeIdMap == null || hostToVolumeIdMap.isEmpty()) {
return Maps.newHashMap();
}
Map<Task<ExportGroupRestRep>, Host> taskToHostMap = new HashMap<>();
for (Entry<Host, URI> hostToVolumeIdEntry : hostToVolumeIdMap.entrySet()) {
Host host = hostToVolumeIdEntry.getKey();
URI volumeId = hostToVolumeIdEntry.getValue();
if (!NullColumnValueGetter.isNullURI(volumeId) && (host != null) && !(host.getInactive())) {
try {
ExportGroupRestRep export = BlockStorageUtils.findExportByHost(host, project, virtualArray, null);
if (export != null && !export.getVolumes().isEmpty()) {
throw new IllegalStateException(new Throwable("Existing export contains other volumes. Controller supports only the boot volume visible to host." + host.getHostName()));
}
// We can add the host to that export group if it's empty.
if (export == null) {
export = BlockStorageUtils.findExportsByName(host.getHostName(), project, virtualArray);
}
boolean createExport = export == null;
boolean isEmptyExport = export != null && BlockStorageUtils.isEmptyExport(export);
String exportName = host.getHostName();
if (export != null && !isEmptyExport) {
exportName = exportName + BlockStorageUtils.UNDERSCORE + new SimpleDateFormat("yyyyMMddhhmmssSSS").format(new Date());
createExport = true;
}
Task<ExportGroupRestRep> task = null;
if (createExport) {
task = BlockStorageUtils.createHostExportNoWait(exportName, project, virtualArray, Arrays.asList(volumeId), hlu, host, portGroup);
} else {
task = BlockStorageUtils.addHostAndVolumeToExportNoWait(export.getId(), // Don't add the host if there are already initiators in this export group.
export.getInitiators() != null && !export.getInitiators().isEmpty() ? null : host.getId(), volumeId, hlu, portGroup);
}
taskToHostMap.put(task, host);
} catch (ExecutionException e) {
String errorMessage = e.getMessage() == null ? "" : e.getMessage();
ExecutionUtils.currentContext().logError("computeutils.exportbootvolumes.failure", host.getHostName(), errorMessage);
}
// prevent exports from rolling back on exception
ExecutionUtils.clearRollback();
}
}
// Monitor tasks
Map<Host, URI> hostToEgIdMap = new HashMap<>();
List<Task<ExportGroupRestRep>> tasks = new ArrayList<>(taskToHostMap.keySet());
while (!tasks.isEmpty()) {
tasks = waitAndRefresh(tasks);
for (Task<ExportGroupRestRep> successfulTask : getSuccessfulTasks(tasks)) {
URI exportId = successfulTask.getResourceId();
addAffectedResource(exportId);
hostToEgIdMap.put(taskToHostMap.get(successfulTask), exportId);
tasks.remove(successfulTask);
}
for (Task<ExportGroupRestRep> failedTask : getFailedTasks(tasks)) {
String errorMessage = failedTask.getMessage() == null ? "" : failedTask.getMessage();
ExecutionUtils.currentContext().logError("computeutils.exportbootvolumes.failure", failedTask.getResource().getName(), errorMessage);
tasks.remove(failedTask);
}
}
return hostToEgIdMap;
}
Aggregations