Search in sources :

Example 26 with CimConnection

use of com.emc.storageos.cimadapter.connections.cim.CimConnection in project coprhd-controller by CoprHD.

the class ConnectionManager method internalRemoveConnection.

/**
 * Looks up the 'hostAndPort' connection in the map. If it exists, the underlying
 * connection will be closed, it will be removed from the map, and related data
 * structures will be updated.
 *
 * @param hostAndPort [IN] - Host + Port key used for looking up connection
 */
private void internalRemoveConnection(String hostAndPort) {
    // Verify the passed host is not null or blank.
    if ((hostAndPort == null) || (hostAndPort.length() == 0)) {
        throw new ConnectionManagerException("Passed host/port is null or blank.");
    }
    try {
        // Verify we are managing a connection to the passed host.
        if (!isConnected(hostAndPort)) {
            throw new ConnectionManagerException(MessageFormatter.format("The connection manager is not managing a connection to host {}", hostAndPort).getMessage());
        }
        // Pause the listener when removing a connection.
        _listener.pause();
        // Remove the connection to the passed host.
        CimConnection connection = _connections.get(hostAndPort);
        if (connection != null) {
            s_logger.info("Closing connection to the CIM provider on host/port {}", hostAndPort);
            connection.close();
            _connections.remove(hostAndPort);
            connectionLastTouch.remove(hostAndPort);
            pinnedConnections.remove(hostAndPort);
        }
    } catch (ConnectionManagerException e) {
        throw e;
    } catch (Exception e) {
        throw new ConnectionManagerException(MessageFormatter.format("Failed removing the connection to the provider on host/port {}", hostAndPort).getMessage(), e);
    } finally {
        // Now resume the listener.
        _listener.resume();
    }
}
Also used : CimConnection(com.emc.storageos.cimadapter.connections.cim.CimConnection) IOException(java.io.IOException)

Example 27 with CimConnection

use of com.emc.storageos.cimadapter.connections.cim.CimConnection in project coprhd-controller by CoprHD.

the class ConnectionManager method createCimConnection.

/**
 * Creates a connection to a CIM provider using the passed connection info.
 *
 * @param connectionInfo Contains the information required to establish the
 *            connection.
 *
 * @throws Exception When an error occurs establishing the connection to the
 *             CIM provider.
 */
private void createCimConnection(CimConnectionInfo connectionInfo) throws Exception {
    String hostAndPort = generateConnectionCacheKey(connectionInfo.getHost(), connectionInfo.getPort());
    s_logger.info("Creating connection to CIM provider on host/port {}", hostAndPort);
    try {
        // Create the CIM connection.
        CimConnection connection = new CimConnection(connectionInfo, _listener, _configuration.getIndicationFilterMap());
        connection.connect(_configuration.getSubscriptionsIdentifier(), _configuration.getDeleteStaleSubscriptionsOnConnect());
        _connections.put(hostAndPort, connection);
        connectionLastTouch.put(hostAndPort, System.currentTimeMillis());
    } catch (Exception e) {
        throw new Exception(MessageFormatter.format("Failed creating connection to CIM provider on host/port {}", hostAndPort).getMessage(), e);
    }
}
Also used : CimConnection(com.emc.storageos.cimadapter.connections.cim.CimConnection) IOException(java.io.IOException)

Example 28 with CimConnection

use of com.emc.storageos.cimadapter.connections.cim.CimConnection in project coprhd-controller by CoprHD.

the class VnxExportOperations method createExportMask.

/*
     * (non-Javadoc)
     *
     * @see
     * com.emc.storageos.volumecontroller.impl.smis.ExportMaskOperations#createExportMask(com.emc.storageos.db.client.
     * model.StorageSystem, java.net.URI, com.emc.storageos.volumecontroller.impl.VolumeURIHLU[], java.util.List,
     * java.util.List, com.emc.storageos.volumecontroller.TaskCompleter)
     *
     */
@Override
public void createExportMask(StorageSystem storage, URI exportMaskURI, VolumeURIHLU[] volumeURIHLUs, List<URI> targetURIList, List<Initiator> initiatorList, TaskCompleter taskCompleter) throws DeviceControllerException {
    _log.info("{} createExportMask START...", storage.getSerialNumber());
    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));
        ExportOperationContext context = new VnxExportOperationContext();
        // Prime the context object
        taskCompleter.updateWorkflowStepContext(context);
        // performing this validation as a precaution.
        if (anyInitiatorsAreInAStorageGroup(storage, initiatorList)) {
            ServiceError error = SmisException.errors.anExistingSGAlreadyHasTheInitiators(exportMaskURI.toString(), Joiner.on(',').join(initiatorList));
            taskCompleter.error(_dbClient, error);
            return;
        }
        CIMObjectPath[] protocolControllers = createOrGrowStorageGroup(storage, exportMaskURI, volumeURIHLUs, null, targetURIList, taskCompleter);
        if (protocolControllers != null) {
            ExportOperationContext.insertContextOperation(taskCompleter, VnxExportOperationContext.OPERATION_CREATE_STORAGE_GROUP, exportMaskURI);
            _log.debug("createExportMask succeeded.");
            for (CIMObjectPath protocolController : protocolControllers) {
                _helper.setProtocolControllerNativeId(exportMaskURI, protocolController);
            }
            CimConnection cimConnection = _helper.getConnection(storage);
            createOrGrowStorageGroup(storage, exportMaskURI, null, initiatorList, targetURIList, taskCompleter);
            // 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);
            modifyClarPrivileges(storage, initiatorList);
            taskCompleter.ready(_dbClient);
        } else {
            _log.debug("createExportMask failed. No protocol controller created.");
            ServiceError error = DeviceControllerException.errors.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.getSerialNumber());
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ExportOperationContext(com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext) CIMObjectPath(javax.cim.CIMObjectPath) CimConnection(com.emc.storageos.cimadapter.connections.cim.CimConnection) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) WBEMException(javax.wbem.WBEMException) SmisException(com.emc.storageos.volumecontroller.impl.smis.SmisException)

Example 29 with CimConnection

use of com.emc.storageos.cimadapter.connections.cim.CimConnection in project coprhd-controller by CoprHD.

the class VnxExportOperations method updateStorageGroupPolicyAndLimits.

/**
 * Updates Auto-tiering policy for the given volumes.
 *
 * @param storage
 *            the storage
 * @param exportMask
 *            the export mask
 * @param volumeURIs
 *            the volume uris
 * @param newVirtualPool
 *            the new virtual pool where policy name can be obtained
 * @param rollback
 *            boolean to know if it is called as a roll back step from workflow.
 * @param taskCompleter
 * @throws Exception
 *             the exception
 */
@Override
public void updateStorageGroupPolicyAndLimits(StorageSystem storage, ExportMask exportMask, List<URI> volumeURIs, VirtualPool newVirtualPool, boolean rollback, TaskCompleter taskCompleter) throws Exception {
    String message = rollback ? ("updateAutoTieringPolicy" + "(rollback)") : ("updateAutoTieringPolicy");
    _log.info("{} {} START...", storage.getSerialNumber(), message);
    _log.info("{} : volumeURIs: {}", message, volumeURIs);
    try {
        String newPolicyName = ControllerUtils.getFastPolicyNameFromVirtualPool(_dbClient, storage, newVirtualPool);
        _log.info("{} : AutoTieringPolicy: {}", message, newPolicyName);
        List<Volume> volumes = _dbClient.queryObject(Volume.class, volumeURIs);
        /**
         * get tier methodology for policy name
         * volume has tier methodology as '4' when no policy set (START_HIGH_THEN_AUTO_TIER).
         *
         * For VNX, Policy is set on Volumes during creation.
         */
        int storageTierMethodologyId = DEFAULT_STORAGE_TIER_METHODOLOGY;
        if (!Constants.NONE.equalsIgnoreCase(newPolicyName)) {
            storageTierMethodologyId = getStorageTierMethodologyFromPolicyName(newPolicyName);
        }
        // Build list of native ids
        Set<String> nativeIds = new HashSet<String>();
        for (Volume volume : volumes) {
            nativeIds.add(volume.getNativeId());
        }
        _log.info("Native Ids of Volumes: {}", nativeIds);
        CimConnection connection = _helper.getConnection(storage);
        WBEMClient client = connection.getCimClient();
        // CIMObjectPath replicationSvc = _cimPath.getControllerReplicationSvcPath(storage);
        String[] memberNames = nativeIds.toArray(new String[nativeIds.size()]);
        CIMObjectPath[] volumePaths = _cimPath.getVolumePaths(storage, memberNames);
        CIMProperty[] inArgs = _helper.getModifyStorageTierMethodologyIdInputArguments(storageTierMethodologyId);
        for (CIMObjectPath volumeObject : volumePaths) {
            if (_helper.getVolumeStorageTierMethodologyId(storage, volumeObject) == storageTierMethodologyId) {
                _log.info("Current and new Storage Tier Methodology Ids are same '{}'." + " No need to update it on Volume Object Path {}.", storageTierMethodologyId, volumeObject);
            } else {
                CIMInstance modifiedSettingInstance = new CIMInstance(volumeObject, inArgs);
                _log.info("Updating Storage Tier Methodology ({}) on Volume Object Path {}.", storageTierMethodologyId, volumeObject);
                client.modifyInstance(modifiedSettingInstance, SmisConstants.PS_EMC_STORAGE_TIER_METHODOLOGY);
            }
        }
        taskCompleter.ready(_dbClient);
    } catch (Exception e) {
        String errMsg = String.format("An error occurred while updating Auto-tiering policy for Volumes %s", volumeURIs);
        _log.error(errMsg, e);
        ServiceError serviceError = DeviceControllerException.errors.jobFailedMsg(errMsg, e);
        taskCompleter.error(_dbClient, serviceError);
    }
    _log.info("{} {} END...", storage.getSerialNumber(), message);
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) CIMObjectPath(javax.cim.CIMObjectPath) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) CIMInstance(javax.cim.CIMInstance) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) WBEMException(javax.wbem.WBEMException) SmisException(com.emc.storageos.volumecontroller.impl.smis.SmisException) Volume(com.emc.storageos.db.client.model.Volume) CIMProperty(javax.cim.CIMProperty) CimConnection(com.emc.storageos.cimadapter.connections.cim.CimConnection) WBEMClient(javax.wbem.client.WBEMClient) HashSet(java.util.HashSet)

Example 30 with CimConnection

use of com.emc.storageos.cimadapter.connections.cim.CimConnection in project coprhd-controller by CoprHD.

the class VnxExportOperations method addVolumes.

/*
     * (non-Javadoc)
     *
     * @see
     * com.emc.storageos.volumecontroller.impl.smis.ExportMaskOperations#addVolume(com.emc.storageos.db.client.model.
     * StorageSystem, java.net.URI, com.emc.storageos.volumecontroller.impl.VolumeURIHLU[],
     * com.emc.storageos.volumecontroller.TaskCompleter)
     */
@Override
public void addVolumes(StorageSystem storage, URI exportMaskURI, VolumeURIHLU[] volumeURIHLUs, List<Initiator> initiatorList, TaskCompleter taskCompleter) throws DeviceControllerException {
    _log.info("{} addVolumes START...", storage.getSerialNumber());
    try {
        _log.info("addVolumes: Export mask id: {}", exportMaskURI);
        _log.info("addVolumes: volume-HLU pairs: {}", Joiner.on(',').join(volumeURIHLUs));
        if (initiatorList != null) {
            _log.info("addVolumes: initiators impacted: {}", Joiner.on(',').join(initiatorList));
        }
        ExportOperationContext context = new VnxExportOperationContext();
        // Prime the context object
        taskCompleter.updateWorkflowStepContext(context);
        // Determine if the volume is already in the masking view.
        // If so, log and remove from volumes we need to process.
        ExportMask mask = _dbClient.queryObject(ExportMask.class, exportMaskURI);
        CIMInstance maskingView = _helper.getLunMaskingProtocolController(storage, mask);
        Map<String, Integer> discoveredVolumes = new HashMap<String, Integer>();
        if (maskingView != null) {
            WBEMClient client = _helper.getConnection(storage).getCimClient();
            // Get volumes for the masking instance
            discoveredVolumes = _helper.getVolumesFromLunMaskingInstance(client, maskingView);
        }
        List<VolumeURIHLU> removeURIs = new ArrayList<>();
        for (VolumeURIHLU volumeUriHLU : volumeURIHLUs) {
            BlockObject bo = BlockObject.fetch(_dbClient, volumeUriHLU.getVolumeURI());
            if (discoveredVolumes.keySet().contains(bo.getNativeId())) {
                _log.info("Found volume {} is already associated with masking view.  Assuming this is from a previous operation.", bo.getLabel());
                removeURIs.add(volumeUriHLU);
            }
        }
        // Create the new array of volumes that don't exist yet in the masking view.
        VolumeURIHLU[] addVolumeURIHLUs = new VolumeURIHLU[volumeURIHLUs.length - removeURIs.size()];
        int index = 0;
        for (VolumeURIHLU volumeUriHLU : volumeURIHLUs) {
            if (!removeURIs.contains(volumeUriHLU)) {
                addVolumeURIHLUs[index++] = volumeUriHLU;
            }
        }
        CIMObjectPath[] protocolControllers = createOrGrowStorageGroup(storage, exportMaskURI, addVolumeURIHLUs, null, null, taskCompleter);
        CimConnection cimConnection = _helper.getConnection(storage);
        ExportMaskOperationsHelper.populateDeviceNumberFromProtocolControllers(_dbClient, cimConnection, exportMaskURI, addVolumeURIHLUs, protocolControllers, taskCompleter);
        // Test mechanism to invoke a failure. No-op on production systems.
        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_002);
        taskCompleter.ready(_dbClient);
    } catch (Exception e) {
        _log.error("Unexpected error: addVolumes failed.", e);
        ServiceError error = DeviceControllerErrors.smis.methodFailed("addVolumes", e.getMessage());
        taskCompleter.error(_dbClient, error);
    }
    _log.info("{} addVolumes END...", storage.getSerialNumber());
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) HashMap(java.util.HashMap) ExportMask(com.emc.storageos.db.client.model.ExportMask) ArrayList(java.util.ArrayList) CIMObjectPath(javax.cim.CIMObjectPath) CIMInstance(javax.cim.CIMInstance) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) WBEMException(javax.wbem.WBEMException) SmisException(com.emc.storageos.volumecontroller.impl.smis.SmisException) ExportOperationContext(com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext) CimConnection(com.emc.storageos.cimadapter.connections.cim.CimConnection) WBEMClient(javax.wbem.client.WBEMClient) BlockObject(com.emc.storageos.db.client.model.BlockObject) VolumeURIHLU(com.emc.storageos.volumecontroller.impl.VolumeURIHLU)

Aggregations

CimConnection (com.emc.storageos.cimadapter.connections.cim.CimConnection)45 WBEMException (javax.wbem.WBEMException)24 WBEMClient (javax.wbem.client.WBEMClient)24 CIMObjectPath (javax.cim.CIMObjectPath)20 CIMInstance (javax.cim.CIMInstance)16 IOException (java.io.IOException)13 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)12 ArrayList (java.util.ArrayList)12 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)10 ConnectionManagerException (com.emc.storageos.cimadapter.connections.ConnectionManagerException)9 Volume (com.emc.storageos.db.client.model.Volume)8 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)8 SmisException (com.emc.storageos.volumecontroller.impl.smis.SmisException)6 CIMArgument (javax.cim.CIMArgument)6 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)5 URI (java.net.URI)5 BlockObject (com.emc.storageos.db.client.model.BlockObject)4 StoragePool (com.emc.storageos.db.client.model.StoragePool)4 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)3 ExportMask (com.emc.storageos.db.client.model.ExportMask)3