Search in sources :

Example 6 with DatabaseException

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

the class HostService method provisionBareMetalHosts.

/**
 * Provision bare metal hosts by taking compute elements from the compute
 * virtual pool.
 *
 * @param param
 *            parameter for multiple host creation
 * @brief Provision bare metal hosts
 * @return TaskResourceRep (asynchronous call)
 * @throws DatabaseException
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/provision-bare-metal")
public TaskList provisionBareMetalHosts(ProvisionBareMetalHostsParam param) throws DatabaseException {
    ComputeVirtualPool cvp = _dbClient.queryObject(ComputeVirtualPool.class, param.getComputeVpool());
    ArgValidator.checkEntity(cvp, param.getComputeVpool(), false);
    VirtualArray varray = _dbClient.queryObject(VirtualArray.class, param.getVarray());
    ArgValidator.checkEntity(varray, param.getVarray(), false);
    TenantOrg tenant = _dbClient.queryObject(TenantOrg.class, param.getTenant());
    ArgValidator.checkEntity(tenant, param.getTenant(), false);
    if (!NullColumnValueGetter.isNullURI(param.getCluster())) {
        Cluster cluster = _dbClient.queryObject(Cluster.class, param.getCluster());
        ArgValidator.checkEntity(cluster, param.getCluster(), false);
    }
    _log.debug("checking if CVP is accessible");
    _permissionsHelper.checkTenantHasAccessToComputeVirtualPool(tenant.getId(), cvp);
    validateHostNames(param);
    InterProcessLock lock = lockBladeReservation();
    List<String> ceList = null;
    try {
        ceList = takeComputeElementsFromPool(cvp, param.getHostNames().size(), varray, param.getCluster());
    } catch (Exception e) {
        _log.error("unable to takeComputeElementsFromPool", e);
        throw e;
    } finally {
        unlockBladeReservation(lock);
    }
    Set<Host> hosts = new HashSet<Host>();
    for (int i = 0; i < param.getHostNames().size(); i++) {
        Host host = populateHost(tenant, param.getHostNames().get(i), ceList.get(i), param.getCluster(), cvp.getId());
        hosts.add(host);
        _dbClient.createObject(host);
    }
    return createHostTasks(hosts, param.getComputeVpool(), param.getVarray());
}
Also used : VirtualArray(com.emc.storageos.db.client.model.VirtualArray) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) Cluster(com.emc.storageos.db.client.model.Cluster) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) Host(com.emc.storageos.db.client.model.Host) ComputeVirtualPool(com.emc.storageos.db.client.model.ComputeVirtualPool) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 7 with DatabaseException

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

the class ComputeVirtualPoolService method checkServiceProfileTemplateURIs.

/**
 * Validates that each of the passed virtual array ids reference an existing
 * virtual array in the database and throws a bad request exception when
 * an invalid id is found.
 *
 * @param dbClient A reference to a DB client.
 */
private void checkServiceProfileTemplateURIs(Set<String> sptIds, DbClient dbClient) {
    Set<String> invalidIds = new HashSet<String>();
    if ((sptIds != null) && (!sptIds.isEmpty())) {
        Iterator<String> sptIdsIter = sptIds.iterator();
        while (sptIdsIter.hasNext()) {
            URI sptURI = null;
            try {
                sptURI = URI.create(sptIdsIter.next());
                UCSServiceProfileTemplate serviceProfileTemplate = dbClient.queryObject(UCSServiceProfileTemplate.class, sptURI);
                if (serviceProfileTemplate == null) {
                    invalidIds.add(sptURI.toString());
                }
            } catch (DatabaseException e) {
                if (sptURI != null) {
                    invalidIds.add(sptURI.toString());
                }
            }
        }
    }
    if (!invalidIds.isEmpty()) {
        throw APIException.badRequests.theURIsOfParametersAreNotValid("service profile templates", invalidIds);
    }
}
Also used : UCSServiceProfileTemplate(com.emc.storageos.db.client.model.UCSServiceProfileTemplate) URI(java.net.URI) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) HashSet(java.util.HashSet)

Example 8 with DatabaseException

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

the class LdapProviderMonitor method queryAuthnProviderFromDB.

private AuthnProvider queryAuthnProviderFromDB(Set<String> domains) {
    URIQueryResultList providers = new URIQueryResultList();
    // Must have at lease one
    String domain = (String) domains.toArray()[0];
    try {
        dbClient.queryByConstraint(AlternateIdConstraint.Factory.getAuthnProviderDomainConstraint(domain), providers);
        Iterator<URI> it = providers.iterator();
        while (it.hasNext()) {
            URI providerURI = it.next();
            AuthnProvider provider = dbClient.queryObject(AuthnProvider.class, providerURI);
            if (provider != null && provider.getDisable() == false) {
                return provider;
            }
        }
    } catch (DatabaseException ex) {
        log.error("Could not query for authn providers to check for existing domain {}", domain, ex);
        throw ex;
    }
    return null;
}
Also used : AuthnProvider(com.emc.storageos.db.client.model.AuthnProvider) URI(java.net.URI) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 9 with DatabaseException

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

the class CassandraTokenManager method getToken.

/**
 * Persist/Update the StorageOSUserDAO record
 * generates a new token or reuses an existing token.
 *
 * @return token as a String
 */
@Override
public String getToken(StorageOSUserDAO userDAO) {
    try {
        // always use lower case username for comparing/saving to db
        userDAO.setUserName(userDAO.getUserName().toLowerCase());
        // find an active user record, if there is one with an active token
        List<StorageOSUserDAO> userRecords = getUserRecords(userDAO.getUserName());
        StorageOSUserDAO user = updateDBWithUser(userDAO, userRecords);
        // do we have a user account to use?
        if (user == null) {
            // No, create one
            userDAO.setId(URIUtil.createId(StorageOSUserDAO.class));
            _dbClient.persistObject(userDAO);
            user = userDAO;
        } else {
            // check count
            List<Token> tokensForUserId = getTokensForUserId(user.getId());
            int maxTokens = user.getUserName().equalsIgnoreCase(PROXY_USER) ? _maxTokensForProxyUser : _maxTokensPerUserId;
            double alertTokensSize = (maxTokens * TOKEN_WARNING_EIGHTY_PERCENT);
            if (tokensForUserId.size() >= maxTokens) {
                throw APIException.unauthorized.maxNumberOfTokenExceededForUser();
            } else if (tokensForUserId.size() == (int) alertTokensSize) {
                _log.warn("Prior to creating new token, user {} had {} tokens.", user.getUserName(), tokensForUserId.size());
            }
        }
        return _tokenEncoder.encode(TokenOnWire.createTokenOnWire(createNewToken(user)));
    } catch (DatabaseException ex) {
        _log.error("Exception while persisting user information {}", userDAO.getUserName(), ex);
    } catch (SecurityException e) {
        _log.error("Token encoding exception. ", e);
    }
    return null;
}
Also used : StorageOSUserDAO(com.emc.storageos.db.client.model.StorageOSUserDAO) ProxyToken(com.emc.storageos.db.client.model.ProxyToken) Token(com.emc.storageos.db.client.model.Token) SecurityException(com.emc.storageos.security.exceptions.SecurityException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DecommissionedConstraint(com.emc.storageos.db.client.constraint.DecommissionedConstraint)

Example 10 with DatabaseException

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

the class UserGroupService method authNProviderExistsForDomain.

/**
 * Check if a provider exists for the given domain
 *
 * @param domain
 * @return
 */
private boolean authNProviderExistsForDomain(String domain) {
    URIQueryResultList providers = new URIQueryResultList();
    try {
        _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getAuthnProviderDomainConstraint(domain), providers);
    } catch (DatabaseException ex) {
        _log.error("Could not query for authn providers to check for existing domain {}", domain, ex.getStackTrace());
        throw ex;
    }
    // check if there is an AuthnProvider contains the given domain and not in disabled state
    boolean bExist = false;
    Iterator<URI> it = providers.iterator();
    while (it.hasNext()) {
        URI providerURI = it.next();
        AuthnProvider provider = _dbClient.queryObject(AuthnProvider.class, providerURI);
        if (provider != null && provider.getDisable() == false) {
            bExist = true;
            break;
        }
    }
    return bExist;
}
Also used : AuthnProvider(com.emc.storageos.db.client.model.AuthnProvider) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Aggregations

DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)109 URI (java.net.URI)70 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 HashSet (java.util.HashSet)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 HashMap (java.util.HashMap)11 List (java.util.List)11 WBEMException (javax.wbem.WBEMException)11