Search in sources :

Example 41 with StorageProvider

use of com.emc.storageos.db.client.model.StorageProvider in project coprhd-controller by CoprHD.

the class VPlexDeviceController method validateStorageProviderConnection.

/**
 * Validate a VPLEX Storage Provider connection.
 *
 * @param ipAddress
 *            the Storage Provider's IP address
 * @param portNumber
 *            the Storage Provider's IP port
 *
 * @return true if the Storage Provider connection is valid
 */
@Override
public boolean validateStorageProviderConnection(String ipAddress, Integer portNumber) {
    boolean connectionValid;
    try {
        // look up the provider by ip address and port
        StringBuffer providerId = new StringBuffer(ipAddress).append(HYPHEN_OPERATOR).append(portNumber);
        URIQueryResultList providerUriList = new URIQueryResultList();
        _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getStorageProviderByProviderIDConstraint(providerId.toString()), providerUriList);
        if (providerUriList.iterator().hasNext()) {
            StorageProvider provider = _dbClient.queryObject(StorageProvider.class, providerUriList.iterator().next());
            VPlexApiClient client = getVPlexAPIClient(_vplexApiFactory, provider, _dbClient);
            if (client != null) {
                client.verifyConnectivity();
                // if we got this far without blowing up, then the connection is valid
                _log.info("VPLEX Storage Provider connection at {} is valid.", providerId);
                connectionValid = true;
            } else {
                _log.error("a VplexApiClient could not be created for provider {}.", provider.getLabel());
                connectionValid = false;
            }
        } else {
            _log.error("Could not find a VPLEX Storage Provider " + "with address-port {} in ViPR.", providerId);
            connectionValid = false;
        }
    } catch (Exception ex) {
        _log.error("Connection to VPLEX Storage Provider {} is invalid.", ipAddress, ex);
        connectionValid = false;
    }
    return connectionValid;
}
Also used : VPlexApiClient(com.emc.storageos.vplex.api.VPlexApiClient) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) VPlexApiException(com.emc.storageos.vplex.api.VPlexApiException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 42 with StorageProvider

use of com.emc.storageos.db.client.model.StorageProvider in project coprhd-controller by CoprHD.

the class VPlexDeviceController method refreshConnectionStatusForAllVPlexManagementServers.

/**
 * Refreshes the connection status for all VPLEX management servers.
 *
 * @return The list of those to which a connection was successful.
 */
public List<URI> refreshConnectionStatusForAllVPlexManagementServers() {
    List<URI> activeMgmntServers = new ArrayList<URI>();
    List<StorageProvider> vplexMnmgtServers = CustomQueryUtility.getActiveStorageProvidersByInterfaceType(_dbClient, StorageProvider.InterfaceType.vplex.name());
    for (StorageProvider vplexMnmgtServer : vplexMnmgtServers) {
        try {
            VPlexApiClient client = getVPlexAPIClient(_vplexApiFactory, vplexMnmgtServer, _dbClient);
            client.verifyConnectivity();
            activeMgmntServers.add(vplexMnmgtServer.getId());
            vplexMnmgtServer.setConnectionStatus(StorageProvider.ConnectionStatus.CONNECTED.toString());
        } catch (Exception e) {
            _log.warn("Can't connect to VPLEX management server {}", vplexMnmgtServer.getIPAddress());
            vplexMnmgtServer.setConnectionStatus(StorageProvider.ConnectionStatus.NOTCONNECTED.toString());
        } finally {
            _dbClient.updateObject(vplexMnmgtServer);
        }
    }
    return activeMgmntServers;
}
Also used : VPlexApiClient(com.emc.storageos.vplex.api.VPlexApiClient) ArrayList(java.util.ArrayList) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) VPlexApiException(com.emc.storageos.vplex.api.VPlexApiException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 43 with StorageProvider

use of com.emc.storageos.db.client.model.StorageProvider in project coprhd-controller by CoprHD.

the class XIVRestOperationsHelper method getRestClient.

/**
 * Gets REST Client instance for a StorageSystem
 *
 * @param storage
 *            StorageSystem instance
 * @return XIVRESTExportOperations instance
 */
private XIVRestClient getRestClient(StorageSystem storage) {
    XIVRestClient restClient = null;
    StorageProvider provider = _dbClient.queryObject(StorageProvider.class, storage.getActiveProviderURI());
    String providerUser = provider.getSecondaryUsername();
    String providerPassword = provider.getSecondaryPassword();
    String providerURL = provider.getSecondaryURL();
    if (StringUtils.isNotEmpty(providerURL) && StringUtils.isNotEmpty(providerPassword) && StringUtils.isNotEmpty(providerUser)) {
        restClient = (XIVRestClient) _restClientFactory.getRESTClient(URI.create(providerURL), providerUser, providerPassword);
    }
    return restClient;
}
Also used : XIVRestClient(com.emc.storageos.xiv.api.XIVRestClient) StorageProvider(com.emc.storageos.db.client.model.StorageProvider)

Example 44 with StorageProvider

use of com.emc.storageos.db.client.model.StorageProvider in project coprhd-controller by CoprHD.

the class XtremIOProvUtils method refreshXtremeIOConnections.

/**
 * Refresh the XIO Providers & its client connections.
 *
 * @param xioProviderList
 *            the XIO provider list
 * @param dbClient
 *            the db client
 * @return the list of active providers
 */
public static List<URI> refreshXtremeIOConnections(final List<StorageProvider> xioProviderList, DbClient dbClient, XtremIOClientFactory xtremioRestClientFactory) {
    List<URI> activeProviders = new ArrayList<URI>();
    for (StorageProvider provider : xioProviderList) {
        try {
            // For providers without version/model, let it try connecting V1 client to update connection status
            XtremIOClient xioClient = (XtremIOClient) xtremioRestClientFactory.getRESTClient(URI.create(XtremIOConstants.getXIOBaseURI(provider.getIPAddress(), provider.getPortNumber())), provider.getUserName(), provider.getPassword(), provider.getVersionString(), true);
            if (null != xioClient.getXtremIOXMSVersion()) {
                // Now update provider status based on connection live check.
                provider.setConnectionStatus(StorageProvider.ConnectionStatus.CONNECTED.toString());
                activeProviders.add(provider.getId());
            } else {
                _log.info("XIO Connection is not active {}", provider.getProviderID());
                provider.setConnectionStatus(StorageProvider.ConnectionStatus.NOTCONNECTED.toString());
            }
        } catch (Exception ex) {
            _log.error("Exception occurred while validating XIO client for {}", provider.getProviderID(), ex);
            provider.setConnectionStatus(StorageProvider.ConnectionStatus.NOTCONNECTED.toString());
        } finally {
            dbClient.updateObject(provider);
        }
    }
    return activeProviders;
}
Also used : ArrayList(java.util.ArrayList) XtremIOClient(com.emc.storageos.xtremio.restapi.XtremIOClient) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) URI(java.net.URI) XtremIOApiException(com.emc.storageos.xtremio.restapi.errorhandling.XtremIOApiException)

Example 45 with StorageProvider

use of com.emc.storageos.db.client.model.StorageProvider in project coprhd-controller by CoprHD.

the class CinderCommunicationInterface method discover.

/**
 * Get volume types, and create a storage pool for each volume type
 */
@Override
public void discover(AccessProfile accessProfile) throws BaseCollectionException {
    if ((null != accessProfile.getnamespace()) && (accessProfile.getnamespace().equals(StorageSystem.Discovery_Namespaces.UNMANAGED_VOLUMES.toString()))) {
        discoverUnManagedVolumes(accessProfile);
    } else {
        _logger.info("Discovery started for system {}", accessProfile.getSystemId());
        List<StoragePool> newPools = new ArrayList<StoragePool>();
        List<StoragePool> updatePools = new ArrayList<StoragePool>();
        List<StoragePool> allPools = new ArrayList<StoragePool>();
        String token = "";
        StorageSystem system = null;
        StorageProvider provider = null;
        String detailedStatusMessage = "Unknown Status";
        try {
            String hostName = null;
            String restuserName = null;
            String restPassword = null;
            String restBaseUri = null;
            String tenantName = null;
            String oldToken = null;
            String tenantId = null;
            system = _dbClient.queryObject(StorageSystem.class, accessProfile.getSystemId());
            system.setReachableStatus(true);
            // first add storage ports if necessary
            addPorts(system);
            // now do the pool discovery
            URI providerUri = system.getActiveProviderURI();
            provider = _dbClient.queryObject(StorageProvider.class, providerUri);
            if (null != provider.getKeys()) {
                StringMap providerKeys = provider.getKeys();
                oldToken = providerKeys.get(CinderConstants.KEY_CINDER_REST_TOKEN);
                hostName = providerKeys.get(CinderConstants.KEY_CINDER_HOST_NAME);
                restuserName = providerKeys.get(CinderConstants.KEY_CINDER_REST_USER);
                restPassword = providerKeys.get(CinderConstants.KEY_CINDER_REST_PASSWORD);
                restBaseUri = providerKeys.get(CinderConstants.KEY_CINDER_REST_URI_BASE);
                tenantName = providerKeys.get(CinderConstants.KEY_CINDER_TENANT_NAME);
                tenantId = providerKeys.get(CinderConstants.KEY_CINDER_TENANT_ID);
            }
            if (null == endPointInfo) {
                endPointInfo = new CinderEndPointInfo(hostName, restuserName, restPassword, tenantName);
                if (restBaseUri.startsWith(CinderConstants.HTTP_URL)) {
                    endPointInfo.setCinderBaseUriHttp(restBaseUri);
                } else {
                    endPointInfo.setCinderBaseUriHttps(restBaseUri);
                }
                // Always set the token and tenant id, when new instance is created
                endPointInfo.setCinderToken(oldToken);
                endPointInfo.setCinderTenantId(tenantId);
            }
            CinderApi api = _cinderApiFactory.getApi(providerUri, endPointInfo);
            _logger.debug("discover : Got the cinder api factory for provider with id: {}", providerUri);
            // check if the cinder is authenticated and if the token is valid
            if (null == oldToken || (isTokenExpired(oldToken))) {
                // This means, authentication is required, go and fetch the token
                token = api.getAuthToken(restBaseUri + "/tokens");
                if (null != token) {
                    _logger.debug("Got new token : {}", token);
                    // update the token in the provider
                    provider.addKey(CinderConstants.KEY_CINDER_REST_TOKEN, token);
                    provider.addKey(CinderConstants.KEY_CINDER_TENANT_ID, endPointInfo.getCinderTenantId());
                }
            } else {
                token = oldToken;
                _logger.debug("Using the old token : {}", token);
            }
            if (token.length() > 1) {
                // Now get the number of volume types
                VolumeTypes types = api.getVolumeTypes();
                if (types != null) {
                    _logger.info("Got {} Volume Type(s)", types.volume_types.length);
                    boolean isDefaultStoragePoolCreated = false;
                    for (int i = 0; i < types.volume_types.length; i++) {
                        boolean isNew = false;
                        String poolName = types.volume_types[i].name;
                        String nativeGuid = types.volume_types[i].id;
                        _logger.info("Storage Pool name = {}, id = {}", poolName, nativeGuid);
                        // Now find association with storage system
                        Map<String, String> extra_specs = types.volume_types[i].extra_specs;
                        String system_title = extra_specs.get(VOLUME_BACKEND_NAME);
                        boolean isThickPool = Boolean.parseBoolean(extra_specs.get(VIPR_THICK_POOL));
                        // If no volume backend name, use default
                        if (system_title == null) {
                            system_title = CinderConstants.DEFAULT;
                        }
                        if (system.getNativeGuid().toUpperCase().contains(system_title.toUpperCase())) {
                            // Check if volume type belongs to the default storage system
                            if (system.getNativeGuid().toUpperCase().startsWith(CinderConstants.DEFAULT)) {
                                isDefaultStoragePoolCreated = true;
                            }
                            // do the association
                            _logger.info("Found association between system {} and pool {}", system_title, poolName);
                            StoragePool pool = checkPoolExistsInDB(nativeGuid);
                            if (null == pool) {
                                isNew = true;
                                pool = createPoolforStorageSystem(system, nativeGuid, poolName, isThickPool);
                                newPools.add(pool);
                            }
                            pool.setPoolName(poolName);
                            pool.setCompatibilityStatus(CompatibilityStatus.COMPATIBLE.name());
                            pool.setDiscoveryStatus(DiscoveryStatus.VISIBLE.name());
                            if (!isNew) {
                                updatePools.add(pool);
                            }
                        } else {
                            _logger.info("Pool {} doesn't belong to storage system {}", poolName, system.getLabel());
                        }
                    }
                    // create default storage pool for storage system
                    if (system.getNativeGuid().toUpperCase().startsWith(CinderConstants.DEFAULT) && !isDefaultStoragePoolCreated) {
                        _logger.debug("Creating defual pool for default storage system");
                        String nativeGuid = "DefaultPool";
                        StoragePool pool = checkPoolExistsInDB(nativeGuid);
                        String poolName = "DefaultPool";
                        if (null != pool) {
                            updatePools.add(pool);
                        } else {
                            pool = createPoolforStorageSystem(system, nativeGuid, poolName, false);
                            newPools.add(pool);
                        }
                        pool.setPoolName(poolName);
                        pool.setCompatibilityStatus(CompatibilityStatus.COMPATIBLE.name());
                        pool.setDiscoveryStatus(DiscoveryStatus.VISIBLE.name());
                    }
                    StoragePoolAssociationHelper.setStoragePoolVarrays(system.getId(), newPools, _dbClient);
                    allPools.addAll(newPools);
                    allPools.addAll(updatePools);
                    StringBuffer errorMessage = new StringBuffer();
                    ImplicitPoolMatcher.matchModifiedStoragePoolsWithAllVpool(allPools, _dbClient, _coordinator, accessProfile.getSystemId(), errorMessage);
                    _logger.info("New pools size: {}", newPools.size());
                    _logger.info("updatePools size: {}", updatePools.size());
                    DiscoveryUtils.checkStoragePoolsNotVisible(allPools, _dbClient, system.getId());
                    _dbClient.createObject(newPools);
                    _dbClient.persistObject(updatePools);
                    // discovery succeeds
                    detailedStatusMessage = String.format("Discovery completed successfully for OpenStack: %s", accessProfile.getSystemId());
                } else /* if types */
                {
                    _logger.error("Error in getting volume types from cinder");
                }
            } else /* if token length */
            {
                _logger.error("Error in getting token from keystone");
            }
        } catch (Exception e) {
            if (null != system) {
                cleanupDiscovery(system);
            }
            detailedStatusMessage = String.format("Discovery failed for Storage System: %s because %s", system.toString(), e.getLocalizedMessage());
            _logger.error(detailedStatusMessage, e);
            throw new CinderColletionException(false, ServiceCode.DISCOVERY_ERROR, null, detailedStatusMessage, null, null);
        } finally {
            try {
                if (system != null) {
                    system.setLastDiscoveryStatusMessage(detailedStatusMessage);
                    _dbClient.persistObject(system);
                }
                // persist the provider
                if (null != provider) {
                    _dbClient.persistObject(provider);
                }
            } catch (DatabaseException e) {
                _logger.error("Failed to persist cinder storage system to Database, Reason: {}", e.getMessage(), e);
            }
        }
        _logger.info("Discovery Ended for system {}", accessProfile.getSystemId());
    }
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) StoragePool(com.emc.storageos.db.client.model.StoragePool) ArrayList(java.util.ArrayList) CinderApi(com.emc.storageos.cinder.api.CinderApi) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) URI(java.net.URI) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) IOException(java.io.IOException) CinderColletionException(com.emc.storageos.volumecontroller.impl.cinder.CinderColletionException) VolumeTypes(com.emc.storageos.cinder.model.VolumeTypes) CinderEndPointInfo(com.emc.storageos.cinder.CinderEndPointInfo) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) CinderColletionException(com.emc.storageos.volumecontroller.impl.cinder.CinderColletionException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Aggregations

StorageProvider (com.emc.storageos.db.client.model.StorageProvider)97 URI (java.net.URI)44 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)26 ArrayList (java.util.ArrayList)24 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)23 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)19 Produces (javax.ws.rs.Produces)19 IOException (java.io.IOException)18 StringSet (com.emc.storageos.db.client.model.StringSet)17 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)15 Path (javax.ws.rs.Path)15 Consumes (javax.ws.rs.Consumes)11 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)10 MapStorageProvider (com.emc.storageos.api.mapper.functions.MapStorageProvider)8 StorageSystemViewObject (com.emc.storageos.plugins.StorageSystemViewObject)8 GET (javax.ws.rs.GET)8 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)7 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)7 AsyncTask (com.emc.storageos.volumecontroller.AsyncTask)7 BlockController (com.emc.storageos.volumecontroller.BlockController)7