-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create test for
/_remotestore/_restore
endpoint
Signed-off-by: Thomas Farr <[email protected]>
- Loading branch information
Showing
4 changed files
with
283 additions
and
4 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,169 @@ | ||
{ | ||
"openapi": "3.0.2", | ||
"info": { | ||
"title": "OpenSearch", | ||
"version": "2021-11-23" | ||
}, | ||
"paths": { | ||
"/_remotestore/_restore": { | ||
"post": { | ||
"description": "Restore one or more indices from a remote backup.", | ||
"operationId": "PostRemoteStoreRestore", | ||
"requestBody": { | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"$ref": "#/components/schemas/PostRemoteStoreRestoreRequestContent" | ||
}, | ||
"examples": { | ||
"PostRemoteStoreRestore_example1": { | ||
"summary": "Examples for Post Remote Storage Restore Operation.", | ||
"description": "", | ||
"value": { | ||
"indices": [ | ||
"books" | ||
] | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"required": true | ||
}, | ||
"parameters": [ | ||
{ | ||
"name": "cluster_manager_timeout", | ||
"in": "query", | ||
"schema": { | ||
"type": "string", | ||
"pattern": "^([0-9]+)(?:d|h|m|s|ms|micros|nanos)$" | ||
} | ||
}, | ||
{ | ||
"name": "wait_for_completion", | ||
"in": "query", | ||
"schema": { | ||
"type": "boolean" | ||
} | ||
} | ||
], | ||
"responses": { | ||
"200": { | ||
"description": "PostRemoteStoreRestore 200 response", | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"$ref": "#/components/schemas/PostRemoteStoreRestoreResponseContent" | ||
}, | ||
"examples": { | ||
"PostRemoteStoreRestore_example1": { | ||
"summary": "Examples for Post Remote Storage Restore Operation.", | ||
"description": "", | ||
"value": { | ||
"remote_store": { | ||
"indices": [ | ||
"books" | ||
], | ||
"shards": { | ||
"total": 1, | ||
"failed": 0, | ||
"successful": 1 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"components": { | ||
"schemas": { | ||
"PostRemoteStoreRestoreRequestContent": { | ||
"type": "object", | ||
"properties": { | ||
"indices": { | ||
"type": "array", | ||
"items": { | ||
"type": "string", | ||
"pattern": "^[^+_\\-\\.][^\\\\, /*?\"<>| ,#\\nA-Z]+$" | ||
} | ||
} | ||
}, | ||
"required": [ | ||
"indices" | ||
] | ||
}, | ||
"PostRemoteStoreRestoreResponseContent": { | ||
"type": "object", | ||
"properties": { | ||
"accepted": { | ||
"type": "boolean" | ||
}, | ||
"remote_store": { | ||
"$ref": "#/components/schemas/RemoteStoreRestoreInfo" | ||
} | ||
}, | ||
"example": { | ||
"remote_store": { | ||
"indices": [ | ||
"books" | ||
], | ||
"shards": { | ||
"total": 1, | ||
"failed": 0, | ||
"successful": 1 | ||
} | ||
} | ||
} | ||
}, | ||
"RemoteStoreRestoreInfo": { | ||
"type": "object", | ||
"properties": { | ||
"snapshot": { | ||
"type": "string" | ||
}, | ||
"indices": { | ||
"type": "array", | ||
"items": { | ||
"type": "string", | ||
"pattern": "^[^+_\\-\\.][^\\\\, /*?\"<>| ,#\\nA-Z]+$" | ||
} | ||
}, | ||
"shards": { | ||
"$ref": "#/components/schemas/RemoteStoreRestoreShardsInfo" | ||
} | ||
} | ||
}, | ||
"RemoteStoreRestoreShardsInfo": { | ||
"type": "object", | ||
"properties": { | ||
"total": { | ||
"type": "number" | ||
}, | ||
"failed": { | ||
"type": "number" | ||
}, | ||
"successful": { | ||
"type": "number" | ||
} | ||
} | ||
} | ||
}, | ||
"securitySchemes": { | ||
"smithy.api.httpBasicAuth": { | ||
"type": "http", | ||
"description": "HTTP Basic authentication", | ||
"scheme": "Basic" | ||
} | ||
} | ||
}, | ||
"security": [ | ||
{ | ||
"smithy.api.httpBasicAuth": [] | ||
} | ||
] | ||
} |
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 @@ | ||
const https = require('https'); | ||
const fetch = require('node-fetch') | ||
const hooks = require('hooks'); | ||
const fs = require('fs'); | ||
|
||
var host = ""; | ||
var protocol = "https"; | ||
var auth = ""; | ||
|
||
// Reading .txt file to set URL | ||
const data = fs.readFileSync('url.txt', {encoding:'utf8', flag:'r'}); | ||
function address() | ||
{ | ||
text = data.toString(); | ||
text = text.split(" "); | ||
host = text[0].substring(8,text[0].length); | ||
auth = text[1]; | ||
return (protocol + "://" + auth + "@" + host); | ||
} | ||
|
||
// Remote Storage Restore | ||
|
||
hooks.before("/_remotestore/_restore > POST > 200 > application/json", function(transactions, done) { | ||
transactions.expected.headers['Content-Type'] = "application/json; charset=UTF-8"; | ||
|
||
const request = async () => { | ||
|
||
var url = address(); | ||
|
||
// Register repository for remote store | ||
await fetch(url + '/_snapshot/books-repo', { | ||
method: 'PUT', | ||
body: JSON.stringify({ | ||
type: 'fs', | ||
settings: { | ||
location: '/mnt/snapshots' | ||
} | ||
}), | ||
headers: { | ||
"content-type": "application/json; charset=UTF-8" | ||
} | ||
}); | ||
|
||
// Create an index configured for remote store | ||
await fetch(url + '/books', { | ||
method: 'PUT', | ||
body: JSON.stringify({ | ||
settings : { | ||
index: { | ||
number_of_shards: 1, | ||
number_of_replicas: 0, | ||
replication: { | ||
type: 'SEGMENT' | ||
}, | ||
remote_store: { | ||
enabled: true, | ||
repository: 'books-repo' | ||
} | ||
} | ||
} | ||
}), | ||
headers: { | ||
"content-type": "application/json; charset=UTF-8" | ||
} | ||
}); | ||
|
||
// Close the index | ||
await fetch(url + '/books/_close', { | ||
method: 'POST' | ||
}); | ||
|
||
done(); | ||
} | ||
|
||
request(); | ||
}); | ||
|
||
hooks.after("/_remotestore/_restore > POST > 200 > application/json", function(transactions, done) { | ||
|
||
const request = async () => { | ||
|
||
var url = address(); | ||
|
||
// Delete index | ||
await fetch(url + '/books', { | ||
method: 'DELETE' | ||
}); | ||
|
||
// Delete repository | ||
await fetch(url + '/_snapshot/books-repo', { | ||
method: 'DELETE' | ||
}); | ||
|
||
done(); | ||
} | ||
request(); | ||
}); | ||
|
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,7 @@ | ||
FROM opensearchproject/opensearch:latest | ||
|
||
USER root | ||
RUN mkdir -p /mnt/snapshots && chown -R opensearch:opensearch /mnt/snapshots | ||
|
||
USER opensearch | ||
VOLUME /mnt/snapshots |