aboutsummaryrefslogtreecommitdiffstats
path: root/config-model-api/src/main/java/com/yahoo/config/model/api/ServiceInfo.java
blob: f2bb0a74a836755da579eadad4b32252178cd5b0 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config.model.api;

import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Collection;

/**
 * Contains information about a service.
 *
 * @author Ulf Lilleengen
 */
public class ServiceInfo {

    private final String serviceName;
    private final String serviceType;
    private final Collection<PortInfo> ports;
    private final Map<String, String> properties;
    private final String configId;
    private final String hostName;

    public ServiceInfo(String serviceName, String serviceType, Collection<PortInfo> ports, Map<String, String> properties,
                       String configId, String hostName) {

        Objects.requireNonNull(configId);

        this.serviceName = serviceName;
        this.serviceType = serviceType;
        this.ports = ports;
        this.properties = properties;
        this.configId = configId;
        this.hostName = hostName;
    }

    public String getServiceName() {
        return serviceName;
    }

    public String getConfigId() {
        return configId;
    }

    public String getServiceType() {
        return serviceType;
    }

    public Optional<String> getProperty(String propertyName) {
        return Optional.ofNullable(properties.get(propertyName));
    }

    public Collection<PortInfo> getPorts() {
        return ports;
    }

    public String getHostName() {
        return hostName;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        ServiceInfo that = (ServiceInfo) o;

        if (ports != null ? !ports.equals(that.ports) : that.ports != null) return false;
        if (properties != null ? !properties.equals(that.properties) : that.properties != null) return false;
        if (!serviceName.equals(that.serviceName)) return false;
        if (!serviceType.equals(that.serviceType)) return false;
        if (!configId.equals(that.configId)) return false;
        if (!hostName.equals(that.hostName)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = serviceName.hashCode();
        result = 31 * result + serviceType.hashCode();
        result = 31 * result + (ports != null ? ports.hashCode() : 0);
        result = 31 * result + (properties != null ? properties.hashCode() : 0);
        result = 31 * result + configId.hashCode();
        result = 31 * result + hostName.hashCode();
        return result;
    }

    @Override
    public String toString() {
        return "service '" + serviceName + "' of type " + serviceType + " on " + hostName;
    }

}