diff --git a/index.js b/index.js index f6120e2..f00e0de 100644 --- a/index.js +++ b/index.js @@ -155,6 +155,7 @@ function clearCircle(option) { messageTextArea.value = ""; } latLonInputPairIdx = 0; + vmReqeustFromSpecList = []; recommendedSpecList = []; cspPointsCircle = []; geoCspPointsCircle = []; @@ -180,6 +181,7 @@ function writeLatLonInputPair(idx, lat, lon) { } var latLonInputPairIdx = 0; +var vmReqeustFromSpecList = new Array(); var recommendedSpecList = new Array(); map.on("singleclick", function (event) { @@ -1008,7 +1010,7 @@ var createMcisReqVmTmplt = { }; function createMcis() { - if (recommendedSpecList.length != 0) { + if (vmReqeustFromSpecList.length != 0) { var hostname = hostnameElement.value; var port = portElement.value; var username = usernameElement.value; @@ -1021,36 +1023,67 @@ function createMcis() { var createMcisReq = createMcisReqTmplt; createMcisReq.name = "mc-" + `${randomString}`; - createMcisReq.vm = recommendedSpecList; + createMcisReq.vm = vmReqeustFromSpecList; + let totalCost = 0; + let totalNodeScale = 0; var subGroupReqString = ""; for (i = 0; i < createMcisReq.vm.length; i++) { - createMcisReq.vm.name; + + totalNodeScale += parseInt(createMcisReq.vm[i].subGroupSize); + let costPerHour = recommendedSpecList[i].costPerHour; + let subTotalCost = "unknown"; + if (costPerHour == "100000000" || costPerHour == "") { + costPerHour = "unknown"; + costPerHour = "Estimated Price(USD/1H)$" + subTotalCost + " ($"+costPerHour+" * "+createMcisReq.vm[i].subGroupSize+")"+"" ; + } else { + totalCost += parseFloat(costPerHour) * createMcisReq.vm[i].subGroupSize; + + subTotalCost = (parseFloat(costPerHour) * createMcisReq.vm[i].subGroupSize).toFixed(4); + costPerHour = "Estimated Price(USD/1H)$" + subTotalCost + " ($"+costPerHour+" * "+createMcisReq.vm[i].subGroupSize+")"+"" ; + } + let acceleratorType = recommendedSpecList[i].acceleratorType; + let acceleratorModel = recommendedSpecList[i].acceleratorModel; + if (acceleratorType == "gpu" ) { + acceleratorType = "AcceleratorGPU ("+ acceleratorModel +")" + } else { + acceleratorType = "Acceleratornone" + } var html = - "

[" + - (i + 1).toString() + - "] " + - createMcisReq.vm[i].name + - " (size: " + - createMcisReq.vm[i].subGroupSize + - ")" + - "
- Image: " + - createMcisReq.vm[i].commonImage + - "
- Spec: " + - createMcisReq.vm[i].commonSpec + - "
- DiskType: " + - createMcisReq.vm[i].rootDiskType + - " / DiskSize: " + - createMcisReq.vm[i].rootDiskSize; + "" + + "" + + "" + + costPerHour + + "" + + "" + + "" + + acceleratorType + + "" + + "" + + + "
[#"+ (i + 1).toString() +"] SubGroup Name" + createMcisReq.vm[i].name + " ("+createMcisReq.vm[i].subGroupSize+" node(s))
Spec" + createMcisReq.vm[i].commonSpec + "
vCPU" + recommendedSpecList[i].vCPU + "
Mem(GiB)" + recommendedSpecList[i].memoryGiB + "
RootDisk(GB)" + recommendedSpecList[i].rootDiskSize +" (type: "+recommendedSpecList[i].rootDiskType+ ")
Selected Image OS Type" + createMcisReq.vm[i].commonImage + "
"+ + "
" + ; subGroupReqString = subGroupReqString + html; } + + var costDetailsHtml = + + "" + + "" + + "" + + "" + + "" + + "
Usage PeriodEstimated Cost
Hourly$" + totalCost.toFixed(4) + "
Daily$" + (totalCost * 24).toFixed(4) + "
Monthly$" + (totalCost * 24 * 31).toFixed(4) + "

(Do not rely on this estimated cost. It is just an estimation using spec price.)
"; + + var hasUserConfirmed = false; Swal.fire({ - title: "Please change the name of MCIS to create if you wish", + title: "Enter the name of the MCIS you wish to create", input: "text", inputAttributes: { autocapitalize: "off", @@ -1063,12 +1096,14 @@ function createMcis() { createMcisReq.name = result.value; Swal.fire({ - title: "Are you sure to create MCIS as follows:", - width: 600, + title: "Are you sure you want to create this MCIS?", + width: 750, html: - "" + - "MCIS name: " + - createMcisReq.name + + "" + + "
" + createMcisReq.name +" ("+totalNodeScale+" node(s))" + "
"+ + "
" + + costDetailsHtml + + "
" + subGroupReqString + "

Hold VM provisioning of the MCIS"+ "
Deploy CB-Dragonfly monitoring agent", @@ -1256,8 +1291,9 @@ function getRecommendedSpec(idx, latitude, longitude) { // } var createMcisReqVm = $.extend({}, createMcisReqVmTmplt); + var recommendedSpec = res.data[0]; - createMcisReqVm.name = "g" + (recommendedSpecList.length + 1).toString(); + createMcisReqVm.name = "g" + (vmReqeustFromSpecList.length + 1).toString(); osImage = document.getElementById("osImage"); diskSize = document.getElementById("diskSize"); @@ -1276,44 +1312,48 @@ function getRecommendedSpec(idx, latitude, longitude) { // need to validate requested disk size >= default disk size given by vm spec } + let costPerHour = res.data[0].costPerHour; + if (costPerHour == "100000000" || costPerHour == "") { + costPerHour = "unknown"; + } + let acceleratorType = res.data[0].acceleratorType; + let acceleratorModel = res.data[0].acceleratorModel; + if (acceleratorType == "gpu" ) { + acceleratorType = "AcceleratorTypeGPU" + acceleratorModel = "AcceleratorModel" + acceleratorModel + "" + } else { + acceleratorType = "AcceleratorTypeNone" + acceleratorModel = "AcceleratorModel" + acceleratorModel + "" + } + Swal.fire({ - title: "Please provide the number of VMs to create (1 ~ 10)", - width: 600, + title: "Recommended Spec and CSP region
(select the number for scaling VMs (1 ~ 10))", + width: 700, html: - "" + - "Recommended VM Spec " + - res.data[0].cspSpecName + - "
OS Image Type: " + - createMcisReqVm.commonImage + - - "

vCPU: " + - res.data[0].vCPU + - "
Mem(GiB): " + - res.data[0].memoryGiB + - "
RootDiskType: " + - res.data[0].rootDiskType + - "
RootDiskSize(GB): " + - createMcisReqVm.rootDiskSize + - "
Cost($/1H): " + - res.data[0].costPerHour + - "
"+ - - "
AcceleratorType: " + - res.data[0].acceleratorType + - "
AcceleratorModel: " + - res.data[0].acceleratorModel + - "
AcceleratorCount: " + - res.data[0].acceleratorCount + - "
AcceleratorMemoryGB: " + - res.data[0].acceleratorMemoryGB + - "
"+ - - "
CSP: " + - res.data[0].providerName + - "
Region: " + - res.data[0].regionName + - "
ConnectionConfig: " + - res.data[0].connectionName + "" + + "" + + "" + + "" + + "" + + + "" + + "" + + "" + + "" + + + "" + + "" + + "" + + "" + + "" + + + "" + + acceleratorType + + acceleratorModel + + "" + + "" + + + "
Recommended Spec" + res.data[0].cspSpecName + "
Estimated Price(USD/1H)$ " + costPerHour + "
Selected Image OS Type" + createMcisReqVm.commonImage + "
------" + "" + "
Provider" + res.data[0].providerName.toUpperCase() + "
Region" + res.data[0].regionName + "
ConnectionConfig" + res.data[0].connectionName + "
------" + "" + "
vCPU" + res.data[0].vCPU + "
Mem(GiB)" + res.data[0].memoryGiB + "
RootDiskType" + res.data[0].rootDiskType + "
RootDiskSize(GB)" + createMcisReqVm.rootDiskSize + "
------" + "" + "
AcceleratorCount" + res.data[0].acceleratorCount + "
AcceleratorMemoryGB" + res.data[0].acceleratorMemoryGB + "
" , input: "number", inputValue: 1, @@ -1343,7 +1383,8 @@ function getRecommendedSpec(idx, latitude, longitude) { messageTextArea.value += `${createMcisReqVm.commonSpec}` + `\t(${createMcisReqVm.subGroupSize})`; - recommendedSpecList.push(createMcisReqVm); + vmReqeustFromSpecList.push(createMcisReqVm); + recommendedSpecList.push(recommendedSpec); } else { messageTextArea.value = messageTextArea.value.replace(/\n.*$/, ""); latLonInputPairIdx--; @@ -3166,7 +3207,7 @@ window.onload = function () { }; let drawCounter = 0; -const shuffleInterval = 100; // Shuffle every 100 draws +const shuffleInterval = 200; // Shuffle every shuffleInterval draws let shuffledKeys = Object.keys(cspIconStyles); // Initialize with original keys function shuffleKeys() {