Search in sources :

Example 1 with VNXeHost

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

the class VNXeStorageDevice 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 = getVnxeClient(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 2 with VNXeHost

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

the class VNXUnityArrayAffinityDiscoverer method getPreferredPoolMap.

/**
 * Construct pool to pool type map for a host
 *
 * @param system
 * @param hostId
 * @param apiClient
 * @param dbClient
 * @return pool to pool type map
 * @throws IOException
 */
private Map<String, String> getPreferredPoolMap(StorageSystem system, URI hostId, VNXeApiClient apiClient, DbClient dbClient) throws IOException {
    Map<String, String> preferredPoolMap = new HashMap<String, String>();
    Map<String, StoragePool> pools = getStoragePoolMap(system, dbClient);
    List<Initiator> allInitiators = CustomQueryUtility.queryActiveResourcesByConstraint(dbClient, Initiator.class, ContainmentConstraint.Factory.getContainedObjectsConstraint(hostId, Initiator.class, Constants.HOST));
    String vnxeHostId = null;
    for (Initiator initiator : allInitiators) {
        logger.info("Processing initiator {}", initiator.getLabel());
        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) {
                vnxeHostId = parentHost.getId();
                break;
            }
        }
    }
    if (vnxeHostId == null) {
        logger.info("Host {} cannot be found on array", hostId);
        return preferredPoolMap;
    }
    // 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());
            // get lun from from hostLun
            VNXeBase lunId = hostLun.getLun();
            if (lunId != null) {
                VNXeLun lun = apiClient.getLun(lunId.getId());
                if (lun != null) {
                    String nativeGuid = NativeGUIDGenerator.generateNativeGuidForVolumeOrBlockSnapShot(system.getNativeGuid(), lun.getId());
                    if (DiscoveryUtils.checkStorageVolumeExistsInDB(dbClient, nativeGuid) != null) {
                        logger.info("Skipping volume {} as it is already managed by ViPR", nativeGuid);
                        continue;
                    }
                    StoragePool pool = getStoragePoolOfUnManagedObject(lun.getPool().getId(), system, pools);
                    if (pool != null) {
                        String exportType = isSharedLun(lun) ? ExportGroup.ExportGroupType.Cluster.name() : ExportGroup.ExportGroupType.Host.name();
                        ArrayAffinityDiscoveryUtils.addPoolToPreferredPoolMap(preferredPoolMap, pool.getId().toString(), exportType);
                    } else {
                        logger.error("Skipping volume {} as its storage pool doesn't exist in ViPR", lun.getId());
                    }
                }
            }
        }
    }
    return preferredPoolMap;
}
Also used : StoragePool(com.emc.storageos.db.client.model.StoragePool) HashMap(java.util.HashMap) HostLun(com.emc.storageos.vnxe.models.HostLun) VNXeHost(com.emc.storageos.vnxe.models.VNXeHost) VNXeHostInitiator(com.emc.storageos.vnxe.models.VNXeHostInitiator) VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) Initiator(com.emc.storageos.db.client.model.Initiator) VNXeHostInitiator(com.emc.storageos.vnxe.models.VNXeHostInitiator) VNXeLun(com.emc.storageos.vnxe.models.VNXeLun)

Example 3 with VNXeHost

use of com.emc.storageos.vnxe.models.VNXeHost 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 4 with VNXeHost

use of com.emc.storageos.vnxe.models.VNXeHost 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 5 with VNXeHost

use of com.emc.storageos.vnxe.models.VNXeHost 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)

Aggregations

VNXeHost (com.emc.storageos.vnxe.models.VNXeHost)12 VNXeBase (com.emc.storageos.vnxe.models.VNXeBase)8 VNXeApiClient (com.emc.storageos.vnxe.VNXeApiClient)6 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)6 HostLun (com.emc.storageos.vnxe.models.HostLun)5 Initiator (com.emc.storageos.db.client.model.Initiator)4 VNXeHostInitiator (com.emc.storageos.vnxe.models.VNXeHostInitiator)4 ArrayList (java.util.ArrayList)4 StringMap (com.emc.storageos.db.client.model.StringMap)3 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)3 VNXeException (com.emc.storageos.vnxe.VNXeException)3 URI (java.net.URI)3 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)2 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)2 ExportRule (com.emc.storageos.model.file.ExportRule)2 VNXeLun (com.emc.storageos.vnxe.models.VNXeLun)2 VNXeNfsShare (com.emc.storageos.vnxe.models.VNXeNfsShare)2 List (java.util.List)2 Map (java.util.Map)2