use of com.amazonaws.services.dynamodbv2.document.AttributeUpdate in project spring-integration-aws by spring-projects.
the class DynamoDbMetaDataStore method putIfAbsent.
@Override
public String putIfAbsent(String key, String value) {
Assert.hasText(key, "'key' must not be empty.");
Assert.hasText(value, "'value' must not be empty.");
awaitForActive();
try {
this.table.updateItem(new UpdateItemSpec().withPrimaryKey(KEY, key).withAttributeUpdate(new AttributeUpdate(VALUE).put(value)).withExpected(new Expected(KEY).notExist()));
return null;
} catch (ConditionalCheckFailedException e) {
return get(key);
}
}
use of com.amazonaws.services.dynamodbv2.document.AttributeUpdate in project spring-integration-aws by spring-projects.
the class DynamoDbMetaDataStore method replace.
@Override
public boolean replace(String key, String oldValue, String newValue) {
Assert.hasText(key, "'key' must not be empty.");
Assert.hasText(oldValue, "'value' must not be empty.");
Assert.hasText(newValue, "'newValue' must not be empty.");
awaitForActive();
try {
return this.table.updateItem(new UpdateItemSpec().withPrimaryKey(KEY, key).withAttributeUpdate(new AttributeUpdate(VALUE).put(newValue)).withExpected(new Expected(VALUE).eq(oldValue)).withReturnValues(ReturnValue.UPDATED_NEW)).getItem() != null;
} catch (ConditionalCheckFailedException e) {
return false;
}
}
use of com.amazonaws.services.dynamodbv2.document.AttributeUpdate in project athenz by yahoo.
the class DynamoDBSSHRecordStoreConnection method updateSSHCertRecord.
@Override
public boolean updateSSHCertRecord(SSHCertRecord certRecord) {
final String primaryKey = getPrimaryKey(certRecord.getInstanceId(), certRecord.getService());
try {
UpdateItemSpec updateItemSpec = new UpdateItemSpec().withPrimaryKey(KEY_PRIMARY, primaryKey).withAttributeUpdate(new AttributeUpdate(KEY_INSTANCE_ID).put(certRecord.getInstanceId()), new AttributeUpdate(KEY_SERVICE).put(certRecord.getService()), new AttributeUpdate(KEY_CLIENT_IP).put(certRecord.getClientIP()), new AttributeUpdate(KEY_PRINCIPALS).put(certRecord.getPrincipals()), new AttributeUpdate(KEY_PRIVATE_IP).put(certRecord.getPrivateIP()), new AttributeUpdate(KEY_TTL).put(System.currentTimeMillis() / 1000L + expiryTime));
table.updateItem(updateItemSpec);
return true;
} catch (Exception ex) {
LOGGER.error("DynamoDB Update Error for {}: {}/{}", primaryKey, ex.getClass(), ex.getMessage());
return false;
}
}
use of com.amazonaws.services.dynamodbv2.document.AttributeUpdate in project athenz by yahoo.
the class DynamoDBCertRecordStoreConnection method updateX509CertRecord.
@Override
public boolean updateX509CertRecord(X509CertRecord certRecord) {
final String primaryKey = getPrimaryKey(certRecord.getProvider(), certRecord.getInstanceId(), certRecord.getService());
if (certRecord.getSvcDataUpdateTime() == null) {
certRecord.setSvcDataUpdateTime(new Date());
}
String hostName = certRecord.getHostName();
// Prevent inserting null values in hostName as the hostName-Index will not allow it
if (StringUtil.isEmpty(hostName)) {
hostName = primaryKey;
}
try {
UpdateItemSpec updateItemSpec = new UpdateItemSpec().withPrimaryKey(KEY_PRIMARY, primaryKey).withAttributeUpdate(new AttributeUpdate(KEY_INSTANCE_ID).put(certRecord.getInstanceId()), new AttributeUpdate(KEY_PROVIDER).put(certRecord.getProvider()), new AttributeUpdate(KEY_SERVICE).put(certRecord.getService()), new AttributeUpdate(KEY_CURRENT_SERIAL).put(certRecord.getCurrentSerial()), new AttributeUpdate(KEY_CURRENT_IP).put(certRecord.getCurrentIP()), new AttributeUpdate(KEY_CURRENT_TIME).put(DynamoDBUtils.getLongFromDate(certRecord.getCurrentTime())), new AttributeUpdate(KEY_CURRENT_DATE).put(DynamoDBUtils.getIso8601FromDate(certRecord.getCurrentTime())), new AttributeUpdate(KEY_PREV_SERIAL).put(certRecord.getPrevSerial()), new AttributeUpdate(KEY_PREV_IP).put(certRecord.getPrevIP()), new AttributeUpdate(KEY_PREV_TIME).put(DynamoDBUtils.getLongFromDate(certRecord.getPrevTime())), new AttributeUpdate(KEY_CLIENT_CERT).put(certRecord.getClientCert()), new AttributeUpdate(KEY_TTL).put(certRecord.getCurrentTime().getTime() / 1000L + expiryTime), new AttributeUpdate(KEY_SVC_DATA_UPDATE_TIME).put(DynamoDBUtils.getLongFromDate(certRecord.getSvcDataUpdateTime())), new AttributeUpdate(KEY_EXPIRY_TIME).put(DynamoDBUtils.getLongFromDate(certRecord.getExpiryTime())), new AttributeUpdate(KEY_HOSTNAME).put(hostName));
updateItemRetryDynamoDBCommand.run(() -> table.updateItem(updateItemSpec));
return true;
} catch (Exception ex) {
LOGGER.error("DynamoDB Update Error for {}: {}/{}", primaryKey, ex.getClass(), ex.getMessage());
return false;
}
}
use of com.amazonaws.services.dynamodbv2.document.AttributeUpdate in project athenz by yahoo.
the class DynamoDBWorkloadRecordStoreConnectionTest method testUpdateWorkloadRecord.
@Test
public void testUpdateWorkloadRecord() {
DynamoDBWorkloadRecordStoreConnection dbConn = getDBConnection();
WorkloadRecord workloadRecord = new WorkloadRecord();
workloadRecord.setProvider("openstack");
long currTime = System.currentTimeMillis();
Date currDate = new Date(currTime);
workloadRecord.setUpdateTime(currDate);
UpdateItemSpec item = new UpdateItemSpec().withPrimaryKey("primaryKey", "athenz.api#1234#10.0.0.1").withAttributeUpdate(new AttributeUpdate("provider").put(workloadRecord.getProvider()), new AttributeUpdate("updateTime").put(workloadRecord.getUpdateTime()));
Mockito.doReturn(updateOutcome).when(table).updateItem(item);
boolean requestSuccess = dbConn.updateWorkloadRecord(workloadRecord);
Assert.assertTrue(requestSuccess);
dbConn.close();
}
Aggregations