3434
3535import com .cloud .network .Network ;
3636import com .cloud .usage .dao .UsageNetworksDao ;
37- import com .cloud .usage .parser .NetworksUsageParser ;
37+ import com .cloud .usage .parser .UsageParser ;
3838import com .cloud .network .vpc .Vpc ;
3939import com .cloud .usage .dao .UsageVpcDao ;
40- import com .cloud .usage .parser .VpcUsageParser ;
4140import javax .inject .Inject ;
4241import javax .naming .ConfigurationException ;
4342import javax .persistence .EntityExistsException ;
7574import com .cloud .usage .dao .UsageVPNUserDao ;
7675import com .cloud .usage .dao .UsageVmDiskDao ;
7776import 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 ;
9377import com .cloud .user .Account ;
9478import com .cloud .user .AccountVO ;
9579import com .cloud .user .UserStatisticsVO ;
@@ -180,6 +164,9 @@ public class UsageManagerImpl extends ManagerBase implements UsageManager, Runna
180164 @ Inject
181165 private UsageVpcDao usageVpcDao ;
182166
167+ @ Inject
168+ private List <UsageParser > usageParsers ;
169+
183170 private String _version = null ;
184171 private final Calendar _jobExecTime = Calendar .getInstance ();
185172 private int _aggregationDuration = 0 ;
@@ -198,6 +185,7 @@ public class UsageManagerImpl extends ManagerBase implements UsageManager, Runna
198185 private Future _heartbeat = null ;
199186 private Future _sanity = null ;
200187 private boolean usageSnapshotSelection = false ;
188+
201189 private static TimeZone usageAggregationTimeZone = TimeZone .getTimeZone ("GMT" );
202190
203191 public UsageManagerImpl () {
@@ -954,114 +942,12 @@ public void parse(UsageJobVO job, long startDateMillis, long endDateMillis) {
954942 private boolean parseHelperTables (AccountVO account , Date currentStartDate , Date currentEndDate ) {
955943 boolean parsed = false ;
956944
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 );
963947
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 );
969949 }
970950
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- }
1065951 return parsed ;
1066952 }
1067953
0 commit comments