Search in sources :

Example 51 with WBEMClient

use of javax.wbem.client.WBEMClient in project coprhd-controller by CoprHD.

the class SmisCommandHelper method getPortGroupMembers.

/**
 * Get storage ports in the port group
 *
 * @param storage
 *            The storage system
 * @param portGroupPath
 *            The port group CIMObjectPath
 * @return The list of storage ports URIs
 * @throws Exception
 */
public List<URI> getPortGroupMembers(StorageSystem storage, CIMObjectPath portGroupPath) throws Exception {
    if (storage.getSystemType().equals(Type.vnxblock)) {
        return null;
    }
    CIMInstance instance = getInstance(storage, portGroupPath, false, false, null);
    WBEMClient client = getConnection(storage).getCimClient();
    List<String> storagePorts = getStoragePortsFromLunMaskingInstance(client, instance);
    _log.info("port group members : {}", Joiner.on(',').join(storagePorts));
    List<URI> storagePortURIs = new ArrayList<URI>();
    storagePortURIs.addAll(transform(ExportUtils.storagePortNamesToURIs(_dbClient, storagePorts), CommonTransformerFunctions.FCTN_STRING_TO_URI));
    return storagePortURIs;
}
Also used : ArrayList(java.util.ArrayList) WBEMClient(javax.wbem.client.WBEMClient) URI(java.net.URI) CIMInstance(javax.cim.CIMInstance)

Example 52 with WBEMClient

use of javax.wbem.client.WBEMClient in project coprhd-controller by CoprHD.

the class SmisCommandHelper method getInstance.

public CIMInstance getInstance(StorageSystem storage, CIMObjectPath objectPath, boolean propagated, boolean includeClassOrigin, String[] propertyList) throws WBEMException {
    CIMInstance cimInstance = null;
    CimConnection connection = _cimConnection.getConnection(storage);
    WBEMClient client = connection.getCimClient();
    try {
        cimInstance = client.getInstance(objectPath, propagated, includeClassOrigin, propertyList);
    } catch (WBEMException we) {
        throw we;
    }
    return cimInstance;
}
Also used : CimConnection(com.emc.storageos.cimadapter.connections.cim.CimConnection) WBEMClient(javax.wbem.client.WBEMClient) WBEMException(javax.wbem.WBEMException) CIMInstance(javax.cim.CIMInstance)

Example 53 with WBEMClient

use of javax.wbem.client.WBEMClient in project coprhd-controller by CoprHD.

the class SmisCommandHelper method invokeMethod.

public Object invokeMethod(StorageSystem storageDevice, CIMObjectPath objectPath, String methodName, CIMArgument[] inArgs, CIMArgument[] outArgs) throws WBEMException {
    CimConnection connection = getConnection(storageDevice);
    WBEMClient client = connection.getCimClient();
    int index = 0;
    StringBuilder inputInfoBuffer = new StringBuilder();
    inputInfoBuffer.append("\nSMI-S Provider: ").append(connection.getHost()).append(" -- Attempting invokeMethod ").append(methodName).append(" on\n").append("  objectPath=").append(objectPath.toString()).append(" with arguments: \n");
    if (inArgs != null) {
        for (CIMArgument arg : inArgs) {
            if (arg != null) {
                inputInfoBuffer.append("    inArg[").append(index++).append("]=").append(arg.toString()).append('\n');
            }
        }
    }
    InvokeTestFailure.internalOnlyInvokeSmisTestFailure(methodName, InvokeTestFailure.ARTIFICIAL_FAILURE_015);
    _log.info(inputInfoBuffer.toString());
    long start = System.nanoTime();
    Object obj = client.invokeMethod(objectPath, methodName, inArgs, outArgs);
    String total = String.format("%2.6f", ((System.nanoTime() - start) / 1000000000.0));
    String str = protectedToString(obj);
    StringBuilder outputInfoBuffer = new StringBuilder();
    outputInfoBuffer.append("\nSMI-S Provider: ").append(connection.getHost()).append(" -- Completed invokeMethod ").append(methodName).append(" on\n").append("  objectPath=").append(objectPath.toString()).append("\n  Returned: ").append(str).append(" with output arguments: \n");
    for (CIMArgument arg : outArgs) {
        if (arg != null) {
            str = protectedToString(arg);
            outputInfoBuffer.append("    outArg=").append(str).append('\n');
        }
    }
    outputInfoBuffer.append("  Execution time: ").append(total).append(" seconds.\n");
    _log.info(outputInfoBuffer.toString());
    return obj;
}
Also used : CimConnection(com.emc.storageos.cimadapter.connections.cim.CimConnection) BlockObject(com.emc.storageos.db.client.model.BlockObject) DiscoveredDataObject(com.emc.storageos.db.client.model.DiscoveredDataObject) WBEMClient(javax.wbem.client.WBEMClient) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) CIMArgument(javax.cim.CIMArgument)

Example 54 with WBEMClient

use of javax.wbem.client.WBEMClient in project coprhd-controller by CoprHD.

the class VmaxExportOperations method removeInitiators.

@Override
public void removeInitiators(StorageSystem storage, URI exportMaskURI, List<URI> volumeURIList, List<Initiator> initiatorList, List<URI> targetURIList, TaskCompleter taskCompleter) throws DeviceControllerException {
    _log.info("{} removeInitiators START...", storage == null ? null : storage.getSerialNumber());
    String clusterName = getClusterNameFromInitiators(initiatorList);
    if (clusterName == null) {
        final String logMsg = "All initiators should belong to the same cluster or not have a cluster name at all";
        _log.error(String.format("removeInitiator failed - maskName: %s", exportMaskURI.toString()), logMsg);
        String opName = ResourceOperationTypeEnum.DELETE_EXPORT_INITIATOR.getName();
        ServiceError serviceError = DeviceControllerException.errors.jobFailedOp(opName);
        taskCompleter.error(_dbClient, serviceError);
        return;
    } else {
        CloseableIterator<CIMInstance> cigInstances = null;
        try {
            _log.info("removeInitiators: Export mask id: {}", exportMaskURI);
            if (volumeURIList != null) {
                _log.info("removeInitiators: volumes : {}", Joiner.on(',').join(volumeURIList));
            }
            _log.info("removeInitiators: initiators : {}", Joiner.on(',').join(initiatorList));
            if (targetURIList != null) {
                _log.info("removeInitiators: targets : {}", Joiner.on(',').join(targetURIList));
            }
            boolean isRollback = WorkflowService.getInstance().isStepInRollbackState(taskCompleter.getOpId());
            ExportMask exportMask = _dbClient.queryObject(ExportMask.class, exportMaskURI);
            ExportMaskValidationContext ctx = new ExportMaskValidationContext();
            ctx.setStorage(storage);
            ctx.setExportMask(exportMask);
            ctx.setBlockObjects(volumeURIList, _dbClient);
            ctx.setInitiators(initiatorList);
            // Allow exceptions to be thrown when not rolling back.
            ctx.setAllowExceptions(!isRollback);
            validator.removeInitiators(ctx).validate();
            if (isRollback) {
                // Get the context from the task completer as this is a rollback.
                ExportOperationContext context = (ExportOperationContext) WorkflowService.getInstance().loadStepData(taskCompleter.getOpId());
                exportMaskRollback(storage, context, taskCompleter);
            } else {
                CIMArgument[] inArgs;
                CIMArgument[] outArgs;
                _log.info("Removing initiators ...");
                // Create a mapping of the InitiatorPort String to Initiator.
                Map<String, Initiator> nameToInitiator = new HashMap<String, Initiator>();
                for (Initiator initiator : initiatorList) {
                    String normalizedName = Initiator.normalizePort(initiator.getInitiatorPort());
                    nameToInitiator.put(normalizedName, initiator);
                }
                // We're going to get a mapping of which InitiatorGroups the initiators belong.
                // With this mapping we can remove initiators from their associated IGs sequentially
                ListMultimap<CIMObjectPath, String> igToInitiators = ArrayListMultimap.create();
                mapInitiatorsToInitiatorGroups(igToInitiators, storage, initiatorList);
                for (CIMObjectPath igPath : igToInitiators.keySet()) {
                    List<String> initiatorPorts = igToInitiators.get(igPath);
                    List<Initiator> initiatorsForIG = new ArrayList<Initiator>();
                    // Using the mapping, create a list of Initiator objects
                    for (String port : initiatorPorts) {
                        Initiator initiator = nameToInitiator.get(port);
                        if (initiator != null) {
                            initiatorsForIG.add(initiator);
                        }
                    }
                    boolean removingAllPortsInIG = initiatorPorts.size() == initiatorsForIG.size();
                    if (removingAllPortsInIG) {
                        // We are apparently trying to remove all the initiators in an Initiator Group.
                        // This is a special condition. It is not a case of removing the initiators
                        // from an individual group, we will instead treat this as a removal of the
                        // IG from the cascade-IG (thereby preventing access to the host pointed to
                        // by this IG).
                        _log.info(String.format("Request to remove all the initiators from IG %s, so we will remove the IG from the cascaded-IG", igPath.toString()));
                        ExportMask mask = _dbClient.queryObject(ExportMask.class, exportMaskURI);
                        CIMObjectPath cigInMVPath = null;
                        CIMInstance mvInstance = _helper.getSymmLunMaskingView(storage, mask);
                        cigInstances = _helper.getAssociatorInstances(storage, mvInstance.getObjectPath(), null, SmisConstants.SE_INITIATOR_MASKING_GROUP, null, null, SmisConstants.PS_ELEMENT_NAME);
                        if (cigInstances.hasNext()) {
                            cigInMVPath = cigInstances.next().getObjectPath();
                        }
                        // Find the cascaded initiator group that this belongs to and remove the IG from it.
                        // Note: we should not be in here if the IG was associated directly to the MV. If the
                        // IG were related to the MV, then the masking orchestrator should have generated
                        // a workflow to delete the MV.
                        cigInstances = _helper.getAssociatorInstances(storage, igPath, null, SmisConstants.SE_INITIATOR_MASKING_GROUP, null, null, SmisConstants.PS_ELEMENT_NAME);
                        while (cigInstances.hasNext()) {
                            CIMObjectPath cigPath = cigInstances.next().getObjectPath();
                            if (!cigPath.equals(cigInMVPath)) {
                                // to remove the initiators from.
                                continue;
                            }
                            _log.info(String.format("Removing IG %s from CIG %s", igPath.toString(), cigPath.toString()));
                            inArgs = _helper.getRemoveIGFromCIG(igPath, cigPath);
                            outArgs = new CIMArgument[5];
                            _helper.invokeMethodSynchronously(storage, _cimPath.getControllerConfigSvcPath(storage), "RemoveMembers", inArgs, outArgs, null);
                            // Determine if the IG contains all initiators that were added by user/ViPR, and if
                            // the IG is no longer referenced by masking views or parent IGs. If so, it can be
                            // removed.
                            boolean removeIG = true;
                            for (Initiator initiator : initiatorsForIG) {
                                if (!mask.hasUserInitiator(initiator.getId())) {
                                    removeIG = false;
                                }
                            }
                            if (removeIG) {
                                List<CIMObjectPath> igList = new ArrayList<>();
                                igList.add(igPath);
                                this.checkIGsAndDeleteIfUnassociated(storage, igList);
                            }
                        }
                    } else {
                        inArgs = _helper.getRemoveInitiatorsFromMaskingGroupInputArguments(storage, igPath, initiatorsForIG);
                        outArgs = new CIMArgument[5];
                        _helper.invokeMethodSynchronously(storage, _cimPath.getControllerConfigSvcPath(storage), "RemoveMembers", inArgs, outArgs, null);
                    }
                }
                if (targetURIList != null && !targetURIList.isEmpty()) {
                    _log.info("Removing targets...");
                    URI pgURI = exportMask.getPortGroup();
                    if (!NullColumnValueGetter.isNullURI(pgURI)) {
                        StoragePortGroup portGroup = _dbClient.queryObject(StoragePortGroup.class, pgURI);
                        if (!portGroup.getMutable()) {
                            _log.info(String.format("The port group %s is immutable, done", portGroup.getNativeGuid()));
                            taskCompleter.ready(_dbClient);
                            return;
                        }
                    }
                    CIMInstance portGroupInstance = _helper.getPortGroupInstance(storage, exportMask.getMaskName());
                    if (null == portGroupInstance) {
                        String errMsg = String.format("removeInitiators failed - maskName %s : Port group not found ", exportMask.getMaskName());
                        ServiceError serviceError = DeviceControllerException.errors.jobFailedMsg(errMsg, null);
                        taskCompleter.error(_dbClient, serviceError);
                        return;
                    }
                    String pgGroupName = (String) portGroupInstance.getPropertyValue(SmisConstants.CP_ELEMENT_NAME);
                    // Get the current ports off of the storage group; only add the ones that aren't there already.
                    WBEMClient client = _helper.getConnection(storage).getCimClient();
                    List<String> storagePorts = _helper.getStoragePortsFromLunMaskingInstance(client, portGroupInstance);
                    Set<URI> storagePortURIs = new HashSet<>();
                    storagePortURIs.addAll(transform(ExportUtils.storagePortNamesToURIs(_dbClient, storagePorts), CommonTransformerFunctions.FCTN_STRING_TO_URI));
                    Set<URI> portsToRemove = intersection(newHashSet(targetURIList), storagePortURIs);
                    boolean removingLast = portsToRemove.size() == storagePortURIs.size();
                    if (!portsToRemove.isEmpty() && !removingLast) {
                        inArgs = _helper.getRemoveTargetPortsFromMaskingGroupInputArguments(storage, pgGroupName, Lists.newArrayList(portsToRemove));
                        outArgs = new CIMArgument[5];
                        _helper.invokeMethodSynchronously(storage, _cimPath.getControllerConfigSvcPath(storage), "RemoveMembers", inArgs, outArgs, null);
                    } else if (!removingLast) {
                        _log.info(String.format("Target ports already removed fom port group %s, likely by a previous operation.", pgGroupName));
                    } else {
                        // In this case, some programming, orchestration, or
                        // user-fiddling-with-things-outside-of-ViPR situation led us
                        // to this scenario.
                        // It's best to just print the ports and port group and leave it alone.
                        _log.error(String.format("Removing target ports would cause an empty port group %s, which is not allowed on VMAX.  Manual port removal may be required.", pgGroupName));
                    // This can lead to an inaccuracy in the ExportMask object, but may be recitified next time
                    // it's refreshed.
                    }
                }
            }
            _log.info(String.format("removeInitiators succeeded - maskName: %s", exportMaskURI.toString()));
            taskCompleter.ready(_dbClient);
        } catch (Exception e) {
            _log.error(String.format("removeInitiators failed - maskName: %s", exportMaskURI.toString()), e);
            String opName = ResourceOperationTypeEnum.DELETE_EXPORT_INITIATOR.getName();
            ServiceError serviceError = DeviceControllerException.errors.jobFailedOpMsg(opName, e.getMessage());
            taskCompleter.error(_dbClient, serviceError);
        } finally {
            if (cigInstances != null) {
                cigInstances.close();
            }
        }
    }
    _log.info("{} removeInitiators END...", storage == null ? null : storage.getSerialNumber());
}
Also used : StoragePortGroup(com.emc.storageos.db.client.model.StoragePortGroup) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URI(java.net.URI) CIMInstance(javax.cim.CIMInstance) Initiator(com.emc.storageos.db.client.model.Initiator) ExportOperationContext(com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext) WBEMClient(javax.wbem.client.WBEMClient) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) HashSet(java.util.HashSet) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ExportMask(com.emc.storageos.db.client.model.ExportMask) CIMObjectPath(javax.cim.CIMObjectPath) SmisException(com.emc.storageos.volumecontroller.impl.smis.SmisException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) WBEMException(javax.wbem.WBEMException) ExportMaskValidationContext(com.emc.storageos.volumecontroller.impl.validators.contexts.ExportMaskValidationContext) CIMArgument(javax.cim.CIMArgument)

Example 55 with WBEMClient

use of javax.wbem.client.WBEMClient in project coprhd-controller by CoprHD.

the class VmaxExportOperations method removeStoragePorts.

/**
 * Remove storage ports from the port group.
 *
 * @param storage - Storage system
 * @param exportMaskURI - Export mask URI
 * @param targetURIList - Storage ports to be removed
 * @return - Removed storage ports
 * @throws Exception
 */
private Set<URI> removeStoragePorts(StorageSystem storage, URI exportMaskURI, List<URI> targetURIList) throws Exception {
    _log.info("Removing storage ports...");
    ExportMask mask = _dbClient.queryObject(ExportMask.class, exportMaskURI);
    Set<URI> portsToRemove = new HashSet<URI>();
    CIMInstance portGroupInstance = _helper.getPortGroupInstance(storage, mask.getMaskName());
    if (null == portGroupInstance) {
        String errMsg = String.format("remove storage ports failed - maskName %s : Port group not found ", mask.getMaskName());
        throw DeviceControllerException.exceptions.exportGroupPathAdjustmentError(errMsg);
    }
    String pgGroupName = (String) portGroupInstance.getPropertyValue(SmisConstants.CP_ELEMENT_NAME);
    // Get the current ports off of the storage group; only remove the ones that are there.
    WBEMClient client = _helper.getConnection(storage).getCimClient();
    List<String> storagePorts = _helper.getStoragePortsFromLunMaskingInstance(client, portGroupInstance);
    Set<URI> storagePortURIs = new HashSet<>();
    storagePortURIs.addAll(transform(ExportUtils.storagePortNamesToURIs(_dbClient, storagePorts), CommonTransformerFunctions.FCTN_STRING_TO_URI));
    portsToRemove = intersection(newHashSet(targetURIList), storagePortURIs);
    boolean removingLast = portsToRemove.size() == storagePortURIs.size();
    if (!portsToRemove.isEmpty() && !removingLast) {
        // Going to remove the ports from the port group, checking if the port group is shared with other masking view
        if (_helper.checkPortGroupShared(storage, pgGroupName, mask.getMaskName())) {
            String msg = String.format("The port group %s has other masking view associated, could not remove ports from it", pgGroupName);
            _log.error(msg);
            throw DeviceControllerException.exceptions.exportGroupPathAdjustmentError(msg);
        }
        CIMArgument[] inArgs = _helper.getRemoveTargetPortsFromMaskingGroupInputArguments(storage, pgGroupName, Lists.newArrayList(portsToRemove));
        CIMArgument[] outArgs = new CIMArgument[5];
        _helper.invokeMethodSynchronously(storage, _cimPath.getControllerConfigSvcPath(storage), "RemoveMembers", inArgs, outArgs, null);
    } else if (!removingLast) {
        _log.info(String.format("Target ports already removed fom port group %s, likely by a previous operation.", pgGroupName));
    } else {
        // In this case, some programming, orchestration, or user-fiddling-with-things-outside-of-ViPR situation led
        // us to this scenario. It's best to just print the ports and port group and leave it alone.
        _log.error(String.format("Removing target ports would cause an empty port group %s, which is not allowed on VMAX.  Manual port removal may be required.", pgGroupName));
    // This can lead to an inaccuracy in the ExportMask object, but may be rectified next time it's refreshed.
    }
    return portsToRemove;
}
Also used : ExportMask(com.emc.storageos.db.client.model.ExportMask) WBEMClient(javax.wbem.client.WBEMClient) URI(java.net.URI) CIMInstance(javax.cim.CIMInstance) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) HashSet(java.util.HashSet) CIMArgument(javax.cim.CIMArgument)

Aggregations

WBEMClient (javax.wbem.client.WBEMClient)110 CIMObjectPath (javax.cim.CIMObjectPath)75 CIMInstance (javax.cim.CIMInstance)69 WBEMException (javax.wbem.WBEMException)42 ArrayList (java.util.ArrayList)39 URI (java.net.URI)35 DbClient (com.emc.storageos.db.client.DbClient)29 Volume (com.emc.storageos.db.client.model.Volume)29 CIMConnectionFactory (com.emc.storageos.volumecontroller.impl.smis.CIMConnectionFactory)27 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)25 HashSet (java.util.HashSet)25 CimConnection (com.emc.storageos.cimadapter.connections.cim.CimConnection)24 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)18 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)18 HashMap (java.util.HashMap)17 ExportMask (com.emc.storageos.db.client.model.ExportMask)16 SmisException (com.emc.storageos.volumecontroller.impl.smis.SmisException)16 CIMProperty (javax.cim.CIMProperty)14 UnsignedInteger32 (javax.cim.UnsignedInteger32)14 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)13