Search in sources :

Example 11 with Task

use of com.emc.vipr.client.Task 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)

Example 12 with Task

use of com.emc.vipr.client.Task in project coprhd-controller by CoprHD.

the class ComputeUtils method installOsOnHosts.

/**
 * Install OS image on the specified hosts
 * @param map of Host to OsInstallParam -- this param has the details of which image to use, the netmask, ip address, etc required for installing os
 */
public static void installOsOnHosts(Map<Host, OsInstallParam> osInstallParamMap) {
    if ((osInstallParamMap == null) || osInstallParamMap.isEmpty()) {
        return;
    }
    Set<Host> hosts = osInstallParamMap.keySet();
    // execute all tasks (no waiting)
    List<Task<HostRestRep>> tasks = Lists.newArrayList();
    for (Host host : hosts) {
        if (host != null) {
            if (osInstallParamMap.get(host) == null) {
                continue;
            }
            try {
                tasks.add(execute(new InstallOs(host, osInstallParamMap.get(host))));
            } catch (Exception e) {
                ExecutionUtils.currentContext().logError("computeutils.installOs.failure", host.getId() + "  " + e.getMessage());
            }
        }
    }
    // monitor tasks
    while (!tasks.isEmpty()) {
        tasks = waitAndRefresh(tasks);
        for (Task<HostRestRep> successfulTask : getSuccessfulTasks(tasks)) {
            tasks.remove(successfulTask);
            URI hostId = successfulTask.getResource().getId();
            Host newHost = execute(new GetHost(hostId));
            if (newHost == null) {
                ExecutionUtils.currentContext().logError("computeutils.installOs.installing.failure", successfulTask.getResource().getName());
            } else {
                ExecutionUtils.currentContext().logInfo("computeutils.installOs.success", newHost.getHostName());
                addAffectedResource(hostId);
            }
        }
        for (Task<HostRestRep> failedTask : getFailedTasks(tasks)) {
            tasks.remove(failedTask);
            String errorMessage = failedTask.getMessage() == null ? "" : failedTask.getMessage();
            ExecutionUtils.currentContext().logError("computeutils.installOs.installing.failure.task", failedTask.getResource().getName(), errorMessage);
        }
    }
}
Also used : Task(com.emc.vipr.client.Task) InstallOs(com.emc.sa.service.vipr.compute.tasks.InstallOs) HostRestRep(com.emc.storageos.model.host.HostRestRep) GetHost(com.emc.sa.service.vipr.tasks.GetHost) 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) TimeoutException(com.emc.vipr.client.exceptions.TimeoutException) ExecutionException(com.emc.sa.engine.ExecutionException) ViPRException(com.emc.vipr.client.exceptions.ViPRException)

Example 13 with Task

use of com.emc.vipr.client.Task in project coprhd-controller by CoprHD.

the class ComputeUtils method setHostBootVolumes.

/**
 * Sets the specified host's boot volume association; Optionally also sets the UCS service profile's san boot targets
 * Any hosts for which boot volume association could not be set are deactivated.
 *
 * @param Map of Host to bootVolume URI
 * @param boolean set to true to update the UCS service profile's san boot targets
 * @return list of hosts for which boot volume association was successfully set.
 */
public static List<Host> setHostBootVolumes(Map<Host, URI> hostToVolumeIdMap, boolean updateSanBootTargets) {
    List<Task<HostRestRep>> tasks = new ArrayList<>();
    Map<URI, URI> volumeIdToHostIdMap = new HashMap<>();
    for (Entry<Host, URI> hostToVolumeIdEntry : hostToVolumeIdMap.entrySet()) {
        Host host = hostToVolumeIdEntry.getKey();
        URI volumeId = hostToVolumeIdEntry.getValue();
        volumeIdToHostIdMap.put(volumeId, host.getId());
        if (host != null && !host.getInactive()) {
            host.setBootVolumeId(volumeId);
            try {
                Task<HostRestRep> task = ViPRExecutionUtils.execute(new SetBootVolume(host, volumeId, updateSanBootTargets));
                tasks.add(task);
            } catch (Exception e) {
                ExecutionUtils.currentContext().logError("computeutils.sethostbootvolume.failure", host.getHostName() + "  " + e.getMessage());
            }
        }
    }
    // monitor tasks
    List<URI> successfulHostIds = Lists.newArrayList();
    List<URI> hostsToRemove = Lists.newArrayList();
    List<URI> bootVolumesToRemove = Lists.newArrayList();
    while (!tasks.isEmpty()) {
        tasks = waitAndRefresh(tasks);
        for (Task<HostRestRep> successfulTask : getSuccessfulTasks(tasks)) {
            tasks.remove(successfulTask);
            URI hostId = successfulTask.getResource().getId();
            Host newHost = execute(new GetHost(hostId));
            if (newHost == null || newHost.getBootVolumeId() == null || newHost.getBootVolumeId().equals("null")) {
                ExecutionUtils.currentContext().logError("computeutils.sethostbootvolume.failure", successfulTask.getResource().getName());
                hostsToRemove.add(hostId);
            } else {
                ExecutionUtils.currentContext().logInfo("computeutils.sethostbootvolume.success", newHost.getHostName());
                addAffectedResource(hostId);
                successfulHostIds.add(hostId);
            }
        }
        for (Task<HostRestRep> failedTask : getFailedTasks(tasks)) {
            tasks.remove(failedTask);
            String errorMessage = failedTask.getMessage() == null ? "" : failedTask.getMessage();
            ExecutionUtils.currentContext().logError("computeutils.sethostbootvolume.failure.task", failedTask.getResource().getName(), errorMessage);
            URI hostId = failedTask.getResource().getId();
            execute(new GetHost(hostId));
            hostsToRemove.add(hostId);
        }
    }
    for (Host host : hostToVolumeIdMap.keySet()) {
        if (host != null && !host.getInactive()) {
            if (!successfulHostIds.contains(host.getId()) && !hostsToRemove.contains(host.getId())) {
                hostsToRemove.add(host.getId());
            }
        }
    }
    for (URI hostId : hostsToRemove) {
        for (Host host : hostToVolumeIdMap.keySet()) {
            if (host.getId().equals(hostId)) {
                ExecutionUtils.currentContext().logInfo("computeutils.deactivatehost.nobootvolumeassociation", host.getHostName());
                bootVolumesToRemove.add(hostToVolumeIdMap.get(host));
                break;
            }
        }
        execute(new DeactivateHost(hostId, true));
    }
    // Cleanup all boot volumes of the deactivated host so that we do not leave any unused boot volumes.
    if (!bootVolumesToRemove.isEmpty()) {
        try {
            ExecutionUtils.currentContext().logInfo("computeutils.deactivatebootvolume.nobootvolumeassociation");
            for (URI bootVolToRemove : bootVolumesToRemove) {
                BlockObjectRestRep volume = BlockStorageUtils.getBlockResource(bootVolToRemove);
                URI hostId = volumeIdToHostIdMap.get(bootVolToRemove);
                removeBootVolumeTag(volume, hostId);
            }
            BlockStorageUtils.deactivateVolumes(bootVolumesToRemove, VolumeDeleteTypeEnum.FULL);
        } catch (Exception e) {
            ExecutionUtils.currentContext().logError("computeutils.bootvolume.deactivate.failure", e.getMessage());
        }
    }
    // Only return successful hosts
    List<Host> successfulHosts = new ArrayList<>();
    for (Host host : hostToVolumeIdMap.keySet()) {
        if ((host != null) && successfulHostIds.contains(host.getId())) {
            successfulHosts.add(host);
        }
    }
    return successfulHosts;
}
Also used : Task(com.emc.vipr.client.Task) DeactivateHost(com.emc.sa.service.vipr.compute.tasks.DeactivateHost) HashMap(java.util.HashMap) GetHost(com.emc.sa.service.vipr.tasks.GetHost) 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) BlockObjectRestRep(com.emc.storageos.model.block.BlockObjectRestRep) TimeoutException(com.emc.vipr.client.exceptions.TimeoutException) ExecutionException(com.emc.sa.engine.ExecutionException) ViPRException(com.emc.vipr.client.exceptions.ViPRException) HostRestRep(com.emc.storageos.model.host.HostRestRep) SetBootVolume(com.emc.sa.service.vipr.compute.tasks.SetBootVolume)

Example 14 with Task

use of com.emc.vipr.client.Task in project coprhd-controller by CoprHD.

the class BlockExportGroups method delete.

private static void delete(List<URI> ids) {
    if (ids != null) {
        ViPRCoreClient client = BourneUtil.getViprClient();
        List<Task<ExportGroupRestRep>> tasks = Lists.newArrayList();
        for (URI id : ids) {
            Task<ExportGroupRestRep> task = client.blockExports().deactivate(id);
            tasks.add(task);
        }
        flash.put("info", MessagesUtils.get("resources.exportgroups.deactivate", tasks.size()));
    }
    exportGroups(null);
}
Also used : Task(com.emc.vipr.client.Task) ViPRCoreClient(com.emc.vipr.client.ViPRCoreClient) ExportGroupRestRep(com.emc.storageos.model.block.export.ExportGroupRestRep) URI(java.net.URI)

Example 15 with Task

use of com.emc.vipr.client.Task in project coprhd-controller by CoprHD.

the class BlockSnapshots method snapshotDetails.

public static void snapshotDetails(String snapshotId) {
    ViPRCoreClient client = BourneUtil.getViprClient();
    AffectedResources.BlockSnapshotDetails blockSnapshot = new AffectedResources.BlockSnapshotDetails(uri(snapshotId));
    if (blockSnapshot.blockSnapshot == null) {
        flash.error(MessagesUtils.get(UNKNOWN, snapshotId));
        snapshots(null);
    }
    AffectedResources.VolumeDetails volume = new AffectedResources.VolumeDetails(blockSnapshot.volume.getId());
    List<Task<BlockSnapshotRestRep>> tasks = null;
    if (blockSnapshot.blockSnapshot != null) {
        Tasks<BlockSnapshotRestRep> tasksResponse = client.blockSnapshots().getTasks(blockSnapshot.blockSnapshot.getId());
        tasks = tasksResponse.getTasks();
    }
    render(blockSnapshot, volume, tasks);
}
Also used : Task(com.emc.vipr.client.Task) ViPRCoreClient(com.emc.vipr.client.ViPRCoreClient) BlockSnapshotRestRep(com.emc.storageos.model.block.BlockSnapshotRestRep)

Aggregations

Task (com.emc.vipr.client.Task)21 URI (java.net.URI)13 ViPRCoreClient (com.emc.vipr.client.ViPRCoreClient)11 ArrayList (java.util.ArrayList)6 ExecutionException (com.emc.sa.engine.ExecutionException)5 DeactivateHost (com.emc.sa.service.vipr.compute.tasks.DeactivateHost)5 DiscoverHost (com.emc.sa.service.vipr.compute.tasks.DiscoverHost)5 GetHost (com.emc.sa.service.vipr.tasks.GetHost)5 Host (com.emc.storageos.db.client.model.Host)5 VolumeRestRep (com.emc.storageos.model.block.VolumeRestRep)4 FileShareRestRep (com.emc.storageos.model.file.FileShareRestRep)4 TimeoutException (com.emc.vipr.client.exceptions.TimeoutException)4 ViPRException (com.emc.vipr.client.exceptions.ViPRException)4 ViPRHttpException (com.emc.vipr.client.exceptions.ViPRHttpException)4 HashMap (java.util.HashMap)4 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)3 FileSnapshotRestRep (com.emc.storageos.model.file.FileSnapshotRestRep)3 HostRestRep (com.emc.storageos.model.host.HostRestRep)3 BlockObjectRestRep (com.emc.storageos.model.block.BlockObjectRestRep)2 ExportGroupRestRep (com.emc.storageos.model.block.export.ExportGroupRestRep)2