-
Notifications
You must be signed in to change notification settings - Fork 24.3k
/
DiscoveryNodeRole.java
178 lines (143 loc) · 5.44 KB
/
DiscoveryNodeRole.java
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.cluster.node;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.node.Node;
import java.util.Objects;
import java.util.Set;
/**
* Represents a node role.
*/
public abstract class DiscoveryNodeRole {
private final String roleName;
/**
* The name of the role.
*
* @return the role name
*/
public final String roleName() {
return roleName;
}
private final String roleNameAbbreviation;
/**
* The abbreviation of the name of the role. This is used in the cat nodes API to display an abbreviated version of the name of the
* role.
*
* @return the role name abbreviation
*/
public final String roleNameAbbreviation() {
return roleNameAbbreviation;
}
private final boolean isKnownRole;
/**
* Whether this role is known by this node, or is an {@link DiscoveryNodeRole.UnknownRole}.
*/
public final boolean isKnownRole() {
return isKnownRole;
}
protected DiscoveryNodeRole(final String roleName, final String roleNameAbbreviation) {
this(true, roleName, roleNameAbbreviation);
}
private DiscoveryNodeRole(final boolean isKnownRole, final String roleName, final String roleNameAbbreviation) {
this.isKnownRole = isKnownRole;
this.roleName = Objects.requireNonNull(roleName);
this.roleNameAbbreviation = Objects.requireNonNull(roleNameAbbreviation);
}
protected abstract Setting<Boolean> roleSetting();
@Override
public final boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
DiscoveryNodeRole that = (DiscoveryNodeRole) o;
return roleName.equals(that.roleName) &&
roleNameAbbreviation.equals(that.roleNameAbbreviation) &&
isKnownRole == that.isKnownRole;
}
@Override
public final int hashCode() {
return Objects.hash(isKnownRole, roleName(), roleNameAbbreviation());
}
@Override
public final String toString() {
return "DiscoveryNodeRole{" +
"roleName='" + roleName + '\'' +
", roleNameAbbreviation='" + roleNameAbbreviation + '\'' +
(isKnownRole ? "" : ", isKnownRole=false") +
'}';
}
/**
* Represents the role for a data node.
*/
public static final DiscoveryNodeRole DATA_ROLE = new DiscoveryNodeRole("data", "d") {
@Override
protected Setting<Boolean> roleSetting() {
return Node.NODE_DATA_SETTING;
}
};
/**
* Represents the role for an ingest node.
*/
public static final DiscoveryNodeRole INGEST_ROLE = new DiscoveryNodeRole("ingest", "i") {
@Override
protected Setting<Boolean> roleSetting() {
return Node.NODE_INGEST_SETTING;
}
};
/**
* Represents the role for a master-eligible node.
*/
public static final DiscoveryNodeRole MASTER_ROLE = new DiscoveryNodeRole("master", "m") {
@Override
protected Setting<Boolean> roleSetting() {
return Node.NODE_MASTER_SETTING;
}
};
public static final DiscoveryNodeRole REMOTE_CLUSTER_CLIENT_ROLE = new DiscoveryNodeRole("remote_cluster_client", "r") {
@Override
protected Setting<Boolean> roleSetting() {
return Node.NODE_REMOTE_CLUSTER_CLIENT;
}
};
/**
* The built-in node roles.
*/
public static Set<DiscoveryNodeRole> BUILT_IN_ROLES = Set.of(DATA_ROLE, INGEST_ROLE, MASTER_ROLE, REMOTE_CLUSTER_CLIENT_ROLE);
static Set<DiscoveryNodeRole> LEGACY_ROLES = Set.of(DATA_ROLE, INGEST_ROLE, MASTER_ROLE);
/**
* Represents an unknown role. This can occur if a newer version adds a role that an older version does not know about, or a newer
* version removes a role that an older version knows about.
*/
static class UnknownRole extends DiscoveryNodeRole {
/**
* Construct an unknown role with the specified role name and role name abbreviation.
*
* @param roleName the role name
* @param roleNameAbbreviation the role name abbreviation
*/
UnknownRole(final String roleName, final String roleNameAbbreviation) {
super(false, roleName, roleNameAbbreviation);
}
@Override
protected Setting<Boolean> roleSetting() {
// since this setting is not registered, it will always return false when testing if the local node has the role
assert false;
return Setting.boolSetting("node. " + roleName(), false, Setting.Property.NodeScope);
}
}
}