Search in sources :

Example 56 with DatabaseException

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

the class DataCollectionJobUtil method getSMISProvidersWithUpdatedSystems.

/**
 * Update all the SMISProviders with their actively managed storage systems information.
 *
 * @param providersToUpdate : dataStructure holds the provider => list of managed systems.
 */
private List<StorageProvider> getSMISProvidersWithUpdatedSystems(Map<URI, List<String>> providersToUpdate) {
    List<StorageProvider> providerList = new ArrayList<StorageProvider>();
    if (!providersToUpdate.isEmpty()) {
        Iterator<URI> providerIdKeyItr = providersToUpdate.keySet().iterator();
        while (providerIdKeyItr.hasNext()) {
            URI providerIdKey = null;
            try {
                providerIdKey = providerIdKeyItr.next();
                List<String> storageSystemList = providersToUpdate.get(providerIdKey);
                StorageProvider provider = _dbClient.queryObject(StorageProvider.class, providerIdKey);
                if (null != provider.getStorageSystems()) {
                    provider.getStorageSystems().clear();
                    provider.getStorageSystems().addAll(storageSystemList);
                } else {
                    StringSet storageSystems = new StringSet();
                    storageSystems.addAll(storageSystemList);
                    provider.setStorageSystems(storageSystems);
                }
                providerList.add(provider);
            } catch (DatabaseException ioEx) {
                _logger.error("IOException occurred while updating storageSystems for provider {}", providerIdKey);
            }
        }
    }
    return providerList;
}
Also used : ArrayList(java.util.ArrayList) StringSet(com.emc.storageos.db.client.model.StringSet) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) URI(java.net.URI) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException)

Example 57 with DatabaseException

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

the class DataCollectionJobUtil method performBookKeeping.

/**
 * 1. Iterate through the scanner result cache.
 * 2. For each serialId, find a storageSystem.
 * 3. If it is null, then create a new StorageSystem and update the details.
 * 4. If it is not null, then update active providers & registered status.
 *
 * @param scannedSystemsNativeGuidsMap
 *            : scanner result cache.
 */
public void performBookKeeping(Map<String, StorageSystemViewObject> scannedSystemsNativeGuidsMap, List<URI> providerList) {
    StorageSystem storageSystem = null;
    List<StorageSystem> systemsToPersist = new ArrayList<StorageSystem>();
    List<StorageSystem> systemsToCreate = new ArrayList<StorageSystem>();
    Set<String> scannedSystemNativeGuidKeySet;
    synchronized (scannedSystemsNativeGuidsMap) {
        scannedSystemNativeGuidKeySet = new HashSet(scannedSystemsNativeGuidsMap.keySet());
    }
    Set<URI> scannedProviderList = new HashSet<URI>(providerList);
    Map<URI, List<String>> providersToUpdate = new HashMap<URI, List<String>>();
    for (String scannedSystemNativeGuid : scannedSystemNativeGuidKeySet) {
        try {
            _logger.info("Found during scan : scannedSystemNativeGuid {}", scannedSystemNativeGuid);
            List<StorageSystem> systems = CustomQueryUtility.getActiveStorageSystemByNativeGuid(_dbClient, scannedSystemNativeGuid);
            if (DecommissionedResource.checkDecommissioned(_dbClient, scannedSystemNativeGuid, StorageSystem.class)) {
                scannedSystemsNativeGuidsMap.remove(scannedSystemNativeGuid);
                _logger.info("Storage system {} was decommissioned and cannot be added to Vipr", scannedSystemNativeGuid);
                continue;
            }
            if (null == systems || systems.isEmpty()) {
                storageSystem = createStorageSystem(scannedSystemsNativeGuidsMap.get(scannedSystemNativeGuid), scannedSystemNativeGuid, providersToUpdate);
                if (storageSystem != null) {
                    systemsToCreate.add(storageSystem);
                    _logger.info("Added new storage system to be created to the create list with Native Guid: {}", storageSystem.getNativeGuid());
                }
            }
        } catch (Exception e) {
            _logger.error(e.getMessage(), e);
            _logger.error("Exception while creating new system: {} due to {}", storageSystem != null ? storageSystem.getId() : "N/A", e.getCause());
        }
    }
    try {
        _dbClient.createObject(systemsToCreate);
    } catch (DatabaseException ex) {
        _logger.error("Exception occurred while persisting new StorageSystems due to ", ex);
    }
    // If a provider is not managing an array and it is moved to some other array,
    // then this will update the active provider in the storage system.
    updateActiveProviderDetailsInDbSystem(scannedSystemsNativeGuidsMap, systemsToPersist, scannedProviderList, providersToUpdate);
    // Persist all storage systems & providers
    persistAllSystemsAndProviders(systemsToPersist, getSMISProvidersWithUpdatedSystems(providersToUpdate));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URI(java.net.URI) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) IOException(java.io.IOException) ArrayList(java.util.ArrayList) List(java.util.List) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) HashSet(java.util.HashSet)

Example 58 with DatabaseException

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

the class RPCommunicationInterface method discover.

@Override
public void discover(AccessProfile accessProfile) throws BaseCollectionException {
    URI storageSystemId = null;
    ProtectionSystem protectionSystem = null;
    boolean discoverySuccess = true;
    StringBuffer errMsgBuilder = new StringBuffer();
    String detailedStatusMessage = "Unknown Status";
    boolean isNewlyCreated = false;
    try {
        _log.info("Access Profile Details :  IpAddress : {}, PortNumber : {}", accessProfile.getIpAddress(), accessProfile.getPortNumber());
        storageSystemId = accessProfile.getSystemId();
        protectionSystem = _dbClient.queryObject(ProtectionSystem.class, storageSystemId);
        if (protectionSystem.getDiscoveryStatus().equals(DiscoveredDataObject.DataCollectionJobStatus.CREATED.toString())) {
            isNewlyCreated = true;
        }
        if (StorageSystem.Discovery_Namespaces.UNMANAGED_CGS.toString().equalsIgnoreCase(accessProfile.getnamespace())) {
            try {
                unManagedCGDiscoverer.discoverUnManagedObjects(accessProfile, _dbClient, _partitionManager);
            } catch (RecoverPointException rpe) {
                discoverySuccess = false;
                String msg = "Discover RecoverPoint Unmanaged CGs failed. Protection system: " + storageSystemId;
                buildErrMsg(errMsgBuilder, rpe, msg);
            }
        } else {
            try {
                discoverCluster(protectionSystem);
            } catch (RecoverPointException rpe) {
                discoverySuccess = false;
                String msg = "Discover RecoverPoint cluster failed. Protection system: " + storageSystemId;
                buildErrMsg(errMsgBuilder, rpe, msg);
            }
            // get RP array mappings
            try {
                if (discoverySuccess) {
                    discoverRPSiteArrays(protectionSystem);
                    _dbClient.persistObject(protectionSystem);
                }
            } catch (Exception rpe) {
                discoverySuccess = false;
                String msg = "Discover RecoverPoint site/cluster failed. Protection system: " + storageSystemId;
                buildErrMsg(errMsgBuilder, rpe, msg);
            }
            try {
                if (discoverySuccess) {
                    discoverConnectivity(protectionSystem);
                }
            } catch (Exception rpe) {
                discoverySuccess = false;
                String msg = "Discover RecoverPoint connectivity failed. Protection system: " + storageSystemId;
                buildErrMsg(errMsgBuilder, rpe, msg);
            }
            // Perform maintenance on the RP bookmarks; some may no longer be valid
            try {
                if (discoverySuccess) {
                    RPHelper.cleanupSnapshots(_dbClient, protectionSystem);
                }
            } catch (Exception rpe) {
                discoverySuccess = false;
                String msg = "Snapshot maintenance failed. Protection system: " + storageSystemId;
                buildErrMsg(errMsgBuilder, rpe, msg);
            }
            // Rematch storage pools for RP virtual pools
            try {
                if (discoverySuccess && isNewlyCreated) {
                    matchVPools(protectionSystem.getId());
                }
            } catch (Exception rpe) {
                discoverySuccess = false;
                String msg = "Virtual Pool matching failed. Protection system: " + storageSystemId;
                buildErrMsg(errMsgBuilder, rpe, msg);
            }
            // Discover the Connected-via-RP-itself Storage Systems
            try {
                if (discoverySuccess) {
                    discoverVisibleStorageSystems(protectionSystem);
                }
            } catch (Exception rpe) {
                discoverySuccess = false;
                String msg = "RP-visible storage system discovery failed. Protection system: " + storageSystemId;
                buildErrMsg(errMsgBuilder, rpe, msg);
            }
            // Discover the Connected-via-NetworkStorage Systems
            try {
                if (discoverySuccess) {
                    discoverAssociatedStorageSystems(protectionSystem);
                }
            } catch (Exception rpe) {
                discoverySuccess = false;
                String msg = "Storage system discovery failed. Protection system: " + storageSystemId;
                buildErrMsg(errMsgBuilder, rpe, msg);
            }
            // Discover the protection sets
            try {
                if (discoverySuccess) {
                    discoverProtectionSets(protectionSystem);
                }
            } catch (Exception rpe) {
                discoverySuccess = false;
                String msg = "Discovery of protection sets failed. Protection system: " + storageSystemId;
                buildErrMsg(errMsgBuilder, rpe, msg);
            }
            // Discover the protection system cluster connectivity topology information
            try {
                if (discoverySuccess) {
                    discoverTopology(protectionSystem);
                }
            } catch (Exception rpe) {
                discoverySuccess = false;
                String msg = "Discovery of topology failed. Protection system: " + storageSystemId;
                buildErrMsg(errMsgBuilder, rpe, msg);
            }
        }
        if (!discoverySuccess) {
            throw DeviceControllerExceptions.recoverpoint.discoveryFailure(errMsgBuilder.toString());
        } else {
            detailedStatusMessage = String.format("Discovery completed successfully for Protection System: %s", storageSystemId.toString());
        }
    } catch (Exception e) {
        detailedStatusMessage = String.format("Discovery failed for Protection System %s because %s", storageSystemId.toString(), e.getLocalizedMessage());
        _log.error(detailedStatusMessage, e);
        throw DeviceControllerExceptions.recoverpoint.discoveryFailure(detailedStatusMessage);
    } finally {
        releaseResources();
        if (null != protectionSystem) {
            try {
                // set detailed message
                protectionSystem.setLastDiscoveryStatusMessage(detailedStatusMessage);
                _dbClient.persistObject(protectionSystem);
            } catch (DatabaseException ex) {
                _log.error("Error while persisting object to DB", ex);
            }
        }
    }
}
Also used : RecoverPointException(com.emc.storageos.recoverpoint.exceptions.RecoverPointException) URI(java.net.URI) ProtectionSystem(com.emc.storageos.db.client.model.ProtectionSystem) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) URISyntaxException(java.net.URISyntaxException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) RecoverPointException(com.emc.storageos.recoverpoint.exceptions.RecoverPointException) RecoverPointCollectionException(com.emc.storageos.plugins.metering.recoverpoint.RecoverPointCollectionException)

Example 59 with DatabaseException

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

the class SMICommunicationInterface method scan.

/**
 * {@inheritDoc}
 */
@Override
public void scan(AccessProfile accessProfile) throws BaseCollectionException {
    URI providerURI = null;
    StorageProvider providerObj = null;
    String detailedStatusMessage = "Unknown Status";
    try {
        _logger.info("Access Profile Details :" + accessProfile.toString());
        providerURI = accessProfile.getSystemId();
        providerObj = _dbClient.queryObject(StorageProvider.class, providerURI);
        _keyMap = new ConcurrentHashMap<String, Object>();
        _wbemClient = getCIMClient(accessProfile);
        _logger.info("CIMClient initialized successfully");
        _keyMap.put(Constants.PROPS, accessProfile.getProps());
        if (accessProfile.getCache() == null) {
            accessProfile.setCache(new HashMap<String, StorageSystemViewObject>());
        }
        _keyMap.put(Constants._computerSystem, new ArrayList<CIMObjectPath>());
        _keyMap.put(Constants.REGISTEREDPROFILE, CimObjectPathCreator.createInstance(Constants.PROFILECLASS, "interop"));
        _keyMap.put(Constants._cimClient, _wbemClient);
        _keyMap.put(Constants.dbClient, _dbClient);
        _keyMap.put(Constants.COORDINATOR_CLIENT, _coordinator);
        if (_networkDeviceController != null) {
            _keyMap.put(Constants.networkDeviceController, _networkDeviceController);
        }
        _keyMap.put(Constants._InteropNamespace, accessProfile.getInteropNamespace());
        _keyMap.put(Constants.ACCESSPROFILE, accessProfile);
        _keyMap.put(Constants.SYSTEMCACHE, accessProfile.getCache());
        executor.setKeyMap(_keyMap);
        executor.execute((Namespace) namespaces.getNsList().get(SCAN));
        // scan succeeds
        detailedStatusMessage = String.format("Scan job completed successfully for " + "SMISProvider: %s", providerURI.toString());
    } catch (Exception e) {
        detailedStatusMessage = String.format("Scan job failed for SMISProvider: %s because %s", providerURI.toString(), e.getMessage());
        throw new SMIPluginException(detailedStatusMessage);
    } finally {
        if (providerObj != null) {
            try {
                // set detailed message
                providerObj.setLastScanStatusMessage(detailedStatusMessage);
                _dbClient.persistObject(providerObj);
            } catch (DatabaseException ex) {
                _logger.error("Error while persisting object to DB", ex);
            }
        }
        releaseResources();
    }
}
Also used : StorageSystemViewObject(com.emc.storageos.plugins.StorageSystemViewObject) CIMObjectPath(javax.cim.CIMObjectPath) LocalReplicaObject(com.emc.storageos.volumecontroller.impl.plugins.discovery.smis.processor.detailedDiscovery.LocalReplicaObject) RemoteMirrorObject(com.emc.storageos.volumecontroller.impl.plugins.discovery.smis.processor.detailedDiscovery.RemoteMirrorObject) StorageSystemViewObject(com.emc.storageos.plugins.StorageSystemViewObject) SMIPluginException(com.emc.storageos.plugins.metering.smis.SMIPluginException) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) URI(java.net.URI) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) WBEMException(javax.wbem.WBEMException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) IOException(java.io.IOException) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) SMIPluginException(com.emc.storageos.plugins.metering.smis.SMIPluginException)

Example 60 with DatabaseException

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

the class VPlexCommunicationInterface method discoverAll.

/**
 * Implementation for discovering everything in a VPLEX storage system.
 *
 * @param accessProfile providing context for this discovery session
 *
 * @throws BaseCollectionException
 */
private void discoverAll(AccessProfile accessProfile) throws BaseCollectionException {
    boolean discoverySuccess = true;
    StringBuffer errMsgBuilder = new StringBuffer();
    URI storageSystemURI = null;
    StorageSystem vplexStorageSystem = null;
    String detailedStatusMessage = "Unknown Status";
    VPlexApiClient client = null;
    try {
        s_logger.info("Access Profile Details :  IpAddress : {}, PortNumber : {}", accessProfile.getIpAddress(), accessProfile.getPortNumber());
        storageSystemURI = accessProfile.getSystemId();
        // Get the VPlex storage system from the database.
        vplexStorageSystem = _dbClient.queryObject(StorageSystem.class, storageSystemURI);
        s_logger.info("Discover VPlex storage system {} at IP:{}, PORT:{}", new Object[] { storageSystemURI.toString(), accessProfile.getIpAddress(), accessProfile.getPortNumber() });
        // Get the Http client for getting information about the VPlex
        // storage system.
        client = getVPlexAPIClient(accessProfile);
        s_logger.debug("Got handle to VPlex API client");
        // clear cached discovery data in the VPlexApiClient
        client.clearCaches();
        client.primeCaches();
        // The version for the storage system is the version of its active provider
        // and since we are discovering it, the provider was compatible, so the
        // VPLEX must also be compatible.
        StorageProvider activeProvider = _dbClient.queryObject(StorageProvider.class, vplexStorageSystem.getActiveProviderURI());
        String serialNumber = getSystemSerialNumber(client, activeProvider, null);
        if (!vplexStorageSystem.getSerialNumber().equals(serialNumber)) {
            s_logger.error(String.format("The VPLEX serial number unexpectedly changed from %s to %s.", vplexStorageSystem.getSerialNumber(), serialNumber));
            throw VPlexApiException.exceptions.vplexSerialNumberChanged(vplexStorageSystem.getSerialNumber(), serialNumber);
        }
        vplexStorageSystem.setFirmwareVersion(activeProvider.getVersionString());
        vplexStorageSystem.setCompatibilityStatus(CompatibilityStatus.COMPATIBLE.toString());
        // Discover the cluster identification (serial number / cluster id ) mapping
        try {
            s_logger.info("Discovering cluster identification.");
            discoverClusterIdentification(vplexStorageSystem, client);
            _completer.statusPending(_dbClient, "Completed cluster identification discovery");
        } catch (VPlexCollectionException vce) {
            discoverySuccess = false;
            String errMsg = String.format("Failed cluster identification discovery for VPlex %s", storageSystemURI.toString());
            s_logger.error(errMsg, vce);
            if (errMsgBuilder.length() != 0) {
                errMsgBuilder.append(", ");
            }
            errMsgBuilder.append(errMsg);
        }
        List<StoragePort> allPorts = new ArrayList<StoragePort>();
        // Discover the VPlex port information.
        try {
            // When we discover storage ports on the VPlex, we create
            // initiators, if they don't exist, for backend ports.
            // The backend storage ports serve as initiators for the
            // connected backend storage.
            s_logger.info("Discovering frontend and backend ports.");
            discoverPorts(client, vplexStorageSystem, allPorts, null);
            _dbClient.updateObject(vplexStorageSystem);
            _completer.statusPending(_dbClient, "Completed port discovery");
        } catch (VPlexCollectionException vce) {
            discoverySuccess = false;
            String errMsg = String.format("Failed port discovery for VPlex %s", storageSystemURI.toString());
            s_logger.error(errMsg, vce);
            if (errMsgBuilder.length() != 0) {
                errMsgBuilder.append(", ");
            }
            errMsgBuilder.append(errMsg);
        }
        // update host initiators with registered initiator names from VPLEX
        try {
            updateHostInitiators(client, vplexStorageSystem.getSerialNumber());
        } catch (VPlexCollectionException vce) {
            discoverySuccess = false;
            String errMsg = String.format("Failed host initiator update for VPlex %s", storageSystemURI.toString());
            s_logger.error(errMsg, vce);
            if (errMsgBuilder.length() != 0) {
                errMsgBuilder.append(", ");
            }
            errMsgBuilder.append(errMsg);
        }
        try {
            s_logger.info("Discovering connectivity.");
            discoverConnectivity(vplexStorageSystem);
            _dbClient.updateObject(vplexStorageSystem);
            _completer.statusPending(_dbClient, "Completed connectivity verification");
        } catch (VPlexCollectionException vce) {
            discoverySuccess = false;
            String errMsg = String.format("Failed connectivity discovery for VPlex %s", storageSystemURI.toString());
            s_logger.error(errMsg, vce);
            if (errMsgBuilder.length() != 0) {
                errMsgBuilder.append(", ");
            }
            errMsgBuilder.append(errMsg);
        }
        if (discoverySuccess) {
            vplexStorageSystem.setReachableStatus(true);
            _dbClient.updateObject(vplexStorageSystem);
        } else {
            // If part of the discovery process failed, throw an exception.
            vplexStorageSystem.setReachableStatus(false);
            _dbClient.updateObject(vplexStorageSystem);
            throw new Exception(errMsgBuilder.toString());
        }
        StoragePortAssociationHelper.runUpdatePortAssociationsProcess(allPorts, null, _dbClient, _coordinator, null);
        // discovery succeeds
        detailedStatusMessage = String.format("Discovery completed successfully for Storage System: %s", storageSystemURI.toString());
    } catch (Exception e) {
        if (null != client) {
            // clear cached discovery data in the VPlexApiClient
            client.clearCaches();
        }
        VPlexCollectionException vce = VPlexCollectionException.exceptions.failedDiscovery(storageSystemURI.toString(), e.getLocalizedMessage());
        detailedStatusMessage = vce.getLocalizedMessage();
        s_logger.error(detailedStatusMessage, e);
        throw vce;
    } finally {
        if (vplexStorageSystem != null) {
            try {
                // set detailed message
                vplexStorageSystem.setLastDiscoveryStatusMessage(detailedStatusMessage);
                _dbClient.updateObject(vplexStorageSystem);
            } catch (DatabaseException ex) {
                s_logger.error("Error persisting last discovery status for storage system {}", vplexStorageSystem.getId(), ex);
            }
        }
    }
}
Also used : StoragePort(com.emc.storageos.db.client.model.StoragePort) ArrayList(java.util.ArrayList) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) VPlexApiException(com.emc.storageos.vplex.api.VPlexApiException) VPlexCollectionException(com.emc.storageos.plugins.metering.vplex.VPlexCollectionException) IOException(java.io.IOException) VPlexCollectionException(com.emc.storageos.plugins.metering.vplex.VPlexCollectionException) VPlexApiClient(com.emc.storageos.vplex.api.VPlexApiClient) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

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