Search in sources :

Example 61 with DatabaseException

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

the class SmisCreateMaskingViewJob method enableRecoverPointTag.

/**
 * Method will set the EMCRecoverPointEnabled flag on the device masking group for VMAX.
 *
 * @param dbClient [in] - Client instance for reading/writing from/to DB
 * @param client [in] - WBEMClient used for reading/writing from/to SMI-S
 * @param deviceGroupPath [in] - CIMObjectPath referencing the volume
 */
private void enableRecoverPointTag(DbClient dbClient, WBEMClient client, CIMObjectPath deviceGroupPath) {
    try {
        boolean isRPTagNeeded = false;
        // Check if the volumes being protected are RP volumes
        for (VolumeURIHLU volUriHlu : _volumeURIHLUs) {
            URI volumeURI = volUriHlu.getVolumeURI();
            BlockObject bo = null;
            if (URIUtil.isType(volumeURI, BlockSnapshot.class)) {
                bo = dbClient.queryObject(BlockSnapshot.class, volumeURI);
            } else if (URIUtil.isType(volumeURI, Volume.class)) {
                bo = dbClient.queryObject(Volume.class, volumeURI);
            }
            if (bo != null && BlockObject.checkForRP(dbClient, bo.getId())) {
                isRPTagNeeded = true;
                break;
            }
        }
        // Do nothing and return from if none of the volumes are RP protected
        if (isRPTagNeeded) {
            _log.info("Attempting to enable RecoverPoint tag on Device Group : " + deviceGroupPath.toString());
            CIMPropertyFactory factoryRef = (CIMPropertyFactory) ControllerServiceImpl.getBean("CIMPropertyFactory");
            CIMInstance toUpdate = new CIMInstance(deviceGroupPath, new CIMProperty[] { factoryRef.bool(SmisConstants.EMC_RECOVERPOINT_ENABLED, true) });
            _log.debug("Params: " + toUpdate.toString());
            client.modifyInstance(toUpdate, SmisConstants.CP_EMC_RECOVERPOINT_ENABLED);
            _log.info(String.format("Device group has been successfully set with RecoverPoint tag "));
        }
    } catch (WBEMException e) {
        _log.error("Encountered an error while trying to set the RecoverPoint tag", e);
    } catch (DatabaseException e) {
        _log.error("Encountered an error while trying to set the RecoverPoint tag", e);
    }
}
Also used : CIMPropertyFactory(com.emc.storageos.volumecontroller.impl.smis.CIMPropertyFactory) Volume(com.emc.storageos.db.client.model.Volume) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) WBEMException(javax.wbem.WBEMException) URI(java.net.URI) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) BlockObject(com.emc.storageos.db.client.model.BlockObject) CIMInstance(javax.cim.CIMInstance) VolumeURIHLU(com.emc.storageos.volumecontroller.impl.VolumeURIHLU)

Example 62 with DatabaseException

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

the class SmisCreateMaskingViewJob method enableRecoverPointTagOn803.

/**
 * Method will set the EMCRecoverPointEnabled flag on all the volumes within 8.0.3 Provider.
 * 8.0.3 Provider doesnt support setting RP tag on Storage Groups.
 *
 * @param dbClient [in] - Client instance for reading/writing from/to DB
 * @param client [in] - WBEMClient used for reading/writing from/to SMI-S
 * @param deviceGroupPath [in] - CIMObjectPath referencing the volume
 */
private void enableRecoverPointTagOn803(DbClient dbClient, WBEMClient client, StorageSystem storage, JobContext jobContext) {
    try {
        boolean isRPTagNeeded = false;
        List<URI> blockObjectUris = new ArrayList<URI>();
        for (VolumeURIHLU volUriHlu : _volumeURIHLUs) {
            URI volumeURI = volUriHlu.getVolumeURI();
            BlockObject bo = null;
            if (URIUtil.isType(volumeURI, BlockSnapshot.class)) {
                bo = dbClient.queryObject(BlockSnapshot.class, volumeURI);
            } else if (URIUtil.isType(volumeURI, Volume.class)) {
                bo = dbClient.queryObject(Volume.class, volumeURI);
            }
            if (bo != null) {
                blockObjectUris.add(bo.getId());
                if (BlockObject.checkForRP(dbClient, bo.getId())) {
                    isRPTagNeeded = true;
                }
            }
        }
        // Do nothing and return from if none of the volumes are RP protected
        if (isRPTagNeeded) {
            SmisCommandHelper helper = jobContext.getSmisCommandHelper();
            helper.setRecoverPointTag(storage, helper.getVolumeMembers(storage, blockObjectUris), true);
        }
    } catch (WBEMException e) {
        _log.error("Encountered an error while trying to set the RecoverPoint tag", e);
    } catch (DatabaseException e) {
        _log.error("Encountered an error while trying to set the RecoverPoint tag", e);
    } catch (Exception e) {
        _log.error("Encountered an error while trying to set the RecoverPoint tag", e);
    }
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) SmisCommandHelper(com.emc.storageos.volumecontroller.impl.smis.SmisCommandHelper) ArrayList(java.util.ArrayList) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) WBEMException(javax.wbem.WBEMException) URI(java.net.URI) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) BlockObject(com.emc.storageos.db.client.model.BlockObject) WBEMException(javax.wbem.WBEMException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) VolumeURIHLU(com.emc.storageos.volumecontroller.impl.VolumeURIHLU)

Example 63 with DatabaseException

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

the class SmisCreateMultiVolumeJob method changeVolumeName.

/**
 * Method will modify the name of a given volume to a generate name.
 *
 * @param dbClient [in] - Client instance for reading/writing from/to DB
 * @param client [in] - WBEMClient used for reading/writing from/to SMI-S
 * @param volumePath [in] - CIMObjectPath referencing the volume
 * @param volume [in] - Volume object
 */
private void changeVolumeName(DbClient dbClient, WBEMClient client, CIMObjectPath volumePath, Volume volume, String name) {
    Lease lease = null;
    try {
        _log.info(String.format("Attempting to modify volume %s to %s", volumePath.toString(), name));
        if (_propertyFactoryRef.get() == null) {
            _propertyFactoryRef.compareAndSet(null, (CIMPropertyFactory) ControllerServiceImpl.getBean("CIMPropertyFactory"));
        }
        CIMInstance toUpdate = new CIMInstance(volumePath, new CIMProperty[] { _propertyFactoryRef.get().string(SmisConstants.CP_ELEMENT_NAME, name) });
        if (_distributedLock.get() == null) {
            if (_coordinator.get() == null) {
                _coordinator.compareAndSet(null, (CoordinatorClient) ControllerServiceImpl.getBean("coordinator"));
            }
            _distributedLock.compareAndSet(null, _coordinator.get().getSemaphore(this.getClass().getSimpleName(), MAX_PERMITS));
        }
        lease = _distributedLock.get().acquireLease();
        client.modifyInstance(toUpdate, SmisConstants.PS_ELEMENT_NAME);
        _distributedLock.get().returnLease(lease);
        lease = null;
        volume.setDeviceLabel(name);
        dbClient.persistObject(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);
    } finally {
        if (lease != null) {
            try {
                _distributedLock.get().returnLease(lease);
            } catch (Exception e) {
                _log.error("Exception when trying to return lease", e);
            }
        }
    }
}
Also used : Lease(org.apache.curator.framework.recipes.locks.Lease) WBEMException(javax.wbem.WBEMException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) CIMInstance(javax.cim.CIMInstance) WBEMException(javax.wbem.WBEMException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException)

Example 64 with DatabaseException

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

the class VDCRoleMigrationCallback method findRootTenant.

private TenantOrg findRootTenant(DbClient _dbClient) {
    URIQueryResultList tenants = new URIQueryResultList();
    try {
        _dbClient.queryByConstraint(ContainmentConstraint.Factory.getTenantOrgSubTenantConstraint(URI.create(TenantOrg.NO_PARENT)), tenants);
        if (tenants.iterator().hasNext() == false) {
            throw new IllegalStateException("The CF of Root Tenant is not found");
        }
        URI root = tenants.iterator().next();
        return _dbClient.queryObject(TenantOrg.class, root);
    } catch (DatabaseException ex) {
        throw new IllegalStateException("Error in finding the CF of root tenant", ex);
    }
}
Also used : URI(java.net.URI) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 65 with DatabaseException

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

the class DBClient method queryForCustomDayStats.

/**
 * Query stats
 *
 * @param dateTime
 */
public void queryForCustomDayStats(DateTime dateTime, String filename) {
    System.out.println("\n\n -> Querying Stats");
    ExecutorService executor = Executors.newFixedThreadPool(100);
    StatQueryResult result = new StatQueryResult(filename);
    try {
        _dbClient.queryTimeSeries(StatTimeSeries.class, dateTime, TimeSeriesMetadata.TimeBucket.HOUR, result, executor);
        System.out.println(" --- Job Exceution for Querying Stats completed ---\n\n");
        return;
    } catch (DatabaseException e) {
        System.err.println("Exception Query " + e);
        log.error("Exception Query ", e);
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) 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