Search in sources :

Example 6 with HostRestRep

use of com.emc.storageos.model.host.HostRestRep in project coprhd-controller by CoprHD.

the class CreateExport method isExportForHpuxOnVmax.

private boolean isExportForHpuxOnVmax() {
    // get host list
    List<HostRestRep> hosts = new ArrayList<HostRestRep>();
    if (clusterId != null) {
        hosts = ComputeUtils.getHostsInCluster(clusterId);
    } else {
        Host host = BlockStorageUtils.getHost(hostId);
        HostRestRep hostRestRep = HostMapper.map(host);
        hosts = Lists.newArrayList(hostRestRep);
    }
    // find if its a HPUX host
    boolean hasHPUX = false;
    for (HostRestRep host : hosts) {
        if (host.getType() != null && (host.getType().equalsIgnoreCase(Host.HostType.HPUX.toString()))) {
            hasHPUX = true;
            break;
        }
    }
    if (!hasHPUX) {
        return false;
    }
    // VMAX
    for (URI volumeId : volumeIds) {
        BlockObjectRestRep volume = BlockStorageUtils.getVolume(volumeId);
        URI storageURI = volume.getStorageController();
        StorageSystemRestRep storageSystem = BlockStorageUtils.getStorageSystem(storageURI);
        if (StringUtils.equals(VMAX, storageSystem.getSystemType())) {
            return true;
        }
    }
    return false;
}
Also used : HostRestRep(com.emc.storageos.model.host.HostRestRep) StorageSystemRestRep(com.emc.storageos.model.systems.StorageSystemRestRep) ArrayList(java.util.ArrayList) Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI) BlockObjectRestRep(com.emc.storageos.model.block.BlockObjectRestRep)

Example 7 with HostRestRep

use of com.emc.storageos.model.host.HostRestRep in project coprhd-controller by CoprHD.

the class ComputeUtils method getOrderErrors.

/**
 * This method calculates whether there were any errors during the order or whether everything succeeded
 * Determines the order status - success, failure or partial success
 * @param Cluster
 * @param List of hostNames
 * @param computeImage
 * @param vcenterURI
 * @return orderError message if any to be displayed on UI
 */
public static String getOrderErrors(Cluster cluster, List<String> hostNames, URI computeImage, URI vcenterId) {
    StringBuilder orderErrors = new StringBuilder();
    List<HostRestRep> hosts = Lists.newArrayList();
    try {
        hosts = getHostsInCluster(cluster.getId(), cluster.getLabel());
    } catch (Exception e) {
        // catches if cluster was removed & marked for delete
        ExecutionUtils.currentContext().logError("compute.cluster.get.hosts.failed", e.getMessage());
    }
    List<String> hostNamesInCluster = Lists.newArrayList();
    for (HostRestRep host : hosts) {
        hostNamesInCluster.add(host.getName());
    }
    int numberOfFailedHosts = 0;
    for (String hostName : hostNames) {
        if (hostName != null && !hostNamesInCluster.contains(hostName)) {
            numberOfFailedHosts++;
        }
    }
    if (numberOfFailedHosts > 0) {
        orderErrors.append(ExecutionUtils.getMessage("compute.cluster.hosts.failed", numberOfFailedHosts + " "));
    }
    for (HostRestRep host : hosts) {
        if ((!NullColumnValueGetter.isNullURI(vcenterId) || !NullColumnValueGetter.isNullURI(cluster.getVcenterDataCenter())) && (host.getvCenterDataCenter() == null) && host.getType() != null && host.getType().equalsIgnoreCase(HostType.Esx.name())) {
            orderErrors.append(ExecutionUtils.getMessage("compute.cluster.vcenter.push.failed", host.getHostName()) + "  ");
        }
    }
    // Check if the OS installed on the new hosts that were created by the order
    if (computeImage != null) {
        List<HostRestRep> newHosts = Lists.newArrayList();
        for (HostRestRep host : hosts) {
            if (hostNames.contains(host.getHostName())) {
                newHosts.add(host);
            }
        }
        for (HostRestRep host : newHosts) {
            if ((host.getType() == null) || host.getType().isEmpty() || host.getType().equals(Host.HostType.No_OS.name())) {
                orderErrors.append(ExecutionUtils.getMessage("computeutils.installOs.failure", host.getHostName()) + "  ");
            }
        }
    }
    return orderErrors.toString();
}
Also used : HostRestRep(com.emc.storageos.model.host.HostRestRep) TimeoutException(com.emc.vipr.client.exceptions.TimeoutException) ExecutionException(com.emc.sa.engine.ExecutionException) ViPRException(com.emc.vipr.client.exceptions.ViPRException)

Example 8 with HostRestRep

use of com.emc.storageos.model.host.HostRestRep in project coprhd-controller by CoprHD.

the class ComputeUtils method validateBootVolumes.

/**
 * Validate that the boot volume for this host is still on the server.
 * This prevents us from deleting a re-purposed volume that was originally
 * a boot volume.
 *
 * @return true if the volumes are valid, or the volumes are not able to be validated, so we can go ahead anyway.
 */
public static boolean validateBootVolumes(Cluster cluster, List<HostRestRep> hostsToValidate) {
    // the references are fixed.
    if (cluster == null || cluster.getInactive()) {
        ExecutionUtils.currentContext().logError("computeutils.removebootvolumes.failure.cluster");
        return false;
    }
    // so return that the boot volume is valid due to lack of technical ability to dig any deeper.
    if (NullColumnValueGetter.isNullURI(cluster.getVcenterDataCenter())) {
        ExecutionUtils.currentContext().logInfo("computeutils.removebootvolumes.validation.skipped.noVcenterDataCenter", cluster.forDisplay());
        return true;
    }
    VcenterDataCenter dataCenter = execute(new GetVcenterDataCenter(cluster.getVcenterDataCenter()));
    // until that's fixed.
    if (dataCenter == null || dataCenter.getInactive() || NullColumnValueGetter.isNullURI(dataCenter.getVcenter())) {
        ExecutionUtils.currentContext().logError("computeutils.removebootvolumes.failure.datacenter", cluster.forDisplay());
        return false;
    }
    Vcenter vcenter = execute(new GetVcenter(dataCenter.getVcenter()));
    // until that's fixed.
    if (vcenter == null || vcenter.getInactive()) {
        ExecutionUtils.currentContext().logError("computeutils.removebootvolumes.failure.vcenter", cluster.forDisplay());
        return false;
    }
    VMwareSupport vmware = null;
    try {
        vmware = new VMwareSupport();
        vmware.connect(vcenter.getId());
        for (HostRestRep clusterHost : hostsToValidate) {
            Host host = BlockStorageUtils.getHost(clusterHost.getId());
            // Do not validate a host no longer in our database
            if (host == null || host.getInactive()) {
                ExecutionUtils.currentContext().logError("computeutils.removebootvolumes.failure.host", "N/A", "host not found or inactive");
                return false;
            }
            // in the vCenter cluster, and therefore we can not perform a deep validation.
            if (NullColumnValueGetter.isNullURI(host.getVcenterDataCenter())) {
                ExecutionUtils.currentContext().logInfo("computeutils.removebootvolumes.validation.skipped.vcenternotinhost", host.getHostName());
                continue;
            }
            // any update to the host using the hostService automatically adds this association.
            if (!NullColumnValueGetter.isNullURI(host.getVcenterDataCenter()) && host.getType() != null && host.getType().equalsIgnoreCase((Host.HostType.No_OS).name())) {
                ExecutionUtils.currentContext().logInfo("computeutils.removebootvolumes.validation.skipped.noOShost", host.getHostName());
                continue;
            }
            // flag it as an issue.
            if (clusterHost.getBootVolume() == null || NullColumnValueGetter.isNullURI(clusterHost.getBootVolume().getId())) {
                ExecutionUtils.currentContext().logWarn("computeutils.removebootvolumes.failure.host", host.getHostName(), "no boot volume associated with host");
                continue;
            }
            BlockObjectRestRep bootVolume = execute(new GetBlockResource(clusterHost.getBootVolume().getId()));
            // Do not validate an old/non-existent boot volume representation
            if (bootVolume == null || bootVolume.getInactive()) {
                ExecutionUtils.currentContext().logError("computeutils.removebootvolumes.failure.host", host.getHostName(), "boot volume not found or inactive");
                return false;
            }
            HostSystem hostSystem = null;
            try {
                hostSystem = vmware.getHostSystem(dataCenter.getLabel(), clusterHost.getName(), false);
                // we can't perform the validation.
                if (hostSystem == null) {
                    ExecutionUtils.currentContext().logInfo("computeutils.removebootvolumes.validation.skipped.hostnotinvcenter", host.getHostName());
                    continue;
                }
                HostSystemConnectionState connectionState = VMwareUtils.getConnectionState(hostSystem);
                if (connectionState == null || connectionState == HostSystemConnectionState.notResponding || connectionState == HostSystemConnectionState.disconnected) {
                    String exMsg = "Validation of boot volume usage on host %s failed. " + "Validation failed because host is in a disconnected state or not responding state, and therefore cannot be validated. " + "Cannot decommission in current state.  Recommended to either re-connect the host or remove the host from vCenter, " + "run vCenter discovery and address actionable events before attempting decommission of hosts in this cluster.";
                    // will print a boot volume re-purposed error message which is kind of misleading or incorrect reason for the failure.
                    throw new IllegalStateException(String.format(exMsg, host.getHostName()));
                }
            } catch (ExecutionException e) {
                if (e.getCause() instanceof IllegalStateException) {
                    ExecutionUtils.currentContext().logInfo("computeutils.removebootvolumes.validation.skipped.hostnotinvcenter", host.getHostName());
                    continue;
                }
                // If it's anything other than the IllegalStateException, re-throw the base exception
                throw e;
            }
            if (vmware.findScsiDisk(hostSystem, null, bootVolume, false, false) == null) {
                // fail, host can't see its boot volume
                ExecutionUtils.currentContext().logError("computeutils.removebootvolumes.failure.bootvolume", bootVolume.getDeviceLabel(), bootVolume.getWwn());
                return false;
            } else {
                ExecutionUtils.currentContext().logInfo("computeutils.removebootvolumes.validated", host.getHostName(), bootVolume.getDeviceLabel());
            }
        }
    } finally {
        if (vmware != null) {
            vmware.disconnect();
        }
    }
    return true;
}
Also used : GetVcenter(com.emc.sa.service.vmware.tasks.GetVcenter) Vcenter(com.emc.storageos.db.client.model.Vcenter) GetVcenter(com.emc.sa.service.vmware.tasks.GetVcenter) VMwareSupport(com.emc.sa.service.vmware.VMwareSupport) 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) GetBlockResource(com.emc.sa.service.vipr.block.tasks.GetBlockResource) BlockObjectRestRep(com.emc.storageos.model.block.BlockObjectRestRep) GetVcenterDataCenter(com.emc.sa.service.vmware.tasks.GetVcenterDataCenter) HostRestRep(com.emc.storageos.model.host.HostRestRep) HostSystem(com.vmware.vim25.mo.HostSystem) GetVcenterDataCenter(com.emc.sa.service.vmware.tasks.GetVcenterDataCenter) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) HostSystemConnectionState(com.vmware.vim25.HostSystemConnectionState) ExecutionException(com.emc.sa.engine.ExecutionException)

Example 9 with HostRestRep

use of com.emc.storageos.model.host.HostRestRep 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;
}
Also used : Task(com.emc.vipr.client.Task) 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) 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) CreateHosts(com.emc.sa.service.vipr.compute.tasks.CreateHosts)

Example 10 with HostRestRep

use of com.emc.storageos.model.host.HostRestRep in project coprhd-controller by CoprHD.

the class InstallOsHelper method installOs.

public void installOs() {
    ExecutionContext context = ExecutionUtils.currentContext();
    List<ViPRTaskMonitor<HostRestRep>> tasks = new ArrayList<>();
    for (HostRestRep host : hostToOsInstall.keySet()) {
        OsInstallParam osInstall = hostToOsInstall.get(host);
        if (osInstall != null) {
            try {
            // tasks.add(ExecutionUtils.startViprTask(new InstallOs(host, osInstall)));
            } catch (ExecutionException e) {
                context.logError("computeutils.installOs.failure", host.getId(), e.getMessage());
            }
        }
    }
    if (!ExecutionUtils.waitForTask(tasks, this)) {
    // TODO: Re-throw the error?
    // ExecutionUtils.checkForError(tasks);
    }
}
Also used : HostRestRep(com.emc.storageos.model.host.HostRestRep) ExecutionContext(com.emc.sa.engine.ExecutionContext) ArrayList(java.util.ArrayList) ViPRTaskMonitor(com.emc.sa.engine.ViPRTaskMonitor) OsInstallParam(com.emc.storageos.model.compute.OsInstallParam) ExecutionException(com.emc.sa.engine.ExecutionException)

Aggregations

HostRestRep (com.emc.storageos.model.host.HostRestRep)46 URI (java.net.URI)17 ArrayList (java.util.ArrayList)10 ExecutionException (com.emc.sa.engine.ExecutionException)7 Host (com.emc.storageos.db.client.model.Host)6 ClusterRestRep (com.emc.storageos.model.host.cluster.ClusterRestRep)6 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 ExportGroupRestRep (com.emc.storageos.model.block.export.ExportGroupRestRep)5 TimeoutException (com.emc.vipr.client.exceptions.TimeoutException)5 ViPRException (com.emc.vipr.client.exceptions.ViPRException)5 HashMap (java.util.HashMap)5 HostUpdateParam (com.emc.storageos.model.host.HostUpdateParam)4 InitiatorRestRep (com.emc.storageos.model.host.InitiatorRestRep)4 Asset (com.emc.sa.asset.annotation.Asset)3 RelatedResourceRep (com.emc.storageos.model.RelatedResourceRep)3 BlockObjectRestRep (com.emc.storageos.model.block.BlockObjectRestRep)3 VcenterDataCenterRestRep (com.emc.storageos.model.host.vcenter.VcenterDataCenterRestRep)3 Task (com.emc.vipr.client.Task)3