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);
}
}
}
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());
}
}
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();
}
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();
}
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;
}
Aggregations