diff --git a/modules/application/index.js b/modules/application/index.js index 7ab5b9f..c598ff3 100644 --- a/modules/application/index.js +++ b/modules/application/index.js @@ -521,6 +521,9 @@ module.exports = { }; }, methods(self) { + validateMetaConstraints = (uuid,doc) => { + return self.apos.modules.exn.bqa_application_validate(uuid,doc) + }; const contentSchema = Joi.string().custom((value, helpers) => { try { yaml.parse(value); @@ -855,7 +858,9 @@ module.exports = { async updateWithRegions(req, doc) { return new Promise(async (resolve) => { - + if(!doc.resources){ + doc.resources = [] + } const resource_uuids = doc.resources.map(r => { return r.uuid }) @@ -950,24 +955,22 @@ module.exports = { const doc = req.body; let errorResponses = self.validateDocument(doc) || []; + + if(doc.uuid){ + const metaConstraintValidation = await validateMetaConstraints(doc.uuid, doc) + if(!metaConstraintValidation.valid){ + errorResponses.push({ + path: `slMetaConstraint`, + index: 90, + key: `slMetaConstraint`, + message: metaConstraintValidation.message || 'Please check the SL Meta Constraints' + }) + } + } if (errorResponses.length > 0) { throw self.apos.error('required', 'Validation failed', {error: errorResponses}); } }, - async validateConstraints(req) { - if (!self.apos.permission.can(req, 'edit')) { - throw self.apos.error('forbidden', 'Insufficient permissions'); - } - const slMetaContraints = req.body; - const valid = await new Promise((resolve) => { - setTimeout(() => { - const randomBoolean = Math.random() < 0.5; - resolve(randomBoolean); - }, 5000); - }); - console.log("Returning valid for ", slMetaContraints, valid); - return valid; - }, async 'generate'(req) { if (!self.apos.permission.can(req, 'edit')) { throw self.apos.error('forbidden', 'Insufficient permissions'); diff --git a/modules/exn/index.js b/modules/exn/index.js index 2436102..3edfedb 100644 --- a/modules/exn/index.js +++ b/modules/exn/index.js @@ -44,6 +44,8 @@ let sender_ui_application_dsl_metric; let sender_ui_policies_rule_upsert; let sender_ui_policies_model_upsert; +let sender_bqa_validate_slos; + let sender_ui_application_user_info; let sender_ui_application_info; @@ -108,6 +110,11 @@ module.exports = { await aposSelf.update_application_state(context.message.application_properties.application, context.message.body); } + if (context.message.to === "topic://eu.nebulouscloud.ontology.bqa.reply") { + correlations[context.message.correlation_id]['resolve'](context.message.body) + return + } + if (context.message.correlation_id in correlations) { if (context.message.body.metaData['status'] >= 400) { correlations[context.message.correlation_id]['reject'](context.message.body['message']) @@ -127,6 +134,7 @@ module.exports = { context.connection.open_receiver('topic://eu.nebulouscloud.optimiser.controller.app_state') context.connection.open_receiver('topic://eu.nebulouscloud.ui.user.get') context.connection.open_receiver('topic://eu.nebulouscloud.ui.app.get') + context.connection.open_receiver('topic://eu.nebulouscloud.ontology.bqa.reply') sender_sal_nodecandidate_get = context.connection.open_sender('topic://eu.nebulouscloud.exn.sal.nodecandidate.get'); sender_sal_cloud_get = context.connection.open_sender('topic://eu.nebulouscloud.exn.sal.cloud.get'); @@ -147,6 +155,8 @@ module.exports = { sender_ui_application_user_info = context.connection.open_sender('topic://eu.nebulouscloud.ui.user.get.reply'); sender_ui_application_info = context.connection.open_sender('topic://eu.nebulouscloud.ui.app.get.reply'); + sender_bqa_validate_slos = context.connection.open_sender('topic://eu.nebulouscloud.ontology.bqa'); + }); if (process.env.EXN_DISABLE == "True") { @@ -350,7 +360,7 @@ module.exports = { }) } , - async bqa_application_validate(uuid,app) { + async bqa_application_validate(uuid) { return new Promise(async (resolve, reject) => { const correlation_id = uuidv4() @@ -367,8 +377,11 @@ module.exports = { body: dsl.json } const timer = setTimeout(() => { - reject(new Error(`Promise timed out after ${5000} ms`)); - }, 5000); + console.warn("SLO Validator timeout") + resolve({ + 'valid':true + }) + }, 7000); console.log("[bqa_application_validate] Send ", JSON.stringify( message)) sender_bqa_validate_slos.send(message)