use of com.amazonaws.services.dynamodbv2.document.Item in project athenz by yahoo.
the class DynamoDBCertRecordStoreConnection method getUnrefreshedCertRecordsByDate.
private List<Item> getUnrefreshedCertRecordsByDate(String provider, long yesterday, String unrefreshedCertDate) {
try {
QuerySpec spec = new QuerySpec().withKeyConditionExpression("currentDate = :v_current_date").withFilterExpression("provider = :v_provider AND attribute_exists(hostName) AND (attribute_not_exists(lastNotifiedTime) OR lastNotifiedTime < :v_last_notified)").withValueMap(new ValueMap().withString(":v_current_date", unrefreshedCertDate).withNumber(":v_last_notified", yesterday).withString(":v_provider", provider));
ItemCollection<QueryOutcome> outcome = itemCollectionRetryDynamoDBCommand.run(() -> currentTimeIndex.query(spec));
List<Item> items = new ArrayList<>();
for (Item item : outcome) {
items.add(item);
}
return items;
} catch (Exception ex) {
LOGGER.error("DynamoDB getUnrefreshedCertRecordsByDate failed for provider: {}, date: {} error: {}", provider, unrefreshedCertDate, ex.getMessage());
}
return new ArrayList<>();
}
use of com.amazonaws.services.dynamodbv2.document.Item 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.Item 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;
}
use of com.amazonaws.services.dynamodbv2.document.Item in project athenz by yahoo.
the class DynamoDBWorkloadRecordStoreConnectionTest method testGetWorkloadRecordsByServiceNotFoundException.
@Test
public void testGetWorkloadRecordsByServiceNotFoundException() {
Mockito.doThrow(new AmazonDynamoDBException("item not found")).when(serviceIndex).query(Mockito.any(QuerySpec.class));
DynamoDBWorkloadRecordStoreConnection dbConn = getDBConnection();
List<WorkloadRecord> wlRecordList = dbConn.getWorkloadRecordsByService("athenz", "api");
Assert.assertTrue(wlRecordList.isEmpty());
dbConn.close();
}
use of com.amazonaws.services.dynamodbv2.document.Item in project athenz by yahoo.
the class DynamoDBWorkloadRecordStoreConnectionTest method testGetWorkloadRecordsByIp.
@Test
public void testGetWorkloadRecordsByIp() {
long currTime = System.currentTimeMillis();
Mockito.doReturn("1234").when(item).getString("instanceId");
Mockito.doReturn("openstack").when(item).getString("provider");
Mockito.doReturn("athenz.api").when(item).getString("service");
Mockito.doReturn("test-host").when(item).getString("hostname");
Mockito.doReturn(currTime).when(item).get("creationTime");
Mockito.doReturn(currTime).when(item).get("updateTime");
Mockito.doReturn(currTime).when(item).get("certExpiryTime");
Mockito.doReturn(currTime).when(item).getLong("creationTime");
Mockito.doReturn(currTime).when(item).getLong("updateTime");
Mockito.doReturn(currTime).when(item).getLong("certExpiryTime");
ItemCollection<QueryOutcome> itemCollection = Mockito.mock(ItemCollection.class);
IteratorSupport<Item, QueryOutcome> iteratorSupport = Mockito.mock(IteratorSupport.class);
when(itemCollection.iterator()).thenReturn(iteratorSupport);
when(iteratorSupport.hasNext()).thenReturn(true, false);
when(iteratorSupport.next()).thenReturn(item);
Mockito.doReturn(itemCollection).when(ipIndex).query(Mockito.any(QuerySpec.class));
DynamoDBWorkloadRecordStoreConnection dbConn = getDBConnection();
dbConn.setOperationTimeout(10);
List<WorkloadRecord> wlRecordList = dbConn.getWorkloadRecordsByIp("10.0.0.1");
Assert.assertNotNull(wlRecordList);
Assert.assertEquals(wlRecordList.get(0).getInstanceId(), "1234");
Assert.assertEquals(wlRecordList.get(0).getProvider(), "openstack");
Assert.assertEquals(wlRecordList.get(0).getService(), "athenz.api");
Assert.assertEquals(wlRecordList.get(0).getHostname(), "NA");
Assert.assertEquals(wlRecordList.get(0).getUpdateTime(), new Date(currTime));
Assert.assertEquals(wlRecordList.get(0).getCertExpiryTime(), new Date(0));
dbConn.close();
}
Aggregations