summaryrefslogtreecommitdiffstats
path: root/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/container/ContainerImage.java
blob: 9652eeef5307cc44a1ab8ea2d77612ba3b3bad4d (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// 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.container;

import com.yahoo.component.Version;

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

/**
 * A container image.
 *
 * @author mpolden
 */
public class ContainerImage {

    private final String id;
    private final String registry;
    private final String repository;
    private final Instant createdAt;
    private final Version version;
    private final Optional<Architecture> architecture;

    public ContainerImage(String id, String registry, String repository, Instant createdAt, Version version, Optional<Architecture> architecture) {
        this.id = Objects.requireNonNull(id);
        this.registry = Objects.requireNonNull(registry);
        this.repository = Objects.requireNonNull(repository);
        this.createdAt = Objects.requireNonNull(createdAt);
        this.version = Objects.requireNonNull(version);
        this.architecture = Objects.requireNonNull(architecture);
    }

    /** Unique identifier of this */
    public String id() {
        return id;
    }

    /** The registry holding this image */
    public String registry() {
        return registry;
    }

    /** Repository of this image */
    public String repository() {
        return repository;
    }

    /** The time this was created */
    public Instant createdAt() {
        return createdAt;
    }

    /** The version of this */
    public Version version() {
        return version;
    }

    /** The architecture of this, if any */
    public Optional<Architecture> architecture() {
        return architecture;
    }

    /** The tag of this image */
    public String tag() {
        return version().toFullString() + architecture.map(arch -> "-" + arch.name()).orElse("");
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ContainerImage that = (ContainerImage) o;
        return id.equals(that.id) &&
               registry.equals(that.registry) &&
               repository.equals(that.repository) &&
               createdAt.equals(that.createdAt) &&
               version.equals(that.version) &&
               architecture.equals(that.architecture);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, registry, repository, createdAt, version, architecture);
    }

    @Override
    public String toString() {
        return "container image " + repository + " [registry=" + registry + ",version=" + version.toFullString() +
               ",createdAt=" + createdAt + ",architecture=" + architecture.map(Enum::name).orElse("<none>") + "]";
    }

    public enum Architecture {
        amd64,
        arm64,
    }

}