8
8
9
9
package org .opensearch .gateway .remote ;
10
10
11
- import org .opensearch .action .LatchedActionListener ;
12
11
import org .opensearch .cluster .ClusterState ;
13
12
import org .opensearch .cluster .DiffableUtils ;
14
13
import org .opensearch .cluster .DiffableUtils .NonDiffableValueSerializer ;
15
- import org .opensearch .common .CheckedRunnable ;
16
14
import org .opensearch .common .remote .AbstractRemoteWritableBlobEntity ;
17
- import org .opensearch .common .remote .RemoteWritableEntityStore ;
15
+ import org .opensearch .common .remote .AbstractRemoteWritableEntityManager ;
18
16
import org .opensearch .core .action .ActionListener ;
19
17
import org .opensearch .core .common .io .stream .NamedWriteableRegistry ;
20
18
import org .opensearch .gateway .remote .model .RemoteClusterBlocks ;
26
24
import org .opensearch .repositories .blobstore .BlobStoreRepository ;
27
25
import org .opensearch .threadpool .ThreadPool ;
28
26
29
- import java .io .IOException ;
30
27
import java .util .Collections ;
31
- import java .util .HashMap ;
32
28
import java .util .Map ;
33
29
34
30
/**
35
31
* A Manager which provides APIs to upload and download attributes of ClusterState to the {@link RemoteClusterStateBlobStore}
36
32
*
37
33
* @opensearch.internal
38
34
*/
39
- public class RemoteClusterStateAttributesManager {
35
+ public class RemoteClusterStateAttributesManager extends AbstractRemoteWritableEntityManager {
40
36
public static final String CLUSTER_STATE_ATTRIBUTE = "cluster_state_attribute" ;
41
37
public static final String DISCOVERY_NODES = "nodes" ;
42
38
public static final String CLUSTER_BLOCKS = "blocks" ;
43
39
public static final int CLUSTER_STATE_ATTRIBUTES_CURRENT_CODEC_VERSION = 1 ;
44
- private final Map <String , RemoteWritableEntityStore > remoteWritableEntityStores ;
45
- private final NamedWriteableRegistry namedWriteableRegistry ;
46
40
47
41
RemoteClusterStateAttributesManager (
48
42
String clusterName ,
@@ -51,8 +45,6 @@ public class RemoteClusterStateAttributesManager {
51
45
NamedWriteableRegistry namedWriteableRegistry ,
52
46
ThreadPool threadpool
53
47
) {
54
- this .namedWriteableRegistry = namedWriteableRegistry ;
55
- this .remoteWritableEntityStores = new HashMap <>();
56
48
this .remoteWritableEntityStores .put (
57
49
RemoteDiscoveryNodes .DISCOVERY_NODES ,
58
50
new RemoteClusterStateBlobStore <>(
@@ -85,46 +77,28 @@ public class RemoteClusterStateAttributesManager {
85
77
);
86
78
}
87
79
88
- /**
89
- * Allows async upload of Cluster State Attribute components to remote
90
- */
91
- CheckedRunnable <IOException > getAsyncMetadataWriteAction (
80
+ @ Override
81
+ protected ActionListener <Void > getWrappedWriteListener (
92
82
String component ,
93
- AbstractRemoteWritableBlobEntity blobEntity ,
94
- LatchedActionListener <ClusterMetadataManifest .UploadedMetadata > latchedActionListener
95
- ) {
96
- return () -> getStore (blobEntity ).writeAsync (blobEntity , getActionListener (component , blobEntity , latchedActionListener ));
97
- }
98
-
99
- private ActionListener <Void > getActionListener (
100
- String component ,
101
- AbstractRemoteWritableBlobEntity remoteObject ,
102
- LatchedActionListener <ClusterMetadataManifest .UploadedMetadata > latchedActionListener
83
+ AbstractRemoteWritableBlobEntity remoteEntity ,
84
+ ActionListener <ClusterMetadataManifest .UploadedMetadata > listener
103
85
) {
104
86
return ActionListener .wrap (
105
- resp -> latchedActionListener .onResponse (remoteObject .getUploadedMetadata ()),
106
- ex -> latchedActionListener .onFailure (new RemoteStateTransferException (component , remoteObject , ex ))
87
+ resp -> listener .onResponse (remoteEntity .getUploadedMetadata ()),
88
+ ex -> listener .onFailure (new RemoteStateTransferException ("Upload failed for " + component , remoteEntity , ex ))
107
89
);
108
90
}
109
91
110
- private RemoteWritableEntityStore getStore (AbstractRemoteWritableBlobEntity entity ) {
111
- RemoteWritableEntityStore remoteStore = remoteWritableEntityStores .get (entity .getType ());
112
- if (remoteStore == null ) {
113
- throw new IllegalArgumentException ("Unknown entity type [" + entity .getType () + "]" );
114
- }
115
- return remoteStore ;
116
- }
117
-
118
- public CheckedRunnable <IOException > getAsyncMetadataReadAction (
92
+ @ Override
93
+ protected ActionListener <Object > getWrappedReadListener (
119
94
String component ,
120
- AbstractRemoteWritableBlobEntity blobEntity ,
121
- LatchedActionListener <RemoteReadResult > listener
95
+ AbstractRemoteWritableBlobEntity remoteEntity ,
96
+ ActionListener <RemoteReadResult > listener
122
97
) {
123
- final ActionListener actionListener = ActionListener .wrap (
98
+ return ActionListener .wrap (
124
99
response -> listener .onResponse (new RemoteReadResult (response , CLUSTER_STATE_ATTRIBUTE , component )),
125
- listener :: onFailure
100
+ ex -> listener . onFailure ( new RemoteStateTransferException ( "Download failed for " + component , remoteEntity , ex ))
126
101
);
127
- return () -> getStore (blobEntity ).readAsync (blobEntity , actionListener );
128
102
}
129
103
130
104
public DiffableUtils .MapDiff <String , ClusterState .Custom , Map <String , ClusterState .Custom >> getUpdatedCustoms (
@@ -158,4 +132,5 @@ public DiffableUtils.MapDiff<String, ClusterState.Custom, Map<String, ClusterSta
158
132
NonDiffableValueSerializer .getAbstractInstance ()
159
133
);
160
134
}
135
+
161
136
}
0 commit comments