Search in sources :

Example 1 with ConnectionManagerException

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

the class CimStorageMonitor method stopMonitoring.

/**
 * Stops event monitoring for the passed storage device by removing the
 * connection to the SMI-S provider for storage device.
 *
 * @param storageDevice A reference to the storage device.
 *
 * @throws StorageMonitorException When an error occurs stopping monitoring
 *             for the device.
 */
@Override
public void stopMonitoring(StorageSystem storageDevice) throws StorageMonitorException {
    s_logger.debug("Disconnecting storage from event monitoring.");
    // Verify we got a non-null storage device.
    if (storageDevice == null) {
        throw new StorageMonitorException("Passed storage device is null");
    }
    s_logger.info("Attempting to disconnect storage provider {} from event monitoring.", storageDevice.getSmisProviderIP());
    // Verify the CIM connection manager reference
    if (_cimConnectionManager == null) {
        throw new StorageMonitorException("CIM adapter connection manager reference is null.");
    }
    // passed provider is currently being managed.
    try {
        _cimConnectionManager.removeConnection(storageDevice.getSmisProviderIP(), storageDevice.getSmisPortNumber());
    } catch (ConnectionManagerException cme) {
        throw new StorageMonitorException(MessageFormatter.format("Failed attempting to remove the connection to storage provider {}", storageDevice.getSmisProviderIP()).getMessage(), cme);
    }
    s_logger.info("Connection to storage provider {} was removed.", storageDevice.getSmisProviderIP());
}
Also used : StorageMonitorException(com.emc.storageos.volumecontroller.StorageMonitorException) ConnectionManagerException(com.emc.storageos.cimadapter.connections.ConnectionManagerException)

Example 2 with ConnectionManagerException

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

the class CIMConnectionFactory method refreshConnections.

/**
 * Refresh the SMISProvider connections. This will be called after loading
 * the SMIS Provider information from DB.
 *
 * @param smisproviderList
 *            : List of SMISProvider.
 * @return List<URI> : returns the list of active provider URIs.
 */
public List<URI> refreshConnections(final List<StorageProvider> smisProviderList) {
    _log.debug("In refreshConnections()");
    List<URI> activeProviderURIList = new ArrayList<URI>();
    for (StorageProvider smisProvider : smisProviderList) {
        try {
            CimConnection connection = getConnection(smisProvider.getIPAddress(), smisProvider.getPortNumber().toString());
            if (null == connection) {
                _log.error("No CIMOM connection found for ip/port {}", ConnectionManager.generateConnectionCacheKey(smisProvider.getIPAddress(), smisProvider.getPortNumber()));
                // No need to add connection, as getConnection() called from any thread would create it.
                continue;
            }
            validateProviderConnection(smisProvider, connection, activeProviderURIList);
        } catch (final DatabaseException ex) {
            _log.error("DatabaseException occurred while fetching the storageDevice for {} due to ", smisProvider.getId(), ex);
        } catch (final ConnectionManagerException ex) {
            _log.error("No CIMOM Connection found for ipaddress due to ", ex);
        } catch (final Exception ex) {
            _log.error("Exception while refreshing connections due to ", ex);
        }
    }
    return activeProviderURIList;
}
Also used : ArrayList(java.util.ArrayList) CimConnection(com.emc.storageos.cimadapter.connections.cim.CimConnection) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) ConnectionManagerException(com.emc.storageos.cimadapter.connections.ConnectionManagerException) URI(java.net.URI) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) WBEMException(javax.wbem.WBEMException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) ConnectionManagerException(com.emc.storageos.cimadapter.connections.ConnectionManagerException) IOException(java.io.IOException)

Example 3 with ConnectionManagerException

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

the class CimListener method getClientCertificate.

/**
 * @param connectionInfo
 * @throws KeyStoreException
 * @throws NoSuchAlgorithmException
 * @throws CertificateException
 * @throws IOException
 * @throws KeyManagementException
 * @throws ConnectionManagerException
 */
public void getClientCertificate(CimConnectionInfo connectionInfo) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException, KeyManagementException, ConnectionManagerException {
    char[] passphrase;
    String passphraseStr = "changeit";
    passphrase = passphraseStr.toCharArray();
    KeyStore ks = getTrustStore(_trustStoreLocation, passphrase);
    SSLContext context = SSLContext.getInstance("TLS");
    TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    tmf.init(ks);
    X509TrustManager defaultTrustManager = (X509TrustManager) tmf.getTrustManagers()[0];
    TrustedCertManager tm = new TrustedCertManager(defaultTrustManager);
    s_logger.debug("Created trust manager");
    context.init(null, new TrustManager[] { tm }, null);
    SSLSocketFactory factory = context.getSocketFactory();
    String smiHost = connectionInfo.getHost();
    int smiPort = defaultSMISSSLPort;
    if (connectionInfo.getUseSSL()) {
        smiPort = connectionInfo.getPort();
    }
    s_logger.debug("Opening connection to {}:{}", smiHost, smiPort);
    SSLSocket socket = (SSLSocket) factory.createSocket(smiHost, smiPort);
    socket.setSoTimeout(10000);
    try {
        s_logger.debug("Starting SSL negotiation");
        socket.startHandshake();
        socket.close();
        socket = null;
    } catch (SSLException e) {
    // We ignore this exception. What we really need is the SSL
    // handshake results.
    } finally {
        if (socket != null) {
            socket.close();
        }
    }
    X509Certificate[] chain = tm.chain;
    if (chain == null) {
        s_logger.debug("Error getting client certificate chain");
        throw new ConnectionManagerException("Error getting client certificate chain");
    }
    X509Certificate cert0 = chain[0];
    String alias0 = smiHost + "-" + "1";
    ks.setCertificateEntry(alias0, cert0);
    s_logger.debug("Added a certificate to the truststore with alias: {}", alias0);
    File trustStoreOut = new File(_trustStoreLocation);
    if (trustStoreOut.exists()) {
        // Save the original truststore
        File trustStoreOutSaved = new File(_trustStoreLocation + "~");
        if (trustStoreOutSaved.exists()) {
            trustStoreOut.delete();
        }
        trustStoreOut.renameTo(trustStoreOutSaved);
    }
    OutputStream out2 = new FileOutputStream(_trustStoreLocation);
    ks.store(out2, passphrase);
    out2.close();
    s_logger.debug("Created/updated the trust store: {}", _trustStoreLocation);
    restart();
}
Also used : SSLSocket(javax.net.ssl.SSLSocket) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) SSLContext(javax.net.ssl.SSLContext) ConnectionManagerException(com.emc.storageos.cimadapter.connections.ConnectionManagerException) KeyStore(java.security.KeyStore) SSLException(javax.net.ssl.SSLException) X509Certificate(java.security.cert.X509Certificate) X509TrustManager(javax.net.ssl.X509TrustManager) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) FileOutputStream(java.io.FileOutputStream) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) File(java.io.File)

Example 4 with ConnectionManagerException

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

the class CimSubscriptionManager method createHandler.

/**
 * Creates an indication handler in the CIMOM from the indication listener's
 * configuration.
 *
 * The WBEM listener interface does not provide a mechanism for getting the
 * source IP address of a received indication. To match indications with
 * connections, the connection name is put in the handler's destination URL
 * as the path component.
 *
 * @return the CIM object path of the handler
 * @throws WBEMException, ConnectionManagerException
 */
private CIMObjectPath createHandler() throws WBEMException, ConnectionManagerException {
    CimListener listener = _connection.getIndicationListener();
    URL listenerURL = listener.getURL();
    if (listenerURL == null) {
        // Verify that the listener URL has been set.
        throw new ConnectionManagerException("Listener URL is not set, Subscription handler cannot be set.");
    }
    StringBuffer handlerNameBuff = new StringBuffer();
    handlerNameBuff.append(_subscriptionsIdentifier);
    handlerNameBuff.append(CimConstants.PATH_NAME_DELIMITER);
    handlerNameBuff.append(listenerURL.getHost());
    handlerNameBuff.append(CimConstants.PATH_NAME_DELIMITER);
    handlerNameBuff.append(listenerURL.getPort());
    String handlerName = handlerNameBuff.toString();
    CIMProperty<?> destinationProperty = new CIMProperty<String>(CimConstants.HANLDER_PROP_DESTINATION, CIMDataType.STRING_T, listenerURL.toString() + '/' + _connection.getConnectionName());
    CIMProperty<?>[] handlerProperties = new CIMProperty[] { destinationProperty };
    return createInstance(CimConstants.CIM_HANDLER_NAME, handlerName, handlerProperties);
}
Also used : CIMProperty(javax.cim.CIMProperty) ConnectionManagerException(com.emc.storageos.cimadapter.connections.ConnectionManagerException) URL(java.net.URL)

Example 5 with ConnectionManagerException

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

the class CimStorageMonitor method startMonitoring.

/**
 * Starts event monitoring for the passed storage device by creating a
 * connection to the SMI-S provider for the storage device.
 *
 * @param storageDevice A reference to the storage device.
 *
 * @throws StorageMonitorException When an error occurs monitoring the
 *             device.
 */
@Override
public void startMonitoring(StorageSystem storageDevice, WorkPool.Work work) throws StorageMonitorException {
    s_logger.debug("Connecting storage for event monitoring. {}", storageDevice.getSystemType());
    // Verify we got a non-null storage device.
    if (storageDevice == null) {
        throw new StorageMonitorException("Passed storage device is null");
    }
    s_logger.info("Attempting to connect to storage provider {} for event monitoring.", storageDevice.getSmisProviderIP());
    // Verify the CIM connection manager reference.
    if (_cimConnectionManager == null) {
        throw new StorageMonitorException("CIM adapter connection manager reference is null.");
    }
    // Create the CIM connection info for the connection.
    CimConnectionInfo connectionInfo = new CimConnectionInfo();
    connectionInfo.setHost(storageDevice.getSmisProviderIP());
    connectionInfo.setPort(storageDevice.getSmisPortNumber());
    connectionInfo.setUser(storageDevice.getSmisUserName());
    connectionInfo.setPassword(storageDevice.getSmisPassword());
    connectionInfo.setInteropNS(CimConstants.DFLT_CIM_CONNECTION_INTEROP_NS);
    connectionInfo.setUseSSL(storageDevice.getSmisUseSSL());
    // Set the type of connection to be created.
    connectionInfo.setType(getConnectionTypeForDevice(storageDevice.getSystemType()));
    // Set the implementation namespace for this type of storage device
    connectionInfo.setImplNS(getImplNamespaceForDevice(storageDevice.getSystemType()));
    // connection is not already managed.
    try {
        _cimConnectionManager.addConnection(connectionInfo);
    } catch (ConnectionManagerException cme) {
        throw new StorageMonitorException(MessageFormatter.format("Failed attempting to establish a connection to storage provider {}.", storageDevice.getSmisProviderIP()).getMessage(), cme);
    }
    s_logger.info("Connection established for storage provider {}.", storageDevice.getSmisProviderIP());
}
Also used : StorageMonitorException(com.emc.storageos.volumecontroller.StorageMonitorException) ConnectionManagerException(com.emc.storageos.cimadapter.connections.ConnectionManagerException) CimConnectionInfo(com.emc.storageos.cimadapter.connections.cim.CimConnectionInfo)

Aggregations

ConnectionManagerException (com.emc.storageos.cimadapter.connections.ConnectionManagerException)8 CimConnection (com.emc.storageos.cimadapter.connections.cim.CimConnection)4 CimConnectionInfo (com.emc.storageos.cimadapter.connections.cim.CimConnectionInfo)3 StorageProvider (com.emc.storageos.db.client.model.StorageProvider)2 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)2 StorageMonitorException (com.emc.storageos.volumecontroller.StorageMonitorException)2 IOException (java.io.IOException)2 WBEMException (javax.wbem.WBEMException)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 URI (java.net.URI)1 URL (java.net.URL)1 KeyStore (java.security.KeyStore)1 X509Certificate (java.security.cert.X509Certificate)1 ArrayList (java.util.ArrayList)1 CIMProperty (javax.cim.CIMProperty)1 SSLContext (javax.net.ssl.SSLContext)1 SSLException (javax.net.ssl.SSLException)1 SSLSocket (javax.net.ssl.SSLSocket)1