Skip to content

Commit

Permalink
Create test for /_remotestore/_restore endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Farr <[email protected]>
  • Loading branch information
Xtansia committed Dec 5, 2022
1 parent c613964 commit d874905
Show file tree
Hide file tree
Showing 4 changed files with 283 additions and 4 deletions.
13 changes: 9 additions & 4 deletions test/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
version: '3'
services:
opensearch-node1:
image: opensearchproject/opensearch:latest
build: ./opensearch
container_name: opensearch-node1
environment:
- cluster.name=opensearch-cluster
- node.name=opensearch-node1
- discovery.seed_hosts=opensearch-node1,opensearch-node2
- cluster.initial_master_nodes=opensearch-node1,opensearch-node2
- bootstrap.memory_lock=true # along with the memlock settings below, disables swapping
- "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m" # minimum and maximum Java heap size, recommend setting both to 50% of system RAM
- path.repo=/mnt/snapshots
- "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m -Dopensearch.experimental.feature.replication_type.enabled=true -Dopensearch.experimental.feature.remote_store.enabled=true"
ulimits:
memlock:
soft: -1
Expand All @@ -19,22 +20,24 @@ services:
hard: 65536
volumes:
- opensearch-data1:/usr/share/opensearch/data
- opensearch-snapshots:/mnt/snapshots
ports:
- 9200:9200
- 9600:9600 # required for Performance Analyzer
networks:
- opensearch-net

opensearch-node2:
image: opensearchproject/opensearch:latest
build: ./opensearch
container_name: opensearch-node2
environment:
- cluster.name=opensearch-cluster
- node.name=opensearch-node2
- discovery.seed_hosts=opensearch-node1,opensearch-node2
- cluster.initial_master_nodes=opensearch-node1,opensearch-node2
- bootstrap.memory_lock=true
- "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m"
- path.repo=/mnt/snapshots
- "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m -Dopensearch.experimental.feature.replication_type.enabled=true -Dopensearch.experimental.feature.remote_store.enabled=true"
ulimits:
memlock:
soft: -1
Expand All @@ -44,12 +47,14 @@ services:
hard: 65536
volumes:
- opensearch-data2:/usr/share/opensearch/data
- opensearch-snapshots:/mnt/snapshots
networks:
- opensearch-net

volumes:
opensearch-data1:
opensearch-data2:
opensearch-snapshots:

networks:
opensearch-net:
169 changes: 169 additions & 0 deletions test/models/remotestore/restore/OpenSearchModel.json
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": []
}
]
}
98 changes: 98 additions & 0 deletions test/models/remotestore/restore/hooks.js
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();
});

7 changes: 7 additions & 0 deletions test/opensearch/Dockerfile
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

0 comments on commit d874905

Please sign in to comment.