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
184 changes: 99 additions & 85 deletions lib/kubevela.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,98 +3,112 @@ const mathutils = require("./math");
const _ = require("lodash");
const transliterate = require('transliteration').transliterate;

// Normalize line endings in string fields to prevent AMQP decoding issues
const normalizeLineEndings = (str) => {
if (typeof str === 'string') {
return str.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
}
return str;
};

module.exports = {
json: (doc) =>{
let object = _.clone(doc)
object['title'] = transliterate(object['title'])
object['variables'] = _.map(doc['variables'], (v)=>{

return {
'key': slugify(transliterate(v['name']).replaceAll("\s+"," ").replaceAll('/','_'),'_'),
'path': '/'+v['name'],
'type': 'float',
'meaning': v['name'].split('/').pop(),
'value' :{
"lower_bound": v['lowerValue'],
"higher_bound": v['higherValue'],
json: (doc) => {
let object = _.clone(doc)
object['title'] = transliterate(object['title'])

// Normalize line endings in content field
if (object['content']) {
object['content'] = normalizeLineEndings(object['content']);
}
}
})

const applicationDeploymentPriceUsed = _.find(doc["utilityFunctions"],(f)=>{
return _.find(f['functionExpressionVariables'],(v) => {
return v['valueVariable'] === 'application_deployment_price'
})
})

if(applicationDeploymentPriceUsed){

object['variables'].push({
'key': 'application_deployment_price',
'path': '',
'type': 'float',
'meaning': 'price',
'value' :{
"lower_bound": 0,
"higher_bound": 0,
object['variables'] = _.map(doc['variables'], (v) => {


return {
'key': slugify(transliterate(v['name']).replaceAll("\s+", " ").replaceAll('/', '_'), '_'),
'path': '/' + v['name'],
'type': 'float',
'meaning': v['name'].split('/').pop(),
'value': {
"lower_bound": v['lowerValue'],
"higher_bound": v['higherValue'],
}
}
})

const applicationDeploymentPriceUsed = _.find(doc["utilityFunctions"], (f) => {
return _.find(f['functionExpressionVariables'], (v) => {
return v['valueVariable'] === 'application_deployment_price'
})
})

if (applicationDeploymentPriceUsed) {

object['variables'].push({
'key': 'application_deployment_price',
'path': '',
'type': 'float',
'meaning': 'price',
'value': {
"lower_bound": 0,
"higher_bound": 0,
}
})
}
})
}

object['sloViolations'] = JSON.parse(doc['sloViolations'])
object['metrics'] = _.map(doc['metrics'], (v)=>{
object['sloViolations'] = JSON.parse(doc['sloViolations'])
object['metrics'] = _.map(doc['metrics'], (v) => {

if (v['type'] === 'composite') {
v['arguments'] = mathutils.extractVariableNames(
mathutils.extractFromEquation(v['formula']))
}

return v
})

object["utilityFunctions"] = _.map(doc['utilityFunctions'], (v) => {
const f = {
"name": v['functionName'],
"type": v['functionType'],
"expression": {
"formula": v["functionExpression"],
"variables": _.map(v["functionExpressionVariables"], (k) => {
return {
"name": k['nameVariable'],
"value": slugify(k['valueVariable'].replaceAll('/', '_'), '_')
}
})
}
}

if (v['functionType'] === 'constraint') {
f['operator'] = v['functionConstraintOperator']
}

if (v['functionType'] === 'maximize' || v['functionType'] === 'minimize') {
f['selected'] = v['selected'];
}

if(v['type'] === 'composite'){
v['arguments'] = mathutils.extractVariableNames(
mathutils.extractFromEquation(v['formula']))
}
return f

return v
})
})

object["utilityFunctions"] = _.map(doc['utilityFunctions'], (v)=>{
const f = {
"name": v['functionName'],
"type": v['functionType'],
"expression":{
"formula":v["functionExpression"],
"variables": _.map(v["functionExpressionVariables"], (k)=>{
object["resources"] = _.map(doc['resources'], (v) => {
return {
"name":k['nameVariable'],
"value": slugify(k['valueVariable'].replaceAll('/','_'),'_')
"title": v['title'],
"uuid": v['uuid'],
"platform": v['platform'],
"enabled": v['enabled'],
"regions": v['_regions'],
"valid_instance_types": v['_valid_instance_types'] || [],
}
})
}
}

if(v['functionType'] === 'constraint'){
f['operator'] = v['functionConstraintOperator']
}

if(v['functionType'] === 'maximize' || v['functionType'] === 'minimize'){
f['selected'] = v['selected'];
}

return f

})

object["resources"] = _.map(doc['resources'], (v)=>{
return {
"title": v['title'],
"uuid": v['uuid'],
"platform": v['platform'],
"enabled": v['enabled'],
"regions": v['_regions'],
"valid_instance_types": v['_valid_instance_types'] || [],
}
})

var protected_variables = ["_id","type",,"metaType","organization","_edit","_publish"]
_.each(protected_variables, (p)=>{
delete object[p]
})

return object
}
})

var protected_variables = ["_id", "type", , "metaType", "organization", "_edit", "_publish"]
_.each(protected_variables, (p) => {
delete object[p]
})

return object
}
}
1 change: 1 addition & 0 deletions modules/exn/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ module.exports = {
return
} else {
const connection = container.connect(connection_options);
console.log("Connected to ",connection_options.host, ":", connection_options.port );
}


Expand Down