use of com.emc.storageos.db.exceptions.DatabaseException in project coprhd-controller by CoprHD.
the class UserFromRequestHelper method parseOldFormat.
/**
* This method parses the userContext information using the "old" format
* ( "user,user@domain.com;group,group2")
* TODO: once AD integration is complete and attribute release is only
* available through that channel, this old format should be removed. For
* now, keeping for backwards compatibility and so that authz testing can
* continue without AD servers.
*
* @param userContext
* @return a UserFromRequest pojo
*/
private StorageOSUser parseOldFormat(String userContext) {
StorageOSUser user = null;
if (!StringUtils.isBlank(userContext)) {
String[] userInfo = userContext.split(";");
String[] userAttributes = userInfo[0].split(",");
String name = userAttributes[0];
String[] parts = name.split("@");
String domain = "";
if (parts.length > 1) {
domain = parts[1];
}
URI tenant = null;
boolean local = false;
if (userAttributes.length > 1 && null != userAttributes[1] && !StringUtils.isBlank(userAttributes[1])) {
String[] attrKV = userAttributes[1].split("=");
if (attrKV[0].equals(USERDETAILS_LOCALUSER)) {
if (attrKV.length > 1 && Boolean.valueOf(attrKV[1])) {
local = true;
}
} else {
UserMapping mapping = new UserMapping();
mapping.setDomain(domain);
if (attrKV.length > 1) {
if (attrKV[0].equalsIgnoreCase("group")) {
mapping.setGroups(Collections.singletonList(attrKV[1]));
} else {
UserMappingAttribute tenantAttribute = new UserMappingAttribute();
tenantAttribute.setKey(attrKV[0]);
tenantAttribute.setValues(Collections.singletonList(attrKV[1]));
}
try {
tenant = _permissionsHelper.lookupTenant(mapping);
} catch (DatabaseException e) {
_logger.error("Failed to query for tenant with attribute: {}. Exception {} ", mapping.toString(), e);
}
}
}
} else if (!domain.isEmpty()) {
UserMapping mapping = new UserMapping();
mapping.setDomain(domain);
try {
tenant = _permissionsHelper.lookupTenant(mapping);
} catch (DatabaseException e) {
_logger.error("Failed to query for tenant with attribute: {}. Exception {} ", mapping.toString(), e);
}
}
if (null == tenant) {
tenant = _permissionsHelper.getRootTenant().getId();
}
user = new StorageOSUser(name, tenant.toString());
user.setIsLocal(local);
if (userInfo.length > 1) {
String[] groups = org.springframework.util.StringUtils.commaDelimitedListToStringArray(userInfo[1]);
if (groups.length > 0) {
for (String group : groups) {
user.addGroup(group);
}
}
}
return user;
}
return null;
}
use of com.emc.storageos.db.exceptions.DatabaseException in project coprhd-controller by CoprHD.
the class DBClient method queryAndPrintRecords.
/**
* Query for records with the given ids and type, and print the contents in human readable format
*
* @param ids
* @param clazz
* @param <T>
*/
private <T extends DataObject> int queryAndPrintRecords(List<URI> ids, Class<T> clazz, Map<String, String> criterias) throws Exception {
int countLimit = 0;
int countAll = 0;
String input;
BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
boolean isPrint = true;
try {
Iterator<URI> uriIter = ids.iterator();
while (uriIter.hasNext()) {
URI uri = uriIter.next();
T object = (T) _dbClient.queryObject(uri);
if (object == null) {
continue;
}
isPrint = printBeanProperties(clazz, object, criterias);
if (isPrint) {
countLimit++;
countAll++;
}
if (!turnOnLimit || countLimit != listLimit) {
continue;
}
System.out.println(String.format("Read %s rows ", countAll));
do {
System.out.println("\nPress 'ENTER' to continue or 'q<ENTER>' to quit...");
input = buf.readLine();
if (input.isEmpty()) {
countLimit = 0;
break;
}
if (input.equalsIgnoreCase(QUITCHAR)) {
return countAll;
}
} while (!input.isEmpty());
}
} catch (DatabaseException ex) {
log.error("Error querying from db: " + ex);
System.err.println("Error querying from db: " + ex);
throw ex;
} finally {
buf.close();
}
return countAll;
}
use of com.emc.storageos.db.exceptions.DatabaseException in project coprhd-controller by CoprHD.
the class DbCli method queryAndPrintRecords.
/**
* Query for records with the given ids and type, and print the contents in human readable format
*
* @param ids
* @param clazz
* @param <T>
*/
private <T extends DataObject> int queryAndPrintRecords(List<URI> ids, Class<T> clazz) throws Exception {
Iterator<T> objects;
BeanInfo bInfo;
int countLimit = 0;
int countAll = 0;
String input;
BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
try {
objects = _dbClient.queryIterativeObjects(clazz, ids);
bInfo = Introspector.getBeanInfo(clazz);
while (objects.hasNext()) {
T object = (T) objects.next();
printBeanProperties(bInfo.getPropertyDescriptors(), object);
countLimit++;
countAll++;
if (!turnOnLimit || countLimit != listLimit) {
continue;
}
System.out.println(String.format("Read %s rows ", countAll));
do {
System.out.println("\nPress 'ENTER' to continue or 'q<ENTER>' to quit...");
input = buf.readLine();
if (input.isEmpty()) {
countLimit = 0;
break;
}
if (input.equalsIgnoreCase(QUITCHAR)) {
return countAll;
}
} while (!input.isEmpty());
}
} catch (DatabaseException ex) {
log.error("Error querying from db: " + ex);
System.out.println("Error querying from db: " + ex);
throw ex;
} catch (IntrospectionException ex) {
log.error("Unexpected exception getting bean info", ex);
throw new RuntimeException("Unexpected exception getting bean info", ex);
} finally {
buf.close();
}
return countAll;
}
use of com.emc.storageos.db.exceptions.DatabaseException in project coprhd-controller by CoprHD.
the class DBClient method queryForCustomDayAudits.
/**
* Query audit
*
* @param dateTime
*/
public void queryForCustomDayAudits(DateTime dateTime, String filename) {
System.out.println("\n\n -> Querying Audits");
ExecutorService executor = Executors.newFixedThreadPool(100);
AuditQueryResult result = new AuditQueryResult(filename);
try {
_dbClient.queryTimeSeries(AuditLogTimeSeries.class, dateTime, TimeSeriesMetadata.TimeBucket.HOUR, result, executor);
System.out.println(" --- Job Exceution for Querying Audits completed ---\n\n");
return;
} catch (DatabaseException e) {
System.err.println("Exception Query " + e);
log.error("Exception Query ", e);
}
}
use of com.emc.storageos.db.exceptions.DatabaseException in project coprhd-controller by CoprHD.
the class ScheduledEventService method deactivateScheduledEvent.
/**
* Deactivates the scheduled event and its orders
*
* @param id the URN of a scheduled event to be deactivated
* @return OK if deactivation completed successfully
* @throws DatabaseException when a DB error occurs
*/
@POST
@Path("/{id}/deactivate")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN })
public Response deactivateScheduledEvent(@PathParam("id") String id) throws DatabaseException {
ScheduledEvent scheduledEvent = queryResource(uri(id));
ArgValidator.checkEntity(scheduledEvent, uri(id), true);
// deactivate all the orders from the scheduled event
URIQueryResultList resultList = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getScheduledEventOrderConstraint(uri(id)), resultList);
for (URI uri : resultList) {
log.info("deleting order: {}", uri);
Order order = _dbClient.queryObject(Order.class, uri);
client.delete(order);
}
try {
log.info("Deleting a scheduledEvent {}:{}", scheduledEvent.getId(), ScheduleInfo.deserialize(org.apache.commons.codec.binary.Base64.decodeBase64(scheduledEvent.getScheduleInfo().getBytes(UTF_8))).toString());
} catch (Exception e) {
log.error("Failed to parse scheduledEvent.");
}
// deactivate the scheduled event
client.delete(scheduledEvent);
return Response.ok().build();
}
Aggregations