Search in sources :

Example 21 with WorkloadRecord

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

the class ZTSImpl method insertWorkloadRecord.

void insertWorkloadRecord(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(",");
    for (String sanIp : sanIps) {
        workloadRecord = new WorkloadRecord();
        workloadRecord.setProvider(provider);
        workloadRecord.setIp(sanIp);
        workloadRecord.setInstanceId(certReqInstanceId);
        workloadRecord.setService(cn);
        workloadRecord.setHostname(hostName);
        workloadRecord.setCreationTime(new Date());
        workloadRecord.setUpdateTime(new Date());
        workloadRecord.setCertExpiryTime(certExpiryTime);
        if (!instanceCertManager.insertWorkloadRecord(workloadRecord)) {
            LOGGER.error("unable to insert workload record={}", workloadRecord);
        }
    }
}
Also used : WorkloadRecord(com.yahoo.athenz.common.server.workload.WorkloadRecord)

Example 22 with WorkloadRecord

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

the class InstanceCertManager method getWorkloadsByService.

public List<Workload> getWorkloadsByService(String domain, String service) {
    if (workloadStore == null) {
        return Collections.emptyList();
    }
    try (WorkloadRecordStoreConnection storeConnection = workloadStore.getConnection()) {
        List<WorkloadRecord> workloadRecords = storeConnection.getWorkloadRecordsByService(domain, service);
        Map<String, List<String>> flattenedIpAddresses = new HashMap<>();
        String mapKey;
        for (WorkloadRecord workloadRecord : workloadRecords) {
            mapKey = workloadRecord.getInstanceId() + ":" + workloadRecord.getProvider() + ":" + workloadRecord.getUpdateTime().getTime() + ":" + workloadRecord.getCertExpiryTime().getTime() + ":" + workloadRecord.getHostname();
            if (flattenedIpAddresses.containsKey(mapKey)) {
                flattenedIpAddresses.get(mapKey).add(workloadRecord.getIp());
            } else {
                List<String> ipList = new ArrayList<>();
                ipList.add(workloadRecord.getIp());
                flattenedIpAddresses.put(mapKey, ipList);
            }
        }
        return flattenedIpAddresses.entrySet().stream().map(entry -> {
            Workload wl = new Workload();
            String[] tempArr = entry.getKey().split(":");
            wl.setUuid(tempArr[0]).setProvider(tempArr[1]).setUpdateTime(Timestamp.fromMillis(Long.parseLong(tempArr[2]))).setCertExpiryTime(Timestamp.fromMillis(Long.parseLong(tempArr[3]))).setHostname(tempArr[4]).setIpAddresses(entry.getValue());
            return wl;
        }).collect(Collectors.toList());
    }
}
Also used : X509Certificate(java.security.cert.X509Certificate) Authorizer(com.yahoo.athenz.auth.Authorizer) java.util(java.util) AthenzUtils(com.yahoo.athenz.auth.util.AthenzUtils) RolesProvider(com.yahoo.athenz.common.server.db.RolesProvider) LoggerFactory(org.slf4j.LoggerFactory) WorkloadRecordStoreConnection(com.yahoo.athenz.common.server.workload.WorkloadRecordStoreConnection) com.yahoo.athenz.common.server.cert(com.yahoo.athenz.common.server.cert) PrivateKeyStore(com.yahoo.athenz.auth.PrivateKeyStore) Function(java.util.function.Function) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) WorkloadRecordStoreFactory(com.yahoo.athenz.common.server.workload.WorkloadRecordStoreFactory) StringUtil(org.eclipse.jetty.util.StringUtil) X509CertUtils(com.yahoo.athenz.common.utils.X509CertUtils) CryptoException(com.yahoo.athenz.auth.util.CryptoException) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) com.yahoo.athenz.zts.utils(com.yahoo.athenz.zts.utils) com.yahoo.athenz.zts(com.yahoo.athenz.zts) Crypto(com.yahoo.athenz.auth.util.Crypto) Logger(org.slf4j.Logger) Predicate(java.util.function.Predicate) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) com.yahoo.athenz.common.server.ssh(com.yahoo.athenz.common.server.ssh) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Authority(com.yahoo.athenz.auth.Authority) HostnameResolver(com.yahoo.athenz.common.server.dns.HostnameResolver) WorkloadRecord(com.yahoo.athenz.common.server.workload.WorkloadRecord) Collectors(java.util.stream.Collectors) NotificationManager(com.yahoo.athenz.common.server.notification.NotificationManager) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) Timestamp(com.yahoo.rdl.Timestamp) Principal(com.yahoo.athenz.auth.Principal) WorkloadRecordStore(com.yahoo.athenz.common.server.workload.WorkloadRecordStore) InetAddresses(com.google.common.net.InetAddresses) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) WorkloadRecordStoreConnection(com.yahoo.athenz.common.server.workload.WorkloadRecordStoreConnection) WorkloadRecord(com.yahoo.athenz.common.server.workload.WorkloadRecord)

Example 23 with WorkloadRecord

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

the class JDBCWorkloadRecordStoreConnectionTest method testUpdateWorkloadRecord.

@Test
public void testUpdateWorkloadRecord() throws Exception {
    JDBCWorkloadRecordStoreConnection jdbcConn = new JDBCWorkloadRecordStoreConnection(mockConn);
    Date now = new Date();
    WorkloadRecord workloadRecord = getRecordWithNonNullableColumns(now);
    Mockito.doReturn(1).when(mockPrepStmt).executeUpdate();
    boolean requestSuccess = jdbcConn.updateWorkloadRecord(workloadRecord);
    assertTrue(requestSuccess);
    Mockito.verify(mockPrepStmt, times(1)).setString(1, "openstack");
    Mockito.verify(mockPrepStmt, times(1)).setTimestamp(2, new java.sql.Timestamp(now.getTime()));
    Mockito.verify(mockPrepStmt, times(1)).setString(3, "instance-id");
    Mockito.verify(mockPrepStmt, times(1)).setString(4, "athenz.api");
    Mockito.verify(mockPrepStmt, times(1)).setString(5, "10.0.0.1");
    jdbcConn.close();
}
Also used : Date(java.util.Date) WorkloadRecord(com.yahoo.athenz.common.server.workload.WorkloadRecord) java.sql(java.sql) Test(org.testng.annotations.Test)

Example 24 with WorkloadRecord

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

the class JDBCWorkloadRecordStoreConnectionTest method testInsertWorkloadRecord.

@Test
public void testInsertWorkloadRecord() throws Exception {
    JDBCWorkloadRecordStoreConnection jdbcConn = new JDBCWorkloadRecordStoreConnection(mockConn);
    Date now = new Date();
    WorkloadRecord workloadRecord = getRecordWithNonNullableColumns(now);
    Mockito.doReturn(1).when(mockPrepStmt).executeUpdate();
    boolean requestSuccess = jdbcConn.insertWorkloadRecord(workloadRecord);
    assertTrue(requestSuccess);
    Mockito.verify(mockPrepStmt, times(1)).setString(1, "athenz.api");
    Mockito.verify(mockPrepStmt, times(1)).setString(2, "instance-id");
    Mockito.verify(mockPrepStmt, times(1)).setString(3, "openstack");
    Mockito.verify(mockPrepStmt, times(1)).setString(4, "10.0.0.1");
    Mockito.verify(mockPrepStmt, times(1)).setString(5, "test-host1.yahoo.cloud");
    Mockito.verify(mockPrepStmt, times(1)).setTimestamp(6, new java.sql.Timestamp(now.getTime()));
    jdbcConn.close();
}
Also used : Date(java.util.Date) WorkloadRecord(com.yahoo.athenz.common.server.workload.WorkloadRecord) java.sql(java.sql) Test(org.testng.annotations.Test)

Example 25 with WorkloadRecord

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

the class JDBCWorkloadRecordStoreConnectionTest method getRecordWithNonNullableColumns.

private WorkloadRecord getRecordWithNonNullableColumns(Date now) {
    WorkloadRecord workloadRecord = new WorkloadRecord();
    workloadRecord.setService("athenz.api");
    workloadRecord.setProvider("openstack");
    workloadRecord.setInstanceId("instance-id");
    workloadRecord.setIp("10.0.0.1");
    workloadRecord.setHostname("test-host1.yahoo.cloud");
    workloadRecord.setCertExpiryTime(now);
    workloadRecord.setCreationTime(now);
    workloadRecord.setUpdateTime(now);
    return workloadRecord;
}
Also used : WorkloadRecord(com.yahoo.athenz.common.server.workload.WorkloadRecord)

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