Search in sources :

Example 1 with EventType

use of com.netflix.simianarmy.EventType 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;
}
Also used : MonkeyType(com.netflix.simianarmy.MonkeyType) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Attribute(com.amazonaws.services.simpledb.model.Attribute) ReplaceableAttribute(com.amazonaws.services.simpledb.model.ReplaceableAttribute) EventType(com.netflix.simianarmy.EventType) BasicRecorderEvent(com.netflix.simianarmy.basic.BasicRecorderEvent) LinkedList(java.util.LinkedList) SelectResult(com.amazonaws.services.simpledb.model.SelectResult) Item(com.amazonaws.services.simpledb.model.Item) BasicRecorderEvent(com.netflix.simianarmy.basic.BasicRecorderEvent) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) SelectRequest(com.amazonaws.services.simpledb.model.SelectRequest)

Example 2 with EventType

use of com.netflix.simianarmy.EventType 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");
}
Also used : MonkeyType(com.netflix.simianarmy.MonkeyType) EventType(com.netflix.simianarmy.EventType) BasicRecorderEvent(com.netflix.simianarmy.basic.BasicRecorderEvent)

Example 3 with EventType

use of com.netflix.simianarmy.EventType 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;
}
Also used : MonkeyType(com.netflix.simianarmy.MonkeyType) EventType(com.netflix.simianarmy.EventType) BasicRecorderEvent(com.netflix.simianarmy.basic.BasicRecorderEvent) BasicRecorderEvent(com.netflix.simianarmy.basic.BasicRecorderEvent) TypeReference(com.fasterxml.jackson.core.type.TypeReference) IOException(java.io.IOException) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 4 with EventType

use of com.netflix.simianarmy.EventType 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);
}
Also used : MonkeyType(com.netflix.simianarmy.MonkeyType) EventType(com.netflix.simianarmy.EventType) Test(org.testng.annotations.Test)

Aggregations

EventType (com.netflix.simianarmy.EventType)4 MonkeyType (com.netflix.simianarmy.MonkeyType)4 BasicRecorderEvent (com.netflix.simianarmy.basic.BasicRecorderEvent)3 Map (java.util.Map)2 Attribute (com.amazonaws.services.simpledb.model.Attribute)1 Item (com.amazonaws.services.simpledb.model.Item)1 ReplaceableAttribute (com.amazonaws.services.simpledb.model.ReplaceableAttribute)1 SelectRequest (com.amazonaws.services.simpledb.model.SelectRequest)1 SelectResult (com.amazonaws.services.simpledb.model.SelectResult)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 Test (org.testng.annotations.Test)1