class 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;
    }

}