jmarchel bdd410672d Adding dockerfile
Change-Id: Iaa70ed769c7d693ff5172f4fd3204677e4834a8a
2024-02-26 21:50:27 +02:00

261 lines
8.7 KiB
JavaScript

const connection_options={
'port': process.env.ACTIVEMQ_PORT,
'host': process.env.ACTIVEMQ_HOST,
'username': process.env.ACTIVEMQ_USERNAME,
'password': process.env.ACTIVEMQ_PASSWORD,
'reconnect': true
}
if(!connection_options.port || !connection_options.host) {
console.error("No connection option provided for EXN skipping asynchronous messaging")
return
}
const container= require('rhea');
let connection;
let sender_sal_nodecandidate_get;
let sender_sal_cloud_get;
let sender_sal_cloud_post;
let sender_sal_cloud_delete;
let sender_sal_node_post;
let sender_ui_application_new;
let sender_ui_application_updated;
let sender_ui_application_deploy;
let sender_ui_application_dsl_json;
let sender_ui_application_dsl_metric;
let sender_ui_policies_rule_upsert;
let sender_ui_policies_model_upsert;
const correlations = {}
container.on('message', (context)=>{
// console.log("Received ",context.message)
if(context.message.correlation_id in correlations){
if(context.message.body.metaData['status'] >= 400){
correlations[context.message.correlation_id]['reject'](context.message.body['message'])
}else{
correlations[context.message.correlation_id]['resolve'](context.message.body)
}
}
})
container.on('connection_open', function (context) {
console.log("Connected ",context.container.id);
context.connection.open_receiver('topic://eu.nebulouscloud.exn.sal.cloud.get.reply')
context.connection.open_receiver('topic://eu.nebulouscloud.exn.sal.cloud.post.reply')
context.connection.open_receiver('topic://eu.nebulouscloud.exn.sal.cloud.delete.reply')
context.connection.open_receiver('topic://eu.nebulouscloud.exn.sal.nodecandidate.get.reply')
context.connection.open_receiver('topic://eu.nebulouscloud.exn.sal.node.post.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');
sender_sal_cloud_post = context.connection.open_sender('topic://eu.nebulouscloud.exn.sal.cloud.post');
sender_sal_cloud_delete = context.connection.open_sender('topic://eu.nebulouscloud.exn.sal.cloud.delete');
sender_sal_node_post = context.connection.open_sender('topic://eu.nebulouscloud.exn.sal.node.post');
sender_ui_application_new = context.connection.open_sender('topic://eu.nebulouscloud.ui.application.new');
sender_ui_application_updated = context.connection.open_sender('topic://eu.nebulouscloud.ui.application.updated');
sender_ui_application_deploy = context.connection.open_sender('topic://eu.nebulouscloud.ui.application.deploy');
sender_ui_application_dsl_json = context.connection.open_sender('topic://eu.nebulouscloud.ui.dsl.generic');
sender_ui_application_dsl_metric = context.connection.open_sender('topic://eu.nebulouscloud.ui.dsl.metric_model');
sender_ui_policies_rule_upsert = context.connection.open_sender('topic://eu.nebulouscloud.ui.policies.rule.upsert');
sender_ui_policies_model_upsert = context.connection.open_sender('topic://eu.nebulouscloud.ui.policies.model.upsert');
});
connection = container.connect();
const {v4: uuidv4} = require("uuid");
module.exports = {
sender_ui_application_new:(uuid) => {
return new Promise((resolve,reject) =>{
const correlation_id = uuidv4()
correlations[correlation_id] = {
'resolve':resolve,
'reject':reject,
};
const message = {
to: sender_ui_deploy_application_new.options.target.address,
correlation_id: correlation_id,
body:{
uuid: uuid
}
}
console.log("Send ", message)
sender_ui_deploy_application_new.send(message)
})
},
application_dsl:(uuid,json,yaml) => {
return new Promise((resolve,reject) =>{
const correlation_id = uuidv4()
correlations[correlation_id] = {
'resolve':resolve,
'reject':reject,
};
console.log("Sending ", sender_ui_application_dsl_json.options.target.address, uuid,json)
const message = {
to: sender_ui_application_dsl_json.options.target.address,
correlation_id: correlation_id,
body:json
}
sender_ui_application_dsl_json.send(message)
console.log("Sending ", sender_ui_application_dsl_metric.options.target.address, uuid,json)
const metrci_message = {
to: sender_ui_application_dsl_metric.options.target.address,
correlation_id: correlation_id,
body:{
'yaml': yaml
}
}
sender_ui_application_dsl_metric.send(message)
})
},
application_updated:(uuid) => {
return new Promise((resolve,reject) =>{
const correlation_id = uuidv4()
correlations[correlation_id] = {
'resolve':resolve,
'reject':reject,
};
const message = {
to: sender_ui_deploy_application_new.options.target.address,
correlation_id: correlation_id,
body:{
uuid: uuid
}
}
console.log("Send ", message)
sender_ui_deploy_application_new.send(message)
})
},
register_cloud:( uuid, user ,secret ) =>{
return new Promise((resolve,reject)=>{
const correlation_id = uuidv4()
correlations[correlation_id] = {
'resolve':resolve,
'reject':reject,
};
const message = {
to: sender_sal_cloud_post.options.target.address,
correlation_id: correlation_id,
body:{
metaData: {
userId: "admin"
},
body: JSON.stringify([{
"cloudId": uuid,
"cloudProviderName": "aws-ec2",
"cloudType": "PUBLIC",
"securityGroup": null,
"subnet": null,
"sshCredentials": {
"username": null,
"keyPairName": "mkl",
"privateKey": null
},
"endpoint": null,
"scope": {
"prefix": null,
"value": null
},
"identityVersion": null,
"defaultNetwork": null,
"credentials": {
"user": user,
"secret": secret,
"domain": null
},
"blacklist": null
}])
}
}
console.log("Send ", message)
sender_sal_cloud_post.send(message)
})
},
deploy_application: (uuid) => {
},
get_cloud_candidates: () => {
return new Promise((resolve,reject)=> {
const correlation_id = uuidv4()
correlations[correlation_id] = {
'resolve': resolve,
'reject': reject,
};
const message = {
to: sender_sal_nodecandidate_get.options.target.address,
correlation_id: correlation_id,
body: {}
}
sender_sal_nodecandidate_get.send(message)
})
},
publish_policies:(policies) =>{
return new Promise((resolve,reject)=> {
const body = JSON.parse(policies)
body.forEach((b)=>{
const correlation_id = uuidv4()
const rule = {
to: sender_ui_policies_rule_upsert.options.target.address,
correlation_id: correlation_id,
body: [{
"name": b['name'],
"policyItem": b['policyItem']
}]
}
const model = {
to: sender_ui_policies_model_upsert.options.target.address,
correlation_id: correlation_id,
body: [{
"name": b['name'],
"enabled": true,
"modelText": b['model']
}]
}
sender_ui_policies_model_upsert.send(model)
sender_ui_policies_rule_upsert.send(rule)
})
resolve()
})
}
}