Search in sources :

Example 1 with PutAttributesRequest

use of com.amazonaws.services.simpledb.model.PutAttributesRequest in project camel by apache.

the class PutAttributesCommand method execute.

public void execute() {
    PutAttributesRequest request = new PutAttributesRequest().withDomainName(determineDomainName()).withItemName(determineItemName()).withAttributes(determineReplaceableAttributes()).withExpected(determineUpdateCondition());
    log.trace("Sending request [{}] for exchange [{}]...", request, exchange);
    this.sdbClient.putAttributes(request);
    log.trace("Request sent");
}
Also used : PutAttributesRequest(com.amazonaws.services.simpledb.model.PutAttributesRequest)

Example 2 with PutAttributesRequest

use of com.amazonaws.services.simpledb.model.PutAttributesRequest in project SimianArmy by Netflix.

the class SimpleDBRecorder method recordEvent.

/** {@inheritDoc} */
@Override
public void recordEvent(Event evt) {
    String evtTime = String.valueOf(evt.eventTime().getTime());
    List<ReplaceableAttribute> attrs = new LinkedList<ReplaceableAttribute>();
    attrs.add(new ReplaceableAttribute(Keys.id.name(), evt.id(), true));
    attrs.add(new ReplaceableAttribute(Keys.eventTime.name(), evtTime, true));
    attrs.add(new ReplaceableAttribute(Keys.region.name(), evt.region(), true));
    attrs.add(new ReplaceableAttribute(Keys.recordType.name(), "MonkeyEvent", true));
    attrs.add(new ReplaceableAttribute(Keys.monkeyType.name(), enumToValue(evt.monkeyType()), true));
    attrs.add(new ReplaceableAttribute(Keys.eventType.name(), enumToValue(evt.eventType()), true));
    for (Map.Entry<String, String> pair : evt.fields().entrySet()) {
        if (pair.getValue() == null || pair.getValue().equals("") || Keys.KEYSET.contains(pair.getKey())) {
            continue;
        }
        attrs.add(new ReplaceableAttribute(pair.getKey(), pair.getValue(), true));
    }
    // Let pk contain the timestamp so that the same resource can have multiple events.
    String pk = String.format("%s-%s-%s-%s", evt.monkeyType().name(), evt.id(), region, evtTime);
    PutAttributesRequest putReq = new PutAttributesRequest(domain, pk, attrs);
    sdbClient().putAttributes(putReq);
}
Also used : PutAttributesRequest(com.amazonaws.services.simpledb.model.PutAttributesRequest) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedList(java.util.LinkedList) ReplaceableAttribute(com.amazonaws.services.simpledb.model.ReplaceableAttribute)

Example 3 with PutAttributesRequest

use of com.amazonaws.services.simpledb.model.PutAttributesRequest in project SimianArmy by Netflix.

the class TestSimpleDBRecorder method testRecordEvent.

@Test
public void testRecordEvent() {
    ArgumentCaptor<PutAttributesRequest> arg = ArgumentCaptor.forClass(PutAttributesRequest.class);
    Event evt = newEvent(Type.MONKEY, EventTypes.EVENT, "region", "testId");
    evt.addField("field1", "value1");
    evt.addField("field2", "value2");
    // this will be ignored as it conflicts with reserved key
    evt.addField("id", "ignoreThis");
    recordEvent(evt);
    verify(sdbMock).putAttributes(arg.capture());
    PutAttributesRequest req = arg.getValue();
    Assert.assertEquals(req.getDomainName(), "DOMAIN");
    Assert.assertEquals(req.getItemName(), "MONKEY-testId-region-" + evt.eventTime().getTime());
    Map<String, String> map = new HashMap<String, String>();
    for (ReplaceableAttribute attr : req.getAttributes()) {
        map.put(attr.getName(), attr.getValue());
    }
    Assert.assertEquals(map.remove("id"), "testId");
    Assert.assertEquals(map.remove("eventTime"), String.valueOf(evt.eventTime().getTime()));
    Assert.assertEquals(map.remove("region"), "region");
    Assert.assertEquals(map.remove("recordType"), "MonkeyEvent");
    Assert.assertEquals(map.remove("monkeyType"), "MONKEY|com.netflix.simianarmy.aws.TestSimpleDBRecorder$Type");
    Assert.assertEquals(map.remove("eventType"), "EVENT|com.netflix.simianarmy.aws.TestSimpleDBRecorder$EventTypes");
    Assert.assertEquals(map.remove("field1"), "value1");
    Assert.assertEquals(map.remove("field2"), "value2");
    Assert.assertEquals(map.size(), 0);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) PutAttributesRequest(com.amazonaws.services.simpledb.model.PutAttributesRequest) ReplaceableAttribute(com.amazonaws.services.simpledb.model.ReplaceableAttribute) Test(org.testng.annotations.Test)

Example 4 with PutAttributesRequest

use of com.amazonaws.services.simpledb.model.PutAttributesRequest in project simplejpa by appoxy.

the class UtilTests method rename.

@Ignore("Rename feature is currently broken")
@Test
public void rename() throws IOException, ExecutionException, InterruptedException, AmazonClientException {
    EntityManagerSimpleJPA em = (EntityManagerSimpleJPA) factory.createEntityManager();
    AmazonSimpleDB db = em.getSimpleDb();
    String domainName = em.getFactory().getDomainName(MyTestObject.class);
    em.getFactory().createIfNotExistDomain(domainName);
    String id = "abc123";
    List<ReplaceableAttribute> atts = new ArrayList<ReplaceableAttribute>();
    atts.add(new ReplaceableAttribute("id", id, true));
    atts.add(new ReplaceableAttribute("nameOld", "Bullwinkle", true));
    db.putAttributes(new PutAttributesRequest().withDomainName(domainName).withItemName(id).withAttributes(atts));
    MyTestObject object;
    object = em.find(MyTestObject.class, id);
    Assert.assertNull(object.getName());
    System.out.println("name before renameField = " + object.getName());
    Assert.assertEquals(id, object.getId());
    em.renameField(MyTestObject.class, "nameOld", "name");
    em.close();
    // now find it again and the name should be good
    em = (EntityManagerSimpleJPA) factory.createEntityManager();
    object = em.find(MyTestObject.class, id);
    Assert.assertEquals("Bullwinkle", object.getName());
    System.out.println("name after renameField = " + object.getName());
    Assert.assertEquals(id, object.getId());
    // now delete object
    em.remove(object);
    // and make sure it's gone
    object = em.find(MyTestObject.class, object.getId());
    Assert.assertNull(object);
    em.close();
}
Also used : AmazonSimpleDB(com.amazonaws.services.simpledb.AmazonSimpleDB) ArrayList(java.util.ArrayList) PutAttributesRequest(com.amazonaws.services.simpledb.model.PutAttributesRequest) ReplaceableAttribute(com.amazonaws.services.simpledb.model.ReplaceableAttribute)

Example 5 with PutAttributesRequest

use of com.amazonaws.services.simpledb.model.PutAttributesRequest in project simplejpa by appoxy.

the class DomainHelperTests method selectItemsTests.

@Test
public void selectItemsTests() {
    EntityManagerSimpleJPA em = (EntityManagerSimpleJPA) factory.createEntityManager();
    AmazonSimpleDB sdbClient = em.getSimpleDb();
    String domainName = "simplejpa-domainhelper-tests";
    sdbClient.createDomain(new CreateDomainRequest().withDomainName(domainName));
    try {
        for (int i = 0; i < 10; i++) {
            sdbClient.putAttributes(new PutAttributesRequest().withItemName("thing" + i).withDomainName(domainName).withAttributes(new ReplaceableAttribute("name", "value", true)));
        }
        SelectResult result = DomainHelper.selectItems(sdbClient, String.format("select * from `%s` LIMIT 3", domainName), null);
        Assert.assertEquals(3, result.getItems().size());
        Assert.assertNotNull(result.getNextToken());
        result = DomainHelper.selectItems(sdbClient, String.format("select * from `%s` LIMIT 3", domainName), result.getNextToken());
        Assert.assertEquals(3, result.getItems().size());
        Assert.assertNotNull(result.getNextToken());
        result = DomainHelper.selectItems(sdbClient, String.format("select * from `%s` LIMIT 3", domainName), result.getNextToken());
        Assert.assertEquals(3, result.getItems().size());
        Assert.assertNotNull(result.getNextToken());
        result = DomainHelper.selectItems(sdbClient, String.format("select * from `%s` LIMIT 3", domainName), result.getNextToken());
        Assert.assertEquals(1, result.getItems().size());
        Assert.assertNull(result.getNextToken());
    } finally {
        sdbClient.deleteDomain(new DeleteDomainRequest().withDomainName(domainName));
    }
}
Also used : SelectResult(com.amazonaws.services.simpledb.model.SelectResult) DeleteDomainRequest(com.amazonaws.services.simpledb.model.DeleteDomainRequest) AmazonSimpleDB(com.amazonaws.services.simpledb.AmazonSimpleDB) CreateDomainRequest(com.amazonaws.services.simpledb.model.CreateDomainRequest) PutAttributesRequest(com.amazonaws.services.simpledb.model.PutAttributesRequest) ReplaceableAttribute(com.amazonaws.services.simpledb.model.ReplaceableAttribute) Test(org.junit.Test)

Aggregations

PutAttributesRequest (com.amazonaws.services.simpledb.model.PutAttributesRequest)15 ReplaceableAttribute (com.amazonaws.services.simpledb.model.ReplaceableAttribute)14 AmazonSimpleDB (com.amazonaws.services.simpledb.AmazonSimpleDB)8 CreateDomainRequest (com.amazonaws.services.simpledb.model.CreateDomainRequest)4 DeleteDomainRequest (com.amazonaws.services.simpledb.model.DeleteDomainRequest)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 Item (com.amazonaws.services.simpledb.model.Item)3 Attribute (com.amazonaws.services.simpledb.model.Attribute)2 DeleteAttributesRequest (com.amazonaws.services.simpledb.model.DeleteAttributesRequest)2 SelectResult (com.amazonaws.services.simpledb.model.SelectResult)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 Test (org.testng.annotations.Test)2 AmazonS3 (com.amazonaws.services.s3.AmazonS3)1 GetAttributesRequest (com.amazonaws.services.simpledb.model.GetAttributesRequest)1 GetAttributesResult (com.amazonaws.services.simpledb.model.GetAttributesResult)1 UpdateCondition (com.amazonaws.services.simpledb.model.UpdateCondition)1 Resource (com.netflix.simianarmy.Resource)1