|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License; |
| 4 | + * you may not use this file except in compliance with the Elastic License. |
| 5 | + */ |
| 6 | + |
| 7 | +package org.elasticsearch.xpack.ccr.action.repositories; |
| 8 | + |
| 9 | +import org.elasticsearch.action.Action; |
| 10 | +import org.elasticsearch.action.FailedNodeException; |
| 11 | +import org.elasticsearch.action.support.ActionFilters; |
| 12 | +import org.elasticsearch.action.support.nodes.BaseNodeResponse; |
| 13 | +import org.elasticsearch.action.support.nodes.BaseNodesResponse; |
| 14 | +import org.elasticsearch.action.support.nodes.TransportNodesAction; |
| 15 | +import org.elasticsearch.client.ElasticsearchClient; |
| 16 | +import org.elasticsearch.cluster.ClusterName; |
| 17 | +import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; |
| 18 | +import org.elasticsearch.cluster.node.DiscoveryNode; |
| 19 | +import org.elasticsearch.cluster.service.ClusterService; |
| 20 | +import org.elasticsearch.common.inject.Inject; |
| 21 | +import org.elasticsearch.common.io.stream.StreamInput; |
| 22 | +import org.elasticsearch.common.io.stream.StreamOutput; |
| 23 | +import org.elasticsearch.common.settings.Settings; |
| 24 | +import org.elasticsearch.threadpool.ThreadPool; |
| 25 | +import org.elasticsearch.transport.TransportService; |
| 26 | +import org.elasticsearch.xpack.ccr.repository.CcrRestoreSourceService; |
| 27 | + |
| 28 | +import java.io.IOException; |
| 29 | +import java.util.List; |
| 30 | + |
| 31 | +public class ClearCcrRestoreSessionAction extends Action<ClearCcrRestoreSessionRequest, |
| 32 | + ClearCcrRestoreSessionAction.ClearCcrRestoreSessionResponse, ClearCcrRestoreSessionRequestBuilder> { |
| 33 | + |
| 34 | + public static final ClearCcrRestoreSessionAction INSTANCE = new ClearCcrRestoreSessionAction(); |
| 35 | + private static final String NAME = "internal:admin/ccr/restore/session/clear"; |
| 36 | + |
| 37 | + private ClearCcrRestoreSessionAction() { |
| 38 | + super(NAME); |
| 39 | + } |
| 40 | + |
| 41 | + @Override |
| 42 | + public ClearCcrRestoreSessionResponse newResponse() { |
| 43 | + return new ClearCcrRestoreSessionResponse(); |
| 44 | + } |
| 45 | + |
| 46 | + @Override |
| 47 | + public ClearCcrRestoreSessionRequestBuilder newRequestBuilder(ElasticsearchClient client) { |
| 48 | + return new ClearCcrRestoreSessionRequestBuilder(client); |
| 49 | + } |
| 50 | + |
| 51 | + public static class TransportDeleteCcrRestoreSessionAction extends TransportNodesAction<ClearCcrRestoreSessionRequest, |
| 52 | + ClearCcrRestoreSessionResponse, ClearCcrRestoreSessionRequest.Request, Response> { |
| 53 | + |
| 54 | + private final CcrRestoreSourceService ccrRestoreService; |
| 55 | + |
| 56 | + @Inject |
| 57 | + public TransportDeleteCcrRestoreSessionAction(Settings settings, ThreadPool threadPool, ClusterService clusterService, |
| 58 | + ActionFilters actionFilters, IndexNameExpressionResolver resolver, |
| 59 | + TransportService transportService, CcrRestoreSourceService ccrRestoreService) { |
| 60 | + super(settings, NAME, threadPool, clusterService, transportService, actionFilters, resolver, |
| 61 | + ClearCcrRestoreSessionRequest::new, ClearCcrRestoreSessionRequest.Request::new, ThreadPool.Names.GENERIC, Response.class); |
| 62 | + this.ccrRestoreService = ccrRestoreService; |
| 63 | + } |
| 64 | + |
| 65 | + @Override |
| 66 | + protected ClearCcrRestoreSessionResponse newResponse(ClearCcrRestoreSessionRequest request, List<Response> responses, |
| 67 | + List<FailedNodeException> failures) { |
| 68 | + return new ClearCcrRestoreSessionResponse(clusterService.getClusterName(), responses, failures); |
| 69 | + } |
| 70 | + |
| 71 | + @Override |
| 72 | + protected ClearCcrRestoreSessionRequest.Request newNodeRequest(String nodeId, ClearCcrRestoreSessionRequest request) { |
| 73 | + return request.getRequest(); |
| 74 | + } |
| 75 | + |
| 76 | + @Override |
| 77 | + protected Response newNodeResponse() { |
| 78 | + return new Response(); |
| 79 | + } |
| 80 | + |
| 81 | + @Override |
| 82 | + protected Response nodeOperation(ClearCcrRestoreSessionRequest.Request request) { |
| 83 | + ccrRestoreService.closeSession(request.getSessionUUID()); |
| 84 | + return new Response(clusterService.localNode()); |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + public static class Response extends BaseNodeResponse { |
| 89 | + |
| 90 | + private Response() { |
| 91 | + } |
| 92 | + |
| 93 | + private Response(StreamInput in) throws IOException { |
| 94 | + readFrom(in); |
| 95 | + } |
| 96 | + |
| 97 | + private Response(DiscoveryNode node) { |
| 98 | + super(node); |
| 99 | + } |
| 100 | + |
| 101 | + @Override |
| 102 | + public void writeTo(StreamOutput out) throws IOException { |
| 103 | + super.writeTo(out); |
| 104 | + } |
| 105 | + |
| 106 | + @Override |
| 107 | + public void readFrom(StreamInput in) throws IOException { |
| 108 | + super.readFrom(in); |
| 109 | + } |
| 110 | + } |
| 111 | + |
| 112 | + public static class ClearCcrRestoreSessionResponse extends BaseNodesResponse<Response> { |
| 113 | + |
| 114 | + ClearCcrRestoreSessionResponse() { |
| 115 | + } |
| 116 | + |
| 117 | + ClearCcrRestoreSessionResponse(ClusterName clusterName, List<Response> chunkResponses, List<FailedNodeException> failures) { |
| 118 | + super(clusterName, chunkResponses, failures); |
| 119 | + } |
| 120 | + |
| 121 | + @Override |
| 122 | + protected List<Response> readNodesFrom(StreamInput in) throws IOException { |
| 123 | + return in.readList(Response::new); |
| 124 | + } |
| 125 | + |
| 126 | + @Override |
| 127 | + protected void writeNodesTo(StreamOutput out, List<Response> nodes) throws IOException { |
| 128 | + out.writeList(nodes); |
| 129 | + } |
| 130 | + } |
| 131 | +} |
0 commit comments