Skip to content

Commit

Permalink
Fixes compile errors
Browse files Browse the repository at this point in the history
Signed-off-by: Darshit Chanpura <[email protected]>
  • Loading branch information
DarshitChanpura committed Oct 4, 2024
1 parent 117671c commit 4d00642
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class CreateResourceAction extends ActionType<CreateResourceResponse> {
/**
* Create sample resource action name
*/
public static final String NAME = "cluster:admin/sampleresource/create";
public static final String NAME = "cluster:admin/sample-resource-plugin/create";

private CreateResourceAction() {
super(NAME, CreateResourceResponse::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ListAccessibleResourcesAction extends ActionType<ListAccessibleReso
/**
* List sample resource action name
*/
public static final String NAME = "cluster:admin/sampleresource/list";
public static final String NAME = "cluster:admin/sample-resource-plugin/list";

private ListAccessibleResourcesAction() {
super(NAME, ListAccessibleResourcesResponse::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class ShareResourceAction extends ActionType<ShareResourceResponse> {
/**
* List sample resource action name
*/
public static final String NAME = "cluster:admin/sampleresource/share";
public static final String NAME = "cluster:admin/sample-resource-plugin/share";

private ShareResourceAction() {
super(NAME, ShareResourceResponse::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class VerifyResourceAccessAction extends ActionType<VerifyResourceAccessR

public static final VerifyResourceAccessAction INSTANCE = new VerifyResourceAccessAction();

public static final String NAME = "cluster:admin/sampleresource/verify/resource_access";
public static final String NAME = "cluster:admin/sample-resource-plugin/verify/resource_access";

private VerifyResourceAccessAction() {
super(NAME, VerifyResourceAccessResponse::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@
import org.opensearch.core.xcontent.ToXContent;
import org.opensearch.sample.Resource;
import org.opensearch.sample.SampleResourcePlugin;
import org.opensearch.sample.actions.create.CreateResourceAction;
import org.opensearch.sample.actions.create.CreateResourceRequest;
import org.opensearch.sample.actions.create.CreateResourceResponse;
import org.opensearch.tasks.Task;
import org.opensearch.transport.TransportService;

import static org.opensearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.opensearch.sample.SampleResourcePlugin.RESOURCE_INDEX_NAME;

/**
* Transport action for CreateSampleResource.
Expand All @@ -44,20 +46,12 @@ public class CreateResourceTransportAction extends HandledTransportAction<Create

private final TransportService transportService;
private final Client nodeClient;
private final String resourceIndex;

@Inject
public CreateResourceTransportAction(
TransportService transportService,
ActionFilters actionFilters,
Client nodeClient,
String actionName,
String resourceIndex
) {
super(actionName, transportService, actionFilters, (in) -> new CreateResourceRequest(in));
public CreateResourceTransportAction(TransportService transportService, ActionFilters actionFilters, Client nodeClient) {
super(CreateResourceAction.NAME, transportService, actionFilters, CreateResourceRequest::new);
this.transportService = transportService;
this.nodeClient = nodeClient;
this.resourceIndex = resourceIndex;
}

@Override
Expand All @@ -73,7 +67,7 @@ protected void doExecute(Task task, CreateResourceRequest request, ActionListene
private void createResource(CreateResourceRequest request, ActionListener<CreateResourceResponse> listener) {
Resource sample = request.getResource();
try {
IndexRequest ir = nodeClient.prepareIndex(resourceIndex)
IndexRequest ir = nodeClient.prepareIndex(RESOURCE_INDEX_NAME)
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
.setSource(sample.toXContent(jsonBuilder(), ToXContent.EMPTY_PARAMS))
.request();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
import org.opensearch.accesscontrol.resources.ShareWith;
import org.opensearch.action.support.ActionFilters;
import org.opensearch.action.support.HandledTransportAction;
import org.opensearch.client.Client;
import org.opensearch.common.inject.Inject;
import org.opensearch.common.util.concurrent.ThreadContext;
import org.opensearch.core.action.ActionListener;
import org.opensearch.sample.SampleResourcePlugin;
import org.opensearch.sample.actions.share.ShareResourceAction;
import org.opensearch.sample.actions.share.ShareResourceRequest;
import org.opensearch.sample.actions.share.ShareResourceResponse;
import org.opensearch.tasks.Task;
Expand All @@ -36,27 +35,14 @@
public class ShareResourceTransportAction extends HandledTransportAction<ShareResourceRequest, ShareResourceResponse> {
private static final Logger log = LogManager.getLogger(ShareResourceTransportAction.class);

private final TransportService transportService;
private final Client nodeClient;
private final String resourceIndex;

@Inject
public ShareResourceTransportAction(
TransportService transportService,
ActionFilters actionFilters,
Client nodeClient,
String actionName,
String resourceIndex
) {
super(actionName, transportService, actionFilters, ShareResourceRequest::new);
this.transportService = transportService;
this.nodeClient = nodeClient;
this.resourceIndex = resourceIndex;
public ShareResourceTransportAction(TransportService transportService, ActionFilters actionFilters) {
super(ShareResourceAction.NAME, transportService, actionFilters, ShareResourceRequest::new);
}

@Override
protected void doExecute(Task task, ShareResourceRequest request, ActionListener<ShareResourceResponse> listener) {
try (ThreadContext.StoredContext ignore = transportService.getThreadPool().getThreadContext().stashContext()) {
try {
shareResource(request);
listener.onResponse(new ShareResourceResponse("Resource " + request.getResourceId() + " shared successfully."));
} catch (Exception e) {
Expand Down

0 comments on commit 4d00642

Please sign in to comment.