use of com.emc.storageos.db.exceptions.DatabaseException in project coprhd-controller by CoprHD.
the class DbClientGeoTest method getRootTenant.
private TenantOrg getRootTenant() {
URIQueryResultList tenants = new URIQueryResultList();
try {
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getTenantOrgSubTenantConstraint(URI.create(TenantOrg.NO_PARENT)), tenants);
if (tenants.iterator().hasNext()) {
URI root = tenants.iterator().next();
TenantOrg rootTenant = _dbClient.queryObject(TenantOrg.class, root);
// It is possible have multiple index entries for the same root tenant at a certain period (CQ610571)
while (tenants.iterator().hasNext()) {
URI mulRoot = tenants.iterator().next();
if (!mulRoot.equals(root)) {
_logger.error("multiple entries found for root tenant. Stop.");
return null;
}
}
return rootTenant;
} else {
_logger.error("root tenant query returned no results");
return null;
}
} catch (DatabaseException ex) {
_logger.error("DatabaseException :", ex);
return null;
}
}
use of com.emc.storageos.db.exceptions.DatabaseException in project coprhd-controller by CoprHD.
the class AbstractPermissionFilter method filter.
/**
* ContainerRequestFilter - checks to see if one of the specified
* permissions exists for the user, if not throws
* APIException.forbidden.insufficientPermissionsForUser
*
* @param request
* @return ContainerRequest
*/
@Override
public ContainerRequest filter(ContainerRequest request) {
Principal p = request.getUserPrincipal();
if (!(p instanceof StorageOSUser)) {
throw APIException.forbidden.invalidSecurityContext();
}
StorageOSUser user = (StorageOSUser) p;
if (_blockProxies && user.isProxied()) {
throw APIException.forbidden.insufficientPermissionsForUser(user.getName());
}
boolean good = false;
// Step 1: Roles check - see if the user has one of the allowed roles
Set<String> tenantRoles = null;
for (Role role : _roles) {
if (user.getRoles().contains(role.toString())) {
good = true;
break;
}
if (_permissionsHelper.isRoleTenantLevel(role.toString())) {
if (tenantRoles == null) {
try {
URI tenantId = getTenantIdFromURI(getUriInfo());
tenantRoles = _permissionsHelper.getTenantRolesForUser(user, tenantId, isIdEmbeddedInURL(tenantId));
if (CollectionUtils.isEmpty(tenantRoles)) {
tenantRoles = getTenantRolesFromResource(user);
}
} catch (DatabaseException ex) {
throw APIException.forbidden.failedReadingTenantRoles(ex);
}
}
if (tenantRoles != null && tenantRoles.contains(role.toString())) {
good = true;
break;
}
}
}
// Step 2: if we are still not good, start checking for acls
if (!good && _acls.length > 0) {
// grab all acls from the resource
Set<String> acls = new HashSet<String>();
URI projectId = getProjectIdFromURI(getUriInfo());
if (projectId != null) {
try {
acls = _permissionsHelper.getProjectACLsForUser(user, projectId, isIdEmbeddedInURL(projectId));
} catch (DatabaseException ex) {
throw APIException.forbidden.failedReadingProjectACLs(ex);
}
} else {
/* other resource acls */
// these acls are assigned to tenant, so enhanced to check not only user's home tenant,
// but also need to take into consideration of subtenants, which user has tenant roles.
acls = getUsageAclsFromURI(user.getTenantId(), getUriInfo());
for (String subtenantId : _permissionsHelper.getSubtenantsForUser(user)) {
Set<String> subTenantAcls = getUsageAclsFromURI(subtenantId, getUriInfo());
if (acls == null) {
acls = subTenantAcls;
} else if (subTenantAcls != null) {
acls.addAll(subTenantAcls);
}
}
}
// see if we got any and we got a hit
if (acls != null) {
for (ACL acl : _acls) {
if (acl.equals(ACL.ANY) && (acls.contains(ACL.OWN.toString()) || acls.contains(ACL.BACKUP.toString()) || acls.contains(ACL.ALL.toString()))) {
good = true;
break;
} else if (acls.contains(acl.toString())) {
good = true;
break;
}
}
}
}
// still not good, its not allowed
if (!good) {
throw APIException.forbidden.insufficientPermissionsForUser(user.getName());
}
return request;
}
use of com.emc.storageos.db.exceptions.DatabaseException in project coprhd-controller by CoprHD.
the class BasePermissionsHelper method getRootTenant.
/**
* Returns root TenantOrg
*
* @return
*/
public TenantOrg getRootTenant() {
if (_usingCache && QueriedObjectCache.getRootTenantOrgObject() != null) {
return QueriedObjectCache.getRootTenantOrgObject();
}
URIQueryResultList tenants = new URIQueryResultList();
try {
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getTenantOrgSubTenantConstraint(URI.create(TenantOrg.NO_PARENT)), tenants);
if (tenants.iterator().hasNext()) {
URI root = tenants.iterator().next();
TenantOrg rootTenant = _dbClient.queryObject(TenantOrg.class, root);
QueriedObjectCache.setRootTenantObject(rootTenant);
// It is possible have multiple index entries for the same root tenant at a certain period (CQ610571)
while (tenants.iterator().hasNext()) {
URI mulRoot = tenants.iterator().next();
if (!mulRoot.equals(root)) {
_log.error("multiple entries found for root tenant. Stop.");
throw SecurityException.fatals.rootTenantQueryReturnedDuplicates();
}
}
return rootTenant;
} else {
_log.error("root tenant query returned no results");
}
} catch (DatabaseException ex) {
throw SecurityException.fatals.tenantQueryFailed(TenantOrg.NO_PARENT, ex);
}
throw SecurityException.fatals.tenantQueryFailed(TenantOrg.NO_PARENT);
}
use of com.emc.storageos.db.exceptions.DatabaseException in project coprhd-controller by CoprHD.
the class AuditLogManager method recordAuditLogs.
/**
* Called to record auditlogs in the database.
*
* @param events references to recordable auditlogs.
*/
public void recordAuditLogs(RecordableAuditLog... auditlogs) {
if (!shouldRecordAuditLog()) {
s_logger.info("Ignore audit log on standby site");
return;
}
AuditLog[] dbAuditLogs = new AuditLog[auditlogs.length];
int i = 0;
for (RecordableAuditLog auditlog : auditlogs) {
AuditLog dbAuditlog = AuditLogUtils.convertToAuditLog(auditlog);
dbAuditLogs[i++] = dbAuditlog;
AuditLog auditSyslog = dbAuditlog;
PropertyInfo propInfo = _coordinator.getPropertyInfo();
if (propInfo.getProperty(SYSLOG_ENALBE).equalsIgnoreCase("true")) {
Locale locale = new Locale("en", "US");
ResourceBundle resb = ResourceBundle.getBundle("SDSAuditlogRes", locale);
AuditLogUtils.resetDesc(auditSyslog, resb);
logger.info("audit log is " + dbAuditlog.getServiceType() + " " + dbAuditlog.getUserId() + " " + dbAuditlog.getOperationalStatus() + " " + dbAuditlog.getDescription());
}
}
// Now insert the events into the database.
try {
_dbClient.start();
String bucketId = _dbClient.insertTimeSeries(AuditLogTimeSeries.class, dbAuditLogs);
s_logger.info("AuditLog(s) persisted into Cassandra with bucketId/rowId : {}", bucketId);
} catch (DatabaseException e) {
s_logger.error("Error inserting auditlogs into the database", e);
throw e;
}
}
use of com.emc.storageos.db.exceptions.DatabaseException in project coprhd-controller by CoprHD.
the class IsilonCommunicationInterface method discoverAll.
public void discoverAll(AccessProfile accessProfile) throws BaseCollectionException {
URI storageSystemId = null;
StorageSystem storageSystem = null;
String detailedStatusMessage = "Unknown Status";
try {
storageSystemId = accessProfile.getSystemId();
storageSystem = _dbClient.queryObject(StorageSystem.class, storageSystemId);
// try to connect to the Isilon cluster first to check if cluster is available
IsilonApi isilonApi = getIsilonDevice(storageSystem);
isilonApi.getClusterInfo();
discoverCluster(storageSystem);
_dbClient.persistObject(storageSystem);
if (!storageSystem.getReachableStatus()) {
throw new IsilonCollectionException("Failed to connect to " + storageSystem.getIpAddress());
}
_completer.statusPending(_dbClient, "Completed cluster discovery");
List<StoragePool> poolsToMatchWithVpool = new ArrayList<StoragePool>();
List<StoragePool> allPools = new ArrayList<StoragePool>();
// discover pools
Map<String, List<StoragePool>> pools = discoverPools(storageSystem, poolsToMatchWithVpool);
_log.info("No of newly discovered pools {}", pools.get(NEW).size());
_log.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);
poolsToMatchWithVpool.addAll(notVisiblePools);
_completer.statusPending(_dbClient, "Completed pool discovery");
// discover ports
List<StoragePort> allPorts = new ArrayList<StoragePort>();
Map<String, List<StoragePort>> ports = discoverPorts(storageSystem);
_log.info("No of newly discovered ports {}", ports.get(NEW).size());
_log.info("No of existing discovered ports {}", ports.get(EXISTING).size());
if (null != ports && !ports.get(NEW).isEmpty()) {
allPorts.addAll(ports.get(NEW));
_dbClient.createObject(ports.get(NEW));
}
if (null != ports && !ports.get(EXISTING).isEmpty()) {
allPorts.addAll(ports.get(EXISTING));
_dbClient.persistObject(ports.get(EXISTING));
}
List<StoragePort> notVisiblePorts = DiscoveryUtils.checkStoragePortsNotVisible(allPorts, _dbClient, storageSystemId);
List<StoragePort> allExistPorts = new ArrayList<StoragePort>(ports.get(EXISTING));
allExistPorts.addAll(notVisiblePorts);
_completer.statusPending(_dbClient, "Completed port discovery");
StoragePortAssociationHelper.runUpdatePortAssociationsProcess(ports.get(NEW), allExistPorts, _dbClient, _coordinator, poolsToMatchWithVpool);
// discover the access zone and its network interfaces
discoverAccessZones(storageSystem);
// Update the virtual nas association with virtual arrays!!!
// For existing virtual nas ports!!
StoragePortAssociationHelper.runUpdateVirtualNasAssociationsProcess(allExistPorts, null, _dbClient);
_completer.statusPending(_dbClient, "Completed Access Zone discovery");
// discovery succeeds
detailedStatusMessage = String.format("Discovery completed successfully for Isilon: %s", storageSystemId.toString());
} catch (Exception e) {
if (storageSystem != null) {
cleanupDiscovery(storageSystem);
}
detailedStatusMessage = String.format("Discovery failed for Isilon %s because %s", storageSystemId.toString(), e.getLocalizedMessage());
_log.error(detailedStatusMessage, e);
throw new IsilonCollectionException(detailedStatusMessage);
} finally {
if (storageSystem != null) {
try {
// set detailed message
storageSystem.setLastDiscoveryStatusMessage(detailedStatusMessage);
_dbClient.persistObject(storageSystem);
} catch (DatabaseException ex) {
_log.error("Error while persisting object to DB", ex);
}
}
}
}
Aggregations