Search in sources :

Example 1 with CIMInstance

use of javax.cim.CIMInstance in project coprhd-controller by CoprHD.

the class VmaxExportOperations method refreshExportMask.

@Override
public ExportMask refreshExportMask(StorageSystem storage, ExportMask mask) throws DeviceControllerException {
    long startTime = System.currentTimeMillis();
    try {
        CIMInstance instance = _helper.getSymmLunMaskingView(storage, mask);
        if (instance != null) {
            StringBuilder builder = new StringBuilder();
            WBEMClient client = _helper.getConnection(storage).getCimClient();
            String name = CIMPropertyFactory.getPropertyValue(instance, SmisConstants.CP_ELEMENT_NAME);
            // Get volumes and initiators for the masking instance
            Map<String, Integer> discoveredVolumes = _helper.getVolumesFromLunMaskingInstance(client, instance);
            List<String> discoveredPorts = _helper.getInitiatorsFromLunMaskingInstance(client, instance);
            Set existingInitiators = (mask.getExistingInitiators() != null) ? mask.getExistingInitiators() : Collections.emptySet();
            Set existingVolumes = (mask.getExistingVolumes() != null) ? mask.getExistingVolumes().keySet() : Collections.emptySet();
            builder.append(String.format("%nXM existing objects: %s I{%s} V:{%s}%n", name, Joiner.on(',').join(existingInitiators), Joiner.on(',').join(existingVolumes)));
            builder.append(String.format("XM discovered: %s I:{%s} V:{%s}%n", name, Joiner.on(',').join(discoveredPorts), Joiner.on(',').join(discoveredVolumes.keySet())));
            List<String> initiatorsToAddToExisting = new ArrayList<String>();
            List<Initiator> initiatorsToAddToUserAddedAndInitiatorList = new ArrayList<Initiator>();
            /**
             * For the newly discovered initiators, if they are ViPR discovered ports and belong to same resource
             * add them to user added and initiators list, otherwise add to existing list.
             */
            for (String port : discoveredPorts) {
                String normalizedPort = Initiator.normalizePort(port);
                if (!mask.hasExistingInitiator(normalizedPort) && !mask.hasUserInitiator(normalizedPort)) {
                    Initiator existingInitiator = ExportUtils.getInitiator(Initiator.toPortNetworkId(port), _dbClient);
                    // Don't add additional initiator to initiators list if it belongs to different host/cluster
                    if (existingInitiator != null && !ExportMaskUtils.checkIfDifferentResource(mask, existingInitiator)) {
                        _log.info("Initiator {}->{} belonging to same compute, adding to userAdded and initiator list.", normalizedPort, existingInitiator.getId());
                        initiatorsToAddToUserAddedAndInitiatorList.add(existingInitiator);
                    } else {
                        initiatorsToAddToExisting.add(normalizedPort);
                    }
                }
            }
            /**
             * Get the existing initiators from the mask and remove the non-discovered ports because
             * they are not discovered and are stale.
             *
             * If the mask has existing initiators but if they are discovered and belongs to same compute resource, then the
             * initiators has to get added to user Added and initiators list, and removed from existing list.
             */
            List<String> initiatorsToRemoveFromExistingList = new ArrayList<String>();
            if (mask.getExistingInitiators() != null && !mask.getExistingInitiators().isEmpty()) {
                for (String existingInitiatorStr : mask.getExistingInitiators()) {
                    if (!discoveredPorts.contains(existingInitiatorStr)) {
                        initiatorsToRemoveFromExistingList.add(existingInitiatorStr);
                    } else {
                        Initiator existingInitiator = ExportUtils.getInitiator(Initiator.toPortNetworkId(existingInitiatorStr), _dbClient);
                        if (existingInitiator != null && !ExportMaskUtils.checkIfDifferentResource(mask, existingInitiator)) {
                            _log.info("Initiator {}->{} belonging to same compute, removing from existing," + " and adding to userAdded and initiator list", existingInitiatorStr, existingInitiator.getId());
                            initiatorsToAddToUserAddedAndInitiatorList.add(existingInitiator);
                            initiatorsToRemoveFromExistingList.add(existingInitiatorStr);
                        }
                    }
                }
            }
            /**
             * Get all the initiators from the mask and remove all the ViPR discovered ports.
             * The remaining list has to be removed from user Added and initiator list, because they are not available in ViPR
             * but has to be moved to existing list.
             */
            List<URI> initiatorsToRemoveFromUserAddedAndInitiatorList = new ArrayList<URI>();
            if (mask.getInitiators() != null && !mask.getInitiators().isEmpty()) {
                initiatorsToRemoveFromUserAddedAndInitiatorList.addAll(transform(mask.getInitiators(), CommonTransformerFunctions.FCTN_STRING_TO_URI));
                for (String port : discoveredPorts) {
                    String normalizedPort = Initiator.normalizePort(port);
                    Initiator initiatorDiscoveredInViPR = ExportUtils.getInitiator(Initiator.toPortNetworkId(port), _dbClient);
                    if (initiatorDiscoveredInViPR != null) {
                        initiatorsToRemoveFromUserAddedAndInitiatorList.remove(initiatorDiscoveredInViPR.getId());
                    } else if (!mask.hasExistingInitiator(normalizedPort)) {
                        _log.info("Initiator {} not found in database, removing from user Added and initiator list," + " and adding to existing list.", port);
                        initiatorsToAddToExisting.add(normalizedPort);
                    }
                }
            }
            boolean removeInitiators = !initiatorsToRemoveFromExistingList.isEmpty() || !initiatorsToRemoveFromUserAddedAndInitiatorList.isEmpty();
            boolean addInitiators = !initiatorsToAddToUserAddedAndInitiatorList.isEmpty() || !initiatorsToAddToExisting.isEmpty();
            // Check the volumes and update the lists as necessary
            Map<String, Integer> volumesToAdd = ExportMaskUtils.diffAndFindNewVolumes(mask, discoveredVolumes);
            boolean addVolumes = !volumesToAdd.isEmpty();
            boolean removeVolumes = false;
            List<String> volumesToRemove = new ArrayList<String>();
            // if the volume is in export mask's user added volumes and also in the existing volumes, remove from existing volumes
            for (String wwn : discoveredVolumes.keySet()) {
                if (mask.hasExistingVolume(wwn)) {
                    URIQueryResultList volumeList = new URIQueryResultList();
                    _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getVolumeWwnConstraint(wwn), volumeList);
                    if (volumeList.iterator().hasNext()) {
                        URI volumeURI = volumeList.iterator().next();
                        if (mask.hasUserCreatedVolume(volumeURI)) {
                            builder.append(String.format("\texisting volumes contain wwn %s, but it is also in the " + "export mask's user added volumes, so removing from existing volumes", wwn));
                            volumesToRemove.add(wwn);
                        }
                    }
                }
            }
            if (mask.getExistingVolumes() != null && !mask.getExistingVolumes().isEmpty()) {
                volumesToRemove.addAll(mask.getExistingVolumes().keySet());
                volumesToRemove.removeAll(discoveredVolumes.keySet());
                removeVolumes = !volumesToRemove.isEmpty();
            }
            // Update user added volume's HLU information in ExportMask and ExportGroup
            ExportMaskUtils.updateHLUsInExportMask(mask, discoveredVolumes, _dbClient);
            // Grab the storage ports that have been allocated for this
            // existing mask and update them.
            List<String> storagePorts = _helper.getStoragePortsFromLunMaskingInstance(client, instance);
            List<String> storagePortURIs = ExportUtils.storagePortNamesToURIs(_dbClient, storagePorts);
            // Check the storagePorts and update the lists as necessary
            boolean addStoragePorts = false;
            List<String> storagePortsToAdd = new ArrayList<>();
            if (mask.getStoragePorts() == null) {
                mask.setStoragePorts(new ArrayList<String>());
            }
            for (String portID : storagePortURIs) {
                if (!mask.getStoragePorts().contains(portID)) {
                    storagePortsToAdd.add(portID);
                    addStoragePorts = true;
                }
            }
            boolean removeStoragePorts = false;
            List<String> storagePortsToRemove = new ArrayList<String>();
            if (mask.getStoragePorts() != null && !mask.getStoragePorts().isEmpty()) {
                storagePortsToRemove.addAll(mask.getStoragePorts());
                storagePortsToRemove.removeAll(storagePortURIs);
                removeStoragePorts = !storagePortsToRemove.isEmpty();
            }
            builder.append(String.format("XM refresh: %s existing initiators; add:{%s} remove:{%s}%n", name, Joiner.on(',').join(initiatorsToAddToExisting), Joiner.on(',').join(initiatorsToRemoveFromExistingList)));
            builder.append(String.format("XM refresh: %s user added and initiator list; add:{%s} remove:{%s}%n", name, Joiner.on(',').join(initiatorsToAddToUserAddedAndInitiatorList), Joiner.on(',').join(initiatorsToRemoveFromUserAddedAndInitiatorList)));
            builder.append(String.format("XM refresh: %s volumes; add:{%s} remove:{%s}%n", name, Joiner.on(',').join(volumesToAdd.keySet()), Joiner.on(',').join(volumesToRemove)));
            builder.append(String.format("XM refresh: %s ports; add:{%s} remove:{%s}%n", name, Joiner.on(',').join(storagePortsToAdd), Joiner.on(',').join(storagePortsToRemove)));
            // Any changes indicated, then update the mask and persist it
            if (addInitiators || removeInitiators || addVolumes || removeVolumes || addStoragePorts || removeStoragePorts) {
                mask.removeFromExistingInitiators(initiatorsToRemoveFromExistingList);
                if (!initiatorsToRemoveFromUserAddedAndInitiatorList.isEmpty()) {
                    mask.removeInitiatorURIs(initiatorsToRemoveFromUserAddedAndInitiatorList);
                    mask.removeFromUserAddedInitiatorsByURI(initiatorsToRemoveFromUserAddedAndInitiatorList);
                }
                // https://coprhd.atlassian.net/browse/COP-17224 - For those cases where InitiatorGroups are shared
                // by
                // MaskingViews, if CoprHD processes one ExportMask by updating it with new initiators, then it
                // could
                // affect another ExportMasks. Consider that this refreshExportMask is against that other
                // ExportMask.
                // We shouldn't read the initiators that we find as 'existing' (that is created outside of CoprHD),
                // instead we should consider them userAdded for this ExportMask, as well.
                List<Initiator> userAddedInitiators = ExportMaskUtils.findIfInitiatorsAreUserAddedInAnotherMask(mask, initiatorsToAddToUserAddedAndInitiatorList, _dbClient);
                mask.addToUserCreatedInitiators(userAddedInitiators);
                builder.append(String.format("XM refresh: %s user added initiators; add:{%s} remove:{%s}%n", name, Joiner.on(',').join(userAddedInitiators), Joiner.on(',').join(initiatorsToRemoveFromUserAddedAndInitiatorList)));
                mask.addInitiators(initiatorsToAddToUserAddedAndInitiatorList);
                mask.addToUserCreatedInitiators(initiatorsToAddToUserAddedAndInitiatorList);
                mask.addToExistingInitiatorsIfAbsent(initiatorsToAddToExisting);
                mask.removeFromExistingInitiators(initiatorsToRemoveFromExistingList);
                mask.removeFromExistingVolumes(volumesToRemove);
                mask.addToExistingVolumesIfAbsent(volumesToAdd);
                mask.getStoragePorts().addAll(storagePortsToAdd);
                mask.getStoragePorts().removeAll(storagePortsToRemove);
                URI pgURI = mask.getPortGroup();
                if (!NullColumnValueGetter.isNullURI(pgURI) && (!storagePortsToAdd.isEmpty() || !storagePortsToRemove.isEmpty())) {
                    StoragePortGroup portGroup = _dbClient.queryObject(StoragePortGroup.class, pgURI);
                    portGroup.getStoragePorts().addAll(storagePortsToAdd);
                    portGroup.getStoragePorts().removeAll(storagePortsToRemove);
                    _dbClient.updateObject(portGroup);
                }
                ExportMaskUtils.sanitizeExportMaskContainers(_dbClient, mask);
                builder.append("XM refresh: There are changes to mask, " + "updating it...\n");
                _dbClient.updateObject(mask);
            } else {
                builder.append("XM refresh: There are no changes to the mask\n");
            }
            _networkDeviceController.refreshZoningMap(mask, transform(initiatorsToRemoveFromUserAddedAndInitiatorList, CommonTransformerFunctions.FCTN_URI_TO_STRING), Collections.EMPTY_LIST, (addInitiators || removeInitiators), true);
            _log.info(builder.toString());
        }
    } catch (Exception e) {
        boolean throwException = true;
        if (e instanceof WBEMException) {
            WBEMException we = (WBEMException) e;
            // Only throw exception if code is not CIM_ERROR_NOT_FOUND
            throwException = (we.getID() != WBEMException.CIM_ERR_NOT_FOUND);
        }
        if (throwException) {
            String msg = "Error when attempting to query LUN masking information: " + e.getMessage();
            _log.error(MessageFormat.format("Encountered an SMIS error when attempting to refresh existing exports: {0}", msg), e);
            throw SmisException.exceptions.refreshExistingMaskFailure(msg, e);
        }
    } finally {
        long totalTime = System.currentTimeMillis() - startTime;
        _log.info(String.format("refreshExportMask took %f seconds", (double) totalTime / (double) 1000));
    }
    return mask;
}
Also used : StoragePortGroup(com.emc.storageos.db.client.model.StoragePortGroup) Set(java.util.Set) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) HashSet(java.util.HashSet) StringSet(com.emc.storageos.db.client.model.StringSet) ArrayList(java.util.ArrayList) WBEMException(javax.wbem.WBEMException) URI(java.net.URI) CIMInstance(javax.cim.CIMInstance) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) SmisException(com.emc.storageos.volumecontroller.impl.smis.SmisException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) WBEMException(javax.wbem.WBEMException) Initiator(com.emc.storageos.db.client.model.Initiator) WBEMClient(javax.wbem.client.WBEMClient)

Example 2 with CIMInstance

use of javax.cim.CIMInstance in project coprhd-controller by CoprHD.

the class BrocadeNetworkSystemDevice method executeInSession.

/**
 * Common code for opening sessions and executing alias-type commands
 *
 * @param networkSystem the network system when the commands will execute
 * @param aliases a list of aliases to be created/updated/deleted
 * @param fabricId the name of fabric where the aliases will be changed
 * @param fabricWwn the WWN of fabric where the aliases will be changed
 * @param methodName the method to be executed
 * @param methodLogName the method name to be used for logging
 * @return the command that contains a map of results-per-alias keyed
 *         by alias name
 * @throws NetworkDeviceControllerException
 */
private BiosCommandResult executeInSession(NetworkSystem networkSystem, List<ZoneWwnAlias> aliases, String fabricId, String fabricWwn, String methodName, String methodLogName) throws NetworkDeviceControllerException {
    // a alias-name-to-result map to hold the results for each alias
    Map<String, String> aliasUpdateResults = new HashMap<String, String>();
    if (aliases.isEmpty()) {
        throw DeviceControllerException.exceptions.entityNullOrEmpty("aliases");
    }
    WBEMClient client = getNetworkDeviceClient(networkSystem);
    CIMInstance zoneServiceIns = null;
    try {
        if (fabricWwn == null) {
            fabricWwn = _smisHelper.getFabricWwn(client, fabricId);
        } else {
            validateFabric(networkSystem, fabricWwn, fabricId);
        }
        _log.info("{} started.", methodLogName);
        _log.info("Attempting to start a zoning session");
        zoneServiceIns = _smisHelper.startSession(client, fabricId, fabricWwn);
        if (zoneServiceIns == null) {
            _log.info("Failed to start a zoning session.");
            throw NetworkDeviceControllerException.exceptions.startZoningSessionFailed();
        }
        Method method = getClass().getMethod(methodName, new Class[] { WBEMClient.class, CIMInstance.class, String.class, String.class, ZoneWwnAlias.class });
        for (ZoneWwnAlias alias : aliases) {
            try {
                if ((Boolean) method.invoke(this, client, zoneServiceIns, fabricId, fabricWwn, alias)) {
                    aliasUpdateResults.put(alias.getName(), SUCCESS);
                } else {
                    aliasUpdateResults.put(alias.getName(), NO_CHANGE);
                }
            } catch (Exception ex) {
                aliasUpdateResults.put(alias.getName(), ERROR + " : " + ex.getMessage());
                _log.info("Exception was encountered but will try the rest of the batch. Error message: ", ex);
            }
        }
        _log.info("Attempting to close zoning session.");
        // If no aliases were changed, just close the session without commit and return.
        if (!hasResult(aliasUpdateResults, SUCCESS)) {
            _log.info("{} was not successful for any entity. Closing the session with no commit", methodLogName);
            if (!_smisHelper.endSession(client, zoneServiceIns, false)) {
                _log.info("Failed to terminate zoning session. Ignoring as session may have expired.");
            }
        } else {
            // if aliases were changed, commit them before ending the session
            if (!_smisHelper.endSession(client, zoneServiceIns, true)) {
                throw NetworkDeviceControllerException.exceptions.zoneSessionCommitFailed(fabricId);
            }
        }
        _log.info("{} completed successfully.", methodLogName);
    } catch (Exception e1) {
        try {
            if (zoneServiceIns != null) {
                _log.info("Attempting to terminate zoning session.");
                _smisHelper.endSession(client, zoneServiceIns, false);
            }
        } catch (WBEMException e) {
            _log.error("Failed to terminate zoning session." + e.getLocalizedMessage(), e);
        }
        _log.error("Failed to " + methodLogName + ": " + e1.getLocalizedMessage(), e1);
        throw NetworkDeviceControllerException.exceptions.operationFailed(methodLogName, e1);
    }
    _log.info(methodLogName + " results: " + toMessage(aliasUpdateResults));
    return getBiosCommandResult(aliasUpdateResults);
}
Also used : HashMap(java.util.HashMap) Method(java.lang.reflect.Method) WBEMClient(javax.wbem.client.WBEMClient) WBEMException(javax.wbem.WBEMException) ZoneWwnAlias(com.emc.storageos.networkcontroller.impl.mds.ZoneWwnAlias) CIMInstance(javax.cim.CIMInstance) WBEMException(javax.wbem.WBEMException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException)

Example 3 with CIMInstance

use of javax.cim.CIMInstance in project coprhd-controller by CoprHD.

the class BrocadeNetworkSystemDevice method activateZones.

@Override
public BiosCommandResult activateZones(NetworkSystem networkSystem, String fabricId, String fabricWwn) throws NetworkDeviceControllerException {
    BiosCommandResult result = null;
    NetworkDeviceControllerException exception = null;
    try {
        WBEMClient client = getNetworkDeviceClient(networkSystem);
        CIMInstance zonesetIns = _smisHelper.getActiveZonesetInstance(client, fabricId, fabricWwn);
        if (zonesetIns != null) {
            CIMObjectPath shadowZonesetPath = _smisHelper.getShadowZonesetPath(client, fabricId, fabricWwn, zonesetIns);
            CIMInstance zoneServiceIns = _smisHelper.getZoneServiceInstance(client, fabricId, fabricWwn);
            boolean activate = !_smisHelper.isEmptyZoneset(client, shadowZonesetPath);
            if (_smisHelper.activateZoneSet(client, zoneServiceIns, zonesetIns.getObjectPath(), activate)) {
                _log.info("The active zoneset for fabric " + fabricId + " was " + (activate ? "re-activated" : "deactivated"));
            } else {
                _log.error("Failed to re-activate zoneset");
                exception = NetworkDeviceControllerException.exceptions.zonesetActivationFailed(fabricId, new Throwable());
            }
        } else {
            exception = NetworkDeviceControllerException.exceptions.noActiveZonesetForFabric(fabricId);
        }
        result = BiosCommandResult.createSuccessfulResult();
    } catch (Exception ex) {
        _log.error("Cannot re-activate zoneset: " + ex.getLocalizedMessage());
        exception = NetworkDeviceControllerException.exceptions.zonesetActivationFailed(fabricId, ex);
    }
    if (exception != null) {
        throw exception;
    }
    return result;
}
Also used : NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) CIMObjectPath(javax.cim.CIMObjectPath) WBEMClient(javax.wbem.client.WBEMClient) CIMInstance(javax.cim.CIMInstance) WBEMException(javax.wbem.WBEMException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException)

Example 4 with CIMInstance

use of javax.cim.CIMInstance in project coprhd-controller by CoprHD.

the class DCNMDialog method makeZoneset.

/**
 * Make a zoneset object from a CIMInstance for the Zoneset
 * Calls makeZone().
 *
 * @param zonesetInstance
 * @return Zoneset
 */
private Zoneset makeZoneset(CIMInstance zonesetInstance) throws WBEMException {
    String name = cimStringProperty(zonesetInstance, "ElementName");
    Zoneset zs = new Zoneset(name);
    zs.setCimObjectPath(zonesetInstance.getObjectPath());
    zs.setInstanceID(cimStringProperty(zonesetInstance, "InstanceID"));
    zs.setDescription(cimStringProperty(zonesetInstance, "Description"));
    zs.setActive(cimBooleanProperty(zonesetInstance, "Active"));
    CloseableIterator<CIMInstance> zns = null;
    try {
        zns = _client.associatorInstances(((CIMObjectPath) zs.getCimObjectPath()), "CIM_MemberOfCollection", "CISCO_Zone", null, null, false, null);
        while (zns.hasNext()) {
            CIMInstance zn = zns.next();
            Zone zone = makeZone(zn);
            zs.getZones().add(zone);
        }
    } finally {
        if (zns != null) {
            zns.close();
        }
    }
    return zs;
}
Also used : CIMInstance(javax.cim.CIMInstance)

Example 5 with CIMInstance

use of javax.cim.CIMInstance in project coprhd-controller by CoprHD.

the class DCNMDialog method makeZone.

/**
 * Make a Zone structure from a CIMInstance.
 *
 * @param zoneInstance
 * @return Zone
 */
private Zone makeZone(CIMInstance zoneInstance) throws WBEMException {
    String name = cimStringProperty(zoneInstance, "ElementName");
    Zone zn = new Zone(name);
    zn.setCimObjectPath(zoneInstance.getObjectPath());
    zn.setInstanceID(cimStringProperty(zoneInstance, "InstanceID"));
    zn.setActive(cimBooleanProperty(zoneInstance, "Active"));
    CloseableIterator<CIMInstance> zms = null;
    try {
        zms = _client.associatorInstances(((CIMObjectPath) zn.getCimObjectPath()), "CISCO_ElementSettingData", "CISCO_ZoneMemberSettingData", null, null, false, null);
        while (zms.hasNext()) {
            CIMInstance zm = zms.next();
            ZoneMember member = makeZoneMember(zm);
            zn.getMembers().add(member);
        }
    } finally {
        if (zms != null) {
            zms.close();
        }
    }
    return zn;
}
Also used : CIMInstance(javax.cim.CIMInstance)

Aggregations

CIMInstance (javax.cim.CIMInstance)373 CIMObjectPath (javax.cim.CIMObjectPath)256 WBEMException (javax.wbem.WBEMException)141 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)105 ArrayList (java.util.ArrayList)99 URI (java.net.URI)81 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)79 CIMArgument (javax.cim.CIMArgument)71 WBEMClient (javax.wbem.client.WBEMClient)71 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)62 Volume (com.emc.storageos.db.client.model.Volume)62 HashSet (java.util.HashSet)61 IOException (java.io.IOException)53 HashMap (java.util.HashMap)53 Iterator (java.util.Iterator)50 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)48 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)48 CIMProperty (javax.cim.CIMProperty)37 StringSet (com.emc.storageos.db.client.model.StringSet)32 SmisException (com.emc.storageos.volumecontroller.impl.smis.SmisException)30