Search in sources :

Example 6 with ExecutionException

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;
}
Also used : Task(com.emc.vipr.client.Task) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) GetHost(com.emc.sa.service.vipr.tasks.GetHost) DiscoverHost(com.emc.sa.service.vipr.compute.tasks.DiscoverHost) DeactivateHost(com.emc.sa.service.vipr.compute.tasks.DeactivateHost) Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI) Date(java.util.Date) ExportGroupRestRep(com.emc.storageos.model.block.export.ExportGroupRestRep) ExecutionException(com.emc.sa.engine.ExecutionException) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

ExecutionException (com.emc.sa.engine.ExecutionException)6 DeactivateHost (com.emc.sa.service.vipr.compute.tasks.DeactivateHost)3 DiscoverHost (com.emc.sa.service.vipr.compute.tasks.DiscoverHost)3 GetHost (com.emc.sa.service.vipr.tasks.GetHost)3 Host (com.emc.storageos.db.client.model.Host)3 ArrayList (java.util.ArrayList)3 VMwareSupport (com.emc.sa.service.vmware.VMwareSupport)2 GetVcenter (com.emc.sa.service.vmware.tasks.GetVcenter)2 GetVcenterDataCenter (com.emc.sa.service.vmware.tasks.GetVcenterDataCenter)2 Vcenter (com.emc.storageos.db.client.model.Vcenter)2 VcenterDataCenter (com.emc.storageos.db.client.model.VcenterDataCenter)2 BlockObjectRestRep (com.emc.storageos.model.block.BlockObjectRestRep)2 ExportGroupRestRep (com.emc.storageos.model.block.export.ExportGroupRestRep)2 HostRestRep (com.emc.storageos.model.host.HostRestRep)2 Task (com.emc.vipr.client.Task)2 URI (java.net.URI)2 HashMap (java.util.HashMap)2 ExecutionContext (com.emc.sa.engine.ExecutionContext)1 ViPRTaskMonitor (com.emc.sa.engine.ViPRTaskMonitor)1 DeactivateBlockExport (com.emc.sa.service.vipr.block.tasks.DeactivateBlockExport)1