13
13
import org .opensearch .cluster .metadata .RepositoryMetadata ;
14
14
import org .opensearch .cluster .node .DiscoveryNode ;
15
15
import org .opensearch .common .settings .Settings ;
16
+ import org .opensearch .core .common .Strings ;
16
17
import org .opensearch .gateway .remote .RemoteClusterStateService ;
17
18
import org .opensearch .node .Node ;
18
19
import org .opensearch .repositories .blobstore .BlobStoreRepository ;
19
20
20
21
import java .util .ArrayList ;
21
- import java .util .HashSet ;
22
22
import java .util .Iterator ;
23
23
import java .util .List ;
24
24
import java .util .Locale ;
25
25
import java .util .Map ;
26
26
import java .util .Objects ;
27
27
import java .util .Set ;
28
28
import java .util .stream .Collectors ;
29
+ import java .util .stream .Stream ;
29
30
30
31
/**
31
32
* This is an abstraction for validating and storing information specific to remote backed storage nodes.
@@ -131,12 +132,16 @@ private RepositoryMetadata buildRepositoryMetadata(DiscoveryNode node, String na
131
132
}
132
133
133
134
private RepositoriesMetadata buildRepositoriesMetadata (DiscoveryNode node ) {
135
+ validateSegmentAttributes (node );
134
136
List <RepositoryMetadata > repositoryMetadataList = new ArrayList <>();
135
- Set <String > repositoryNames = new HashSet <>();
136
-
137
- repositoryNames .add (validateAttributeNonNull (node , REMOTE_STORE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY ));
138
- repositoryNames .add (validateAttributeNonNull (node , REMOTE_STORE_TRANSLOG_REPOSITORY_NAME_ATTRIBUTE_KEY ));
139
- repositoryNames .add (validateAttributeNonNull (node , REMOTE_STORE_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEY ));
137
+ Set <String > repositoryNames = Stream .of (
138
+ REMOTE_STORE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY ,
139
+ REMOTE_STORE_TRANSLOG_REPOSITORY_NAME_ATTRIBUTE_KEY ,
140
+ REMOTE_STORE_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEY
141
+ )
142
+ .map (repoKey -> node .getAttributes ().get (repoKey ))
143
+ .filter (repositoryName -> Strings .isNullOrEmpty (repositoryName ) == false )
144
+ .collect (Collectors .toSet ());
140
145
141
146
for (String repositoryName : repositoryNames ) {
142
147
repositoryMetadataList .add (buildRepositoryMetadata (node , repositoryName ));
@@ -145,12 +150,31 @@ private RepositoriesMetadata buildRepositoriesMetadata(DiscoveryNode node) {
145
150
return new RepositoriesMetadata (repositoryMetadataList );
146
151
}
147
152
153
+ private void validateSegmentAttributes (DiscoveryNode node ) {
154
+ if (node .getAttributes ().containsKey (REMOTE_STORE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY )
155
+ || node .getAttributes ().containsKey (REMOTE_STORE_TRANSLOG_REPOSITORY_NAME_ATTRIBUTE_KEY )) {
156
+ validateAttributeNonNull (node , REMOTE_STORE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY );
157
+ validateAttributeNonNull (node , REMOTE_STORE_TRANSLOG_REPOSITORY_NAME_ATTRIBUTE_KEY );
158
+ }
159
+ }
160
+
148
161
public static boolean isRemoteStoreAttributePresent (Settings settings ) {
149
162
return settings .getByPrefix (Node .NODE_ATTRIBUTES .getKey () + REMOTE_STORE_NODE_ATTRIBUTE_KEY_PREFIX ).isEmpty () == false ;
150
163
}
151
164
165
+ public static boolean isRemoteStoreSegmentOrTranslogAttributePresent (Settings settings ) {
166
+ return settings .getByPrefix (Node .NODE_ATTRIBUTES .getKey () + REMOTE_STORE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY ).isEmpty () == false
167
+ || settings .getByPrefix (Node .NODE_ATTRIBUTES .getKey () + REMOTE_STORE_TRANSLOG_REPOSITORY_NAME_ATTRIBUTE_KEY ).isEmpty () == false ;
168
+ }
169
+
170
+ public static boolean isRemoteClusterStateAttributePresent (Settings settings ) {
171
+ return settings .getByPrefix (Node .NODE_ATTRIBUTES .getKey () + REMOTE_STORE_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEY )
172
+ .isEmpty () == false ;
173
+ }
174
+
152
175
public static boolean isRemoteStoreClusterStateEnabled (Settings settings ) {
153
- return RemoteClusterStateService .REMOTE_CLUSTER_STATE_ENABLED_SETTING .get (settings ) && isRemoteStoreAttributePresent (settings );
176
+ return RemoteClusterStateService .REMOTE_CLUSTER_STATE_ENABLED_SETTING .get (settings )
177
+ && isRemoteClusterStateAttributePresent (settings );
154
178
}
155
179
156
180
public RepositoriesMetadata getRepositoriesMetadata () {
@@ -175,8 +199,12 @@ public int hashCode() {
175
199
176
200
@ Override
177
201
public boolean equals (Object o ) {
178
- if (this == o ) return true ;
179
- if (o == null || getClass () != o .getClass ()) return false ;
202
+ if (this == o ) {
203
+ return true ;
204
+ }
205
+ if (o == null || getClass () != o .getClass ()) {
206
+ return false ;
207
+ }
180
208
181
209
RemoteStoreNodeAttribute that = (RemoteStoreNodeAttribute ) o ;
182
210
0 commit comments