Search in sources :

Example 66 with Host

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

the class XtremIOCommunicationInterface method discoverArrayAffinity.

@Override
public void discoverArrayAffinity(AccessProfile accessProfile) throws BaseCollectionException {
    _logger.info("XtremIO Array Affinity discovery started for : {}", accessProfile.toString());
    boolean errorOccurred = false;
    StringBuilder errorStrBldr = new StringBuilder();
    try {
        XtremIOClient xtremIOClient = (XtremIOClient) xtremioRestClientFactory.getXtremIOV1Client(URI.create(XtremIOConstants.getXIOBaseURI(accessProfile.getIpAddress(), accessProfile.getPortNumber())), accessProfile.getUserName(), accessProfile.getPassword(), true);
        List<XtremIOSystem> xioSystems = xtremIOClient.getXtremIOSystemInfo();
        _logger.info("Found {} clusters for XMS {}", xioSystems.size(), accessProfile.getIpAddress());
        for (XtremIOSystem xioSystem : xioSystems) {
            try {
                String sysNativeGuid = NativeGUIDGenerator.generateNativeGuid(DiscoveredDataObject.Type.xtremio.name(), xioSystem.getSerialNumber());
                // check if system registered in ViPR
                List<StorageSystem> systems = CustomQueryUtility.getActiveStorageSystemByNativeGuid(_dbClient, sysNativeGuid);
                if (systems.isEmpty()) {
                    _logger.info("No Storage System found in database for {}, hence skipping..", sysNativeGuid);
                    continue;
                }
                StorageSystem system = systems.get(0);
                // Host based array affinity discovery
                if (accessProfile.getProps() != null && accessProfile.getProps().get(Constants.HOST_IDS) != null) {
                    String hostIdsStr = accessProfile.getProps().get(Constants.HOST_IDS);
                    _logger.info("Array Affinity Discovery started for Hosts {}, for XtremIO system {}", hostIdsStr, system.getNativeGuid());
                    String[] hostIds = hostIdsStr.split(Constants.ID_DELIMITER);
                    for (String hostId : hostIds) {
                        _logger.info("Processing Host {}", hostId);
                        Host host = _dbClient.queryObject(Host.class, URI.create(hostId));
                        if (host != null && !host.getInactive()) {
                            arrayAffinityDiscoverer.findAndUpdatePreferredPoolsForHost(system, host, _dbClient);
                        }
                    }
                } else {
                    // Storage system based array affinity discovery
                    _logger.info("Array Affinity Discovery started for XtremIO system {}", system.getNativeGuid());
                    arrayAffinityDiscoverer.findAndUpdatePreferredPools(system, _dbClient, _partitionManager);
                }
            } catch (Exception ex) {
                String errMsg = String.format("Error discovering Array Affinity for XtremIO system %s. Reason: %s", xioSystem.getSerialNumber(), ex.getMessage());
                _logger.error(errMsg, ex);
                errorOccurred = true;
                errorStrBldr.append(errMsg);
            }
        }
    } catch (Exception e) {
        _logger.error("Error discovering Array Affinity for XtremIO Provider {}", accessProfile.getIpAddress(), e);
        throw XtremIOApiException.exceptions.discoveryFailed(accessProfile.getIpAddress());
    } finally {
        if (errorOccurred) {
            _logger.error("Array Affinity discovery for XtremIO Provider {} failed. {}", accessProfile.getIpAddress(), errorStrBldr.toString());
            throw XtremIOApiException.exceptions.discoveryFailed(accessProfile.getIpAddress());
        }
    }
    _logger.info("XtremIO Array Affinity discovery ended");
}
Also used : XtremIOSystem(com.emc.storageos.xtremio.restapi.model.response.XtremIOSystem) XtremIOClient(com.emc.storageos.xtremio.restapi.XtremIOClient) Host(com.emc.storageos.db.client.model.Host) XtremIOApiException(com.emc.storageos.xtremio.restapi.errorhandling.XtremIOApiException) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 67 with Host

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

the class DataCollectionJobScheduler method loadSystemfromDB.

/**
 * Load Physical Systems from DB, and add to Discovery Job Queue
 *
 * @throws Exception
 */
private void loadSystemfromDB(String jobType) throws Exception {
    _logger.info("Started Loading Systems from DB for " + jobType + " jobs");
    ArrayList<DataCollectionJob> jobs = new ArrayList<DataCollectionJob>();
    List<URI> allSystemsURIs = new ArrayList<URI>();
    Map<URI, List<URI>> providerToSystemsMap = new HashMap<URI, List<URI>>();
    if (jobType.equalsIgnoreCase(ControllerServiceImpl.NS_DISCOVERY)) {
        addToList(allSystemsURIs, _dbClient.queryByType(NetworkSystem.class, true).iterator());
    } else if (jobType.equalsIgnoreCase(ControllerServiceImpl.CS_DISCOVERY)) {
        addToList(allSystemsURIs, _dbClient.queryByType(Host.class, true).iterator());
        addToList(allSystemsURIs, _dbClient.queryByType(Vcenter.class, true).iterator());
    } else if (jobType.equalsIgnoreCase(ControllerServiceImpl.COMPUTE_DISCOVERY)) {
        addToList(allSystemsURIs, _dbClient.queryByType(ComputeSystem.class, true).iterator());
    } else if (jobType.equalsIgnoreCase(ControllerServiceImpl.ARRAYAFFINITY_DISCOVERY)) {
        List<URI> systemURIs = _dbClient.queryByType(StorageSystem.class, true);
        List<StorageSystem> systems = new ArrayList<StorageSystem>();
        Iterator<StorageSystem> storageSystems = _dbClient.queryIterativeObjects(StorageSystem.class, systemURIs, true);
        while (storageSystems.hasNext()) {
            StorageSystem system = storageSystems.next();
            if (system.deviceIsType(Type.vmax) || system.deviceIsType(Type.vnxblock) || system.deviceIsType(Type.xtremio) || system.deviceIsType(Type.unity)) {
                systems.add(system);
            }
        }
        // Sort systems by last array affinity time, so that system with the earliest last array affinity time will be used
        // when checking if job should be scheduled
        Collections.sort(systems, new Comparator<StorageSystem>() {

            public int compare(StorageSystem system1, StorageSystem system2) {
                return Long.compare(system1.getLastArrayAffinityRunTime(), system2.getLastArrayAffinityRunTime());
            }
        });
        for (StorageSystem system : systems) {
            if (system.deviceIsType(Type.unity)) {
                List<URI> systemIds = new ArrayList<URI>();
                systemIds.add(system.getId());
                providerToSystemsMap.put(system.getId(), systemIds);
            } else {
                StorageProvider provider = _dbClient.queryObject(StorageProvider.class, system.getActiveProviderURI());
                if (provider != null && !provider.getInactive()) {
                    List<URI> systemIds = providerToSystemsMap.get(provider.getId());
                    if (systemIds == null) {
                        systemIds = new ArrayList<URI>();
                        providerToSystemsMap.put(provider.getId(), systemIds);
                    }
                    systemIds.add(system.getId());
                }
            }
        }
    } else {
        addToList(allSystemsURIs, _dbClient.queryByType(StorageSystem.class, true).iterator());
        addToList(allSystemsURIs, _dbClient.queryByType(ProtectionSystem.class, true).iterator());
    }
    if (!providerToSystemsMap.isEmpty()) {
        for (Map.Entry<URI, List<URI>> entry : providerToSystemsMap.entrySet()) {
            String taskId = UUID.randomUUID().toString();
            List<URI> systemIds = entry.getValue();
            ArrayAffinityDataCollectionTaskCompleter completer = new ArrayAffinityDataCollectionTaskCompleter(StorageSystem.class, systemIds, taskId, jobType);
            DataCollectionArrayAffinityJob job = new DataCollectionArrayAffinityJob(null, systemIds, completer, DataCollectionJob.JobOrigin.SCHEDULER, Discovery_Namespaces.ARRAY_AFFINITY.name());
            jobs.add(job);
        }
        scheduleMultipleJobs(jobs, ControllerServiceImpl.Lock.getLock(jobType));
    } else if (!allSystemsURIs.isEmpty()) {
        Iterator<URI> systemURIsItr = allSystemsURIs.iterator();
        while (systemURIsItr.hasNext()) {
            URI systemURI = systemURIsItr.next();
            String taskId = UUID.randomUUID().toString();
            DataCollectionJob job = null;
            StorageProvider provider = null;
            if (URIUtil.isType(systemURI, StorageSystem.class)) {
                StorageSystem systemObj = _dbClient.queryObject(StorageSystem.class, systemURI);
                if (systemObj == null || systemObj.getInactive()) {
                    _logger.warn(String.format("StorageSystem %s is no longer in the DB or is inactive. It could have been deleted or decommissioned", systemURI));
                    continue;
                }
                // check devices managed by SMIS/hicommand/vplex device mgr has ActiveProviderURI or not.
                if (systemObj.isStorageSystemManagedByProvider()) {
                    if (systemObj.getActiveProviderURI() == null || NullColumnValueGetter.getNullURI().equals(systemObj.getActiveProviderURI())) {
                        _logger.info("Skipping {} Job : StorageSystem {} does not have an active provider", jobType, systemURI);
                        continue;
                    }
                    provider = _dbClient.queryObject(StorageProvider.class, systemObj.getActiveProviderURI());
                    if (provider == null || provider.getInactive()) {
                        _logger.info("Skipping {} Job : StorageSystem {} does not have a valid active provider", jobType, systemURI);
                        continue;
                    }
                }
                // For Metering, check SerialNumber has populated or not.
                if (ControllerServiceImpl.METERING.equalsIgnoreCase(jobType)) {
                    if (null == systemObj.getSerialNumber()) {
                        _logger.info("Skipping {} Job : StorageSystem {} discovery failed or hasn't run.", jobType, systemURI);
                        continue;
                    } else if (CompatibilityStatus.INCOMPATIBLE.name().equalsIgnoreCase(systemObj.getCompatibilityStatus())) {
                        _logger.info("Skipping {} Job : StorageSystem {} has incompatible version", jobType, systemURI);
                        continue;
                    }
                }
                job = getDataCollectionJobByType(StorageSystem.class, jobType, taskId, systemURI);
            } else if (URIUtil.isType(systemURI, NetworkSystem.class)) {
                job = getDataCollectionJobByType(NetworkSystem.class, jobType, taskId, systemURI);
            } else if (URIUtil.isType(systemURI, ComputeSystem.class)) {
                job = getDataCollectionJobByType(ComputeSystem.class, jobType, taskId, systemURI);
            } else if (URIUtil.isType(systemURI, Host.class)) {
                Host host = _dbClient.queryObject(Host.class, systemURI);
                // Add host
                if ((host.getDiscoverable() == null || host.getDiscoverable())) {
                    job = getDataCollectionJobByType(Host.class, jobType, taskId, systemURI);
                }
            } else if (URIUtil.isType(systemURI, Vcenter.class)) {
                job = getDataCollectionJobByType(Vcenter.class, jobType, taskId, systemURI);
            } else if (URIUtil.isType(systemURI, ProtectionSystem.class)) {
                // Protection System metrics are not used for "metering" per vpool/project/tenant
                if (!jobType.equals(ControllerServiceImpl.METERING)) {
                    job = getDataCollectionJobByType(ProtectionSystem.class, jobType, taskId, systemURI);
                }
            }
            if (null != job) {
                jobs.add(job);
            }
        }
        scheduleMultipleJobs(jobs, ControllerServiceImpl.Lock.getLock(jobType));
    } else {
        _logger.info("No systems found in db to schedule jobs.");
    }
}
Also used : Vcenter(com.emc.storageos.db.client.model.Vcenter) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) Host(com.emc.storageos.db.client.model.Host) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) URI(java.net.URI) ProtectionSystem(com.emc.storageos.db.client.model.ProtectionSystem) Comparator(java.util.Comparator) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) ComputeSystem(com.emc.storageos.db.client.model.ComputeSystem) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 68 with Host

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

the class ArrayAffinityExportProcessor method updatePreferredPools.

private void updatePreferredPools() {
    Map<URI, Set<String>> hostToExportMasks = getHostToExportMasksMap();
    Map<String, Set<URI>> exportToMaskHostCount = getExportMaskToHostsMap();
    Map<String, Set<String>> maskToVolumes = getExportMaskToVolumesMap();
    Map<String, Set<URI>> maskToStroagePools = getMaskToStoragePoolsMap();
    Map<String, URI> volumeToStoragePool = getVolumeToStoragePoolMap();
    String systemIdsStr = _profile.getProps().get(Constants.SYSTEM_IDS);
    String[] systemIds = systemIdsStr.split(Constants.ID_DELIMITER);
    Set<String> systemIdSet = new HashSet<String>(Arrays.asList(systemIds));
    List<Host> hostsToUpdate = new ArrayList<Host>();
    Map<URI, Set<String>> hostToVolumes = new HashMap<URI, Set<String>>();
    Map<String, Set<URI>> volumeToHosts = new HashMap<String, Set<URI>>();
    // populate hostToVolumes and volumeToHosts maps
    for (Map.Entry<URI, Set<String>> entry : hostToExportMasks.entrySet()) {
        URI host = entry.getKey();
        for (String mask : entry.getValue()) {
            Set<String> volumes = maskToVolumes.get(mask);
            if (volumes != null) {
                Set<String> hostVols = hostToVolumes.get(host);
                if (hostVols == null) {
                    hostVols = new HashSet<String>();
                    hostToVolumes.put(host, hostVols);
                }
                hostVols.addAll(volumes);
                for (String volume : volumes) {
                    Set<URI> hosts = volumeToHosts.get(volume);
                    if (hosts == null) {
                        hosts = new HashSet<URI>();
                        volumeToHosts.put(volume, hosts);
                    }
                    hosts.add(host);
                }
            }
        }
    }
    try {
        List<URI> hostURIs = _dbClient.queryByType(Host.class, true);
        Iterator<Host> hosts = _dbClient.queryIterativeObjectFields(Host.class, ArrayAffinityDiscoveryUtils.HOST_PROPERTIES, hostURIs);
        while (hosts.hasNext()) {
            Host host = hosts.next();
            if (host != null) {
                _logger.info("Processing host {}", host.getLabel());
                // check masks
                Map<String, String> preferredPoolMap = new HashMap<String, String>();
                Set<String> masks = hostToExportMasks.get(host.getId());
                if (masks != null && !masks.isEmpty()) {
                    for (String mask : masks) {
                        Set<URI> pools = maskToStroagePools.get(mask);
                        String exportType = exportToMaskHostCount.get(mask).size() > 1 ? ExportGroup.ExportGroupType.Cluster.name() : ExportGroup.ExportGroupType.Host.name();
                        if (pools != null && !pools.isEmpty()) {
                            for (URI pool : pools) {
                                ArrayAffinityDiscoveryUtils.addPoolToPreferredPoolMap(preferredPoolMap, pool.toString(), exportType);
                            }
                        }
                    }
                }
                // check volumes
                Set<String> volumes = hostToVolumes.get(host.getId());
                if (volumes != null && !volumes.isEmpty()) {
                    for (String volume : volumes) {
                        URI pool = volumeToStoragePool.get(volume);
                        if (pool != null) {
                            String exportType = volumeToHosts.get(volume).size() > 1 ? ExportGroup.ExportGroupType.Cluster.name() : ExportGroup.ExportGroupType.Host.name();
                            ArrayAffinityDiscoveryUtils.addPoolToPreferredPoolMap(preferredPoolMap, pool.toString(), exportType);
                        }
                    }
                }
                if (ArrayAffinityDiscoveryUtils.updatePreferredPools(host, systemIdSet, _dbClient, preferredPoolMap)) {
                    hostsToUpdate.add(host);
                }
            }
            // if hostsToUpdate size reaches BATCH_SIZE, persist to db
            if (hostsToUpdate.size() >= BATCH_SIZE) {
                _partitionManager.updateInBatches(hostsToUpdate, BATCH_SIZE, _dbClient, HOST);
                hostsToUpdate.clear();
            }
        }
        if (!hostsToUpdate.isEmpty()) {
            _partitionManager.updateInBatches(hostsToUpdate, BATCH_SIZE, _dbClient, HOST);
        }
    } catch (Exception e) {
        _logger.warn("Exception on updatePreferredPools", e);
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 69 with Host

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

the class XIVExportOperations method createSMISExportMask.

private void createSMISExportMask(StorageSystem storage, URI exportMaskURI, VolumeURIHLU[] volumeURIHLUs, List<URI> targetURIList, List<Initiator> initiatorList, TaskCompleter taskCompleter) throws DeviceControllerException {
    _log.info("{} createExportMask START...", storage.getLabel());
    try {
        _log.info("createExportMask: Export mask id: {}", exportMaskURI);
        _log.info("createExportMask: volume-HLU pairs: {}", Joiner.on(',').join(volumeURIHLUs));
        _log.info("createExportMask: initiators: {}", Joiner.on(',').join(initiatorList));
        _log.info("createExportMask: assignments: {}", Joiner.on(',').join(targetURIList));
        CIMInstance controllerInst = null;
        boolean createdBySystem = true;
        Map<String, Initiator> initiatorMap = _helper.getInitiatorMap(initiatorList);
        String[] initiatorNames = initiatorMap.keySet().toArray(new String[] {});
        List<Initiator> userAddedInitiators = new ArrayList<Initiator>();
        Map<String, CIMObjectPath> existingHwStorageIds = getStorageHardwareIds(storage);
        // note - the initiator list maybe just a subset of all initiators on a host, need to
        // get all the initiators from the host, and check here
        // a special case is that there is a host on array side with i1 and i2,
        // while there is a host with initiator i2 and i3 on ViPR side,
        // we will not be able to match the two hosts if there is common initiator(s)
        // if an HBA get moved from one host to another, it need to be removed on array side manually
        List<Initiator> allInitiators;
        Host host = null;
        Initiator firstInitiator = initiatorList.get(0);
        String label;
        if (initiatorList.get(0).getHost() != null) {
            allInitiators = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, Initiator.class, ContainmentConstraint.Factory.getContainedObjectsConstraint(firstInitiator.getHost(), Initiator.class, "host"));
            host = _dbClient.queryObject(Host.class, firstInitiator.getHost());
            label = host.getLabel();
        } else {
            allInitiators = CustomQueryUtility.queryActiveResourcesByAltId(_dbClient, Initiator.class, "hostname", firstInitiator.getHostName());
            label = firstInitiator.getHostName();
        }
        for (Initiator initiator : allInitiators) {
            String normalizedPortName = Initiator.normalizePort(initiator.getInitiatorPort());
            CIMObjectPath initiatorPath = existingHwStorageIds.get(normalizedPortName);
            if (initiatorPath != null) {
                _log.info(String.format("Initiator %s already exists", initiator.getInitiatorPort()));
                createdBySystem = false;
                // get controller instance
                controllerInst = getSCSIProtocolControllerInstanceByHwId(storage, initiatorPath);
                if (controllerInst == null) {
                    _log.debug("createExportMask failed. No protocol controller created.");
                    ServiceError error = DeviceControllerErrors.smis.noProtocolControllerCreated();
                    taskCompleter.error(_dbClient, error);
                    _log.info("{} createExportMask END...", storage.getLabel());
                    return;
                }
                // get initiators
                Map<String, CIMObjectPath> initiatorPortPaths = _helper.getInitiatorsFromScsiProtocolController(storage, controllerInst.getObjectPath());
                Set<String> existingInitiatorPorts = initiatorPortPaths.keySet();
                // check if initiators need to be added
                List<String> initiatorsToAdd = new ArrayList<String>();
                for (String port : initiatorNames) {
                    if (!existingInitiatorPorts.contains(port)) {
                        initiatorsToAdd.add(port);
                        userAddedInitiators.add(initiatorMap.get(port));
                    }
                }
                if (!initiatorsToAdd.isEmpty()) {
                    // add initiator to host on array side
                    CIMObjectPath specificCollectionPath = getSystemSpecificCollectionPathByHwId(storage, initiatorPath);
                    CIMArgument[] outArgs = new CIMArgument[5];
                    _helper.addHardwareIDsToCollection(storage, specificCollectionPath, initiatorsToAdd.toArray(new String[] {}), outArgs);
                    if (outArgs[0] == null) {
                        Set<String> hwIds = hasHwIdsInCollection(storage, specificCollectionPath);
                        if (!hwIds.containsAll(initiatorsToAdd)) {
                            throw new Exception("Failed to add initiator: " + Joiner.on(',').join(initiatorsToAdd));
                        }
                    }
                }
                // same host/controller on both ViPR and array sides
                break;
            }
        }
        // no matched initiator on array side, now try to find host with the given name
        if (controllerInst == null) {
            String query = String.format("Select * From %s Where ElementName=\"%s\"", IBMSmisConstants.CP_SYSTEM_SPECIFIC_COLLECTION, label);
            CIMObjectPath hostPath = CimObjectPathCreator.createInstance(IBMSmisConstants.CP_SYSTEM_SPECIFIC_COLLECTION, Constants.IBM_NAMESPACE, null);
            List<CIMInstance> hostInstances = _helper.executeQuery(storage, hostPath, query, "WQL");
            if (!hostInstances.isEmpty()) {
                CIMObjectPath specificCollectionPath = hostInstances.get(0).getObjectPath();
                if (!hasHwIdInCollection(storage, specificCollectionPath)) {
                    createdBySystem = false;
                    userAddedInitiators = initiatorList;
                    // re-use the empty host
                    CIMArgument[] outArgs = new CIMArgument[5];
                    _helper.addHardwareIDsToCollection(storage, specificCollectionPath, initiatorNames, outArgs);
                    if (outArgs[0] == null) {
                        Set<String> hwIds = hasHwIdsInCollection(storage, specificCollectionPath);
                        if (!hwIds.containsAll(new ArrayList<String>(Arrays.asList(initiatorNames)))) {
                            throw new Exception("Failed to add initiator: " + Joiner.on(',').join(initiatorNames));
                        }
                    }
                    controllerInst = getSCSIProtocolControllerInstanceByIdCollection(storage, specificCollectionPath);
                    if (controllerInst == null) {
                        _log.debug("createExportMask failed. No protocol controller created.");
                        ServiceError error = DeviceControllerErrors.smis.noProtocolControllerCreated();
                        taskCompleter.error(_dbClient, error);
                        _log.info("{} createExportMask END...", storage.getLabel());
                        return;
                    }
                }
            }
        }
        // create new protocol controller
        if (controllerInst == null) {
            // create host first so that the desired host label could be used
            CIMObjectPath sysSpecificCollectionPath = getSystemSpecificCollectionPath(storage, label, initiatorNames);
            if (sysSpecificCollectionPath == null) {
                _log.debug("createExportMask failed. No host created.");
                ServiceError error = DeviceControllerErrors.smis.noProtocolControllerCreated();
                taskCompleter.error(_dbClient, error);
                _log.info("{} createExportMask END...", storage.getLabel());
                return;
            }
            controllerInst = getSCSIProtocolControllerInstanceByIdCollection(storage, sysSpecificCollectionPath);
        }
        if (controllerInst != null) {
            String elementName = CIMPropertyFactory.getPropertyValue(controllerInst, SmisConstants.CP_ELEMENT_NAME);
            // set host tag is needed
            if (host != null) {
                if (label.equals(elementName)) {
                    _helper.unsetTag(host, storage.getSerialNumber());
                } else {
                    _helper.setTag(host, storage.getSerialNumber(), elementName);
                }
            }
            CIMObjectPath controller = controllerInst.getObjectPath();
            ExportMask exportMask = _dbClient.queryObject(ExportMask.class, exportMaskURI);
            if (!createdBySystem) {
                exportMask.setCreatedBySystem(createdBySystem);
                exportMask.addToUserCreatedInitiators(userAddedInitiators);
            }
            // SCSIProtocolController.ElementName
            exportMask.setMaskName(elementName);
            // is the same as
            // SystemSpecificCollection.ElementName
            exportMask.setLabel(elementName);
            CIMProperty<String> deviceId = (CIMProperty<String>) controller.getKey(IBMSmisConstants.CP_DEVICE_ID);
            exportMask.setNativeId(deviceId.getValue());
            _dbClient.persistObject(exportMask);
            CIMArgument[] inArgs = _helper.getExposePathsInputArguments(volumeURIHLUs, null, controller);
            CIMArgument[] outArgs = new CIMArgument[5];
            // don't care if the volumes/initiators have already been in the
            // mask
            _helper.invokeMethod(storage, _cimPath.getControllerConfigSvcPath(storage), IBMSmisConstants.EXPOSE_PATHS, inArgs, outArgs);
            CIMObjectPath[] protocolControllers = _cimPath.getProtocolControllersFromOutputArgs(outArgs);
            CIMObjectPath protocolController = protocolControllers[0];
            // for debug only
            if (_log.isDebugEnabled()) {
                List<String> targetEndpoints = getTargetEndpoints(protocolController, storage);
                _log.debug(String.format("ProtocolController %s with target ports: %s", protocolController.getObjectName(), Joiner.on(',').join(targetEndpoints)));
            }
            CimConnection cimConnection = _helper.getConnection(storage);
            // Call populateDeviceNumberFromProtocolControllers only after
            // initiators
            // have been added. HLU's will not be reported till the Device
            // is Host visible
            ExportMaskOperationsHelper.populateDeviceNumberFromProtocolControllers(_dbClient, cimConnection, exportMaskURI, volumeURIHLUs, protocolControllers, taskCompleter);
            taskCompleter.ready(_dbClient);
        } else {
            _log.debug("createExportMask failed. No protocol controller created.");
            ServiceError error = DeviceControllerErrors.smis.noProtocolControllerCreated();
            taskCompleter.error(_dbClient, error);
        }
    } catch (Exception e) {
        _log.error("Unexpected error: createExportMask failed.", e);
        ServiceError error = DeviceControllerErrors.smis.methodFailed("createExportMask", e.getMessage());
        taskCompleter.error(_dbClient, error);
    }
    _log.info("{} createExportMask END...", storage.getLabel());
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ExportMask(com.emc.storageos.db.client.model.ExportMask) ArrayList(java.util.ArrayList) CIMObjectPath(javax.cim.CIMObjectPath) Host(com.emc.storageos.db.client.model.Host) CIMInstance(javax.cim.CIMInstance) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) WBEMException(javax.wbem.WBEMException) SmisException(com.emc.storageos.volumecontroller.impl.smis.SmisException) Initiator(com.emc.storageos.db.client.model.Initiator) CIMProperty(javax.cim.CIMProperty) CimConnection(com.emc.storageos.cimadapter.connections.cim.CimConnection) CIMArgument(javax.cim.CIMArgument)

Example 70 with Host

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

the class XIVExportOperations method removeInitiatorsUsingSMIS.

// TOD -test
private void removeInitiatorsUsingSMIS(StorageSystem storage, URI exportMaskURI, List<URI> volumeURIList, List<Initiator> initiatorList, List<URI> targets, TaskCompleter taskCompleter) throws DeviceControllerException {
    _log.info("{} removeInitiators START...", storage.getLabel());
    try {
        _log.info("removeInitiators: Export mask id: {}", exportMaskURI);
        // 2. If any other volumes are impacted by removing this initiator, fail the operation
        if (volumeURIList != null) {
            _log.info("removeInitiators: volumes : {}", Joiner.on(',').join(volumeURIList));
        }
        _log.info("removeInitiators: initiators : {}", Joiner.on(',').join(initiatorList));
        _log.info("removeInitiators: targets : {}", Joiner.on(',').join(targets));
        if (initiatorList != null && !initiatorList.isEmpty()) {
            ExportMask exportMask = _dbClient.queryObject(ExportMask.class, exportMaskURI);
            CIMObjectPath controllerPath = _cimPath.getSCSIProtocolControllerPath(storage, exportMask.getNativeId());
            if (controllerPath != null) {
                Map<String, CIMObjectPath> hwIdPaths = _helper.getInitiatorsFromScsiProtocolController(storage, controllerPath);
                CIMObjectPath hwIdManagementSvc = _cimPath.getStorageHardwareIDManagementService(storage);
                String[] initiatorNames = _helper.getInitiatorNames(initiatorList);
                for (String initiator : initiatorNames) {
                    CIMObjectPath hwIdPath = hwIdPaths.get(initiator);
                    if (hwIdPath != null) {
                        try {
                            CIMArgument[] deleteHwIdIn = _helper.getDeleteStorageHardwareIDInputArgs(storage, hwIdPath);
                            _helper.invokeMethod(storage, hwIdManagementSvc, SmisConstants.DELETE_STORAGE_HARDWARE_ID, deleteHwIdIn);
                        } catch (WBEMException e) {
                            _log.error("deleteStorageHWIDs -- WBEMException: ", e);
                        } catch (Exception e) {
                            _log.error("deleteStorageHWIDs -- Exception: " + e);
                        }
                    } else {
                        _log.info("Initiator {} is not on array", initiator);
                    }
                }
                CIMObjectPath idCollectionPath = getIdCollectionBySCSIProtocolController(storage, controllerPath);
                if (!hasHwIdInCollection(storage, idCollectionPath)) {
                    // update host label
                    Host host = _dbClient.queryObject(Host.class, initiatorList.get(0).getHost());
                    _helper.unsetTag(host, storage.getSerialNumber());
                }
            } else {
                _log.error("Protocol controller is null");
                ServiceError error = DeviceControllerErrors.smis.noProtocolControllerCreated();
                taskCompleter.error(_dbClient, error);
                return;
            }
        }
        taskCompleter.ready(_dbClient);
    } catch (Exception e) {
        _log.error("Unexpected error: removeInitiators failed.", e);
        ServiceError error = DeviceControllerErrors.smis.methodFailed("removeInitiators", e.getMessage());
        taskCompleter.error(_dbClient, error);
    }
    _log.info("{} removeInitiators END...", storage.getLabel());
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ExportMask(com.emc.storageos.db.client.model.ExportMask) CIMObjectPath(javax.cim.CIMObjectPath) Host(com.emc.storageos.db.client.model.Host) WBEMException(javax.wbem.WBEMException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) WBEMException(javax.wbem.WBEMException) SmisException(com.emc.storageos.volumecontroller.impl.smis.SmisException) CIMArgument(javax.cim.CIMArgument)

Aggregations

Host (com.emc.storageos.db.client.model.Host)227 URI (java.net.URI)104 Initiator (com.emc.storageos.db.client.model.Initiator)52 ArrayList (java.util.ArrayList)49 HashMap (java.util.HashMap)38 Cluster (com.emc.storageos.db.client.model.Cluster)37 HashSet (java.util.HashSet)35 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)33 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)32 VcenterDataCenter (com.emc.storageos.db.client.model.VcenterDataCenter)26 ComputeElement (com.emc.storageos.db.client.model.ComputeElement)24 Volume (com.emc.storageos.db.client.model.Volume)20 Path (javax.ws.rs.Path)20 Produces (javax.ws.rs.Produces)20 Vcenter (com.emc.storageos.db.client.model.Vcenter)19 ComputeSystemControllerException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)18 ExportMask (com.emc.storageos.db.client.model.ExportMask)18 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)17 NamedURI (com.emc.storageos.db.client.model.NamedURI)16 StringSet (com.emc.storageos.db.client.model.StringSet)16