aboutsummaryrefslogtreecommitdiffstats
path: root/openo-portal/portal-lifecyclemgr/src/main
diff options
context:
space:
mode:
authorLuji7 <lu.ji3@zte.com.cn>2016-10-26 17:21:57 +0800
committerLuji <lu.ji3@zte.com.cn>2016-10-26 14:32:59 +0000
commit29ecef3228539d51ebf3b998f3a9aa3eca95edd7 (patch)
tree2125bd06aadb20658939db6673f0f04214fce2f6 /openo-portal/portal-lifecyclemgr/src/main
parent1fb807a55d7a3d9c9bd1bcbefd7b023d280e36a2 (diff)
Issue#GSO-53 Support to config location per nesting nfvo service template.
Change-Id: Ibb6dc67b1c59bd493a0ed2b473ff93e3c5de8540 Signed-off-by: Luji7 <lu.ji3@zte.com.cn> (cherry picked from commit 44e4d940b2c5ca753a74491e94fa3f703014d5ec)
Diffstat (limited to 'openo-portal/portal-lifecyclemgr/src/main')
-rw-r--r--openo-portal/portal-lifecyclemgr/src/main/webapp/lifecyclemgr/js/gsolcm.js371
1 files changed, 215 insertions, 156 deletions
diff --git a/openo-portal/portal-lifecyclemgr/src/main/webapp/lifecyclemgr/js/gsolcm.js b/openo-portal/portal-lifecyclemgr/src/main/webapp/lifecyclemgr/js/gsolcm.js
index 2bfe351a..7dc4279a 100644
--- a/openo-portal/portal-lifecyclemgr/src/main/webapp/lifecyclemgr/js/gsolcm.js
+++ b/openo-portal/portal-lifecyclemgr/src/main/webapp/lifecyclemgr/js/gsolcm.js
@@ -15,7 +15,8 @@
*/
var templateParameters = {
changed: true,
- parameters: []
+ parameters: [],
+ vimInfos: []
};
var lcmHandler = function () {
@@ -27,18 +28,15 @@ lcmHandler.prototype = {
$('#createNS').click(this.okAction);
},
okAction: function () {
- var vimLocation = $('#vim_location').val();
- if(vimLocation == 'select') {
- alert('Location must be selected in Template Parameters');
- return;
- }
-
+ if(!checkLocation(templateParameters.parameters)) {
+ alert('Location must be selected in Template Parameters');
+ return;
+ }
var serviceInstance = {
serviceTemplateId: $("#svcTempl").val(),
serviceName: $('#svcName').val(),
description: $('#svcDesc').val(),
- inputParameters: collectServiceParameters(templateParameters.parameters),
- vimLocation: vimLocation
+ inputParameters: collectServiceParameters(templateParameters.parameters)
};
var gatewayService = '/openoapi/servicegateway/v1/services';
$.when(
@@ -58,8 +56,22 @@ lcmHandler.prototype = {
}
};
+function checkLocation(parameters) {
+ var checkPass = true;
+ var i = 0;
+ for(i = 0; i < parameters.length; i++) {
+ if(parameters[i].type === 'location') {
+ var value = $('#' + parameters[i].id).val();
+ if(value === undefined || value === 'select') {
+ checkPass = false;
+ }
+ }
+ }
+ return checkPass;
+}
+
function initParameterTab() {
- // Service template was not changed. Do not re-initiate the parameter tab.
+ // Service template was not changed. Do not re-initiate the parameter tab.
if (!templateParameters.changed) {
return;
}
@@ -68,26 +80,78 @@ function initParameterTab() {
document.getElementById("templateParameterTab").innerHTML = '';
return;
}
+ $.when(
+ fetchServiceTemplateBy(templateId)
+ ).then(
+ function(template) {
+ if(template.serviceType === 'GSO') {
+ return fetchGsoTemplateInputParameters(templateId);
+ } else if(template.serviceType === 'NFVO') {
+ return fetchNfvoTemplateInputParameters(templateId);
+ } else if(template.serviceType === 'SDNO') {
+ return fetchSdnoTemplateInputParameters(templateId);
+ }
+ }
+ ).then(
+ function(parameters) {
+ var components = transformToComponents(parameters);
+ document.getElementById("templateParameterTab").innerHTML = components;
+ }
+ );
+}
+
+function fetchServiceTemplateBy(templateId) {
+ var defer = $.Deferred();
+ var serviceTemplateUri = '/openoapi/catalog/v1/servicetemplates/' + templateId;
+ var template = {};
$.when(
- generateTemplateParametersComponent(templateId),
- generateLocationComponent(templateId)
+ $.ajax({
+ type: "GET",
+ url: serviceTemplateUri,
+ contentType: "application/json"
+ })
).then(
- function (templateParameters, location) {
- document.getElementById("templateParameterTab").innerHTML = templateParameters + location;
+ function(response) {
+ template.name = response.templateName;
+ template.gsarId = response.csarId;
+ return fetchCsar(template.gsarId);
+ }
+ ).then(
+ function(response) {
+ if(response.type === 'GSAR') {
+ template.serviceType = 'GSO';
+ } else if(response.type === 'NSAR' || response.type === 'NFAR') {
+ template.serviceType = 'NFVO';
+ } else if(response.type === 'SSAR') {
+ template.serviceType = "SDNO";
+ }
+ defer.resolve(template)
}
);
+ return defer;
}
-function generateTemplateParametersComponent(templateId) {
- var defer = $.Deferred();
+function fetchCsar(csarId) {
+ var queryCsarUri = '/openoapi/catalog/v1/csars/' + csarId;
+ return $.ajax({
+ type: "GET",
+ url: queryCsarUri,
+ contentType: "application/json"
+ });
+}
+
+function fetchGsoTemplateInputParameters(templateId) {
+ var defer = $.Deferred();
$.when(
fetchTemplateParameterDefinitions(templateId),
- fetchGsoNestingTemplateParameters(templateId)
+ fetchGsoNestingTemplateParameters(templateId),
+ fetchVimInfo()
).then(
- function (templateParameterResponse, nestingTempatesParas) {
+ function (templateParameterResponse, nestingTempatesParas, vimInfoResponse) {
var inputParas = concat(templateParameterResponse[0].inputs, nestingTempatesParas);
- templateParameters = translateToTemplateParameters(inputParas);
- defer.resolve(transformToComponents(templateParameters.parameters));
+ var vims = translateToVimInfo(vimInfoResponse[0]);
+ templateParameters = translateToTemplateParameters(inputParas, vims);
+ defer.resolve(templateParameters);
}
);
return defer;
@@ -95,17 +159,8 @@ function generateTemplateParametersComponent(templateId) {
function fetchGsoNestingTemplateParameters(templateId) {
var defer = $.Deferred();
- var nestingParams = [];
$.when(
- fetchServiceTemplateBy(templateId)
- ).then(
- function(template) {
- if(template.serviceType === 'GSO') {
- return fetchNodeTemplates(templateId);
- }
- // There are no nesting template parameters for non GSO.
- defer.resolve([]);
- }
+ fetchNodeTemplates(templateId)
).then(
function(nodeTemplates) {
var count = nodeTemplates.length;
@@ -113,13 +168,8 @@ function fetchGsoNestingTemplateParameters(templateId) {
defer.resolve([]);
return;
}
- var params = $.Deferred();
- params.progress(function(inputs) {
- pushAll(nestingParams, inputs);
- count--;
- if(count === 0) {
- defer.resolve(nestingParams);
- }
+ var nestingParasAggregatation = aggregate(count, function(nestingParas) {
+ defer.resolve(nestingParas);
});
nodeTemplates.forEach(function(nodeTemplate) {
var nestingNodeUri = '/openoapi/catalog/v1/servicetemplates/nesting?nodeTypeIds=' + nodeTemplate.type;
@@ -130,14 +180,30 @@ function fetchGsoNestingTemplateParameters(templateId) {
})
).then(
function(serviceTemplates) {
- var oneNodeParameters = []
+ var nodeAggregatation = aggregate(serviceTemplates.length, function(oneNodeParameters) {
+ nestingParasAggregatation.notify(oneNodeParameters);
+ });
serviceTemplates.forEach(function(serviceTemplate) {
- pushAll(oneNodeParameters, serviceTemplate.inputs.map(function(input) {
+ var inputs = serviceTemplate.inputs.map(function(input) {
input.name = nodeTemplate.type + '.' + input.name;
return input;
- }));
- })
- params.notify(oneNodeParameters);
+ });
+ $.when(
+ fetchCsar(serviceTemplate.csarId)
+ ).then(
+ function(response) {
+ if(response.type === 'NSAR' || response.type === 'NFAR') {
+ inputs.push({
+ name: nodeTemplate.type + '.location',
+ type: 'location',
+ description: nodeTemplate.name + ' Location',
+ required: 'true'
+ });
+ }
+ nodeAggregatation.notify(inputs);
+ }
+ );
+ });
}
);
});
@@ -154,6 +220,20 @@ function fetchNodeTemplates(templateId) {
});
}
+function aggregate(n, deferFun) {
+ var aggregation = $.Deferred();
+ var count = n;
+ var result = [];
+ aggregation.progress(function(array) {
+ pushAll(result, array);
+ count--;
+ if(count === 0) {
+ deferFun(result);
+ }
+ });
+ return aggregation;
+}
+
function concat(array1, array2) {
var result = [];
pushAll(result, array1);
@@ -169,28 +249,56 @@ function pushAll(acc, array) {
return result;
}
-function generateLocationComponent(templateId) {
- var defer = $.Deferred();
- $.when(
- fetchServiceTemplateBy(templateId)
- ).then(
- function (template) {
- if(template.serviceType === 'SDNO') {
- // SDNO need not config location parameter.
- defer.resolve('');
- return;
- }
- $.when(
- fetchVimInfo()
- ).then(
- function (vimsResponse) {
- var vims = translateToVimInfo(vimsResponse);
- defer.resolve(transformToLocationComponent(vims));
- }
- )
- }
- );
- return defer;
+function translateToTemplateParameters(inputs, vims) {
+ var inputParameters = [];
+ var i;
+ for (i = 0; i < inputs.length; i += 1) {
+ inputParameters[i] = {
+ name: inputs[i].name,
+ type: inputs[i].type,
+ description: inputs[i].description,
+ defaultValue: inputs[i].defaultValue,
+ required: inputs[i].required,
+ id: 'parameters_' + i,
+ value: inputs[i].defaultValue || ''
+ };
+ }
+ return {changed: false, parameters: inputParameters, vimInfos: vims};
+}
+
+function fetchNfvoTemplateInputParameters(templateId) {
+ var defer = $.Deferred();
+ $.when(
+ fetchTemplateParameterDefinitions(templateId),
+ fetchVimInfo()
+ ).then(
+ function (templateParameterResponse, vimInfoResponse) {
+ var vims = translateToVimInfo(vimInfoResponse[0]);
+ var inputParas = templateParameterResponse[0].inputs;
+ inputParas.push({
+ name: 'location',
+ type: 'location',
+ description: 'Location',
+ required: 'true'
+ });
+ templateParameters = translateToTemplateParameters(inputParas, vims);
+ defer.resolve(templateParameters);
+ }
+ );
+ return defer;
+}
+
+function fetchSdnoTemplateInputParameters(templateId) {
+ var defer = $.Deferred();
+ $.when(
+ fetchTemplateParameterDefinitions(templateId)
+ ).then(
+ function (templateParameterResponse) {
+ templateParameters = translateToTemplateParameters(templateParameterResponse.inputs, []);
+ defer.resolve(templateParameters);
+ }
+ );
+ return defer;
}
function fetchTemplateParameterDefinitions(templateId) {
@@ -209,71 +317,39 @@ function fetchVimInfo() {
});
}
-function translateToTemplateParameters(inputs) {
- var inputParameters = [];
- var i;
- for (i = 0; i < inputs.length; i += 1) {
- inputParameters[i] = {
- name: inputs[i].name,
- type: inputs[i].type,
- description: inputs[i].description,
- defaultValue: inputs[i].defaultValue,
- required: inputs[i].required,
- id: 'parameter_' + i,
- value: inputs[i].defaultValue || ''
- };
- }
- return {changed: false, parameters: inputParameters};
-}
-
function translateToVimInfo(vims) {
- var result = [];
- var i;
- for (i = 0; i < vims.length; i += 1) {
- var option = '<option value="' + vims[i].vimId + '">' + vims[i].name + '</option>';
- result[i] = {
- vimId: vims[i].vimId,
- vimName: vims[i].name
- };
- }
- return result;
-}
-
-function transformToComponents(parameters) {
- var components = '';
- var i;
- for (i = 0; i < parameters.length; i += 1) {
- var component = '<div class="mT15 form-group" style="margin-left:25px;">' +
- '<label class="col-sm-3 control-label">' +
- '<span>' + parameters[i].description + '</span>' + generateRequiredLabel(parameters[i]) +
- '</label>' +
- '<div class="col-sm-7">' +
- '<input type="text" id="' + parameters[i].id + '" name="parameter description" class="form-control" placeholder="' +
- parameters[i].description + '" value="' + parameters[i].value + '" />' +
- '</div></div>';
- components = components + component;
- }
- return components;
+ return vims.map(function (vim) {
+ return {
+ vimId: vim.vimId,
+ vimName: vim.name
+ };
+ });
}
-function generateRequiredLabel(parameter) {
- var requiredLabel = '';
- if (parameter.required === 'true') {
- requiredLabel = '<span class="required">*</span>';
- }
- return requiredLabel;
+function transformToComponents(templateParas) {
+ var inputs = templateParas.parameters;
+ var vimInfos = templateParas.vimInfos;
+ var components = '';
+ inputs.forEach(function (inputPara) {
+ if(inputPara.type === 'location') {
+ components = components + generateLocationComponent(inputPara, vimInfos);
+ } else {
+ components = components + generateComponent(inputPara);
+ }
+ });
+ return components;
}
-function transformToLocationComponent(vims) {
+function generateLocationComponent(inputPara, vimInfos) {
var component = '<div class="form-group" style="margin-left:25px;margin-bottom:15px;">' +
'<label class="col-sm-3 control-label">' +
- '<span>Location</span>' +
+ '<span>'+ inputPara.description +'</span>' +
'<span class="required">*</span>' +
'</label>' +
'<div class="col-sm-7">' +
'<select class="form-control" style ="padding-top: 0px;padding-bottom: 0px;"' +
- ' id="vim_location" name="vim_location">' +
- transformToOptions(vims) +
+ ' id="' + inputPara.id + '" name="vim_location">' +
+ transformToOptions(vimInfos) +
'</select></div></div>';
return component;
}
@@ -288,40 +364,24 @@ function transformToOptions(vims) {
return options;
}
-function fetchServiceTemplateBy(templateId) {
- var defer = $.Deferred();
- var serviceTemplateUri = '/openoapi/catalog/v1/servicetemplates/' + templateId;
- var template = {};
- $.when(
- $.ajax({
- type: "GET",
- url: serviceTemplateUri,
- contentType: "application/json"
- })
- ).then(
- function(response) {
- template.name = response.templateName;
- template.gsarId = response.csarId;
- var queryCsarUri = '/openoapi/catalog/v1/csars/' + template.gsarId;
- return $.ajax({
- type: "GET",
- url: queryCsarUri,
- contentType: "application/json"
- });
- }
- ).then(
- function(response) {
- if(response.type === 'GSAR') {
- template.serviceType = 'GSO';
- } else if(response.type === 'NSAR' || response.type === 'NFAR') {
- template.serviceType = 'NFVO';
- } else if(response.type === 'SSAR') {
- template.serviceType = "SDNO";
- }
- defer.resolve(template)
- }
- );
- return defer;
+function generateComponent(inputPara) {
+ var component = '<div class="mT15 form-group" style="margin-left:25px;">' +
+ '<label class="col-sm-3 control-label">' +
+ '<span>' + inputPara.description + '</span>' + generateRequiredLabel(inputPara) +
+ '</label>' +
+ '<div class="col-sm-7">' +
+ '<input type="text" id="' + inputPara.id + '" name="parameter description" class="form-control" placeholder="' +
+ inputPara.description + '" value="' + inputPara.value + '" />' +
+ '</div></div>';
+ return component;
+}
+
+function generateRequiredLabel(parameter) {
+ var requiredLabel = '';
+ if (parameter.required === 'true') {
+ requiredLabel = '<span class="required">*</span>';
+ }
+ return requiredLabel;
}
function createNetworkServiceInstance(template, serviceInstance, gatewayService) {
@@ -336,7 +396,6 @@ function createNetworkServiceInstance(template, serviceInstance, gatewayService)
function createGsoServiceInstance(gatewayService, serviceInstance, serviceTemplate) {
var defer = $.Deferred();
- serviceInstance.inputParameters.location = serviceInstance.vimLocation;
var gsoLcmUri = '/openoapi/gso/v1/services';
var parameter = {
'service': {
@@ -364,7 +423,6 @@ function createGsoServiceInstance(gatewayService, serviceInstance, serviceTempla
function createNfvoServiceInstance(gatewayService, serviceInstance) {
var nfvoLcmNsUri = '/openoapi/nslcm/v1.0/ns';
- serviceInstance.inputParameters.location = serviceInstance.vimLocation;
return createServiceInstance(gatewayService, nfvoLcmNsUri, serviceInstance);
}
@@ -414,7 +472,8 @@ function collectServiceParameters(parameters) {
var serviceParameters = {};
var i;
for (i = 0; i < parameters.length; i += 1) {
- serviceParameters[parameters[i].name] = $('#' + parameters[i].id).val();
+ var value = $('#' + parameters[i].id).val();
+ serviceParameters[parameters[i].name] = value;
}
return serviceParameters;
}
@@ -474,7 +533,7 @@ function deleteNonGsoServiceInstance(gatewayService, nsUri, instanceId, remove)
function() {
remove();
}
- )
+ );
}
function deleteNetworkServiceInstance(gatewayService, nsUri, instanceId) {