Search in sources :

Example 16 with WorkloadRecord

use of com.yahoo.athenz.common.server.workload.WorkloadRecord in project athenz by yahoo.

the class JDBCWorkloadRecordStoreConnectionTest method testGetWorkloadRecordsByService.

@Test
public void testGetWorkloadRecordsByService() throws Exception {
    Date now = new Date();
    Mockito.when(mockResultSet.next()).thenReturn(true, false);
    mockNonNullableColumns(now);
    Mockito.doReturn("10.0.0.1").when(mockResultSet).getString(JDBCWorkloadRecordStoreConnection.DB_COLUMN_IP);
    JDBCWorkloadRecordStoreConnection jdbcConn = new JDBCWorkloadRecordStoreConnection(mockConn);
    List<WorkloadRecord> workloadRecordList = jdbcConn.getWorkloadRecordsByService("athenz", "api");
    assertNotNull(workloadRecordList);
    assertNonNullableColumns(now, workloadRecordList.get(0));
    assertEquals(workloadRecordList.get(0).getIp(), "10.0.0.1");
    jdbcConn.close();
}
Also used : Date(java.util.Date) WorkloadRecord(com.yahoo.athenz.common.server.workload.WorkloadRecord) Test(org.testng.annotations.Test)

Example 17 with WorkloadRecord

use of com.yahoo.athenz.common.server.workload.WorkloadRecord in project athenz by yahoo.

the class FileWorkloadRecordStoreConnectionTest method testWorkloadOperations.

@Test
public void testWorkloadOperations() {
    ZTSTestUtils.deleteDirectory(new File("/tmp/zts-workload-tests"));
    File rootDir = new File("/tmp/zts-workload-tests");
    rootDir.deleteOnExit();
    FileWorkloadRecordStore store = new FileWorkloadRecordStore(rootDir);
    FileWorkloadRecordStoreConnection con = (FileWorkloadRecordStoreConnection) store.getConnection();
    assertNotNull(con);
    con.setOperationTimeout(10);
    // first verify that we don't have the entry
    List<WorkloadRecord> wlRecordCheck = con.getWorkloadRecordsByService("athenz", "api");
    assertTrue(wlRecordCheck.isEmpty());
    WorkloadRecord workloadRecord = new WorkloadRecord();
    Date now = new Date();
    workloadRecord.setService("athenz.api");
    workloadRecord.setProvider("openstack");
    workloadRecord.setInstanceId("instance-id");
    workloadRecord.setIp("10.0.0.1");
    workloadRecord.setHostname("test-host.corp.yahoo.com");
    workloadRecord.setCreationTime(now);
    workloadRecord.setUpdateTime(now);
    boolean result = con.insertWorkloadRecord(workloadRecord);
    assertTrue(result);
    wlRecordCheck = con.getWorkloadRecordsByService("athenz", "api");
    assertNotNull(wlRecordCheck);
    assertEquals(wlRecordCheck.get(0).getProvider(), "openstack");
    assertEquals(wlRecordCheck.get(0).getInstanceId(), "instance-id");
    assertEquals(wlRecordCheck.get(0).getIp(), "10.0.0.1");
    assertEquals(wlRecordCheck.get(0).getHostname(), "test-host.corp.yahoo.com");
    assertEquals(wlRecordCheck.get(0).getCreationTime().getTime(), now.getTime());
    assertEquals(wlRecordCheck.get(0).getUpdateTime().getTime(), now.getTime());
    wlRecordCheck = con.getWorkloadRecordsByIp("10.0.0.1");
    assertNotNull(wlRecordCheck);
    assertEquals(wlRecordCheck.get(0).getProvider(), "openstack");
    assertEquals(wlRecordCheck.get(0).getInstanceId(), "instance-id");
    assertEquals(wlRecordCheck.get(0).getService(), "athenz.api");
    assertEquals(wlRecordCheck.get(0).getHostname(), "test-host.corp.yahoo.com");
    assertEquals(wlRecordCheck.get(0).getCreationTime().getTime(), now.getTime());
    assertEquals(wlRecordCheck.get(0).getUpdateTime().getTime(), now.getTime());
    workloadRecord.setProvider("kubernetes");
    result = con.updateWorkloadRecord(workloadRecord);
    assertTrue(result);
    wlRecordCheck = con.getWorkloadRecordsByIp("10.0.0.1");
    assertNotNull(wlRecordCheck);
    assertEquals(wlRecordCheck.get(0).getProvider(), "kubernetes");
    assertTrue(con.getWorkloadRecordsByService("xyz", "abc").isEmpty());
    assertTrue(con.getWorkloadRecordsByIp("172.10.0.131").isEmpty());
    assertNull(con.getWorkloadRecord(new File("/proc/root")));
    try {
        con.writeWorkloadRecord(new File("/proc/root"), "xyz");
    } catch (Exception ignored) {
        fail();
    }
    con.close();
}
Also used : File(java.io.File) WorkloadRecord(com.yahoo.athenz.common.server.workload.WorkloadRecord) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 18 with WorkloadRecord

use of com.yahoo.athenz.common.server.workload.WorkloadRecord in project athenz by yahoo.

the class InstanceCertManagerTest method nullWorkloadsStoreTest.

@Test
public void nullWorkloadsStoreTest() {
    InstanceCertManager instance = new InstanceCertManager(null, null, null, true, null);
    instance.setWorkloadStore(null);
    WorkloadRecord wlr = new WorkloadRecord();
    assertFalse(instance.insertWorkloadRecord(wlr));
    assertFalse(instance.updateWorkloadRecord(wlr));
    instance.shutdown();
}
Also used : WorkloadRecord(com.yahoo.athenz.common.server.workload.WorkloadRecord) Test(org.testng.annotations.Test)

Example 19 with WorkloadRecord

use of com.yahoo.athenz.common.server.workload.WorkloadRecord 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 20 with WorkloadRecord

use of com.yahoo.athenz.common.server.workload.WorkloadRecord in project athenz by yahoo.

the class InstanceCertManagerTest method testGetWorkloadsByIp.

@Test
public void testGetWorkloadsByIp() {
    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 w5 = ZTSTestUtils.createWorkloadRecord(d, d, "aws", "i-123", "test-host2.corp.yahoo.com", "10.0.0.1", "athenz.secondapi", d);
    List<WorkloadRecord> workloadRecordList = new ArrayList<>();
    workloadRecordList.add(w1);
    workloadRecordList.add(w5);
    Mockito.when(storeConn.getWorkloadRecordsByIp(any())).thenReturn(workloadRecordList);
    List<Workload> workloadList = instance.getWorkloadsByIp("10.0.0.1");
    assertNotNull(workloadList);
    assertEquals(workloadList.size(), 2);
    List<String> expectedServices = workloadList.stream().map(Workload::getServiceName).collect(Collectors.toList());
    assertTrue(expectedServices.contains("api"));
    assertTrue(expectedServices.contains("secondapi"));
    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)

Aggregations

WorkloadRecord (com.yahoo.athenz.common.server.workload.WorkloadRecord)27 Test (org.testng.annotations.Test)18 Date (java.util.Date)12 QuerySpec (com.amazonaws.services.dynamodbv2.document.spec.QuerySpec)4 AmazonDynamoDBException (com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException)4 WorkloadRecordStore (com.yahoo.athenz.common.server.workload.WorkloadRecordStore)3 WorkloadRecordStoreConnection (com.yahoo.athenz.common.server.workload.WorkloadRecordStoreConnection)3 UpdateItemSpec (com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec)2 java.sql (java.sql)2 ArrayList (java.util.ArrayList)2 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