Skip to content

Commit

Permalink
Move the solr-utils lambda from aws-scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
mbklein committed Oct 19, 2023
1 parent 282446c commit a9ca7bb
Show file tree
Hide file tree
Showing 13 changed files with 555 additions and 48 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
**/.terraform
**/builds
*.tfstate
*.tfvars
*.plan
*.plan
node_modules
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
terraform 1.3.7
tflint 0.44.1
terraform 1.6.2
tflint 0.48.0
94 changes: 77 additions & 17 deletions solrcloud/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 66 additions & 0 deletions solrcloud/backup-lambda/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
const { format } = require('date-and-time');
const SolrCluster = require('./solr_cluster');

const handler = async (event, _context) => {
switch (event.operation) {
case 'backup':
return await solrBackup(event);
case 'restore':
return await solrRestore(event);
case 'ready':
return await solrReady(event);
case 'set-log-level':
return await setLogLevel(event);
}
};

const setLogLevel = async (event) => {
const cluster = new SolrCluster(event.solr.baseUrl);
return await cluster.setLogLevel(event.level);
}

const solrBackup = async (event) => {
const cluster = new SolrCluster(event.solr.baseUrl);
if (event.collection) {
return await cluster.backup(event.collection);
} else if (event.collections) {
return await backupMultiple(cluster, event.collections);
} else {
const state = await cluster.status();
const collections = Object.keys(state.cluster.collections);
return await backupMultiple(cluster, collections);
}
};

const backupMultiple = async (cluster, collections) => {
const result = {};
const suffix = format(new Date(), '_YYYYMMDDHHmmss')
for (const collection of collections) {
result[collection] = await cluster.backup(collection, `${collection}${suffix}`);
}
return result;
};

const solrRestore = async (event) => {
const cluster = new SolrCluster(event.solr.baseUrl);
const collection = event.collection;
const name = event.name || collection;
const failIfExists = event.failIfExists === true;
const backupId = event.backupId;

return await cluster.restore(collection, name, { backupId, failIfExists });
}

const solrReady = async (event) => {
try {
const cluster = new SolrCluster(event.solr.baseUrl);
const desiredNodes = Number(event.solr.nodeCount);
const liveNodes = await cluster.liveNodeCount();
return liveNodes == desiredNodes;
} catch(err) {
console.error(err.code, err.reason);
return false;
}
};

module.exports = { handler };
180 changes: 180 additions & 0 deletions solrcloud/backup-lambda/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions solrcloud/backup-lambda/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "scaling-lambda",
"version": "0.1.0",
"description": "Lambda with function to help scale NUL AWS services up and down",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "MBK",
"license": "Apache-2.0",
"dependencies": {
"axios": "^1.5.1",
"date-and-time": "^3.0.3"
}
}
Loading

0 comments on commit a9ca7bb

Please sign in to comment.