forked from AnythingLinux/cloudstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabaseConfig.java
More file actions
executable file
·1435 lines (1277 loc) · 66.9 KB
/
DatabaseConfig.java
File metadata and controls
executable file
·1435 lines (1277 loc) · 66.9 KB
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
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you 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.
package com.cloud.test;
import java.io.File;
import java.io.IOException;
import java.math.BigInteger;
import java.net.URISyntaxException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import com.cloud.host.Status;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.service.dao.ServiceOfferingDaoImpl;
import com.cloud.storage.DiskOfferingVO;
import com.cloud.storage.dao.DiskOfferingDaoImpl;
import com.cloud.utils.PropertiesUtil;
import com.cloud.utils.component.ComponentContext;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.Transaction;
import com.cloud.utils.net.NfsUtils;
public class DatabaseConfig {
private static final Logger s_logger = Logger.getLogger(DatabaseConfig.class.getName());
private String _configFileName = null;
private String _currentObjectName = null;
private String _currentFieldName = null;
private Map<String, String> _currentObjectParams = null;
private static Map<String, String> s_configurationDescriptions = new HashMap<String, String>();
private static Map<String, String> s_configurationComponents = new HashMap<String, String>();
private static Map<String, String> s_defaultConfigurationValues = new HashMap<String, String>();
// Change to HashSet
private static HashSet<String> objectNames = new HashSet<String>();
private static HashSet<String> fieldNames = new HashSet<String>();
// Maintain an IPRangeConfig object to handle IP related logic
private final IPRangeConfig iprc = ComponentContext.inject(IPRangeConfig.class);
// Maintain a PodZoneConfig object to handle Pod/Zone related logic
private final PodZoneConfig pzc = ComponentContext.inject(PodZoneConfig.class);
// Global variables to store network.throttling.rate and multicast.throttling.rate from the configuration table
// Will be changed from null to a non-null value if the value existed in the configuration table
private String _networkThrottlingRate = null;
private String _multicastThrottlingRate = null;
static {
// initialize the objectNames ArrayList
objectNames.add("zone");
objectNames.add("physicalNetwork");
objectNames.add("vlan");
objectNames.add("pod");
objectNames.add("cluster");
objectNames.add("storagePool");
objectNames.add("secondaryStorage");
objectNames.add("serviceOffering");
objectNames.add("diskOffering");
objectNames.add("user");
objectNames.add("pricing");
objectNames.add("configuration");
objectNames.add("privateIpAddresses");
objectNames.add("publicIpAddresses");
objectNames.add("physicalNetworkServiceProvider");
objectNames.add("virtualRouterProvider");
// initialize the fieldNames ArrayList
fieldNames.add("id");
fieldNames.add("name");
fieldNames.add("dns1");
fieldNames.add("dns2");
fieldNames.add("internalDns1");
fieldNames.add("internalDns2");
fieldNames.add("guestNetworkCidr");
fieldNames.add("gateway");
fieldNames.add("netmask");
fieldNames.add("vncConsoleIp");
fieldNames.add("zoneId");
fieldNames.add("vlanId");
fieldNames.add("cpu");
fieldNames.add("ramSize");
fieldNames.add("speed");
fieldNames.add("useLocalStorage");
fieldNames.add("hypervisorType");
fieldNames.add("diskSpace");
fieldNames.add("nwRate");
fieldNames.add("mcRate");
fieldNames.add("price");
fieldNames.add("username");
fieldNames.add("password");
fieldNames.add("firstname");
fieldNames.add("lastname");
fieldNames.add("email");
fieldNames.add("priceUnit");
fieldNames.add("type");
fieldNames.add("value");
fieldNames.add("podId");
fieldNames.add("podName");
fieldNames.add("ipAddressRange");
fieldNames.add("vlanType");
fieldNames.add("vlanName");
fieldNames.add("cidr");
fieldNames.add("vnet");
fieldNames.add("mirrored");
fieldNames.add("enableHA");
fieldNames.add("displayText");
fieldNames.add("domainId");
fieldNames.add("hostAddress");
fieldNames.add("hostPath");
fieldNames.add("guestIpType");
fieldNames.add("url");
fieldNames.add("storageType");
fieldNames.add("category");
fieldNames.add("tags");
fieldNames.add("networktype");
fieldNames.add("clusterId");
fieldNames.add("physicalNetworkId");
fieldNames.add("destPhysicalNetworkId");
fieldNames.add("providerName");
fieldNames.add("vpn");
fieldNames.add("dhcp");
fieldNames.add("dns");
fieldNames.add("firewall");
fieldNames.add("sourceNat");
fieldNames.add("loadBalance");
fieldNames.add("staticNat");
fieldNames.add("portForwarding");
fieldNames.add("userData");
fieldNames.add("securityGroup");
fieldNames.add("nspId");
s_configurationDescriptions.put("host.stats.interval", "the interval in milliseconds when host stats are retrieved from agents");
s_configurationDescriptions.put("storage.stats.interval", "the interval in milliseconds when storage stats (per host) are retrieved from agents");
s_configurationDescriptions.put("volume.stats.interval", "the interval in milliseconds when volume stats are retrieved from agents");
s_configurationDescriptions.put("host", "host address to listen on for agent connection");
s_configurationDescriptions.put("port", "port to listen on for agent connection");
s_configurationDescriptions.put("guest.domain.suffix", "domain suffix for users");
s_configurationDescriptions.put("instance.name", "Name of the deployment instance");
s_configurationDescriptions.put("storage.overprovisioning.factor", "Storage Allocator overprovisioning factor");
s_configurationDescriptions.put("retries.per.host", "The number of times each command sent to a host should be retried in case of failure.");
s_configurationDescriptions.put("integration.api.port", "internal port used by the management server for servicing Integration API requests");
s_configurationDescriptions.put("usage.stats.job.exec.time", "the time at which the usage statistics aggregation job will run as an HH24:MM time, e.g. 00:30 to run at 12:30am");
s_configurationDescriptions.put("usage.stats.job.aggregation.range", "the range of time for aggregating the user statistics specified in minutes (e.g. 1440 for daily, 60 for hourly)");
s_configurationDescriptions.put("consoleproxy.domP.enable", "Obsolete");
s_configurationDescriptions.put("consoleproxy.port", "Obsolete");
s_configurationDescriptions.put("consoleproxy.url.port", "Console proxy port for AJAX viewer");
s_configurationDescriptions.put("consoleproxy.ram.size", "RAM size (in MB) used to create new console proxy VMs");
s_configurationDescriptions.put("consoleproxy.cmd.port", "Console proxy command port that is used to communicate with management server");
s_configurationDescriptions.put("consoleproxy.loadscan.interval", "The time interval(in milliseconds) to scan console proxy working-load info");
s_configurationDescriptions.put("consoleproxy.capacityscan.interval", "The time interval(in millisecond) to scan whether or not system needs more console proxy to ensure minimal standby capacity");
s_configurationDescriptions.put("consoleproxy.capacity.standby", "The minimal number of console proxy viewer sessions that system is able to serve immediately(standby capacity)");
s_configurationDescriptions.put("alert.email.addresses", "comma seperated list of email addresses used for sending alerts");
s_configurationDescriptions.put("alert.smtp.host", "SMTP hostname used for sending out email alerts");
s_configurationDescriptions.put("alert.smtp.port", "port the SMTP server is listening on (default is 25)");
s_configurationDescriptions.put("alert.smtp.useAuth", "If true, use SMTP authentication when sending emails. If false, do not use SMTP authentication when sending emails.");
s_configurationDescriptions.put("alert.smtp.username", "username for SMTP authentication (applies only if alert.smtp.useAuth is true)");
s_configurationDescriptions.put("alert.smtp.password", "password for SMTP authentication (applies only if alert.smtp.useAuth is true)");
s_configurationDescriptions.put("alert.email.sender", "sender of alert email (will be in the From header of the email)");
s_configurationDescriptions.put("memory.capacity.threshold", "percentage (as a value between 0 and 1) of memory utilization above which alerts will be sent about low memory available");
s_configurationDescriptions.put("cpu.capacity.threshold", "percentage (as a value between 0 and 1) of cpu utilization above which alerts will be sent about low cpu available");
s_configurationDescriptions.put("storage.capacity.threshold", "percentage (as a value between 0 and 1) of storage utilization above which alerts will be sent about low storage available");
s_configurationDescriptions.put("public.ip.capacity.threshold", "percentage (as a value between 0 and 1) of public IP address space utilization above which alerts will be sent");
s_configurationDescriptions.put("private.ip.capacity.threshold", "percentage (as a value between 0 and 1) of private IP address space utilization above which alerts will be sent");
s_configurationDescriptions.put("expunge.interval", "the interval to wait before running the expunge thread");
s_configurationDescriptions.put("network.throttling.rate", "default data transfer rate in megabits per second allowed per user");
s_configurationDescriptions.put("multicast.throttling.rate", "default multicast rate in megabits per second allowed");
s_configurationDescriptions.put("system.vm.use.local.storage", "Indicates whether to use local storage pools or shared storage pools for system VMs.");
s_configurationDescriptions.put("snapshot.poll.interval", "The time interval in seconds when the management server polls for snapshots to be scheduled.");
s_configurationDescriptions.put("snapshot.max.hourly", "Maximum hourly snapshots for a volume");
s_configurationDescriptions.put("snapshot.max.daily", "Maximum daily snapshots for a volume");
s_configurationDescriptions.put("snapshot.max.weekly", "Maximum weekly snapshots for a volume");
s_configurationDescriptions.put("snapshot.max.monthly", "Maximum monthly snapshots for a volume");
s_configurationDescriptions.put("snapshot.delta.max", "max delta snapshots between two full snapshots.");
s_configurationDescriptions.put("snapshot.recurring.test", "Flag for testing recurring snapshots");
s_configurationDescriptions.put("snapshot.test.minutes.per.hour", "Set it to a smaller value to take more recurring snapshots");
s_configurationDescriptions.put("snapshot.test.hours.per.day", "Set it to a smaller value to take more recurring snapshots");
s_configurationDescriptions.put("snapshot.test.days.per.week", "Set it to a smaller value to take more recurring snapshots");
s_configurationDescriptions.put("snapshot.test.days.per.month", "Set it to a smaller value to take more recurring snapshots");
s_configurationDescriptions.put("snapshot.test.weeks.per.month", "Set it to a smaller value to take more recurring snapshots");
s_configurationDescriptions.put("snapshot.test.months.per.year", "Set it to a smaller value to take more recurring snapshots");
s_configurationDescriptions.put("hypervisor.type", "The type of hypervisor that this deployment will use.");
s_configurationComponents.put("host.stats.interval", "management-server");
s_configurationComponents.put("storage.stats.interval", "management-server");
s_configurationComponents.put("volume.stats.interval", "management-server");
s_configurationComponents.put("integration.api.port", "management-server");
s_configurationComponents.put("usage.stats.job.exec.time", "management-server");
s_configurationComponents.put("usage.stats.job.aggregation.range", "management-server");
s_configurationComponents.put("consoleproxy.domP.enable", "management-server");
s_configurationComponents.put("consoleproxy.port", "management-server");
s_configurationComponents.put("consoleproxy.url.port", "management-server");
s_configurationComponents.put("alert.email.addresses", "management-server");
s_configurationComponents.put("alert.smtp.host", "management-server");
s_configurationComponents.put("alert.smtp.port", "management-server");
s_configurationComponents.put("alert.smtp.useAuth", "management-server");
s_configurationComponents.put("alert.smtp.username", "management-server");
s_configurationComponents.put("alert.smtp.password", "management-server");
s_configurationComponents.put("alert.email.sender", "management-server");
s_configurationComponents.put("memory.capacity.threshold", "management-server");
s_configurationComponents.put("cpu.capacity.threshold", "management-server");
s_configurationComponents.put("storage.capacity.threshold", "management-server");
s_configurationComponents.put("public.ip.capacity.threshold", "management-server");
s_configurationComponents.put("private.ip.capacity.threshold", "management-server");
s_configurationComponents.put("capacity.check.period", "management-server");
s_configurationComponents.put("network.throttling.rate", "management-server");
s_configurationComponents.put("multicast.throttling.rate", "management-server");
s_configurationComponents.put("event.purge.interval", "management-server");
s_configurationComponents.put("account.cleanup.interval", "management-server");
s_configurationComponents.put("expunge.delay", "UserVmManager");
s_configurationComponents.put("expunge.interval", "UserVmManager");
s_configurationComponents.put("host", "AgentManager");
s_configurationComponents.put("port", "AgentManager");
s_configurationComponents.put("domain", "AgentManager");
s_configurationComponents.put("instance.name", "AgentManager");
s_configurationComponents.put("storage.overprovisioning.factor", "StorageAllocator");
s_configurationComponents.put("retries.per.host", "AgentManager");
s_configurationComponents.put("start.retry", "AgentManager");
s_configurationComponents.put("wait", "AgentManager");
s_configurationComponents.put("ping.timeout", "AgentManager");
s_configurationComponents.put("ping.interval", "AgentManager");
s_configurationComponents.put("alert.wait", "AgentManager");
s_configurationComponents.put("update.wait", "AgentManager");
s_configurationComponents.put("guest.domain.suffix", "AgentManager");
s_configurationComponents.put("consoleproxy.ram.size", "AgentManager");
s_configurationComponents.put("consoleproxy.cmd.port", "AgentManager");
s_configurationComponents.put("consoleproxy.loadscan.interval", "AgentManager");
s_configurationComponents.put("consoleproxy.capacityscan.interval", "AgentManager");
s_configurationComponents.put("consoleproxy.capacity.standby", "AgentManager");
s_configurationComponents.put("consoleproxy.session.max", "AgentManager");
s_configurationComponents.put("consoleproxy.session.timeout", "AgentManager");
s_configurationComponents.put("expunge.workers", "UserVmManager");
s_configurationComponents.put("extract.url.cleanup.interval", "management-server");
s_configurationComponents.put("stop.retry.interval", "HighAvailabilityManager");
s_configurationComponents.put("restart.retry.interval", "HighAvailabilityManager");
s_configurationComponents.put("investigate.retry.interval", "HighAvailabilityManager");
s_configurationComponents.put("migrate.retry.interval", "HighAvailabilityManager");
s_configurationComponents.put("storage.overwrite.provisioning", "UserVmManager");
s_configurationComponents.put("init", "none");
s_configurationComponents.put("system.vm.use.local.storage", "ManagementServer");
s_configurationComponents.put("snapshot.poll.interval", "SnapshotManager");
s_configurationComponents.put("snapshot.max.hourly", "SnapshotManager");
s_configurationComponents.put("snapshot.max.daily", "SnapshotManager");
s_configurationComponents.put("snapshot.max.weekly", "SnapshotManager");
s_configurationComponents.put("snapshot.max.monthly", "SnapshotManager");
s_configurationComponents.put("snapshot.delta.max", "SnapshotManager");
s_configurationComponents.put("snapshot.recurring.test", "SnapshotManager");
s_configurationComponents.put("snapshot.test.minutes.per.hour", "SnapshotManager");
s_configurationComponents.put("snapshot.test.hours.per.day", "SnapshotManager");
s_configurationComponents.put("snapshot.test.days.per.week", "SnapshotManager");
s_configurationComponents.put("snapshot.test.days.per.month", "SnapshotManager");
s_configurationComponents.put("snapshot.test.weeks.per.month", "SnapshotManager");
s_configurationComponents.put("snapshot.test.months.per.year", "SnapshotManager");
s_configurationComponents.put("hypervisor.type", "ManagementServer");
s_defaultConfigurationValues.put("host.stats.interval", "60000");
s_defaultConfigurationValues.put("storage.stats.interval", "60000");
//s_defaultConfigurationValues.put("volume.stats.interval", "-1");
s_defaultConfigurationValues.put("port", "8250");
s_defaultConfigurationValues.put("integration.api.port", "8096");
s_defaultConfigurationValues.put("usage.stats.job.exec.time", "00:15"); // run at 12:15am
s_defaultConfigurationValues.put("usage.stats.job.aggregation.range", "1440"); // do a daily aggregation
s_defaultConfigurationValues.put("storage.overprovisioning.factor", "2");
s_defaultConfigurationValues.put("retries.per.host", "2");
s_defaultConfigurationValues.put("ping.timeout", "2.5");
s_defaultConfigurationValues.put("ping.interval", "60");
s_defaultConfigurationValues.put("snapshot.poll.interval", "300");
s_defaultConfigurationValues.put("snapshot.max.hourly", "8");
s_defaultConfigurationValues.put("snapshot.max.daily", "8");
s_defaultConfigurationValues.put("snapshot.max.weekly", "8");
s_defaultConfigurationValues.put("snapshot.max.monthly", "8");
s_defaultConfigurationValues.put("snapshot.delta.max", "16");
s_defaultConfigurationValues.put("snapshot.recurring.test", "false");
s_defaultConfigurationValues.put("snapshot.test.minutes.per.hour", "60");
s_defaultConfigurationValues.put("snapshot.test.hours.per.day", "24");
s_defaultConfigurationValues.put("snapshot.test.days.per.week", "7");
s_defaultConfigurationValues.put("snapshot.test.days.per.month", "30");
s_defaultConfigurationValues.put("snapshot.test.weeks.per.month", "4");
s_defaultConfigurationValues.put("snapshot.test.months.per.year", "12");
s_defaultConfigurationValues.put("alert.wait", "1800");
s_defaultConfigurationValues.put("update.wait", "600");
s_defaultConfigurationValues.put("expunge.interval", "86400");
s_defaultConfigurationValues.put("extract.url.cleanup.interval", "120");
s_defaultConfigurationValues.put("instance.name", "VM");
s_defaultConfigurationValues.put("expunge.workers", "1");
s_defaultConfigurationValues.put("stop.retry.interval", "600");
s_defaultConfigurationValues.put("restart.retry.interval", "600");
s_defaultConfigurationValues.put("investigate.retry.interval", "60");
s_defaultConfigurationValues.put("migrate.retry.interval", "120");
s_defaultConfigurationValues.put("event.purge.interval", "86400");
s_defaultConfigurationValues.put("account.cleanup.interval", "86400");
s_defaultConfigurationValues.put("system.vm.use.local.storage", "false");
s_defaultConfigurationValues.put("init", "false");
s_defaultConfigurationValues.put("cpu.overprovisioning.factor", "1");
s_defaultConfigurationValues.put("mem.overprovisioning.factor", "1");
}
protected DatabaseConfig() {
}
/**
* @param args - name of server-setup.xml file which contains the bootstrap data
*/
public static void main(String[] args) {
System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
System.setProperty("javax.xml.parsers.SAXParserFactory", "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl");
File file = PropertiesUtil.findConfigFile("log4j-cloud.xml");
if(file != null) {
System.out.println("Log4j configuration from : " + file.getAbsolutePath());
DOMConfigurator.configureAndWatch(file.getAbsolutePath(), 10000);
} else {
System.out.println("Configure log4j with default properties");
}
if (args.length < 1) {
s_logger.error("error starting database config, missing initial data file");
} else {
try {
DatabaseConfig config = ComponentContext.inject(DatabaseConfig.class);
config.doVersionCheck();
config.doConfig();
System.exit(0);
} catch (Exception ex) {
System.out.print("Error Caught");
ex.printStackTrace();
s_logger.error("error", ex);
}
}
}
public DatabaseConfig(String configFileName) {
_configFileName = configFileName;
}
private void doVersionCheck() {
try {
String warningMsg = "\nYou are using an outdated format for server-setup.xml. Please switch to the new format.\n";
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder dbuilder = dbf.newDocumentBuilder();
File configFile = new File(_configFileName);
Document d = dbuilder.parse(configFile);
NodeList nodeList = d.getElementsByTagName("version");
if (nodeList.getLength() == 0) {
System.out.println(warningMsg);
return;
}
Node firstNode = nodeList.item(0);
String version = firstNode.getTextContent();
if (!version.equals("2.0")) {
System.out.println(warningMsg);
}
} catch (ParserConfigurationException parserException) {
parserException.printStackTrace();
} catch (IOException ioException) {
ioException.printStackTrace();
} catch (SAXException saxException) {
saxException.printStackTrace();
}
}
@DB
protected void doConfig() {
Transaction txn = Transaction.currentTxn();
try {
File configFile = new File(_configFileName);
SAXParserFactory spfactory = SAXParserFactory.newInstance();
SAXParser saxParser = spfactory.newSAXParser();
DbConfigXMLHandler handler = new DbConfigXMLHandler();
handler.setParent(this);
txn.start();
// Save user configured values for all fields
saxParser.parse(configFile, handler);
// Save default values for configuration fields
saveVMTemplate();
saveRootDomain();
saveDefaultConfiguations();
txn.commit();
// Check pod CIDRs against each other, and against the guest ip network/netmask
pzc.checkAllPodCidrSubnets();
} catch (Exception ex) {
System.out.print("ERROR IS"+ex);
s_logger.error("error", ex);
txn.rollback();
}
}
private void setCurrentObjectName(String name) {
_currentObjectName = name;
}
private void saveCurrentObject() {
if ("zone".equals(_currentObjectName)) {
saveZone();
} else if ("physicalNetwork".equals(_currentObjectName)) {
savePhysicalNetwork();
} else if ("vlan".equals(_currentObjectName)) {
saveVlan();
} else if ("pod".equals(_currentObjectName)) {
savePod();
} else if ("serviceOffering".equals(_currentObjectName)) {
saveServiceOffering();
} else if ("diskOffering".equals(_currentObjectName)) {
saveDiskOffering();
} else if ("user".equals(_currentObjectName)) {
saveUser();
} else if ("configuration".equals(_currentObjectName)) {
saveConfiguration();
} else if ("storagePool".equals(_currentObjectName)) {
saveStoragePool();
} else if ("secondaryStorage".equals(_currentObjectName)) {
saveSecondaryStorage();
} else if ("cluster".equals(_currentObjectName)) {
saveCluster();
} else if ("physicalNetworkServiceProvider".equals(_currentObjectName)) {
savePhysicalNetworkServiceProvider();
} else if ("virtualRouterProvider".equals(_currentObjectName)) {
saveVirtualRouterProvider();
}
_currentObjectParams = null;
}
@DB
public void saveSecondaryStorage() {
long dataCenterId = Long.parseLong(_currentObjectParams.get("zoneId"));
String url = _currentObjectParams.get("url");
String mountPoint;
try {
mountPoint = NfsUtils.url2Mount(url);
} catch (URISyntaxException e1) {
return;
}
String insertSql1 = "INSERT INTO `host` (`id`, `name`, `status` , `type` , `private_ip_address`, `private_netmask` ,`private_mac_address` , `storage_ip_address` ,`storage_netmask`, `storage_mac_address`, `data_center_id`, `version`, `dom0_memory`, `last_ping`, `resource`, `guid`, `hypervisor_type`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
String insertSqlHostDetails = "INSERT INTO `host_details` (`id`, `host_id`, `name`, `value`) VALUES(?,?,?,?)";
String insertSql2 = "INSERT INTO `op_host` (`id`, `sequence`) VALUES(?, ?)";
Transaction txn = Transaction.currentTxn();
try {
PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql1);
stmt.setLong(1, 0);
stmt.setString(2, url);
stmt.setString(3, "UP");
stmt.setString(4, "SecondaryStorage");
stmt.setString(5, "192.168.122.1");
stmt.setString(6, "255.255.255.0");
stmt.setString(7, "92:ff:f5:ad:23:e1");
stmt.setString(8, "192.168.122.1");
stmt.setString(9, "255.255.255.0");
stmt.setString(10, "92:ff:f5:ad:23:e1");
stmt.setLong(11, dataCenterId);
stmt.setString(12, "2.2.4");
stmt.setLong(13, 0);
stmt.setLong(14, 1238425896);
boolean nfs = false;
if (url.startsWith("nfs")) {
nfs = true;
}
if (nfs) {
stmt.setString(15, "com.cloud.storage.resource.NfsSecondaryStorageResource");
} else {
stmt.setString(15, "com.cloud.storage.secondary.LocalSecondaryStorageResource");
}
stmt.setString(16, url);
stmt.setString(17, "None");
stmt.executeUpdate();
stmt = txn.prepareAutoCloseStatement(insertSqlHostDetails);
stmt.setLong(1, 1);
stmt.setLong(2, 1);
stmt.setString(3, "mount.parent");
if (nfs) {
stmt.setString(4, "/mnt");
} else {
stmt.setString(4, "/");
}
stmt.executeUpdate();
stmt.setLong(1, 2);
stmt.setLong(2, 1);
stmt.setString(3, "mount.path");
if (nfs) {
stmt.setString(4, mountPoint);
} else {
stmt.setString(4, url.replaceFirst("file:/", ""));
}
stmt.executeUpdate();
stmt.setLong(1, 3);
stmt.setLong(2, 1);
stmt.setString(3, "orig.url");
stmt.setString(4, url);
stmt.executeUpdate();
stmt = txn.prepareAutoCloseStatement(insertSql2);
stmt.setLong(1, 1);
stmt.setLong(2, 1);
stmt.executeUpdate();
} catch (SQLException ex) {
System.out.println("Error creating secondary storage: " + ex.getMessage());
return;
}
}
@DB
public void saveCluster() {
String name = _currentObjectParams.get("name");
long id = Long.parseLong(_currentObjectParams.get("id"));
long dataCenterId = Long.parseLong(_currentObjectParams.get("zoneId"));
long podId = Long.parseLong(_currentObjectParams.get("podId"));
String hypervisor = _currentObjectParams.get("hypervisorType");
String insertSql1 = "INSERT INTO `cluster` (`id`, `name`, `data_center_id` , `pod_id`, `hypervisor_type` , `cluster_type`, `allocation_state`) VALUES (?,?,?,?,?,?,?)";
Transaction txn = Transaction.currentTxn();
try {
PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql1);
stmt.setLong(1, id);
stmt.setString(2, name);
stmt.setLong(3, dataCenterId);
stmt.setLong(4, podId);
stmt.setString(5, hypervisor);
stmt.setString(6, "CloudManaged");
stmt.setString(7, "Enabled");
stmt.executeUpdate();
} catch (SQLException ex) {
System.out.println("Error creating cluster: " + ex.getMessage());
s_logger.error("error creating cluster", ex);
return;
}
}
@DB
public void saveStoragePool() {
String name = _currentObjectParams.get("name");
long id = Long.parseLong(_currentObjectParams.get("id"));
long dataCenterId = Long.parseLong(_currentObjectParams.get("zoneId"));
long podId = Long.parseLong(_currentObjectParams.get("podId"));
long clusterId = Long.parseLong(_currentObjectParams.get("clusterId"));
String hostAddress = _currentObjectParams.get("hostAddress");
String hostPath = _currentObjectParams.get("hostPath");
String storageType = _currentObjectParams.get("storageType");
String uuid = UUID.nameUUIDFromBytes(new String(hostAddress+hostPath).getBytes()).toString();
String insertSql1 = "INSERT INTO `storage_pool` (`id`, `name`, `uuid` , `pool_type` , `port`, `data_center_id` ,`available_bytes` , `capacity_bytes` ,`host_address`, `path`, `created`, `pod_id`,`status` , `cluster_id`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
// String insertSql2 = "INSERT INTO `netfs_storage_pool` VALUES (?,?,?)";
Transaction txn = Transaction.currentTxn();
try {
PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql1);
stmt.setLong(1, id);
stmt.setString(2, name);
stmt.setString(3, uuid);
if (storageType == null) {
stmt.setString(4, "NetworkFileSystem");
} else {
stmt.setString(4, storageType);
}
stmt.setLong(5, 111);
stmt.setLong(6, dataCenterId);
stmt.setLong(7,0);
stmt.setLong(8,0);
stmt.setString(9, hostAddress);
stmt.setString(10, hostPath);
stmt.setDate(11, new Date(new java.util.Date().getTime()));
stmt.setLong(12, podId);
stmt.setString(13, Status.Up.toString());
stmt.setLong(14, clusterId);
stmt.executeUpdate();
} catch (SQLException ex) {
System.out.println("Error creating storage pool: " + ex.getMessage());
s_logger.error("error creating storage pool ", ex);
return;
}
}
private void saveZone() {
long id = Long.parseLong(_currentObjectParams.get("id"));
String name = _currentObjectParams.get("name");
//String description = _currentObjectParams.get("description");
String dns1 = _currentObjectParams.get("dns1");
String dns2 = _currentObjectParams.get("dns2");
String internalDns1 = _currentObjectParams.get("internalDns1");
String internalDns2 = _currentObjectParams.get("internalDns2");
//String vnetRange = _currentObjectParams.get("vnet");
String guestNetworkCidr = _currentObjectParams.get("guestNetworkCidr");
String networkType = _currentObjectParams.get("networktype");
// Check that all IPs are valid
String ipError = "Please enter a valid IP address for the field: ";
if (!IPRangeConfig.validOrBlankIP(dns1)) {
printError(ipError + "dns1");
}
if (!IPRangeConfig.validOrBlankIP(dns2)) {
printError(ipError + "dns2");
}
if (!IPRangeConfig.validOrBlankIP(internalDns1)) {
printError(ipError + "internalDns1");
}
if (!IPRangeConfig.validOrBlankIP(internalDns2)) {
printError(ipError + "internalDns2");
}
if (!IPRangeConfig.validCIDR(guestNetworkCidr)) {
printError("Please enter a valid value for guestNetworkCidr");
}
pzc.saveZone(false, id, name, dns1, dns2, internalDns1, internalDns2, guestNetworkCidr, networkType);
}
private void savePhysicalNetwork() {
long id = Long.parseLong(_currentObjectParams.get("id"));
String zoneId = _currentObjectParams.get("zoneId");
String vnetRange = _currentObjectParams.get("vnet");
int vnetStart = -1;
int vnetEnd = -1;
if (vnetRange != null) {
String[] tokens = vnetRange.split("-");
vnetStart = Integer.parseInt(tokens[0]);
vnetEnd = Integer.parseInt(tokens[1]);
}
long zoneDbId = Long.parseLong(zoneId);
pzc.savePhysicalNetwork(false, id, zoneDbId, vnetStart, vnetEnd);
}
private void savePhysicalNetworkServiceProvider() {
long id = Long.parseLong(_currentObjectParams.get("id"));
long physicalNetworkId = Long.parseLong(_currentObjectParams.get("physicalNetworkId"));
String providerName = _currentObjectParams.get("providerName");
long destPhysicalNetworkId = Long.parseLong(_currentObjectParams.get("destPhysicalNetworkId"));
String uuid = UUID.randomUUID().toString();
int vpn = Integer.parseInt(_currentObjectParams.get("vpn"));
int dhcp = Integer.parseInt(_currentObjectParams.get("dhcp"));
int dns = Integer.parseInt(_currentObjectParams.get("dns"));
int gateway = Integer.parseInt(_currentObjectParams.get("gateway"));
int firewall = Integer.parseInt(_currentObjectParams.get("firewall"));
int sourceNat = Integer.parseInt(_currentObjectParams.get("sourceNat"));
int lb = Integer.parseInt(_currentObjectParams.get("loadBalance"));
int staticNat = Integer.parseInt(_currentObjectParams.get("staticNat"));
int pf =Integer.parseInt(_currentObjectParams.get("portForwarding"));
int userData =Integer.parseInt(_currentObjectParams.get("userData"));
int securityGroup =Integer.parseInt(_currentObjectParams.get("securityGroup"));
String insertSql1 = "INSERT INTO `physical_network_service_providers` (`id`, `uuid`, `physical_network_id` , `provider_name`, `state` ," +
"`destination_physical_network_id`, `vpn_service_provided`, `dhcp_service_provided`, `dns_service_provided`, `gateway_service_provided`," +
"`firewall_service_provided`, `source_nat_service_provided`, `load_balance_service_provided`, `static_nat_service_provided`," +
"`port_forwarding_service_provided`, `user_data_service_provided`, `security_group_service_provided`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
Transaction txn = Transaction.currentTxn();
try {
PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql1);
stmt.setLong(1, id);
stmt.setString(2, uuid);
stmt.setLong(3, physicalNetworkId);
stmt.setString(4, providerName);
stmt.setString(5, "Enabled");
stmt.setLong(6, destPhysicalNetworkId);
stmt.setInt(7, vpn);
stmt.setInt(8, dhcp);
stmt.setInt(9, dns);
stmt.setInt(10, gateway);
stmt.setInt(11, firewall);
stmt.setInt(12, sourceNat);
stmt.setInt(13, lb);
stmt.setInt(14, staticNat);
stmt.setInt(15, pf);
stmt.setInt(16, userData);
stmt.setInt(17, securityGroup);
stmt.executeUpdate();
} catch (SQLException ex) {
System.out.println("Error creating physical network service provider: " + ex.getMessage());
s_logger.error("error creating physical network service provider", ex);
return;
}
}
private void saveVirtualRouterProvider() {
long id = Long.parseLong(_currentObjectParams.get("id"));
long nspId = Long.parseLong(_currentObjectParams.get("nspId"));
String uuid = UUID.randomUUID().toString();
String type = _currentObjectParams.get("type");
String insertSql1 = "INSERT INTO `virtual_router_providers` (`id`, `nsp_id`, `uuid` , `type` , `enabled`) " +
"VALUES (?,?,?,?,?)";
Transaction txn = Transaction.currentTxn();
try {
PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql1);
stmt.setLong(1, id);
stmt.setLong(2, nspId);
stmt.setString(3, uuid);
stmt.setString(4, type);
stmt.setInt(5, 1);
stmt.executeUpdate();
} catch (SQLException ex) {
System.out.println("Error creating virtual router provider: " + ex.getMessage());
s_logger.error("error creating virtual router provider ", ex);
return;
}
}
private void saveVlan() {
String zoneId = _currentObjectParams.get("zoneId");
String physicalNetworkIdStr = _currentObjectParams.get("physicalNetworkId");
String vlanId = _currentObjectParams.get("vlanId");
String gateway = _currentObjectParams.get("gateway");
String netmask = _currentObjectParams.get("netmask");
String publicIpRange = _currentObjectParams.get("ipAddressRange");
String vlanType = _currentObjectParams.get("vlanType");
String vlanPodName = _currentObjectParams.get("podName");
String ipError = "Please enter a valid IP address for the field: ";
if (!IPRangeConfig.validOrBlankIP(gateway)) {
printError(ipError + "gateway");
}
if (!IPRangeConfig.validOrBlankIP(netmask)) {
printError(ipError + "netmask");
}
// Check that the given IP address range was valid
if (!checkIpAddressRange(publicIpRange)) {
printError("Please enter a valid public IP range.");
}
// Split the IP address range
String[] ipAddressRangeArray = publicIpRange.split("\\-");
String startIP = ipAddressRangeArray[0];
String endIP = null;
if (ipAddressRangeArray.length > 1) {
endIP = ipAddressRangeArray[1];
}
// If a netmask was provided, check that the startIP, endIP, and gateway all belong to the same subnet
if (netmask != null && !netmask.equals("")) {
if (endIP != null) {
if (!IPRangeConfig.sameSubnet(startIP, endIP, netmask)) {
printError("Start and end IPs for the public IP range must be in the same subnet, as per the provided netmask.");
}
}
if (gateway != null && !gateway.equals("")) {
if (!IPRangeConfig.sameSubnet(startIP, gateway, netmask)) {
printError("The start IP for the public IP range must be in the same subnet as the gateway, as per the provided netmask.");
}
if (endIP != null) {
if (!IPRangeConfig.sameSubnet(endIP, gateway, netmask)) {
printError("The end IP for the public IP range must be in the same subnet as the gateway, as per the provided netmask.");
}
}
}
}
long zoneDbId = Long.parseLong(zoneId);
String zoneName = PodZoneConfig.getZoneName(zoneDbId);
long physicalNetworkId = Long.parseLong(physicalNetworkIdStr);
//Set networkId to be 0, the value will be updated after management server starts up
pzc.modifyVlan(zoneName, true, vlanId, gateway, netmask, vlanPodName, vlanType, publicIpRange, 0, physicalNetworkId);
long vlanDbId = pzc.getVlanDbId(zoneName, vlanId);
iprc.saveIPRange("public", -1, zoneDbId, vlanDbId, startIP, endIP, null, physicalNetworkId);
}
private void savePod() {
long id = Long.parseLong(_currentObjectParams.get("id"));
String name = _currentObjectParams.get("name");
long dataCenterId = Long.parseLong(_currentObjectParams.get("zoneId"));
String privateIpRange = _currentObjectParams.get("ipAddressRange");
String gateway = _currentObjectParams.get("gateway");
String cidr = _currentObjectParams.get("cidr");
String zoneName = PodZoneConfig.getZoneName(dataCenterId);
String startIP = null;
String endIP = null;
String vlanRange = _currentObjectParams.get("vnet");
int vlanStart = -1;
int vlanEnd = -1;
if (vlanRange != null) {
String[] tokens = vlanRange.split("-");
vlanStart = Integer.parseInt(tokens[0]);
vlanEnd = Integer.parseInt(tokens[1]);
}
// Get the individual cidrAddress and cidrSize values
String[] cidrPair = cidr.split("\\/");
String cidrAddress = cidrPair[0];
String cidrSize = cidrPair[1];
long cidrSizeNum = Long.parseLong(cidrSize);
// Check that the gateway is in the same subnet as the CIDR
if (!IPRangeConfig.sameSubnetCIDR(gateway, cidrAddress, cidrSizeNum)) {
printError("For pod " + name + " in zone " + zoneName + " , please ensure that your gateway is in the same subnet as the pod's CIDR address.");
}
pzc.savePod(false, id, name, dataCenterId, gateway, cidr, vlanStart, vlanEnd);
if (privateIpRange != null) {
// Check that the given IP address range was valid
if (!checkIpAddressRange(privateIpRange)) {
printError("Please enter a valid private IP range.");
}
String[] ipAddressRangeArray = privateIpRange.split("\\-");
startIP = ipAddressRangeArray[0];
endIP = null;
if (ipAddressRangeArray.length > 1) {
endIP = ipAddressRangeArray[1];
}
}
// Check that the start IP and end IP match up with the CIDR
if (!IPRangeConfig.sameSubnetCIDR(startIP, endIP, cidrSizeNum)) {
printError("For pod " + name + " in zone " + zoneName + ", please ensure that your start IP and end IP are in the same subnet, as per the pod's CIDR size.");
}
if (!IPRangeConfig.sameSubnetCIDR(startIP, cidrAddress, cidrSizeNum)) {
printError("For pod " + name + " in zone " + zoneName + ", please ensure that your start IP is in the same subnet as the pod's CIDR address.");
}
if (!IPRangeConfig.sameSubnetCIDR(endIP, cidrAddress, cidrSizeNum)) {
printError("For pod " + name + " in zone " + zoneName + ", please ensure that your end IP is in the same subnet as the pod's CIDR address.");
}
if (privateIpRange != null) {
// Save the IP address range
iprc.saveIPRange("private", id, dataCenterId, -1, startIP, endIP, null, -1);
}
}
@DB
protected void saveServiceOffering() {
long id = Long.parseLong(_currentObjectParams.get("id"));
String name = _currentObjectParams.get("name");
String displayText = _currentObjectParams.get("displayText");
int cpu = Integer.parseInt(_currentObjectParams.get("cpu"));
int ramSize = Integer.parseInt(_currentObjectParams.get("ramSize"));
int speed = Integer.parseInt(_currentObjectParams.get("speed"));
String useLocalStorageValue = _currentObjectParams.get("useLocalStorage");
// int nwRate = Integer.parseInt(_currentObjectParams.get("nwRate"));
// int mcRate = Integer.parseInt(_currentObjectParams.get("mcRate"));
boolean ha = Boolean.parseBoolean(_currentObjectParams.get("enableHA"));
boolean mirroring = Boolean.parseBoolean(_currentObjectParams.get("mirrored"));
boolean useLocalStorage;
if (useLocalStorageValue != null) {
if (Boolean.parseBoolean(useLocalStorageValue)) {
useLocalStorage = true;
} else {
useLocalStorage = false;
}
} else {
useLocalStorage = false;
}
ServiceOfferingVO serviceOffering = new ServiceOfferingVO(name, cpu, ramSize, speed, null, null, ha, displayText, useLocalStorage, false, null, false, null, false);
Long bytesReadRate = Long.parseLong(_currentObjectParams.get("bytesReadRate"));
if ((bytesReadRate != null) && (bytesReadRate > 0))
serviceOffering.setBytesReadRate(bytesReadRate);
Long bytesWriteRate = Long.parseLong(_currentObjectParams.get("bytesWriteRate"));
if ((bytesWriteRate != null) && (bytesWriteRate > 0))
serviceOffering.setBytesWriteRate(bytesWriteRate);
Long iopsReadRate = Long.parseLong(_currentObjectParams.get("iopsReadRate"));
if ((iopsReadRate != null) && (iopsReadRate > 0))
serviceOffering.setIopsReadRate(iopsReadRate);
Long iopsWriteRate = Long.parseLong(_currentObjectParams.get("iopsWriteRate"));
if ((iopsWriteRate != null) && (iopsWriteRate > 0))
serviceOffering.setIopsWriteRate(iopsWriteRate);
ServiceOfferingDaoImpl dao = ComponentContext.inject(ServiceOfferingDaoImpl.class);
try {
dao.persist(serviceOffering);
} catch (Exception e) {
s_logger.error("error creating service offering", e);
}
/*
String insertSql = "INSERT INTO `cloud`.`service_offering` (id, name, cpu, ram_size, speed, nw_rate, mc_rate, created, ha_enabled, mirrored, display_text, guest_ip_type, use_local_storage) " +
"VALUES (" + id + ",'" + name + "'," + cpu + "," + ramSize + "," + speed + "," + nwRate + "," + mcRate + ",now()," + ha + "," + mirroring + ",'" + displayText + "','" + guestIpType + "','" + useLocalStorage + "')";
Transaction txn = Transaction.currentTxn();
try {
PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql);
stmt.executeUpdate();
} catch (SQLException ex) {
s_logger.error("error creating service offering", ex);
return;
}
*/
}
@DB
protected void saveDiskOffering() {
long id = Long.parseLong(_currentObjectParams.get("id"));
long domainId = Long.parseLong(_currentObjectParams.get("domainId"));
String name = _currentObjectParams.get("name");
String displayText = _currentObjectParams.get("displayText");
long diskSpace = Long.parseLong(_currentObjectParams.get("diskSpace"));
diskSpace = diskSpace * 1024 * 1024;
// boolean mirroring = Boolean.parseBoolean(_currentObjectParams.get("mirrored"));
String tags = _currentObjectParams.get("tags");
String useLocal = _currentObjectParams.get("useLocal");
boolean local = false;
if (useLocal != null) {
local = Boolean.parseBoolean(useLocal);
}
if (tags != null && tags.length() > 0) {
String[] tokens = tags.split(",");
StringBuilder newTags = new StringBuilder();
for (String token : tokens) {
newTags.append(token.trim()).append(",");
}
newTags.delete(newTags.length() - 1, newTags.length());
tags = newTags.toString();
}
DiskOfferingVO diskOffering = new DiskOfferingVO(domainId, name, displayText, diskSpace, tags, false, null, null, null);
diskOffering.setUseLocalStorage(local);
Long bytesReadRate = Long.parseLong(_currentObjectParams.get("bytesReadRate"));
if (bytesReadRate != null && (bytesReadRate > 0))
diskOffering.setBytesReadRate(bytesReadRate);
Long bytesWriteRate = Long.parseLong(_currentObjectParams.get("bytesWriteRate"));
if (bytesWriteRate != null && (bytesWriteRate > 0))
diskOffering.setBytesWriteRate(bytesWriteRate);
Long iopsReadRate = Long.parseLong(_currentObjectParams.get("iopsReadRate"));
if (iopsReadRate != null && (iopsReadRate > 0))
diskOffering.setIopsReadRate(iopsReadRate);
Long iopsWriteRate = Long.parseLong(_currentObjectParams.get("iopsWriteRate"));
if (iopsWriteRate != null && (iopsWriteRate > 0))
diskOffering.setIopsWriteRate(iopsWriteRate);
DiskOfferingDaoImpl offering = ComponentContext.inject(DiskOfferingDaoImpl.class);
try {
offering.persist(diskOffering);