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());
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations