Search in sources :

Example 76 with VPlexApiClient

use of com.emc.storageos.vplex.api.VPlexApiClient in project coprhd-controller by CoprHD.

the class VPlexConsistencyGroupManager method setCGProperties.

/**
 * Called by the workflow to set the properties for an existing VPLEX
 * consistency group with no volumes.
 *
 * @param vplexURI The URI of the VPLEX storage system.
 * @param cgURI The URI of the Bourne consistency group.
 * @param vplexVolumeURIs The URIs of the VPLEX volumes to be added to the
 *            consistency group.
 * @param stepId The workflow step id.
 *
 * @throws WorkflowException When an error occurs updating the workflow step
 *             state.
 */
public void setCGProperties(URI vplexURI, URI cgURI, List<URI> vplexVolumeURIs, String stepId) throws WorkflowException {
    try {
        // Update workflow step.
        WorkflowStepCompleter.stepExecuting(stepId);
        log.info("Updated step state for consistency group properties to execute.");
        // Lock the CG for the step duration.
        List<String> lockKeys = new ArrayList<String>();
        lockKeys.add(ControllerLockingUtil.getConsistencyGroupStorageKey(dbClient, cgURI, vplexURI));
        workflowService.acquireWorkflowStepLocks(stepId, lockKeys, LockTimeoutValue.get(LockType.RP_VPLEX_CG));
        // Get the API client.
        StorageSystem vplexSystem = getDataObject(StorageSystem.class, vplexURI, dbClient);
        VPlexApiClient client = getVPlexAPIClient(vplexApiFactory, vplexSystem, dbClient);
        log.info("Got VPLEX API client.");
        // Get the consistency group
        BlockConsistencyGroup cg = getDataObject(BlockConsistencyGroup.class, cgURI, dbClient);
        // We need to know on what cluster to find the consistency group.
        // The cluster would be determined by the virtual array specified in
        // a volume creation request, which is the virtual array of the
        // passed virtual volumes. Get the virtual array for one of the
        // vplex volumes.
        Volume firstVPlexVolume = getDataObject(Volume.class, vplexVolumeURIs.get(0), dbClient);
        ClusterConsistencyGroupWrapper clusterConsistencyGroup = getClusterConsistencyGroup(firstVPlexVolume, cg);
        String cgName = clusterConsistencyGroup.getCgName();
        String clusterName = clusterConsistencyGroup.getClusterName();
        boolean isDistributed = clusterConsistencyGroup.isDistributed();
        // Now we can update the consistency group properties.
        client.updateConsistencyGroupProperties(cgName, clusterName, isDistributed);
        log.info("Updated VPLEX consistency group properties.");
        // Update workflow step state to success.
        WorkflowStepCompleter.stepSucceded(stepId);
        log.info("Updated workflow step for consistency group properties to success.");
    } catch (VPlexApiException vae) {
        log.error("Exception updating consistency group properties: " + vae.getMessage(), vae);
        WorkflowStepCompleter.stepFailed(stepId, vae);
    } catch (Exception ex) {
        log.error("Exception updating consistency group properties: " + ex.getMessage(), ex);
        ServiceError serviceError = VPlexApiException.errors.jobFailed(ex);
        WorkflowStepCompleter.stepFailed(stepId, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ClusterConsistencyGroupWrapper(com.emc.storageos.volumecontroller.impl.utils.ClusterConsistencyGroupWrapper) Volume(com.emc.storageos.db.client.model.Volume) VPlexApiException(com.emc.storageos.vplex.api.VPlexApiException) VPlexApiClient(com.emc.storageos.vplex.api.VPlexApiClient) ArrayList(java.util.ArrayList) WorkflowException(com.emc.storageos.workflow.WorkflowException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) VPlexApiException(com.emc.storageos.vplex.api.VPlexApiException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup)

Example 77 with VPlexApiClient

use of com.emc.storageos.vplex.api.VPlexApiClient in project coprhd-controller by CoprHD.

the class VPlexConsistencyGroupManager method rollbackCreateCG.

/**
 * Method call when we need to rollback the deletion of a consistency group.
 *
 * @param vplexSystemURI The URI of the VPlex system.
 * @param cgURI The consistency group URI
 * @param deleteStepId The step that deleted the CG.
 * @param stepId The step id.
 */
public void rollbackCreateCG(URI vplexSystemURI, URI cgURI, String createStepId, String stepId) {
    try {
        // Update step state to executing.
        WorkflowStepCompleter.stepExecuting(stepId);
        log.info("Updated workflow step to executing");
        // Get the rollback data.
        Object rbDataObj = workflowService.loadStepData(createStepId);
        if (rbDataObj == null) {
            // Update step state to done.
            log.info("CG was not created, nothing to do.");
            cleanUpVplexCG(vplexSystemURI, cgURI, null, false);
            WorkflowStepCompleter.stepSucceded(stepId);
            return;
        }
        StorageSystem vplexSystem = getDataObject(StorageSystem.class, vplexSystemURI, dbClient);
        // Get the CG.
        BlockConsistencyGroup cg = getDataObject(BlockConsistencyGroup.class, cgURI, dbClient);
        // Get the VPlex API client.
        VPlexApiClient client = getVPlexAPIClient(vplexApiFactory, vplexSystem, dbClient);
        log.info("Got VPlex API client for VPlex system {}", vplexSystemURI);
        // at this point.
        if (BlockConsistencyGroupUtils.referencesVPlexCGs(cg, dbClient)) {
            for (StorageSystem storageSystem : BlockConsistencyGroupUtils.getVPlexStorageSystems(cg, dbClient)) {
                URI vplexSystemUri = storageSystem.getId();
                // Iterate over the VPlex consistency groups that need to be
                // deleted.
                Map<String, String> vplexCgsToDelete = new HashMap<String, String>();
                for (String clusterCgName : cg.getSystemConsistencyGroups().get(vplexSystemUri.toString())) {
                    String cgName = BlockConsistencyGroupUtils.fetchCgName(clusterCgName);
                    String clusterName = BlockConsistencyGroupUtils.fetchClusterName(clusterCgName);
                    if (!vplexCgsToDelete.containsKey(cgName)) {
                        vplexCgsToDelete.put(cgName, clusterName);
                    }
                }
                for (Map.Entry<String, String> vplexCg : vplexCgsToDelete.entrySet()) {
                    String cgName = vplexCg.getKey();
                    // Make a call to the VPlex API client to delete the consistency group.
                    client.deleteConsistencyGroup(cgName);
                    log.info(String.format("Deleted consistency group %s", cgName));
                    cleanUpVplexCG(vplexSystemURI, cgURI, cgName, false);
                }
            }
        }
        // Update step state to done.
        WorkflowStepCompleter.stepSucceded(stepId);
    } catch (VPlexApiException vae) {
        log.error("Exception rolling back VPLEX consistency group creation: " + vae.getMessage(), vae);
        WorkflowStepCompleter.stepFailed(stepId, vae);
    } catch (Exception ex) {
        log.error("Exception rolling back VPLEX consistency group creation: " + ex.getMessage(), ex);
        String opName = ResourceOperationTypeEnum.DELETE_CONSISTENCY_GROUP.getName();
        ServiceError serviceError = VPlexApiException.errors.deleteCGFailed(opName, ex);
        WorkflowStepCompleter.stepFailed(stepId, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) HashMap(java.util.HashMap) URI(java.net.URI) WorkflowException(com.emc.storageos.workflow.WorkflowException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) VPlexApiException(com.emc.storageos.vplex.api.VPlexApiException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup) VPlexApiException(com.emc.storageos.vplex.api.VPlexApiException) VPlexApiClient(com.emc.storageos.vplex.api.VPlexApiClient) VPlexControllerUtils.getDataObject(com.emc.storageos.vplexcontroller.VPlexControllerUtils.getDataObject) HashMap(java.util.HashMap) Map(java.util.Map) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 78 with VPlexApiClient

use of com.emc.storageos.vplex.api.VPlexApiClient in project coprhd-controller by CoprHD.

the class VPlexConsistencyGroupManager method addVolumesToCG.

/**
 * The method called by the workflow to add VPLEX volumes to a VPLEX
 * consistency group.
 *
 * @param vplexURI The URI of the VPLEX storage system.
 * @param cgURI The URI of the consistency group.
 * @param vplexVolumeURIs The URIs of the volumes to be added to the
 *            consistency group.
 * @param stepId The workflow step id.
 *
 * @throws WorkflowException When an error occurs updating the workflow step
 *             state.
 */
public void addVolumesToCG(URI vplexURI, URI cgURI, List<URI> vplexVolumeURIs, String stepId) throws WorkflowException {
    try {
        // Update workflow step.
        WorkflowStepCompleter.stepExecuting(stepId);
        log.info("Updated workflow step state to execute for add volumes to consistency group.");
        // Get the API client.
        StorageSystem vplexSystem = getDataObject(StorageSystem.class, vplexURI, dbClient);
        VPlexApiClient client = getVPlexAPIClient(vplexApiFactory, vplexSystem, dbClient);
        log.info("Got VPLEX API client.");
        Volume firstVPlexVolume = getDataObject(Volume.class, vplexVolumeURIs.get(0), dbClient);
        String cgName = getVplexCgName(firstVPlexVolume, cgURI);
        // Get the names of the volumes to be added.
        List<Volume> vplexVolumes = new ArrayList<Volume>();
        List<String> vplexVolumeNames = new ArrayList<String>();
        for (URI vplexVolumeURI : vplexVolumeURIs) {
            Volume vplexVolume = getDataObject(Volume.class, vplexVolumeURI, dbClient);
            vplexVolumes.add(vplexVolume);
            vplexVolumeNames.add(vplexVolume.getDeviceLabel());
            log.info("VPLEX volume:" + vplexVolume.getDeviceLabel());
        }
        log.info("Got VPLEX volume names.");
        long startTime = System.currentTimeMillis();
        // Add the volumes to the CG.
        client.addVolumesToConsistencyGroup(cgName, vplexVolumeNames);
        long elapsed = System.currentTimeMillis() - startTime;
        log.info(String.format("TIMER: Adding %s virtual volume(s) %s to the consistency group %s took %f seconds", vplexVolumeNames.size(), vplexVolumeNames, cgName, (double) elapsed / (double) 1000));
        // adding volumes to a CG after volume creation.
        for (Volume vplexVolume : vplexVolumes) {
            vplexVolume.setConsistencyGroup(cgURI);
            dbClient.updateObject(vplexVolume);
        }
        // Update workflow step state to success.
        WorkflowStepCompleter.stepSucceded(stepId);
        log.info("Updated workflow step state to success for add volumes to consistency group.");
    } catch (VPlexApiException vae) {
        log.error("Exception adding volumes to consistency group: " + vae.getMessage(), vae);
        WorkflowStepCompleter.stepFailed(stepId, vae);
    } catch (Exception ex) {
        log.error("Exception adding volumes to consistency group: " + ex.getMessage(), ex);
        ServiceError svcError = VPlexApiException.errors.jobFailed(ex);
        WorkflowStepCompleter.stepFailed(stepId, svcError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) Volume(com.emc.storageos.db.client.model.Volume) VPlexApiException(com.emc.storageos.vplex.api.VPlexApiException) VPlexApiClient(com.emc.storageos.vplex.api.VPlexApiClient) ArrayList(java.util.ArrayList) URI(java.net.URI) WorkflowException(com.emc.storageos.workflow.WorkflowException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) VPlexApiException(com.emc.storageos.vplex.api.VPlexApiException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 79 with VPlexApiClient

use of com.emc.storageos.vplex.api.VPlexApiClient in project coprhd-controller by CoprHD.

the class VPlexControllerUtils method getDeviceInfo.

/**
 * Returns a VPlexResourceInfo object for the given device name based
 * on its virtual volume type (local or distributed).
 *
 * @param deviceName the name of the device
 * @param virtualVolumeType the type of virtual volume (local or distributed)
 * @param vplexUri the URI of the VPLEX system
 * @param dbClient a reference to the database client
 *
 * @return a VPlexResourceInfo object for the device name
 * @throws VPlexApiException
 */
public static VPlexResourceInfo getDeviceInfo(String deviceName, String virtualVolumeType, URI vplexUri, DbClient dbClient) throws VPlexApiException {
    VPlexResourceInfo device = null;
    VPlexApiClient client = null;
    try {
        VPlexApiFactory vplexApiFactory = VPlexApiFactory.getInstance();
        client = VPlexControllerUtils.getVPlexAPIClient(vplexApiFactory, vplexUri, dbClient);
    } catch (URISyntaxException e) {
        log.error("cannot load vplex api client", e);
    }
    if (null != client) {
        device = client.getDeviceStructure(deviceName, virtualVolumeType);
    }
    return device;
}
Also used : VPlexApiClient(com.emc.storageos.vplex.api.VPlexApiClient) URISyntaxException(java.net.URISyntaxException) VPlexResourceInfo(com.emc.storageos.vplex.api.VPlexResourceInfo) VPlexApiFactory(com.emc.storageos.vplex.api.VPlexApiFactory)

Example 80 with VPlexApiClient

use of com.emc.storageos.vplex.api.VPlexApiClient in project coprhd-controller by CoprHD.

the class VPlexControllerUtils method getClusterNameForId.

/**
 * Returns the cluster name (free form, user-configurable)
 * for a given VPLEX cluster id (either "1" or "2").
 *
 * @param clusterId the cluster id (either "1" or "2")
 * @param vplexUri URI of the VPLEX to look at
 * @param dbClient a database client instance
 *
 * @return the cluster name as configured by the user, or null
 *         if it couldn't be determined
 */
public static String getClusterNameForId(String clusterId, URI vplexUri, DbClient dbClient) {
    String clusterName = null;
    VPlexApiClient client = null;
    try {
        VPlexApiFactory vplexApiFactory = VPlexApiFactory.getInstance();
        client = VPlexControllerUtils.getVPlexAPIClient(vplexApiFactory, vplexUri, dbClient);
    } catch (URISyntaxException e) {
        log.error("cannot load vplex api client", e);
    }
    if (null != client) {
        clusterName = client.getClusterNameForId(clusterId);
    }
    log.info("VPLEX cluster name for cluster id {} is {}", clusterId, clusterName);
    return clusterName;
}
Also used : VPlexApiClient(com.emc.storageos.vplex.api.VPlexApiClient) URISyntaxException(java.net.URISyntaxException) VPlexApiFactory(com.emc.storageos.vplex.api.VPlexApiFactory)

Aggregations

VPlexApiClient (com.emc.storageos.vplex.api.VPlexApiClient)81 VPlexApiException (com.emc.storageos.vplex.api.VPlexApiException)57 URISyntaxException (java.net.URISyntaxException)57 ControllerException (com.emc.storageos.volumecontroller.ControllerException)55 WorkflowException (com.emc.storageos.workflow.WorkflowException)55 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)54 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)52 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)52 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)52 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)48 IOException (java.io.IOException)47 URI (java.net.URI)41 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)40 Volume (com.emc.storageos.db.client.model.Volume)34 ArrayList (java.util.ArrayList)34 NamedURI (com.emc.storageos.db.client.model.NamedURI)26 HashMap (java.util.HashMap)18 ExportMask (com.emc.storageos.db.client.model.ExportMask)16 VPlexStorageViewInfo (com.emc.storageos.vplex.api.VPlexStorageViewInfo)16 VPlexVirtualVolumeInfo (com.emc.storageos.vplex.api.VPlexVirtualVolumeInfo)16