Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to get snapshot status for running snapshots
Closes #4946
- Loading branch information
Showing
30 changed files
with
2,423 additions
and
34 deletions.
There are no files selected for viewing
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
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,27 @@ | ||
{ | ||
"snapshot.status": { | ||
"documentation": "http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/modules-snapshots.html", | ||
"methods": ["GET"], | ||
"url": { | ||
"path": "/_snapshot/_status", | ||
"paths": ["/_snapshot/_status", "/_snapshot/{repository}/_status", "/_snapshot/{repository}/{snapshot}/_status"], | ||
"parts": { | ||
"repository": { | ||
"type": "string", | ||
"description": "A repository name" | ||
}, | ||
"snapshot": { | ||
"type": "list", | ||
"description": "A comma-separated list of snapshot names" | ||
} | ||
}, | ||
"params": { | ||
"master_timeout": { | ||
"type" : "time", | ||
"description" : "Explicit operation timeout for connection to master node" | ||
} | ||
} | ||
}, | ||
"body": null | ||
} | ||
} |
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
98 changes: 98 additions & 0 deletions
98
...java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotIndexShardStage.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,98 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.action.admin.cluster.snapshots.status; | ||
|
||
import org.elasticsearch.ElasticsearchIllegalArgumentException; | ||
|
||
/** | ||
*/ | ||
public enum SnapshotIndexShardStage { | ||
|
||
/** | ||
* Snapshot hasn't started yet | ||
*/ | ||
INIT((byte)0, false), | ||
/** | ||
* Index files are being copied | ||
*/ | ||
STARTED((byte)1, false), | ||
/** | ||
* Snapshot metadata is being written | ||
*/ | ||
FINALIZE((byte)2, false), | ||
/** | ||
* Snapshot completed successfully | ||
*/ | ||
DONE((byte)3, true), | ||
/** | ||
* Snapshot failed | ||
*/ | ||
FAILURE((byte)4, true); | ||
|
||
private byte value; | ||
|
||
private boolean completed; | ||
|
||
private SnapshotIndexShardStage(byte value, boolean completed) { | ||
this.value = value; | ||
this.completed = completed; | ||
} | ||
|
||
/** | ||
* Returns code that represents the snapshot state | ||
* | ||
* @return code for the state | ||
*/ | ||
public byte value() { | ||
return value; | ||
} | ||
|
||
/** | ||
* Returns true if snapshot completed (successfully or not) | ||
* | ||
* @return true if snapshot completed, false otherwise | ||
*/ | ||
public boolean completed() { | ||
return completed; | ||
} | ||
|
||
/** | ||
* Generate snapshot state from code | ||
* | ||
* @param value the state code | ||
* @return state | ||
*/ | ||
public static SnapshotIndexShardStage fromValue(byte value) { | ||
switch (value) { | ||
case 0: | ||
return INIT; | ||
case 1: | ||
return STARTED; | ||
case 2: | ||
return FINALIZE; | ||
case 3: | ||
return DONE; | ||
case 4: | ||
return FAILURE; | ||
default: | ||
throw new ElasticsearchIllegalArgumentException("No snapshot shard stage for value [" + value + "]"); | ||
} | ||
} | ||
} |
157 changes: 157 additions & 0 deletions
157
...ava/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotIndexShardStatus.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,157 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.action.admin.cluster.snapshots.status; | ||
|
||
import org.elasticsearch.ElasticsearchIllegalArgumentException; | ||
import org.elasticsearch.action.support.broadcast.BroadcastShardOperationResponse; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.common.xcontent.ToXContent; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
import org.elasticsearch.common.xcontent.XContentBuilderString; | ||
import org.elasticsearch.index.shard.ShardId; | ||
import org.elasticsearch.index.snapshots.IndexShardSnapshotStatus; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
*/ | ||
public class SnapshotIndexShardStatus extends BroadcastShardOperationResponse implements ToXContent { | ||
|
||
private SnapshotIndexShardStage stage = SnapshotIndexShardStage.INIT; | ||
|
||
private SnapshotStats stats; | ||
|
||
private String nodeId; | ||
|
||
private String failure; | ||
|
||
private SnapshotIndexShardStatus() { | ||
} | ||
|
||
SnapshotIndexShardStatus(String index, int shardId, SnapshotIndexShardStage stage) { | ||
super(index, shardId); | ||
this.stage = stage; | ||
} | ||
|
||
SnapshotIndexShardStatus(ShardId shardId, IndexShardSnapshotStatus indexShardStatus) { | ||
this(shardId, indexShardStatus, null); | ||
} | ||
|
||
SnapshotIndexShardStatus(ShardId shardId, IndexShardSnapshotStatus indexShardStatus, String nodeId) { | ||
super(shardId.getIndex(), shardId.getId()); | ||
switch (indexShardStatus.stage()) { | ||
case INIT: | ||
stage = SnapshotIndexShardStage.INIT; | ||
break; | ||
case STARTED: | ||
stage = SnapshotIndexShardStage.STARTED; | ||
break; | ||
case FINALIZE: | ||
stage = SnapshotIndexShardStage.FINALIZE; | ||
break; | ||
case DONE: | ||
stage = SnapshotIndexShardStage.DONE; | ||
break; | ||
case FAILURE: | ||
stage = SnapshotIndexShardStage.FAILURE; | ||
break; | ||
default: | ||
throw new ElasticsearchIllegalArgumentException("Unknown stage type " + indexShardStatus.stage()); | ||
} | ||
stats = new SnapshotStats(indexShardStatus); | ||
failure = indexShardStatus.failure(); | ||
this.nodeId = nodeId; | ||
} | ||
|
||
/** | ||
* Returns snapshot stage | ||
*/ | ||
public SnapshotIndexShardStage getStage() { | ||
return stage; | ||
} | ||
|
||
/** | ||
* Returns snapshot stats | ||
*/ | ||
public SnapshotStats getStats() { | ||
return stats; | ||
} | ||
|
||
/** | ||
* Returns node id of the node where snapshot is currently running | ||
*/ | ||
public String getNodeId() { | ||
return nodeId; | ||
} | ||
|
||
/** | ||
* Returns reason for snapshot failure | ||
*/ | ||
public String getFailure() { | ||
return failure; | ||
} | ||
|
||
|
||
public static SnapshotIndexShardStatus readShardSnapshotStatus(StreamInput in) throws IOException { | ||
SnapshotIndexShardStatus shardStatus = new SnapshotIndexShardStatus(); | ||
shardStatus.readFrom(in); | ||
return shardStatus; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeByte(stage.value()); | ||
stats.writeTo(out); | ||
out.writeOptionalString(nodeId); | ||
out.writeOptionalString(failure); | ||
} | ||
|
||
@Override | ||
public void readFrom(StreamInput in) throws IOException { | ||
super.readFrom(in); | ||
stage = SnapshotIndexShardStage.fromValue(in.readByte()); | ||
stats = SnapshotStats.readSnapshotStats(in); | ||
nodeId = in.readOptionalString(); | ||
failure = in.readOptionalString(); | ||
} | ||
|
||
static final class Fields { | ||
static final XContentBuilderString STAGE = new XContentBuilderString("stage"); | ||
static final XContentBuilderString REASON = new XContentBuilderString("reason"); | ||
static final XContentBuilderString NODE = new XContentBuilderString("node"); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(Integer.toString(getShardId())); | ||
builder.field(Fields.STAGE, getStage()); | ||
stats.toXContent(builder, params); | ||
if (getNodeId() != null) { | ||
builder.field(Fields.NODE, getNodeId()); | ||
} | ||
if (getFailure() != null) { | ||
builder.field(Fields.REASON, getFailure()); | ||
} | ||
builder.endObject(); | ||
return builder; | ||
} | ||
} |
Oops, something went wrong.