-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move the solr-utils lambda from aws-scaling
- Loading branch information
Showing
13 changed files
with
555 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
**/.terraform | ||
**/builds | ||
*.tfstate | ||
*.tfvars | ||
*.plan | ||
*.plan | ||
node_modules |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
terraform 1.3.7 | ||
tflint 0.44.1 | ||
terraform 1.6.2 | ||
tflint 0.48.0 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,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 }; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,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" | ||
} | ||
} |
Oops, something went wrong.