Skip to content

Commit

Permalink
make sure master is latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
seattlevine committed Jan 2, 2018
1 parent 1415efb commit 67887f3
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 19 deletions.
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) 8fd2183ea2a11be20291919d773461c01d2e253d3f6e5a23a11d2b8aa6466b9f3117b474dabd3a6a8d9d9d38927472065630aa669e0989b29f96a4cd80f32ebb
set hashes(f5-cloud-libs.tar.gz) 818b3d156283003889a12c3585bed7aba10a9e8bf0c97f21b0e9cf306f15a81d4f3ac52c1b1c503ae3d525f083937b777e2c2d0ecbc3347f968bf9625514915a
set hashes(f5-cloud-libs-aws.tar.gz) 1a4ba191e997b2cfaaee0104deccc0414a6c4cc221aedc65fbdec8e47a72f1d5258b047d6487a205fa043fdbd6c8fcb1b978cac36788e493e94a4542f90bd92b
set hashes(f5-cloud-libs-azure.tar.gz) f3b24e383b81090996f051279400679f26eb7c0ec1c1de3d712b446eea4a2cbd7d5edb4e1638033078339ba606451b35afaaa0a9e71fd04de3e3151434917b5d
set hashes(f5-cloud-libs-gce.tar.gz) 6ef33cc94c806b1e4e9e25ebb96a20eb1fe5975a83b2cd82b0d6ccbc8374be113ac74121d697f3bfc26bf49a55e948200f731607ce9aa9d23cd2e81299a653c1
Expand Down
1 change: 1 addition & 0 deletions lib/autoscaleProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ AutoscaleProvider.MESSAGE_SYNC_COMPLETE = 'SYNC_COMPLETE'; // a sync has been co
AutoscaleProvider.STATUS_OK = 'OK';
AutoscaleProvider.STATUS_NOT_EXTERNAL = 'NOT_EXTERNAL';
AutoscaleProvider.STATUS_NOT_IN_CLOUD_LIST = 'NOT_IN_CLOUD_LIST';
AutoscaleProvider.STATUS_VERSION_NOT_UP_TO_DATE = 'VERSION_NOT_UP_TO_DATE';
AutoscaleProvider.STATUS_UNKNOWN = 'UNKNOWN';

const MAX_STORED_INSTANCE_AGE = 60000 * 60 * 24; // 1 day
Expand Down
81 changes: 64 additions & 17 deletions scripts/autoscale.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
var logFileName;
var masterInstance;
var masterIid;
var masterExpired;
var masterBad;
var masterBadReason;
var newMaster;
var Provider;
var provider;
Expand Down Expand Up @@ -222,19 +223,34 @@
.then(function () {
return provider.bigIpReady();
}.bind(this))
.then(function() {
return bigIp.deviceInfo();
}.bind(this))
.then(function(response) {
this.instance.version = response.version;
return provider.putInstance(this.instanceId, this.instance);
}.bind(this))
.then(function() {
var status = AutoscaleProvider.STATUS_UNKNOWN;

logger.info('Determining master instance id.');
masterInstance = getMasterInstance(this.instances);

if (masterInstance) {
markVersions(this.instances);
if (!masterInstance.instance.versionOk) {
masterBadReason = 'version not most recent in group';
logger.silly(masterBadReason);
status = AutoscaleProvider.STATUS_VERSION_NOT_UP_TO_DATE;
masterBad = true;
}
// if there are external instances in the mix, make sure the master
// is one of them
if (!checkExternalMasterExternalValue(masterInstance.id, this.instances)) {
logger.silly('master is not external, but there are external instances');
else if (!isMasterExternalValueOk(masterInstance.id, this.instances)) {
masterBadReason = 'master is not external, but there are external instances';
logger.silly(masterBadReason);
status = AutoscaleProvider.STATUS_NOT_EXTERNAL;
masterExpired = true;
masterBad = true;
}
else if (!masterInstance.instance.providerVisible) {
// The cloud provider does not currently see this instance
Expand All @@ -256,24 +272,25 @@
.then(function() {
// If the master is not visible, check to see if it's been gone
// for a while or if this is a random error
if (masterInstance && !masterExpired && isMasterExpired(this.instance)) {
masterExpired = true;
if (masterInstance && !masterBad && isMasterExpired(this.instance)) {
masterBad = true;
masterBadReason = 'master is expired';
}

if (masterIid) {
logger.info('Possible master ID:', masterIid);
return provider.isValidMaster(masterIid, this.instances);
}
else if (masterExpired) {
logger.info('Old master expired or is not external when it should be.');
else if (masterBad) {
logger.info('Old master no longer valid:', masterBadReason);
}
else {
logger.info('No master ID found.');
}
}.bind(this))
.then(function(validMaster) {

logger.silly('validMaster:', validMaster, ', masterInstance: ', masterInstance, ', masterExpired:', masterExpired);
logger.silly('validMaster:', validMaster, ', masterInstance: ', masterInstance, ', masterBad:', masterBad);

if (validMaster) {
// true validMaster means we have a valid masterIid, just pass it on
Expand All @@ -290,7 +307,7 @@
// if no master, master is visible or expired, elect, otherwise, wait
if (!masterInstance ||
masterInstance.instance.providerVisible ||
masterExpired) {
masterBad) {

logger.info('Electing master.');
return provider.electMaster(this.instances);
Expand Down Expand Up @@ -350,9 +367,9 @@
if (this.instance.status === INSTANCE_STATUS_OK) {
switch(options.clusterAction) {
case 'join':
return handleJoin.call(this, provider, bigIp, masterIid, masterExpired, options);
return handleJoin.call(this, provider, bigIp, masterIid, masterBad, options);
case 'update':
return handleUpdate.call(this, provider, bigIp, masterIid, masterExpired, options);
return handleUpdate.call(this, provider, bigIp, masterIid, masterBad, options);
case 'unblock-sync':
logger.info("Cluster action UNBLOCK-SYNC");
return bigIp.cluster.configSyncIp(this.instance.privateIp);
Expand Down Expand Up @@ -401,7 +418,7 @@
*
* Called with this bound to the caller
*/
var handleJoin = function(provider, bigIp, masterIid, masterExpired, options) {
var handleJoin = function(provider, bigIp, masterIid, masterBad, options) {
var deferred = q.defer();

logger.info('Cluster action JOIN');
Expand Down Expand Up @@ -481,10 +498,10 @@
*
* Called with this bound to the caller
*/
var handleUpdate = function(provider, bigIp, masterIid, masterExpired, options) {
var handleUpdate = function(provider, bigIp, masterIid, masterBad, options) {
logger.info('Cluster action UPDATE');

if (this.instance.isMaster && !masterExpired) {
if (this.instance.isMaster && !masterBad) {
return checkForDisconnectedDevices.call(this, bigIp);
}
else if (!this.instance.isMaster) {
Expand All @@ -494,7 +511,7 @@
}

// If there is a new master, join the cluster
if (masterExpired && masterIid) {
if (masterBad && masterIid) {
return joinCluster.call(this, provider, bigIp, masterIid, options);
}
else if (masterIid) {
Expand Down Expand Up @@ -989,17 +1006,47 @@
}
};

/**
* Checks that master instance has the most recent
* version of all the BIG-IP instances
*
* @param {Object} instances - Instances map
*/
var markVersions = function(instances) {
var highestVersion = '0.0.0';
var instance;
var instanceId;

for (instanceId in instances) {
instance = instances[instanceId];
if (instance.version && util.versionCompare(instance.version, highestVersion) > 0) {
highestVersion = instance.version;
}
};

for (instanceId in instances) {
instance = instances[instanceId];
if (!instance.version || util.versionCompare(instance.version, highestVersion) === 0) {
instance.versionOk = true;
}
else {
instance.versionOk = false;
}
};
};

/**
* Checks that if there are external instances, the master is
* one of them
*
* @param {String} masterId - Instance ID of master
* @param {Object} instances - Instances map
*
* @returns {Boolean} True if there are no external instances or
* if there are external instances and the master is
* one of them
*/
var checkExternalMasterExternalValue = function(masterId, instances) {
var isMasterExternalValueOk = function(masterId, instances) {
var instanceIds = Object.keys(instances);
var instance;
var hasExternal;
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/autoscaleTests.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2016 F5 Networks, Inc.
* Copyright 2016-2018 F5 Networks, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down

0 comments on commit 67887f3

Please sign in to comment.