Search in sources :

Example 6 with PrimaryKey

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;
    }
}
Also used : DeleteItemSpec(com.amazonaws.services.dynamodbv2.document.spec.DeleteItemSpec) ConditionalCheckFailedException(com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException)

Example 7 with PrimaryKey

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;
    }
}
Also used : UpdateItemSpec(com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec) ConditionalCheckFailedException(com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException)

Example 8 with PrimaryKey

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;
    }
}
Also used : AttributeUpdate(com.amazonaws.services.dynamodbv2.document.AttributeUpdate) UpdateItemSpec(com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec)

Example 9 with PrimaryKey

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;
}
Also used : AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue)

Example 10 with PrimaryKey

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;
}
Also used : AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue)

Aggregations

Test (org.testng.annotations.Test)15 UpdateItemSpec (com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec)11 Item (com.amazonaws.services.dynamodbv2.document.Item)9 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)8 Table (com.amazonaws.services.dynamodbv2.document.Table)7 DeleteItemSpec (com.amazonaws.services.dynamodbv2.document.spec.DeleteItemSpec)5 X509CertRecord (com.yahoo.athenz.common.server.cert.X509CertRecord)5 UpdateItemOutcome (com.amazonaws.services.dynamodbv2.document.UpdateItemOutcome)4 AmazonServiceException (com.amazonaws.AmazonServiceException)3 SSHCertRecord (com.yahoo.athenz.common.server.ssh.SSHCertRecord)3 Date (java.util.Date)3 AmazonClientException (com.amazonaws.AmazonClientException)2 ClientConfiguration (com.amazonaws.ClientConfiguration)2 PropertiesCredentials (com.amazonaws.auth.PropertiesCredentials)2 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)2 DynamoDB (com.amazonaws.services.dynamodbv2.document.DynamoDB)2 PrimaryKey (com.amazonaws.services.dynamodbv2.document.PrimaryKey)2 ValueMap (com.amazonaws.services.dynamodbv2.document.utils.ValueMap)2 AmazonDynamoDBException (com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException)2 ConditionalCheckFailedException (com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException)2