Search in sources :

Example 1 with WorkloadRecordStoreConnection

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());
    }
}
Also used : WorkloadRecordStoreConnection(com.yahoo.athenz.common.server.workload.WorkloadRecordStoreConnection)

Example 2 with WorkloadRecordStoreConnection

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();
}
Also used : WorkloadRecordStoreConnection(com.yahoo.athenz.common.server.workload.WorkloadRecordStoreConnection) Test(org.testng.annotations.Test)

Example 3 with WorkloadRecordStoreConnection

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();
}
Also used : WorkloadRecordStore(com.yahoo.athenz.common.server.workload.WorkloadRecordStore) WorkloadRecordStoreConnection(com.yahoo.athenz.common.server.workload.WorkloadRecordStoreConnection) Test(org.testng.annotations.Test)

Example 4 with WorkloadRecordStoreConnection

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();
}
Also used : WorkloadRecordStore(com.yahoo.athenz.common.server.workload.WorkloadRecordStore) WorkloadRecordStoreConnection(com.yahoo.athenz.common.server.workload.WorkloadRecordStoreConnection) WorkloadRecord(com.yahoo.athenz.common.server.workload.WorkloadRecord) Test(org.testng.annotations.Test)

Example 5 with WorkloadRecordStoreConnection

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();
}
Also used : WorkloadRecordStore(com.yahoo.athenz.common.server.workload.WorkloadRecordStore) WorkloadRecordStoreConnection(com.yahoo.athenz.common.server.workload.WorkloadRecordStoreConnection) Test(org.testng.annotations.Test)

Aggregations

WorkloadRecordStoreConnection (com.yahoo.athenz.common.server.workload.WorkloadRecordStoreConnection)7 WorkloadRecordStore (com.yahoo.athenz.common.server.workload.WorkloadRecordStore)5 Test (org.testng.annotations.Test)5 WorkloadRecord (com.yahoo.athenz.common.server.workload.WorkloadRecord)3 DeserializationFeature (com.fasterxml.jackson.databind.DeserializationFeature)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 InetAddresses (com.google.common.net.InetAddresses)1 Authority (com.yahoo.athenz.auth.Authority)1 Authorizer (com.yahoo.athenz.auth.Authorizer)1 Principal (com.yahoo.athenz.auth.Principal)1 PrivateKeyStore (com.yahoo.athenz.auth.PrivateKeyStore)1 AthenzUtils (com.yahoo.athenz.auth.util.AthenzUtils)1 Crypto (com.yahoo.athenz.auth.util.Crypto)1 CryptoException (com.yahoo.athenz.auth.util.CryptoException)1 com.yahoo.athenz.common.server.cert (com.yahoo.athenz.common.server.cert)1 RolesProvider (com.yahoo.athenz.common.server.db.RolesProvider)1 HostnameResolver (com.yahoo.athenz.common.server.dns.HostnameResolver)1 NotificationManager (com.yahoo.athenz.common.server.notification.NotificationManager)1 com.yahoo.athenz.common.server.ssh (com.yahoo.athenz.common.server.ssh)1 WorkloadRecordStoreFactory (com.yahoo.athenz.common.server.workload.WorkloadRecordStoreFactory)1