Search in sources :

Example 71 with CIMArgument

use of javax.cim.CIMArgument 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)

Example 72 with CIMArgument

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

the class XIVExportOperations method getSystemSpecificCollectionPath.

/*
     * create SystemSpecificCollection for the initiators
     * 
     * Try to use the given element name first, if not success, retry without
     * element name
     */
private CIMObjectPath getSystemSpecificCollectionPath(StorageSystem storage, String elementName, String[] initiators) throws Exception {
    @SuppressWarnings("rawtypes") CIMArgument[] outArgs = new CIMArgument[5];
    CIMObjectPath hwIdManagementSvc = _cimPath.getStorageHardwareIDManagementService(storage);
    _helper.createHardwareIDCollection(storage, hwIdManagementSvc, elementName, initiators, outArgs);
    if (outArgs[0] == null) {
        // must be return code 45504 (Host name already exists)
        // now let system generate element name
        _helper.createHardwareIDCollection(storage, hwIdManagementSvc, null, initiators, outArgs);
    }
    return (CIMObjectPath) _cimPath.getFromOutputArgs(outArgs, IBMSmisConstants.CP_HARDWARE_ID_COLLECTION);
}
Also used : CIMObjectPath(javax.cim.CIMObjectPath) CIMArgument(javax.cim.CIMArgument)

Example 73 with CIMArgument

use of javax.cim.CIMArgument 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 74 with CIMArgument

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

the class XIVSmisCommandHelper method invokeMethod.

/**
 * Invoke CIM method.
 */
@SuppressWarnings("rawtypes")
public void invokeMethod(StorageSystem storageDevice, CIMObjectPath objectPath, String methodName, CIMArgument[] inArgs, CIMArgument[] outArgs) throws Exception {
    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");
    for (CIMArgument arg : inArgs) {
        inputInfoBuffer.append("    inArg[").append(index++).append("]=").append(arg.toString()).append('\n');
    }
    _log.info(inputInfoBuffer.toString());
    long start = System.nanoTime();
    // workaround for CTRL-8024 (CIMError: "request-not-well-formed" ...)
    // retry CIM_MAX_RETRY_COUNT times if encounter the error
    // the invoke method will return quickly with the error, so extensive retry (e.g., 25 times), won't be a big overhead
    Object obj = null;
    int retryCount = 0;
    while (true) {
        try {
            _log.info("Invoke method {}, attempt {}", methodName, retryCount);
            obj = client.invokeMethod(objectPath, methodName, inArgs, outArgs);
        } catch (WBEMException e) {
            if (CIM_BAD_REQUEST.equals(e.getMessage())) {
                if (retryCount < CIM_MAX_RETRY_COUNT) {
                    _log.warn("Encountered 'request-not-well-formed' error. Retry...");
                    retryCount++;
                    try {
                        Thread.sleep(CIM_RETRY_WAIT_INTERVAL);
                    } catch (InterruptedException ie) {
                        _log.warn("Thread: " + Thread.currentThread().getName() + " interrupted.");
                        throw e;
                    }
                    continue;
                }
                _log.warn("Exhausted {} retries", CIM_MAX_RETRY_COUNT);
            }
            // other WBEMException, or reach the max retry count
            throw e;
        }
        // no exception
        break;
    }
    String total = String.format("%2.6f", ((System.nanoTime() - start) / 1000000000.0));
    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(obj.toString()).append(" with output arguments: \n");
    int returnCode = NumberUtils.toInt(obj.toString(), INVALID_RETURN_CODE);
    for (CIMArgument arg : outArgs) {
        if (arg != null) {
            if (returnCode == CIM_SUCCESS_CODE) {
                outputInfoBuffer.append("    outArg=").append(arg.toString()).append('\n');
            } else {
                outputInfoBuffer.append("    outArg=").append(arg.getName()).append("=").append(arg.getValue()).append(" (Type ").append(arg.getDataType()).append(")\n");
            }
        }
    }
    outputInfoBuffer.append("  Execution time: ").append(total).append(" seconds.\n");
    _log.info(outputInfoBuffer.toString());
    if (returnCode == CIM_MAPPING_NOT_DEFINED && methodName.equals(HIDE_PATHS)) {
    // ignore the error
    } else if (returnCode == this.CIM_DUPLICATED_HOST_NAME && methodName.equals(CREATE_HARDWARE_ID_COLLECTION)) {
        outArgs[0] = null;
    } else if (returnCode == this.CIM_OPERATION_PARTIALLY_SUCCEEDED && methodName.equals(ADD_HARDWARE_IDS_TO_COLLECTION)) {
        outArgs[0] = null;
    } else if (returnCode == CIM_DUPLICATED_CG_NAME_CODE) {
        throw new Exception(DUPLICATED_CG_NAME_ERROR);
    } else if (returnCode == CIM_ONLY_ALLOWED_ON_EMPTY_CG_CODE && methodName.equals(REMOVE_MEMBERS)) {
        // after this call
        throw new Exception("Failed with return code: " + obj);
    } else if (returnCode != CIM_SUCCESS_CODE && methodName.equals(CREATE_OR_MODIFY_ELEMENTS_FROM_STORAGE_POOL) && checkIfVolumeSizeExceedingPoolSize(inArgs, outArgs)) {
        throw DeviceControllerException.exceptions.volumeSizeExceedingPoolSize(getVolumeName(inArgs));
    } else if (returnCode != CIM_SUCCESS_CODE) {
        throw new Exception("Failed with return code: " + obj);
    }
}
Also used : CimConnection(com.emc.storageos.cimadapter.connections.cim.CimConnection) BlockObject(com.emc.storageos.db.client.model.BlockObject) DataObject(com.emc.storageos.db.client.model.DataObject) WBEMClient(javax.wbem.client.WBEMClient) 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)

Example 75 with CIMArgument

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

the class XIVSmisCommandHelper method getExpandVolumeInputArguments.

/*
     * Construct input arguments for expanding volume.
     */
public CIMArgument[] getExpandVolumeInputArguments(StorageSystem storageDevice, Volume volume, Long size) {
    ArrayList<CIMArgument> list = new ArrayList<CIMArgument>();
    try {
        CIMObjectPath volumePath = _cimPath.getBlockObjectPath(storageDevice, volume);
        list.add(_cimArgument.reference(CP_THE_ELEMENT, volumePath));
        list.add(_cimArgument.uint64(CP_SIZE, size));
        CIMProperty[] goalPropKeys = { _cimProperty.string(CP_INSTANCE_ID, SYSTEM_BLOCK_SIZE) };
        CIMObjectPath goalPath = CimObjectPathCreator.createInstance(DATA_TYPE_SETTING, Constants.IBM_NAMESPACE, goalPropKeys);
        list.add(_cimArgument.reference(CP_GOAL, goalPath));
    } catch (Exception e) {
        throw new IllegalStateException("Problem getting input arguments: " + storageDevice.getLabel());
    }
    return list.toArray(new CIMArgument[list.size()]);
}
Also used : CIMProperty(javax.cim.CIMProperty) ArrayList(java.util.ArrayList) CIMObjectPath(javax.cim.CIMObjectPath) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) WBEMException(javax.wbem.WBEMException) SmisException(com.emc.storageos.volumecontroller.impl.smis.SmisException) CIMArgument(javax.cim.CIMArgument)

Aggregations

CIMArgument (javax.cim.CIMArgument)234 CIMObjectPath (javax.cim.CIMObjectPath)190 WBEMException (javax.wbem.WBEMException)129 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)127 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)80 ArrayList (java.util.ArrayList)74 CIMInstance (javax.cim.CIMInstance)71 Volume (com.emc.storageos.db.client.model.Volume)48 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)42 URI (java.net.URI)39 SmisException (com.emc.storageos.volumecontroller.impl.smis.SmisException)36 QueueJob (com.emc.storageos.volumecontroller.impl.job.QueueJob)32 BlockObject (com.emc.storageos.db.client.model.BlockObject)29 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)29 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)26 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)23 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)22 HashSet (java.util.HashSet)16 List (java.util.List)16 CIMProperty (javax.cim.CIMProperty)16