use of com.netflix.simianarmy.MonkeyType 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.MonkeyType 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.MonkeyType 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;
}
use of com.netflix.simianarmy.MonkeyType in project SimianArmy by Netflix.
the class TestBasicRecorderEvent method test.
@Test
public void test() {
MonkeyType monkeyType = Types.MONKEY;
EventType eventType = EventTypes.EVENT;
BasicRecorderEvent evt = new BasicRecorderEvent(monkeyType, eventType, "region", "test-id");
testEvent(evt);
// CHECKSTYLE IGNORE MagicNumberCheck
long time = 1330538400000L;
evt = new BasicRecorderEvent(monkeyType, eventType, "region", "test-id", time);
testEvent(evt);
Assert.assertEquals(evt.eventTime().getTime(), time);
}
Aggregations