~ubuntu-branches/ubuntu/raring/eucalyptus/raring

« back to all changes in this revision

Viewing changes to clc/modules/reporting/src/main/java/com/eucalyptus/reporting/modules/instance/InstanceUsageSummary.java

  • Committer: Package Import Robot
  • Author(s): Brian Thomason
  • Date: 2011-11-29 13:17:52 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 185.
  • Revision ID: package-import@ubuntu.com-20111129131752-rq31al3ntutv2vvl
Tags: upstream-3.0.999beta1
ImportĀ upstreamĀ versionĀ 3.0.999beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package com.eucalyptus.reporting.modules.instance;
 
2
 
 
3
import com.eucalyptus.reporting.Period;
 
4
 
 
5
/**
 
6
 * <p>InstanceUsageSummary is a summary of all resource usage for some entity
 
7
 * over a time period. It includes summations of the instance types,
 
8
 * numbers, running times, resource usage, etc, for a given user,
 
9
 * account or other entity.
 
10
 * 
 
11
 * @author tom.werges
 
12
 */
 
13
public class InstanceUsageSummary
 
14
{
 
15
        private Long m1SmallNum;
 
16
        private Long m1SmallTimeSecs;
 
17
        private Long c1MediumNum;
 
18
        private Long c1MediumTimeSecs;
 
19
        private Long m1LargeNum;
 
20
        private Long m1LargeTimeSecs;
 
21
        private Long m1XLargeNum;
 
22
        private Long m1XLargeTimeSecs;
 
23
        private Long c1XLargeNum;
 
24
        private Long c1XLargeTimeSecs;
 
25
        private Long networkIoMegs;
 
26
        private Long diskIoMegs;
 
27
        
 
28
        public InstanceUsageSummary()
 
29
        {
 
30
                this.m1SmallNum = new Long(0);
 
31
                this.m1SmallTimeSecs = new Long(0);
 
32
                this.c1MediumNum = new Long(0);
 
33
                this.c1MediumTimeSecs = new Long(0);
 
34
                this.m1LargeNum = new Long(0);
 
35
                this.m1LargeTimeSecs = new Long(0);
 
36
                this.m1XLargeNum = new Long(0);
 
37
                this.m1XLargeTimeSecs = new Long(0);
 
38
                this.c1XLargeNum = new Long(0);
 
39
                this.c1XLargeTimeSecs = new Long(0);
 
40
                this.networkIoMegs = new Long(0);
 
41
                this.diskIoMegs = new Long(0);
 
42
        }
 
43
 
 
44
        public InstanceUsageSummary(Long m1SmallNum, Long m1SmallTimeSecs,
 
45
                        Long c1MediumNum, Long c1MediumTimeSecs, Long m1LargeNum,
 
46
                        Long m1LargeTimeSecs, Long m1XLargeNum, Long m1XLargeTimeSecs,
 
47
                        Long c1XLargeNum, Long c1XLargeTimeSecs, Long networkIoMegs,
 
48
                        Long diskIoMegs)
 
49
        {
 
50
                //Check that no args are null
 
51
                if (m1SmallNum == null || m1SmallTimeSecs == null || c1MediumNum == null
 
52
                        || c1MediumTimeSecs == null || m1LargeNum == null || m1LargeTimeSecs == null
 
53
                        || m1XLargeNum == null || m1XLargeTimeSecs == null || c1XLargeNum == null
 
54
                        || c1XLargeTimeSecs == null || networkIoMegs == null || diskIoMegs == null)
 
55
                {
 
56
                        throw new IllegalArgumentException("ctor args cannot be null");
 
57
                }
 
58
                
 
59
                this.m1SmallNum = m1SmallNum;
 
60
                this.m1SmallTimeSecs = m1SmallTimeSecs;
 
61
                this.c1MediumNum = c1MediumNum;
 
62
                this.c1MediumTimeSecs = c1MediumTimeSecs;
 
63
                this.m1LargeNum = m1LargeNum;
 
64
                this.m1LargeTimeSecs = m1LargeTimeSecs;
 
65
                this.m1XLargeNum = m1XLargeNum;
 
66
                this.m1XLargeTimeSecs = m1XLargeTimeSecs;
 
67
                this.c1XLargeNum = c1XLargeNum;
 
68
                this.c1XLargeTimeSecs = c1XLargeTimeSecs;
 
69
                this.networkIoMegs = networkIoMegs;
 
70
                this.diskIoMegs = diskIoMegs;
 
71
        }
 
72
 
 
73
        public Long getM1SmallNum()
 
74
        {
 
75
                return m1SmallNum;
 
76
        }
 
77
 
 
78
        public void setM1SmallNum(Long m1SmallNum)
 
79
        {
 
80
                if (m1SmallNum == null)
 
81
                        throw new IllegalArgumentException("arg can't be null");
 
82
                this.m1SmallNum = m1SmallNum;
 
83
        }
 
84
        
 
85
        public Long getM1SmallTimeSecs()
 
86
        {
 
87
                return m1SmallTimeSecs;
 
88
        }
 
89
 
 
90
        public void setM1SmallTimeSecs(Long m1SmallTimeSecs)
 
91
        {
 
92
                if (m1SmallTimeSecs == null)
 
93
                        throw new IllegalArgumentException("arg can't be null");
 
94
                this.m1SmallTimeSecs = m1SmallTimeSecs;
 
95
        }
 
96
 
 
97
        public Long getC1MediumNum()
 
98
        {
 
99
                return c1MediumNum;
 
100
        }
 
101
 
 
102
        public void setC1MediumNum(Long c1MediumNum)
 
103
        {
 
104
                if (c1MediumNum == null)
 
105
                        throw new IllegalArgumentException("arg can't be null");
 
106
                this.c1MediumNum = c1MediumNum;
 
107
        }
 
108
 
 
109
        public Long getC1MediumTimeSecs()
 
110
        {
 
111
                return c1MediumTimeSecs;
 
112
        }
 
113
 
 
114
        public void setC1MediumTimeSecs(Long c1MediumTimeSecs)
 
115
        {
 
116
                if (c1MediumTimeSecs == null)
 
117
                        throw new IllegalArgumentException("arg can't be null");
 
118
                this.c1MediumTimeSecs = c1MediumTimeSecs;
 
119
        }
 
120
 
 
121
        public Long getM1LargeNum()
 
122
        {
 
123
                return m1LargeNum;
 
124
        }
 
125
 
 
126
        public void setM1LargeNum(Long m1LargeNum)
 
127
        {
 
128
                if (m1LargeNum  == null)
 
129
                        throw new IllegalArgumentException("arg can't be null");
 
130
                this.m1LargeNum = m1LargeNum;
 
131
        }
 
132
 
 
133
        public Long getM1LargeTimeSecs()
 
134
        {
 
135
                return m1LargeTimeSecs;
 
136
        }
 
137
 
 
138
        public void setM1LargeTimeSecs(Long m1LargeTimeSecs)
 
139
        {
 
140
                if (m1LargeTimeSecs == null)
 
141
                        throw new IllegalArgumentException("arg can't be null");
 
142
                this.m1LargeTimeSecs = m1LargeTimeSecs;
 
143
        }
 
144
 
 
145
        public Long getM1XLargeNum()
 
146
        {
 
147
                return m1XLargeNum;
 
148
        }
 
149
 
 
150
        public void setM1XLargeNum(Long m1XLargeNum)
 
151
        {
 
152
                if (m1XLargeNum == null)
 
153
                        throw new IllegalArgumentException("arg can't be null");
 
154
                this.m1XLargeNum = m1XLargeNum;
 
155
        }
 
156
 
 
157
        public Long getM1XLargeTimeSecs()
 
158
        {
 
159
                return m1XLargeTimeSecs;
 
160
        }
 
161
 
 
162
        public void setM1XLargeTimeSecs(Long m1XLargeTimeSecs)
 
163
        {
 
164
                if (m1XLargeTimeSecs == null)
 
165
                        throw new IllegalArgumentException("arg can't be null");
 
166
                this.m1XLargeTimeSecs = m1XLargeTimeSecs;
 
167
        }
 
168
 
 
169
        public Long getC1XLargeNum()
 
170
        {
 
171
                return c1XLargeNum;
 
172
        }
 
173
 
 
174
        public void setC1XLargeNum(Long c1XLargeNum)
 
175
        {
 
176
                if (c1XLargeNum == null)
 
177
                        throw new IllegalArgumentException("arg can't be null");
 
178
                this.c1XLargeNum = c1XLargeNum;
 
179
        }
 
180
 
 
181
        public Long getC1XLargeTimeSecs()
 
182
        {
 
183
                return c1XLargeTimeSecs;
 
184
        }
 
185
 
 
186
        public void setC1XLargeTimeSecs(Long c1XLargeTimeSecs)
 
187
        {
 
188
                if (c1XLargeTimeSecs == null)
 
189
                        throw new IllegalArgumentException("arg can't be null");
 
190
                this.c1XLargeTimeSecs = c1XLargeTimeSecs;
 
191
        }
 
192
 
 
193
        public Long getDiskIoMegs()
 
194
        {
 
195
                return diskIoMegs;
 
196
        }
 
197
 
 
198
        public void setDiskIoMegs(Long diskIoMegs)
 
199
        {
 
200
                if (diskIoMegs == null)
 
201
                        throw new IllegalArgumentException("arg can't be null");
 
202
                this.diskIoMegs = diskIoMegs;
 
203
        }
 
204
 
 
205
        public Long getNetworkIoMegs()
 
206
        {
 
207
                return networkIoMegs;
 
208
        }
 
209
 
 
210
        public void setNetworkIoMegs(Long networkIoMegs)
 
211
        {
 
212
                if (networkIoMegs == null)
 
213
                        throw new IllegalArgumentException("arg can't be null");
 
214
                this.networkIoMegs = networkIoMegs;
 
215
        }
 
216
 
 
217
        void addM1SmallNum(long addBy)
 
218
        {
 
219
                this.m1SmallNum = new Long(this.m1SmallNum.longValue() + addBy);
 
220
        }
 
221
 
 
222
        void addM1SmallTimeSecs(long addBy)
 
223
        {
 
224
                this.m1SmallTimeSecs = new Long(this.m1SmallTimeSecs.longValue() + addBy);
 
225
        }
 
226
 
 
227
        void addC1MediumNum(long addBy)
 
228
        {
 
229
                this.c1MediumNum = new Long(this.c1MediumNum.longValue() + addBy);
 
230
        }
 
231
 
 
232
        void addC1MediumTimeSecs(long addBy)
 
233
        {
 
234
                this.c1MediumTimeSecs = new Long(this.c1MediumTimeSecs.longValue() + addBy);
 
235
        }
 
236
 
 
237
        void addM1LargeNum(long addBy)
 
238
        {
 
239
                this.m1LargeNum = new Long(this.m1LargeNum.longValue() + addBy);
 
240
        }
 
241
 
 
242
        void addM1LargeTimeSecs(long addBy)
 
243
        {
 
244
                this.m1LargeTimeSecs = new Long(this.m1LargeTimeSecs.longValue() + addBy);
 
245
        }
 
246
 
 
247
        void addM1XLargeNum(long addBy)
 
248
        {
 
249
                this.m1XLargeNum = new Long(this.m1XLargeNum.longValue() + addBy);
 
250
        }
 
251
 
 
252
        void addM1XLargeTimeSecs(long addBy)
 
253
        {
 
254
                this.m1XLargeTimeSecs = new Long(this.m1XLargeTimeSecs.longValue() + addBy);
 
255
        }
 
256
 
 
257
        void addC1XLargeNum(long addBy)
 
258
        {
 
259
                this.c1XLargeNum = new Long(this.c1XLargeNum.longValue() + addBy);
 
260
        }
 
261
 
 
262
        void addC1XLargeTimeSecs(long addBy)
 
263
        {
 
264
                this.c1XLargeTimeSecs = new Long(this.c1XLargeTimeSecs.longValue() + addBy);
 
265
        }
 
266
 
 
267
        void addNetworkIoMegs(long addBy)
 
268
        {
 
269
                this.networkIoMegs = new Long(this.networkIoMegs.longValue() + addBy);
 
270
        }
 
271
 
 
272
        void addDiskIoMegs(long addBy)
 
273
        {
 
274
                this.diskIoMegs = new Long(this.diskIoMegs.longValue() + addBy);
 
275
        }
 
276
 
 
277
        public void addUsage(InstanceUsageSummary summary)
 
278
        {
 
279
                this.diskIoMegs = addLongs(this.diskIoMegs, summary.diskIoMegs);
 
280
                this.networkIoMegs = addLongs(this.networkIoMegs, summary.networkIoMegs);
 
281
                this.m1SmallNum = addLongs(this.m1SmallNum, summary.m1SmallNum);
 
282
                this.c1MediumNum = addLongs(this.c1MediumNum, summary.c1MediumNum);
 
283
                this.m1LargeNum = addLongs(this.m1LargeNum, summary.m1LargeNum);
 
284
                this.m1XLargeNum = addLongs(this.m1XLargeNum, summary.m1XLargeNum);
 
285
                this.c1XLargeNum = addLongs(this.c1XLargeNum, summary.c1XLargeNum);
 
286
                this.m1SmallTimeSecs = addLongs(this.m1SmallTimeSecs, summary.m1SmallTimeSecs);
 
287
                this.c1MediumTimeSecs = addLongs(this.c1MediumTimeSecs, summary.c1MediumTimeSecs);
 
288
                this.m1LargeTimeSecs = addLongs(this.m1LargeTimeSecs, summary.m1LargeTimeSecs);
 
289
                this.m1XLargeTimeSecs = addLongs(this.m1XLargeTimeSecs, summary.m1XLargeTimeSecs);
 
290
                this.c1XLargeTimeSecs = addLongs(this.c1XLargeTimeSecs, summary.c1XLargeTimeSecs);
 
291
        }
 
292
        
 
293
        private static Long addLongs(Long a, Long b)
 
294
        {
 
295
                if (a != null && b != null) {
 
296
                        return new Long(a.longValue() + b.longValue());
 
297
                } else {
 
298
                        return null;
 
299
                }
 
300
        }
 
301
        
 
302
        public void sumFromUsageData(InstanceUsageData ud)
 
303
        {
 
304
                //Autoboxing should work because I prevented nulls everywhere
 
305
                this.diskIoMegs = this.diskIoMegs + ud.getDiskIoMegs();
 
306
                this.networkIoMegs = this.networkIoMegs + ud.getNetworkIoMegs();
 
307
        }
 
308
        
 
309
        public void sumFromPeriodType(Period period, String type)
 
310
        {
 
311
                if (period == null || type == null) {
 
312
                        throw new IllegalArgumentException("args can't be null");
 
313
                }
 
314
                long timeSecs = (period.getEndingMs() - period.getBeginningMs())/1000;
 
315
 
 
316
                //TODO: the strings here should be in an enum or something. same with events?
 
317
                //Autoboxing should work because we prevented nulls everywhere
 
318
                if (type.equalsIgnoreCase("m1.small")) {
 
319
                        this.m1SmallNum = this.m1SmallNum + 1;
 
320
                        this.m1SmallTimeSecs = this.m1SmallTimeSecs + timeSecs;
 
321
                } else if (type.equalsIgnoreCase("c1.medium")) {
 
322
                        this.c1MediumNum = this.c1MediumNum + 1;
 
323
                        this.c1MediumTimeSecs = this.c1MediumTimeSecs + timeSecs;
 
324
                } else if (type.equalsIgnoreCase("m1.large")) {
 
325
                        this.m1LargeNum = this.m1LargeNum + 1;
 
326
                        this.m1LargeTimeSecs = this.m1LargeTimeSecs + timeSecs;
 
327
                } else if (type.equalsIgnoreCase("m1.xlarge")) {
 
328
                        this.m1XLargeNum = this.m1XLargeNum + 1;
 
329
                        this.m1XLargeTimeSecs = this.m1XLargeTimeSecs + timeSecs;
 
330
                } else if (type.equalsIgnoreCase("c1.xlarge")) {
 
331
                        this.c1XLargeNum = this.c1XLargeNum + 1;
 
332
                        this.c1XLargeTimeSecs = this.c1XLargeTimeSecs + timeSecs;
 
333
                } else {
 
334
                        throw new RuntimeException("Unrecognized type:" + type);
 
335
                }
 
336
        }
 
337
        
 
338
        /**
 
339
         * toString() for logging and debugging
 
340
         */
 
341
        public String toString()
 
342
        {
 
343
                return String.format("[num,timeSecs m1Small:%d,%d c1Medium:%d,%d m1Large"
 
344
                                + ":%d,%d m1XLarge:%d,%d c1XLarge:%d,%d disk:%d net:%d]",
 
345
                                this.m1SmallNum, this.m1SmallTimeSecs, this.c1MediumNum,
 
346
                                this.c1MediumTimeSecs, this.m1LargeNum, this.m1LargeTimeSecs,
 
347
                                this.m1XLargeNum, this.m1XLargeTimeSecs, this.c1XLargeNum,
 
348
                                this.c1XLargeTimeSecs, this.diskIoMegs, this.networkIoMegs);
 
349
        }
 
350
}