use of com.yahoo.athenz.common.server.workload.WorkloadRecordStoreConnection in project athenz by yahoo.
the class InstanceCertManager method getWorkloadsByIp.
public List<Workload> getWorkloadsByIp(String ip) {
if (workloadStore == null) {
return Collections.emptyList();
}
try (WorkloadRecordStoreConnection storeConnection = workloadStore.getConnection()) {
return storeConnection.getWorkloadRecordsByIp(ip).stream().map(wr -> {
Workload wl = new Workload();
String[] strArr = AthenzUtils.splitPrincipalName(wr.getService());
if (strArr != null) {
wl.setDomainName(strArr[0]).setServiceName(strArr[1]);
}
wl.setProvider(wr.getProvider()).setUuid(wr.getInstanceId()).setUpdateTime(Timestamp.fromDate(wr.getUpdateTime())).setHostname(wr.getHostname()).setCertExpiryTime(Timestamp.fromDate(wr.getCertExpiryTime()));
return wl;
}).filter(distinctByKey(w -> w.getUuid() + "#" + AthenzUtils.getPrincipalName(w.getDomainName(), w.getServiceName()))).collect(Collectors.toList());
}
}
use of com.yahoo.athenz.common.server.workload.WorkloadRecordStoreConnection in project athenz by yahoo.
the class DynamoDBWorkloadRecordStoreTest method testGetConnection.
@Test
public void testGetConnection() {
DynamoDBWorkloadRecordStore store = new DynamoDBWorkloadRecordStore(dbClient, "Workload-Table", "service-index", "ip-index");
WorkloadRecordStoreConnection dbConn = store.getConnection();
Assert.assertNotNull(dbConn);
// empty methods
store.setOperationTimeout(10);
store.clearConnections();
}
use of com.yahoo.athenz.common.server.workload.WorkloadRecordStoreConnection in project athenz by yahoo.
the class InstanceCertManagerTest method testInsertWorkloadRecord.
@Test
public void testInsertWorkloadRecord() {
InstanceCertManager instance = new InstanceCertManager(null, null, null, true, null);
WorkloadRecordStore store = Mockito.mock(WorkloadRecordStore.class);
instance.setWorkloadStore(store);
WorkloadRecordStoreConnection storeConn = Mockito.mock(WorkloadRecordStoreConnection.class);
Mockito.when(store.getConnection()).thenReturn(storeConn);
Mockito.when(storeConn.insertWorkloadRecord(any())).thenReturn(true);
Date d = new Date();
assertTrue(instance.insertWorkloadRecord(ZTSTestUtils.createWorkloadRecord(d, d, "aws", "i-123", "test-host1.corp.yahoo.com", "10.0.0.1", "athenz.api", d)));
instance.shutdown();
}
use of com.yahoo.athenz.common.server.workload.WorkloadRecordStoreConnection in project athenz by yahoo.
the class InstanceCertManagerTest method testGetWorkloadsByService.
@Test
public void testGetWorkloadsByService() {
InstanceCertManager instance = new InstanceCertManager(null, null, null, true, null);
WorkloadRecordStore store = Mockito.mock(WorkloadRecordStore.class);
instance.setWorkloadStore(store);
WorkloadRecordStoreConnection storeConn = Mockito.mock(WorkloadRecordStoreConnection.class);
Mockito.when(store.getConnection()).thenReturn(storeConn);
long currTime = System.currentTimeMillis();
Date d = new Date(currTime);
WorkloadRecord w1 = ZTSTestUtils.createWorkloadRecord(d, d, "aws", "i-123", "test-host1.corp.yahoo.com", "10.0.0.1", "athenz.api", d);
WorkloadRecord w2 = ZTSTestUtils.createWorkloadRecord(d, d, "aws", "i-234", "test-host2.corp.yahoo.com", "10.0.0.2", "athenz.api", d);
WorkloadRecord w3 = ZTSTestUtils.createWorkloadRecord(d, d, "aws", "i-234", "test-host2.corp.yahoo.com", "2001:0db8:85a3:0000:0000:8a2e:0370:7334", "athenz.api", d);
List<WorkloadRecord> workloadRecordList = new ArrayList<>();
workloadRecordList.add(w1);
workloadRecordList.add(w2);
workloadRecordList.add(w3);
Mockito.when(storeConn.getWorkloadRecordsByService(any(), any())).thenReturn(workloadRecordList);
List<Workload> workloadList = instance.getWorkloadsByService("athenz", "api");
assertNotNull(workloadList);
assertEquals(workloadList.size(), 2);
instance.shutdown();
}
use of com.yahoo.athenz.common.server.workload.WorkloadRecordStoreConnection in project athenz by yahoo.
the class InstanceCertManagerTest method testUpdateWorkloadRecord.
@Test
public void testUpdateWorkloadRecord() {
InstanceCertManager instance = new InstanceCertManager(null, null, null, true, null);
WorkloadRecordStore store = Mockito.mock(WorkloadRecordStore.class);
instance.setWorkloadStore(store);
WorkloadRecordStoreConnection storeConn = Mockito.mock(WorkloadRecordStoreConnection.class);
Mockito.when(store.getConnection()).thenReturn(storeConn);
Mockito.when(storeConn.updateWorkloadRecord(any())).thenReturn(true);
Date d = new Date();
assertTrue(instance.updateWorkloadRecord(ZTSTestUtils.createWorkloadRecord(d, d, "aws", "i-123", "test-host1.corp.yahoo.com", "10.0.0.1", "athenz.api", d)));
Mockito.when(storeConn.updateWorkloadRecord(any())).thenReturn(false);
Mockito.when(storeConn.insertWorkloadRecord(any())).thenReturn(true);
assertTrue(instance.updateWorkloadRecord(ZTSTestUtils.createWorkloadRecord(d, d, "aws", "i-123", "test-host1.corp.yahoo.com", "10.0.0.1", "athenz.api", d)));
instance.shutdown();
}
Aggregations