Search in sources :

Example 76 with DatabaseException

use of com.emc.storageos.db.exceptions.DatabaseException in project coprhd-controller by CoprHD.

the class NetAppClusterModeCommIntf method discoverAll.

public void discoverAll(AccessProfile accessProfile) throws BaseCollectionException {
    URI storageSystemId = null;
    StorageSystem storageSystem = null;
    String detailedStatusMessage = "Unknown Status";
    try {
        _logger.info("Access Profile Details :  IpAddress : {}, PortNumber : {}", accessProfile.getIpAddress(), accessProfile.getPortNumber());
        storageSystemId = accessProfile.getSystemId();
        storageSystem = _dbClient.queryObject(StorageSystem.class, storageSystemId);
        // Retrieve NetAppC Filer information.
        discoverFilerInfo(storageSystem);
        String minimumSupportedVersion = VersionChecker.getMinimumSupportedVersion(Type.valueOf(storageSystem.getSystemType()));
        String firmwareVersion = storageSystem.getFirmwareVersion();
        // Example version String for NetappC looks like 8.2
        _logger.info("Verifying version details : Minimum Supported Version {} - Discovered NetApp Cluster Mode Version {}", minimumSupportedVersion, firmwareVersion);
        if (VersionChecker.verifyVersionDetails(minimumSupportedVersion, firmwareVersion) < 0) {
            storageSystem.setCompatibilityStatus(DiscoveredDataObject.CompatibilityStatus.INCOMPATIBLE.name());
            storageSystem.setReachableStatus(false);
            DiscoveryUtils.setSystemResourcesIncompatible(_dbClient, _coordinator, storageSystem.getId());
            throw new NetAppCException(String.format(" ** This version of NetApp Cluster Mode is not supported ** Should be a minimum of %s", minimumSupportedVersion));
        }
        storageSystem.setCompatibilityStatus(DiscoveredDataObject.CompatibilityStatus.COMPATIBLE.name());
        storageSystem.setReachableStatus(true);
        _dbClient.persistObject(storageSystem);
        if (!storageSystem.getReachableStatus()) {
            throw new NetAppCException("Failed to connect to " + storageSystem.getIpAddress());
        }
        _completer.statusPending(_dbClient, "Identified physical storage");
        List<StorageVirtualMachineInfo> svms = new ArrayList<StorageVirtualMachineInfo>();
        Map<String, List<StorageHADomain>> groups = discoverPortGroups(storageSystem, svms);
        _logger.info("No of newly discovered groups {}", groups.get(NEW).size());
        _logger.info("No of existing discovered groups {}", groups.get(EXISTING).size());
        if (!groups.get(NEW).isEmpty()) {
            _dbClient.createObject(groups.get(NEW));
        }
        if (!groups.get(EXISTING).isEmpty()) {
            _dbClient.persistObject(groups.get(EXISTING));
        }
        List<StoragePool> poolsToMatchWithVpool = new ArrayList<StoragePool>();
        List<StoragePool> allPools = new ArrayList<StoragePool>();
        Map<String, List<StoragePool>> pools = discoverStoragePools(storageSystem, poolsToMatchWithVpool);
        _logger.info("No of newly discovered pools {}", pools.get(NEW).size());
        _logger.info("No of existing discovered pools {}", pools.get(EXISTING).size());
        if (!pools.get(NEW).isEmpty()) {
            allPools.addAll(pools.get(NEW));
            _dbClient.createObject(pools.get(NEW));
        }
        if (!pools.get(EXISTING).isEmpty()) {
            allPools.addAll(pools.get(EXISTING));
            _dbClient.persistObject(pools.get(EXISTING));
        }
        List<StoragePool> notVisiblePools = DiscoveryUtils.checkStoragePoolsNotVisible(allPools, _dbClient, storageSystemId);
        if (notVisiblePools != null && !notVisiblePools.isEmpty()) {
            poolsToMatchWithVpool.addAll(notVisiblePools);
        }
        _completer.statusPending(_dbClient, "Completed pool discovery");
        // discover ports
        List<StoragePort> allPorts = new ArrayList<StoragePort>();
        Map<String, List<StoragePort>> ports = discoverPorts(storageSystem, svms, groups.get(NEW));
        _logger.info("No of newly discovered port {}", ports.get(NEW).size());
        _logger.info("No of existing discovered port {}", ports.get(EXISTING).size());
        if (!ports.get(NEW).isEmpty()) {
            allPorts.addAll(ports.get(NEW));
            _dbClient.createObject(ports.get(NEW));
        }
        if (!ports.get(EXISTING).isEmpty()) {
            allPorts.addAll(ports.get(EXISTING));
            _dbClient.persistObject(ports.get(EXISTING));
        }
        List<StoragePort> notVisiblePorts = DiscoveryUtils.checkStoragePortsNotVisible(allPorts, _dbClient, storageSystemId);
        _completer.statusPending(_dbClient, "Completed port discovery");
        List<StoragePort> allExistingPorts = new ArrayList<StoragePort>(ports.get(EXISTING));
        if (notVisiblePorts != null && !notVisiblePorts.isEmpty()) {
            allExistingPorts.addAll(notVisiblePorts);
        }
        StoragePortAssociationHelper.runUpdatePortAssociationsProcess(ports.get(NEW), allExistingPorts, _dbClient, _coordinator, poolsToMatchWithVpool);
        // discovery succeeds
        detailedStatusMessage = String.format("Discovery completed successfully for Storage System: %s", storageSystemId.toString());
    } catch (Exception e) {
        if (null != storageSystem) {
            cleanupDiscovery(storageSystem);
        }
        detailedStatusMessage = String.format("Discovery failed for Storage System: %s because %s", storageSystemId.toString(), e.getLocalizedMessage());
        _logger.error(detailedStatusMessage, e);
        throw new NetAppCException(detailedStatusMessage);
    } finally {
        if (storageSystem != null) {
            try {
                // set detailed message
                storageSystem.setLastDiscoveryStatusMessage(detailedStatusMessage);
                _dbClient.persistObject(storageSystem);
            } catch (DatabaseException ex) {
                _logger.error("Error while persisting object to DB", ex);
            }
        }
    }
}
Also used : StoragePool(com.emc.storageos.db.client.model.StoragePool) ArrayList(java.util.ArrayList) StoragePort(com.emc.storageos.db.client.model.StoragePort) URI(java.net.URI) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) NetAppException(com.emc.storageos.netapp.NetAppException) NetAppCException(com.emc.storageos.netappc.NetAppCException) IOException(java.io.IOException) NetAppCException(com.emc.storageos.netappc.NetAppCException) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) StorageVirtualMachineInfo(com.iwave.ext.netappc.StorageVirtualMachineInfo) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 77 with DatabaseException

use of com.emc.storageos.db.exceptions.DatabaseException 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)

Example 78 with DatabaseException

use of com.emc.storageos.db.exceptions.DatabaseException in project coprhd-controller by CoprHD.

the class ECSCommunicationInterface method discover.

/**
 * Get storage pool and storage ports
 */
@Override
public void discover(AccessProfile accessProfile) throws BaseCollectionException {
    URI storageSystemId = null;
    StorageSystem storageSystem = null;
    String detailedStatusMessage = "Unknown Status";
    long startTime = System.currentTimeMillis();
    _logger.info("ECSCommunicationInterface:discover Access Profile Details :" + accessProfile.toString());
    try {
        storageSystemId = accessProfile.getSystemId();
        storageSystem = _dbClient.queryObject(StorageSystem.class, storageSystemId);
        // try to connect to the ECS
        ECSApi ecsApi = getECSDevice(storageSystem);
        String authToken = ecsApi.getAuthToken();
        if (authToken.isEmpty()) {
            throw ECSException.exceptions.discoverFailed("Could not obtain authToken");
        }
        // Make sure user is system admin before proceeding to discovery
        if (!ecsApi.isSystemAdmin()) {
            _logger.error("User:" + accessProfile.getUserName() + "dont have privileges to access Elastic Cloud Storage: " + accessProfile.getIpAddress());
            _logger.error("Discovery failed");
            throw ECSException.exceptions.discoverFailed("User is not ECS System Admin");
        }
        String ecsVersion = ecsApi.getECSVersion();
        String ecsSerialNumber = ecsApi.getECSSerialNum();
        // Get details of storage system
        String nativeGuid = NativeGUIDGenerator.generateNativeGuid(DiscoveredDataObject.Type.ecs.toString(), ecsSerialNumber);
        storageSystem.setNativeGuid(nativeGuid);
        storageSystem.setSerialNumber(ecsSerialNumber);
        storageSystem.setFirmwareVersion(ecsVersion);
        storageSystem.setUsername(accessProfile.getUserName());
        storageSystem.setPassword(accessProfile.getPassword());
        storageSystem.setPortNumber(accessProfile.getPortNumber());
        storageSystem.setIpAddress(accessProfile.getIpAddress());
        storageSystem.setCompatibilityStatus(DiscoveredDataObject.CompatibilityStatus.COMPATIBLE.name());
        storageSystem.setReachableStatus(true);
        storageSystem.setInactive(false);
        _dbClient.persistObject(storageSystem);
        // Discover storage pools
        Map<String, List<StoragePool>> allPools = new HashMap<String, List<StoragePool>>();
        List<StoragePool> newPools = new ArrayList<StoragePool>();
        List<StoragePool> existingPools = new ArrayList<StoragePool>();
        StoragePool storagePool;
        List<ECSStoragePool> ecsStoragePools = ecsApi.getStoragePools();
        for (ECSStoragePool ecsPool : ecsStoragePools) {
            // Check if this storage pool was already discovered
            storagePool = null;
            String storagePoolNativeGuid = NativeGUIDGenerator.generateNativeGuid(storageSystem, ecsPool.getId(), NativeGUIDGenerator.POOL);
            @SuppressWarnings("deprecation") List<URI> poolURIs = _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getStoragePoolByNativeGuidConstraint(storagePoolNativeGuid));
            for (URI poolUri : poolURIs) {
                StoragePool pool = _dbClient.queryObject(StoragePool.class, poolUri);
                if (!pool.getInactive() && pool.getStorageDevice().equals(storageSystemId)) {
                    storagePool = pool;
                    break;
                }
            }
            if (storagePool == null) {
                storagePool = new StoragePool();
                storagePool.setId(URIUtil.createId(StoragePool.class));
                storagePool.setNativeId(ecsPool.getId());
                storagePool.setNativeGuid(storagePoolNativeGuid);
                storagePool.setLabel(storagePoolNativeGuid);
                storagePool.setPoolClassName("ECS Pool");
                storagePool.setStorageDevice(storageSystem.getId());
                StringSet protocols = new StringSet();
                protocols.add("S3");
                protocols.add("Swift");
                protocols.add("Atmos");
                storagePool.setProtocols(protocols);
                storagePool.setPoolName(ecsPool.getName());
                storagePool.setOperationalStatus(StoragePool.PoolOperationalStatus.READY.toString());
                storagePool.setPoolServiceType(PoolServiceType.object.toString());
                storagePool.setRegistrationStatus(RegistrationStatus.REGISTERED.toString());
                storagePool.setSupportedResourceTypes(StoragePool.SupportedResourceTypes.THICK_ONLY.toString());
                storagePool.setFreeCapacity(ecsPool.getFreeCapacity() * BYTESCONVERTER * BYTESCONVERTER);
                storagePool.setTotalCapacity(ecsPool.getTotalCapacity() * BYTESCONVERTER * BYTESCONVERTER);
                storagePool.setInactive(false);
                storagePool.setDataCenters(ecsPool.getTotalDataCenters());
                _logger.info("Creating new ECS storage pool using NativeId : {}", storagePoolNativeGuid);
                storagePool.setDiscoveryStatus(DiscoveryStatus.VISIBLE.name());
                storagePool.setCompatibilityStatus(DiscoveredDataObject.CompatibilityStatus.COMPATIBLE.name());
                newPools.add(storagePool);
            } else {
                existingPools.add(storagePool);
            }
        }
        allPools.put(NEW, newPools);
        allPools.put(EXISTING, existingPools);
        _logger.info("No of newly discovered pools {}", allPools.get(NEW).size());
        _logger.info("No of existing discovered pools {}", allPools.get(EXISTING).size());
        if (!allPools.get(NEW).isEmpty()) {
            _dbClient.createObject(allPools.get(NEW));
        }
        if (!allPools.get(EXISTING).isEmpty()) {
            _dbClient.persistObject(allPools.get(EXISTING));
        }
        // Get storage ports
        HashMap<String, List<StoragePort>> storagePorts = new HashMap<String, List<StoragePort>>();
        List<StoragePort> newStoragePorts = new ArrayList<StoragePort>();
        List<StoragePort> existingStoragePorts = new ArrayList<StoragePort>();
        List<ECSStoragePort> ecsStoragePorts = ecsApi.getStoragePort(storageSystem.getIpAddress());
        for (ECSStoragePort ecsPort : ecsStoragePorts) {
            StoragePort storagePort = null;
            String portNativeGuid = NativeGUIDGenerator.generateNativeGuid(storageSystem, ecsPort.getIpAddress(), NativeGUIDGenerator.PORT);
            // Check if storage port was already discovered
            @SuppressWarnings("deprecation") List<URI> portURIs = _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getStoragePortByNativeGuidConstraint(portNativeGuid));
            for (URI portUri : portURIs) {
                StoragePort port = _dbClient.queryObject(StoragePort.class, portUri);
                if (port.getStorageDevice().equals(storageSystemId) && !port.getInactive()) {
                    storagePort = port;
                    break;
                }
            }
            if (storagePort == null) {
                // Create new port
                storagePort = new StoragePort();
                storagePort.setId(URIUtil.createId(StoragePort.class));
                storagePort.setTransportType("IP");
                storagePort.setNativeGuid(portNativeGuid);
                storagePort.setLabel(portNativeGuid);
                storagePort.setStorageDevice(storageSystemId);
                storagePort.setPortNetworkId(ecsPort.getIpAddress().toLowerCase());
                storagePort.setPortName(ecsPort.getName());
                storagePort.setLabel(ecsPort.getName());
                storagePort.setPortGroup(ecsPort.getName());
                storagePort.setRegistrationStatus(RegistrationStatus.REGISTERED.toString());
                storagePort.setOperationalStatus(StoragePort.OperationalStatus.OK.toString());
                _logger.info("Creating new storage port using NativeGuid : {}", portNativeGuid);
                newStoragePorts.add(storagePort);
            } else {
                existingStoragePorts.add(storagePort);
            }
            storagePort.setDiscoveryStatus(DiscoveryStatus.VISIBLE.name());
            storagePort.setCompatibilityStatus(DiscoveredDataObject.CompatibilityStatus.COMPATIBLE.name());
        }
        storagePorts.put(NEW, newStoragePorts);
        storagePorts.put(EXISTING, existingStoragePorts);
        _logger.info("No of newly discovered ports {}", storagePorts.get(NEW).size());
        _logger.info("No of existing discovered ports {}", storagePorts.get(EXISTING).size());
        if (!storagePorts.get(NEW).isEmpty()) {
            _dbClient.createObject(storagePorts.get(NEW));
        }
        if (!storagePorts.get(EXISTING).isEmpty()) {
            _dbClient.persistObject(storagePorts.get(EXISTING));
        }
        // Discover ECS Namespaces
        List<ObjectNamespace> allNamespaces = new ArrayList<ObjectNamespace>();
        Map<String, List<ObjectNamespace>> bothNamespaces = discoverNamespaces(storageSystem);
        _logger.info("No of newly discovered namespaces {}", bothNamespaces.get(NEW).size());
        _logger.info("No of existing discovered namespaces {}", bothNamespaces.get(EXISTING).size());
        if (bothNamespaces != null && !bothNamespaces.get(NEW).isEmpty()) {
            allNamespaces.addAll(bothNamespaces.get(NEW));
            _dbClient.createObject(bothNamespaces.get(NEW));
        }
        if (bothNamespaces != null && !bothNamespaces.get(EXISTING).isEmpty()) {
            allNamespaces.addAll(bothNamespaces.get(EXISTING));
            _dbClient.updateObject(bothNamespaces.get(EXISTING));
        }
        // Some namespaces might have been deleted
        DiscoveryUtils.checkNamespacesNotVisible(allNamespaces, _dbClient, storageSystemId);
        _completer.statusPending(_dbClient, "Completed namespace discovery");
        // Discovery success
        detailedStatusMessage = String.format("Discovery completed successfully for ECS: %s", storageSystemId.toString());
    } catch (Exception e) {
        if (storageSystem != null) {
            cleanupDiscovery(storageSystem);
        }
        detailedStatusMessage = String.format("Discovery failed for Storage System ECS %s: because %s", storageSystemId.toString(), e.getLocalizedMessage());
        _logger.error(detailedStatusMessage, e);
        throw new ECSCollectionException(false, ServiceCode.DISCOVERY_ERROR, null, detailedStatusMessage, null, null);
    } finally {
        if (storageSystem != null) {
            try {
                // set detailed message
                storageSystem.setLastDiscoveryStatusMessage(detailedStatusMessage);
                _dbClient.persistObject(storageSystem);
            } catch (DatabaseException ex) {
                _logger.error("Error while persisting object to DB", ex);
            }
        }
        long totalTime = System.currentTimeMillis() - startTime;
        _logger.info(String.format("Discovery of ECS Storage System %s took %f seconds", accessProfile.getIpAddress(), (double) totalTime / (double) 1000));
    }
}
Also used : StoragePool(com.emc.storageos.db.client.model.StoragePool) ECSStoragePool(com.emc.storageos.ecs.api.ECSStoragePool) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URI(java.net.URI) StringSet(com.emc.storageos.db.client.model.StringSet) ECSStoragePort(com.emc.storageos.ecs.api.ECSStoragePort) ArrayList(java.util.ArrayList) List(java.util.List) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) ECSStoragePort(com.emc.storageos.ecs.api.ECSStoragePort) StoragePort(com.emc.storageos.db.client.model.StoragePort) URISyntaxException(java.net.URISyntaxException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) ECSCollectionException(com.emc.storageos.plugins.metering.ecs.ECSCollectionException) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) SMIPluginException(com.emc.storageos.plugins.metering.smis.SMIPluginException) ECSException(com.emc.storageos.ecs.api.ECSException) ECSApi(com.emc.storageos.ecs.api.ECSApi) ECSStoragePool(com.emc.storageos.ecs.api.ECSStoragePool) ObjectNamespace(com.emc.storageos.db.client.model.ObjectNamespace) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) ECSCollectionException(com.emc.storageos.plugins.metering.ecs.ECSCollectionException)

Example 79 with DatabaseException

use of com.emc.storageos.db.exceptions.DatabaseException in project coprhd-controller by CoprHD.

the class SmisCommandHelper method renameVolume.

/**
 * Rename a volume on the SMIS storage device. Used by SRDF.
 *
 * @param dbClient - database reference (volume deviceLabel is updated)
 * @param storageSystem - StorageSystem
 * @param volume - Volume
 * @param name - new name String
 */
public void renameVolume(DbClient dbClient, StorageSystem storageSystem, Volume volume, String name) {
    try {
        CIMObjectPath volumePath = _cimPath.getBlockObjectPath(storageSystem, volume);
        _log.info(String.format("Attempting to modify volume %s to %s", volumePath.toString(), name));
        CIMInstance toUpdate = new CIMInstance(volumePath, new CIMProperty[] { new CIMPropertyFactory().string(SmisConstants.CP_ELEMENT_NAME, name) });
        modifyInstance(storageSystem, toUpdate, SmisConstants.PS_ELEMENT_NAME);
        volume.setDeviceLabel(name);
        dbClient.updateAndReindexObject(volume);
        _log.info(String.format("Volume name has been modified to %s", name));
    } catch (WBEMException e) {
        _log.error("Encountered an error while trying to set the volume name", e);
    } catch (DatabaseException e) {
        _log.error("Encountered an error while trying to set the volume name", e);
    } catch (Exception e) {
        _log.error("Encountered an error while trying to set the volume name", e);
    }
}
Also used : CIMObjectPath(javax.cim.CIMObjectPath) WBEMException(javax.wbem.WBEMException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) CIMInstance(javax.cim.CIMInstance) IOException(java.io.IOException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) WBEMException(javax.wbem.WBEMException) ServiceCodeException(com.emc.storageos.svcs.errorhandling.resources.ServiceCodeException)

Example 80 with DatabaseException

use of com.emc.storageos.db.exceptions.DatabaseException in project coprhd-controller by CoprHD.

the class SmisStorageDevice method doActivateSnapshot.

@Override
public void doActivateSnapshot(final StorageSystem storage, final List<URI> snapshotList, final TaskCompleter taskCompleter) throws DeviceControllerException {
    try {
        List<BlockSnapshot> snapshots = _dbClient.queryObject(BlockSnapshot.class, snapshotList);
        URI snapshot = snapshots.get(0).getId();
        if (ControllerUtils.checkSnapshotsInConsistencyGroup(snapshots, _dbClient, taskCompleter)) {
            _snapshotOperations.activateGroupSnapshots(storage, snapshot, taskCompleter);
        } else {
            _snapshotOperations.activateSingleVolumeSnapshot(storage, snapshot, taskCompleter);
        }
    } catch (DatabaseException e) {
        String message = String.format("IO exception when trying to create snapshot(s) on array %s", storage.getSerialNumber());
        _log.error(message, e);
        ServiceError error = DeviceControllerErrors.smis.methodFailed("doActivateSnapshot", e.getMessage());
        taskCompleter.error(_dbClient, error);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException)

Aggregations

DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)109 URI (java.net.URI)71 ArrayList (java.util.ArrayList)29 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)22 IOException (java.io.IOException)21 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)20 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)19 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)18 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)17 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)16 NamedURI (com.emc.storageos.db.client.model.NamedURI)14 ControllerException (com.emc.storageos.volumecontroller.ControllerException)13 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)12 HashMap (java.util.HashMap)12 HashSet (java.util.HashSet)12 List (java.util.List)12 StoragePool (com.emc.storageos.db.client.model.StoragePool)11 StoragePort (com.emc.storageos.db.client.model.StoragePort)11 Volume (com.emc.storageos.db.client.model.Volume)11 WBEMException (javax.wbem.WBEMException)11