use of com.amazonaws.services.dynamodbv2.document.Item in project aws-doc-sdk-examples by awsdocs.
the class TryDaxTests method scanTest.
void scanTest(String tableName, DynamoDB client, int iterations) {
long startTime, endTime;
System.out.println("Scan test - all items in the table");
Table table = client.getTable(tableName);
for (int i = 0; i < iterations; i++) {
startTime = System.nanoTime();
ItemCollection<ScanOutcome> items = table.scan();
try {
Iterator<Item> iter = items.iterator();
while (iter.hasNext()) {
iter.next();
}
} catch (Exception e) {
System.err.println("Unable to scan table:");
e.printStackTrace();
}
endTime = System.nanoTime();
printTime(startTime, endTime, iterations);
}
}
use of com.amazonaws.services.dynamodbv2.document.Item in project aws-doc-sdk-examples by awsdocs.
the class DynamoDBScanItems method main.
public static void main(String[] args) {
if (args.length < 1) {
System.out.println("Please specify a table name");
System.exit(1);
}
// snippet-start:[dynamodb.java.dynamoDB_scan.main]
String tableName = args[0];
AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().build();
try {
ScanRequest scanRequest = new ScanRequest().withTableName(tableName);
ScanResult result = client.scan(scanRequest);
for (Map<String, AttributeValue> item : result.getItems()) {
Set<String> keys = item.keySet();
for (String key : keys) {
System.out.println("The key name is " + key + "\n");
System.out.println("The value is " + item.get(key).getS());
}
}
} catch (AmazonDynamoDBException e) {
e.getStackTrace();
}
// snippet-end:[dynamodb.java.dynamoDB_scan.main]
}
use of com.amazonaws.services.dynamodbv2.document.Item in project athenz by yahoo.
the class DynamoDBSSHRecordStoreConnection method insertSSHCertRecord.
@Override
public boolean insertSSHCertRecord(SSHCertRecord certRecord) {
final String primaryKey = getPrimaryKey(certRecord.getInstanceId(), certRecord.getService());
try {
Item item = new Item().withPrimaryKey(KEY_PRIMARY, primaryKey).withString(KEY_INSTANCE_ID, certRecord.getInstanceId()).withString(KEY_SERVICE, certRecord.getService()).withString(KEY_CLIENT_IP, certRecord.getClientIP()).withString(KEY_PRINCIPALS, certRecord.getPrincipals()).withString(KEY_PRIVATE_IP, certRecord.getPrivateIP()).withLong(KEY_TTL, System.currentTimeMillis() / 1000L + expiryTime);
table.putItem(item);
return true;
} catch (Exception ex) {
LOGGER.error("DynamoDB Insert Error for {}: {}/{}", primaryKey, ex.getClass(), ex.getMessage());
return false;
}
}
use of com.amazonaws.services.dynamodbv2.document.Item in project athenz by yahoo.
the class DynamoDBCertRecordStoreConnection method updateLastNotified.
private List<X509CertRecord> updateLastNotified(String lastNotifiedServer, long lastNotifiedTime, List<Item> items) {
long yesterday = lastNotifiedTime - TimeUnit.DAYS.toMillis(1);
List<X509CertRecord> updatedRecords = new ArrayList<>();
for (Item item : items) {
try {
Item updatedItem = dynamoDBNotificationsHelper.updateLastNotifiedItem(lastNotifiedServer, lastNotifiedTime, yesterday, item, KEY_PRIMARY, table);
if (isRecordUpdatedWithNotificationTimeAndServer(lastNotifiedServer, lastNotifiedTime, updatedItem)) {
X509CertRecord x509CertRecord = itemToX509CertRecord(updatedItem);
updatedRecords.add(x509CertRecord);
}
} catch (ConditionalCheckFailedException ex) {
// This error appears when the update didn't work because it was already updated by another server. We can ignore it.
} catch (Exception ex) {
LOGGER.error("DynamoDB updateLastNotified failed for item: {}, error: {}", item.toString(), ex.getMessage());
}
}
return updatedRecords;
}
use of com.amazonaws.services.dynamodbv2.document.Item in project athenz by yahoo.
the class DynamoDBCertRecordStoreConnection method mostUpdatedHostRecord.
private boolean mostUpdatedHostRecord(Item recordToCheck) {
try {
// Query all records with the same hostName / provider / service as recordToCheck
QuerySpec spec = new QuerySpec().withKeyConditionExpression("hostName = :v_host_name").withFilterExpression("attribute_exists(provider) AND provider = :v_provider AND attribute_exists(service) AND service = :v_service").withValueMap(new ValueMap().withString(":v_host_name", recordToCheck.getString(KEY_HOSTNAME)).withString(":v_provider", recordToCheck.getString(KEY_PROVIDER)).withString(":v_service", recordToCheck.getString(KEY_SERVICE)));
ItemCollection<QueryOutcome> outcome = itemCollectionRetryDynamoDBCommand.run(() -> hostNameIndex.query(spec));
List<Item> allRecordsWithHost = new ArrayList<>();
for (Item item : outcome) {
allRecordsWithHost.add(item);
}
// Verify recordToCheck is the most updated record with this hostName
return dynamoDBNotificationsHelper.isMostUpdatedRecordBasedOnAttribute(recordToCheck, allRecordsWithHost, KEY_CURRENT_TIME, KEY_PRIMARY);
} catch (Exception ex) {
LOGGER.error("DynamoDB mostUpdatedHostRecord failed for item: {}, error: {}", recordToCheck.toString(), ex.getMessage());
return false;
}
}
Aggregations