1
package com.eucalyptus.reporting.modules.instance;
3
import com.eucalyptus.reporting.Period;
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.
13
public class InstanceUsageSummary
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;
28
public InstanceUsageSummary()
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);
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,
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)
56
throw new IllegalArgumentException("ctor args cannot be null");
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;
73
public Long getM1SmallNum()
78
public void setM1SmallNum(Long m1SmallNum)
80
if (m1SmallNum == null)
81
throw new IllegalArgumentException("arg can't be null");
82
this.m1SmallNum = m1SmallNum;
85
public Long getM1SmallTimeSecs()
87
return m1SmallTimeSecs;
90
public void setM1SmallTimeSecs(Long m1SmallTimeSecs)
92
if (m1SmallTimeSecs == null)
93
throw new IllegalArgumentException("arg can't be null");
94
this.m1SmallTimeSecs = m1SmallTimeSecs;
97
public Long getC1MediumNum()
102
public void setC1MediumNum(Long c1MediumNum)
104
if (c1MediumNum == null)
105
throw new IllegalArgumentException("arg can't be null");
106
this.c1MediumNum = c1MediumNum;
109
public Long getC1MediumTimeSecs()
111
return c1MediumTimeSecs;
114
public void setC1MediumTimeSecs(Long c1MediumTimeSecs)
116
if (c1MediumTimeSecs == null)
117
throw new IllegalArgumentException("arg can't be null");
118
this.c1MediumTimeSecs = c1MediumTimeSecs;
121
public Long getM1LargeNum()
126
public void setM1LargeNum(Long m1LargeNum)
128
if (m1LargeNum == null)
129
throw new IllegalArgumentException("arg can't be null");
130
this.m1LargeNum = m1LargeNum;
133
public Long getM1LargeTimeSecs()
135
return m1LargeTimeSecs;
138
public void setM1LargeTimeSecs(Long m1LargeTimeSecs)
140
if (m1LargeTimeSecs == null)
141
throw new IllegalArgumentException("arg can't be null");
142
this.m1LargeTimeSecs = m1LargeTimeSecs;
145
public Long getM1XLargeNum()
150
public void setM1XLargeNum(Long m1XLargeNum)
152
if (m1XLargeNum == null)
153
throw new IllegalArgumentException("arg can't be null");
154
this.m1XLargeNum = m1XLargeNum;
157
public Long getM1XLargeTimeSecs()
159
return m1XLargeTimeSecs;
162
public void setM1XLargeTimeSecs(Long m1XLargeTimeSecs)
164
if (m1XLargeTimeSecs == null)
165
throw new IllegalArgumentException("arg can't be null");
166
this.m1XLargeTimeSecs = m1XLargeTimeSecs;
169
public Long getC1XLargeNum()
174
public void setC1XLargeNum(Long c1XLargeNum)
176
if (c1XLargeNum == null)
177
throw new IllegalArgumentException("arg can't be null");
178
this.c1XLargeNum = c1XLargeNum;
181
public Long getC1XLargeTimeSecs()
183
return c1XLargeTimeSecs;
186
public void setC1XLargeTimeSecs(Long c1XLargeTimeSecs)
188
if (c1XLargeTimeSecs == null)
189
throw new IllegalArgumentException("arg can't be null");
190
this.c1XLargeTimeSecs = c1XLargeTimeSecs;
193
public Long getDiskIoMegs()
198
public void setDiskIoMegs(Long diskIoMegs)
200
if (diskIoMegs == null)
201
throw new IllegalArgumentException("arg can't be null");
202
this.diskIoMegs = diskIoMegs;
205
public Long getNetworkIoMegs()
207
return networkIoMegs;
210
public void setNetworkIoMegs(Long networkIoMegs)
212
if (networkIoMegs == null)
213
throw new IllegalArgumentException("arg can't be null");
214
this.networkIoMegs = networkIoMegs;
217
void addM1SmallNum(long addBy)
219
this.m1SmallNum = new Long(this.m1SmallNum.longValue() + addBy);
222
void addM1SmallTimeSecs(long addBy)
224
this.m1SmallTimeSecs = new Long(this.m1SmallTimeSecs.longValue() + addBy);
227
void addC1MediumNum(long addBy)
229
this.c1MediumNum = new Long(this.c1MediumNum.longValue() + addBy);
232
void addC1MediumTimeSecs(long addBy)
234
this.c1MediumTimeSecs = new Long(this.c1MediumTimeSecs.longValue() + addBy);
237
void addM1LargeNum(long addBy)
239
this.m1LargeNum = new Long(this.m1LargeNum.longValue() + addBy);
242
void addM1LargeTimeSecs(long addBy)
244
this.m1LargeTimeSecs = new Long(this.m1LargeTimeSecs.longValue() + addBy);
247
void addM1XLargeNum(long addBy)
249
this.m1XLargeNum = new Long(this.m1XLargeNum.longValue() + addBy);
252
void addM1XLargeTimeSecs(long addBy)
254
this.m1XLargeTimeSecs = new Long(this.m1XLargeTimeSecs.longValue() + addBy);
257
void addC1XLargeNum(long addBy)
259
this.c1XLargeNum = new Long(this.c1XLargeNum.longValue() + addBy);
262
void addC1XLargeTimeSecs(long addBy)
264
this.c1XLargeTimeSecs = new Long(this.c1XLargeTimeSecs.longValue() + addBy);
267
void addNetworkIoMegs(long addBy)
269
this.networkIoMegs = new Long(this.networkIoMegs.longValue() + addBy);
272
void addDiskIoMegs(long addBy)
274
this.diskIoMegs = new Long(this.diskIoMegs.longValue() + addBy);
277
public void addUsage(InstanceUsageSummary summary)
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);
293
private static Long addLongs(Long a, Long b)
295
if (a != null && b != null) {
296
return new Long(a.longValue() + b.longValue());
302
public void sumFromUsageData(InstanceUsageData ud)
304
//Autoboxing should work because I prevented nulls everywhere
305
this.diskIoMegs = this.diskIoMegs + ud.getDiskIoMegs();
306
this.networkIoMegs = this.networkIoMegs + ud.getNetworkIoMegs();
309
public void sumFromPeriodType(Period period, String type)
311
if (period == null || type == null) {
312
throw new IllegalArgumentException("args can't be null");
314
long timeSecs = (period.getEndingMs() - period.getBeginningMs())/1000;
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;
334
throw new RuntimeException("Unrecognized type:" + type);
339
* toString() for logging and debugging
341
public String toString()
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);