Search in sources :

Example 16 with CIMProperty

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

the class IBMCIMObjectPathFactory method getConfigSvcPath.

/*
     * (non-Javadoc) Construct object path of
     * IBMTSDS_StorageConfigurationService.
     * 
     * Example - Namespace: "/root/ibm"
     * CreationClassName="IBMTSDS_StorageConfigurationService"
     * Name="StorageConfigurationService for IBM.2810-7825363"
     * SystemCreationClassName="IBMTSDS_StorageSystem"
     * SystemName="IBM.2810-7825363"
     */
public CIMObjectPath getConfigSvcPath(StorageSystem storageDevice) {
    CIMObjectPath configSvcPath;
    try {
        String systemName = storageDevice.getSerialNumber();
        CIMProperty[] configSvcPropKeys = { _cimProperty.string(CP_CREATION_CLASS_NAME, prefixWithParamName(STORAGE_CONFIGURATION_SERVICE)), _cimProperty.string(CP_NAME, STORAGE_CONFIGURATION_SERVICE_NAME + systemName), _cimProperty.string(CP_SYSTEM_CREATION_CLASS_NAME, prefixWithParamName(STORAGE_SYSTEM)), _cimProperty.string(CP_SYSTEM_NAME, systemName) };
        configSvcPath = CimObjectPathCreator.createInstance(prefixWithParamName(STORAGE_CONFIGURATION_SERVICE), Constants.IBM_NAMESPACE, configSvcPropKeys);
    } catch (Exception e) {
        _log.error(e.getMessage(), e);
        throw new IllegalStateException("Problem getting config service: " + storageDevice.getLabel());
    }
    return configSvcPath;
}
Also used : CIMProperty(javax.cim.CIMProperty) CIMObjectPath(javax.cim.CIMObjectPath) WBEMException(javax.wbem.WBEMException)

Example 17 with CIMProperty

use of javax.cim.CIMProperty 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 18 with CIMProperty

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

Example 19 with CIMProperty

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

the class XIVSmisCommandHelper method addTargetPoolToArgs.

@SuppressWarnings("rawtypes")
private void addTargetPoolToArgs(StorageSystem storageSystem, StoragePool pool, List<CIMArgument> args) {
    CIMProperty[] inPoolPropKeys = { _cimProperty.string(CP_INSTANCE_ID, pool.getNativeId()) };
    CIMObjectPath inPoolPath = CimObjectPathCreator.createInstance(pool.getPoolClassName(), _cimConnection.getNamespace(storageSystem), inPoolPropKeys);
    args.add(_cimArgument.reference(CP_TARGET_POOL, inPoolPath));
}
Also used : CIMProperty(javax.cim.CIMProperty) CIMObjectPath(javax.cim.CIMObjectPath)

Example 20 with CIMProperty

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

the class SmisAbstractCreateVolumeJob method updateStatus.

/**
 * Called to update the job status when the volume create job completes.
 * <p/>
 * This is common update code for volume create operations.
 *
 * @param jobContext The job context.
 */
@Override
public void updateStatus(JobContext jobContext) throws Exception {
    CloseableIterator<CIMObjectPath> iterator = null;
    DbClient dbClient = jobContext.getDbClient();
    JobStatus jobStatus = getJobStatus();
    try {
        if (jobStatus == JobStatus.IN_PROGRESS) {
            return;
        }
        int volumeCount = 0;
        String opId = getTaskCompleter().getOpId();
        StringBuilder logMsgBuilder = new StringBuilder(String.format("Updating status of job %s to %s", opId, jobStatus.name()));
        CIMConnectionFactory cimConnectionFactory = jobContext.getCimConnectionFactory();
        WBEMClient client = getWBEMClient(dbClient, cimConnectionFactory);
        iterator = client.associatorNames(getCimJob(), null, SmisConstants.CIM_STORAGE_VOLUME, null, null);
        Calendar now = Calendar.getInstance();
        // from pool's reserved capacity map.
        if (jobStatus == JobStatus.SUCCESS || jobStatus == JobStatus.FAILED || jobStatus == JobStatus.FATAL_ERROR) {
            SmisUtils.updateStoragePoolCapacity(dbClient, client, _storagePool);
            StoragePool pool = dbClient.queryObject(StoragePool.class, _storagePool);
            StringMap reservationMap = pool.getReservedCapacityMap();
            for (URI volumeId : getTaskCompleter().getIds()) {
                // remove from reservation map
                reservationMap.remove(volumeId.toString());
            }
            dbClient.persistObject(pool);
        }
        if (jobStatus == JobStatus.SUCCESS) {
            List<URI> volumes = new ArrayList<URI>();
            while (iterator.hasNext()) {
                CIMObjectPath volumePath = iterator.next();
                CIMProperty<String> deviceID = (CIMProperty<String>) volumePath.getKey(SmisConstants.CP_DEVICE_ID);
                String nativeID = deviceID.getValue();
                URI volumeId = getTaskCompleter().getId(volumeCount++);
                volumes.add(volumeId);
                persistVolumeNativeID(dbClient, volumeId, nativeID, now);
                processVolume(jobContext, volumePath, nativeID, volumeId, client, dbClient, logMsgBuilder, now);
            }
            // Add Volumes to Consistency Group (if needed)
            addVolumesToConsistencyGroup(jobContext, volumes);
        } else if (jobStatus == JobStatus.FAILED) {
            if (iterator.hasNext()) {
                while (iterator.hasNext()) {
                    CIMObjectPath volumePath = iterator.next();
                    CIMProperty<String> deviceID = (CIMProperty<String>) volumePath.getKey(SmisConstants.CP_DEVICE_ID);
                    String nativeID = deviceID.getValue();
                    URI volumeId = getTaskCompleter().getId(volumeCount++);
                    if ((nativeID != null) && (nativeID.length() != 0)) {
                        persistVolumeNativeID(dbClient, volumeId, nativeID, now);
                        processVolume(jobContext, volumePath, nativeID, volumeId, client, dbClient, logMsgBuilder, now);
                    } else {
                        logMsgBuilder.append("\n");
                        logMsgBuilder.append(String.format("Task %s failed to create volume: %s", opId, volumeId));
                        Volume volume = dbClient.queryObject(Volume.class, volumeId);
                        volume.setInactive(true);
                        dbClient.persistObject(volume);
                    }
                }
            } else {
                for (URI id : getTaskCompleter().getIds()) {
                    logMsgBuilder.append("\n");
                    logMsgBuilder.append(String.format("Task %s failed to create volume: %s", opId, id.toString()));
                    Volume volume = dbClient.queryObject(Volume.class, id);
                    volume.setInactive(true);
                    dbClient.persistObject(volume);
                }
            }
        }
        _log.info(logMsgBuilder.toString());
    } catch (Exception e) {
        _log.error("Caught an exception while trying to updateStatus for SmisCreateVolumeJob", e);
        setPostProcessingErrorStatus("Encountered an internal error during volume create job status processing : " + e.getMessage());
    } finally {
        super.updateStatus(jobContext);
        if (iterator != null) {
            iterator.close();
        }
    }
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) DbClient(com.emc.storageos.db.client.DbClient) StoragePool(com.emc.storageos.db.client.model.StoragePool) Calendar(java.util.Calendar) CIMObjectPath(javax.cim.CIMObjectPath) ArrayList(java.util.ArrayList) URI(java.net.URI) WBEMException(javax.wbem.WBEMException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) IOException(java.io.IOException) CIMConnectionFactory(com.emc.storageos.volumecontroller.impl.smis.CIMConnectionFactory) CIMProperty(javax.cim.CIMProperty) Volume(com.emc.storageos.db.client.model.Volume) WBEMClient(javax.wbem.client.WBEMClient)

Aggregations

CIMProperty (javax.cim.CIMProperty)74 CIMObjectPath (javax.cim.CIMObjectPath)57 CIMInstance (javax.cim.CIMInstance)37 ArrayList (java.util.ArrayList)26 WBEMException (javax.wbem.WBEMException)25 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)18 CIMArgument (javax.cim.CIMArgument)16 WBEMClient (javax.wbem.client.WBEMClient)14 IOException (java.io.IOException)11 Volume (com.emc.storageos.db.client.model.Volume)10 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)10 URI (java.net.URI)9 ServiceCodeException (com.emc.storageos.svcs.errorhandling.resources.ServiceCodeException)8 UnsignedInteger16 (javax.cim.UnsignedInteger16)8 DbClient (com.emc.storageos.db.client.DbClient)7 SmisException (com.emc.storageos.volumecontroller.impl.smis.SmisException)7 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)6 HashMap (java.util.HashMap)6 ExportMask (com.emc.storageos.db.client.model.ExportMask)5 Initiator (com.emc.storageos.db.client.model.Initiator)5