Search in sources :

Example 16 with VNXeBase

use of com.emc.storageos.vnxe.models.VNXeBase in project coprhd-controller by CoprHD.

the class VNXUnityBlockStorageDevice method doDeleteVolumes.

@Override
public void doDeleteVolumes(StorageSystem storageSystem, String opId, List<Volume> volumes, TaskCompleter completer) throws DeviceControllerException {
    logger.info("deleting volumes, array: {}", storageSystem.getSerialNumber());
    VNXeApiClient apiClient = getVnxUnityClient(storageSystem);
    Map<String, List<String>> cgNameMap = new HashMap<String, List<String>>();
    try {
        Set<URI> updateStoragePools = new HashSet<URI>();
        // Invoke a test failure if testing
        for (Volume volume : volumes) {
            String lunId = volume.getNativeId();
            if (NullColumnValueGetter.isNullValue(lunId)) {
                logger.info(String.format("The volume %s does not have native id, do nothing", volume.getLabel()));
                continue;
            }
            updateStoragePools.add(volume.getPool());
            if (!apiClient.checkLunExists(lunId)) {
                logger.info(String.format("The volume %s does not exist in the array, do nothing", volume.getLabel()));
                continue;
            }
            String cgName = volume.getReplicationGroupInstance();
            if (NullColumnValueGetter.isNotNullValue(cgName)) {
                List<String> lunIds = cgNameMap.get(cgName);
                if (lunIds == null) {
                    lunIds = new ArrayList<String>();
                    cgNameMap.put(cgName, lunIds);
                }
                lunIds.add(volume.getNativeId());
            } else {
                InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_035);
                apiClient.deleteLunSync(volume.getNativeId(), false);
                InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_036);
            }
        }
        for (Map.Entry<String, List<String>> entry : cgNameMap.entrySet()) {
            String cgName = entry.getKey();
            List<String> lunIDs = entry.getValue();
            String cgId = apiClient.getConsistencyGroupIdByName(cgName);
            boolean isRP = false;
            if (cgId != null && !cgId.isEmpty()) {
                // Check if the CG has blockHostAccess to a RP host. if the CG is exported to a RP, we could not delete the lun
                // directly, we have to remove the volume from the CG first, then delete it.
                StorageResource cg = apiClient.getStorageResource(cgId);
                List<BlockHostAccess> hosts = cg.getBlockHostAccess();
                if (hosts != null && !hosts.isEmpty()) {
                    for (BlockHostAccess hostAccess : hosts) {
                        VNXeBase hostId = hostAccess.getHost();
                        if (hostId != null) {
                            VNXeHost host = apiClient.getHostById(hostId.getId());
                            if (host != null) {
                                if (host.getType() == HostTypeEnum.RPA.getValue()) {
                                    // Remove the luns from the CG
                                    isRP = true;
                                    logger.info(String.format("Removing volumes from CG because the CG %sis exported to RP", cgName));
                                    VNXeUtils.getCGLock(workflowService, storageSystem, cgName, opId);
                                    InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_034);
                                    apiClient.removeLunsFromConsistencyGroup(cgId, lunIDs);
                                    for (String lunId : lunIDs) {
                                        logger.info(String.format("Deleting the volume %s", lunId));
                                        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_035);
                                        apiClient.deleteLunSync(lunId, false);
                                        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_036);
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            if (!isRP) {
                VNXeUtils.getCGLock(workflowService, storageSystem, cgName, opId);
                InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_034);
                apiClient.deleteLunsFromConsistencyGroup(cgId, lunIDs);
                InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_037);
            }
        }
        for (URI pool : updateStoragePools) {
            VNXeJob.updateStoragePoolCapacity(dbClient, apiClient, pool, null);
        }
        completer.ready(dbClient);
    } catch (VNXeException e) {
        logger.error("Delete volumes got the exception", e);
        completer.error(dbClient, e);
    } catch (Exception ex) {
        logger.error("Delete volumes got the exception", ex);
        ServiceError error = DeviceControllerErrors.vnxe.jobFailed("DeleteVolumes", ex.getMessage());
        completer.error(dbClient, error);
    }
}
Also used : StorageResource(com.emc.storageos.vnxe.models.StorageResource) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) HashMap(java.util.HashMap) VNXeHost(com.emc.storageos.vnxe.models.VNXeHost) URI(java.net.URI) VNXeException(com.emc.storageos.vnxe.VNXeException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) BlockHostAccess(com.emc.storageos.vnxe.models.BlockHostAccess) VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) Volume(com.emc.storageos.db.client.model.Volume) VNXeException(com.emc.storageos.vnxe.VNXeException) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) StringMap(com.emc.storageos.db.client.model.StringMap) HashSet(java.util.HashSet)

Example 17 with VNXeBase

use of com.emc.storageos.vnxe.models.VNXeBase in project coprhd-controller by CoprHD.

the class VNXUnityExportOperations method findHLUsForInitiators.

@Override
public Set<Integer> findHLUsForInitiators(StorageSystem storage, List<String> initiatorNames, boolean mustHaveAllPorts) {
    Set<Integer> usedHLUs = new HashSet<Integer>();
    try {
        Set<String> vnxeHostIds = new HashSet<String>();
        VNXeApiClient apiClient = getVnxeClient(storage);
        for (String initiatorName : initiatorNames) {
            initiatorName = Initiator.toPortNetworkId(initiatorName);
            URIQueryResultList initiatorResult = new URIQueryResultList();
            _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getInitiatorPortInitiatorConstraint(initiatorName), initiatorResult);
            if (initiatorResult.iterator().hasNext()) {
                Initiator initiator = _dbClient.queryObject(Initiator.class, initiatorResult.iterator().next());
                String initiatorId = initiator.getInitiatorPort();
                if (Protocol.FC.name().equals(initiator.getProtocol())) {
                    initiatorId = initiator.getInitiatorNode() + ":" + initiatorId;
                }
                // query VNX Unity initiator
                VNXeHostInitiator vnxeInitiator = apiClient.getInitiatorByWWN(initiatorId);
                if (vnxeInitiator != null) {
                    VNXeBase parentHost = vnxeInitiator.getParentHost();
                    if (parentHost != null) {
                        vnxeHostIds.add(parentHost.getId());
                    }
                }
            }
        }
        if (vnxeHostIds.isEmpty()) {
            log.info("No Host found on array for initiators {}", Joiner.on(',').join(initiatorNames));
        } else {
            log.info("Found matching hosts {} on array", vnxeHostIds);
            for (String vnxeHostId : vnxeHostIds) {
                // Get vnxeHost from vnxeHostId
                VNXeHost vnxeHost = apiClient.getHostById(vnxeHostId);
                List<VNXeBase> hostLunIds = vnxeHost.getHostLUNs();
                if (hostLunIds != null && !hostLunIds.isEmpty()) {
                    for (VNXeBase hostLunId : hostLunIds) {
                        HostLun hostLun = apiClient.getHostLun(hostLunId.getId());
                        log.info("Looking at Host Lun {}; Lun: {}, HLU: {}", hostLunId.getId(), hostLun.getLun(), hostLun.getHlu());
                        usedHLUs.add(hostLun.getHlu());
                    }
                }
            }
        }
        log.info(String.format("HLUs found for Initiators { %s }: %s", Joiner.on(',').join(initiatorNames), usedHLUs));
    } catch (Exception e) {
        String errMsg = "Encountered an error when attempting to query used HLUs for initiators: " + e.getMessage();
        log.error(errMsg, e);
        throw VNXeException.exceptions.hluRetrievalFailed(errMsg, e);
    }
    return usedHLUs;
}
Also used : VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) HostLun(com.emc.storageos.vnxe.models.HostLun) VNXeHost(com.emc.storageos.vnxe.models.VNXeHost) VNXeHostInitiator(com.emc.storageos.vnxe.models.VNXeHostInitiator) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) VNXeException(com.emc.storageos.vnxe.VNXeException) VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) Initiator(com.emc.storageos.db.client.model.Initiator) VNXeHostInitiator(com.emc.storageos.vnxe.models.VNXeHostInitiator) HashSet(java.util.HashSet)

Example 18 with VNXeBase

use of com.emc.storageos.vnxe.models.VNXeBase in project coprhd-controller by CoprHD.

the class VNXUnityFileStorageDevice method extraExportRuleFromArray.

/**
 * Get the export rule which are present in array but not in CoprHD Database.
 *
 * @param storage
 * @param args
 * @return map with security flavor and export rule
 */
private Map<String, ExportRule> extraExportRuleFromArray(StorageSystem storage, FileDeviceInputOutput args) {
    // map to store the export rule grouped by sec flavor
    Map<String, ExportRule> exportRuleMap = new HashMap<>();
    List<VNXeNfsShare> exportsList = new ArrayList<VNXeNfsShare>();
    Set<String> arrayReadOnlyHost = new HashSet<>();
    Set<String> arrayReadWriteHost = new HashSet<>();
    Set<String> arrayRootHost = new HashSet<>();
    Set<String> dbReadOnlyHost = new HashSet<>();
    Set<String> dbReadWriteHost = new HashSet<>();
    Set<String> dbRootHost = new HashSet<>();
    // get all export rule from CoprHD data base
    List<ExportRule> existingDBExportRules = args.getExistingDBExportRules();
    // get the all the export from the storage system.
    VNXeApiClient apiClient = getVnxUnityClient(storage);
    for (ExportRule exportRule : existingDBExportRules) {
        if (exportRule.getReadOnlyHosts() != null) {
            dbReadOnlyHost.addAll(exportRule.getReadOnlyHosts());
        }
        if (exportRule.getReadWriteHosts() != null) {
            dbReadWriteHost.addAll(exportRule.getReadWriteHosts());
        }
        if (exportRule.getRootHosts() != null) {
            dbRootHost.addAll(exportRule.getRootHosts());
        }
        String vnxeExportId = exportRule.getDeviceExportId();
        if (vnxeExportId != null) {
            List<VNXeNfsShare> vnxeExports = null;
            vnxeExports = apiClient.getNfsSharesForFileSystem(args.getFs().getNativeId());
            exportsList.addAll(vnxeExports);
            for (VNXeNfsShare vnXeNfsShare : vnxeExports) {
                List<VNXeBase> hostIdReadOnly = vnXeNfsShare.getReadOnlyHosts();
                for (VNXeBase vnXeBase : hostIdReadOnly) {
                    VNXeHost host = apiClient.getHostById(vnXeBase.getId());
                    arrayReadOnlyHost.add(host.getName());
                }
                List<VNXeBase> hostIdReadWrite = vnXeNfsShare.getReadWriteHosts();
                for (VNXeBase vnXeBase : hostIdReadWrite) {
                    VNXeHost host = apiClient.getHostById(vnXeBase.getId());
                    arrayReadWriteHost.add(host.getName());
                }
                List<VNXeBase> hostIdRootHost = vnXeNfsShare.getRootAccessHosts();
                for (VNXeBase vnXeBase : hostIdRootHost) {
                    VNXeHost host = apiClient.getHostById(vnXeBase.getId());
                    arrayRootHost.add(host.getName());
                }
            }
        }
        // find out the change between array and CoprHD database.
        Set<String> arrayExtraReadOnlyHost = Sets.difference(arrayReadOnlyHost, dbReadOnlyHost);
        Set<String> arrayExtraReadWriteHost = Sets.difference(arrayReadWriteHost, dbReadWriteHost);
        Set<String> arrayExtraRootHost = Sets.difference(arrayRootHost, dbRootHost);
        // if change found update the exportRuleMap
        if (!arrayExtraReadOnlyHost.isEmpty() || !arrayExtraReadWriteHost.isEmpty() || !arrayExtraRootHost.isEmpty()) {
            ExportRule extraRuleFromArray = new ExportRule();
            extraRuleFromArray.setDeviceExportId(exportRule.getDeviceExportId());
            extraRuleFromArray.setAnon(exportRule.getAnon());
            extraRuleFromArray.setSecFlavor(exportRule.getSecFlavor());
            extraRuleFromArray.setExportPath(exportRule.getExportPath());
            extraRuleFromArray.setReadOnlyHosts(arrayExtraReadOnlyHost);
            extraRuleFromArray.setReadWriteHosts(arrayExtraReadWriteHost);
            extraRuleFromArray.setRootHosts(arrayExtraRootHost);
            exportRuleMap.put(exportRule.getSecFlavor(), extraRuleFromArray);
        }
    }
    return exportRuleMap;
}
Also used : HashMap(java.util.HashMap) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) ArrayList(java.util.ArrayList) VNXeHost(com.emc.storageos.vnxe.models.VNXeHost) VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) VNXeNfsShare(com.emc.storageos.vnxe.models.VNXeNfsShare) ExportRule(com.emc.storageos.model.file.ExportRule) HashSet(java.util.HashSet)

Example 19 with VNXeBase

use of com.emc.storageos.vnxe.models.VNXeBase in project coprhd-controller by CoprHD.

the class FileSystemSnapRequestsTest method createFileSystemSnap.

// @Test
public void createFileSystemSnap() {
    FileSystemSnapCreateParam parm = new FileSystemSnapCreateParam();
    VNXeBase resource = new VNXeBase();
    resource.setId("res_12");
    parm.setStorageResource(resource);
    parm.setName("test-snap");
    parm.setIsReadOnly(false);
    FileSystemSnapRequests req = new FileSystemSnapRequests(_client);
    VNXeCommandJob response = null;
    try {
        response = req.createFileSystemSnap(parm);
    } catch (VNXeException e) {
        // TODO Auto-generated catch block
        logger.error("VNXeException occured", e);
    }
    System.out.println(response.getId() + "state: " + response.getState());
}
Also used : VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) VNXeException(com.emc.storageos.vnxe.VNXeException) FileSystemSnapCreateParam(com.emc.storageos.vnxe.models.FileSystemSnapCreateParam)

Example 20 with VNXeBase

use of com.emc.storageos.vnxe.models.VNXeBase in project coprhd-controller by CoprHD.

the class HostIpPortRequestsTest method createHostIpPortTest.

@Test
public void createHostIpPortTest() {
    HostIpPortRequests req = new HostIpPortRequests(_client);
    HostIpPortCreateParam parm = new HostIpPortCreateParam();
    parm.setAddress("10.247.87.208");
    VNXeBase host = new VNXeBase();
    host.setId("Host_1");
    parm.setHost(host);
    VNXeCommandResult result = req.createHostIpPort(parm);
    String id = result.getId();
    System.out.println(id);
}
Also used : VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) VNXeCommandResult(com.emc.storageos.vnxe.models.VNXeCommandResult) HostIpPortCreateParam(com.emc.storageos.vnxe.models.HostIpPortCreateParam) Test(org.junit.Test)

Aggregations

VNXeBase (com.emc.storageos.vnxe.models.VNXeBase)71 ArrayList (java.util.ArrayList)39 URI (java.net.URI)17 HashMap (java.util.HashMap)14 LunGroupModifyParam (com.emc.storageos.vnxe.models.LunGroupModifyParam)13 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)12 VNXeHostInitiator (com.emc.storageos.vnxe.models.VNXeHostInitiator)11 HashSet (java.util.HashSet)11 List (java.util.List)11 StoragePort (com.emc.storageos.db.client.model.StoragePort)9 VNXeException (com.emc.storageos.vnxe.VNXeException)9 VNXeCommandJob (com.emc.storageos.vnxe.models.VNXeCommandJob)9 ConsistencyGroupRequests (com.emc.storageos.vnxe.requests.ConsistencyGroupRequests)9 LunGroupRequests (com.emc.storageos.vnxe.requests.LunGroupRequests)9 VNXeApiClient (com.emc.storageos.vnxe.VNXeApiClient)8 BlockHostAccess (com.emc.storageos.vnxe.models.BlockHostAccess)8 LunParam (com.emc.storageos.vnxe.models.LunParam)8 ModifyFileSystemParam (com.emc.storageos.vnxe.models.ModifyFileSystemParam)8 Initiator (com.emc.storageos.db.client.model.Initiator)7 VNXeHost (com.emc.storageos.vnxe.models.VNXeHost)7