This repository has been archived by the owner on Oct 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCompositionsRepositoryDAO.java
1068 lines (904 loc) · 37.6 KB
/
CompositionsRepositoryDAO.java
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
package databases.mysql.daos;
import com.sun.istack.internal.Nullable;
import databases.mysql.CloudEntityData;
import databases.mysql.DAO;
import databases.mysql.FunctionalityURL;
import databases.mysql.MySQLConnect;
import utility.PropertiesManager;
import java.sql.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
* Data Access Object for serverless function composition related information
*/
@SuppressWarnings({"DuplicatedCode", "SqlResolve", "RedundantSuppression"})
public class CompositionsRepositoryDAO extends DAO {
/**
* Queries
*/
private static final String CREATE_GOOGLE_COMPOSITION_CLOUD_FUNCTIONS_HANDLER = "CREATE TABLE IF NOT EXISTS " +
PropertiesManager.getInstance().getProperty(PropertiesManager.MYSQL_DB) +
".google_serverless_handler_function (" +
"id enum('1') NOT NULL, " +
"function_name varchar(50) NOT NULL, " +
"url varchar(100) NOT NULL, " +
"region varchar(15) NOT NULL, " +
"PRIMARY KEY (id)" +
")";
private static final String CREATE_AMAZON_COMPOSITION_LAMBDA_HANDLER = "CREATE TABLE IF NOT EXISTS " +
PropertiesManager.getInstance().getProperty(PropertiesManager.MYSQL_DB) +
".amazon_serverless_handler_function (" +
"id enum('1') NOT NULL, " +
"function_name varchar(50) NOT NULL, " +
"url varchar(100) NOT NULL, " +
"api_id varchar(50) NOT NULL, " +
"region varchar(15) NOT NULL, " +
"PRIMARY KEY (id)" +
")";
private static final String CREATE_GOOGLE_COMPOSITION_TABLE_MAIN = "CREATE TABLE IF NOT EXISTS " +
PropertiesManager.getInstance().getProperty(PropertiesManager.MYSQL_DB) +
".google_serverless_compositions_main (" +
"workflow_name varchar(50) NOT NULL, " +
"workflow_region varchar(15) NOT NULL, " +
"PRIMARY KEY (workflow_name)" +
")";
private static final String CREATE_AMAZON_COMPOSITION_TABLE_MAIN = "CREATE TABLE IF NOT EXISTS " +
PropertiesManager.getInstance().getProperty(PropertiesManager.MYSQL_DB) +
".amazon_serverless_compositions_main (" +
"machine_name varchar(50) NOT NULL, " +
"machine_arn varchar(100) NOT NULL UNIQUE, " +
"machine_region varchar(15) NOT NULL, " +
"PRIMARY KEY (machine_name)" +
")";
private static final String CREATE_OPENWHISK_COMPOSITION_TABLE_MAIN = "CREATE TABLE IF NOT EXISTS " +
PropertiesManager.getInstance().getProperty(PropertiesManager.MYSQL_DB) +
".openwhisk_serverless_compositions_main (" +
"composition_name varchar(50) NOT NULL, " +
"url varchar(100) NOT NULL, " +
"PRIMARY KEY (composition_name)" +
")";
private static final String CREATE_GOOGLE_COMPOSITION_TABLE_FUNCTIONS = "CREATE TABLE IF NOT EXISTS " +
PropertiesManager.getInstance().getProperty(PropertiesManager.MYSQL_DB) +
".google_serverless_compositions_functions (" +
"function_name varchar(50) NOT NULL, " +
"function_region varchar(15) NOT NULL, " +
"workflow varchar(50) NOT NULL, " +
"PRIMARY KEY (function_name), " +
"CONSTRAINT workflow_name_fk FOREIGN KEY (workflow) REFERENCES " +
PropertiesManager.getInstance().getProperty(PropertiesManager.MYSQL_DB) +
".google_serverless_compositions_main(workflow_name)" +
")";
private static final String CREATE_AMAZON_COMPOSITION_TABLE_FUNCTIONS = "CREATE TABLE IF NOT EXISTS " +
PropertiesManager.getInstance().getProperty(PropertiesManager.MYSQL_DB) +
".amazon_serverless_compositions_functions (" +
"function_name varchar(50) NOT NULL, " +
"function_region varchar(15) NOT NULL, " +
"state_machine_arn varchar(100) NOT NULL, " +
"PRIMARY KEY (function_name), " +
"CONSTRAINT state_machine_arn_fk FOREIGN KEY (state_machine_arn) REFERENCES " +
PropertiesManager.getInstance().getProperty(PropertiesManager.MYSQL_DB) +
".amazon_serverless_compositions_main(machine_arn)" +
")";
private static final String CREATE_OPENWHISK_COMPOSITION_TABLE_FUNCTIONS = "CREATE TABLE IF NOT EXISTS " +
PropertiesManager.getInstance().getProperty(PropertiesManager.MYSQL_DB) +
".openwhisk_serverless_compositions_functions (" +
"function_name varchar(50) NOT NULL, " +
"composition varchar(50) NOT NULL, " +
"PRIMARY KEY (function_name), " +
"CONSTRAINT composition_name_fk FOREIGN KEY (composition) REFERENCES " +
PropertiesManager.getInstance().getProperty(PropertiesManager.MYSQL_DB) +
".openwhisk_serverless_compositions_main(composition_name)" +
")";
private static final String INSERT_GOOGLE_HANDLER = "INSERT INTO " +
PropertiesManager.getInstance().getProperty(PropertiesManager.MYSQL_DB) +
".google_serverless_handler_function " +
"(function_name, url, region) " + "VALUES (?, ?, ?) " +
"ON DUPLICATE KEY UPDATE function_name=VALUES(function_name), url=VALUES(url), region=VALUES(region)";
private static final String INSERT_AMAZON_HANDLER = "INSERT INTO " +
PropertiesManager.getInstance().getProperty(PropertiesManager.MYSQL_DB) +
".amazon_serverless_handler_function " +
"(function_name, url, api_id, region) " + "VALUES (?, ?, ?, ?) " +
"ON DUPLICATE KEY UPDATE function_name=VALUES(function_name), url=VALUES(url), " +
"api_id=VALUES(api_id), region=VALUES(region)";
private static final String INSERT_GOOGLE_COMPOSITION_MAIN = "INSERT INTO " +
PropertiesManager.getInstance().getProperty(PropertiesManager.MYSQL_DB) +
".google_serverless_compositions_main " +
"(workflow_name, workflow_region) " + "VALUES (?, ?) " +
"ON DUPLICATE KEY UPDATE workflow_name=VALUES(workflow_name), workflow_region=VALUES(workflow_region)";
private static final String INSERT_AMAZON_COMPOSITION_MAIN = "INSERT INTO " +
PropertiesManager.getInstance().getProperty(PropertiesManager.MYSQL_DB) +
".amazon_serverless_compositions_main " +
"(machine_name, machine_arn, machine_region) " + "VALUES (?, ?, ?) " +
"ON DUPLICATE KEY UPDATE machine_name=VALUES(machine_name), machine_arn=VALUES(machine_arn), " +
"machine_region=VALUES(machine_region)";
private static final String INSERT_OPENWHISK_COMPOSITION_MAIN = "INSERT INTO " +
PropertiesManager.getInstance().getProperty(PropertiesManager.MYSQL_DB) +
".openwhisk_serverless_compositions_main " +
"(composition_name, url) " + "VALUES (?, ?) " +
"ON DUPLICATE KEY UPDATE composition_name=VALUES(composition_name), url=VALUES(url)";
private static final String INSERT_GOOGLE_COMPOSITION_FUNCTION = "INSERT INTO " +
PropertiesManager.getInstance().getProperty(PropertiesManager.MYSQL_DB) +
".google_serverless_compositions_functions " +
"(function_name, function_region, workflow) " + "VALUES (?, ?, ?) " +
"ON DUPLICATE KEY UPDATE function_name=VALUES(function_name), function_region=VALUES(function_region), " +
"workflow=VALUES(workflow)";
private static final String INSERT_AMAZON_COMPOSITION_FUNCTION = "INSERT INTO " +
PropertiesManager.getInstance().getProperty(PropertiesManager.MYSQL_DB) +
".amazon_serverless_compositions_functions " +
"(function_name, function_region, state_machine_arn) " + "VALUES (?, ?, ?) " +
"ON DUPLICATE KEY UPDATE function_name=VALUES(function_name), function_region=VALUES(function_region), " +
"state_machine_arn=VALUES(state_machine_arn)";
private static final String INSERT_OPENWHISK_COMPOSITION_FUNCTION = "INSERT INTO " +
PropertiesManager.getInstance().getProperty(PropertiesManager.MYSQL_DB) +
".openwhisk_serverless_compositions_functions " +
"(function_name, composition) " + "VALUES (?, ?) " +
"ON DUPLICATE KEY UPDATE function_name=VALUES(function_name), composition=VALUES(composition)";
private static final String SELECT_GOOGLE_HANDLER_INFO = "SELECT function_name, region " +
"FROM " + PropertiesManager.getInstance().getProperty(PropertiesManager.MYSQL_DB) +
".google_serverless_handler_function WHERE id=1";
private static final String SELECT_AMAZON_HANDLER_INFO = "SELECT function_name, api_id, region " +
"FROM " + PropertiesManager.getInstance().getProperty(PropertiesManager.MYSQL_DB) +
".amazon_serverless_handler_function WHERE id=1";
private static final String SELECT_GOOGLE_FUNCTION_INFOS = "SELECT function_name, function_region " +
"FROM " + PropertiesManager.getInstance().getProperty(PropertiesManager.MYSQL_DB) +
".google_serverless_compositions_functions";
private static final String SELECT_AMAZON_FUNCTION_INFOS = "SELECT function_name, function_region " +
"FROM " + PropertiesManager.getInstance().getProperty(PropertiesManager.MYSQL_DB) +
".amazon_serverless_compositions_functions";
private static final String SELECT_OPENWHISK_FUNCTION_INFOS = "SELECT function_name " +
"FROM " + PropertiesManager.getInstance().getProperty(PropertiesManager.MYSQL_DB) +
".openwhisk_serverless_compositions_functions";
private static final String SELECT_GOOGLE_WORKFLOW_INFOS = "SELECT workflow_name, workflow_region " +
"FROM " + PropertiesManager.getInstance().getProperty(PropertiesManager.MYSQL_DB) +
".google_serverless_compositions_main";
private static final String SELECT_AMAZON_MACHINE_INFOS = "SELECT machine_name, machine_arn, machine_region " +
"FROM " + PropertiesManager.getInstance().getProperty(PropertiesManager.MYSQL_DB) +
".amazon_serverless_compositions_main";
private static final String SELECT_OPENWHISK_COMPOSITION_INFOS = "SELECT composition_name, url " +
"FROM " + PropertiesManager.getInstance().getProperty(PropertiesManager.MYSQL_DB) +
".openwhisk_serverless_compositions_main";
private static final String SELECT_GOOGLE_HANDLER_URL = "SELECT url " +
"FROM " + PropertiesManager.getInstance().getProperty(PropertiesManager.MYSQL_DB) +
".google_serverless_handler_function WHERE id=1";
private static final String SELECT_AMAZON_HANDLER_URL = "SELECT url " +
"FROM " + PropertiesManager.getInstance().getProperty(PropertiesManager.MYSQL_DB) +
".amazon_serverless_handler_function WHERE id=1";
private static final String SELECT_GOOGLE_WORKFLOWS_NAMES = "SELECT workflow_name " +
"FROM " + PropertiesManager.getInstance().getProperty(PropertiesManager.MYSQL_DB) +
".google_serverless_compositions_main";
@SuppressWarnings("SpellCheckingInspection")
private static final String SELECT_AMAZON_MACHINES_ARNS = "SELECT machine_name, machine_arn " +
"FROM " + PropertiesManager.getInstance().getProperty(PropertiesManager.MYSQL_DB) +
".amazon_serverless_compositions_main";
private static final String SELECT_OPENWHISK_COMPOSITION_NAMES = "SELECT composition_name " +
"FROM " + PropertiesManager.getInstance().getProperty(PropertiesManager.MYSQL_DB) +
".openwhisk_serverless_compositions_main";
private static final String DROP_CLOUD_FUNCTIONS_HANDLER = "DROP TABLE IF EXISTS " +
PropertiesManager.getInstance().getProperty(PropertiesManager.MYSQL_DB) +
".google_serverless_handler_function";
private static final String DROP_LAMBDA_HANDLER = "DROP TABLE IF EXISTS " +
PropertiesManager.getInstance().getProperty(PropertiesManager.MYSQL_DB) +
".amazon_serverless_handler_function";
private static final String DROP_GOOGLE_COMPOSITION_FUNCTIONS = "DROP TABLE IF EXISTS " +
PropertiesManager.getInstance().getProperty(PropertiesManager.MYSQL_DB) +
".google_serverless_compositions_functions";
private static final String DROP_AMAZON_COMPOSITION_FUNCTIONS = "DROP TABLE IF EXISTS " +
PropertiesManager.getInstance().getProperty(PropertiesManager.MYSQL_DB) +
".amazon_serverless_compositions_functions";
private static final String DROP_OPENWHISK_COMPOSITION_FUNCTIONS = "DROP TABLE IF EXISTS " +
PropertiesManager.getInstance().getProperty(PropertiesManager.MYSQL_DB) +
".openwhisk_serverless_compositions_functions";
private static final String DROP_GOOGLE_COMPOSITION_MAIN = "DROP TABLE IF EXISTS " +
PropertiesManager.getInstance().getProperty(PropertiesManager.MYSQL_DB) +
".google_serverless_compositions_main";
private static final String DROP_AMAZON_COMPOSITION_MAIN = "DROP TABLE IF EXISTS " +
PropertiesManager.getInstance().getProperty(PropertiesManager.MYSQL_DB) +
".amazon_serverless_compositions_main";
private static final String DROP_OPENWHISK_COMPOSITION_MAIN = "DROP TABLE IF EXISTS " +
PropertiesManager.getInstance().getProperty(PropertiesManager.MYSQL_DB) +
".openwhisk_serverless_compositions_main";
/**
* Initializes tables
* @param connection database connection to use
* @param provider select which provider is needed to initialize corresponding tables
* @throws SQLException query definition and execution related problems
*/
private static void initTables(Connection connection, String provider) throws SQLException {
if (connection != null) {
initDatabase(connection);
Statement statement = connection.createStatement();
switch (provider) {
case GOOGLE:
statement.executeUpdate(CREATE_GOOGLE_COMPOSITION_CLOUD_FUNCTIONS_HANDLER);
statement.executeUpdate(CREATE_GOOGLE_COMPOSITION_TABLE_MAIN);
statement.executeUpdate(CREATE_GOOGLE_COMPOSITION_TABLE_FUNCTIONS);
break;
case AMAZON:
statement.executeUpdate(CREATE_AMAZON_COMPOSITION_LAMBDA_HANDLER);
statement.executeUpdate(CREATE_AMAZON_COMPOSITION_TABLE_MAIN);
statement.executeUpdate(CREATE_AMAZON_COMPOSITION_TABLE_FUNCTIONS);
break;
case OPENWHISK:
statement.executeUpdate(CREATE_OPENWHISK_COMPOSITION_TABLE_MAIN);
statement.executeUpdate(CREATE_OPENWHISK_COMPOSITION_TABLE_FUNCTIONS);
default:
statement.executeUpdate(CREATE_GOOGLE_COMPOSITION_CLOUD_FUNCTIONS_HANDLER);
statement.executeUpdate(CREATE_GOOGLE_COMPOSITION_TABLE_MAIN);
statement.executeUpdate(CREATE_GOOGLE_COMPOSITION_TABLE_FUNCTIONS);
statement.executeUpdate(CREATE_AMAZON_COMPOSITION_LAMBDA_HANDLER);
statement.executeUpdate(CREATE_AMAZON_COMPOSITION_TABLE_MAIN);
statement.executeUpdate(CREATE_AMAZON_COMPOSITION_TABLE_FUNCTIONS);
statement.executeUpdate(CREATE_OPENWHISK_COMPOSITION_TABLE_MAIN);
statement.executeUpdate(CREATE_OPENWHISK_COMPOSITION_TABLE_FUNCTIONS);
break;
}
statement.close();
} else {
System.err.println("Could not initialize database");
}
}
/**
* Drop every table associated to Google Cloud Platform Function Compositions
*/
public static void dropGoogle() {
dropTable(GOOGLE);
}
/**
* Drop every table associated to Amazon Web Services Function Compositions
*/
public static void dropAmazon() {
dropTable(AMAZON);
}
/**
* Drop every table associated to OpenWhisk Compositions
*/
public static void dropOpenWhisk() {
dropTable(OPENWHISK);
}
/**
* Generic drop table function
* @param provider select which provider is needed to delete corresponding tables
*/
private static void dropTable(String provider) {
try {
Connection connection = MySQLConnect.connectDatabase();
if (connection == null) {
System.err.println("Could not connect to database, please check your connection");
return;
}
Statement statement = connection.createStatement();
switch (provider) {
case GOOGLE:
statement.executeUpdate(DROP_GOOGLE_COMPOSITION_FUNCTIONS);
statement.executeUpdate(DROP_GOOGLE_COMPOSITION_MAIN);
statement.executeUpdate(DROP_CLOUD_FUNCTIONS_HANDLER);
break;
case AMAZON:
statement.executeUpdate(DROP_AMAZON_COMPOSITION_FUNCTIONS);
statement.executeUpdate(DROP_AMAZON_COMPOSITION_MAIN);
statement.executeUpdate(DROP_LAMBDA_HANDLER);
break;
case OPENWHISK:
statement.executeUpdate(DROP_OPENWHISK_COMPOSITION_FUNCTIONS);
statement.executeUpdate(DROP_OPENWHISK_COMPOSITION_MAIN);
break;
default:
System.err.println("Provider not supported! Could not perform DB drop");
}
statement.close();
MySQLConnect.closeConnection(connection);
} catch (SQLException e) {
System.err.println("Could not drop table(s): " + e.getMessage());
}
}
/**
* Persists a new Google Cloud Functions Handler (just one for DB)
* @param functionName name of the handler
* @param url url of the handler
* @param region region of deployment for the handler
*/
public static void persistGoogleHandler(String functionName, String url, String region) {
try {
Connection connection = MySQLConnect.connectDatabase();
if (connection == null) {
System.err.println("Could not connect to database, please check your connection");
return;
}
initTables(connection, GOOGLE);
PreparedStatement preparedStatement = connection.prepareStatement(INSERT_GOOGLE_HANDLER);
preparedStatement.setString(1, functionName);
preparedStatement.setString(2, url);
preparedStatement.setString(3, region);
preparedStatement.execute();
preparedStatement.close();
MySQLConnect.closeConnection(connection);
} catch (SQLException e) {
System.err.println("Could not perform insertion: " + e.getMessage());
}
}
/**
* Persists a new Amazon Lambda and API Gateway Handler (just one for DB)
* @param functionName name of the handler
* @param url url of the handler
* @param apiId id of the api associated to the handler
* @param region region of deployment for the handler
*/
public static void persistAmazonHandler(String functionName, String url, String apiId, String region) {
try {
Connection connection = MySQLConnect.connectDatabase();
if (connection == null) {
System.err.println("Could not connect to database, please check your connection");
return;
}
initTables(connection, AMAZON);
PreparedStatement preparedStatement = connection.prepareStatement(INSERT_AMAZON_HANDLER);
preparedStatement.setString(1, functionName);
preparedStatement.setString(2, url);
preparedStatement.setString(3, apiId);
preparedStatement.setString(4, region);
preparedStatement.execute();
preparedStatement.close();
MySQLConnect.closeConnection(connection);
} catch (SQLException e) {
System.err.println("Could not perform insertion: " + e.getMessage());
}
}
/**
* Persists a new Google Cloud Platform workflow and associated functions
* @param workflowName name of the workflow
* @param workflowRegion workflow region of deployment
* @param functionNames names of functions (consistent ordering)
* @param functionRegions regions of function deployments (consistent ordering)
*/
public static void persistGoogle(String workflowName, String workflowRegion, String[] functionNames,
String[] functionRegions) {
assert functionNames.length == functionRegions.length;
try {
Connection connection = MySQLConnect.connectDatabase();
if (connection == null) {
System.err.println("Could not connect to database, please check your connection");
return;
}
initTables(connection, GOOGLE);
PreparedStatement preparedStatement = connection.prepareStatement(INSERT_GOOGLE_COMPOSITION_MAIN);
preparedStatement.setString(1, workflowName);
preparedStatement.setString(2, workflowRegion);
preparedStatement.execute();
preparedStatement.close();
preparedStatement = connection.prepareStatement(INSERT_GOOGLE_COMPOSITION_FUNCTION);
for (int i = 0; i < functionNames.length; i++) {
preparedStatement.setString(1, functionNames[i]);
preparedStatement.setString(2, functionRegions[i]);
preparedStatement.setString(3, workflowName);
preparedStatement.addBatch();
}
preparedStatement.executeBatch();
preparedStatement.close();
MySQLConnect.closeConnection(connection);
} catch (SQLException e) {
System.err.println("Could not perform insertion: " + e.getMessage());
}
}
/**
* Persists a new Amazon Web Services state machine and associated functions
* @param machineName name of the state machine
* @param machineArn ARN of the state machine
* @param machineRegion state machine region of deployment
* @param functionNames names of functions (consistent ordering)
* @param functionRegions regions of function deployments (consistent ordering)
*/
public static void persistAmazon(String machineName, String machineArn, String machineRegion,
String[] functionNames, String[] functionRegions) {
assert functionNames.length == functionRegions.length;
try {
Connection connection = MySQLConnect.connectDatabase();
if (connection == null) {
System.err.println("Could not connect to database, please check your connection");
return;
}
initTables(connection, AMAZON);
PreparedStatement preparedStatement = connection.prepareStatement(INSERT_AMAZON_COMPOSITION_MAIN);
preparedStatement.setString(1, machineName);
preparedStatement.setString(2, machineArn);
preparedStatement.setString(3, machineRegion);
preparedStatement.execute();
preparedStatement.close();
preparedStatement = connection.prepareStatement(INSERT_AMAZON_COMPOSITION_FUNCTION);
for (int i = 0; i < functionNames.length; i++) {
preparedStatement.setString(1, functionNames[i]);
preparedStatement.setString(2, functionRegions[i]);
preparedStatement.setString(3, machineArn);
preparedStatement.addBatch();
}
preparedStatement.executeBatch();
preparedStatement.close();
MySQLConnect.closeConnection(connection);
} catch (SQLException e) {
System.err.println("Could not perform insertion: " + e.getMessage());
}
}
/**
* Persists a new OpenWhisk composition and associated functions
* @param compositionName name of the composition
* @param url url of the composition
* @param functionNames names of functions
*/
public static void persistOpenWhisk(String compositionName, String url, String[] functionNames) {
try {
Connection connection = MySQLConnect.connectDatabase();
if (connection == null) {
System.err.println("Could not connect to database, please check your connection");
return;
}
initTables(connection, OPENWHISK);
PreparedStatement preparedStatement = connection.prepareStatement(INSERT_OPENWHISK_COMPOSITION_MAIN);
preparedStatement.setString(1, compositionName);
preparedStatement.setString(2, url);
preparedStatement.execute();
preparedStatement.close();
preparedStatement = connection.prepareStatement(INSERT_OPENWHISK_COMPOSITION_FUNCTION);
for (String functionName : functionNames) {
preparedStatement.setString(1, functionName);
preparedStatement.setString(2, compositionName);
preparedStatement.addBatch();
}
preparedStatement.executeBatch();
preparedStatement.close();
MySQLConnect.closeConnection(connection);
} catch (SQLException e) {
System.err.println("Could not perform insertion: " + e.getMessage());
}
}
/**
* Checks whether an handler for Google Workflows [BETA] already exists
* @param openedConnection opened connection to database (or null)
* @return true if the handler exists, false elsewhere
*/
public static boolean existsGoogleHandler(@Nullable Connection openedConnection) {
try {
Connection connection;
if (openedConnection != null && !openedConnection.isClosed()) {
connection = openedConnection;
} else {
connection = MySQLConnect.connectDatabase();
}
if (connection == null) {
System.err.println("Could not connect to database, please check your connection");
return false;
}
initTables(connection, GOOGLE);
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(SELECT_GOOGLE_HANDLER_INFO);
boolean result = resultSet.next();
statement.close();
resultSet.close();
if (openedConnection == null) {
MySQLConnect.closeConnection(connection);
}
return result;
} catch (SQLException e) {
System.err.println("Could not perform select: " + e.getMessage());
return false;
}
}
/**
* Checks whether an handler for Amazon Step Functions already exists
* @param openedConnection opened connection to database (or null)
* @return true if the handler exists, false elsewhere
*/
public static boolean existsAmazonHandler(@Nullable Connection openedConnection) {
try {
Connection connection;
if (openedConnection != null && !openedConnection.isClosed()) {
connection = openedConnection;
} else {
connection = MySQLConnect.connectDatabase();
}
if (connection == null) {
System.err.println("Could not connect to database, please check your connection");
return false;
}
initTables(connection, AMAZON);
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(SELECT_AMAZON_HANDLER_INFO);
boolean result = resultSet.next();
statement.close();
resultSet.close();
if (openedConnection == null) {
MySQLConnect.closeConnection(connection);
}
return result;
} catch (SQLException e) {
System.err.println("Could not perform select: " + e.getMessage());
return false;
}
}
/**
* Getter for Google Workflows [BETA] handler
* @return CloudEntityData containing handler info
*/
public static CloudEntityData getGoogleHandlerInfo() {
try {
Connection connection = MySQLConnect.connectDatabase();
if (connection == null) {
System.err.println("Could not connect to database, please check your connection");
return null;
}
initTables(connection, GOOGLE);
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(SELECT_GOOGLE_HANDLER_INFO);
// function name and region
CloudEntityData result = null;
if (resultSet.next()) {
result = new CloudEntityData(resultSet.getString("function_name"),
resultSet.getString("region"));
}
statement.close();
resultSet.close();
MySQLConnect.closeConnection(connection);
return result;
} catch (SQLException e) {
System.err.println("Could not perform select: " + e.getMessage());
return null;
}
}
/**
* Getter for Amazon Step Functions handler
* @return CloudEntityData containing handler info
*/
public static CloudEntityData getAmazonHandlerInfo() {
try {
Connection connection = MySQLConnect.connectDatabase();
if (connection == null) {
System.err.println("Could not connect to database, please check your connection");
return null;
}
initTables(connection, AMAZON);
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(SELECT_AMAZON_HANDLER_INFO);
// function name, region and api id
CloudEntityData result = null;
if (resultSet.next()) {
result = new CloudEntityData(resultSet.getString("function_name"),
resultSet.getString("region"), resultSet.getString("api_id"));
}
statement.close();
resultSet.close();
MySQLConnect.closeConnection(connection);
return result;
} catch (SQLException e) {
System.err.println("Could not perform select: " + e.getMessage());
return null;
}
}
/**
* Getter for every workflow associated Google Cloud Functions function
* @return list of CloudEntityData with function information
*/
public static List<CloudEntityData> getGoogleFunctionInfos() {
try {
Connection connection = MySQLConnect.connectDatabase();
if (connection == null) {
System.err.println("Could not connect to database, please check your connection");
return null;
}
initTables(connection, GOOGLE);
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(SELECT_GOOGLE_FUNCTION_INFOS);
List<CloudEntityData> result = new ArrayList<>();
// function_name, function_region
while (resultSet.next()) {
result.add(new CloudEntityData(resultSet.getString("function_name"),
resultSet.getString("function_region"), null));
}
statement.close();
resultSet.close();
MySQLConnect.closeConnection(connection);
return result;
} catch (SQLException e) {
System.err.println("Could not perform select: " + e.getMessage());
return null;
}
}
/**
* Getter for every state machine associated Amazon Lambda function
* @return list of CloudEntityData with function information
*/
public static List<CloudEntityData> getAmazonFunctionInfos() {
try {
Connection connection = MySQLConnect.connectDatabase();
if (connection == null) {
System.err.println("Could not connect to database, please check your connection");
return null;
}
initTables(connection, AMAZON);
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(SELECT_AMAZON_FUNCTION_INFOS);
List<CloudEntityData> result = new ArrayList<>();
// function_name, function_region
while (resultSet.next()) {
result.add(new CloudEntityData(resultSet.getString("function_name"),
resultSet.getString("function_region"), null));
}
statement.close();
resultSet.close();
MySQLConnect.closeConnection(connection);
return result;
} catch (SQLException e) {
System.err.println("Could not perform select: " + e.getMessage());
return null;
}
}
/**
* Getter for every composition associated OpenWhisk function
* @return list of CloudEntityData with function information
*/
public static List<CloudEntityData> getOpenWhiskFunctionInfos() {
try {
Connection connection = MySQLConnect.connectDatabase();
if (connection == null) {
System.err.println("Could not connect to database, please check your connection");
return null;
}
initTables(connection, OPENWHISK);
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(SELECT_OPENWHISK_FUNCTION_INFOS);
List<CloudEntityData> result = new ArrayList<>();
// function_name, function_region
while (resultSet.next()) {
result.add(new CloudEntityData(resultSet.getString("function_name")));
}
statement.close();
resultSet.close();
MySQLConnect.closeConnection(connection);
return result;
} catch (SQLException e) {
System.err.println("Could not perform select: " + e.getMessage());
return null;
}
}
/**
* Getter for every Google Cloud Platform Workflows [BETA] workflow
* @return list of CloudEntityData with workflow information
*/
public static List<CloudEntityData> getGoogleWorkflowInfos() {
try {
Connection connection = MySQLConnect.connectDatabase();
if (connection == null) {
System.err.println("Could not connect to database, please check your connection");
return null;
}
initTables(connection, GOOGLE);
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(SELECT_GOOGLE_WORKFLOW_INFOS);
List<CloudEntityData> result = new ArrayList<>();
while (resultSet.next()) {
result.add(new CloudEntityData(resultSet.getString("workflow_name"),
resultSet.getString("workflow_region")));
}
statement.close();
resultSet.close();
MySQLConnect.closeConnection(connection);
return result;
} catch (SQLException e) {
System.err.println("Could not perform select: " + e.getMessage());
return null;
}
}
/**
* Getter for every AWS Step Functions state machine
* @return list of CloudEntityData with state machine information
*/
public static List<CloudEntityData> getAmazonMachineInfos() {
try {
Connection connection = MySQLConnect.connectDatabase();
if (connection == null) {
System.err.println("Could not connect to database, please check your connection");
return null;
}
initTables(connection, AMAZON);
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(SELECT_AMAZON_MACHINE_INFOS);
List<CloudEntityData> result = new ArrayList<>();
while (resultSet.next()) {
result.add(new CloudEntityData(resultSet.getString("machine_name"),
resultSet.getString("machine_region"),
resultSet.getString("machine_arn")));
}
statement.close();
resultSet.close();
MySQLConnect.closeConnection(connection);
return result;
} catch (SQLException e) {
System.err.println("Could not perform select: " + e.getMessage());
return null;
}
}
/**
* Getter for every OpenWhisk composition
* @return list of CloudEntityData with composition information
*/
public static List<CloudEntityData> getOpenWhiskCompositionInfos() {
try {
Connection connection = MySQLConnect.connectDatabase();
if (connection == null) {
System.err.println("Could not connect to database, please check your connection");
return null;
}
initTables(connection, OPENWHISK);
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(SELECT_OPENWHISK_COMPOSITION_NAMES);
List<CloudEntityData> result = new ArrayList<>();
while (resultSet.next()) {
result.add(new CloudEntityData(resultSet.getString("composition_name")));
}
statement.close();
resultSet.close();
MySQLConnect.closeConnection(connection);
return result;
} catch (SQLException e) {
System.err.println("Could not perform select: " + e.getMessage());
return null;
}
}
/**
* Getter for Google Workflows [BETA] handler url
* @param openedConnection opened connection to database (or null)
* @return url as string
*/
public static String getGoogleHandlerUrl(@Nullable Connection openedConnection) {
try {
Connection connection;
if (openedConnection != null && !openedConnection.isClosed()) {
connection = openedConnection;
} else {
connection = MySQLConnect.connectDatabase();
}
if (connection == null) {
System.err.println("Could not connect to database, please check your connection");
return null;
}
initTables(connection, GOOGLE);
if (!existsGoogleHandler(connection)) {
System.err.println("Google handler not found");
return null;
}
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(SELECT_GOOGLE_HANDLER_URL);
resultSet.next();
String result = resultSet.getString("url");
resultSet.close();
statement.close();
if (openedConnection == null) {
MySQLConnect.closeConnection(connection);
}
return result;
} catch (SQLException e) {
System.err.println("Could not perform select: " + e.getMessage());
return null;
}
}
/**
* Getter for Amazon Step Functions handler url
* @param openedConnection opened connection to database (or null)
* @return url as string
*/
public static String getAmazonHandlerUrl(@Nullable Connection openedConnection) {
try {
Connection connection;
if (openedConnection != null && !openedConnection.isClosed()) {
connection = openedConnection;
} else {
connection = MySQLConnect.connectDatabase();
}
if (connection == null) {
System.err.println("Could not connect to database, please check your connection");
return null;
}
initTables(connection, AMAZON);
if (!existsAmazonHandler(connection)) {
System.err.println("Amazon handler not found");
return null;
}
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(SELECT_AMAZON_HANDLER_URL);
resultSet.next();
String result = resultSet.getString("url");
resultSet.close();
statement.close();
if (openedConnection == null) {
MySQLConnect.closeConnection(connection);
}
return result;
} catch (SQLException e) {
System.err.println("Could not perform select: " + e.getMessage());
return null;
}
}
/**
* List every composition url, there can be one or more URL per composition basing on different provider
* implementation of the same one
* @return list of composition urls (FunctionalityURL)
*/
public static List<FunctionalityURL> getUrls() {
try {
Connection connection = MySQLConnect.connectDatabase();
if (connection == null) {
System.err.println("Could not connect to database, please check your connection");
return null;
}
initTables(connection, "*");
HashMap<String, FunctionalityURL> dynamicResult = new HashMap<>();
String name;
String url;
FunctionalityURL functionalityURL;
Statement statement;
ResultSet resultSet;
String googlePreamble = getGoogleHandlerUrl(connection);
if (googlePreamble == null) {
System.err.println("Could not build Google composition urls, handler not found!");
} else {
// if google handler exists
googlePreamble = googlePreamble + "?workflow=";
statement = connection.createStatement();
resultSet = statement.executeQuery(SELECT_GOOGLE_WORKFLOWS_NAMES);
while (resultSet.next()) {
name = resultSet.getString("workflow_name");
url = googlePreamble + name;
if (dynamicResult.containsKey(name)) {
dynamicResult.get(name).setGoogleUrl(url);
} else {