From 3045b803c2a85a0655a9116d50876b25d369d6a0 Mon Sep 17 00:00:00 2001 From: valerijf Date: Mon, 19 Jun 2017 14:45:07 +0200 Subject: Remove unneeded created field in Container --- .../hosted/node/admin/nodeagent/NodeAgentImpl.java | 17 ++--------------- .../hosted/node/admin/nodeagent/NodeAgentImplTest.java | 3 +-- 2 files changed, 3 insertions(+), 17 deletions(-) (limited to 'node-admin') diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImpl.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImpl.java index 3c8327d1836..87d4509d7c9 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImpl.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImpl.java @@ -96,7 +96,7 @@ public class NodeAgentImpl implements NodeAgent { // The attributes of the last successful node repo attribute update for this node. Used to avoid redundant calls. private NodeAttributes lastAttributesSet = null; private ContainerNodeSpec lastNodeSpec = null; - private CpuUsageReporter lastCpuMetric; + private CpuUsageReporter lastCpuMetric = new CpuUsageReporter(); public NodeAgentImpl( final String hostName, @@ -134,12 +134,8 @@ public class NodeAgentImpl implements NodeAgent { }; // If the container is already running, initialize vespaVersion and lastCpuMetric - lastCpuMetric = new CpuUsageReporter(clock.instant()); dockerOperations.getContainer(containerName) .ifPresent(container -> { - if (container.state.isRunning()) { - lastCpuMetric = new CpuUsageReporter(container.created); - } containerState = RUNNING_HOWEVER_RESUME_SCRIPT_NOT_RUN; logger.info("Container is already running, setting containerState to " + containerState); }); @@ -260,7 +256,7 @@ public class NodeAgentImpl implements NodeAgent { private void startContainer(ContainerNodeSpec nodeSpec) { aclMaintainer.ifPresent(AclMaintainer::run); dockerOperations.startContainer(containerName, nodeSpec); - lastCpuMetric = new CpuUsageReporter(clock.instant()); + lastCpuMetric = new CpuUsageReporter(); currentFilebeatRestarter = filebeatRestarter.scheduleWithFixedDelay(() -> serviceRestarter.accept("filebeat"), 1, 1, TimeUnit.DAYS); storageMaintainer.ifPresent(maintainer -> { @@ -626,11 +622,6 @@ public class NodeAgentImpl implements NodeAgent { class CpuUsageReporter { private long totalContainerUsage = 0; private long totalSystemUsage = 0; - private final Instant created; - - CpuUsageReporter(Instant created) { - this.created = created; - } double getCpuUsagePercentage(long currentContainerUsage, long currentSystemUsage) { long deltaSystemUsage = currentSystemUsage - totalSystemUsage; @@ -641,10 +632,6 @@ public class NodeAgentImpl implements NodeAgent { totalSystemUsage = currentSystemUsage; return cpuUsagePct; } - - long getUptime() { - return Duration.between(created, clock.instant()).getSeconds(); - } } // TODO: Also skip orchestration if we're downgrading in test/staging diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImplTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImplTest.java index d71d130f9b8..91d9b382b7c 100644 --- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImplTest.java +++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImplTest.java @@ -573,8 +573,7 @@ public class NodeAgentImplTest { dockerImage, containerName, isRunning ? Container.State.RUNNING : Container.State.EXITED, - isRunning ? 1 : 0, - clock.instant().toString())) : + isRunning ? 1 : 0)) : Optional.empty(); when(dockerOperations.getContainerStats(any())).thenReturn(Optional.of(emptyContainerStats)); -- cgit v1.2.3