Search in sources :

Example 11 with PutAttributesRequest

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

the class EntityManagerSimpleJPA method putAndDelete.

private void putAndDelete(String domainName, String oldAttributeName, String newAttributeName, List<Item> items) throws AmazonClientException {
    AmazonSimpleDB db = factory.getSimpleDb();
    for (Item item : items) {
        GetAttributesResult getOldResults = db.getAttributes(new GetAttributesRequest().withDomainName(domainName).withConsistentRead(true).withItemName(item.getName()).withAttributeNames(oldAttributeName));
        List<Attribute> oldAtts = getOldResults.getAttributes();
        if (oldAtts.size() > 0) {
            Attribute oldAtt = oldAtts.get(0);
            List<ReplaceableAttribute> atts = new ArrayList<ReplaceableAttribute>();
            atts.add(new ReplaceableAttribute(newAttributeName, oldAtt.getValue(), true));
            db.putAttributes(new PutAttributesRequest().withDomainName(domainName).withItemName(item.getName()).withAttributes(atts));
            db.deleteAttributes(new DeleteAttributesRequest().withDomainName(domainName).withItemName(item.getName()).withAttributes(oldAtts));
        }
    }
}
Also used : Item(com.amazonaws.services.simpledb.model.Item) Attribute(com.amazonaws.services.simpledb.model.Attribute) ReplaceableAttribute(com.amazonaws.services.simpledb.model.ReplaceableAttribute) AmazonSimpleDB(com.amazonaws.services.simpledb.AmazonSimpleDB) PutAttributesRequest(com.amazonaws.services.simpledb.model.PutAttributesRequest) DeleteAttributesRequest(com.amazonaws.services.simpledb.model.DeleteAttributesRequest) GetAttributesRequest(com.amazonaws.services.simpledb.model.GetAttributesRequest) GetAttributesResult(com.amazonaws.services.simpledb.model.GetAttributesResult) ReplaceableAttribute(com.amazonaws.services.simpledb.model.ReplaceableAttribute)

Example 12 with PutAttributesRequest

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

the class EntityManagerSimpleJPA method putNewValue.

private void putNewValue(String domainName, List<Item> items, String dtype, String newClassName) throws AmazonClientException {
    AmazonSimpleDB db = factory.getSimpleDb();
    for (Item item : items) {
        List<ReplaceableAttribute> atts = new ArrayList<ReplaceableAttribute>();
        atts.add(new ReplaceableAttribute(dtype, newClassName, true));
        db.putAttributes(new PutAttributesRequest(domainName, item.getName(), atts));
    }
}
Also used : Item(com.amazonaws.services.simpledb.model.Item) AmazonSimpleDB(com.amazonaws.services.simpledb.AmazonSimpleDB) PutAttributesRequest(com.amazonaws.services.simpledb.model.PutAttributesRequest) ReplaceableAttribute(com.amazonaws.services.simpledb.model.ReplaceableAttribute)

Example 13 with PutAttributesRequest

use of com.amazonaws.services.simpledb.model.PutAttributesRequest in project siena by mandubian.

the class SdbMappingUtils method createPutRequest.

public static PutAttributesRequest createPutRequest(String domain, Class<?> clazz, ClassInfo info, Object obj) {
    PutAttributesRequest req = new PutAttributesRequest().withDomainName(domain);
    req.withItemName(getItemName(clazz, obj));
    for (Field field : ClassInfo.getClassInfo(clazz).updateFields) {
        try {
            String value = objectFieldToString(obj, field);
            if (value != null) {
                ReplaceableAttribute attr = new ReplaceableAttribute(getAttributeName(field), value, true);
                req.withAttributes(attr);
            } else {
                if (ClassInfo.isEmbeddedNative(field)) {
                    SdbNativeSerializer.embed(req, ClassInfo.getSingleColumnName(field), value);
                }
            }
        } catch (Exception e) {
            throw new SienaException(e);
        }
    }
    return req;
}
Also used : Field(java.lang.reflect.Field) PutAttributesRequest(com.amazonaws.services.simpledb.model.PutAttributesRequest) SienaException(siena.SienaException) SienaException(siena.SienaException) SienaRestrictedApiException(siena.SienaRestrictedApiException) IOException(java.io.IOException) ReplaceableAttribute(com.amazonaws.services.simpledb.model.ReplaceableAttribute)

Example 14 with PutAttributesRequest

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

the class SimpleDBConformityClusterTracker method addOrUpdate.

/** {@inheritDoc} */
@Override
public void addOrUpdate(Cluster cluster) {
    List<ReplaceableAttribute> attrs = new ArrayList<ReplaceableAttribute>();
    Map<String, String> fieldToValueMap = cluster.getFieldToValueMap();
    for (Map.Entry<String, String> entry : fieldToValueMap.entrySet()) {
        attrs.add(new ReplaceableAttribute(entry.getKey(), StringUtils.left(entry.getValue(), MAX_ATTR_SIZE), true));
    }
    PutAttributesRequest putReqest = new PutAttributesRequest(domain, getSimpleDBItemName(cluster), attrs);
    LOGGER.debug(String.format("Saving cluster %s to SimpleDB domain %s", cluster.getName(), domain));
    this.simpleDBClient.putAttributes(putReqest);
    LOGGER.debug("Successfully saved.");
}
Also used : ArrayList(java.util.ArrayList) PutAttributesRequest(com.amazonaws.services.simpledb.model.PutAttributesRequest) HashMap(java.util.HashMap) Map(java.util.Map) ReplaceableAttribute(com.amazonaws.services.simpledb.model.ReplaceableAttribute)

Example 15 with PutAttributesRequest

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

the class TestSimpleDBJanitorResourceTracker method testAddResource.

@Test
public void testAddResource() {
    String id = "i-12345678901234567";
    AWSResourceType resourceType = AWSResourceType.INSTANCE;
    Resource.CleanupState state = Resource.CleanupState.MARKED;
    String description = "This is a test resource.";
    String ownerEmail = "owner@test.com";
    String region = "us-east-1";
    String terminationReason = "This is a test termination reason.";
    DateTime now = DateTime.now();
    Date expectedTerminationTime = new Date(now.plusDays(10).getMillis());
    Date markTime = new Date(now.getMillis());
    String fieldName = "fieldName123";
    String fieldValue = "fieldValue456";
    Resource resource = new AWSResource().withId(id).withResourceType(resourceType).withDescription(description).withOwnerEmail(ownerEmail).withRegion(region).withState(state).withTerminationReason(terminationReason).withExpectedTerminationTime(expectedTerminationTime).withMarkTime(markTime).withOptOutOfJanitor(false).setAdditionalField(fieldName, fieldValue);
    ArgumentCaptor<PutAttributesRequest> arg = ArgumentCaptor.forClass(PutAttributesRequest.class);
    TestSimpleDBJanitorResourceTracker tracker = new TestSimpleDBJanitorResourceTracker();
    tracker.addOrUpdate(resource);
    verify(tracker.sdbMock).putAttributes(arg.capture());
    PutAttributesRequest req = arg.getValue();
    Assert.assertEquals(req.getDomainName(), "DOMAIN");
    Assert.assertEquals(req.getItemName(), getSimpleDBItemName(resource));
    Map<String, String> map = new HashMap<String, String>();
    for (ReplaceableAttribute attr : req.getAttributes()) {
        map.put(attr.getName(), attr.getValue());
    }
    Assert.assertEquals(map.remove(AWSResource.FIELD_RESOURCE_ID), id);
    Assert.assertEquals(map.remove(AWSResource.FIELD_DESCRIPTION), description);
    Assert.assertEquals(map.remove(AWSResource.FIELD_EXPECTED_TERMINATION_TIME), AWSResource.DATE_FORMATTER.print(expectedTerminationTime.getTime()));
    Assert.assertEquals(map.remove(AWSResource.FIELD_MARK_TIME), AWSResource.DATE_FORMATTER.print(markTime.getTime()));
    Assert.assertEquals(map.remove(AWSResource.FIELD_REGION), region);
    Assert.assertEquals(map.remove(AWSResource.FIELD_OWNER_EMAIL), ownerEmail);
    Assert.assertEquals(map.remove(AWSResource.FIELD_RESOURCE_TYPE), resourceType.name());
    Assert.assertEquals(map.remove(AWSResource.FIELD_STATE), state.name());
    Assert.assertEquals(map.remove(AWSResource.FIELD_TERMINATION_REASON), terminationReason);
    Assert.assertEquals(map.remove(AWSResource.FIELD_OPT_OUT_OF_JANITOR), "false");
    Assert.assertEquals(map.remove(fieldName), fieldValue);
    Assert.assertEquals(map.size(), 0);
}
Also used : HashMap(java.util.HashMap) AWSResource(com.netflix.simianarmy.aws.AWSResource) Resource(com.netflix.simianarmy.Resource) DateTime(org.joda.time.DateTime) Date(java.util.Date) ReplaceableAttribute(com.amazonaws.services.simpledb.model.ReplaceableAttribute) AWSResourceType(com.netflix.simianarmy.aws.AWSResourceType) AWSResource(com.netflix.simianarmy.aws.AWSResource) PutAttributesRequest(com.amazonaws.services.simpledb.model.PutAttributesRequest) Test(org.testng.annotations.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