Search in sources :

Example 36 with Host

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

the class ComputeSystemControllerImpl method setHostBootVolumeId.

public void setHostBootVolumeId(URI hostId, URI volumeId, String stepId) throws ControllerException {
    _log.info("setHostBootVolumeId :" + hostId.toString());
    Host host = null;
    try {
        WorkflowStepCompleter.stepExecuting(stepId);
        host = _dbClient.queryObject(Host.class, hostId);
        if (host == null) {
            throw ComputeSystemControllerException.exceptions.hostNotFound(hostId.toString());
        }
        _log.info("Setting boot volume association for host");
        host.setBootVolumeId(volumeId);
        _dbClient.persistObject(host);
        WorkflowStepCompleter.stepSucceded(stepId);
    } catch (Exception e) {
        _log.error("unexpected exception: " + e.getMessage(), e);
        String hostString = hostId.toString();
        if (host != null) {
            hostString = host.getHostName();
        }
        ServiceCoded serviceCoded = ComputeSystemControllerException.exceptions.unableToSetBootVolume(hostString, e);
        WorkflowStepCompleter.stepFailed(stepId, serviceCoded);
    }
}
Also used : ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) 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)

Example 37 with Host

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

the class ComputeSystemControllerImpl method attachAndMount.

/**
 * Attaches and mounts every disk and datastore associated with the volumes in the export group.
 * For each volume in the export group, the associated disk is attached to the host and any datastores backed by the
 * volume are mounted
 * to 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 attachAndMount(URI exportGroupId, URI hostId, URI vCenterId, URI vcenterDatacenter, String stepId) {
    WorkflowStepCompleter.stepExecuting(stepId);
    try {
        // Test mechanism to invoke a failure. No-op on production systems.
        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_054);
        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 attach disks and mount datastores");
            WorkflowStepCompleter.stepSucceded(stepId);
            return;
        }
        HostStorageAPI storageAPI = new HostStorageAPI(hostSystem);
        if (exportGroup != null && exportGroup.getVolumes() != null) {
            _log.info("Refreshing storage");
            storageAPI.refreshStorage();
            Set<BlockObject> blockObjects = Sets.newHashSet();
            for (String volume : exportGroup.getVolumes().keySet()) {
                BlockObject blockObject = BlockObject.fetch(_dbClient, URI.create(volume));
                blockObjects.add(blockObject);
                for (HostScsiDisk entry : storageAPI.listScsiDisks()) {
                    if (VolumeWWNUtils.wwnMatches(VMwareUtils.getDiskWwn(entry), blockObject.getWWN())) {
                        if (VMwareUtils.isDiskOff(entry)) {
                            _log.info("Attach SCSI Lun " + entry.getCanonicalName() + " on host " + esxHost.getLabel());
                            storageAPI.attachScsiLun(entry);
                        }
                        // Test mechanism to invoke a failure. No-op on production systems.
                        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_055);
                        break;
                    }
                }
            }
            int retries = 0;
            while (retries++ < MAXIMUM_RESCAN_ATTEMPTS && !blockObjects.isEmpty()) {
                _log.info("Rescanning VMFS for host " + esxHost.getLabel());
                storageAPI.getStorageSystem().rescanVmfs();
                _log.info("Waiting for {} milliseconds before checking for datastores", RESCAN_DELAY_MS);
                Thread.sleep(RESCAN_DELAY_MS);
                _log.info("Looking for datastores for {} volumes", blockObjects.size());
                Map<String, Datastore> wwnDatastores = getWwnDatastoreMap(hostSystem);
                Iterator<BlockObject> objectIterator = blockObjects.iterator();
                while (objectIterator.hasNext()) {
                    BlockObject blockObject = objectIterator.next();
                    if (blockObject != null) {
                        Datastore datastore = getDatastoreByWwn(wwnDatastores, blockObject.getWWN());
                        if (datastore != null && VMwareUtils.isDatastoreMountedOnHost(datastore, hostSystem)) {
                            _log.info("Datastore {} is already mounted on {}", datastore.getName(), esxHost.getLabel());
                            objectIterator.remove();
                        } else if (datastore != null && !VMwareUtils.isDatastoreMountedOnHost(datastore, hostSystem)) {
                            _log.info("Mounting datastore {} on host {}", datastore.getName(), esxHost.getLabel());
                            storageAPI.mountDatastore(datastore);
                            objectIterator.remove();
                            // Test mechanism to invoke a failure. No-op on production systems.
                            InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_056);
                        }
                    }
                }
            }
        }
        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) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) 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 38 with Host

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

the class ComputeSystemControllerImpl method rescanHostStorage.

/**
 * Rescans HBAs and storage system for an ESX host
 *
 * @param hostId the host id
 * @param vCenterId the vcenter id
 * @param vcenterDatacenter the vcenter datacenter id
 * @param stepId the workflow step
 */
public void rescanHostStorage(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);
        VCenterAPI api = VcenterDiscoveryAdapter.createVCenterAPI(vCenter);
        HostSystem hostSystem = api.findHostSystem(vCenterDataCenter.getLabel(), esxHost.getLabel());
        if (hostSystem == null) {
            _log.info("Not able to find host {} in vCenter. Unable to refresh HBAs", esxHost.getLabel());
            WorkflowStepCompleter.stepSucceded(stepId);
            return;
        }
        HostStorageAPI storageAPI = new HostStorageAPI(hostSystem);
        storageAPI.refreshStorage();
        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) HostSystem(com.vmware.vim25.mo.HostSystem) Host(com.emc.storageos.db.client.model.Host) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) HostStorageAPI(com.iwave.ext.vmware.HostStorageAPI) 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)

Example 39 with Host

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

the class ComputeSystemControllerImpl method addStepForVcenterDataCenter.

public String addStepForVcenterDataCenter(Workflow workflow, String waitFor, URI datacenterUri) {
    VcenterDataCenter dataCenter = _dbClient.queryObject(VcenterDataCenter.class, datacenterUri);
    if (dataCenter != null && !dataCenter.getInactive()) {
        // clean all export related to host in datacenter
        List<NamedElementQueryResultList.NamedElement> hostUris = ComputeSystemHelper.listChildren(_dbClient, dataCenter.getId(), Host.class, "label", "vcenterDataCenter");
        for (NamedElementQueryResultList.NamedElement hostUri : hostUris) {
            Host host = _dbClient.queryObject(Host.class, hostUri.getId());
            // do not detach storage of provisioned hosts
            if (host != null && !host.getInactive() && NullColumnValueGetter.isNullURI(host.getComputeElement())) {
                waitFor = unmountHostStorage(workflow, waitFor, host.getId());
            }
        }
        List<NamedElementQueryResultList.NamedElement> clustersUris = ComputeSystemHelper.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()) {
                waitFor = unmountClusterStorage(workflow, waitFor, cluster.getId());
            }
        }
        for (NamedElementQueryResultList.NamedElement hostUri : hostUris) {
            Host host = _dbClient.queryObject(Host.class, hostUri.getId());
            // do not detach storage of provisioned hosts
            if (host != null && !host.getInactive() && NullColumnValueGetter.isNullURI(host.getComputeElement())) {
                waitFor = addStepsForExportGroups(workflow, waitFor, host.getId());
                waitFor = addStepsForFileShares(workflow, waitFor, host.getId());
            }
        }
        // cluster unexport removes the storage.(because we didn't consider the skipped hosts above)
        for (NamedElementQueryResultList.NamedElement clusterUri : clustersUris) {
            Cluster cluster = _dbClient.queryObject(Cluster.class, clusterUri.getId());
            if (cluster != null && !cluster.getInactive()) {
                waitFor = addStepsForClusterExportGroups(workflow, waitFor, cluster.getId());
            }
        }
    }
    return waitFor;
}
Also used : Cluster(com.emc.storageos.db.client.model.Cluster) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) Host(com.emc.storageos.db.client.model.Host) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList)

Example 40 with Host

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

the class ComputeSystemHelper method updateHostAndInitiatorClusterReferences.

/**
 * Update the cluster references for the host and its initiators
 *
 * @param dbClient dbclient
 * @param clusterURI the cluster that the host is being assigned to
 * @param hostURI the host id
 */
public static void updateHostAndInitiatorClusterReferences(DbClient dbClient, URI clusterURI, URI hostURI) {
    Host host = dbClient.queryObject(Host.class, hostURI);
    host.setCluster(clusterURI);
    dbClient.updateObject(host);
    updateInitiatorClusterName(dbClient, clusterURI, hostURI);
}
Also used : Host(com.emc.storageos.db.client.model.Host)

Aggregations

Host (com.emc.storageos.db.client.model.Host)227 URI (java.net.URI)104 Initiator (com.emc.storageos.db.client.model.Initiator)52 ArrayList (java.util.ArrayList)49 HashMap (java.util.HashMap)38 Cluster (com.emc.storageos.db.client.model.Cluster)37 HashSet (java.util.HashSet)35 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)33 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)32 VcenterDataCenter (com.emc.storageos.db.client.model.VcenterDataCenter)26 ComputeElement (com.emc.storageos.db.client.model.ComputeElement)24 Volume (com.emc.storageos.db.client.model.Volume)20 Path (javax.ws.rs.Path)20 Produces (javax.ws.rs.Produces)20 Vcenter (com.emc.storageos.db.client.model.Vcenter)19 ComputeSystemControllerException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)18 ExportMask (com.emc.storageos.db.client.model.ExportMask)18 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)17 NamedURI (com.emc.storageos.db.client.model.NamedURI)16 StringSet (com.emc.storageos.db.client.model.StringSet)16