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");
}
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);
}
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);
}
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();
}
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));
}
}
Aggregations