use of com.yahoo.athenz.common.server.workload.WorkloadRecord in project athenz by yahoo.
the class ZTSImpl method updateWorkloadRecord.
void updateWorkloadRecord(String cn, String provider, String certReqInstanceId, String sanIpStr, String hostName, Date certExpiryTime) {
if (StringUtil.isEmpty(sanIpStr)) {
return;
}
if (hostName == null) {
hostName = cn + "." + sanIpStr;
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("hostname is not set by agent, hence forming the hostname {} with domain.service {} and sanIpStr {} ..", hostName, cn, sanIpStr);
}
}
WorkloadRecord workloadRecord;
String[] sanIps = sanIpStr.split(",");
Date currDate = new Date();
for (String sanIp : sanIps) {
workloadRecord = new WorkloadRecord();
workloadRecord.setProvider(provider);
workloadRecord.setIp(sanIp);
workloadRecord.setInstanceId(certReqInstanceId);
workloadRecord.setService(cn);
workloadRecord.setCreationTime(currDate);
workloadRecord.setUpdateTime(currDate);
workloadRecord.setCertExpiryTime(certExpiryTime);
workloadRecord.setHostname(hostName);
if (!instanceCertManager.updateWorkloadRecord(workloadRecord)) {
LOGGER.error("unable to update workload record={}", workloadRecord);
}
}
}
use of com.yahoo.athenz.common.server.workload.WorkloadRecord 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.yahoo.athenz.common.server.workload.WorkloadRecord 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();
}
use of com.yahoo.athenz.common.server.workload.WorkloadRecord in project athenz by yahoo.
the class DynamoDBWorkloadRecordStoreConnectionTest method testGetWorkloadRecordsByService.
@Test
public void testGetWorkloadRecordsByService() {
long currTime = System.currentTimeMillis();
Mockito.doReturn("1234").when(item).getString("instanceId");
Mockito.doReturn("openstack").when(item).getString("provider");
Mockito.doReturn("10.10.10.11").when(item).getString("ip");
Mockito.doReturn("test-host").when(item).getString("hostname");
Mockito.doReturn(true).when(item).hasAttribute("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");
Mockito.doReturn(true).when(item).hasAttribute("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(serviceIndex).query(Mockito.any(QuerySpec.class));
DynamoDBWorkloadRecordStoreConnection dbConn = getDBConnection();
dbConn.setOperationTimeout(10);
List<WorkloadRecord> wlRecordList = dbConn.getWorkloadRecordsByService("athenz", "api");
Assert.assertNotNull(wlRecordList);
Assert.assertEquals(wlRecordList.get(0).getInstanceId(), "1234");
Assert.assertEquals(wlRecordList.get(0).getProvider(), "openstack");
Assert.assertEquals(wlRecordList.get(0).getIp(), "10.10.10.11");
Assert.assertEquals(wlRecordList.get(0).getHostname(), "test-host");
Assert.assertEquals(wlRecordList.get(0).getUpdateTime(), new Date(currTime));
Assert.assertEquals(wlRecordList.get(0).getCertExpiryTime(), new Date(currTime));
dbConn.close();
}
use of com.yahoo.athenz.common.server.workload.WorkloadRecord 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