34
34
35
35
import com .cloud .network .Network ;
36
36
import com .cloud .usage .dao .UsageNetworksDao ;
37
- import com .cloud .usage .parser .NetworksUsageParser ;
37
+ import com .cloud .usage .parser .UsageParser ;
38
38
import com .cloud .network .vpc .Vpc ;
39
39
import com .cloud .usage .dao .UsageVpcDao ;
40
- import com .cloud .usage .parser .VpcUsageParser ;
41
40
import javax .inject .Inject ;
42
41
import javax .naming .ConfigurationException ;
43
42
import javax .persistence .EntityExistsException ;
75
74
import com .cloud .usage .dao .UsageVPNUserDao ;
76
75
import com .cloud .usage .dao .UsageVmDiskDao ;
77
76
import com .cloud .usage .dao .UsageVolumeDao ;
78
- import com .cloud .usage .parser .BackupUsageParser ;
79
- import com .cloud .usage .parser .BucketUsageParser ;
80
- import com .cloud .usage .parser .IPAddressUsageParser ;
81
- import com .cloud .usage .parser .LoadBalancerUsageParser ;
82
- import com .cloud .usage .parser .NetworkOfferingUsageParser ;
83
- import com .cloud .usage .parser .NetworkUsageParser ;
84
- import com .cloud .usage .parser .PortForwardingUsageParser ;
85
- import com .cloud .usage .parser .SecurityGroupUsageParser ;
86
- import com .cloud .usage .parser .StorageUsageParser ;
87
- import com .cloud .usage .parser .VMInstanceUsageParser ;
88
- import com .cloud .usage .parser .VMSnapshotOnPrimaryParser ;
89
- import com .cloud .usage .parser .VMSnapshotUsageParser ;
90
- import com .cloud .usage .parser .VPNUserUsageParser ;
91
- import com .cloud .usage .parser .VmDiskUsageParser ;
92
- import com .cloud .usage .parser .VolumeUsageParser ;
93
77
import com .cloud .user .Account ;
94
78
import com .cloud .user .AccountVO ;
95
79
import com .cloud .user .UserStatisticsVO ;
@@ -180,6 +164,9 @@ public class UsageManagerImpl extends ManagerBase implements UsageManager, Runna
180
164
@ Inject
181
165
private UsageVpcDao usageVpcDao ;
182
166
167
+ @ Inject
168
+ private List <UsageParser > usageParsers ;
169
+
183
170
private String _version = null ;
184
171
private final Calendar _jobExecTime = Calendar .getInstance ();
185
172
private int _aggregationDuration = 0 ;
@@ -198,6 +185,7 @@ public class UsageManagerImpl extends ManagerBase implements UsageManager, Runna
198
185
private Future _heartbeat = null ;
199
186
private Future _sanity = null ;
200
187
private boolean usageSnapshotSelection = false ;
188
+
201
189
private static TimeZone usageAggregationTimeZone = TimeZone .getTimeZone ("GMT" );
202
190
203
191
public UsageManagerImpl () {
@@ -954,114 +942,12 @@ public void parse(UsageJobVO job, long startDateMillis, long endDateMillis) {
954
942
private boolean parseHelperTables (AccountVO account , Date currentStartDate , Date currentEndDate ) {
955
943
boolean parsed = false ;
956
944
957
- parsed = VMInstanceUsageParser .parse (account , currentStartDate , currentEndDate );
958
- if (logger .isDebugEnabled ()) {
959
- if (!parsed ) {
960
- logger .debug ("vm usage instances successfully parsed? " + parsed + " (for account: " + account .getAccountName () + ", id: " + account .getId () + ")" );
961
- }
962
- }
945
+ for (UsageParser parser : usageParsers ) {
946
+ parsed = parser .doParsing (account , currentStartDate , currentEndDate );
963
947
964
- parsed = NetworkUsageParser .parse (account , currentStartDate , currentEndDate );
965
- if (logger .isDebugEnabled ()) {
966
- if (!parsed ) {
967
- logger .debug ("network usage successfully parsed? " + parsed + " (for account: " + account .getAccountName () + ", id: " + account .getId () + ")" );
968
- }
948
+ logger .debug ("{} usage was {} parsed for [{}]." , parser .getParserName (), parsed ? "successfully" : "not successfully" , account );
969
949
}
970
950
971
- parsed = VmDiskUsageParser .parse (account , currentStartDate , currentEndDate );
972
- if (logger .isDebugEnabled ()) {
973
- if (!parsed ) {
974
- logger .debug ("vm disk usage successfully parsed? " + parsed + " (for account: " + account .getAccountName () + ", id: " + account .getId () + ")" );
975
- }
976
- }
977
-
978
- parsed = VolumeUsageParser .parse (account , currentStartDate , currentEndDate );
979
- if (logger .isDebugEnabled ()) {
980
- if (!parsed ) {
981
- logger .debug ("volume usage successfully parsed? " + parsed + " (for account: " + account .getAccountName () + ", id: " + account .getId () + ")" );
982
- }
983
- }
984
-
985
- parsed = StorageUsageParser .parse (account , currentStartDate , currentEndDate );
986
- if (logger .isDebugEnabled ()) {
987
- if (!parsed ) {
988
- logger .debug ("storage usage successfully parsed? " + parsed + " (for account: " + account .getAccountName () + ", id: " + account .getId () + ")" );
989
- }
990
- }
991
-
992
- parsed = SecurityGroupUsageParser .parse (account , currentStartDate , currentEndDate );
993
- if (logger .isDebugEnabled ()) {
994
- if (!parsed ) {
995
- logger .debug ("Security Group usage successfully parsed? " + parsed + " (for account: " + account .getAccountName () + ", id: " + account .getId () + ")" );
996
- }
997
- }
998
-
999
- parsed = LoadBalancerUsageParser .parse (account , currentStartDate , currentEndDate );
1000
- if (logger .isDebugEnabled ()) {
1001
- if (!parsed ) {
1002
- logger .debug ("load balancer usage successfully parsed? " + parsed + " (for account: " + account .getAccountName () + ", id: " + account .getId () + ")" );
1003
- }
1004
- }
1005
-
1006
- parsed = PortForwardingUsageParser .parse (account , currentStartDate , currentEndDate );
1007
- if (logger .isDebugEnabled ()) {
1008
- if (!parsed ) {
1009
- logger .debug ("port forwarding usage successfully parsed? " + parsed + " (for account: " + account .getAccountName () + ", id: " + account .getId () + ")" );
1010
- }
1011
- }
1012
-
1013
- parsed = NetworkOfferingUsageParser .parse (account , currentStartDate , currentEndDate );
1014
- if (logger .isDebugEnabled ()) {
1015
- if (!parsed ) {
1016
- logger .debug ("network offering usage successfully parsed? " + parsed + " (for account: " + account .getAccountName () + ", id: " + account .getId () + ")" );
1017
- }
1018
- }
1019
-
1020
- parsed = IPAddressUsageParser .parse (account , currentStartDate , currentEndDate );
1021
- if (logger .isDebugEnabled ()) {
1022
- if (!parsed ) {
1023
- logger .debug ("IPAddress usage successfully parsed? " + parsed + " (for account: " + account .getAccountName () + ", id: " + account .getId () + ")" );
1024
- }
1025
- }
1026
- parsed = VPNUserUsageParser .parse (account , currentStartDate , currentEndDate );
1027
- if (logger .isDebugEnabled ()) {
1028
- if (!parsed ) {
1029
- logger .debug ("VPN user usage successfully parsed? " + parsed + " (for account: " + account .getAccountName () + ", id: " + account .getId () + ")" );
1030
- }
1031
- }
1032
- parsed = VMSnapshotUsageParser .parse (account , currentStartDate , currentEndDate );
1033
- if (logger .isDebugEnabled ()) {
1034
- if (!parsed ) {
1035
- logger .debug ("VM Snapshot usage successfully parsed? " + parsed + " (for account: " + account .getAccountName () + ", id: " + account .getId () + ")" );
1036
- }
1037
- }
1038
- parsed = VMSnapshotOnPrimaryParser .parse (account , currentStartDate , currentEndDate );
1039
- if (logger .isDebugEnabled ()) {
1040
- if (!parsed ) {
1041
- logger .debug ("VM Snapshot on primary usage successfully parsed? " + parsed + " (for account: " + account .getAccountName () + ", id: " + account .getId () + ")" );
1042
- }
1043
- }
1044
- parsed = BackupUsageParser .parse (account , currentStartDate , currentEndDate );
1045
- if (logger .isDebugEnabled ()) {
1046
- if (!parsed ) {
1047
- logger .debug ("VM Backup usage successfully parsed? " + parsed + " (for account: " + account .getAccountName () + ", id: " + account .getId () + ")" );
1048
- }
1049
- }
1050
- parsed = BucketUsageParser .parse (account , currentStartDate , currentEndDate );
1051
- if (logger .isDebugEnabled ()) {
1052
- if (!parsed ) {
1053
- logger .debug ("Bucket usage successfully parsed? " + parsed + " (for account: " + account .getAccountName () + ", id: " + account .getId () + ")" );
1054
- }
1055
- }
1056
- parsed = NetworksUsageParser .parse (account , currentStartDate , currentEndDate );
1057
- if (!parsed ) {
1058
- logger .debug ("Networks usage not parsed for account [{}}]." , account );
1059
- }
1060
-
1061
- parsed = VpcUsageParser .parse (account , currentStartDate , currentEndDate );
1062
- if (!parsed ) {
1063
- logger .debug (String .format ("VPC usage failed to parse for account [%s]." , account ));
1064
- }
1065
951
return parsed ;
1066
952
}
1067
953
0 commit comments