6
6
* compatible open source license.
7
7
*/
8
8
9
- package org .opensearch .gateway .remote . model ;
9
+ package org .opensearch .common .remote ;
10
10
11
11
import org .opensearch .common .blobstore .BlobPath ;
12
12
import org .opensearch .common .blobstore .stream .write .WritePriority ;
13
- import org .opensearch .common .remote .AbstractRemoteWritableBlobEntity ;
14
- import org .opensearch .common .remote .RemoteWritableEntityStore ;
15
- import org .opensearch .common .remote .RemoteWriteableEntity ;
16
13
import org .opensearch .core .action .ActionListener ;
17
- import org .opensearch .gateway .remote .RemoteClusterStateUtils ;
18
14
import org .opensearch .index .translog .transfer .BlobStoreTransferService ;
19
15
import org .opensearch .repositories .blobstore .BlobStoreRepository ;
20
16
import org .opensearch .threadpool .ThreadPool ;
21
17
22
18
import java .io .IOException ;
23
19
import java .io .InputStream ;
20
+ import java .nio .charset .StandardCharsets ;
21
+ import java .util .Base64 ;
24
22
import java .util .concurrent .ExecutorService ;
25
23
26
- import static org .opensearch .gateway .remote .RemoteClusterStateUtils .CLUSTER_STATE_PATH_TOKEN ;
27
-
28
24
/**
29
25
* Abstract class for a blob type storage
30
26
*
31
27
* @param <T> The entity which can be uploaded to / downloaded from blob store
32
28
* @param <U> The concrete class implementing {@link RemoteWriteableEntity} which is used as a wrapper for T entity.
33
29
*/
34
- public class RemoteClusterStateBlobStore <T , U extends AbstractRemoteWritableBlobEntity <T >> implements RemoteWritableEntityStore <T , U > {
30
+ public class RemoteWriteableEntityBlobStore <T , U extends RemoteWriteableBlobEntity <T >> implements RemoteWritableEntityStore <T , U > {
35
31
36
32
private final BlobStoreTransferService transferService ;
37
33
private final BlobStoreRepository blobStoreRepository ;
38
34
private final String clusterName ;
39
35
private final ExecutorService executorService ;
36
+ private final String pathToken ;
40
37
41
- public RemoteClusterStateBlobStore (
38
+ public RemoteWriteableEntityBlobStore (
42
39
final BlobStoreTransferService blobStoreTransferService ,
43
40
final BlobStoreRepository blobStoreRepository ,
44
41
final String clusterName ,
45
42
final ThreadPool threadPool ,
46
- final String executor
43
+ final String executor ,
44
+ final String pathToken
47
45
) {
48
46
this .transferService = blobStoreTransferService ;
49
47
this .blobStoreRepository = blobStoreRepository ;
50
48
this .clusterName = clusterName ;
51
49
this .executorService = threadPool .executor (executor );
50
+ this .pathToken = pathToken ;
52
51
}
53
52
54
53
@ Override
@@ -95,21 +94,18 @@ public String getClusterName() {
95
94
}
96
95
97
96
public BlobPath getBlobPathPrefix (String clusterUUID ) {
98
- return blobStoreRepository .basePath ()
99
- .add (RemoteClusterStateUtils .encodeString (getClusterName ()))
100
- .add (CLUSTER_STATE_PATH_TOKEN )
101
- .add (clusterUUID );
97
+ return blobStoreRepository .basePath ().add (encodeString (getClusterName ())).add (pathToken ).add (clusterUUID );
102
98
}
103
99
104
- public BlobPath getBlobPathForUpload (final AbstractRemoteWritableBlobEntity <T > obj ) {
100
+ public BlobPath getBlobPathForUpload (final RemoteWriteableBlobEntity <T > obj ) {
105
101
BlobPath blobPath = getBlobPathPrefix (obj .clusterUUID ());
106
102
for (String token : obj .getBlobPathParameters ().getPathTokens ()) {
107
103
blobPath = blobPath .add (token );
108
104
}
109
105
return blobPath ;
110
106
}
111
107
112
- public BlobPath getBlobPathForDownload (final AbstractRemoteWritableBlobEntity <T > obj ) {
108
+ public BlobPath getBlobPathForDownload (final RemoteWriteableBlobEntity <T > obj ) {
113
109
String [] pathTokens = obj .getBlobPathTokens ();
114
110
BlobPath blobPath = new BlobPath ();
115
111
if (pathTokens == null || pathTokens .length < 1 ) {
@@ -122,4 +118,8 @@ public BlobPath getBlobPathForDownload(final AbstractRemoteWritableBlobEntity<T>
122
118
return blobPath ;
123
119
}
124
120
121
+ private static String encodeString (String content ) {
122
+ return Base64 .getUrlEncoder ().withoutPadding ().encodeToString (content .getBytes (StandardCharsets .UTF_8 ));
123
+ }
124
+
125
125
}
0 commit comments