Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions modules/application/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
})
Expand Down Expand Up @@ -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');
Expand Down
19 changes: 16 additions & 3 deletions modules/exn/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'])
Expand All @@ -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');
Expand All @@ -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") {
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand Down