Skip to content

Commit

Permalink
Add javadocs
Browse files Browse the repository at this point in the history
Signed-off-by: Shivansh Arora <hishiv@amazon.com>
  • Loading branch information
shiv0408 committed Jul 8, 2024
1 parent 1aa6f3d commit 21ff759
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,22 @@
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) {
Expand All @@ -29,12 +42,29 @@ protected RemoteWritableEntityStore getStore(AbstractRemoteWritableBlobEntity en
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,33 @@

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,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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.core.action.ActionListener;
import org.opensearch.gateway.remote.ClusterMetadataManifest;
import org.opensearch.gateway.remote.model.RemoteReadResult;
import org.opensearch.test.OpenSearchTestCase;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

public class AbstractRemoteEntitiesManagerTests extends OpenSearchTestCase {
public void testGetStoreWithKnownEntityType() {
AbstractRemoteEntitiesManager manager = new ConcreteRemoteEntitiesManager();
String knownEntityType = "knownType";
RemoteWritableEntityStore mockStore = mock(RemoteWritableEntityStore.class);
manager.remoteWritableEntityStores.put(knownEntityType, mockStore);
AbstractRemoteWritableBlobEntity mockEntity = mock(AbstractRemoteWritableBlobEntity.class);
when(mockEntity.getType()).thenReturn(knownEntityType);

RemoteWritableEntityStore store = manager.getStore(mockEntity);
verify(mockEntity).getType();
assertEquals(mockStore, store);
}

public void testGetStoreWithUnknownEntityType() {
AbstractRemoteEntitiesManager manager = new ConcreteRemoteEntitiesManager();
String unknownEntityType = "unknownType";
AbstractRemoteWritableBlobEntity mockEntity = mock(AbstractRemoteWritableBlobEntity.class);
when(mockEntity.getType()).thenReturn(unknownEntityType);

assertThrows(IllegalArgumentException.class, () -> manager.getStore(mockEntity));
verify(mockEntity, times(2)).getType();
}

private static class ConcreteRemoteEntitiesManager extends AbstractRemoteEntitiesManager {
@Override
protected ActionListener<Void> getWriteActionListener(String component, AbstractRemoteWritableBlobEntity remoteObject, LatchedActionListener<ClusterMetadataManifest.UploadedMetadata> latchedActionListener) {
return null;
}

@Override
protected ActionListener<Object> getReadActionListener(String component, AbstractRemoteWritableBlobEntity remoteObject, LatchedActionListener<RemoteReadResult> latchedActionListener) {
return null;
}
}
}

0 comments on commit 21ff759

Please sign in to comment.