From a5739ab3e9f7f97652e6814233abeee51f28db5e Mon Sep 17 00:00:00 2001 From: Alex Shatov Date: Fri, 3 Aug 2018 14:39:33 -0400 Subject: 3.0.0 new dataflow on policy-update and catchup - external version 3.0.0 - internal version 5.0.0 for API and code - changed API and functionality - new dataflow - new dataflow between policy-handler and deployment-handler on policy-update and catchup = GET /policy - returns the deployed policy_ids+versions and policy-filters = PUT /policy updates policies on deployed components = new message format for policy-update and catchup = matching by policy_id+version and policy_filter_id only - removed POST to /policy - the obsolete API = removed the 'smart' matching of the policies by policy-filter -- it is done by the policy-handler now Coverage summary Statements : 77.06% ( 870/1129 ) Branches : 53.55% ( 264/493 ) Functions : 78.53% ( 150/191 ) Lines : 77.45% ( 862/1113 ) Change-Id: I5409f32e1acd4870f1d74b466902a796fa10f6c7 Signed-off-by: Alex Shatov Issue-ID: DCAEGEN2-492 --- deployment-handler-API.yaml | 181 ++++++++++++++++++++---- deployment-handler.js | 2 +- lib/cloudify.js | 14 +- lib/policy.js | 314 +++++++++++++++++++++-------------------- package.json | 2 +- pom.xml | 2 +- tests/test_dcae-deployments.js | 2 +- tests/test_policy.js | 61 ++++---- version.properties | 4 +- 9 files changed, 353 insertions(+), 229 deletions(-) diff --git a/deployment-handler-API.yaml b/deployment-handler-API.yaml index b85a554..b910f9b 100644 --- a/deployment-handler-API.yaml +++ b/deployment-handler-API.yaml @@ -20,7 +20,7 @@ swagger: '2.0' info: - version: "4.3.0" + version: "5.0.0" title: "deployment-handler API" license: name: "Apache 2.0" @@ -140,7 +140,7 @@ paths: - name: cfy_tenant_name description: | Tenant Name in Cloudify. Optional, if not specified, "default_tenant" will be used. - in: path + in: query type: string required: false @@ -267,7 +267,7 @@ paths: - name: cfy_tenant_name description: | Tenant Name in Cloudify. Optional, if not specified, "default_tenant" will be used. - in: path + in: query type: string required: false @@ -305,7 +305,28 @@ paths: $ref: "#/definitions/DCAEErrorResponse" /policy: - post: + get: + tags: + - "policy" + description: debug API to find deployed policies and policy-filters on components + produces: + - application/json + + parameters: + - name: cfy_tenant_name + description: | + Tenant Name in Cloudify. Optional, if not specified, "default_tenant" will be used. + in: query + type: string + required: false + + responses: + 200: + description: policies and policy_filters found on deployed components + schema: + $ref: "#/definitions/DCAEPoliciesResponse" + + put: tags: - "policy" description: policy update API consumed by policy-handler @@ -319,18 +340,20 @@ paths: - name: cfy_tenant_name description: | Tenant Name in Cloudify. Optional, if not specified, "default_tenant" will be used. - in: path + in: query type: string required: false - name: body in: body schema: - $ref: "#/definitions/DCAEPolicyRequest" + $ref: "#/definitions/DCAEPolicyUpdateRequest" required: true responses: 200: description: deployment-handler always responds with ok to /policy before processing the request + schema: + $ref: "#/definitions/DCAEPolicyUpdateResponse" /policy/components: get: @@ -344,7 +367,7 @@ paths: - name: cfy_tenant_name description: | Tenant Name in Cloudify. Optional, if not specified, "default_tenant" will be used. - in: path + in: query type: string required: false @@ -508,17 +531,28 @@ definitions: policy_body: $ref: "#/definitions/DCAEPolicyBody" - DCAEPolicyRequest: + DCAEPolicyMatchToFilters: + description: | + collection of policy-filter-ids the policy matches to + dictionary of (policy_filter_id -> true) + In example: replace additionalProp1,2,3 with policy_filter_id1,2,3 values + type: object + default: {} + additionalProperties: + type: boolean + + DCAEPolicyUpdateRequest: description: request to update policies on DCAE components. type: object required: - catch_up - latest_policies - removed_policies + - policy_filter_matches properties: catch_up: - description: flag to indicate whether the request contains all the policies in PDP or not + description: indicates whether the request contains the policies for catch_up event type: boolean default: false @@ -541,28 +575,123 @@ definitions: additionalProperties: type: boolean - errored_policies: + policy_filter_matches: description: | - whether policy-engine returned an error on the policy. - dictionary of (policy_id -> true). + whether latest policy matches to policy-filters + dictionary of (policy_id -> DCAEPolicyMatchToFilters). In example: replace additionalProp1,2,3 with policy_id1,2,3 values type: object default: {} + additionalProperties: + $ref: "#/definitions/DCAEPolicyMatchToFilters" + + DCAEPolicyUpdateResponse: + description: response to update policies on DCAE components. + type: object + properties: + server_instance_uuid: + description: uuid of the deployment-handler instance + type: string + + + DCAEPolicyTopInfo: + description: | + single policy-info object that contains policy_id + and the collection of policy-versions along with the indicator + that at least one deployment that contains that policy is busy with execution + type: object + required: + - policy_id + - policy_versions + - pending_update + + properties: + policy_id: + description: unique identifier of policy regardless of its version + type: string + policy_versions: + description: | + dictionary of (policy_version -> true). + In example: replace additionalProp1,2,3 with "1","2","3" keys + For instance {"1":true, "3":true} + type: object + default: {} additionalProperties: type: boolean + pending_update: + description: | + boolean indicating whether there are any executions are in place + for any of deployments that have this policy + type: boolean - errored_scopes: - description: > - on cartchup - list of policy scope_prefix values on wchich - the policy-engine experienced an error other than not-found data. - type: array - items: - type: string + DCAEPolicyFilter: + description: single policy-filter object + type: object + required: + - policy_filter_id + - policy_filter + - pending_update - scope_prefixes: - description: > - on catchup - list of all scope_prefixes used by the policy-handler - to retrieve the policies from policy-engine. - type: array - items: - type: string + properties: + policy_filter_id: + description: unique identifier of deployed policy-filter + type: string + policy_filter: + description: policy-filter contains fields used in /getConfig on policy-engine API + type: object + properties: + policyName: + description: string or regular expression to match policyName in policy-engine + type: string + unique: + description: whether expected unique or not policy in policy-engine + type: boolean + onapName: + description: name of ONAP system for the policy in policy-engine + type: string + configName: + description: name of ONAP system for the policy in policy-engine + type: string + configAttributes: + description: dictionary of (key -> value) pairs used to match the policy + type: object + default: {} + additionalProperties: + type: string + + pending_update: + description: | + boolean indicating whether there are any executions are in place + for any of deployments that have this policy + type: boolean + + DCAEPoliciesResponse: + description: response to get /policy + type: object + required: + - server_instance_uuid + - policies + - policy_filters + + properties: + server_instance_uuid: + description: uuid of the deployment-handler instance + type: string + + policies: + description: | + dictionary of (policy_id -> DCAEPolicyTopInfo object). + In example: replace additionalProp1,2,3 with policy_id1,2,3 values + type: object + default: {} + additionalProperties: + $ref: "#/definitions/DCAEPolicyTopInfo" + + policy_filters: + description: | + dictionary of (policy_filter_id -> DCAEPolicyFilter object). + In example: replace additionalProp1,2,3 with policy_id1,2,3 values + type: object + default: {} + additionalProperties: + $ref: "#/definitions/DCAEPolicyFilter" diff --git a/deployment-handler.js b/deployment-handler.js index 2ae1391..02a0750 100644 --- a/deployment-handler.js +++ b/deployment-handler.js @@ -18,7 +18,7 @@ See the License for the specific language governing permissions and limitations "use strict"; -const API_VERSION = "4.3.0"; +const API_VERSION = "5.0.0"; const fs = require('fs'); const util = require('util'); diff --git a/lib/cloudify.js b/lib/cloudify.js index 2db460a..053bdb8 100644 --- a/lib/cloudify.js +++ b/lib/cloudify.js @@ -67,14 +67,6 @@ ExeQueue.prototype.nextExecution = function(deployment_id) { const exeQueue = new ExeQueue(); exports.exeQueue = exeQueue; -// Delay function--returns a promise that's resolved after 'dtime' -// milliseconds.` -var delay = function(dtime) { - return new Promise(function(resolve, reject) { - setTimeout(resolve, dtime); - }); -}; - // Get current status of a workflow execution const getExecutionStatus = function(req, execution_id) { var reqOptions = { @@ -407,8 +399,8 @@ exports.getNodeInstances = function (mainReq, on_next_node_instances, offset) { const runQueuedExecution = function(mainReq, deployment_id, workflow_id, parameters, waitedCount) { mainReq = mainReq || {}; var execution_id; - var exe_deployment_str = " deployment_id " + deployment_id + " to " + workflow_id - + " with params(" + JSON.stringify(parameters || {}) + ")"; + const exe_deployment_str = " deployment_id " + deployment_id + " to " + workflow_id + + " with params(" + JSON.stringify(parameters || {}) + ")"; startWorkflowExecution(mainReq, deployment_id, workflow_id, parameters) .then(function(result) { logger.info(mainReq.dcaeReqId, "result of start the execution for" + exe_deployment_str + ": " + JSON.stringify(result)); @@ -461,7 +453,7 @@ const runQueuedExecution = function(mainReq, deployment_id, workflow_id, paramet exports.executeOperation = function (mainReq, deployment_id, operation, operation_kwargs, node_instance_ids) { const workflow_id = "execute_operation"; - var parameters = { + const parameters = { 'operation': operation, 'operation_kwargs': operation_kwargs, 'node_instance_ids': node_instance_ids, diff --git a/lib/policy.js b/lib/policy.js index 1aefc8a..d6a701f 100644 --- a/lib/policy.js +++ b/lib/policy.js @@ -34,32 +34,72 @@ cloudify.setCredentials(config.cloudify.user, config.cloudify.password); cloudify.setLogger(logger); /** - * receive the policy-updated message from the policy-handler + * send the policy-update execute-operation to cloudify per deployment */ -function policyUpdate(req, res, next) { +const update_policies_on_deployments = function(result, req, policy_update) { + logger.info(req.dcaeReqId, "finished loading policy_deployments" + JSON.stringify(result)); + if (result.status !== 200) { + const error_msg = "failed to retrieve component policies from cloudify " + result.message; + logger.error(createError(error_msg, result.status, "api", 502, 'cloudify-manager'), req); + logger.audit(req, result.status, error_msg); + return; + } + + const deployment_ids = Object.keys(policy_update.policy_deployments); + if (!deployment_ids.length) { + const audit_msg = "no updated policies to apply to deployments"; + logger.debug(req.dcaeReqId, audit_msg); + logger.audit(req, result.status, audit_msg); + return; + } + const audit_msg = "going to apply updated policies[" + Object.keys(policy_update.updated_policy_ids).length + + "] and added policies[" + Object.keys(policy_update.added_policy_ids).length + + "] and removed policies[" + Object.keys(policy_update.removed_policy_ids).length + + "] to deployments[" + deployment_ids.length + "]"; + logger.info(req.dcaeReqId, audit_msg + ": " + JSON.stringify(deployment_ids)); + logger.audit(req, result.status, audit_msg); + deployment_ids.forEach(deployment_id => { + const deployment = policy_update.policy_deployments[deployment_id]; + deployment.updated_policies = Object.keys(deployment.updated_policies).map(policy_id => { + return deployment.updated_policies[policy_id]; + }); + deployment.removed_policy_ids = Object.keys(deployment.removed_policy_ids); + + logger.info(req.dcaeReqId, "ready to execute-operation policy-update on deployment " + JSON.stringify(deployment)); + cloudify.executeOperation(req, deployment.deployment_id, POLICY_UPDATE_OPERATION, + { + 'updated_policies': deployment.updated_policies, + 'added_policies': deployment.added_policies, + 'removed_policies': deployment.removed_policy_ids + }, + deployment.node_instance_ids + ); + }); +}; + +/** + * receive the policy-updated message from the policy-handler and send to cloudify + * - redesigned data-flow 2018 - R3 Casablanca + */ +function update_policies(req, res) { const policy_update = { - catch_up : req.body && req.body.catch_up, 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_filter_matches : JSON.stringify((req.body && req.body.policy_filter_matches) || {}), + policy_matches_by_filter : {}, policy_deployments : {}, updated_policy_ids : {}, added_policy_ids : {}, removed_policy_ids : {} }; - logger.info(req.dcaeReqId, "policyUpdate " - + req.method + ' ' + req.protocol + '://' + req.get('host') + req.originalUrl - + " catch_up: " + policy_update.catch_up - + " 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 - ); + logger.info(req.dcaeReqId, "update_policies " + + req.method + ' ' + req.protocol + '://' + req.get('host') + req.originalUrl + + " latest_policies: " + policy_update.latest_policies + + " removed_policies: " + policy_update.removed_policies + + " policy_filter_matches: " + policy_update.policy_filter_matches + ); /** * reply to and free up the policy_handler */ @@ -70,25 +110,32 @@ 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); + policy_update.policy_filter_matches = JSON.parse(policy_update.policy_filter_matches); - const is_policy_in_scopes = function(policy_id) { - return policy_update.scope_prefixes.some(scope_prefix => { - return policy_id.startsWith(scope_prefix); + Object.keys(policy_update.policy_filter_matches).forEach(policy_id => { + Object.keys(policy_update.policy_filter_matches[policy_id]).forEach(policy_filter_id => { + var policy_ids_by_filter = policy_update.policy_matches_by_filter[policy_filter_id]; + if (!policy_ids_by_filter) { + policy_ids_by_filter = policy_update.policy_matches_by_filter[policy_filter_id] = {}; + } + policy_ids_by_filter[policy_id] = true; }); - }; + }); - const is_policy_in_errored_scopes = function(policy_id) { - return policy_update.errored_scopes.some(errored_scope => { - return policy_id.startsWith(errored_scope); - }); + const is_policy_update_in_filters = function(policy_id, policy_filters) { + if (!policy_id || !policy_filters) {return null;} + + const policy_update_filters = policy_update.policy_filter_matches[policy_id]; + if (!policy_update_filters) {return null;} + + return Object.keys(policy_update_filters).some(policy_filter_id => + !!policy_filters[policy_filter_id]); }; + /** * filter out the policies to what is deployed in components and needs updating (new policyVersion) */ - const collect_policy_deployments = function(node_instances) { + const collect_policy_deployments = function collect_policy_deployments(node_instances) { node_instances.forEach(node_instance => { if (!node_instance.runtime_properties || (!node_instance.runtime_properties.policies @@ -108,17 +155,14 @@ function policyUpdate(req, res, next) { var have_policies = false; const deployed_policies = node_instance.runtime_properties.policies || {}; + const deployed_policy_filters = node_instance.runtime_properties.policy_filters; 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 - && (deployed_policy.policy_body || deployment.is_deployment_busy) - && !latest_policy - && !policy_update.errored_policies[policy_id] - && !is_policy_in_errored_scopes(policy_id) - && is_policy_in_scopes(policy_id))) { + if ((deployed_policy.policy_body || deployment.is_deployment_busy) + && (policy_update.removed_policies[policy_id] + || (!deployed_policy.policy_persistent + && false === is_policy_update_in_filters(policy_id, deployed_policy_filters)))) { have_policies = true; deployment.removed_policy_ids[policy_id] = true; policy_update.removed_policy_ids[policy_id] = true; @@ -126,6 +170,7 @@ function policyUpdate(req, res, next) { return; } + const latest_policy = policy_update.latest_policies[policy_id]; if (!latest_policy || !latest_policy.policy_body || isNaN(latest_policy.policy_body.policyVersion)) {return;} @@ -138,86 +183,27 @@ function policyUpdate(req, res, next) { logger.info(req.dcaeReqId, "going to update policy " + policy_id + " on node_instance: " + JSON.stringify(node_instance)); }); - const policy_filters = node_instance.runtime_properties.policy_filters || {}; - const policy_filter_ids = Object.keys(policy_filters); - if (policy_filter_ids.length) { - logger.info(req.dcaeReqId, "matching latest policies to policy_filters[" + policy_filter_ids.length + "] on node_instance: " + JSON.stringify(node_instance)); - try { - Object.keys(policy_update.latest_policies).forEach(policy_id => { - if (!deployment.is_deployment_busy && deployed_policies[policy_id]) {return;} - - const latest_policy = policy_update.latest_policies[policy_id]; - const policy_body = latest_policy && latest_policy.policy_body; - if (!policy_body || isNaN(policy_body.policyVersion)) {return;} - const policy_name = policy_body.policyName; - if (!policy_name) {return;} - const matching_conditions = policy_body.matchingConditions || {}; - - logger.debug(req.dcaeReqId, "matching policy " + JSON.stringify(latest_policy)); - policy_filter_ids.some(policy_filter_id => { - const policy_filter = policy_filters[policy_filter_id].policy_filter; - if (!policy_filter || !policy_filter.policyName) {return false;} - - logger.debug(req.dcaeReqId, "matching to policy_filter " + JSON.stringify(policy_filter)); - - if (!!policy_filter.onapName - && policy_filter.onapName !== matching_conditions.ONAPName) { - logger.debug(req.dcaeReqId, "not match policy_filter_id " + policy_filter_id - + " by ONAPName: " - + policy_filter.onapName + " !== " + matching_conditions.ONAPName); - return false; - } - if (!!policy_filter.configName - && policy_filter.configName !== matching_conditions.ConfigName) { - logger.debug(req.dcaeReqId, "not match policy_filter_id " + policy_filter_id - + " by configName: " - + policy_filter.configName + " !== " + matching_conditions.ConfigName); - return false; - } - - if (policy_filter.configAttributes - && !Object.keys(policy_filter.configAttributes).every(filter_key => { - return (matching_conditions.hasOwnProperty(filter_key) - && policy_filter.configAttributes[filter_key] - === matching_conditions[filter_key]); - })) { - logger.debug(req.dcaeReqId, "not match policy_filter_id " + policy_filter_id - + " by configAttributes: " - + JSON.stringify(policy_filter.configAttributes) + " !== " + JSON.stringify(matching_conditions)); - return false; - } - - if (policy_filter.policyName !== policy_id && policy_filter.policyName !== policy_name) { - const match_policy_name = new RegExp(policy_filter.policyName); - if (!match_policy_name.test(policy_name)) { - logger.debug(req.dcaeReqId, "not match policy_filter_id " + policy_filter_id - + " by policyName: " - + policy_filter.policyName + " versus " + policy_name); - return false; - } - } - - have_policies = true; - if (!deployment.added_policies[policy_filter_id]) { - deployment.added_policies[policy_filter_id] = { - "policy_filter_id" : policy_filter_id, - "policies" : {} - }; - } - deployment.added_policies[policy_filter_id].policies[policy_id] = latest_policy; - policy_update.added_policy_ids[policy_id] = true; - logger.info(req.dcaeReqId, "going to add policy " + JSON.stringify(latest_policy) - + " per policy_filter_id " + policy_filter_id - + " on node_instance: " + JSON.stringify(node_instance)); - return true; - }); - }); - } catch (e) { - const error_msg = "error on matching policy to filter " + (e.message || "") - + " " + (e.stack || "").replace(/\n/g, " ") - logger.error(createError(error_msg, 500, "api", 553, 'deployment-handler'), req); - } - } + Object.keys(deployed_policy_filters || {}).forEach(policy_filter_id => { + Object.keys(policy_update.policy_matches_by_filter[policy_filter_id] || {}).forEach(policy_id => { + if (!deployment.is_deployment_busy && deployed_policies[policy_id]) {return;} + + const latest_policy = policy_update.latest_policies[policy_id]; + const policy_body = latest_policy && latest_policy.policy_body; + if (!policy_body || isNaN(policy_body.policyVersion)) {return;} + + have_policies = true; + deployment.added_policies[policy_filter_id] = deployment.added_policies[policy_filter_id] || { + "policy_filter_id" : policy_filter_id, + "policies" : {} + }; + + deployment.added_policies[policy_filter_id].policies[policy_id] = latest_policy; + policy_update.added_policy_ids[policy_id] = true; + logger.info(req.dcaeReqId, "going to add policy " + JSON.stringify(latest_policy) + + " per policy_filter_id " + policy_filter_id + + " on node_instance: " + JSON.stringify(node_instance)); + }); + }); if (have_policies) { deployment.node_instance_ids.push(node_instance.id); @@ -228,50 +214,66 @@ function policyUpdate(req, res, next) { logger.info(req.dcaeReqId, "collected policy_deployments to update " + JSON.stringify(policy_update.policy_deployments)); }; - const update_policies_on_deployments = function(result) { - logger.info(req.dcaeReqId, "finished loading policy_deployments" + JSON.stringify(result)); - if (result.status !== 200) { - const error_msg = "failed to retrieve component policies from cloudify " + result.message; - logger.error(createError(error_msg, result.status, "api", 502, 'cloudify-manager'), req); - logger.audit(req, result.status, error_msg); - return; - } + cloudify.getNodeInstances(req, collect_policy_deployments) + .then(result => {update_policies_on_deployments(result, req, policy_update);}); +} - const deployment_ids = Object.keys(policy_update.policy_deployments); - if (!deployment_ids.length) { - const audit_msg = "no updated policies to apply to deployments"; - logger.debug(req.dcaeReqId, audit_msg); - logger.audit(req, result.status, audit_msg); - return; - } - const audit_msg = "going to apply updated policies[" + Object.keys(policy_update.updated_policy_ids).length - + "] and added policies[" + Object.keys(policy_update.added_policy_ids).length - + "] and removed policies[" + Object.keys(policy_update.removed_policy_ids).length - + "] to deployments[" + deployment_ids.length + "]"; - logger.info(req.dcaeReqId, audit_msg + ": " + JSON.stringify(deployment_ids)); - logger.audit(req, result.status, audit_msg); - deployment_ids.forEach(deployment_id => { - const deployment = policy_update.policy_deployments[deployment_id]; - deployment.updated_policies = Object.keys(deployment.updated_policies).map(policy_id => { - return deployment.updated_policies[policy_id]; - }); - deployment.removed_policy_ids = Object.keys(deployment.removed_policy_ids); - - logger.info(req.dcaeReqId, "ready to execute-operation policy-update on deployment " + JSON.stringify(deployment)); - cloudify.executeOperation(req, deployment.deployment_id, POLICY_UPDATE_OPERATION, - { - 'updated_policies': deployment.updated_policies, - 'added_policies': deployment.added_policies, - 'removed_policies': deployment.removed_policy_ids - }, - deployment.node_instance_ids - ); +/** + * retrieve the unique set of policies and policy-filters from cloudify + */ +function get_policies_from_cloudify(req, res, next) { + logger.info(req.dcaeReqId, "getPoliciesFromCloudify " + req.originalUrl); + const response = {"requestID": req.dcaeReqId}; + response.started = new Date(); + response.server_instance_uuid = process.mainModule.exports.config.server_instance_uuid; + response.policies = {}; + response.policy_filters = {}; + + cloudify.getNodeInstances(req, function(node_instances) { + node_instances.forEach(node_instance => { + if (!node_instance.runtime_properties) {return;} + const pending_update = cloudify.exeQueue.isDeploymentBusy(node_instance.deployment_id); + + if (node_instance.runtime_properties.policies) { + Object.keys(node_instance.runtime_properties.policies).forEach(policy_id => { + const deployed_policy = response.policies[policy_id] || { + "policy_id": policy_id, + "policy_versions": {} + }; + const policy = node_instance.runtime_properties.policies[policy_id]; + if (policy.policy_body && policy.policy_body.policyVersion) { + deployed_policy.policy_versions[policy.policy_body.policyVersion] = true; + } + deployed_policy.pending_update = deployed_policy.pending_update || pending_update; + response.policies[policy_id] = deployed_policy; + }); + } + if (node_instance.runtime_properties.policy_filters) { + Object.keys(node_instance.runtime_properties.policy_filters).forEach(policy_filter_id => { + node_instance.runtime_properties.policy_filters[policy_filter_id].pending_update = pending_update; + }); + Object.assign(response.policy_filters, node_instance.runtime_properties.policy_filters); + } }); - }; - cloudify.getNodeInstances(req, collect_policy_deployments).then(update_policies_on_deployments); + logger.info(req.dcaeReqId, "deployed policies: " + JSON.stringify(response.policies) + + " policy_filters: " + JSON.stringify(response.policy_filters) + ); + }) + .then(function(result) { + response.ended = new Date(); + response.status = result.status; + response.message = result.message; + logger.info(req.dcaeReqId, result.message); + if (result.status !== 200) { + logger.error(createError(result.message, result.status, "api", 502, 'cloudify-manager'), req); + } + res.status(result.status).json(response); + logger.audit(req, result.status, result.message); + }); } + /** * retrieve all component-policies from cloudify */ @@ -358,7 +360,9 @@ app.use(function(req, res, next) { next(); }); -app.post('/', policyUpdate); +app.get('/', get_policies_from_cloudify); +app.put('/', update_policies); + app.get('/components', getComponentPoliciesFromCloudify); module.exports = app; diff --git a/package.json b/package.json index 033d064..196c8e2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "onap-dcae-deployment-handler", - "version": "4.5.0", + "version": "5.0.0", "description": "ONAP DCAE Deployment Handler", "main": "deployment-handler.js", "dependencies": { diff --git a/pom.xml b/pom.xml index a076d59..78b4048 100644 --- a/pom.xml +++ b/pom.xml @@ -29,7 +29,7 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property. org.onap.dcaegen2.platform deployment-handler dcaegen2-platform-deployment-handler - 2.2.0-SNAPSHOT + 3.0.0-SNAPSHOT http://maven.apache.org UTF-8 diff --git a/tests/test_dcae-deployments.js b/tests/test_dcae-deployments.js index 664615e..a010017 100644 --- a/tests/test_dcae-deployments.js +++ b/tests/test_dcae-deployments.js @@ -104,7 +104,7 @@ const Inventory = { "owner": "dcaeorch", "typeName": "svc-type-000", "typeVersion": 1, - "blueprintTemplate": "tosca_definitions_version: cloudify_dsl_1_3\nimports:\n - \"http://www.getcloudify.org/spec/cloudify/3.4/types.yaml\"\n - https://nexus.onap.org/service/local/repositories/raw/content/org.onap.dcaegen2.platform.plugins/R3/dockerplugin/3.2.0/dockerplugin_types.yaml\n - https://nexus.onap.org/service/local/repositories/raw/content/org.onap.dcaegen2.platform.plugins/R3/relationshipplugin/1.0.0/relationshipplugin_types.yaml\n - https://nexus.onap.org/service/local/repositories/raw/content/org.onap.dcaegen2.platform.plugins/R3/dcaepolicyplugin/2.3.0/dcaepolicyplugin_types.yaml\n\ninputs:\n dh_override:\n type: string\n default: \"dockerhost\"\n dh_location_id:\n type: string\n default: \"zone1\"\n aaiEnrichmentHost:\n type: string\n default: \"none\"\n aaiEnrichmentPort:\n type: string \n default: 8443\n enableAAIEnrichment:\n type: string\n default: false\n dmaap_host:\n type: string\n default: dmaap.onap-message-router \n dmaap_port:\n type: string\n default: 3904 \n enableRedisCaching:\n type: string\n default: false \n redisHosts:\n type: string \n tag_version:\n type: string\n default: \"nexus3.onap.org:10001/onap/org.onap.dcaegen2.deployments.tca-cdap-container:1.0.0\"\n consul_host:\n type: string\n default: consul-server.onap-consul\n consul_port:\n type: string\n default: \"8500\"\n cbs_host:\n type: string\n default: \"config-binding-service.dcae\"\n cbs_port:\n type: string\n default: \"10000\"\n policy_id:\n type: string\n default: \"none\"\n external_port:\n type: string\n description: \"Port for CDAPgui to be exposed\"\n default: \"32010\"\n scn_name: \n default: dcaegen2-analytics_tca_clampinstance_1\n type: string\nnode_templates:\n docker_service_host:\n properties:\n docker_host_override:\n get_input: dh_override\n location_id:\n get_input: dh_location_id\n type: dcae.nodes.SelectedDockerHost\n tca_docker:\n relationships:\n - type: dcae.relationships.component_contained_in\n target: docker_service_host\n - target: tca_policy\n type: cloudify.relationships.depends_on \n type: dcae.nodes.DockerContainerForComponentsUsingDmaap\n properties:\n application_config:\n app_config:\n appDescription: DCAE Analytics Threshold Crossing Alert Application\n appName: dcae-tca\n tcaAlertsAbatementTableName: TCAAlertsAbatementTable\n tcaAlertsAbatementTableTTLSeconds: '1728000'\n tcaSubscriberOutputStreamName: TCASubscriberOutputStream\n tcaVESAlertsTableName: TCAVESAlertsTable\n tcaVESAlertsTableTTLSeconds: '1728000'\n tcaVESMessageStatusTableName: TCAVESMessageStatusTable\n tcaVESMessageStatusTableTTLSeconds: '86400'\n thresholdCalculatorFlowletInstances: '2'\n app_preferences:\n aaiEnrichmentHost: \n get_input: aaiEnrichmentHost\n aaiEnrichmentIgnoreSSLCertificateErrors: 'true'\n aaiEnrichmentPortNumber: '8443'\n aaiEnrichmentProtocol: https\n aaiEnrichmentUserName: DCAE\n aaiEnrichmentUserPassword: DCAE\n aaiVMEnrichmentAPIPath: /aai/v11/search/nodes-query\n aaiVNFEnrichmentAPIPath: /aai/v11/network/generic-vnfs/generic-vnf\n enableAAIEnrichment: \n get_input: enableAAIEnrichment\n enableRedisCaching: \n get_input: enableRedisCaching\n redisHosts: \n get_input: redisHosts\n enableAlertCEFFormat: 'false'\n publisherContentType: application/json\n publisherHostName: \n get_input: dmaap_host\n publisherHostPort: \n get_input: dmaap_port \n publisherMaxBatchSize: '1'\n publisherMaxRecoveryQueueSize: '100000'\n publisherPollingInterval: '20000'\n publisherProtocol: http\n publisherTopicName: unauthenticated.DCAE_CL_OUTPUT\n subscriberConsumerGroup: OpenDCAE-c12\n subscriberConsumerId: c12\n subscriberContentType: application/json\n subscriberHostName: \n get_input: dmaap_host\n subscriberHostPort:\n get_input: dmaap_port \n subscriberMessageLimit: '-1'\n subscriberPollingInterval: '30000'\n subscriberProtocol: http\n subscriberTimeoutMS: '-1'\n subscriberTopicName: unauthenticated.SEC_MEASUREMENT_OUTPUT\n tca_policy_default: '{\"domain\":\"measurementsForVfScaling\",\"metricsPerEventName\":[{\"eventName\":\"vFirewallBroadcastPackets\",\"controlLoopSchemaType\":\"VNF\",\"policyScope\":\"DCAE\",\"policyName\":\"DCAE.Config_tca-hi-lo\",\"policyVersion\":\"v0.0.1\",\"thresholds\":[{\"closedLoopControlName\":\"ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a\",\"version\":\"1.0.2\",\"fieldPath\":\"$.event.measurementsForVfScalingFields.vNicUsageArray[*].receivedTotalPacketsDelta\",\"thresholdValue\":300,\"direction\":\"LESS_OR_EQUAL\",\"severity\":\"MAJOR\",\"closedLoopEventStatus\":\"ONSET\"},{\"closedLoopControlName\":\"ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a\",\"version\":\"1.0.2\",\"fieldPath\":\"$.event.measurementsForVfScalingFields.vNicUsageArray[*].receivedTotalPacketsDelta\",\"thresholdValue\":700,\"direction\":\"GREATER_OR_EQUAL\",\"severity\":\"CRITICAL\",\"closedLoopEventStatus\":\"ONSET\"}]},{\"eventName\":\"vLoadBalancer\",\"controlLoopSchemaType\":\"VM\",\"policyScope\":\"DCAE\",\"policyName\":\"DCAE.Config_tca-hi-lo\",\"policyVersion\":\"v0.0.1\",\"thresholds\":[{\"closedLoopControlName\":\"ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3\",\"version\":\"1.0.2\",\"fieldPath\":\"$.event.measurementsForVfScalingFields.vNicUsageArray[*].receivedTotalPacketsDelta\",\"thresholdValue\":300,\"direction\":\"GREATER_OR_EQUAL\",\"severity\":\"CRITICAL\",\"closedLoopEventStatus\":\"ONSET\"}]},{\"eventName\":\"Measurement_vGMUX\",\"controlLoopSchemaType\":\"VNF\",\"policyScope\":\"DCAE\",\"policyName\":\"DCAE.Config_tca-hi-lo\",\"policyVersion\":\"v0.0.1\",\"thresholds\":[{\"closedLoopControlName\":\"ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e\",\"version\":\"1.0.2\",\"fieldPath\":\"$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value\",\"thresholdValue\":0,\"direction\":\"EQUAL\",\"severity\":\"MAJOR\",\"closedLoopEventStatus\":\"ABATED\"},{\"closedLoopControlName\":\"ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e\",\"version\":\"1.0.2\",\"fieldPath\":\"$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value\",\"thresholdValue\":0,\"direction\":\"GREATER\",\"severity\":\"CRITICAL\",\"closedLoopEventStatus\":\"ONSET\"}]}]}'\n service_component_type: dcaegen2-analytics_tca \n docker_config:\n healthcheck:\n endpoint: /\n interval: 15s\n timeout: 1s\n type: http\n image:\n get_input: tag_version \n service_component_name_override: \n get_input: scn_name \n interfaces:\n cloudify.interfaces.lifecycle:\n start:\n inputs:\n envs:\n DMAAPHOST: \n { get_input: dmaap_host }\n DMAAPPORT:\n { get_input: dmaap_port }\n DMAAPPUBTOPIC: \"unauthenticated.DCAE_CL_OUTPUT\"\n DMAAPSUBTOPIC: \"unauthenticated.SEC_MEASUREMENT_OUTPUT\"\n AAIHOST: \n { get_input: aaiEnrichmentHost }\n AAIPORT: \n { get_input: aaiEnrichmentPort }\n CONSUL_HOST: \n { get_input: consul_host }\n CONSUL_PORT: \n { get_input: consul_port }\n CBS_HOST: \n { get_input: cbs_host }\n CBS_PORT: \n { get_input: cbs_port }\n CONFIG_BINDING_SERVICE: \"config_binding_service\" \n SERVICE_11011_NAME: \n { get_input: scn_name }\n SERVICE_11015_IGNORE: \"true\" \n ports:\n - concat: [\"11011:\", { get_input: external_port }] \n stop:\n inputs:\n cleanup_image: true \n tca_policy:\n type: dcae.nodes.policy\n properties:\n policy_id:\n get_input: policy_id\n", + "blueprintTemplate": "tosca_definitions_version: cloudify_dsl_1_3\nimports:\n - \"http://www.getcloudify.org/spec/cloudify/3.4/types.yaml\"\n - https://nexus.onap.org/service/local/repositories/raw/content/org.onap.dcaegen2.platform.plugins/R2/dockerplugin/3.2.0/dockerplugin_types.yaml\n - https://nexus.onap.org/service/local/repositories/raw/content/org.onap.dcaegen2.platform.plugins/R2/relationshipplugin/1.0.0/relationshipplugin_types.yaml\n - https://nexus.onap.org/service/local/repositories/raw/content/org.onap.dcaegen2.platform.plugins/R2/dcaepolicyplugin/2.3.0/dcaepolicyplugin_types.yaml\n\ninputs:\n dh_override:\n type: string\n default: \"dockerhost\"\n dh_location_id:\n type: string\n default: \"zone1\"\n aaiEnrichmentHost:\n type: string\n default: \"none\"\n aaiEnrichmentPort:\n type: string \n default: 8443\n enableAAIEnrichment:\n type: string\n default: false\n dmaap_host:\n type: string\n default: dmaap.onap-message-router \n dmaap_port:\n type: string\n default: 3904 \n enableRedisCaching:\n type: string\n default: false \n redisHosts:\n type: string \n tag_version:\n type: string\n default: \"nexus3.onap.org:10001/onap/org.onap.dcaegen2.deployments.tca-cdap-container:1.0.0\"\n consul_host:\n type: string\n default: consul-server.onap-consul\n consul_port:\n type: string\n default: \"8500\"\n cbs_host:\n type: string\n default: \"config-binding-service.dcae\"\n cbs_port:\n type: string\n default: \"10000\"\n policy_id:\n type: string\n default: \"none\"\n external_port:\n type: string\n description: \"Port for CDAPgui to be exposed\"\n default: \"32010\"\n scn_name: \n default: dcaegen2-analytics_tca_clampinstance_1\n type: string\nnode_templates:\n docker_service_host:\n properties:\n docker_host_override:\n get_input: dh_override\n location_id:\n get_input: dh_location_id\n type: dcae.nodes.SelectedDockerHost\n tca_docker:\n relationships:\n - type: dcae.relationships.component_contained_in\n target: docker_service_host\n - target: tca_policy\n type: cloudify.relationships.depends_on \n type: dcae.nodes.DockerContainerForComponentsUsingDmaap\n properties:\n application_config:\n app_config:\n appDescription: DCAE Analytics Threshold Crossing Alert Application\n appName: dcae-tca\n tcaAlertsAbatementTableName: TCAAlertsAbatementTable\n tcaAlertsAbatementTableTTLSeconds: '1728000'\n tcaSubscriberOutputStreamName: TCASubscriberOutputStream\n tcaVESAlertsTableName: TCAVESAlertsTable\n tcaVESAlertsTableTTLSeconds: '1728000'\n tcaVESMessageStatusTableName: TCAVESMessageStatusTable\n tcaVESMessageStatusTableTTLSeconds: '86400'\n thresholdCalculatorFlowletInstances: '2'\n app_preferences:\n aaiEnrichmentHost: \n get_input: aaiEnrichmentHost\n aaiEnrichmentIgnoreSSLCertificateErrors: 'true'\n aaiEnrichmentPortNumber: '8443'\n aaiEnrichmentProtocol: https\n aaiEnrichmentUserName: DCAE\n aaiEnrichmentUserPassword: DCAE\n aaiVMEnrichmentAPIPath: /aai/v11/search/nodes-query\n aaiVNFEnrichmentAPIPath: /aai/v11/network/generic-vnfs/generic-vnf\n enableAAIEnrichment: \n get_input: enableAAIEnrichment\n enableRedisCaching: \n get_input: enableRedisCaching\n redisHosts: \n get_input: redisHosts\n enableAlertCEFFormat: 'false'\n publisherContentType: application/json\n publisherHostName: \n get_input: dmaap_host\n publisherHostPort: \n get_input: dmaap_port \n publisherMaxBatchSize: '1'\n publisherMaxRecoveryQueueSize: '100000'\n publisherPollingInterval: '20000'\n publisherProtocol: http\n publisherTopicName: unauthenticated.DCAE_CL_OUTPUT\n subscriberConsumerGroup: OpenDCAE-c12\n subscriberConsumerId: c12\n subscriberContentType: application/json\n subscriberHostName: \n get_input: dmaap_host\n subscriberHostPort:\n get_input: dmaap_port \n subscriberMessageLimit: '-1'\n subscriberPollingInterval: '30000'\n subscriberProtocol: http\n subscriberTimeoutMS: '-1'\n subscriberTopicName: unauthenticated.SEC_MEASUREMENT_OUTPUT\n tca_policy_default: '{\"domain\":\"measurementsForVfScaling\",\"metricsPerEventName\":[{\"eventName\":\"vFirewallBroadcastPackets\",\"controlLoopSchemaType\":\"VNF\",\"policyScope\":\"DCAE\",\"policyName\":\"DCAE.Config_tca-hi-lo\",\"policyVersion\":\"v0.0.1\",\"thresholds\":[{\"closedLoopControlName\":\"ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a\",\"version\":\"1.0.2\",\"fieldPath\":\"$.event.measurementsForVfScalingFields.vNicUsageArray[*].receivedTotalPacketsDelta\",\"thresholdValue\":300,\"direction\":\"LESS_OR_EQUAL\",\"severity\":\"MAJOR\",\"closedLoopEventStatus\":\"ONSET\"},{\"closedLoopControlName\":\"ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a\",\"version\":\"1.0.2\",\"fieldPath\":\"$.event.measurementsForVfScalingFields.vNicUsageArray[*].receivedTotalPacketsDelta\",\"thresholdValue\":700,\"direction\":\"GREATER_OR_EQUAL\",\"severity\":\"CRITICAL\",\"closedLoopEventStatus\":\"ONSET\"}]},{\"eventName\":\"vLoadBalancer\",\"controlLoopSchemaType\":\"VM\",\"policyScope\":\"DCAE\",\"policyName\":\"DCAE.Config_tca-hi-lo\",\"policyVersion\":\"v0.0.1\",\"thresholds\":[{\"closedLoopControlName\":\"ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3\",\"version\":\"1.0.2\",\"fieldPath\":\"$.event.measurementsForVfScalingFields.vNicUsageArray[*].receivedTotalPacketsDelta\",\"thresholdValue\":300,\"direction\":\"GREATER_OR_EQUAL\",\"severity\":\"CRITICAL\",\"closedLoopEventStatus\":\"ONSET\"}]},{\"eventName\":\"Measurement_vGMUX\",\"controlLoopSchemaType\":\"VNF\",\"policyScope\":\"DCAE\",\"policyName\":\"DCAE.Config_tca-hi-lo\",\"policyVersion\":\"v0.0.1\",\"thresholds\":[{\"closedLoopControlName\":\"ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e\",\"version\":\"1.0.2\",\"fieldPath\":\"$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value\",\"thresholdValue\":0,\"direction\":\"EQUAL\",\"severity\":\"MAJOR\",\"closedLoopEventStatus\":\"ABATED\"},{\"closedLoopControlName\":\"ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e\",\"version\":\"1.0.2\",\"fieldPath\":\"$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value\",\"thresholdValue\":0,\"direction\":\"GREATER\",\"severity\":\"CRITICAL\",\"closedLoopEventStatus\":\"ONSET\"}]}]}'\n service_component_type: dcaegen2-analytics_tca \n docker_config:\n healthcheck:\n endpoint: /\n interval: 15s\n timeout: 1s\n type: http\n image:\n get_input: tag_version \n service_component_name_override: \n get_input: scn_name \n interfaces:\n cloudify.interfaces.lifecycle:\n start:\n inputs:\n envs:\n DMAAPHOST: \n { get_input: dmaap_host }\n DMAAPPORT:\n { get_input: dmaap_port }\n DMAAPPUBTOPIC: \"unauthenticated.DCAE_CL_OUTPUT\"\n DMAAPSUBTOPIC: \"unauthenticated.SEC_MEASUREMENT_OUTPUT\"\n AAIHOST: \n { get_input: aaiEnrichmentHost }\n AAIPORT: \n { get_input: aaiEnrichmentPort }\n CONSUL_HOST: \n { get_input: consul_host }\n CONSUL_PORT: \n { get_input: consul_port }\n CBS_HOST: \n { get_input: cbs_host }\n CBS_PORT: \n { get_input: cbs_port }\n CONFIG_BINDING_SERVICE: \"config_binding_service\" \n SERVICE_11011_NAME: \n { get_input: scn_name }\n SERVICE_11015_IGNORE: \"true\" \n ports:\n - concat: [\"11011:\", { get_input: external_port }] \n stop:\n inputs:\n cleanup_image: true \n tca_policy:\n type: dcae.nodes.policy\n properties:\n policy_id:\n get_input: policy_id\n", "serviceIds": null, "vnfTypes": ["TESTVNF000"], "serviceLocations": null, diff --git a/tests/test_policy.js b/tests/test_policy.js index 0d7550e..bc424e0 100644 --- a/tests/test_policy.js +++ b/tests/test_policy.js @@ -32,7 +32,6 @@ const dh = require('./mock_deployment_handler'); const utils = require('./mock_utils'); const RUN_TS = new Date(); -const RUN_TS_HOURS = RUN_TS.getHours(); const POLICY_ID = 'policy_id'; const POLICY_VERSION = "policyVersion"; @@ -245,7 +244,7 @@ function test_get_policy_components(dh_server) { }); } -function test_post_policy_catch_up(dh_server) { +function test_put_policy_catch_up(dh_server) { const req_path = "/policy"; const message = JSON.parse(JSON.stringify(message_catch_up)); message.errored_scopes = ["CLAMP.Config_"]; @@ -260,19 +259,19 @@ function test_post_policy_catch_up(dh_server) { "fail_filtered_2": create_policy("fail_filtered_2", 32, {"ConfigName": "not-match2"}), "": create_policy("", 1) }; - const test_txt = "POST " + req_path + " - catchup " + JSON.stringify(message); + const test_txt = "put " + req_path + " - catchup " + JSON.stringify(message); describe(test_txt, () => { - it('POST policy-update - catchup', function() { + it('put policy-update - catchup', function() { const action_timer = new utils.ActionTimer(); console.log(action_timer.step, test_txt); const execution_id = "policy_catch_up"; const resp_to_exe = {"status": "none"}; nock_cfy_node_instances(action_timer); - nock(dh.CLOUDIFY_URL).post(CFY_API_EXECUTIONS) + nock(dh.CLOUDIFY_URL).put(CFY_API_EXECUTIONS) .reply(201, function(uri, requestBody) { requestBody = JSON.stringify(requestBody); - console.log(action_timer.step, "on_post", dh.CLOUDIFY_URL, uri, requestBody); + console.log(action_timer.step, "on_put", dh.CLOUDIFY_URL, uri, requestBody); Object.assign(resp_to_exe, JSON.parse(requestBody)); resp_to_exe.status = "pending"; resp_to_exe.created_at = RUN_TS; @@ -285,7 +284,7 @@ function test_post_policy_catch_up(dh_server) { resp_to_exe.parameters.operation = OPERATION_POLICY_UPDATE; resp_to_exe.parameters.type_names = []; - console.log(action_timer.step, "reply to post", dh.CLOUDIFY_URL, uri, JSON.stringify(resp_to_exe)); + console.log(action_timer.step, "reply to put", dh.CLOUDIFY_URL, uri, JSON.stringify(resp_to_exe)); return JSON.stringify(resp_to_exe); }); @@ -315,9 +314,9 @@ function test_post_policy_catch_up(dh_server) { message.latest_policies[policy_id] = create_policy(policy_id, extra_i); } - return chai.request(dh_server.app).post(req_path) + return chai.request(dh_server.app).put(req_path) .set('content-type', 'application/json') - .set('X-ECOMP-RequestID', 'test_post_policy_catch_up') + .set('X-ECOMP-RequestID', 'test_put_policy_catch_up') .send(message) .then(function(res) { console.log(action_timer.step, "res for", test_txt, res.text); @@ -343,30 +342,30 @@ function test_fail_cfy_policy_catch_up(dh_server) { message.latest_policies = { [MONKEYED_POLICY_ID_6]: create_policy(MONKEYED_POLICY_ID_6, 66) }; - const test_txt = "fail POST " + req_path + " - catchup without execution_id " + JSON.stringify(message); + const test_txt = "fail put " + req_path + " - catchup without execution_id " + JSON.stringify(message); describe(test_txt, () => { - it('fail POST policy-update - catchup without execution_id', function() { + it('fail put policy-update - catchup without execution_id', function() { const action_timer = new utils.ActionTimer(); console.log(action_timer.step, test_txt); const execution_id = "policy_catch_up"; const resp_to_exe = {"status": "none"}; nock_cfy_node_instances(action_timer); - nock(dh.CLOUDIFY_URL).post(CFY_API_EXECUTIONS) + nock(dh.CLOUDIFY_URL).put(CFY_API_EXECUTIONS) .reply(201, function(uri, requestBody) { requestBody = JSON.stringify(requestBody); - console.log(action_timer.step, "on_post", dh.CLOUDIFY_URL, uri, requestBody); + console.log(action_timer.step, "on_put", dh.CLOUDIFY_URL, uri, requestBody); Object.assign(resp_to_exe, JSON.parse(requestBody)); resp_to_exe.status = "pending"; - console.log(action_timer.step, "reply to post", dh.CLOUDIFY_URL, uri, JSON.stringify(resp_to_exe)); + console.log(action_timer.step, "reply to put", dh.CLOUDIFY_URL, uri, JSON.stringify(resp_to_exe)); return JSON.stringify(resp_to_exe); }); - return chai.request(dh_server.app).post(req_path) + return chai.request(dh_server.app).put(req_path) .set('content-type', 'application/json') - .set('X-ECOMP-RequestID', 'test_post_policy_catch_up') + .set('X-ECOMP-RequestID', 'test_put_policy_catch_up') .send(message) .then(function(res) { console.log(action_timer.step, "res for", test_txt, res.text); @@ -392,25 +391,25 @@ function test_fail_400_cfy_policy_catch_up(dh_server) { message.latest_policies = { [MONKEYED_POLICY_ID_6]: create_policy(MONKEYED_POLICY_ID_6, 66) }; - const test_txt = "fail 400 POST " + req_path + " - existing_running_execution_error " + JSON.stringify(message); + const test_txt = "fail 400 put " + req_path + " - existing_running_execution_error " + JSON.stringify(message); describe(test_txt, () => { - it('fail 400 POST policy-update - existing_running_execution_error', function() { + it('fail 400 put policy-update - existing_running_execution_error', function() { const action_timer = new utils.ActionTimer(); console.log(action_timer.step, test_txt); const execution_id = "policy_catch_up"; const resp_to_exe = {"error_code": "existing_running_execution_error"}; nock_cfy_node_instances(action_timer); - nock(dh.CLOUDIFY_URL).post(CFY_API_EXECUTIONS).times(5) + nock(dh.CLOUDIFY_URL).put(CFY_API_EXECUTIONS).times(5) .reply(400, function(uri, requestBody) { - console.log(action_timer.step, "on_post", dh.CLOUDIFY_URL, uri, JSON.stringify(requestBody)); - console.log(action_timer.step, "reply to post", dh.CLOUDIFY_URL, uri, JSON.stringify(resp_to_exe)); + console.log(action_timer.step, "on_put", dh.CLOUDIFY_URL, uri, JSON.stringify(requestBody)); + console.log(action_timer.step, "reply to put", dh.CLOUDIFY_URL, uri, JSON.stringify(resp_to_exe)); return JSON.stringify(resp_to_exe); }); - return chai.request(dh_server.app).post(req_path) + return chai.request(dh_server.app).put(req_path) .set('content-type', 'application/json') - .set('X-ECOMP-RequestID', 'test_post_policy_catch_up') + .set('X-ECOMP-RequestID', 'test_put_policy_catch_up') .send(message) .then(function(res) { console.log(action_timer.step, "res for", test_txt, res.text); @@ -436,25 +435,25 @@ function test_fail_404_cfy_policy_catch_up(dh_server) { message.latest_policies = { [MONKEYED_POLICY_ID_6]: create_policy(MONKEYED_POLICY_ID_6, 66) }; - const test_txt = "fail 404 POST " + req_path + " - not_found_error " + JSON.stringify(message); + const test_txt = "fail 404 put " + req_path + " - not_found_error " + JSON.stringify(message); describe(test_txt, () => { - it('fail 404 POST policy-update - not_found_error', function() { + it('fail 404 put policy-update - not_found_error', function() { const action_timer = new utils.ActionTimer(); console.log(action_timer.step, test_txt); const execution_id = "policy_catch_up"; const resp_to_exe = {"error_code": "not_found_error"}; nock_cfy_node_instances(action_timer); - nock(dh.CLOUDIFY_URL).post(CFY_API_EXECUTIONS).times(5) + nock(dh.CLOUDIFY_URL).put(CFY_API_EXECUTIONS).times(5) .reply(404, function(uri, requestBody) { - console.log(action_timer.step, "on_post", dh.CLOUDIFY_URL, uri, JSON.stringify(requestBody)); - console.log(action_timer.step, "reply to post", dh.CLOUDIFY_URL, uri, JSON.stringify(resp_to_exe)); + console.log(action_timer.step, "on_put", dh.CLOUDIFY_URL, uri, JSON.stringify(requestBody)); + console.log(action_timer.step, "reply to put", dh.CLOUDIFY_URL, uri, JSON.stringify(resp_to_exe)); return JSON.stringify(resp_to_exe); }); - return chai.request(dh_server.app).post(req_path) + return chai.request(dh_server.app).put(req_path) .set('content-type', 'application/json') - .set('X-ECOMP-RequestID', 'test_post_policy_catch_up') + .set('X-ECOMP-RequestID', 'test_put_policy_catch_up') .send(message) .then(function(res) { console.log(action_timer.step, "res for", test_txt, res.text); @@ -476,7 +475,7 @@ function test_fail_404_cfy_policy_catch_up(dh_server) { dh.add_tests([ test_get_policy_components, - test_post_policy_catch_up, + test_put_policy_catch_up, test_fail_cfy_policy_catch_up, test_fail_400_cfy_policy_catch_up, test_fail_404_cfy_policy_catch_up diff --git a/version.properties b/version.properties index 5791c10..b67dd8a 100644 --- a/version.properties +++ b/version.properties @@ -1,5 +1,5 @@ -major=2 -minor=2 +major=3 +minor=0 patch=0 base_version=${major}.${minor}.${patch} release_version=${base_version} -- cgit 1.2.3-korg