summaryrefslogtreecommitdiffstats
path: root/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/artifact/Artifact.java
blob: e0a4e0c0ae8fd344881ab01d6b0cc000cd535317 (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
// 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.artifact;

import com.yahoo.component.Version;

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

/**
 * A registry artifact (e.g. container image or RPM)
 *
 * @author mpolden
 */
public class Artifact {

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

    public Artifact(String id, String registry, String repository, String tag, Instant createdAt, Version version) {
        this.id = Objects.requireNonNull(id);
        this.registry = Optional.of(registry);
        this.repository = Optional.of(repository);
        this.tag = Optional.of(tag);
        this.createdAt = Objects.requireNonNull(createdAt);
        this.version = Objects.requireNonNull(version);
    }

    public Artifact(String id, Instant createdAt, Optional<String> tag, Version version) {
        this.id = Objects.requireNonNull(id);
        this.registry = Optional.empty();
        this.repository = Optional.empty();
        this.tag = Objects.requireNonNull(tag);
        this.createdAt = Objects.requireNonNull(createdAt);
        this.version = Objects.requireNonNull(version);
    }

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

    /** The registry holding this artifact */
    public Optional<String> registry() {
        return registry;
    }

    /** Repository of this artifact */
    public Optional<String> repository() {
        return repository;
    }

    /** Tag of this artifact */
    public Optional<String> tag() {
        return tag;
    }

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

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

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

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

    @Override
    public String toString() {
        String name = repository.isPresent() ? registry.get() + "/" + repository.get() : id;
        return "artifact " + name + " [version=" + version.toFullString() + ",createdAt=" + createdAt + tag.map(t -> ",tag=" + t).orElse("") + "]";
    }
}