Skip to content

Commit b8d91ef

Browse files
committed
Improve logging to include more identifiable information for kvm plugin
1 parent 019f2c6 commit b8d91ef

File tree

6 files changed

+25
-24
lines changed

6 files changed

+25
-24
lines changed

engine/schema/src/main/java/com/cloud/storage/VolumeVO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ public void setUpdated(Date updated) {
511511

512512
@Override
513513
public String toString() {
514-
return new StringBuilder("Vol[").append(id).append("|name=").append(name).append("|vm=").append(instanceId).append("|").append(volumeType).append("]").toString();
514+
return String.format("StoragePool %s", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, "id", "name", "uuid", "volumeType", "instanceId"));
515515
}
516516

517517
@Override

engine/schema/src/main/java/org/apache/cloudstack/engine/cloud/entity/api/db/VMEntityVO.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import com.cloud.vm.VirtualMachine.State;
5151
import com.google.gson.Gson;
5252
import org.apache.cloudstack.util.HypervisorTypeConverter;
53+
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
5354

5455
@Entity
5556
@Table(name = "vm_instance")
@@ -460,7 +461,7 @@ public void setDetails(Map<String, String> details) {
460461
@Override
461462
public String toString() {
462463
if (toString == null) {
463-
toString = new StringBuilder("VM[").append(type.toString()).append("|").append(hostName).append("]").toString();
464+
toString = String.format("VM %s", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, "id", "instanceName", "uuid", "type"));
464465
}
465466
return toString;
466467
}

engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/StoragePoolVO.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.cloud.utils.db.Encrypt;
2727
import com.cloud.utils.db.GenericDao;
2828
import org.apache.cloudstack.util.HypervisorTypeConverter;
29+
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
2930

3031
import javax.persistence.Column;
3132
import javax.persistence.Convert;
@@ -370,7 +371,7 @@ public int hashCode() {
370371

371372
@Override
372373
public String toString() {
373-
return new StringBuilder("Pool[").append(id).append("|").append(poolType).append("]").toString();
374+
return String.format("StoragePool %s", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, "id", "name", "uuid", "poolType"));
374375
}
375376

376377
@Override

plugins/hypervisors/kvm/src/main/java/com/cloud/ha/KVMInvestigator.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public boolean isVmAlive(com.cloud.vm.VirtualMachine vm, Host host) throws Unkno
6060
return haManager.isVMAliveOnHost(host);
6161
}
6262
Status status = isAgentAlive(host);
63-
logger.debug("HA: HOST is ineligible legacy state " + status + " for host " + host.getId());
63+
logger.debug("HA: HOST is ineligible legacy state {} for host {}", status, host);
6464
if (status == null) {
6565
throw new UnknownVM();
6666
}
@@ -88,8 +88,7 @@ public Status isAgentAlive(Host agent) {
8888
storageSupportHA = storageSupportHa(zonePools);
8989
}
9090
if (!storageSupportHA) {
91-
logger.warn(
92-
"Agent investigation was requested on host " + agent + ", but host does not support investigation because it has no NFS storage. Skipping investigation.");
91+
logger.warn("Agent investigation was requested on host {}, but host does not support investigation because it has no NFS storage. Skipping investigation.", agent);
9392
return Status.Disconnected;
9493
}
9594

@@ -104,7 +103,7 @@ public Status isAgentAlive(Host agent) {
104103
hostStatus = answer.getResult() ? Status.Down : Status.Up;
105104
}
106105
} catch (Exception e) {
107-
logger.debug("Failed to send command to host: " + agent.getId());
106+
logger.debug("Failed to send command to host: {}", agent);
108107
}
109108
if (hostStatus == null) {
110109
hostStatus = Status.Disconnected;
@@ -116,18 +115,18 @@ public Status isAgentAlive(Host agent) {
116115
|| (neighbor.getHypervisorType() != Hypervisor.HypervisorType.KVM && neighbor.getHypervisorType() != Hypervisor.HypervisorType.LXC)) {
117116
continue;
118117
}
119-
logger.debug("Investigating host:" + agent.getId() + " via neighbouring host:" + neighbor.getId());
118+
logger.debug("Investigating host:{} via neighbouring host:{}", agent, neighbor);
120119
try {
121120
Answer answer = _agentMgr.easySend(neighbor.getId(), cmd);
122121
if (answer != null) {
123122
neighbourStatus = answer.getResult() ? Status.Down : Status.Up;
124-
logger.debug("Neighbouring host:" + neighbor.getId() + " returned status:" + neighbourStatus + " for the investigated host:" + agent.getId());
123+
logger.debug("Neighbouring host:{} returned status:{} for the investigated host:{}", neighbor, neighbourStatus, agent);
125124
if (neighbourStatus == Status.Up) {
126125
break;
127126
}
128127
}
129128
} catch (Exception e) {
130-
logger.debug("Failed to send command to host: " + neighbor.getId());
129+
logger.debug("Failed to send command to host: {}", neighbor);
131130
}
132131
}
133132
if (neighbourStatus == Status.Up && (hostStatus == Status.Disconnected || hostStatus == Status.Down)) {
@@ -136,7 +135,7 @@ public Status isAgentAlive(Host agent) {
136135
if (neighbourStatus == Status.Down && (hostStatus == Status.Disconnected || hostStatus == Status.Down)) {
137136
hostStatus = Status.Down;
138137
}
139-
logger.debug("HA: HOST is ineligible legacy state " + hostStatus + " for host " + agent.getId());
138+
logger.debug("HA: HOST is ineligible legacy state {} for host {}", hostStatus, agent);
140139
return hostStatus;
141140
}
142141

plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ public boolean recover(Host r) throws HARecoveryException {
7373
final OutOfBandManagementResponse resp = outOfBandManagementService.executePowerOperation(r, PowerOperation.RESET, null);
7474
return resp.getSuccess();
7575
} else {
76-
logger.warn("OOBM recover operation failed for the host " + r.getName());
76+
logger.warn("OOBM recover operation failed for the host {}", r);
7777
return false;
7878
}
7979
} catch (Exception e){
80-
logger.warn("OOBM service is not configured or enabled for this host " + r.getName() + " error is " + e.getMessage());
81-
throw new HARecoveryException(" OOBM service is not configured or enabled for this host " + r.getName(), e);
80+
logger.warn("OOBM service is not configured or enabled for this host {} error is {}", r, e.getMessage());
81+
throw new HARecoveryException(" OOBM service is not configured or enabled for this host " + r, e);
8282
}
8383
}
8484

@@ -90,11 +90,11 @@ public boolean fence(Host r) throws HAFenceException {
9090
final OutOfBandManagementResponse resp = outOfBandManagementService.executePowerOperation(r, PowerOperation.OFF, null);
9191
return resp.getSuccess();
9292
} else {
93-
logger.warn("OOBM fence operation failed for this host " + r.getName());
93+
logger.warn("OOBM fence operation failed for this host {}", r);
9494
return false;
9595
}
9696
} catch (Exception e){
97-
logger.warn("OOBM service is not configured or enabled for this host " + r.getName() + " error is " + e.getMessage());
97+
logger.warn("OOBM service is not configured or enabled for this host {} error is {}", r, e.getMessage());
9898
throw new HAFenceException("OBM service is not configured or enabled for this host " + r.getName() , e);
9999
}
100100
}

plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHostActivityChecker.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ private boolean isVMActivtyOnHost(Host agent, DateTime suspectTime) throws HAChe
155155
for (StoragePool pool : poolVolMap.keySet()) {
156156
activityStatus = verifyActivityOfStorageOnHost(poolVolMap, pool, agent, suspectTime, activityStatus);
157157
if (!activityStatus) {
158-
logger.warn(String.format("It seems that the storage pool [%s] does not have activity on %s.", pool.getId(), agent.toString()));
158+
logger.warn("It seems that the storage pool [{}] does not have activity on {}.", pool, agent.toString());
159159
break;
160160
}
161161
}
@@ -167,20 +167,20 @@ protected boolean verifyActivityOfStorageOnHost(HashMap<StoragePool, List<Volume
167167
List<Volume> volume_list = poolVolMap.get(pool);
168168
final CheckVMActivityOnStoragePoolCommand cmd = new CheckVMActivityOnStoragePoolCommand(agent, pool, volume_list, suspectTime);
169169

170-
logger.debug(String.format("Checking VM activity for %s on storage pool [%s].", agent.toString(), pool.getId()));
170+
logger.debug("Checking VM activity for {} on storage pool [{}].", agent.toString(), pool);
171171
try {
172172
Answer answer = storageManager.sendToPool(pool, getNeighbors(agent), cmd);
173173

174174
if (answer != null) {
175175
activityStatus = !answer.getResult();
176-
logger.debug(String.format("%s %s activity on storage pool [%s]", agent.toString(), activityStatus ? "has" : "does not have", pool.getId()));
176+
logger.debug("{} {} activity on storage pool [{}]", agent.toString(), activityStatus ? "has" : "does not have", pool);
177177
} else {
178-
String message = String.format("Did not get a valid response for VM activity check for %s on storage pool [%s].", agent.toString(), pool.getId());
178+
String message = String.format("Did not get a valid response for VM activity check for %s on storage pool [%s].", agent.toString(), pool);
179179
logger.debug(message);
180180
throw new IllegalStateException(message);
181181
}
182182
} catch (StorageUnavailableException e){
183-
String message = String.format("Storage [%s] is unavailable to do the check, probably the %s is not reachable.", pool.getId(), agent.toString());
183+
String message = String.format("Storage [%s] is unavailable to do the check, probably the %s is not reachable.", pool, agent.toString());
184184
logger.warn(message, e);
185185
throw new HACheckerException(message, e);
186186
}
@@ -191,15 +191,15 @@ private HashMap<StoragePool, List<Volume>> getVolumeUuidOnHost(Host agent) {
191191
List<VMInstanceVO> vm_list = vmInstanceDao.listByHostId(agent.getId());
192192
List<VolumeVO> volume_list = new ArrayList<VolumeVO>();
193193
for (VirtualMachine vm : vm_list) {
194-
logger.debug(String.format("Retrieving volumes of VM [%s]...", vm.getId()));
194+
logger.debug("Retrieving volumes of VM [{}]...", vm);
195195
List<VolumeVO> vm_volume_list = volumeDao.findByInstance(vm.getId());
196196
volume_list.addAll(vm_volume_list);
197197
}
198198

199199
HashMap<StoragePool, List<Volume>> poolVolMap = new HashMap<StoragePool, List<Volume>>();
200200
for (Volume vol : volume_list) {
201-
logger.debug(String.format("Retrieving storage pool [%s] of volume [%s]...", vol.getPoolId(), vol.getId()));
202201
StoragePool sp = storagePool.findById(vol.getPoolId());
202+
logger.debug("Retrieving storage pool [{}] of volume [{}]...", sp, vol);
203203
if (!poolVolMap.containsKey(sp)) {
204204
List<Volume> list = new ArrayList<Volume>();
205205
list.add(vol);
@@ -215,7 +215,7 @@ private HashMap<StoragePool, List<Volume>> getVolumeUuidOnHost(Host agent) {
215215
public long[] getNeighbors(Host agent) {
216216
List<Long> neighbors = new ArrayList<Long>();
217217
List<HostVO> cluster_hosts = resourceManager.listHostsInClusterByStatus(agent.getClusterId(), Status.Up);
218-
logger.debug(String.format("Retrieving all \"Up\" hosts from cluster [%s]...", agent.getClusterId()));
218+
logger.debug("Retrieving all \"Up\" hosts from cluster [{}]...", agent.getClusterId());
219219
for (HostVO host : cluster_hosts) {
220220
if (host.getId() == agent.getId() || (host.getHypervisorType() != Hypervisor.HypervisorType.KVM && host.getHypervisorType() != Hypervisor.HypervisorType.LXC)) {
221221
continue;

0 commit comments

Comments
 (0)