// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.dockerapi;

import java.util.Map;

/**
 * Wrapper class for {@link com.github.dockerjava.api.model.Statistics} to prevent leaking from docker-java library.
 *
 * @author valerijf
 */
public class ContainerStatsImpl implements Docker.ContainerStats {
    private final Map<String, Object> networks;
    private final Map<String, Object> cpuStats;
    private final Map<String, Object> memoryStats;
    private final Map<String, Object> blkioStats;

    public ContainerStatsImpl(Map<String, Object> networks, Map<String, Object> cpuStats,
                              Map<String, Object> memoryStats, Map<String, Object> blkioStats) {
        this.networks = networks;
        this.cpuStats = cpuStats;
        this.memoryStats = memoryStats;
        this.blkioStats = blkioStats;
    }

    public Map<String, Object> getNetworks() {
        return networks;
    }

    public Map<String, Object> getCpuStats() {
        return cpuStats;
    }

    public Map<String, Object> getMemoryStats() {
        return memoryStats;
    }

    public Map<String, Object> getBlkioStats() {
        return blkioStats;
    }
}

@@ -172,19 +172,76 @@
 va.util.
-Map
+Collections;%0Aimport java.util.Map;%0Aimport java.util.Optional
 ;%0A%0A/**%0A 
@@ -374,16 +374,13 @@
 hor 
-valerijf
+freva
 %0A */
@@ -844,32 +844,151 @@
     
-this.networks = networks
+// Network stats are null when container uses host network%0A        this.networks = Optional.ofNullable(networks).orElse(Collections.emptyMap())
 ;%0A  

Handle null network stats