Search in sources :

Example 36 with VcenterDataCenter

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

the class ActionableEventExecutor method hostVcenterChangeDetails.

/**
 * Get details for the hostVcenterChange method
 * NOTE: In order to maintain backwards compatibility, do not change the signature of this method.
 *
 * @param hostId the host that is moving vcenters
 * @param clusterId the cluster the host is moving to
 * @param datacenterId the datacenter the host is moving to
 * @param isVcenter if true, vcenter api operations will be executed against the host to detach/unmount and attach/mount disks and
 *            datastores
 * @return list of event details
 */
// Invoked using reflection for the event framework
@SuppressWarnings("unused")
public List<String> hostVcenterChangeDetails(URI hostId, URI clusterId, URI datacenterId, boolean isVcenter) {
    List<String> result = Lists.newArrayList();
    Host host = _dbClient.queryObject(Host.class, hostId);
    VcenterDataCenter datacenter = _dbClient.queryObject(VcenterDataCenter.class, datacenterId);
    if (host != null && datacenter != null) {
        result.add(ComputeSystemDialogProperties.getMessage("ComputeSystem.hostVcenterChangeDetails", host.getLabel(), datacenter.getLabel()));
        result.addAll(hostClusterChangeDetails(hostId, clusterId, datacenterId, isVcenter));
    }
    return result;
}
Also used : Host(com.emc.storageos.db.client.model.Host) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter)

Example 37 with VcenterDataCenter

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

the class ComputeSystemHelper method isDataCenterInUse.

/**
 * Checks if an datacenter is in use by an export groups
 *
 * @param dbClient
 * @param datacenterURI the datacenter URI
 * @return true if the datacenter is in used by an export group.
 */
public static boolean isDataCenterInUse(DbClient dbClient, URI datacenterURI) {
    VcenterDataCenter dataCenter = dbClient.queryObject(VcenterDataCenter.class, datacenterURI);
    if (dataCenter != null && !dataCenter.getInactive()) {
        List<NamedElementQueryResultList.NamedElement> hostUris = listChildren(dbClient, dataCenter.getId(), Host.class, "label", "vcenterDataCenter");
        for (NamedElementQueryResultList.NamedElement hostUri : hostUris) {
            Host host = dbClient.queryObject(Host.class, hostUri.getId());
            // ignore provisioned hosts
            if (host != null && !host.getInactive() && NullColumnValueGetter.isNullURI(host.getComputeElement()) && isHostInUse(dbClient, host.getId())) {
                return true;
            }
        }
        List<NamedElementQueryResultList.NamedElement> clustersUris = listChildren(dbClient, dataCenter.getId(), Cluster.class, "label", "vcenterDataCenter");
        for (NamedElementQueryResultList.NamedElement clusterUri : clustersUris) {
            Cluster cluster = dbClient.queryObject(Cluster.class, clusterUri.getId());
            if (cluster != null && !cluster.getInactive() && isClusterInExport(dbClient, clusterUri.getId())) {
                return true;
            }
        }
    }
    return false;
}
Also used : NamedElement(com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement) Cluster(com.emc.storageos.db.client.model.Cluster) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) Host(com.emc.storageos.db.client.model.Host) NamedElement(com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList)

Example 38 with VcenterDataCenter

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

the class ComputeSystemControllerImpl method rescanHostStorage.

/**
 * Creates workflow steps for rescanning HBAs and host storage for a list of ESX hosts
 *
 * @param hostIds list of host ids
 * @param virtualDataCenter the virtual datacenter id that the hosts belong to
 * @param waitFor the step to wait on for this workflow step
 * @param workflow the workflow
 * @return the step id
 */
private String rescanHostStorage(List<URI> hostIds, URI virtualDataCenter, String waitFor, Workflow workflow) {
    String newWaitFor = waitFor;
    for (URI hostId : hostIds) {
        Host esxHost = _dbClient.queryObject(Host.class, hostId);
        if (esxHost != null) {
            VcenterDataCenter vcenterDataCenter = _dbClient.queryObject(VcenterDataCenter.class, virtualDataCenter);
            if (vcenterDataCenter != null) {
                URI vCenterId = vcenterDataCenter.getVcenter();
                newWaitFor = workflow.createStep(RESCAN_HOST_STORAGE_STEP, String.format("Refreshing HBAs for host %s", esxHost.forDisplay()), newWaitFor, esxHost.getId(), esxHost.getId().toString(), this.getClass(), rescanHostStorageMethod(esxHost.getId(), vCenterId, vcenterDataCenter.getId()), rollbackMethodNullMethod(), null);
            }
        }
    }
    return newWaitFor;
}
Also used : Host(com.emc.storageos.db.client.model.Host) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) URI(java.net.URI)

Example 39 with VcenterDataCenter

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

the class ComputeSystemControllerImpl method unmountAndDetach.

/**
 * Unmounts and detaches every datastore and disk associated with the volumes in the export group.
 * For each volume in the export group, the backed datastore is unmounted and the associated disk is detached from
 * the host.
 *
 * @param exportGroupId
 *            export group that contains volumes
 * @param hostId
 *            host to attach and mount to
 * @param vcenterId
 *            vcenter that the host belongs to
 * @param vcenterDatacenter
 *            vcenter datacenter that the host belongs to
 * @param stepId
 *            the id of the workflow step
 */
public void unmountAndDetach(URI exportGroupId, URI hostId, URI vCenterId, URI vcenterDatacenter, String stepId) {
    WorkflowStepCompleter.stepExecuting(stepId);
    try {
        Host esxHost = _dbClient.queryObject(Host.class, hostId);
        Vcenter vCenter = _dbClient.queryObject(Vcenter.class, vCenterId);
        VcenterDataCenter vCenterDataCenter = _dbClient.queryObject(VcenterDataCenter.class, vcenterDatacenter);
        ExportGroup exportGroup = _dbClient.queryObject(ExportGroup.class, exportGroupId);
        VCenterAPI api = VcenterDiscoveryAdapter.createVCenterAPI(vCenter);
        HostSystem hostSystem = api.findHostSystem(vCenterDataCenter.getLabel(), esxHost.getLabel());
        if (hostSystem == null) {
            _log.info("Not able to find host " + esxHost.getLabel() + " in vCenter. Unable to validate");
            WorkflowStepCompleter.stepSucceded(stepId);
            return;
        }
        HostStorageAPI storageAPI = new HostStorageAPI(hostSystem);
        Map<String, Datastore> wwnDatastores = getWwnDatastoreMap(hostSystem);
        if (exportGroup != null && exportGroup.getVolumes() != null) {
            for (String volume : exportGroup.getVolumes().keySet()) {
                BlockObject blockObject = BlockObject.fetch(_dbClient, URI.create(volume));
                if (blockObject != null) {
                    Datastore datastore = getDatastoreByWwn(wwnDatastores, blockObject.getWWN());
                    if (datastore != null) {
                        if (VMwareUtils.isDatastoreMountedOnHost(datastore, hostSystem)) {
                            boolean storageIOControlEnabled = datastore.getIormConfiguration().isEnabled();
                            if (storageIOControlEnabled) {
                                setStorageIOControl(api, datastore, false);
                            }
                            _log.info("Unmount datastore " + datastore.getName() + " from host " + esxHost.getLabel());
                            storageAPI.unmountVmfsDatastore(datastore);
                            if (storageIOControlEnabled) {
                                setStorageIOControl(api, datastore, true);
                            }
                        } else {
                            _log.info("Datastore " + datastore.getName() + " is not mounted on host " + esxHost.getLabel() + ". Skipping unmounting of datastore.");
                        }
                    }
                }
                // VBDU TODO: COP-28459, If datastore doesn't match, why do we need to run DetachSCSILun() ?
                // Test mechanism to invoke a failure. No-op on production systems.
                InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_030);
                for (HostScsiDisk entry : storageAPI.listScsiDisks()) {
                    if (VolumeWWNUtils.wwnMatches(VMwareUtils.getDiskWwn(entry), blockObject.getWWN())) {
                        if (!VMwareUtils.isDiskOff(entry)) {
                            _log.info("Detach SCSI Lun " + entry.getCanonicalName() + " from host " + esxHost.getLabel());
                            storageAPI.detachScsiLun(entry);
                        } else {
                            _log.info("SCSI Lun " + entry.getCanonicalName() + " is not in a valid state to detach");
                        }
                    }
                }
                storageAPI.refreshStorage();
                // Test mechanism to invoke a failure. No-op on production systems.
                InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_031);
            }
        }
        WorkflowStepCompleter.stepSucceded(stepId);
    } catch (Exception ex) {
        _log.error(ex.getMessage(), ex);
        WorkflowStepCompleter.stepFailed(stepId, DeviceControllerException.errors.jobFailed(ex));
    }
}
Also used : VCenterAPI(com.iwave.ext.vmware.VCenterAPI) Vcenter(com.emc.storageos.db.client.model.Vcenter) Host(com.emc.storageos.db.client.model.Host) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) ComputeSystemControllerException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) RemoteException(java.rmi.RemoteException) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) ClientControllerException(com.emc.storageos.exceptions.ClientControllerException) ExportGroup(com.emc.storageos.db.client.model.ExportGroup) Datastore(com.vmware.vim25.mo.Datastore) HostSystem(com.vmware.vim25.mo.HostSystem) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) HostScsiDisk(com.vmware.vim25.HostScsiDisk) HostStorageAPI(com.iwave.ext.vmware.HostStorageAPI) BlockObject(com.emc.storageos.db.client.model.BlockObject)

Example 40 with VcenterDataCenter

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

the class VcenterCompleter method complete.

@Override
protected void complete(DbClient dbClient, Status status, ServiceCoded coded) throws DeviceControllerException {
    super.complete(dbClient, status, coded);
    switch(status) {
        case error:
            dbClient.error(Vcenter.class, this.getId(), getOpId(), coded);
            break;
        default:
            dbClient.ready(Vcenter.class, this.getId(), getOpId());
    }
    if (deactivateOnComplete && status.equals(Status.ready)) {
        Vcenter vcenter = dbClient.queryObject(Vcenter.class, this.getId());
        List<NamedElementQueryResultList.NamedElement> datacenterUris = ComputeSystemHelper.listChildren(dbClient, vcenter.getId(), VcenterDataCenter.class, "label", "vcenter");
        for (NamedElementQueryResultList.NamedElement datacenterUri : datacenterUris) {
            VcenterDataCenter dataCenter = dbClient.queryObject(VcenterDataCenter.class, datacenterUri.getId());
            if (dataCenter != null && !dataCenter.getInactive()) {
                ComputeSystemHelper.doDeactivateVcenterDataCenter(dbClient, dataCenter);
            }
        }
        vcenter.setRegistrationStatus(RegistrationStatus.UNREGISTERED.toString());
        dbClient.markForDeletion(vcenter);
        _logger.info("Deactivating Vcenter: " + this.getId());
    }
}
Also used : Vcenter(com.emc.storageos.db.client.model.Vcenter) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList)

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