use of com.amazonaws.services.simpledb.model.SelectRequest in project siena by mandubian.
the class SdbPersistenceManager method rawGet.
protected <T> int rawGet(Iterable<T> models) {
StringBuffer domainBuf = new StringBuffer();
SelectRequest req = SdbMappingUtils.buildBatchGetQuery(models, prefix, domainBuf);
req.setConsistentRead(isReadConsistent());
try {
checkDomain(domainBuf.toString());
SelectResult res = sdb.select(req);
int nb = SdbMappingUtils.mapSelectResult(res, models);
// join management
// gets class
Class<?> clazz = null;
for (T obj : models) {
if (clazz == null) {
clazz = obj.getClass();
break;
}
}
if (!ClassInfo.getClassInfo(clazz).joinFields.isEmpty()) {
mapJoins(models);
}
return nb;
} catch (AmazonClientException ex) {
throw new SienaException(ex);
}
}
use of com.amazonaws.services.simpledb.model.SelectRequest in project SimianArmy by Netflix.
the class SimpleDBRecorder method findEvents.
/**
* Find events.
*
* @param queryMap
* the query map
* @param after
* the start time to query for all events after
* @return the list
*/
protected List<Event> findEvents(Map<String, String> queryMap, long after) {
StringBuilder query = new StringBuilder(String.format("select * from `%s` where region = '%s'", domain, region));
for (Map.Entry<String, String> pair : queryMap.entrySet()) {
query.append(String.format(" and %s = '%s'", pair.getKey(), pair.getValue()));
}
query.append(String.format(" and eventTime > '%d'", after));
// always return with most recent record first
query.append(" order by eventTime desc");
List<Event> list = new LinkedList<Event>();
SelectRequest request = new SelectRequest(query.toString());
request.setConsistentRead(Boolean.TRUE);
SelectResult result = new SelectResult();
do {
result = sdbClient().select(request.withNextToken(result.getNextToken()));
for (Item item : result.getItems()) {
Map<String, String> fields = new HashMap<String, String>();
Map<String, String> res = new HashMap<String, String>();
for (Attribute attr : item.getAttributes()) {
if (Keys.KEYSET.contains(attr.getName())) {
res.put(attr.getName(), attr.getValue());
} else {
fields.put(attr.getName(), attr.getValue());
}
}
String eid = res.get(Keys.id.name());
String ereg = res.get(Keys.region.name());
MonkeyType monkeyType = valueToEnum(MonkeyType.class, res.get(Keys.monkeyType.name()));
EventType eventType = valueToEnum(EventType.class, res.get(Keys.eventType.name()));
long eventTime = Long.parseLong(res.get(Keys.eventTime.name()));
list.add(new BasicRecorderEvent(monkeyType, eventType, ereg, eid, eventTime).addFields(fields));
}
} while (result.getNextToken() != null);
return list;
}
use of com.amazonaws.services.simpledb.model.SelectRequest in project SimianArmy by Netflix.
the class TestSimpleDBJanitorResourceTracker method testGetResources.
@Test
public void testGetResources() {
String id1 = "id-1";
String id2 = "id-2";
AWSResourceType resourceType = AWSResourceType.INSTANCE;
Resource.CleanupState state = Resource.CleanupState.MARKED;
String description = "This is a test resource.";
String ownerEmail = "owner@test.com";
String region = "us-east-1";
String terminationReason = "This is a test termination reason.";
DateTime now = DateTime.now();
Date expectedTerminationTime = new Date(now.plusDays(10).getMillis());
Date markTime = new Date(now.getMillis());
String fieldName = "fieldName123";
String fieldValue = "fieldValue456";
SelectResult result1 = mkSelectResult(id1, resourceType, state, description, ownerEmail, region, terminationReason, expectedTerminationTime, markTime, false, fieldName, fieldValue);
result1.setNextToken("nextToken");
SelectResult result2 = mkSelectResult(id2, resourceType, state, description, ownerEmail, region, terminationReason, expectedTerminationTime, markTime, true, fieldName, fieldValue);
ArgumentCaptor<SelectRequest> arg = ArgumentCaptor.forClass(SelectRequest.class);
TestSimpleDBJanitorResourceTracker tracker = new TestSimpleDBJanitorResourceTracker();
when(tracker.sdbMock.select(any(SelectRequest.class))).thenReturn(result1).thenReturn(result2);
verifyResources(tracker.getResources(resourceType, state, region), id1, id2, resourceType, state, description, ownerEmail, region, terminationReason, expectedTerminationTime, markTime, fieldName, fieldValue);
verify(tracker.sdbMock, times(2)).select(arg.capture());
}
use of com.amazonaws.services.simpledb.model.SelectRequest in project SimianArmy by Netflix.
the class TestSimpleDBRecorder method testFindEvent.
@Test
public void testFindEvent() {
SelectResult result1 = mkSelectResult("testId1");
result1.setNextToken("nextToken");
SelectResult result2 = mkSelectResult("testId2");
ArgumentCaptor<SelectRequest> arg = ArgumentCaptor.forClass(SelectRequest.class);
when(sdbMock.select(any(SelectRequest.class))).thenReturn(result1).thenReturn(result2);
Map<String, String> query = new LinkedHashMap<String, String>();
query.put("instanceId", "testId1");
verifyEvents(findEvents(query, new Date(0)));
verify(sdbMock, times(2)).select(arg.capture());
SelectRequest req = arg.getValue();
StringBuilder sb = new StringBuilder();
sb.append("select * from `DOMAIN` where region = 'region'");
sb.append(" and instanceId = 'testId1'");
Assert.assertEquals(req.getSelectExpression(), sb.toString() + " and eventTime > '0' order by eventTime desc");
// reset for next test
when(sdbMock.select(any(SelectRequest.class))).thenReturn(result1).thenReturn(result2);
verifyEvents(findEvents(Type.MONKEY, query, new Date(0)));
verify(sdbMock, times(4)).select(arg.capture());
req = arg.getValue();
sb.append(" and monkeyType = 'MONKEY|com.netflix.simianarmy.aws.TestSimpleDBRecorder$Type'");
Assert.assertEquals(req.getSelectExpression(), sb.toString() + " and eventTime > '0' order by eventTime desc");
// reset for next test
when(sdbMock.select(any(SelectRequest.class))).thenReturn(result1).thenReturn(result2);
verifyEvents(findEvents(Type.MONKEY, EventTypes.EVENT, query, new Date(0)));
verify(sdbMock, times(6)).select(arg.capture());
req = arg.getValue();
sb.append(" and eventType = 'EVENT|com.netflix.simianarmy.aws.TestSimpleDBRecorder$EventTypes'");
Assert.assertEquals(req.getSelectExpression(), sb.toString() + " and eventTime > '0' order by eventTime desc");
// reset for next test
when(sdbMock.select(any(SelectRequest.class))).thenReturn(result1).thenReturn(result2);
verifyEvents(findEvents(Type.MONKEY, EventTypes.EVENT, query, new Date(1330538400000L)));
verify(sdbMock, times(8)).select(arg.capture());
req = arg.getValue();
sb.append(" and eventTime > '1330538400000' order by eventTime desc");
Assert.assertEquals(req.getSelectExpression(), sb.toString());
}
use of com.amazonaws.services.simpledb.model.SelectRequest in project SimianArmy by Netflix.
the class SimpleDBConformityClusterTracker method querySimpleDBItems.
private List<Item> querySimpleDBItems(String query) {
Validate.notNull(query);
String nextToken = null;
List<Item> items = new ArrayList<Item>();
do {
SelectRequest request = new SelectRequest(query);
request.setNextToken(nextToken);
request.setConsistentRead(Boolean.TRUE);
SelectResult result = this.simpleDBClient.select(request);
items.addAll(result.getItems());
nextToken = result.getNextToken();
} while (nextToken != null);
return items;
}
Aggregations