|
29 | 29 | import org.elasticsearch.cluster.service.ClusterService; |
30 | 30 | import org.elasticsearch.common.inject.Inject; |
31 | 31 | import org.elasticsearch.common.settings.Settings; |
32 | | -import org.elasticsearch.snapshots.Snapshot; |
33 | | -import org.elasticsearch.snapshots.SnapshotInfo; |
34 | 32 | import org.elasticsearch.snapshots.SnapshotsService; |
35 | 33 | import org.elasticsearch.threadpool.ThreadPool; |
36 | 34 | import org.elasticsearch.transport.TransportService; |
@@ -73,37 +71,13 @@ protected ClusterBlockException checkBlock(CreateSnapshotRequest request, Cluste |
73 | 71 |
|
74 | 72 | @Override |
75 | 73 | protected void masterOperation(final CreateSnapshotRequest request, ClusterState state, |
76 | | - final ActionListener<CreateSnapshotResponse> listener) { |
77 | | - snapshotsService.createSnapshot(request, new SnapshotsService.CreateSnapshotListener() { |
78 | | - @Override |
79 | | - public void onResponse(Snapshot snapshotCreated) { |
80 | | - if (request.waitForCompletion()) { |
81 | | - snapshotsService.addListener(new SnapshotsService.SnapshotCompletionListener() { |
82 | | - @Override |
83 | | - public void onSnapshotCompletion(Snapshot snapshot, SnapshotInfo snapshotInfo) { |
84 | | - if (snapshotCreated.equals(snapshot)) { |
85 | | - listener.onResponse(new CreateSnapshotResponse(snapshotInfo)); |
86 | | - snapshotsService.removeListener(this); |
87 | | - } |
88 | | - } |
89 | | - |
90 | | - @Override |
91 | | - public void onSnapshotFailure(Snapshot snapshot, Exception e) { |
92 | | - if (snapshotCreated.equals(snapshot)) { |
93 | | - listener.onFailure(e); |
94 | | - snapshotsService.removeListener(this); |
95 | | - } |
96 | | - } |
97 | | - }); |
98 | | - } else { |
99 | | - listener.onResponse(new CreateSnapshotResponse()); |
100 | | - } |
101 | | - } |
102 | | - |
103 | | - @Override |
104 | | - public void onFailure(Exception e) { |
105 | | - listener.onFailure(e); |
106 | | - } |
107 | | - }); |
| 74 | + final ActionListener<CreateSnapshotResponse> listener) { |
| 75 | + if (request.waitForCompletion()) { |
| 76 | + snapshotsService.executeSnapshot(request, |
| 77 | + ActionListener.wrap(snapshotInfo-> listener.onResponse(new CreateSnapshotResponse(snapshotInfo)), listener::onFailure)); |
| 78 | + } else { |
| 79 | + snapshotsService.createSnapshot(request, |
| 80 | + ActionListener.wrap(snapshot -> listener.onResponse(new CreateSnapshotResponse()), listener::onFailure)); |
| 81 | + } |
108 | 82 | } |
109 | 83 | } |
0 commit comments