Search in sources :

Example 6 with PortInfo

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

the class VPlexApiExportManager method findTargets.

/**
 * Finds the target FE ports corresponding to the ports identified by the
 * passed port information.
 *
 * @param targetPortInfo The target port information.
 * @param targetInfoList Out param containing the target information.
 * @param allTargetsOnSameCluster Whether or not all targets are on the same
 *            cluster.
 *
 * @return The cluster on which the targets were found.
 *
 * @throws VPlexApiException When an error occurs attempting to find the
 *             targets corresponding to the passed port information.
 */
private VPlexClusterInfo findTargets(List<PortInfo> targetPortInfo, List<VPlexTargetInfo> targetInfoList, boolean allTargetsOnSameCluster) throws VPlexApiException {
    VPlexClusterInfo targetClusterInfo = null;
    VPlexApiDiscoveryManager discoveryMgr = _vplexApiClient.getDiscoveryManager();
    List<VPlexClusterInfo> clusterInfoList = discoveryMgr.getClusterInfoLite();
    for (VPlexClusterInfo clusterInfo : clusterInfoList) {
        List<VPlexTargetInfo> clusterTargetInfoList = discoveryMgr.getTargetInfoForCluster(clusterInfo.getName());
        for (PortInfo portInfo : targetPortInfo) {
            String portWWN = portInfo.getPortWWN();
            for (VPlexTargetInfo clusterTargetInfo : clusterTargetInfoList) {
                // TBD: Check node WWNs as well? The are optional.
                if (portWWN.equals(clusterTargetInfo.getPortWwn())) {
                    targetInfoList.add(clusterTargetInfo);
                    targetClusterInfo = clusterInfo;
                    break;
                }
            }
        }
        // if we found one, we are done.
        if ((allTargetsOnSameCluster) && (!targetInfoList.isEmpty())) {
            break;
        }
    }
    return targetClusterInfo;
}
Also used : PortInfo(com.emc.storageos.vplex.api.clientdata.PortInfo)

Example 7 with PortInfo

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

the class VPlexApiExportManager method buildInitiatorInfoList.

/**
 * This methods builds the VPlexInitiatorInfo for the initiators which does not
 * exist on VPlex and returns the list of VPlexInitiatorInfo for all the initiators.
 *
 * @param alreadyFoundInitiatorInfoList List of initiators that exist on VPlex
 * @param initiatorPortInfo All the initiators that needs to be registered on VPlex
 * @param clusterInfo The VPlex cluster info for the VPlex cluster where initiators
 *            should be registered
 *
 * @return List of VPlexInitiatorInfo that includes all the initiators that needs
 *         to be registered and the initiators which already exist on VPlex
 */
List<VPlexInitiatorInfo> buildInitiatorInfoList(List<VPlexInitiatorInfo> alreadyFoundInitiatorInfoList, List<PortInfo> initiatorPortInfo, VPlexClusterInfo clusterInfo) {
    List<VPlexInitiatorInfo> initiatorInfoList = new ArrayList<VPlexInitiatorInfo>();
    // Create map by pwwn of the already found initiators on VPLEX.
    Map<String, VPlexInitiatorInfo> initiatorInfoMap = new HashMap<String, VPlexInitiatorInfo>();
    for (VPlexInitiatorInfo initiatorInfo : alreadyFoundInitiatorInfoList) {
        initiatorInfoMap.put(initiatorInfo.getPortWwn(), initiatorInfo);
    }
    // found on the VPLEX.
    for (PortInfo initiatorInfo : initiatorPortInfo) {
        if (initiatorInfoMap.get(initiatorInfo.getPortWWN()) != null) {
            initiatorInfoList.add(initiatorInfoMap.get(initiatorInfo.getPortWWN()));
        } else {
            // This initiator does not exist on VPlex. Create VPlexInitiatorInfo for it.
            s_logger.info("Creating VPlexInitiatorInfo for the initiator :" + initiatorInfo.getPortWWN());
            VPlexInitiatorInfo info = new VPlexInitiatorInfo();
            info.setRegistrationName(VPlexApiConstants.REGISTERED_INITIATOR_PREFIX + VPlexApiConstants.WWN_PREFIX + initiatorInfo.getPortWWN().toLowerCase());
            info.setName(VPlexApiConstants.UNREGISTERED_INITIATOR_PREFIX + VPlexApiConstants.WWN_PREFIX + initiatorInfo.getPortWWN().toLowerCase());
            info.setPortWwn(VPlexApiConstants.WWN_PREFIX + initiatorInfo.getPortWWN().toLowerCase());
            info.setNodeWwn(VPlexApiConstants.WWN_PREFIX + initiatorInfo.getNodeWWN().toLowerCase());
            if (initiatorInfo.getType() != null && !initiatorInfo.getType().isEmpty()) {
                info.setInitiatorType(Initiator_Type.valueOfType(initiatorInfo.getType()));
            }
            info.setPath(clusterInfo.getPath() + VPlexApiConstants.URI_INITIATORS + info.getName());
            initiatorInfoList.add(info);
        }
    }
    return initiatorInfoList;
}
Also used : PortInfo(com.emc.storageos.vplex.api.clientdata.PortInfo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 8 with PortInfo

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

the class VPlexApiTest method testCreateStorageViewWithInitiatorsAndVolumes.

/**
 * Tests the API createStorageView when target ports, initiator ports, and
 * virtual volumes are passed in the request.
 */
@Test
public void testCreateStorageViewWithInitiatorsAndVolumes() {
    boolean wasException = false;
    try {
        // Get the storage view name
        String storageViewName = _properties.getProperty(STORAGE_VIEW_NAME_PROP_KEY);
        // Get the target ports
        List<PortInfo> targetPortInfoList = new ArrayList<PortInfo>();
        String storageViewTargetsStr = _properties.getProperty(STORAGE_VIEW_TARGETS_PROP_KEY);
        StringTokenizer tokenizer = new StringTokenizer(storageViewTargetsStr, ",");
        while (tokenizer.hasMoreTokens()) {
            String portWWN = tokenizer.nextToken();
            PortInfo targetPortInfo = new PortInfo(portWWN);
            targetPortInfoList.add(targetPortInfo);
        }
        // Get the initiator ports
        List<PortInfo> initiatorPortInfoList = new ArrayList<PortInfo>();
        String storageViewInitiatorsStr = _properties.getProperty(STORAGE_VIEW_INITIATORS_PROP_KEY);
        tokenizer = new StringTokenizer(storageViewInitiatorsStr, ",");
        while (tokenizer.hasMoreTokens()) {
            String portWWN = tokenizer.nextToken();
            PortInfo initiatorPortInfo = new PortInfo(portWWN);
            initiatorPortInfoList.add(initiatorPortInfo);
        }
        // Create the virtual volume.
        VPlexVirtualVolumeInfo vvInfo = createSimpleVirtualVolume();
        Assert.assertNotNull(vvInfo);
        Map<String, Integer> vvMap = new HashMap<String, Integer>();
        vvMap.put(vvInfo.getName(), Integer.valueOf(VPlexApiConstants.LUN_UNASSIGNED));
        // Create the storage view
        VPlexStorageViewInfo storageViewInfo = _client.createStorageView(storageViewName, targetPortInfoList, initiatorPortInfoList, vvMap);
        Assert.assertNotNull(storageViewInfo);
        Assert.assertEquals(storageViewInfo.getName(), storageViewName);
        // Cleanup
        Boolean[] viewFound = new Boolean[] { new Boolean(false) };
        _client.deleteStorageView(storageViewName, VPLEX_TEST_CLUSTER, viewFound);
        _client.deleteVirtualVolume(vvInfo.getName(), true, false);
    } catch (Exception e) {
        wasException = true;
    }
    Assert.assertFalse(wasException);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PortInfo(com.emc.storageos.vplex.api.clientdata.PortInfo) StringTokenizer(java.util.StringTokenizer) Test(org.junit.Test)

Example 9 with PortInfo

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

the class VPlexApiTest method testRemoveVirtualVolumesFromStorageView.

/**
 * Tests the API removeVirtualVolumesFromStorageView.
 */
@Test
public void testRemoveVirtualVolumesFromStorageView() {
    boolean wasException = false;
    try {
        // Get the storage view name
        String storageViewName = _properties.getProperty(STORAGE_VIEW_NAME_PROP_KEY);
        // Get the target ports
        List<PortInfo> targetPortInfoList = new ArrayList<PortInfo>();
        String storageViewTargetsStr = _properties.getProperty(STORAGE_VIEW_TARGETS_PROP_KEY);
        StringTokenizer tokenizer = new StringTokenizer(storageViewTargetsStr, ",");
        while (tokenizer.hasMoreTokens()) {
            String portWWN = tokenizer.nextToken();
            PortInfo targetPortInfo = new PortInfo(portWWN);
            targetPortInfoList.add(targetPortInfo);
        }
        // Create the virtual volume.
        VPlexVirtualVolumeInfo vvInfo = createSimpleVirtualVolume();
        Assert.assertNotNull(vvInfo);
        Map<String, Integer> vvMap = new HashMap<String, Integer>();
        vvMap.put(vvInfo.getName(), Integer.valueOf(VPlexApiConstants.LUN_UNASSIGNED));
        // Create the storage view
        VPlexStorageViewInfo storageViewInfo = _client.createStorageView(storageViewName, targetPortInfoList, null, vvMap);
        Assert.assertNotNull(storageViewInfo);
        Assert.assertEquals(storageViewInfo.getName(), storageViewName);
        // Remove the virtual volume from the storage view.
        List<String> vvNames = new ArrayList<String>();
        vvNames.addAll(vvMap.keySet());
        _client.removeVirtualVolumesFromStorageView(storageViewName, VPLEX_TEST_CLUSTER, vvNames);
        // Cleanup
        Boolean[] viewFound = new Boolean[] { new Boolean(false) };
        _client.deleteStorageView(storageViewName, VPLEX_TEST_CLUSTER, viewFound);
        _client.deleteVirtualVolume(vvInfo.getName(), true, false);
    } catch (Exception e) {
        wasException = true;
    }
    Assert.assertFalse(wasException);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PortInfo(com.emc.storageos.vplex.api.clientdata.PortInfo) StringTokenizer(java.util.StringTokenizer) Test(org.junit.Test)

Example 10 with PortInfo

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

the class VPlexDeviceController method registerInitiators.

/**
 * A Workflow Step to register initiators on the VPLEX, if not already found registered.
 *
 * @param initiatorUris the initiator URIs to check for registration
 * @param vplexURI the VPLEX URI
 * @param vplexClusterName the VPLEX cluster name (like cluster-1 or cluster-2)
 * @param stepId the workflow step id
 * @throws ControllerException if something went wrong
 */
public void registerInitiators(List<URI> initiatorUris, URI vplexURI, String vplexClusterName, String stepId) throws ControllerException {
    try {
        WorkflowStepCompleter.stepExecuting(stepId);
        StorageSystem vplex = getDataObject(StorageSystem.class, vplexURI, _dbClient);
        VPlexApiClient client = getVPlexAPIClient(_vplexApiFactory, vplex, _dbClient);
        client.clearInitiatorCache(vplexClusterName);
        List<PortInfo> initiatorPortInfos = new ArrayList<PortInfo>();
        List<Initiator> inits = _dbClient.queryObject(Initiator.class, initiatorUris);
        for (Initiator initiator : inits) {
            PortInfo pi = new PortInfo(initiator.getInitiatorPort().toUpperCase().replaceAll(":", ""), initiator.getInitiatorNode().toUpperCase().replaceAll(":", ""), initiator.getLabel(), getVPlexInitiatorType(initiator));
            initiatorPortInfos.add(pi);
        }
        client.registerInitiators(initiatorPortInfos, vplexClusterName);
        WorkflowStepCompleter.stepSucceded(stepId);
    } catch (Exception ex) {
        _log.error("Exception registering initiators: " + ex.getMessage(), ex);
        String opName = ResourceOperationTypeEnum.REGISTER_EXPORT_INITIATOR.getName();
        ServiceError serviceError = VPlexApiException.errors.registerInitiatorsStepFailed(opName, ex);
        WorkflowStepCompleter.stepFailed(stepId, serviceError);
    }
}
Also used : PortInfo(com.emc.storageos.vplex.api.clientdata.PortInfo) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) Initiator(com.emc.storageos.db.client.model.Initiator) VPlexApiClient(com.emc.storageos.vplex.api.VPlexApiClient) ArrayList(java.util.ArrayList) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) VPlexApiException(com.emc.storageos.vplex.api.VPlexApiException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Aggregations

PortInfo (com.emc.storageos.vplex.api.clientdata.PortInfo)19 ArrayList (java.util.ArrayList)17 HashMap (java.util.HashMap)8 StringTokenizer (java.util.StringTokenizer)8 Test (org.junit.Test)8 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)6 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)6 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)6 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)6 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)6 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)6 ControllerException (com.emc.storageos.volumecontroller.ControllerException)6 VPlexApiClient (com.emc.storageos.vplex.api.VPlexApiClient)6 VPlexApiException (com.emc.storageos.vplex.api.VPlexApiException)6 WorkflowException (com.emc.storageos.workflow.WorkflowException)6 IOException (java.io.IOException)6 URISyntaxException (java.net.URISyntaxException)6 ExportMask (com.emc.storageos.db.client.model.ExportMask)5 NamedURI (com.emc.storageos.db.client.model.NamedURI)5 StoragePort (com.emc.storageos.db.client.model.StoragePort)5