Skip to content

Commit

Permalink
remove interval, add default max files
Browse files Browse the repository at this point in the history
  • Loading branch information
seattlevine committed Mar 7, 2018
1 parent 0dbf992 commit cc71480
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 52 deletions.
1 change: 1 addition & 0 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ Runs autoscale code to elect master and cluster
--dns-ip-type <address_type> Type of ip address to use (public | private).
--dns-app-port <port> Port on which application is listening on for health check
--dns-provider-options <dns_provider_options> Options specific to dns_provider. Ex: param1:value1,param2:value2 (default: [object Object])
--max-ucs-files <max_ucs_files_to_save> When running cluster action backup-ucs, maximum number of backup files to keep. (default: 10)
-h, --help output usage information
## network.js

Expand Down
Binary file modified dist/f5-cloud-libs.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/verifyHash
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cli script /Common/verifyHash {
proc script::run {} {
if {[catch {
set hashes(f5-cloud-libs.tar.gz) 906b48571d1000a98f5afdce55ee7ffb49de812ccc3ad23a88f45b06c40f88addb74f5791cab49663ffe373967e95e5e5eeb756275ba7d5d685baedb364ff429
set hashes(f5-cloud-libs.tar.gz) 8b07d245d4ee8e0bf0bb6d0e0a30a875b41f1d4f699e75807f002ac85a490368728d140398c582de78535c41c11d25402e653c7ebde6116f7b2076050b2116a0
set hashes(f5-cloud-libs-aws.tar.gz) 1a4ba191e997b2cfaaee0104deccc0414a6c4cc221aedc65fbdec8e47a72f1d5258b047d6487a205fa043fdbd6c8fcb1b978cac36788e493e94a4542f90bd92b
set hashes(f5-cloud-libs-azure.tar.gz) 5c256d017d0a57f5c96c2cb43f4d8b76297ae0b91e7a11c6d74e5c14268232f6a458bf0c16033b992040be076e934392c69f32fc8beffe070b5d84924ec7b947
set hashes(f5-cloud-libs-gce.tar.gz) 6ef33cc94c806b1e4e9e25ebb96a20eb1fe5975a83b2cd82b0d6ccbc8374be113ac74121d697f3bfc26bf49a55e948200f731607ce9aa9d23cd2e81299a653c1
Expand Down
85 changes: 42 additions & 43 deletions scripts/autoscale.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,9 @@ const commonOptions = require('./commonOptions');
const AUTOSCALE_PRIVATE_KEY = 'cloudLibsAutoscalePrivate';
const AUTOSCALE_PRIVATE_KEY_FOLDER = 'CloudLibsAutoscale';

const UCS_PREFIX = 'ucsAutosave_';
// TODO: change this back
// const UCS_BACKUP_INTERVAL_MS = 60 * 60000; // 1 hour
const UCS_BACKUP_INTERVAL_MS = 2 * 60000; // 2 minutes
const UCS_BACKUP_MAX_FILES = 10;
const UCS_DIRECTORY = '/var/local/ucs';
const UCS_BACKUP_PREFIX = 'ucsAutosave_';
const UCS_BACKUP_DEFAULT_MAX_FILES = 10;
const UCS_BACKUP_DIRECTORY = '/var/local/ucs';

let logger;

Expand Down Expand Up @@ -191,6 +188,11 @@ const commonOptions = require('./commonOptions');
util.map,
dnsProviderOptions
)
.option(
'--max-ucs-files <max_ucs_files_to_save>',
'When running cluster action backup-ucs, maximum number of backup files to keep.',
UCS_BACKUP_DEFAULT_MAX_FILES
)
.parse(argv);
/* eslint-enable max-len */

Expand Down Expand Up @@ -517,7 +519,7 @@ const commonOptions = require('./commonOptions');
return bigIp.cluster.configSyncIp(this.instance.privateIp);
case 'backup-ucs':
logger.info('Cluster action backup-ucs');
return handleBackupUcs.call(this, asProvider, bigIp);
return handleBackupUcs.call(this, asProvider, bigIp, options);
default:
message = `Unknown cluster action ${options.clusterAction}`;
logger.warn(message);
Expand Down Expand Up @@ -905,45 +907,42 @@ const commonOptions = require('./commonOptions');
return deferred.promise;
}

function handleBackupUcs(provider, bigIp) {
function handleBackupUcs(provider, bigIp, options) {
if (!this.instance.isMaster
|| this.instance.status !== AutoscaleInstance.INSTANCE_STATUS_OK) {
logger.debug('not master or not ready, skipping ucs backup');
return q();
}

const now = new Date().getTime();
const ucsName = `${UCS_PREFIX}${now}`;

if (now - this.instance.lastBackup > UCS_BACKUP_INTERVAL_MS) {
logger.info('Backing up UCS');
// ajv, which is installed as a dependency of the Azure node SDK has a couple files that start
// with '$'. prior to 13.1, Meanwhile, mcpd has a bug which fails to save a ucs if it runs
// into a file that starts with a '$'. So, let's just move the file. It's a bit ugly, but
// there's not really a better place to do this since it's a one-off bug. All of
// f5-cloud-libs is removed before ucs is loaded, so we don't need to do anything on that end.

this.instance.lastBackup = now;
return cleanupAjv(bigIp)
.then(() => {
return bigIp.saveUcs(ucsName);
})
.then(() => {
return provider.storeUcs(
`${UCS_DIRECTORY}/${ucsName}.ucs`,
UCS_BACKUP_MAX_FILES,
UCS_PREFIX
);
})
.then(() => {
return removeOldUcsFiles(`${ucsName}.ucs`);
})
.catch((err) => {
logger.info('Error backing up ucs', err);
return q.reject(err);
});
}
return q();
const ucsName = `${UCS_BACKUP_PREFIX}${now}`;

logger.info('Backing up UCS');
// ajv, which is installed as a dependency of the Azure node SDK has a couple files that start
// with '$'. prior to 13.1, Meanwhile, mcpd has a bug which fails to save a ucs if it runs
// into a file that starts with a '$'. So, let's just move the file. It's a bit ugly, but
// there's not really a better place to do this since it's a one-off bug. All of
// f5-cloud-libs is removed before ucs is loaded, so we don't need to do anything on that end.

this.instance.lastBackup = now;
return cleanupAjv(bigIp)
.then(() => {
return bigIp.saveUcs(ucsName);
})
.then(() => {
return provider.storeUcs(
`${UCS_BACKUP_DIRECTORY}/${ucsName}.ucs`,
options.maxUcsFiles,
UCS_BACKUP_PREFIX
);
})
.then(() => {
return removeOldUcsFiles(`${ucsName}.ucs`);
})
.catch((err) => {
logger.info('Error backing up ucs', err);
return q.reject(err);
});
}

/**
Expand Down Expand Up @@ -1594,14 +1593,14 @@ const commonOptions = require('./commonOptions');
const deferred = q.defer();

logger.silly('removing old ucs files');
fs.readdir(UCS_DIRECTORY, (err, files) => {
fs.readdir(UCS_BACKUP_DIRECTORY, (err, files) => {
if (err) {
logger.info(`Error reading ${UCS_DIRECTORY}`, err);
logger.info(`Error reading ${UCS_BACKUP_DIRECTORY}`, err);
deferred.reject(err);
} else {
files.forEach((file) => {
if (file.startsWith(UCS_PREFIX) && file !== latestFile) {
fs.unlinkSync(`${UCS_DIRECTORY}/${file}`);
if (file.startsWith(UCS_BACKUP_PREFIX) && file !== latestFile) {
fs.unlinkSync(`${UCS_BACKUP_DIRECTORY}/${file}`);
}
});
deferred.resolve();
Expand Down
8 changes: 0 additions & 8 deletions test/scripts/autoscaleTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -999,14 +999,6 @@ module.exports = {
});
},

testNotCalledTooSoon: function(test) {
instances.two.lastBackup = new Date().getTime();
autoscale.run(argv, testOptions, function() {
test.strictEqual(ucsBackupName, undefined);
test.done();
})
},

testOldFilesDeleted: function(test) {
test.expect(2);
autoscale.run(argv, testOptions, function() {
Expand Down

0 comments on commit cc71480

Please sign in to comment.