@Test public void testCollectShouldReturnsWithTheVmMetadataListWithoutError() { List<CloudInstance> vms = createVms(); Map<String, Optional<NetworkInterface>> networkInterfaces = createNetworkInterfaces(); when(gcpNetworkInterfaceProvider.provide(eq(authenticatedContext), any())).thenReturn(networkInterfaces); List<CloudVmMetaDataStatus> actual = underTest.collect(authenticatedContext, resources, vms, KNOWN_INSTANCES); CloudVmMetaDataStatus vm1 = getVm(INSTANCE_NAME_1, actual); assertEquals(InstanceStatus.CREATED, vm1.getCloudVmInstanceStatus().getStatus()); assertEquals(PUBLIC_IP, vm1.getMetaData().getPublicIp()); assertEquals(PRIVATE_IP, vm1.getMetaData().getPrivateIp()); CloudVmMetaDataStatus vm2 = getVm(INSTANCE_NAME_2, actual); assertEquals(InstanceStatus.CREATED, vm2.getCloudVmInstanceStatus().getStatus()); assertEquals(PUBLIC_IP, vm2.getMetaData().getPublicIp()); assertEquals(PRIVATE_IP, vm2.getMetaData().getPrivateIp()); CloudVmMetaDataStatus vm3 = getVm(INSTANCE_NAME_3, actual); assertEquals(InstanceStatus.CREATED, vm3.getCloudVmInstanceStatus().getStatus()); assertEquals(PUBLIC_IP, vm3.getMetaData().getPublicIp()); assertEquals(PRIVATE_IP, vm3.getMetaData().getPrivateIp()); }
@Override public List<CloudVmMetaDataStatus> collect(AuthenticatedContext authenticatedContext, List<CloudResource> resources, List<CloudInstance> vms, List<CloudInstance> knownInstances) { List<CloudVmMetaDataStatus> instanceMetaData = new ArrayList<>(); Map<String, CloudResource> instanceNameMap = groupByInstanceName(resources); Map<Long, CloudResource> privateIdMap = groupByPrivateId(resources); Map<String, Optional<NetworkInterface>> networkInterfacesByInstance = getNetworkInterfaceByInstance(authenticatedContext, instanceNameMap); for (CloudInstance cloudInstance : vms) { String instanceId = cloudInstance.getInstanceId(); CloudResource cloudResource; cloudResource = instanceId != null ? instanceNameMap.get(instanceId) : privateIdMap.get(cloudInstance.getTemplate().getPrivateId()); CloudVmMetaDataStatus cloudVmMetaDataStatus = getCloudVmMetaDataStatus(cloudResource, cloudInstance, networkInterfacesByInstance); instanceMetaData.add(cloudVmMetaDataStatus); } return instanceMetaData; }
GcpMetadataCollector implements MetadataCollector { @Override public List<CloudVmMetaDataStatus> collect(AuthenticatedContext authenticatedContext, List<CloudResource> resources, List<CloudInstance> vms, List<CloudInstance> knownInstances) { List<CloudVmMetaDataStatus> instanceMetaData = new ArrayList<>(); Map<String, CloudResource> instanceNameMap = groupByInstanceName(resources); Map<Long, CloudResource> privateIdMap = groupByPrivateId(resources); Map<String, Optional<NetworkInterface>> networkInterfacesByInstance = getNetworkInterfaceByInstance(authenticatedContext, instanceNameMap); for (CloudInstance cloudInstance : vms) { String instanceId = cloudInstance.getInstanceId(); CloudResource cloudResource; cloudResource = instanceId != null ? instanceNameMap.get(instanceId) : privateIdMap.get(cloudInstance.getTemplate().getPrivateId()); CloudVmMetaDataStatus cloudVmMetaDataStatus = getCloudVmMetaDataStatus(cloudResource, cloudInstance, networkInterfacesByInstance); instanceMetaData.add(cloudVmMetaDataStatus); } return instanceMetaData; } }
GcpMetadataCollector implements MetadataCollector { @Override public List<CloudVmMetaDataStatus> collect(AuthenticatedContext authenticatedContext, List<CloudResource> resources, List<CloudInstance> vms, List<CloudInstance> knownInstances) { List<CloudVmMetaDataStatus> instanceMetaData = new ArrayList<>(); Map<String, CloudResource> instanceNameMap = groupByInstanceName(resources); Map<Long, CloudResource> privateIdMap = groupByPrivateId(resources); Map<String, Optional<NetworkInterface>> networkInterfacesByInstance = getNetworkInterfaceByInstance(authenticatedContext, instanceNameMap); for (CloudInstance cloudInstance : vms) { String instanceId = cloudInstance.getInstanceId(); CloudResource cloudResource; cloudResource = instanceId != null ? instanceNameMap.get(instanceId) : privateIdMap.get(cloudInstance.getTemplate().getPrivateId()); CloudVmMetaDataStatus cloudVmMetaDataStatus = getCloudVmMetaDataStatus(cloudResource, cloudInstance, networkInterfacesByInstance); instanceMetaData.add(cloudVmMetaDataStatus); } return instanceMetaData; }  }
GcpMetadataCollector implements MetadataCollector { @Override public List<CloudVmMetaDataStatus> collect(AuthenticatedContext authenticatedContext, List<CloudResource> resources, List<CloudInstance> vms, List<CloudInstance> knownInstances) { List<CloudVmMetaDataStatus> instanceMetaData = new ArrayList<>(); Map<String, CloudResource> instanceNameMap = groupByInstanceName(resources); Map<Long, CloudResource> privateIdMap = groupByPrivateId(resources); Map<String, Optional<NetworkInterface>> networkInterfacesByInstance = getNetworkInterfaceByInstance(authenticatedContext, instanceNameMap); for (CloudInstance cloudInstance : vms) { String instanceId = cloudInstance.getInstanceId(); CloudResource cloudResource; cloudResource = instanceId != null ? instanceNameMap.get(instanceId) : privateIdMap.get(cloudInstance.getTemplate().getPrivateId()); CloudVmMetaDataStatus cloudVmMetaDataStatus = getCloudVmMetaDataStatus(cloudResource, cloudInstance, networkInterfacesByInstance); instanceMetaData.add(cloudVmMetaDataStatus); } return instanceMetaData; }  @Override List<CloudVmMetaDataStatus> collect(AuthenticatedContext authenticatedContext, List<CloudResource> resources, List<CloudInstance> vms,
            List<CloudInstance> knownInstances); }
GcpMetadataCollector implements MetadataCollector { @Override public List<CloudVmMetaDataStatus> collect(AuthenticatedContext authenticatedContext, List<CloudResource> resources, List<CloudInstance> vms, List<CloudInstance> knownInstances) { List<CloudVmMetaDataStatus> instanceMetaData = new ArrayList<>(); Map<String, CloudResource> instanceNameMap = groupByInstanceName(resources); Map<Long, CloudResource> privateIdMap = groupByPrivateId(resources); Map<String, Optional<NetworkInterface>> networkInterfacesByInstance = getNetworkInterfaceByInstance(authenticatedContext, instanceNameMap); for (CloudInstance cloudInstance : vms) { String instanceId = cloudInstance.getInstanceId(); CloudResource cloudResource; cloudResource = instanceId != null ? instanceNameMap.get(instanceId) : privateIdMap.get(cloudInstance.getTemplate().getPrivateId()); CloudVmMetaDataStatus cloudVmMetaDataStatus = getCloudVmMetaDataStatus(cloudResource, cloudInstance, networkInterfacesByInstance); instanceMetaData.add(cloudVmMetaDataStatus); } return instanceMetaData; }  @Override List<CloudVmMetaDataStatus> collect(AuthenticatedContext authenticatedContext, List<CloudResource> resources, List<CloudInstance> vms,
            List<CloudInstance> knownInstances);  }