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 () {
@@ -956,114 +944,12 @@ public void parse(UsageJobVO job, long startDateMillis, long endDateMillis) {
956944 private boolean parseHelperTables (AccountVO account , Date currentStartDate , Date currentEndDate ) {
957945 boolean parsed = false ;
958946
959- parsed = VMInstanceUsageParser .parse (account , currentStartDate , currentEndDate );
960- if (logger .isDebugEnabled ()) {
961- if (!parsed ) {
962- logger .debug ("vm usage instances successfully parsed? " + parsed + " (for account: " + account .getAccountName () + ", id: " + account .getId () + ")" );
963- }
964- }
947+ for (UsageParser parser : usageParsers ) {
948+ parsed = parser .doParsing (account , currentStartDate , currentEndDate );
965949
966- parsed = NetworkUsageParser .parse (account , currentStartDate , currentEndDate );
967- if (logger .isDebugEnabled ()) {
968- if (!parsed ) {
969- logger .debug ("network usage successfully parsed? " + parsed + " (for account: " + account .getAccountName () + ", id: " + account .getId () + ")" );
970- }
950+ logger .debug ("{} usage was {} parsed for [{}]." , parser .getParserName (), parsed ? "successfully" : "not successfully" , account );
971951 }
972952
973- parsed = VmDiskUsageParser .parse (account , currentStartDate , currentEndDate );
974- if (logger .isDebugEnabled ()) {
975- if (!parsed ) {
976- logger .debug ("vm disk usage successfully parsed? " + parsed + " (for account: " + account .getAccountName () + ", id: " + account .getId () + ")" );
977- }
978- }
979-
980- parsed = VolumeUsageParser .parse (account , currentStartDate , currentEndDate );
981- if (logger .isDebugEnabled ()) {
982- if (!parsed ) {
983- logger .debug ("volume usage successfully parsed? " + parsed + " (for account: " + account .getAccountName () + ", id: " + account .getId () + ")" );
984- }
985- }
986-
987- parsed = StorageUsageParser .parse (account , currentStartDate , currentEndDate );
988- if (logger .isDebugEnabled ()) {
989- if (!parsed ) {
990- logger .debug ("storage usage successfully parsed? " + parsed + " (for account: " + account .getAccountName () + ", id: " + account .getId () + ")" );
991- }
992- }
993-
994- parsed = SecurityGroupUsageParser .parse (account , currentStartDate , currentEndDate );
995- if (logger .isDebugEnabled ()) {
996- if (!parsed ) {
997- logger .debug ("Security Group usage successfully parsed? " + parsed + " (for account: " + account .getAccountName () + ", id: " + account .getId () + ")" );
998- }
999- }
1000-
1001- parsed = LoadBalancerUsageParser .parse (account , currentStartDate , currentEndDate );
1002- if (logger .isDebugEnabled ()) {
1003- if (!parsed ) {
1004- logger .debug ("load balancer usage successfully parsed? " + parsed + " (for account: " + account .getAccountName () + ", id: " + account .getId () + ")" );
1005- }
1006- }
1007-
1008- parsed = PortForwardingUsageParser .parse (account , currentStartDate , currentEndDate );
1009- if (logger .isDebugEnabled ()) {
1010- if (!parsed ) {
1011- logger .debug ("port forwarding usage successfully parsed? " + parsed + " (for account: " + account .getAccountName () + ", id: " + account .getId () + ")" );
1012- }
1013- }
1014-
1015- parsed = NetworkOfferingUsageParser .parse (account , currentStartDate , currentEndDate );
1016- if (logger .isDebugEnabled ()) {
1017- if (!parsed ) {
1018- logger .debug ("network offering usage successfully parsed? " + parsed + " (for account: " + account .getAccountName () + ", id: " + account .getId () + ")" );
1019- }
1020- }
1021-
1022- parsed = IPAddressUsageParser .parse (account , currentStartDate , currentEndDate );
1023- if (logger .isDebugEnabled ()) {
1024- if (!parsed ) {
1025- logger .debug ("IPAddress usage successfully parsed? " + parsed + " (for account: " + account .getAccountName () + ", id: " + account .getId () + ")" );
1026- }
1027- }
1028- parsed = VPNUserUsageParser .parse (account , currentStartDate , currentEndDate );
1029- if (logger .isDebugEnabled ()) {
1030- if (!parsed ) {
1031- logger .debug ("VPN user usage successfully parsed? " + parsed + " (for account: " + account .getAccountName () + ", id: " + account .getId () + ")" );
1032- }
1033- }
1034- parsed = VMSnapshotUsageParser .parse (account , currentStartDate , currentEndDate );
1035- if (logger .isDebugEnabled ()) {
1036- if (!parsed ) {
1037- logger .debug ("VM Snapshot usage successfully parsed? " + parsed + " (for account: " + account .getAccountName () + ", id: " + account .getId () + ")" );
1038- }
1039- }
1040- parsed = VMSnapshotOnPrimaryParser .parse (account , currentStartDate , currentEndDate );
1041- if (logger .isDebugEnabled ()) {
1042- if (!parsed ) {
1043- logger .debug ("VM Snapshot on primary usage successfully parsed? " + parsed + " (for account: " + account .getAccountName () + ", id: " + account .getId () + ")" );
1044- }
1045- }
1046- parsed = BackupUsageParser .parse (account , currentStartDate , currentEndDate );
1047- if (logger .isDebugEnabled ()) {
1048- if (!parsed ) {
1049- logger .debug ("VM Backup usage successfully parsed? " + parsed + " (for account: " + account .getAccountName () + ", id: " + account .getId () + ")" );
1050- }
1051- }
1052- parsed = BucketUsageParser .parse (account , currentStartDate , currentEndDate );
1053- if (logger .isDebugEnabled ()) {
1054- if (!parsed ) {
1055- logger .debug ("Bucket usage successfully parsed? " + parsed + " (for account: " + account .getAccountName () + ", id: " + account .getId () + ")" );
1056- }
1057- }
1058- parsed = NetworksUsageParser .parse (account , currentStartDate , currentEndDate );
1059- if (!parsed ) {
1060- logger .debug ("Networks usage not parsed for account [{}}]." , account );
1061- }
1062-
1063- parsed = VpcUsageParser .parse (account , currentStartDate , currentEndDate );
1064- if (!parsed ) {
1065- logger .debug (String .format ("VPC usage failed to parse for account [%s]." , account ));
1066- }
1067953 return parsed ;
1068954 }
1069955
0 commit comments