aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAlex Shatov <alexs@att.com>2018-02-01 14:18:52 -0500
committerAlex Shatov <alexs@att.com>2018-02-01 14:18:52 -0500
commit92effedd77c816b1bac67fbcf2b3a14a68930a90 (patch)
tree67dec79dfc08864b8136d919710a7658a9de361d /lib
parent4e30c82b172cf422ab5179e3c566ef01ca14cb3a (diff)
improved message to deployment-handler
* added errored_scopes and scope_prefixes to the message to deployment-handler - to prevent erroneous removal of policies * unit test coverage 67% Change-Id: I97a5d2e949273b4564f95e0a1dd71ac5eca66f41 Issue-ID: DCAEGEN2-249 Signed-off-by: Alex Shatov <alexs@att.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/policy.js28
1 files changed, 24 insertions, 4 deletions
diff --git a/lib/policy.js b/lib/policy.js
index 89e5b6a..87280e6 100644
--- a/lib/policy.js
+++ b/lib/policy.js
@@ -43,6 +43,8 @@ function policyUpdate(req, res, next) {
latest_policies : JSON.stringify((req.body && req.body.latest_policies) || {}),
removed_policies : JSON.stringify((req.body && req.body.removed_policies) || {}),
errored_policies : JSON.stringify((req.body && req.body.errored_policies) || {}),
+ errored_scopes : JSON.stringify((req.body && req.body.errored_scopes) || []),
+ scope_prefixes : JSON.stringify((req.body && req.body.scope_prefixes) || []),
policy_deployments : {},
updated_policy_ids : {},
added_policy_ids : {},
@@ -55,6 +57,8 @@ function policyUpdate(req, res, next) {
+ " latest_policies: " + policy_update.latest_policies
+ " removed_policies: " + policy_update.removed_policies
+ " errored_policies: " + policy_update.errored_policies
+ + " errored_scopes: " + policy_update.errored_scopes
+ + " scope_prefixes: " + policy_update.scope_prefixes
);
/**
* reply to and free up the policy_handler
@@ -64,11 +68,23 @@ function policyUpdate(req, res, next) {
policy_update.latest_policies = JSON.parse(policy_update.latest_policies);
policy_update.removed_policies = JSON.parse(policy_update.removed_policies);
policy_update.errored_policies = JSON.parse(policy_update.errored_policies);
+ policy_update.errored_scopes = JSON.parse(policy_update.errored_scopes);
+ policy_update.scope_prefixes = JSON.parse(policy_update.scope_prefixes);
+ const is_policy_in_scopes = function(policy_id) {
+ return policy_update.scope_prefixes.some(scope_prefix => {
+ return policy_id.startsWith(scope_prefix);
+ });
+ };
+
+ const is_policy_in_errored_scopes = function(policy_id) {
+ return policy_update.errored_scopes.some(errored_scope => {
+ return policy_id.startsWith(errored_scope);
+ });
+ };
/**
* filter out the policies to what is deployed in components and needs updating (new policyVersion)
*/
-
const collect_policy_deployments = function(node_instances) {
node_instances.forEach(node_instance => {
if (!node_instance.runtime_properties
@@ -90,10 +106,15 @@ function policyUpdate(req, res, next) {
const deployed_policies = node_instance.runtime_properties.policies || {};
Object.keys(deployed_policies).forEach(policy_id => {
+ const deployed_policy = deployed_policies[policy_id];
const latest_policy = policy_update.latest_policies[policy_id];
if (policy_update.removed_policies[policy_id]
- || (policy_update.catch_up && !latest_policy
- && !policy_update.errored_policies[policy_id])) {
+ || (policy_update.catch_up
+ && deployed_policy.policy_body
+ && !latest_policy
+ && !policy_update.errored_policies[policy_id])
+ && !is_policy_in_errored_scopes(policy_id)
+ && is_policy_in_scopes(policy_id)) {
have_policies = true;
deployment.removed_policy_ids[policy_id] = true;
policy_update.removed_policy_ids[policy_id] = true;
@@ -101,7 +122,6 @@ function policyUpdate(req, res, next) {
return;
}
- const deployed_policy = deployed_policies[policy_id];
if (!latest_policy || !latest_policy.policy_body
|| isNaN(latest_policy.policy_body.policyVersion)
|| latest_policy.policy_body.policyVersion