Skip to content

Commit 0ba6091

Browse files
author
Alex Huang
committed
better way to log the agent request and response. Introduced the idea of via agents in the request header
1 parent e552f11 commit 0ba6091

23 files changed

Lines changed: 415 additions & 385 deletions

‎api/src/com/cloud/agent/api/Command.java‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
* all of the methods that needs to be implemented by the children classes.
2929
*
3030
*/
31-
@LogLevel(level = Log4jLevel.Debug)
3231
public abstract class Command {
3332

3433
// allow command to carry over hypervisor or other environment related context info
34+
@LogLevel(Log4jLevel.Trace)
3535
protected Map<String, String> contextMap = new HashMap<String, String>();
3636

3737
protected Command() {
@@ -56,12 +56,4 @@ public void setContextParam(String name, String value) {
5656
public String getContextParam(String name) {
5757
return contextMap.get(name);
5858
}
59-
60-
public boolean logTrace() {
61-
return false;
62-
}
63-
64-
public boolean doNotLogCommandParams() {
65-
return false;
66-
}
6759
}

‎api/src/com/cloud/agent/api/GetFileStatsAnswer.java‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,22 @@
1717
*/
1818
package com.cloud.agent.api;
1919

20+
import com.cloud.agent.api.LogLevel.Log4jLevel;
2021
import com.cloud.storage.VolumeStats;
2122

23+
@LogLevel(Log4jLevel.Trace)
2224
public class GetFileStatsAnswer extends Answer implements VolumeStats {
2325
long size;
2426
protected GetFileStatsAnswer() {
2527
}
26-
28+
2729
public GetFileStatsAnswer(GetFileStatsCommand cmd, long value) {
2830
super(cmd);
2931
size = value;
3032
}
31-
33+
3234
@Override
3335
public long getBytesUsed() {
3436
return size;
3537
}
36-
37-
@Override
38-
public boolean logTrace() {
39-
return true;
40-
}
4138
}

‎api/src/com/cloud/agent/api/GetFileStatsCommand.java‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,26 @@
1717
*/
1818
package com.cloud.agent.api;
1919

20+
import com.cloud.agent.api.LogLevel.Log4jLevel;
2021
import com.cloud.storage.Volume;
2122

23+
@LogLevel(Log4jLevel.Trace)
2224
public class GetFileStatsCommand extends Command {
2325
protected GetFileStatsCommand() {
2426
}
25-
27+
2628
String paths;
27-
29+
2830
public GetFileStatsCommand(Volume volume) {
2931
paths = volume.getPath();
3032
}
3133

3234
public String getPaths() {
3335
return paths;
3436
}
35-
37+
3638
@Override
3739
public boolean executeInSequence() {
3840
return false;
3941
}
40-
41-
@Override
42-
public boolean logTrace() {
43-
return true;
44-
}
4542
}

‎api/src/com/cloud/agent/api/GetHostStatsAnswer.java‎

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,80 +17,77 @@
1717
*/
1818
package com.cloud.agent.api;
1919

20+
import com.cloud.agent.api.LogLevel.Log4jLevel;
2021
import com.cloud.host.HostStats;
2122

2223
/**
2324
* @author ajoshi
2425
*
2526
*/
27+
@LogLevel(Log4jLevel.Trace)
2628
public class GetHostStatsAnswer extends Answer implements HostStats {
27-
28-
HostStatsEntry hostStats;
29+
30+
HostStatsEntry hostStats;
2931

3032
protected GetHostStatsAnswer() {
31-
hostStats = new HostStatsEntry();
33+
hostStats = new HostStatsEntry();
34+
}
35+
36+
public GetHostStatsAnswer(GetHostStatsCommand cmd, HostStatsEntry hostStatistics) {
37+
super(cmd);
38+
this.hostStats = hostStatistics;
3239
}
33-
34-
public GetHostStatsAnswer(GetHostStatsCommand cmd, HostStatsEntry hostStatistics) {
35-
super(cmd);
36-
this.hostStats = hostStatistics;
37-
}
38-
39-
public GetHostStatsAnswer(GetHostStatsCommand cmd, double cpuUtilization, double freeMemoryKBs, double totalMemoryKBs, double networkReadKBs,
40-
double networkWriteKBs, String entityType) {
40+
41+
public GetHostStatsAnswer(GetHostStatsCommand cmd, double cpuUtilization, double freeMemoryKBs, double totalMemoryKBs, double networkReadKBs,
42+
double networkWriteKBs, String entityType) {
4143
super(cmd);
4244
hostStats = new HostStatsEntry();
43-
45+
4446
hostStats.setCpuUtilization(cpuUtilization);
4547
hostStats.setFreeMemoryKBs(freeMemoryKBs);
4648
hostStats.setTotalMemoryKBs(totalMemoryKBs);
4749
hostStats.setNetworkReadKBs(networkReadKBs);
4850
hostStats.setNetworkWriteKBs(networkWriteKBs);
4951
hostStats.setEntityType(entityType);
5052
}
51-
53+
5254
@Override
5355
public double getUsedMemory() {
54-
return hostStats.getUsedMemory();
56+
return hostStats.getUsedMemory();
5557
}
56-
58+
5759
@Override
5860
public double getFreeMemoryKBs() {
5961
return hostStats.getFreeMemoryKBs();
6062
}
61-
63+
6264
@Override
6365
public double getTotalMemoryKBs() {
64-
return hostStats.getTotalMemoryKBs();
66+
return hostStats.getTotalMemoryKBs();
6567
}
66-
68+
6769
@Override
6870
public double getCpuUtilization() {
6971
return hostStats.getCpuUtilization();
7072
}
71-
73+
7274
@Override
7375
public double getNetworkReadKBs() {
74-
return hostStats.getNetworkReadKBs();
76+
return hostStats.getNetworkReadKBs();
7577
}
76-
78+
7779
@Override
7880
public double getNetworkWriteKBs() {
79-
return hostStats.getNetworkWriteKBs();
81+
return hostStats.getNetworkWriteKBs();
8082
}
8183

82-
@Override
83-
public String getEntityType() {
84-
return hostStats.getEntityType();
85-
}
84+
@Override
85+
public String getEntityType() {
86+
return hostStats.getEntityType();
87+
}
8688

87-
@Override
88-
public HostStats getHostStats() {
89-
return hostStats;
90-
}
91-
9289
@Override
93-
public boolean logTrace() {
94-
return true;
90+
public HostStats getHostStats() {
91+
return hostStats;
9592
}
9693
}

‎api/src/com/cloud/agent/api/GetHostStatsCommand.java‎

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,41 +17,38 @@
1717
*/
1818
package com.cloud.agent.api;
1919

20+
import com.cloud.agent.api.LogLevel.Log4jLevel;
2021

21-
public class GetHostStatsCommand extends Command
22+
@LogLevel(Log4jLevel.Trace)
23+
public class GetHostStatsCommand extends Command
2224
{
2325
String hostGuid;
2426
String hostName;
2527
long hostId;
26-
28+
2729
protected GetHostStatsCommand() {
2830
}
29-
31+
3032
public GetHostStatsCommand(String hostGuid, String hostName, long hostId) {
3133
this.hostGuid = hostGuid;
3234
this.hostName = hostName;
3335
this.hostId = hostId;
3436
}
35-
37+
3638
public String getHostGuid(){
37-
return this.hostGuid;
39+
return this.hostGuid;
3840
}
39-
41+
4042
public String getHostName(){
41-
return this.hostName;
43+
return this.hostName;
4244
}
43-
45+
4446
public long getHostId(){
45-
return this.hostId;
47+
return this.hostId;
4648
}
47-
49+
4850
@Override
4951
public boolean executeInSequence() {
5052
return false;
5153
}
52-
53-
@Override
54-
public boolean logTrace() {
55-
return true;
56-
}
5754
}

‎api/src/com/cloud/agent/api/GetStorageStatsAnswer.java‎

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,39 +17,36 @@
1717
*/
1818
package com.cloud.agent.api;
1919

20+
import com.cloud.agent.api.LogLevel.Log4jLevel;
2021
import com.cloud.storage.StorageStats;
2122

23+
@LogLevel(Log4jLevel.Trace)
2224
public class GetStorageStatsAnswer extends Answer implements StorageStats {
2325
protected GetStorageStatsAnswer() {
2426
}
25-
27+
2628
protected long used;
27-
29+
2830
protected long capacity;
29-
31+
3032
@Override
3133
public long getByteUsed() {
3234
return used;
3335
}
34-
36+
3537
@Override
3638
public long getCapacityBytes() {
3739
return capacity;
3840
}
39-
40-
41+
42+
4143
public GetStorageStatsAnswer(GetStorageStatsCommand cmd, long capacity, long used) {
4244
super(cmd, true, null);
4345
this.capacity = capacity;
4446
this.used = used;
4547
}
46-
48+
4749
public GetStorageStatsAnswer(GetStorageStatsCommand cmd, String details) {
4850
super(cmd, false, details);
4951
}
50-
51-
@Override
52-
public boolean logTrace() {
53-
return true;
54-
}
5552
}

‎api/src/com/cloud/agent/api/GetStorageStatsCommand.java‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717
*/
1818
package com.cloud.agent.api;
1919

20+
import com.cloud.agent.api.LogLevel.Log4jLevel;
2021
import com.cloud.storage.Storage.StoragePoolType;
2122

23+
@LogLevel(Log4jLevel.Trace)
2224
public class GetStorageStatsCommand extends Command {
2325
private String id;
2426
private String localPath;
2527
private StoragePoolType pooltype;
26-
28+
2729

2830
public GetStorageStatsCommand() {
2931
}
@@ -39,12 +41,12 @@ public void setPooltype(StoragePoolType pooltype) {
3941
public GetStorageStatsCommand(String id) {
4042
this.id = id;
4143
}
42-
44+
4345
public GetStorageStatsCommand(String id, StoragePoolType pooltype) {
4446
this.id = id;
4547
this.pooltype = pooltype;
4648
}
47-
49+
4850
public GetStorageStatsCommand(String id, StoragePoolType pooltype, String localPath) {
4951
this.id = id;
5052
this.pooltype = pooltype;
@@ -54,18 +56,13 @@ public GetStorageStatsCommand(String id, StoragePoolType pooltype, String localP
5456
public String getStorageId() {
5557
return this.id;
5658
}
57-
59+
5860
public String getLocalPath() {
59-
return this.localPath;
61+
return this.localPath;
6062
}
6163

6264
@Override
6365
public boolean executeInSequence() {
6466
return false;
6567
}
66-
67-
@Override
68-
public boolean logTrace() {
69-
return true;
70-
}
7168
}

‎api/src/com/cloud/agent/api/GetVmStatsAnswer.java‎

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,23 @@
2020

2121
import java.util.HashMap;
2222

23+
import com.cloud.agent.api.LogLevel.Log4jLevel;
24+
25+
@LogLevel(Log4jLevel.Trace)
2326
public class GetVmStatsAnswer extends Answer {
24-
25-
HashMap<String, VmStatsEntry> vmStatsMap;
26-
27-
public GetVmStatsAnswer(GetVmStatsCommand cmd, HashMap<String, VmStatsEntry> vmStatsMap) {
28-
super(cmd);
29-
this.vmStatsMap = vmStatsMap;
30-
}
31-
32-
public HashMap<String, VmStatsEntry> getVmStatsMap() {
33-
return vmStatsMap;
34-
}
35-
36-
protected GetVmStatsAnswer() {
37-
//no-args constructor for json serialization-deserialization
38-
}
39-
40-
@Override
41-
public boolean logTrace() {
42-
return true;
27+
28+
HashMap<String, VmStatsEntry> vmStatsMap;
29+
30+
public GetVmStatsAnswer(GetVmStatsCommand cmd, HashMap<String, VmStatsEntry> vmStatsMap) {
31+
super(cmd);
32+
this.vmStatsMap = vmStatsMap;
33+
}
34+
35+
public HashMap<String, VmStatsEntry> getVmStatsMap() {
36+
return vmStatsMap;
37+
}
38+
39+
protected GetVmStatsAnswer() {
40+
//no-args constructor for json serialization-deserialization
4341
}
4442
}

0 commit comments

Comments
 (0)