use of com.amazonaws.services.dynamodbv2.document.PrimaryKey in project athenz by yahoo.
the class DynamoDBCertRecordStoreConnection method deleteX509CertRecord.
@Override
public boolean deleteX509CertRecord(String provider, String instanceId, String service) {
final String primaryKey = getPrimaryKey(provider, instanceId, service);
try {
DeleteItemSpec deleteItemSpec = new DeleteItemSpec().withPrimaryKey(KEY_PRIMARY, primaryKey);
deleteItemRetryDynamoDBCommand.run(() -> table.deleteItem(deleteItemSpec));
return true;
} catch (Exception ex) {
LOGGER.error("DynamoDB Delete Error for {}: {}/{}", primaryKey, ex.getClass(), ex.getMessage());
return false;
}
}
use of com.amazonaws.services.dynamodbv2.document.PrimaryKey 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.PrimaryKey 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.PrimaryKey in project athenz by yahoo.
the class ZTSTestUtils method generateAttributeValues.
public static Map<String, AttributeValue> generateAttributeValues(String service, String instanceId, String currentTime, String lastNotifiedTime, String lastNotifiedServer, String expiryTime, String hostName) {
String provider = "provider";
String primaryKey = provider + ":" + service + ":" + instanceId;
Map<String, AttributeValue> item = new HashMap<>();
item.put("primaryKey", new AttributeValue(primaryKey));
item.put("service", new AttributeValue(service));
item.put("provider", new AttributeValue(provider));
item.put("instanceId", new AttributeValue(instanceId));
item.put("currentSerial", new AttributeValue("currentSerial"));
AttributeValue currentTimeVal = new AttributeValue();
currentTimeVal.setN(currentTime);
if (!StringUtil.isEmpty(currentTime)) {
item.put("currentTime", currentTimeVal);
item.put("prevTime", currentTimeVal);
}
item.put("currentIP", new AttributeValue("currentIP"));
item.put("prevSerial", new AttributeValue("prevSerial"));
item.put("prevIP", new AttributeValue("prevIP"));
AttributeValue clientCertVal = new AttributeValue();
clientCertVal.setBOOL(false);
item.put("clientCert", clientCertVal);
if (!StringUtil.isEmpty(lastNotifiedTime)) {
AttributeValue lastNotifiedTimeVal = new AttributeValue();
lastNotifiedTimeVal.setN(lastNotifiedTime);
item.put("lastNotifiedTime", lastNotifiedTimeVal);
}
if (!StringUtil.isEmpty(lastNotifiedServer)) {
item.put("lastNotifiedServer", new AttributeValue(lastNotifiedServer));
}
if (!StringUtil.isEmpty(expiryTime)) {
AttributeValue expiryTimeVal = new AttributeValue();
expiryTimeVal.setN(expiryTime);
item.put("expiryTime", expiryTimeVal);
}
if (!StringUtil.isEmpty(hostName)) {
item.put("hostName", new AttributeValue(hostName));
}
return item;
}
use of com.amazonaws.services.dynamodbv2.document.PrimaryKey in project athenz by yahoo.
the class ZTSTestUtils method generateWorkloadAttributeValues.
public static Map<String, AttributeValue> generateWorkloadAttributeValues(String service, String instanceId, String provider, String ip, String hostname, String creationTime, String updateTime, String certExpiryTime) {
String primaryKey = service + "#" + instanceId + "#" + ip;
Map<String, AttributeValue> item = new HashMap<>();
item.put("primaryKey", new AttributeValue(primaryKey));
item.put("service", new AttributeValue(service));
item.put("provider", new AttributeValue(provider));
item.put("instanceId", new AttributeValue(instanceId));
item.put("ip", new AttributeValue(ip));
item.put("hostname", new AttributeValue(hostname));
AttributeValue creationTimeVal = new AttributeValue();
creationTimeVal.setN(creationTime);
AttributeValue updateTimeVal = new AttributeValue();
updateTimeVal.setN(updateTime);
AttributeValue certExpiryTimeVal = new AttributeValue();
certExpiryTimeVal.setN(certExpiryTime);
item.put("creationTime", creationTimeVal);
item.put("updateTime", updateTimeVal);
item.put("certExpiryTime", certExpiryTimeVal);
return item;
}
Aggregations