Skip to content

Commit ae1bf38

Browse files
author
Boris
committed
release v0.0.7
1 parent 4df341e commit ae1bf38

File tree

5 files changed

+132
-60
lines changed

5 files changed

+132
-60
lines changed

front/index.html

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ <h1 class="my-4">Snapshots list
6262
</h1>
6363

6464
<div class="d-flex align-items-center invisible" id="loading"><strong>Loading...</strong><div class="spinner-border ml-auto" role="status" aria-hidden="true"></div></div>
65-
<ul class="list-unstyled mb-0" id="snapshotlist"> </ul>
65+
<ul class="list-unstyled mb-0 overflow-auto" style="max-height: 800px;" id="snapshotlist"> </ul>
6666

6767
</div>
6868

@@ -347,14 +347,17 @@ <h5 class="modal-title" id="exampleModalLabel">X-tract indices from snapshot</h5
347347
dataType: 'json',
348348
contentType: 'application/json',
349349
success: function (data) {
350-
$("#result").html('<div class="alert alert-success alert-dismissible fade show">Index restored.<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>');
350+
if ( data.error == 0 ) {
351+
$("#result").html('<div class="alert alert-success alert-dismissible fade show">'+data.message+'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>');
352+
} else {
353+
$("#result").html('<div class="alert alert-danger alert-dismissible fade show">'+data.message+'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>')
354+
}
351355
},
352356
error: function (data) {
353-
console.log("error",data.responseJSON)
354-
$("#result").html('<div class="alert alert-danger alert-dismissible fade show">'+data.responseJSON.error+'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>')
357+
$("#result").html('<div class="alert alert-danger alert-dismissible fade show">'+data.responseJSON.message+'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>')
355358
}
356359
});
357-
event.preventDefault();
360+
event.preventDefault();
358361
});
359362

360363
$('#update_instance').on('hidden.bs.modal',function(){

mock/queries.txt

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,59 @@ POST /_snapshot/my_repository/snapshot_2/_restore?wait_for_completion=false
105105

106106
curl "http://localhost:9200/_snapshot/s3-backup/mp-2020.11.02/_restore?wait_for_completion=false" -H "Content-type: application/json" -d'
107107
{
108-
"indices": "mp-2020.11.01",
109-
"ignore_unavailable": true,
110-
"include_global_state": false,
111-
"rename_pattern": "(.+)",
112-
"rename_replacement": "restored_$1",
113-
"include_aliases": false
108+
"indices": "boris,filebeat-2020.10.10", "ignore_unavailable": true, "include_global_state": false, "rename_pattern": "(.+)", "rename_replacement": "restored_$1", "include_aliases": false
114109
}'
115110

111+
curl -ks https://opendistro:9200/_cat/indices/restored*?health=green
112+
113+
for _, iname := range request.Values.Indices {
114+
ind := snap_status.Snapshots[0].Indices[iname]
115+
116+
if ind.ShardsStats.Total == 1 {
117+
if ind.Stats.Total.Size < rt.nodes.max {
118+
119+
req := map[string]interface{}{
120+
"ignore_unavailable": false,
121+
"include_global_state": false,
122+
"include_aliases": false,
123+
"rename_pattern": "(.+)",
124+
"rename_replacement": "restored_$1",
125+
"indices": request.Values.Indices,
126+
"index_settings": map[string]interface{}{"index.number_of_replicas": 0},
127+
}
128+
129+
response, err := rt.doPost(rt.conf.Elastic.Host+"_snapshot/"+request.Values.Repo+"/"+request.Values.Snapshot+"/_restore?wait_for_completion=false", req)
130+
if err != nil {
131+
http.Error(w, err.Error(), 500)
132+
log.Println(remoteIP, "\t", r.Method, "\t", r.URL.Path, "\t", request.Action, "\t", 500, "\t", err.Error(), "\t", r.UserAgent())
133+
return
134+
}
135+
w.Write(response)
136+
137+
} else {
138+
msg := fmt.Sprintf("{\"error\":\"Restore index '%s' failed with: Not enough space\"}", iname)
139+
http.Error(w, msg, 600)
140+
log.Println(request.Action, "\t", 600, "\t", "Restore index '", iname, "' failed with: not enough space")
141+
return
142+
}
143+
} else { // индексы с snapshots >1 - пока восстанавливаем без проверок
144+
req := map[string]interface{}{
145+
"ignore_unavailable": false,
146+
"include_global_state": false,
147+
"include_aliases": false,
148+
"rename_pattern": "(.+)",
149+
"rename_replacement": "restored_$1",
150+
"indices": request.Values.Indices,
151+
"index_settings": map[string]interface{}{"index.number_of_replicas": 0},
152+
}
116153

154+
response, err := rt.doPost(rt.conf.Elastic.Host+"_snapshot/"+request.Values.Repo+"/"+request.Values.Snapshot+"/_restore?wait_for_completion=false", req)
155+
if err != nil {
156+
http.Error(w, err.Error(), 500)
157+
log.Println(remoteIP, "\t", r.Method, "\t", r.URL.Path, "\t", request.Action, "\t", 500, "\t", err.Error(), "\t", r.UserAgent())
158+
return
159+
}
160+
w.Write(response)
161+
}
117162

163+
} // end for

0 commit comments

Comments
 (0)