use of com.netflix.simianarmy.basic.BasicRecorderEvent 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.netflix.simianarmy.basic.BasicRecorderEvent in project SimianArmy by Netflix.
the class TestChaosMonkeyResource method mkEvent.
private MonkeyRecorder.Event mkEvent(String instance) {
final MonkeyType monkeyType = ChaosMonkey.Type.CHAOS;
final EventType eventType = ChaosMonkey.EventTypes.CHAOS_TERMINATION;
// SUPPRESS CHECKSTYLE MagicNumber
return new BasicRecorderEvent(monkeyType, eventType, "region", instance, 1330538400000L).addField("groupType", "ASG").addField("groupName", "testGroup");
}
use of com.netflix.simianarmy.basic.BasicRecorderEvent in project SimianArmy by Netflix.
the class TestRDSRecorder method testFindEvent.
@SuppressWarnings("unchecked")
@Test
public void testFindEvent() {
Event evt1 = new BasicRecorderEvent(Type.MONKEY, EventTypes.EVENT, "region", "testId1", 1330538400000L);
mkSelectResult("testId1", evt1);
Event evt2 = new BasicRecorderEvent(Type.MONKEY, EventTypes.EVENT, "region", "testId2", 1330538400000L);
mkSelectResult("testId2", evt2);
ArrayList<Event> events = new ArrayList<>();
TestRDSRecorder recorder = new TestRDSRecorder();
events.add(evt1);
events.add(evt2);
when(recorder.getJdbcTemplate().query(Matchers.anyString(), Matchers.argThat(new ArgumentMatcher<Object[]>() {
@Override
public boolean matches(Object argument) {
Object[] args = (Object[]) argument;
Assert.assertTrue(args[0] instanceof String);
Assert.assertEquals((String) args[0], REGION);
return true;
}
}), Matchers.any(RowMapper.class))).thenReturn(events);
Map<String, String> query = new LinkedHashMap<String, String>();
query.put("instanceId", "testId1");
verifyEvents(recorder.findEvents(query, new Date(0)));
}
use of com.netflix.simianarmy.basic.BasicRecorderEvent in project SimianArmy by Netflix.
the class RDSRecorder method mapEvent.
private Event mapEvent(ResultSet rs) throws SQLException {
String json = rs.getString("dataJson");
ObjectMapper mapper = new ObjectMapper();
Event event = null;
try {
String id = rs.getString(FIELD_ID);
MonkeyType monkeyType = SimpleDBRecorder.valueToEnum(MonkeyType.class, rs.getString(FIELD_MONKEY_TYPE));
EventType eventType = SimpleDBRecorder.valueToEnum(EventType.class, rs.getString(FIELD_EVENT_TYPE));
String region = rs.getString(FIELD_REGION);
long time = rs.getLong(FIELD_EVENT_TIME);
event = new BasicRecorderEvent(monkeyType, eventType, region, id, time);
TypeReference<Map<String, String>> typeRef = new TypeReference<Map<String, String>>() {
};
Map<String, String> map = mapper.readValue(json, typeRef);
for (String key : map.keySet()) {
event.addField(key, map.get(key));
}
} catch (IOException ie) {
LOGGER.error("Error parsing resource from json", ie);
}
return event;
}
Aggregations