-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create interface RemoteEntitiesManager
- Add javadocs - fix after rebase Signed-off-by: Shivansh Arora <hishiv@amazon.com>
- Loading branch information
Showing
10 changed files
with
423 additions
and
225 deletions.
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
server/src/main/java/org/opensearch/common/remote/AbstractRemoteEntitiesManager.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,91 @@ | ||
/* | ||
* 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.common.remote; | ||
|
||
import org.opensearch.action.LatchedActionListener; | ||
import org.opensearch.common.CheckedRunnable; | ||
import org.opensearch.core.action.ActionListener; | ||
import org.opensearch.gateway.remote.ClusterMetadataManifest; | ||
import org.opensearch.gateway.remote.model.RemoteReadResult; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* An abstract class that provides a base implementation for managing remote entities in the remote store. | ||
*/ | ||
public abstract class AbstractRemoteEntitiesManager implements RemoteEntitiesManager { | ||
/** | ||
* A map that stores the remote writable entity stores, keyed by the entity type. | ||
*/ | ||
protected final Map<String, RemoteWritableEntityStore> remoteWritableEntityStores = new HashMap<>(); | ||
|
||
/** | ||
* Retrieves the remote writable entity store for the given entity. | ||
* | ||
* @param entity the entity for which the store is requested | ||
* @return the remote writable entity store for the given entity | ||
* @throws IllegalArgumentException if the entity type is unknown | ||
*/ | ||
protected RemoteWritableEntityStore getStore(AbstractRemoteWritableBlobEntity entity) { | ||
RemoteWritableEntityStore remoteStore = remoteWritableEntityStores.get(entity.getType()); | ||
if (remoteStore == null) { | ||
throw new IllegalArgumentException("Unknown entity type [" + entity.getType() + "]"); | ||
} | ||
return remoteStore; | ||
} | ||
|
||
/** | ||
* Returns an ActionListener for handling the write operation for the specified component, remote object, and latched action listener. | ||
* | ||
* @param component the component for which the write operation is performed | ||
* @param remoteObject the remote object to be written | ||
* @param latchedActionListener the latched action listener to be notified when the write operation completes | ||
* @return an ActionListener for handling the write operation | ||
*/ | ||
protected abstract ActionListener<Void> getWriteActionListener( | ||
String component, | ||
AbstractRemoteWritableBlobEntity remoteObject, | ||
LatchedActionListener<ClusterMetadataManifest.UploadedMetadata> latchedActionListener | ||
); | ||
|
||
/** | ||
* Returns an ActionListener for handling the read operation for the specified component, | ||
* remote object, and latched action listener. | ||
* | ||
* @param component the component for which the read operation is performed | ||
* @param remoteObject the remote object to be read | ||
* @param latchedActionListener the latched action listener to be notified when the read operation completes | ||
* @return an ActionListener for handling the read operation | ||
*/ | ||
protected abstract ActionListener<Object> getReadActionListener( | ||
String component, | ||
AbstractRemoteWritableBlobEntity remoteObject, | ||
LatchedActionListener<RemoteReadResult> latchedActionListener | ||
); | ||
|
||
@Override | ||
public CheckedRunnable<IOException> getAsyncWriteRunnable( | ||
String component, | ||
AbstractRemoteWritableBlobEntity entity, | ||
LatchedActionListener<ClusterMetadataManifest.UploadedMetadata> latchedActionListener | ||
) { | ||
return () -> getStore(entity).writeAsync(entity, getWriteActionListener(component, entity, latchedActionListener)); | ||
} | ||
|
||
@Override | ||
public CheckedRunnable<IOException> getAsyncReadRunnable( | ||
String component, | ||
AbstractRemoteWritableBlobEntity entity, | ||
LatchedActionListener<RemoteReadResult> latchedActionListener | ||
) { | ||
return () -> getStore(entity).readAsync(entity, getReadActionListener(component, entity, latchedActionListener)); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
server/src/main/java/org/opensearch/common/remote/RemoteEntitiesManager.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,50 @@ | ||
/* | ||
* 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.common.remote; | ||
|
||
import org.opensearch.action.LatchedActionListener; | ||
import org.opensearch.common.CheckedRunnable; | ||
import org.opensearch.gateway.remote.ClusterMetadataManifest.UploadedMetadata; | ||
import org.opensearch.gateway.remote.model.RemoteReadResult; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* The RemoteEntitiesManager interface provides async read and write methods for managing remote entities in the remote store | ||
*/ | ||
public interface RemoteEntitiesManager { | ||
|
||
/** | ||
* Returns a CheckedRunnable that performs an asynchronous read operation for the specified component and entity. | ||
* | ||
* @param component the component for which the read operation is performed | ||
* @param entity the entity to be read | ||
* @param latchedActionListener the listener to be notified when the read operation completes | ||
* @return a CheckedRunnable that performs the asynchronous read operation | ||
*/ | ||
CheckedRunnable<IOException> getAsyncReadRunnable( | ||
String component, | ||
AbstractRemoteWritableBlobEntity entity, | ||
LatchedActionListener<RemoteReadResult> latchedActionListener | ||
); | ||
|
||
/** | ||
* Returns a CheckedRunnable that performs an asynchronous write operation for the specified component and entity. | ||
* | ||
* @param component the component for which the write operation is performed | ||
* @param entity the entity to be written | ||
* @param latchedActionListener the listener to be notified when the write operation completes | ||
* @return a CheckedRunnable that performs the asynchronous write operation | ||
*/ | ||
CheckedRunnable<IOException> getAsyncWriteRunnable( | ||
String component, | ||
AbstractRemoteWritableBlobEntity entity, | ||
LatchedActionListener<UploadedMetadata> latchedActionListener | ||
); | ||
} |
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
Oops, something went wrong.