forked from seokho-son/cb-mapui
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
4047 lines (3601 loc) · 127 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright 2019 The Cloud-Barista Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
----
Copyright for OpenLayers (https://openlayers.org/)
BSD 2-Clause License
Copyright 2005-present, OpenLayers Contributors
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
----
*/
// OpenLayers CSS
import "ol/ol.css";
// OpenLayers core components
import Map from "ol/Map";
import View from "ol/View";
import Feature from "ol/Feature";
import Overlay from "ol/Overlay";
// OpenLayers geometry types
import { MultiPoint, Point, LineString, Polygon } from "ol/geom";
// OpenLayers layer types
import TileLayer from "ol/layer/Tile";
import { Vector as VectorLayer } from "ol/layer";
// OpenLayers source types
import OSM from "ol/source/OSM";
import { TileJSON, Vector as VectorSource } from "ol/source";
// OpenLayers style components
import {
Circle as CircleStyle,
Fill,
Stroke,
Style,
Text,
Icon,
} from "ol/style";
// OpenLayers utilities and controls
import { getVectorContext } from "ol/render";
import { useGeographic, toLonLat } from "ol/proj";
import { toStringHDMS, createStringXY } from "ol/coordinate";
import MousePosition from "ol/control/MousePosition";
import { defaults as defaultControls } from "ol/control";
// Third-party libraries
import Swal from "sweetalert2";
import axios, { AxiosError } from "axios";
import JSONFormatter from "json-formatter-js";
useGeographic();
var i, j;
var cnti, cntj;
const cntInit = 0;
var cnt = cntInit;
//var n = 1000;
var geometries = new Array();
var geometriesPoints = new Array();
var mciName = new Array();
var mciStatus = new Array();
var mciGeo = new Array();
var cspListDisplayEnabled = document.getElementById("displayOn");
var tableDisplayEnabled = document.getElementById("tableOn");
var table = document.getElementById("detailTable");
var recommendPolicy = document.getElementById("recommendPolicy");
var selectApp = document.getElementById("selectApp");
var messageTextArea = document.getElementById("message");
var messageJsonOutput = document.getElementById("jsonoutput");
var hostnameElement = document.getElementById("hostname");
var portElement = document.getElementById("port");
var usernameElement = document.getElementById("username");
var passwordElement = document.getElementById("password");
var namespaceElement = document.getElementById("namespace");
var mciidElement = document.getElementById("mciid");
const typeStringConnection = "connection";
const typeStringProvider = "provider";
const typeStringImage = "image";
const typeStringSpec = "spec";
const typeStringSG = "securityGroup";
const typeStringSshKey = "sshKey";
const typeStringVNet = "vNet";
const typeInfo = "info";
const typeError = "error";
var tileLayer = new TileLayer({
source: new OSM(),
});
/*
* Create the map.
*/
var map = new Map({
layers: [tileLayer],
target: "map",
view: new View({
center: [30, 30],
zoom: 3,
}),
//projection: 'EPSG:4326'
});
// fucntion for clear map.
function clearMap() {
// table.innerHTML = "";
messageJsonOutput.value = "";
messageTextArea.value = "";
geometries = [];
geoResourceLocation.k8s = [];
geoResourceLocation.sg = [];
geoResourceLocation.sshKey = [];
geoResourceLocation.vnet = [];
geoResourceLocation.vpn = [];
map.render();
}
window.clearMap = clearMap;
function clearCircle(option) {
//document.getElementById("latLonInputPairArea").innerHTML = '';
if (option == "clearText") {
messageTextArea.value = "";
}
latLonInputPairIdx = 0;
vmReqeustFromSpecList = [];
recommendedSpecList = [];
cspPointsCircle = [];
geoCspPointsCircle = [];
messageJsonOutput.value = "";
// table.innerHTML = "";
}
window.clearCircle = clearCircle;
function writeLatLonInputPair(idx, lat, lon) {
var recommendedSpec = getRecommendedSpec(idx, lat, lon);
var latf = lat.toFixed(4);
var lonf = lon.toFixed(4);
//document.getElementById("latLonInputPairArea").innerHTML +=
`VM ${idx + 1}: (${latf}, ${lonf}) / `;
if (idx == 0) {
messageTextArea.value = `[Started MCI configuration]\n`;
}
messageTextArea.value += `\n - [VM-${idx + 1
}] Location: ${latf}, ${lonf}\t\t| Best Spec: `;
messageTextArea.scrollTop = messageTextArea.scrollHeight;
}
var latLonInputPairIdx = 0;
var vmReqeustFromSpecList = new Array();
var recommendedSpecList = new Array();
map.on("singleclick", function (event) {
const coord = event.coordinate;
// document.getElementById('latitude').value = coord[1];
// document.getElementById('longitude').value = coord[0];
writeLatLonInputPair(latLonInputPairIdx, coord[1], coord[0]);
latLonInputPairIdx++;
});
// Initialize an object to keep track of the active spinner tasks
let spinnerStack = {};
// A counter to generate unique IDs for spinner tasks
let currentSpinnerId = 0;
// Function to create a unique spinner task ID based on the function name
function generateSpinnerId(functionName) {
currentSpinnerId++; // Increment the ID
return "[" + currentSpinnerId + "] " + functionName; // Return the unique task ID
}
// Function to add a new task to the spinner stack and update the spinner's visibility
function addSpinnerTask(functionName) {
const taskId = generateSpinnerId(functionName); // Create a unique task ID
spinnerStack[taskId] = true; // Add the task to the stack
updateSpinnerVisibility(); // Update the spinner display
return taskId; // Return the task ID for later reference
}
// Function to remove a task from the spinner stack by its ID and update the spinner's visibility
function removeSpinnerTask(taskId) {
if (spinnerStack[taskId]) {
delete spinnerStack[taskId]; // Remove the task from the stack
updateSpinnerVisibility(); // Update the spinner display
}
}
// Function to update the spinner's visibility based on the active tasks in the stack
function updateSpinnerVisibility() {
const spinnerContainer = document.getElementById("spinner-container"); // Get the spinner container element
const spinnerText = document.getElementById("spinner-text"); // Get the spinner text element
// Check if there are any tasks remaining in the stack
const tasksRemaining = Object.keys(spinnerStack).length > 0;
if (tasksRemaining) {
spinnerContainer.style.display = "flex"; // If there are tasks, display the spinner
// Update the spinner text to show all active task names
spinnerText.textContent = Object.keys(spinnerStack).join(", ");
} else {
spinnerContainer.style.display = "none"; // If no tasks, hide the spinner
}
}
// Display Icon for Cloud locations
// npm i -s csv-parser
const http = require("http");
const csv = require("csv-parser");
const csvPath =
"https://raw.githubusercontent.com/cloud-barista/cb-tumblebug/main/assets/cloudlocation.csv";
var cloudLocation = [];
var cspPointsCircle = [];
var geoCspPointsCircle = new Array();
var geoResourceLocation = {
sshKey: [],
sg: [],
k8s: [],
vnet: [],
vpn: []
};
var cspPoints = {};
var geoCspPoints = {};
function displayCSPListOn() {
if (cspListDisplayEnabled.checked) {
cloudLocation = [];
http.get(csvPath, (response) => {
response
.pipe(csv())
.on("data", (chunk) => cloudLocation.push(chunk))
.on("end", () => {
console.log(cloudLocation);
messageTextArea.value =
"[Complete] Display Known Cloud Regions: " +
cloudLocation.length +
"\n";
cloudLocation.forEach((location) => {
const { CloudType, Longitude, Latitude } = location;
const cloudTypeLower = CloudType.toLowerCase();
if (!cspPoints[cloudTypeLower]) {
cspPoints[cloudTypeLower] = [];
}
if (!geoCspPoints[cloudTypeLower]) {
geoCspPoints[cloudTypeLower] = [];
}
cspPoints[cloudTypeLower].push([
parseFloat(Longitude),
parseFloat(Latitude),
]);
});
Object.keys(cspPoints).forEach((csp) => {
if (cspPoints[csp].length > 0) {
geoCspPoints[csp][0] = new MultiPoint(cspPoints[csp]);
}
});
});
});
} else {
Object.keys(cspPoints).forEach((csp) => {
cspPoints[csp] = [];
geoCspPoints[csp] = [];
});
}
}
window.displayCSPListOn = displayCSPListOn;
function displayTableOn() {
// table.innerHTML = "";
}
window.displayTableOn = displayTableOn;
function endpointChanged() {
//getMci();
var hostname = document.getElementById('hostname').value;
var iframe = document.getElementById('iframe');
var iframe2 = document.getElementById('iframe2');
iframe.src = "http://" + hostname + ":1324/swagger.html";
iframe2.src = "http://" + hostname + ":1024/spider/adminweb";
}
window.endpointChanged = endpointChanged;
var alpha = 0.3;
var cororList = [
[153, 255, 51, alpha],
[210, 210, 10, alpha],
[0, 176, 244, alpha],
[200, 10, 10, alpha],
[0, 162, 194, alpha],
[38, 63, 143, alpha],
[58, 58, 58, alpha],
[81, 45, 23, alpha],
[225, 136, 65, alpha],
[106, 34, 134, alpha],
[255, 162, 191, alpha],
[239, 45, 53, alpha],
[255, 255, 255, alpha],
[154, 135, 199, alpha],
];
alpha = 0.6;
var cororLineList = [
[0, 255, 0, alpha],
[210, 210, 10, alpha],
[0, 176, 244, alpha],
[200, 10, 10, alpha],
[0, 162, 194, alpha],
[38, 63, 143, alpha],
[58, 58, 58, alpha],
[81, 45, 23, alpha],
[225, 136, 65, alpha],
[106, 34, 134, alpha],
[255, 162, 191, alpha],
[239, 45, 53, alpha],
[255, 255, 255, alpha],
[154, 135, 199, alpha],
];
var polygonFeature = new Feature(
new Polygon([
[
[10, -3],
[-5, 2],
[-1, 1],
],
])
);
function createStyle(src) {
return new Style({
image: new Icon({
anchor: [0.5, 0.5],
crossOrigin: "anonymous",
src: src,
imgSize: [50, 50],
scale: 0.1,
}),
});
}
// temporary point
var pnt = new Point([-68, -50]);
addIconToMap("img/iconVm.png", pnt, "001");
var iconStyleVm = new Style({
image: new Icon({
crossOrigin: "anonymous",
src: "img/iconVm.png",
opacity: 1.0,
scale: 0.7,
}),
});
addIconToMap("img/iconK8s.png", pnt, "001");
var iconStyleK8s = new Style({
image: new Icon({
crossOrigin: "anonymous",
src: "img/iconK8s.png",
opacity: 1.0,
scale: 0.7,
}),
});
addIconToMap("img/iconNlb.png", pnt, "001");
var iconStyleNlb = new Style({
image: new Icon({
crossOrigin: "anonymous",
src: "img/iconNlb.png",
opacity: 1.0,
scale: 0.8,
}),
});
addIconToMap("img/iconVPN.png", pnt, "001");
var iconStyleVPN = new Style({
image: new Icon({
crossOrigin: "anonymous",
src: "img/iconVPN.png",
opacity: 1.0,
scale: 0.8,
}),
});
addIconToMap("img/iconVnet.png", pnt, "001");
var iconStyleVnet = new Style({
image: new Icon({
crossOrigin: "anonymous",
src: "img/iconVnet.png",
opacity: 1.0,
scale: 0.8,
}),
});
addIconToMap("img/iconSG.png", pnt, "001");
var iconStyleSG = new Style({
image: new Icon({
crossOrigin: "anonymous",
src: "img/iconSG.png",
opacity: 1.0,
scale: 0.8,
}),
});
addIconToMap("img/iconKey.png", pnt, "001");
var iconStyleKey = new Style({
image: new Icon({
crossOrigin: "anonymous",
src: "img/iconKey.png",
opacity: 1.0,
scale: 0.8,
}),
});
addIconToMap("img/circle.png", pnt, "001");
var iconStyleCircle = new Style({
image: new Icon({
crossOrigin: "anonymous",
src: "img/circle.png",
opacity: 1.0,
anchor: [0.4, 0.4],
anchorXUnits: "fraction",
anchorYUnits: "fraction",
scale: 1.5,
//imgSize: [50, 50]
}),
});
// CSP location icon styles
const cspIconImg = {
azure: "img/ht-azure.png",
aws: "img/ht-aws.png",
gcp: "img/ht-gcp.png",
alibaba: "img/ht-alibaba.png",
cloudit: "img/ht-cloudit.png",
ibm: "img/ibm.png",
tencent: "img/tencent.png",
ncpvpc: "img/ncpvpc.png",
ncp: "img/ncp.png",
ktcloud: "img/kt.png",
ktcloudvpc: "img/ktvpc.png",
nhncloud: "img/nhn.png",
// Add more CSP icons here
};
// cspIconStyles
const cspIconStyles = {};
function createIconStyle(imageSrc) {
return new Style({
image: new Icon({
crossOrigin: "anonymous",
src: imageSrc,
opacity: 1.0,
scale: 1.0,
}),
});
}
// addIconToMap
Object.keys(cspIconImg).forEach((csp) => {
cspIconStyles[csp] = createIconStyle(cspIconImg[csp]);
});
function addIconToMap(imageSrc, point, index) {
var vectorSource = new VectorSource({ projection: "EPSG:4326" });
var iconFeature = new Feature(point);
iconFeature.set("style", createStyle(imageSrc));
iconFeature.set("index", index);
vectorSource.addFeature(iconFeature);
var iconLayer = new VectorLayer({
style: function (feature) {
return feature.get("style");
},
source: vectorSource,
});
map.addLayer(iconLayer);
map.render();
}
Object.keys(cspIconImg).forEach((csp, index) => {
const iconIndex = index.toString().padStart(3, "0");
addIconToMap(cspIconImg[csp], pnt, iconIndex);
});
// magenta black blue orange yellow red grey green
function changeColorStatus(status) {
if (status.includes("Partial")) {
return "green";
} else if (status.includes("Running")) {
return "blue";
} else if (status.includes("Suspending")) {
return "black";
} else if (status.includes("Creating")) {
return "orange";
} else if (status.includes("Terminated")) {
return "red";
} else if (status.includes("Terminating")) {
return "grey";
} else {
return "grey";
}
}
function changeSizeStatus(status) {
if (status.includes("-df")) {
return 0.4;
} else if (status.includes("-ws")) {
return 0.4;
} else if (status.includes("NLB")) {
return 1.5;
} else if (status.includes("Partial")) {
return 2.4;
} else if (status.includes("Running")) {
return 2.5;
} else if (status.includes("Suspending")) {
return 2.4;
} else if (status.includes("Suspended")) {
return 2.4;
} else if (status.includes("Creating")) {
return 2.5;
} else if (status.includes("Resuming")) {
return 2.4;
} else if (status.includes("Terminated")) {
return 2.4;
} else if (status.includes("Terminating")) {
return 2.4;
} else {
return 1.0;
}
}
function changeSizeByName(status) {
if (status.includes("-best")) {
return 3.5;
} else if (status.includes("-df")) {
return 0.4;
} else if (status.includes("-ws")) {
return 0.4;
} else if (status.includes("NLB")) {
return 1.5;
} else {
return 2.5;
}
}
function returnAdjustmentPoint(num) {
ax = 0.0;
ay = 0.0;
if (num == 1) {
ax = 0;
ay = 0.75;
} else if (num == 2) {
ax = 0.5;
ay = 0.5;
} else if (num == 3) {
ax = 0.75;
ay = 0;
} else if (num == 4) {
ax = 0.5;
ay = -0.5;
} else if (num == 5) {
ax = 0;
ay = -0.75;
} else if (num == 6) {
ax = -0.5;
ay = -0.5;
} else if (num == 7) {
ax = -0.75;
ay = -0;
} else if (num == 8) {
ax = -0.5;
ay = 0.5;
} else {
ax = Math.random() - Math.random();
ay = Math.random() - Math.random();
}
ax = Math.random() * 0.01 + ax;
ay = Math.random() * 0.01 + ay;
ay = ay * 0.78;
return { ax, ay };
}
var n = 400;
var omegaTheta = 600000; // Rotation period in ms
var R = 7;
var r = 2;
var p = 2;
var coordinates = [];
coordinates.push([-180, -90]);
var coordinatesFromX = [];
coordinatesFromX.push([0]);
var coordinatesFromY = [];
coordinatesFromY.push([0]);
var coordinatesToX = [];
coordinatesToX.push([1]);
var coordinatesToY = [];
coordinatesToY.push([1]);
function makeTria(ip1, ip2, ip3) {
changePoints(ip1, ip2);
changePoints(ip2, ip3);
changePoints(ip3, ip1);
geometries[cnt] = new Polygon([[ip1, ip2, ip3, ip1]]);
//cnt++;
}
function makePolyDot(vmPoints) {
//for (i = 0; i < vmPoints.length; i++) {
//coordinates.push(vmPoints[i]);
//}
var resourcePoints = [];
for (i = 0; i < vmPoints.length; i++) {
resourcePoints.push(vmPoints[i]);
}
geometriesPoints[cnt] = new MultiPoint(resourcePoints);
//cnt++;
}
function makePolyArray(vmPoints) {
//for (i = 0; i < vmPoints.length; i++) {
//coordinates.push(vmPoints[i]);
//}
var resourcePoints = [];
for (i = 0; i < vmPoints.length; i++) {
resourcePoints.push(vmPoints[i]);
}
//geometriesPoints[cnt] = new MultiPoint(resourcePoints);
resourcePoints.push(vmPoints[0]);
geometries[cnt] = new Polygon([resourcePoints]);
mciGeo[cnt] = new Polygon([resourcePoints]);
//cnt++;
}
function cross(a, b, o) {
return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]);
}
/**
* @param points An array of [X, Y] coordinates
*/
function convexHull(points) {
points.sort(function (a, b) {
return a[0] == b[0] ? a[1] - b[1] : a[0] - b[0];
});
var lower = [];
for (var i = 0; i < points.length; i++) {
while (
lower.length >= 2 &&
cross(lower[lower.length - 2], lower[lower.length - 1], points[i]) <= 0
) {
lower.pop();
}
lower.push(points[i]);
}
var upper = [];
for (var i = points.length - 1; i >= 0; i--) {
while (
upper.length >= 2 &&
cross(upper[upper.length - 2], upper[upper.length - 1], points[i]) <= 0
) {
upper.pop();
}
upper.push(points[i]);
}
upper.pop();
lower.pop();
return lower.concat(upper);
}
function changePoints(ipFrom, ipTo) {
var lon = 360 * Math.random() - 180;
var lat = 180 * Math.random() - 90;
var lon1 = 360 * Math.random() - 180;
var lat1 = 180 * Math.random() - 90;
console.log(ipFrom);
console.log(ipTo);
coordinates.push(ipFrom);
coordinates.push(ipTo);
var i, j;
var xFrom = ipFrom[0];
var yFrom = ipFrom[1];
var xTo = ipTo[0];
var yTo = ipTo[1];
for (j = 1; j < n; ++j) {
var goX = xFrom + (j * (xTo - xFrom)) / n;
var goY = ((yTo - yFrom) / (xTo - xFrom)) * (goX - xFrom) + yFrom;
}
}
var refreshInterval = 5;
// setTimeout(() => getMci(), refreshInterval*1000);
//setTimeout(() => console.log(getConnection()), refreshInterval*1000);
function infoAlert(message) {
Swal.fire({
// position: 'top-end',
icon: "info",
title: message,
showConfirmButton: false,
timer: 2500,
});
}
function errorAlert(message) {
Swal.fire({
// position: 'bottom-start',
icon: "error",
title: message,
showConfirmButton: true,
//timer: 2000
});
}
function outputAlert(jsonData, type) {
const jsonOutputConfig = {
theme: "dark",
};
Swal.fire({
position: "top-end",
icon: type,
html: '<div id="json-output" class="form-control" style="height: auto; background-color: black; text-align: left; white-space: pre-wrap; word-break: break-all; overflow-wrap: break-word; overflow-x: auto;"></div>',
background: "#0e1746",
showConfirmButton: true,
width: '40%',
//backdrop: false,
didOpen: () => {
const container = document.getElementById("json-output");
const formatter = new JSONFormatter(jsonData, Infinity, jsonOutputConfig);
container.appendChild(formatter.render());
},
});
}
function displayJsonData(jsonData, type) {
const jsonOutputConfig = {
theme: "dark",
};
outputAlert(jsonData, type);
const messageJsonOutput = document.getElementById("jsonoutput");
messageJsonOutput.innerHTML = ""; // Clear existing content
messageJsonOutput.appendChild(
new JSONFormatter(jsonData, Infinity, jsonOutputConfig).render()
);
}
function getMci() {
var hostname = hostnameElement.value;
var port = portElement.value;
var username = usernameElement.value;
var password = passwordElement.value;
var namespace = namespaceElement.value;
refreshInterval = document.getElementById("refreshInterval").value;
var filteredRefreshInterval = isNormalInteger(refreshInterval)
? refreshInterval
: 5;
setTimeout(() => getMci(), filteredRefreshInterval * 1000);
var zoomLevel = map.getView().getZoom() * 2.0;
var radius = 4.0;
if (namespace && namespace != "") {
// get mci list and put them on the map
var url = `http://${hostname}:${port}/tumblebug/ns/${namespace}/mci?option=status`;
axios({
method: "get",
url: url,
auth: {
username: `${username}`,
password: `${password}`,
},
timeout: 60000,
})
.then((res) => {
var obj = res.data;
cnt = cntInit;
if (obj.mci != null) {
for (let item of obj.mci) {
console.log(item);
var hideFlag = false;
for (let hideName of mciHideList) {
if (item.id == hideName) {
hideFlag = true;
break;
}
}
if (hideFlag) {
continue;
}
var vmGeo = [];
var validateNum = 0;
if (item.vm == null) {
console.log(item);
break;
}
for (j = 0; j < item.vm.length; j++) {
//vmGeo.push([(item.vm[j].location.longitude*1) + (Math.round(Math.random()) / zoomLevel - 1) * Math.random()*1, (item.vm[j].location.latitude*1) + (Math.round(Math.random()) / zoomLevel - 1) * Math.random()*1 ])
if (j == 0) {
vmGeo.push([
item.vm[j].location.longitude * 1,
item.vm[j].location.latitude * 1,
]);
} else {
var groupCnt = 0;
if ((item.vm[j].location.longitude == item.vm[j - 1].location.longitude) && (item.vm[j].location.latitude == item.vm[j - 1].location.latitude)) {
vmGeo.push([
item.vm[j].location.longitude * 1 +
(returnAdjustmentPoint(j).ax / zoomLevel) * radius,
item.vm[j].location.latitude * 1 +
(returnAdjustmentPoint(j).ay / zoomLevel) * radius,
]);
} else {
vmGeo.push([
item.vm[j].location.longitude * 1,
item.vm[j].location.latitude * 1,
]);
}
}
validateNum++;
}
if (item.vm.length == 1) {
// handling if there is only one vm so that we can not draw geometry
vmGeo.pop();
vmGeo.push([
item.vm[0].location.longitude * 1,
item.vm[0].location.latitude * 1,
]);
vmGeo.push([
item.vm[0].location.longitude * 1 + Math.random() * 0.001,
item.vm[0].location.latitude * 1 + Math.random() * 0.001,
]);
vmGeo.push([
item.vm[0].location.longitude * 1 + Math.random() * 0.001,
item.vm[0].location.latitude * 1 + Math.random() * 0.001,
]);
}
if (validateNum == item.vm.length) {
//console.log("Found all GEOs validateNum : " + validateNum);
//make dots without convexHull
makePolyDot(vmGeo);
vmGeo = convexHull(vmGeo);
mciStatus[cnt] = item.status;
var newName = item.name;
if (newName.includes("-nlb")) {
newName = "NLB";
}
if (item.targetAction == "None" || item.targetAction == "") {
mciName[cnt] = "[" + newName + "]";
} else {
mciName[cnt] = item.targetAction + "-> " + "[" + newName + "]";
}
//make poly with convexHull
makePolyArray(vmGeo);
cnt++;
}
}
} else {
geometries = [];
}
})
.catch(function (error) {
console.log(error);
});
// get vnet list and put them on the map
var url = `http://${hostname}:${port}/tumblebug/ns/${namespace}/resources/vNet`;
axios({
method: "get",
url: url,
auth: {
username: `${username}`,
password: `${password}`,
},
timeout: 10000,
}).then((res) => {
var obj = res.data;
if (obj.vNet != null) {
var resourceLocation = [];
for (let item of obj.vNet) {
resourceLocation.push([
item.connectionConfig.regionDetail.location.longitude * 1 ,
item.connectionConfig.regionDetail.location.latitude * 1 - 0.05 ,
]);
geoResourceLocation.vnet[0] = new MultiPoint([resourceLocation]);
//console.log("geoResourceLocation.vnet[0]");
//console.log(geoResourceLocation.vnet[0]);
}
} else {
geoResourceLocation.vnet = [];
}
})
.catch(function (error) {
console.log(error);
});
// get securityGroup list and put them on the map
var url = `http://${hostname}:${port}/tumblebug/ns/${namespace}/resources/securityGroup`;
axios({
method: "get",
url: url,
auth: {
username: `${username}`,
password: `${password}`,
},
timeout: 10000,
}).then((res) => {
var obj = res.data;
if (obj.securityGroup != null) {
var resourceLocation = [];
for (let item of obj.securityGroup) {
resourceLocation.push([
item.connectionConfig.regionDetail.location.longitude * 1 - 0.05 ,
item.connectionConfig.regionDetail.location.latitude * 1 ,
]);
geoResourceLocation.sg[0] = new MultiPoint([resourceLocation]);
}
} else {
geoResourceLocation.sg = [];
}
})