-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Remote Object managers and use them in orchestration from Remo…
…teClusterStateService Signed-off-by: Shivansh Arora <hishiv@amazon.com>
- Loading branch information
Showing
12 changed files
with
1,387 additions
and
1,026 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
981 changes: 165 additions & 816 deletions
981
server/src/main/java/org/opensearch/gateway/remote/RemoteClusterStateService.java
Large diffs are not rendered by default.
Oops, something went wrong.
102 changes: 102 additions & 0 deletions
102
server/src/main/java/org/opensearch/gateway/remote/RemoteClusterStateUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.gateway.remote; | ||
|
||
import org.opensearch.cluster.metadata.Metadata; | ||
import org.opensearch.common.blobstore.BlobContainer; | ||
import org.opensearch.common.blobstore.BlobPath; | ||
import org.opensearch.core.xcontent.ToXContent; | ||
import org.opensearch.repositories.blobstore.BlobStoreRepository; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.util.ArrayList; | ||
import java.util.Base64; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.Map; | ||
|
||
public class RemoteClusterStateUtils { | ||
public static final String METADATA_NAME_FORMAT = "%s.dat"; | ||
public static final String METADATA_FILE_PREFIX = "metadata"; | ||
public static final String CLUSTER_STATE_PATH_TOKEN = "cluster-state"; | ||
public static final String GLOBAL_METADATA_PATH_TOKEN = "global-metadata"; | ||
public static final String DELIMITER = "__"; | ||
|
||
// ToXContent Params with gateway mode. | ||
// We are using gateway context mode to persist all custom metadata. | ||
public static final ToXContent.Params FORMAT_PARAMS = new ToXContent.MapParams( | ||
Map.of(Metadata.CONTEXT_MODE_PARAM, Metadata.CONTEXT_MODE_GATEWAY) | ||
); | ||
|
||
public static BlobPath getCusterMetadataBasePath(BlobStoreRepository blobStoreRepository, String clusterName, String clusterUUID) { | ||
return blobStoreRepository.basePath().add(encodeString(clusterName)).add(CLUSTER_STATE_PATH_TOKEN).add(clusterUUID); | ||
} | ||
|
||
public static String encodeString(String content) { | ||
return Base64.getUrlEncoder().withoutPadding().encodeToString(content.getBytes(StandardCharsets.UTF_8)); | ||
} | ||
|
||
public static String getFormattedFileName(String fileName, int codecVersion) { | ||
return String.format(Locale.ROOT, METADATA_NAME_FORMAT, fileName); | ||
} | ||
|
||
static BlobContainer clusterUUIDContainer(BlobStoreRepository blobStoreRepository, String clusterName) { | ||
return blobStoreRepository.blobStore() | ||
.blobContainer( | ||
blobStoreRepository.basePath() | ||
.add(Base64.getUrlEncoder().withoutPadding().encodeToString(clusterName.getBytes(StandardCharsets.UTF_8))) | ||
.add(CLUSTER_STATE_PATH_TOKEN) | ||
); | ||
} | ||
|
||
/** | ||
* Exception for Remote state transfer. | ||
*/ | ||
public static class RemoteStateTransferException extends RuntimeException { | ||
|
||
public RemoteStateTransferException(String errorDesc) { | ||
super(errorDesc); | ||
} | ||
|
||
public RemoteStateTransferException(String errorDesc, Throwable cause) { | ||
super(errorDesc, cause); | ||
} | ||
} | ||
|
||
public static class UploadedMetadataResults { | ||
List<ClusterMetadataManifest.UploadedIndexMetadata> uploadedIndexMetadata; | ||
Map<String, ClusterMetadataManifest.UploadedMetadataAttribute> uploadedCustomMetadataMap; | ||
ClusterMetadataManifest.UploadedMetadataAttribute uploadedCoordinationMetadata; | ||
ClusterMetadataManifest.UploadedMetadataAttribute uploadedSettingsMetadata; | ||
ClusterMetadataManifest.UploadedMetadataAttribute uploadedTemplatesMetadata; | ||
|
||
public UploadedMetadataResults( | ||
List<ClusterMetadataManifest.UploadedIndexMetadata> uploadedIndexMetadata, | ||
Map<String, ClusterMetadataManifest.UploadedMetadataAttribute> uploadedCustomMetadataMap, | ||
ClusterMetadataManifest.UploadedMetadataAttribute uploadedCoordinationMetadata, | ||
ClusterMetadataManifest.UploadedMetadataAttribute uploadedSettingsMetadata, | ||
ClusterMetadataManifest.UploadedMetadataAttribute uploadedTemplatesMetadata | ||
) { | ||
this.uploadedIndexMetadata = uploadedIndexMetadata; | ||
this.uploadedCustomMetadataMap = uploadedCustomMetadataMap; | ||
this.uploadedCoordinationMetadata = uploadedCoordinationMetadata; | ||
this.uploadedSettingsMetadata = uploadedSettingsMetadata; | ||
this.uploadedTemplatesMetadata = uploadedTemplatesMetadata; | ||
} | ||
|
||
public UploadedMetadataResults() { | ||
this.uploadedIndexMetadata = new ArrayList<>(); | ||
this.uploadedCustomMetadataMap = new HashMap<>(); | ||
this.uploadedCoordinationMetadata = null; | ||
this.uploadedSettingsMetadata = null; | ||
this.uploadedTemplatesMetadata = null; | ||
} | ||
} | ||
} |
Oops, something went wrong.