aboutsummaryrefslogtreecommitdiffstats
path: root/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/noderepository/ScalingEventData.java
blob: a1c4427857768369834db6fd4f03ff0b544697c9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.api.integration.noderepository;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.yahoo.vespa.hosted.controller.api.integration.configserver.Cluster;

import java.time.Instant;
import java.util.Optional;

/**
 * @author bratseth
 */
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ScalingEventData {

    @JsonProperty("from")
    public ClusterResourcesData from;

    @JsonProperty("to")
    public ClusterResourcesData to;

    @JsonProperty("at")
    public Long at;

    @JsonProperty("completion")
    public Long completion;

    public Cluster.ScalingEvent toScalingEvent() {
        return new Cluster.ScalingEvent(from.toClusterResources(), to.toClusterResources(), Instant.ofEpochMilli(at),
                                        toOptionalInstant(completion));
    }

    private Optional<Instant> toOptionalInstant(Long epochMillis) {
        if (epochMillis == null) return Optional.empty();
        return Optional.of(Instant.ofEpochMilli(epochMillis));
    }

}