Search in sources :

Example 41 with ExportGroup

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

the class VolumeIngestionUtil method initializeExportGroup.

/**
 * Initialize an Export Group.
 *
 * @param project the Project
 * @param type the ExportGroup type
 * @param vArray the VirtualArray for the ExportGroup
 * @param label the text label for the ExportGroup
 * @param dbClient a reference to the database client
 * @param nameGenerator a name generator
 * @param tenantOrg the TenantOrg to use
 * @return a newly-created ExportGroup
 */
public static ExportGroup initializeExportGroup(Project project, String type, URI vArray, String label, DbClient dbClient, ResourceAndUUIDNameGenerator nameGenerator, TenantOrg tenantOrg) {
    ExportGroup exportGroup = new ExportGroup();
    exportGroup.setLabel(label);
    exportGroup.setType(type);
    exportGroup.setId(URIUtil.createId(ExportGroup.class));
    exportGroup.setProject(new NamedURI(project.getId(), exportGroup.getLabel()));
    exportGroup.setVirtualArray(vArray);
    exportGroup.setTenant(new NamedURI(project.getTenantOrg().getURI(), exportGroup.getLabel()));
    String generatedName = nameGenerator.generate(tenantOrg.getLabel(), exportGroup.getLabel(), exportGroup.getId().toString(), '_', 56);
    exportGroup.setGeneratedName(generatedName);
    return exportGroup;
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) NamedURI(com.emc.storageos.db.client.model.NamedURI)

Example 42 with ExportGroup

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

the class ComputeSystemControllerImpl method addStepsForSynchronizeClusterExport.

/**
 * Synchronize a cluster's export groups by following steps:
 * - Add all hosts in the cluster that are not in the cluster's export groups
 * - Remove all hosts in cluster's export groups that don't belong to the cluster
 *
 * @param workflow
 *            the workflow
 * @param waitFor
 *            waitfor step
 * @param clusterHostIds
 *            hosts that belong to the cluster
 * @param clusterId
 *            cluster id
 * @return
 */
public String addStepsForSynchronizeClusterExport(Workflow workflow, String waitFor, List<URI> clusterHostIds, URI clusterId) {
    for (ExportGroup export : getSharedExports(_dbClient, clusterId)) {
        List<URI> existingInitiators = StringSetUtil.stringSetToUriList(export.getInitiators());
        List<URI> existingHosts = StringSetUtil.stringSetToUriList(export.getHosts());
        List<URI> updatedClusters = StringSetUtil.stringSetToUriList(export.getClusters());
        Map<URI, Integer> updatedVolumesMap = StringMapUtil.stringMapToVolumeMap(export.getVolumes());
        Set<URI> addedClusters = new HashSet<>();
        Set<URI> removedClusters = new HashSet<>();
        Set<URI> addedHosts = new HashSet<>();
        Set<URI> removedHosts = new HashSet<>();
        Set<URI> addedInitiators = new HashSet<>();
        Set<URI> removedInitiators = new HashSet<>();
        // 1. Add all hosts in clusters that are not in the cluster's export groups
        for (URI clusterHost : clusterHostIds) {
            if (!existingHosts.contains(clusterHost)) {
                _log.info("Adding host " + clusterHost + " to cluster export group " + export.getId());
                addedHosts.add(clusterHost);
                List<Initiator> hostInitiators = ComputeSystemHelper.queryInitiators(_dbClient, clusterHost);
                for (Initiator initiator : hostInitiators) {
                    addedInitiators.add(initiator.getId());
                }
            }
        }
        // 2. Remove all hosts in cluster's export groups that don't belong to the cluster
        Iterator<URI> existingHostsIterator = existingHosts.iterator();
        while (existingHostsIterator.hasNext()) {
            URI hostId = existingHostsIterator.next();
            if (!clusterHostIds.contains(hostId)) {
                removedHosts.add(hostId);
                _log.info("Removing host " + hostId + " from shared export group " + export.getId() + " because this host does not belong to the cluster");
                List<Initiator> hostInitiators = ComputeSystemHelper.queryInitiators(_dbClient, hostId);
                for (Initiator initiator : hostInitiators) {
                    removedInitiators.add(initiator.getId());
                }
            }
        }
        waitFor = workflow.createStep(UPDATE_EXPORT_GROUP_STEP, String.format("Updating export group %s", export.getId()), waitFor, export.getId(), export.getId().toString(), this.getClass(), updateExportGroupMethod(export.getId(), updatedVolumesMap, addedClusters, removedClusters, addedHosts, removedHosts, addedInitiators, removedInitiators), updateExportGroupRollbackMethod(export.getId()), null);
    }
    return waitFor;
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) Initiator(com.emc.storageos.db.client.model.Initiator) URI(java.net.URI) HashSet(java.util.HashSet)

Example 43 with ExportGroup

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

the class ComputeSystemControllerImpl method addStepsForClusterExportGroups.

public String addStepsForClusterExportGroups(Workflow workflow, String waitFor, URI clusterId) {
    List<ExportGroup> exportGroups = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, ExportGroup.class, AlternateIdConstraint.Factory.getConstraint(ExportGroup.class, "clusters", clusterId.toString()));
    for (ExportGroup export : exportGroups) {
        Set<URI> addedClusters = new HashSet<>();
        Set<URI> removedClusters = new HashSet<>();
        Set<URI> addedHosts = new HashSet<>();
        Set<URI> removedHosts = new HashSet<>();
        Set<URI> addedInitiators = new HashSet<>();
        Set<URI> removedInitiators = new HashSet<>();
        Map<URI, Integer> updatedVolumesMap = StringMapUtil.stringMapToVolumeMap(export.getVolumes());
        removedClusters.add(clusterId);
        List<URI> hostUris = ComputeSystemHelper.getChildrenUris(_dbClient, clusterId, Host.class, "cluster");
        for (URI hosturi : hostUris) {
            removedHosts.add(hosturi);
            removedInitiators.addAll(ComputeSystemHelper.getChildrenUris(_dbClient, hosturi, Initiator.class, "host"));
        }
        // VBDU [DONE]: COP-28452, This doesn't look that dangerous, as we might see more than one cluster in export
        // group. Delete export Group in controller means export all volumes in the export group.
        // This call's intention is to remove a host, if for some reason one of the export group doesn't have the
        // right set of initiator then we might end up in unexporting all volumes from all the hosts rather than
        // executing remove Host.
        // Fixed to only perform export update instead of delete
        waitFor = workflow.createStep(UPDATE_EXPORT_GROUP_STEP, String.format("Updating export group %s", export.getId()), waitFor, export.getId(), export.getId().toString(), this.getClass(), updateExportGroupMethod(export.getId(), updatedVolumesMap, addedClusters, removedClusters, addedHosts, removedHosts, addedInitiators, removedInitiators), updateExportGroupRollbackMethod(export.getId()), null);
    }
    return waitFor;
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) Initiator(com.emc.storageos.db.client.model.Initiator) URI(java.net.URI) HashSet(java.util.HashSet)

Example 44 with ExportGroup

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

the class ComputeSystemControllerImpl method verifyDatastore.

/**
 * Verifies that datastores contained within an export group can be unmounted. It must not be entering maintenance mode or contain any
 * virtual machines running on the given ESXi host.
 *
 * @param exportGroupId
 *            export group that contains volumes
 * @param vcenterId
 *            vcenter that the host belongs to
 * @param vcenterDatacenter
 *            vcenter datacenter that the host belongs to
 * @param esxHostname
 *            the hostname of the ESXi host
 *
 * @param stepId
 *            the id of the workflow step
 */
public void verifyDatastore(URI exportGroupId, URI vCenterId, URI vcenterDatacenter, String esxHostname, String stepId) {
    WorkflowStepCompleter.stepExecuting(stepId);
    try {
        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 host = api.findHostSystem(vCenterDataCenter.getLabel(), esxHostname);
        if (host == null) {
            _log.info("Not able to find host " + esxHostname + " in vCenter. Unable to validate");
            WorkflowStepCompleter.stepSucceded(stepId);
            return;
        }
        Map<String, Datastore> wwnDatastores = getWwnDatastoreMap(host);
        if (exportGroup != null && exportGroup.getVolumes() != null) {
            for (String volume : exportGroup.getVolumes().keySet()) {
                BlockObject blockObject = BlockObject.fetch(_dbClient, URI.create(volume));
                Datastore datastore = getDatastoreByWwn(wwnDatastores, blockObject.getWWN());
                if (datastore != null) {
                    ComputeSystemHelper.verifyDatastore(datastore, host);
                }
            }
        }
        // Test mechanism to invoke a failure. No-op on production systems.
        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_029);
        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) 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) BlockObject(com.emc.storageos.db.client.model.BlockObject) 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 45 with ExportGroup

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

the class ComputeSystemControllerImpl method addStepsForUpdateInitiators.

/**
 * Creates steps for updating export groups for the given host with the new and old initiators
 *
 * @param workflow the workflow
 * @param waitFor the wait for step
 * @param hostId the host id
 * @param newInitiatorIds list of new initiators added to the host
 * @param oldInitiatorIds list of old initiators removed from the host
 * @param eventId the actionable event id
 * @return wait for step id
 */
public String addStepsForUpdateInitiators(Workflow workflow, String waitFor, URI hostId, Collection<URI> newInitiatorIds, Collection<URI> oldInitiatorIds, URI eventId) {
    Map<URI, List<InitiatorChange>> map = getInitiatorOperations(hostId, newInitiatorIds, oldInitiatorIds);
    verifyNotRemovingAllInitiatorsFromExportGroup(map, hostId);
    for (URI eg : map.keySet()) {
        ExportGroup export = _dbClient.queryObject(ExportGroup.class, eg);
        Map<URI, Integer> updatedVolumesMap = StringMapUtil.stringMapToVolumeMap(export.getVolumes());
        Set<URI> addedClusters = new HashSet<>();
        Set<URI> removedClusters = new HashSet<>();
        Set<URI> addedHosts = new HashSet<>();
        Set<URI> removedHosts = new HashSet<>();
        boolean removingInitiator = true;
        // the list of initiators is empty. This is where we perform alternating Remove/Add initiator operations
        while (!map.get(export.getId()).isEmpty()) {
            Set<URI> addedInitiators = new HashSet<>();
            Set<URI> removedInitiators = new HashSet<>();
            boolean update = false;
            // Alternate between removing and then adding initiator to the export group
            if (removingInitiator) {
                Initiator remove = getNextInitiatorOperation(export.getId(), map, InitiatorOperation.REMOVE);
                if (remove != null) {
                    removedInitiators.add(remove.getId());
                    update = true;
                }
            } else {
                Initiator add = getNextInitiatorOperation(export.getId(), map, InitiatorOperation.ADD);
                if (add != null) {
                    addedInitiators.add(add.getId());
                    update = true;
                }
            }
            if (update) {
                waitFor = workflow.createStep(UPDATE_EXPORT_GROUP_STEP, String.format("Updating export group %s", export.getId()), waitFor, export.getId(), export.getId().toString(), this.getClass(), updateExportGroupMethod(export.getId(), updatedVolumesMap, addedClusters, removedClusters, addedHosts, removedHosts, addedInitiators, removedInitiators), updateExportGroupRollbackMethod(export.getId()), null);
            }
            removingInitiator = !removingInitiator;
        }
    }
    return waitFor;
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) Initiator(com.emc.storageos.db.client.model.Initiator) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList) ArrayList(java.util.ArrayList) List(java.util.List) URI(java.net.URI) HashSet(java.util.HashSet)

Aggregations

ExportGroup (com.emc.storageos.db.client.model.ExportGroup)278 URI (java.net.URI)206 ArrayList (java.util.ArrayList)139 ExportMask (com.emc.storageos.db.client.model.ExportMask)138 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)111 HashMap (java.util.HashMap)94 Initiator (com.emc.storageos.db.client.model.Initiator)86 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)84 NamedURI (com.emc.storageos.db.client.model.NamedURI)80 HashSet (java.util.HashSet)70 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)63 Workflow (com.emc.storageos.workflow.Workflow)61 List (java.util.List)59 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)55 BlockObject (com.emc.storageos.db.client.model.BlockObject)49 Map (java.util.Map)47 ExportOrchestrationTask (com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportOrchestrationTask)44 ControllerException (com.emc.storageos.volumecontroller.ControllerException)41 StringSet (com.emc.storageos.db.client.model.StringSet)38 StringMap (com.emc.storageos.db.client.model.StringMap)33