Search in sources :

Example 26 with VcenterDataCenter

use of com.emc.storageos.db.client.model.VcenterDataCenter in project coprhd-controller by CoprHD.

the class VcenterControllerImpl method vcenterClusterSelectHostOperation.

// Find a host connected and powered on then refresh it
public void vcenterClusterSelectHostOperation(URI vcenterId, URI vcenterDataCenterId, URI clusterId, URI[] hostUris, String stepId) {
    VcenterApiClient vcenterApiClient = null;
    try {
        WorkflowStepCompleter.stepExecuting(stepId);
        VcenterDataCenter vcenterDataCenter = _dbClient.queryObject(VcenterDataCenter.class, vcenterDataCenterId);
        Cluster cluster = _dbClient.queryObject(Cluster.class, clusterId);
        Vcenter vcenter = _dbClient.queryObject(Vcenter.class, vcenterId);
        Collection<Host> hosts = _dbClient.queryObject(Host.class, hostUris);
        vcenterApiClient = new VcenterApiClient(_coordinator.getPropertyInfo());
        vcenterApiClient.setup(vcenter.getIpAddress(), vcenter.getUsername(), vcenter.getPassword(), vcenter.getPortNumber());
        Host hostForStorageOperations = null;
        for (Host host : hosts) {
            try {
                vcenterApiClient.checkHostConnectedPoweredOn(vcenterDataCenter.getLabel(), cluster.getExternalId(), host.getHostName());
                hostForStorageOperations = host;
                _log.info("Host " + host.getHostName() + " to be used for storage operations");
                break;
            } catch (Exception e) {
                _log.info("Host " + host.getHostName() + " not valid for storage operations due to exception " + e.getLocalizedMessage());
            }
        }
        if (hostForStorageOperations == null) {
            _log.error("No host valid for performing storage operations thus cannot perform datastore operations");
            throw new Exception("No host valid for performing storage operations thus cannot perform datastore operations");
        }
        vcenterApiClient.refreshRescanHostStorage(vcenterDataCenter.getLabel(), cluster.getExternalId(), hostForStorageOperations.getHostName());
        // persist hostForStorageOperations ID in wf data
        _workflowService.storeStepData(stepId, hostForStorageOperations.getId());
        WorkflowStepCompleter.stepSucceded(stepId);
    } catch (Exception e) {
        _log.error("vcenterClusterSelectHostOperation exception " + e);
        WorkflowStepCompleter.stepFailed(stepId, VcenterControllerException.exceptions.hostException(e.getLocalizedMessage(), e));
    } finally {
        if (vcenterApiClient != null) {
            vcenterApiClient.destroy();
        }
    }
}
Also used : Vcenter(com.emc.storageos.db.client.model.Vcenter) VcenterApiClient(com.emc.storageos.vcentercontroller.VcenterApiClient) Cluster(com.emc.storageos.db.client.model.Cluster) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) Host(com.emc.storageos.db.client.model.Host) VcenterServerConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) VcenterControllerException(com.emc.storageos.vcentercontroller.exceptions.VcenterControllerException)

Example 27 with VcenterDataCenter

use of com.emc.storageos.db.client.model.VcenterDataCenter in project coprhd-controller by CoprHD.

the class VMwareHostService method validateClusterHosts.

/**
 * Validates the vCenter cluster hosts match the same hosts we have in our database for the cluster. If there is a mismatch the check
 * will fail the order.
 */
protected void validateClusterHosts() {
    if (hostCluster != null) {
        VcenterDataCenter datacenter = getModelClient().datacenters().findById(datacenterId);
        Cluster cluster = getModelClient().clusters().findById(hostCluster.getId());
        ClusterComputeResource vcenterCluster = vmware.getCluster(datacenter.getLabel(), cluster.getLabel(), checkClusterConnectivity());
        if (vcenterCluster == null) {
            ExecutionUtils.fail("failTask.vmware.cluster.notfound", args(), args(cluster.getLabel()));
        }
        Set<String> vCenterHostUuids = Sets.newHashSet();
        for (HostSystem hostSystem : vcenterCluster.getHosts()) {
            if (hostSystem.getHardware() != null && hostSystem.getHardware().systemInfo != null) {
                vCenterHostUuids.add(hostSystem.getHardware().systemInfo.uuid);
            }
        }
        List<Host> dbHosts = getModelClient().hosts().findByCluster(hostCluster.getId());
        Set<String> dbHostUuids = Sets.newHashSet();
        for (Host host : dbHosts) {
            // Validate the hosts within the cluster all have good discovery status
            if (!DiscoveredDataObject.CompatibilityStatus.COMPATIBLE.toString().equalsIgnoreCase(host.getCompatibilityStatus())) {
                ExecutionUtils.fail("failTask.vmware.cluster.hostincompatible", args(), args(cluster.getLabel(), host.getLabel()));
            } else if (DiscoveredDataObject.DataCollectionJobStatus.ERROR.toString().equalsIgnoreCase(host.getDiscoveryStatus())) {
                ExecutionUtils.fail("failTask.vmware.cluster.hostsdiscoveryfailed", args(), args(cluster.getLabel(), host.getLabel()));
            }
            dbHostUuids.add(host.getUuid());
        }
        if (!vCenterHostUuids.equals(dbHostUuids)) {
            ExecutionUtils.fail("failTask.vmware.cluster.mismatch", args(), args(cluster.getLabel()));
        } else {
            info("Hosts in cluster %s matches correctly", cluster.getLabel());
        }
    }
}
Also used : ClusterComputeResource(com.vmware.vim25.mo.ClusterComputeResource) HostSystem(com.vmware.vim25.mo.HostSystem) Cluster(com.emc.storageos.db.client.model.Cluster) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) Host(com.emc.storageos.db.client.model.Host)

Example 28 with VcenterDataCenter

use of com.emc.storageos.db.client.model.VcenterDataCenter in project coprhd-controller by CoprHD.

the class ComputeUtils method verifyClusterInVcenter.

/**
 * Precheck to verify if cluster is associated to a datacenter and if it still
 * on the same datacenter and vcenter.  Precheck fails the order if the cluster
 * has datacenter association and is not found on the vcenter under the same datacenter
 * Precheck also fails if the cluster found by name in vcenter does not match externalId
 * in ViPR Cluster.
 * If cluster does not have a datacenter association, then the cluster is
 * a vipr cluster and precheck passes.
 * @param cluster {@link Cluster} cluster instance
 * @param preCheckErrors {@link StringBuilder} instance
 * @return preCheckErrors
 */
public static StringBuilder verifyClusterInVcenter(Cluster cluster, StringBuilder preCheckErrors) {
    // else fail order
    if (!NullColumnValueGetter.isNullURI(cluster.getVcenterDataCenter())) {
        VcenterDataCenter dataCenter = execute(new GetVcenterDataCenter(cluster.getVcenterDataCenter()));
        if (dataCenter != null && !dataCenter.getInactive()) {
            if (!NullColumnValueGetter.isNullURI(dataCenter.getVcenter())) {
                Vcenter vcenter = execute(new GetVcenter(dataCenter.getVcenter()));
                if (vcenter != null && !vcenter.getInactive()) {
                    VMwareSupport vmware = null;
                    try {
                        vmware = new VMwareSupport();
                        vmware.connect(vcenter.getId());
                        ClusterComputeResource vcenterCluster = vmware.getCluster(dataCenter.getLabel(), cluster.getLabel(), false);
                        if (null == vcenterCluster) {
                            preCheckErrors.append(ExecutionUtils.getMessage("compute.cluster.precheck.cluster.VcenterDataCenter.notfound.in.vcenter", cluster.getLabel(), dataCenter.getLabel(), vcenter.getLabel()));
                        } else if (vcenterCluster.getMOR() != null && vcenterCluster.getMOR().getVal() != null && vcenterCluster.getMOR().getVal().equalsIgnoreCase(cluster.getExternalId())) {
                            ExecutionUtils.currentContext().logInfo("compute.cluster.precheck.cluster.VcenterDataCenter.found.in.vcenter", cluster.getLabel(), dataCenter.getLabel(), vcenter.getLabel());
                        } else {
                            preCheckErrors.append(ExecutionUtils.getMessage("compute.cluster.precheck.cluster.VcenterDataCenter.nomatch.in.vcenter", cluster.getLabel(), vcenter.getLabel()));
                        }
                    } catch (ExecutionException e) {
                        if (e.getCause() instanceof IllegalStateException) {
                            preCheckErrors.append(ExecutionUtils.getMessage("compute.cluster.precheck.cluster.VcenterDataCenter.notfound.in.vcenter", cluster.getLabel(), dataCenter.getLabel(), vcenter.getLabel()));
                        } else {
                            // exception
                            throw e;
                        }
                    } finally {
                        if (vmware != null) {
                            vmware.disconnect();
                        }
                    }
                } else {
                    // If the vcenter isn't returned properly, not found in
                    // DB, but the cluster has a reference to
                    // it, there's an issue with the sync of the DB object.
                    // Do not allow the validation to pass
                    // until that's fixed.
                    preCheckErrors.append(ExecutionUtils.getMessage("compute.cluster.precheck.cluster.VcenterDataCenter.improper.vcenter", dataCenter.getVcenter()));
                }
            } else {
                // If datacenter does not have reference to a vcenter then
                // there's an issue with the sync of the DB object. Do not allow the validation to pass
                // until that's fixed.
                preCheckErrors.append(ExecutionUtils.getMessage("compute.cluster.precheck.cluster.VcenterDataCenter.noVcenter", dataCenter.getLabel()));
            }
        } else {
            // If the datacenter isn't returned properly, not found in DB,
            // but the cluster has a reference to
            // it, there's an issue with the sync of the DB object. Do not
            // allow the validation to pass
            // until that's fixed.
            preCheckErrors.append(ExecutionUtils.getMessage("compute.cluster.precheck.cluster.improper.VcenterDataCenter", cluster.getVcenterDataCenter()));
        }
    } else {
        // cluster is a vipr cluster only no need to check anything further.
        ExecutionUtils.currentContext().logInfo("compute.cluster.precheck.cluster.noVCenterDataCenter", cluster.getLabel());
    }
    return preCheckErrors;
}
Also used : GetVcenterDataCenter(com.emc.sa.service.vmware.tasks.GetVcenterDataCenter) GetVcenter(com.emc.sa.service.vmware.tasks.GetVcenter) Vcenter(com.emc.storageos.db.client.model.Vcenter) ClusterComputeResource(com.vmware.vim25.mo.ClusterComputeResource) GetVcenter(com.emc.sa.service.vmware.tasks.GetVcenter) GetVcenterDataCenter(com.emc.sa.service.vmware.tasks.GetVcenterDataCenter) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) VMwareSupport(com.emc.sa.service.vmware.VMwareSupport) ExecutionException(com.emc.sa.engine.ExecutionException)

Example 29 with VcenterDataCenter

use of com.emc.storageos.db.client.model.VcenterDataCenter in project coprhd-controller by CoprHD.

the class ComputeUtils method verifyHostInVcenterCluster.

/**
 * Validate that the hosts are in their respective cluster.  Typically used before
 * performing destructive operations, such as decommissioning a host or cluster.
 *
 * @param hostIds host IDs
 * @return false if any host still exists in the vCenter, but is NOT in the cluster assigned to the host in our DB.
 */
public static boolean verifyHostInVcenterCluster(Cluster cluster, List<URI> hostIds) {
    // If the cluster isn't returned properly, then something went wrong. We must fail validation.
    if (cluster == null || cluster.getInactive()) {
        ExecutionUtils.currentContext().logError("The cluster is not active in ViPR DB, therefore we can not proceed with validation.");
        return false;
    }
    // So log it and return.
    if (NullColumnValueGetter.isNullURI(cluster.getVcenterDataCenter())) {
        ExecutionUtils.currentContext().logInfo("computeutils.decommission.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.decommission.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.decommission.failure.vcenter", cluster.forDisplay());
        return false;
    }
    VMwareSupport vmware = null;
    try {
        vmware = new VMwareSupport();
        vmware.connect(vcenter.getId());
        for (URI hostId : hostIds) {
            Host host = BlockStorageUtils.getHost(hostId);
            // Do not validate a host no longer in our database
            if (host == null || host.getInactive()) {
                ExecutionUtils.currentContext().logError("computeutils.decommission.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.decommission.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.decommission.validation.skipped.noOShost", host.getHostName());
                continue;
            }
            HostSystem hostSystem = null;
            VCenterAPI api = null;
            try {
                hostSystem = vmware.getHostSystem(dataCenter.getLabel(), host.getHostName(), false);
                // we'll need to hunt it down elsewhere.
                if (hostSystem == null) {
                    // Now look for the host system in other datacenters and clusters. If you find it, return false.
                    // If you do not find it, return true because it couldn't be found.
                    api = VcenterDiscoveryAdapter.createVCenterAPI(vcenter);
                    List<HostSystem> hostSystems = api.listAllHostSystems();
                    if (hostSystems == null || hostSystems.isEmpty()) {
                        // No host systems were found. We'll assume this is a lie and report a validation failure.
                        // But the error can be clear that we can not decommission if we're getting empty responses
                        // from the vSphere API.
                        ExecutionUtils.currentContext().logError("computeutils.decommission.failure.host.nohostsatall", host.getHostName());
                        return false;
                    }
                    for (HostSystem foundHostSystem : hostSystems) {
                        if (foundHostSystem != null && (foundHostSystem.getName().equalsIgnoreCase(host.getLabel()) || (foundHostSystem.getHardware() != null && foundHostSystem.getHardware().systemInfo != null && foundHostSystem.getHardware().systemInfo.uuid != null && foundHostSystem.getHardware().systemInfo.uuid.equalsIgnoreCase(host.getUuid())))) {
                            // We found a match someplace else in the vcenter. Post an error and return false.
                            ExecutionUtils.currentContext().logError("computeutils.decommission.failure.host.moved", host.getHostName());
                            return false;
                        }
                    }
                    // If we get to here, we can't find the host in this vCenter at all and we are going to fail. We don't want to
                    // delete this host from a vCenter outside of our control.
                    ExecutionUtils.currentContext().logInfo("computeutils.decommission.failure.host.notinvcenter", host.getHostName());
                    return false;
                } else {
                    // Make sure the UUID of the host matches what we have in our database.
                    if (hostSystem.getHardware() != null && hostSystem.getHardware().systemInfo != null && hostSystem.getHardware().systemInfo.uuid != null && !hostSystem.getHardware().systemInfo.uuid.equalsIgnoreCase(host.getUuid())) {
                        // The host UUID doesn't match what we have in our database. The host may have been renamed.
                        ExecutionUtils.currentContext().logError("computeutils.decommission.failure.host.uuidmismatch", host.getHostName());
                        return false;
                    }
                    // We found the host, so now we check that the host belongs to the correct cluster
                    if (hostSystem.getParent() != null && hostSystem.getParent() instanceof ClusterComputeResource) {
                        ClusterComputeResource clusterResource = (ClusterComputeResource) hostSystem.getParent();
                        if (clusterResource != null && clusterResource.getMOR() != null && clusterResource.getMOR().getVal() != null && !clusterResource.getMOR().getVal().equalsIgnoreCase(cluster.getExternalId())) {
                            // Host is in a different cluster, fail the validation
                            ExecutionUtils.currentContext().logError("computeutils.decommission.failure.host.moved", host.getHostName());
                            return false;
                        }
                    } else {
                        // We found the host but it doesn't belong to a cluster, fail the validation
                        ExecutionUtils.currentContext().logError("computeutils.decommission.failure.host.notincluster", host.getHostName());
                        return false;
                    }
                }
            } finally {
                if (api != null) {
                    api.logout();
                }
            }
        }
    } finally {
        if (vmware != null) {
            vmware.disconnect();
        }
    }
    return true;
}
Also used : VCenterAPI(com.iwave.ext.vmware.VCenterAPI) GetVcenterDataCenter(com.emc.sa.service.vmware.tasks.GetVcenterDataCenter) GetVcenter(com.emc.sa.service.vmware.tasks.GetVcenter) Vcenter(com.emc.storageos.db.client.model.Vcenter) ClusterComputeResource(com.vmware.vim25.mo.ClusterComputeResource) GetVcenter(com.emc.sa.service.vmware.tasks.GetVcenter) HostSystem(com.vmware.vim25.mo.HostSystem) GetVcenterDataCenter(com.emc.sa.service.vmware.tasks.GetVcenterDataCenter) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) 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) URI(java.net.URI)

Example 30 with VcenterDataCenter

use of com.emc.storageos.db.client.model.VcenterDataCenter in project coprhd-controller by CoprHD.

the class AddHostToClusterService method pushToVcenter.

private void pushToVcenter() {
    // If the cluster has a datacenter associated with it,
    // it needs to be updated and push hosts to vcenter
    VcenterDataCenter dataCenter = null;
    boolean status = true;
    URI existingDatacenterId = cluster.getVcenterDataCenter();
    if (!NullColumnValueGetter.isNullURI(existingDatacenterId)) {
        logInfo("vcenter.cluster.update", cluster.getLabel());
        try {
            dataCenter = ComputeUtils.getVcenterDataCenter(existingDatacenterId);
            // else invoke using datacenter obj so that we show a user friendly name in UI.
            if (dataCenter == null) {
                status = ComputeUtils.updateVcenterCluster(cluster, existingDatacenterId);
            } else {
                status = ComputeUtils.updateVcenterCluster(cluster, dataCenter);
            }
            if (!status) {
                throw new IllegalStateException(ExecutionUtils.getMessage("vcenter.cluster.update.failed", cluster.getLabel()));
            }
        } catch (Exception e) {
            logError("compute.cluster.vcenter.sync.failed.corrective.user.message", cluster.getLabel());
            logError("compute.cluster.vcenter.push.failed", e.getMessage());
            throw e;
        }
    }
}
Also used : GetVcenterDataCenter(com.emc.sa.service.vmware.tasks.GetVcenterDataCenter) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) URI(java.net.URI) ExecutionException(com.emc.sa.engine.ExecutionException)

Aggregations

VcenterDataCenter (com.emc.storageos.db.client.model.VcenterDataCenter)40 Host (com.emc.storageos.db.client.model.Host)27 Vcenter (com.emc.storageos.db.client.model.Vcenter)25 Cluster (com.emc.storageos.db.client.model.Cluster)19 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)15 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)15 URI (java.net.URI)12 VcenterControllerException (com.emc.storageos.vcentercontroller.exceptions.VcenterControllerException)11 VcenterObjectConnectionException (com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException)11 VcenterObjectNotFoundException (com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException)11 VcenterServerConnectionException (com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException)11 VcenterApiClient (com.emc.storageos.vcentercontroller.VcenterApiClient)10 HostSystem (com.vmware.vim25.mo.HostSystem)9 VCenterAPI (com.iwave.ext.vmware.VCenterAPI)7 GetVcenterDataCenter (com.emc.sa.service.vmware.tasks.GetVcenterDataCenter)4 ComputeSystemControllerException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)4 CoordinatorException (com.emc.storageos.coordinator.exceptions.CoordinatorException)4 ClientControllerException (com.emc.storageos.exceptions.ClientControllerException)4 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)4 ControllerException (com.emc.storageos.volumecontroller.ControllerException)4