diff --git a/engine/orchestration/src/main/java/com/cloud/agent/manager/ClusteredAgentManagerImpl.java b/engine/orchestration/src/main/java/com/cloud/agent/manager/ClusteredAgentManagerImpl.java index 7a16971ee71d..fa24df290d34 100644 --- a/engine/orchestration/src/main/java/com/cloud/agent/manager/ClusteredAgentManagerImpl.java +++ b/engine/orchestration/src/main/java/com/cloud/agent/manager/ClusteredAgentManagerImpl.java @@ -286,7 +286,7 @@ protected AgentAttache createAttacheForConnect(final HostVO host, final Link lin @Override protected AgentAttache createAttacheForDirectConnect(final Host host, final ServerResource resource) { - s_logger.debug("create ClusteredDirectAgentAttache for " + host.getId()); + s_logger.debug(String.format("Create ClusteredDirectAgentAttache for %s.", host)); final DirectAgentAttache attache = new ClusteredDirectAgentAttache(this, host.getId(), host.getName(), _nodeId, resource, host.isInMaintenanceStates()); AgentAttache old = null; synchronized (_agents) { diff --git a/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java b/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java index 0cb766e7b6ee..618e79c312f7 100755 --- a/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java @@ -4345,19 +4345,25 @@ private void orchestrateMigrateForScale(final String vmUuid, final long srcHostI throws ResourceUnavailableException, ConcurrentOperationException { VMInstanceVO vm = _vmDao.findByUuid(vmUuid); - s_logger.info("Migrating " + vm + " to " + dest); + s_logger.info(String.format("Migrating %s to %s", vm, dest)); vm.getServiceOfferingId(); final long dstHostId = dest.getHost().getId(); final Host fromHost = _hostDao.findById(srcHostId); + Host srcHost = _hostDao.findById(srcHostId); if (fromHost == null) { - s_logger.info("Unable to find the host to migrate from: " + srcHostId); - throw new CloudRuntimeException("Unable to find the host to migrate from: " + srcHostId); + String logMessageUnableToFindHost = String.format("Unable to find host to migrate from %s.", srcHost); + s_logger.info(logMessageUnableToFindHost); + throw new CloudRuntimeException(logMessageUnableToFindHost); } - if (fromHost.getClusterId().longValue() != dest.getCluster().getId()) { - s_logger.info("Source and destination host are not in same cluster, unable to migrate to host: " + dstHostId); - throw new CloudRuntimeException("Source and destination host are not in same cluster, unable to migrate to host: " + dest.getHost().getId()); + Host dstHost = _hostDao.findById(dstHostId); + long destHostClusterId = dest.getCluster().getId(); + long fromHostClusterId = fromHost.getClusterId(); + if (fromHostClusterId != destHostClusterId) { + String logMessageHostsOnDifferentCluster = String.format("Source and destination host are not in same cluster, unable to migrate to %s", srcHost); + s_logger.info(logMessageHostsOnDifferentCluster); + throw new CloudRuntimeException(logMessageHostsOnDifferentCluster); } final VirtualMachineGuru vmGuru = getVmGuru(vm); @@ -4474,13 +4480,13 @@ private void orchestrateMigrateForScale(final String vmUuid, final long srcHostI try { _agentMgr.send(srcHostId, new Commands(cleanup(vm.getInstanceName())), null); } catch (final AgentUnavailableException e) { - s_logger.error("AgentUnavailableException while cleanup on source host: " + srcHostId); + s_logger.error(String.format("Unable to cleanup source %s. ", srcHost), e); } cleanup(vmGuru, new VirtualMachineProfileImpl(vm), work, Event.AgentReportStopped, true); throw new CloudRuntimeException("Unable to complete migration for " + vm); } } catch (final OperationTimedoutException e) { - s_logger.debug("Error while checking the vm " + vm + " on host " + dstHostId, e); + s_logger.debug(String.format("Error while checking the %s on %s", vm, dstHost), e); } migrated = true; @@ -4488,9 +4494,10 @@ private void orchestrateMigrateForScale(final String vmUuid, final long srcHostI if (!migrated) { s_logger.info("Migration was unsuccessful. Cleaning up: " + vm); - _alertMgr.sendAlert(alertType, fromHost.getDataCenterId(), fromHost.getPodId(), - "Unable to migrate vm " + vm.getInstanceName() + " from host " + fromHost.getName() + " in zone " + dest.getDataCenter().getName() + " and pod " + - dest.getPod().getName(), "Migrate Command failed. Please check logs."); + String alertSubject = String.format("Unable to migrate %s from %s in Zone [%s] and Pod [%s].", + vm.getInstanceName(), fromHost, dest.getDataCenter().getName(), dest.getPod().getName()); + String alertBody = "Migrate Command failed. Please check logs."; + _alertMgr.sendAlert(alertType, fromHost.getDataCenterId(), fromHost.getPodId(), alertSubject, alertBody); try { _agentMgr.send(dstHostId, new Commands(cleanup(vm.getInstanceName())), null); } catch (final AgentUnavailableException ae) { @@ -4840,6 +4847,8 @@ private void handlePowerOnReportWithNoPendingJobsOnVM(final VMInstanceVO vm) { // 3) handle out of sync stationary states, marking VM from Stopped to Running with // alert messages // + Host host = _hostDao.findById(vm.getHostId()); + Host poweredHost = _hostDao.findById(vm.getPowerHostId()); switch (vm.getState()) { case Starting: s_logger.info("VM " + vm.getInstanceName() + " is at " + vm.getState() + " and we received a power-on report while there is no pending jobs on it"); @@ -4861,7 +4870,7 @@ private void handlePowerOnReportWithNoPendingJobsOnVM(final VMInstanceVO vm) { case Running: try { if (vm.getHostId() != null && vm.getHostId().longValue() != vm.getPowerHostId().longValue()) { - s_logger.info("Detected out of band VM migration from host " + vm.getHostId() + " to host " + vm.getPowerHostId()); + s_logger.info(String.format("Detected out of band VM migration from %s to %s", host, poweredHost)); } stateTransitTo(vm, VirtualMachine.Event.FollowAgentPowerOnReport, vm.getPowerHostId()); } catch (final NoTransitionException e) { diff --git a/engine/schema/src/main/java/com/cloud/dc/ClusterVO.java b/engine/schema/src/main/java/com/cloud/dc/ClusterVO.java index 2a76789136a9..f60765e28566 100644 --- a/engine/schema/src/main/java/com/cloud/dc/ClusterVO.java +++ b/engine/schema/src/main/java/com/cloud/dc/ClusterVO.java @@ -196,4 +196,9 @@ public void setUuid(String uuid) { public PartitionType partitionType() { return PartitionType.Cluster; } + + @Override + public String toString() { + return String.format("Cluster {id: \"%s\", name: \"%s\", uuid: \"%s\"}", id, name, uuid); + } } diff --git a/engine/schema/src/main/java/com/cloud/vm/VMInstanceVO.java b/engine/schema/src/main/java/com/cloud/vm/VMInstanceVO.java index aa2e7360bf4b..afc7134990c9 100644 --- a/engine/schema/src/main/java/com/cloud/vm/VMInstanceVO.java +++ b/engine/schema/src/main/java/com/cloud/vm/VMInstanceVO.java @@ -506,7 +506,7 @@ public void setRemoved(Date removed) { @Override public String toString() { - return String.format("VM instance {\"id\": \"%s\", \"name\": \"%s\", \"uuid\": \"%s\", \"type\"=\"%s\"}", id, getInstanceName(), uuid, type); + return String.format("VM instance {id: \"%s\", name: \"%s\", uuid: \"%s\", type=\"%s\"}", id, getInstanceName(), uuid, type); } @Override diff --git a/server/src/main/java/com/cloud/capacity/CapacityManagerImpl.java b/server/src/main/java/com/cloud/capacity/CapacityManagerImpl.java index a5c1f3b4927e..05ea9fd94ca2 100644 --- a/server/src/main/java/com/cloud/capacity/CapacityManagerImpl.java +++ b/server/src/main/java/com/cloud/capacity/CapacityManagerImpl.java @@ -926,8 +926,11 @@ public boolean postStateTransitionEvent(StateMachine2.Transition t State oldState = transition.getCurrentState(); State newState = transition.getToState(); Event event = transition.getEvent(); - s_logger.debug("VM state transitted from :" + oldState + " to " + newState + " with event: " + event + "vm's original host id: " + vm.getLastHostId() + - " new host id: " + vm.getHostId() + " host id before state transition: " + oldHostId); + Host lastHost = _hostDao.findById(vm.getLastHostId()); + Host oldHost = _hostDao.findById(oldHostId); + Host newHost = _hostDao.findById(vm.getHostId()); + s_logger.debug(String.format("%s state transited from [%s] to [%s] with event [%s]. VM's original host: %s, new host: %s, host before state transition: %s", vm, oldState, + newState, event, lastHost, newHost, oldHost)); if (oldState == State.Starting) { if (newState != State.Running) { diff --git a/server/src/main/java/com/cloud/network/element/VirtualRouterElement.java b/server/src/main/java/com/cloud/network/element/VirtualRouterElement.java index 9191ddddb5b9..d101a5e4f607 100644 --- a/server/src/main/java/com/cloud/network/element/VirtualRouterElement.java +++ b/server/src/main/java/com/cloud/network/element/VirtualRouterElement.java @@ -411,12 +411,13 @@ public boolean stopVpn(final RemoteAccessVpn vpn) throws ResourceUnavailableExce if (canHandle(network, Service.Vpn)) { final List routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER); if (routers == null || routers.isEmpty()) { - s_logger.debug("Virtual router elemnt doesn't need stop vpn on the backend; virtual router doesn't " + "exist in the network " + network.getId()); + s_logger.debug(String.format("There is no virtual router in network [uuid: %s, name: %s], it is not necessary to stop the VPN on backend.", + network.getUuid(), network.getName())); return true; } return _routerMgr.deleteRemoteAccessVpn(network, vpn, routers); } else { - s_logger.debug("Element " + getName() + " doesn't handle removeVpn command"); + s_logger.debug(String.format("Element %s doesn't handle removeVpn command", getName())); return false; } } diff --git a/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java b/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java index ca3505fb6800..488be99e32da 100755 --- a/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java +++ b/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java @@ -909,6 +909,7 @@ public void doInTransactionWithoutResult(final TransactionStatus status) { host.setClusterId(null); _hostDao.update(host.getId(), host); + Host hostRemoved = _hostDao.findById(hostId); _hostDao.remove(hostId); if (clusterId != null) { final List hosts = listAllHostsInCluster(clusterId); @@ -922,7 +923,7 @@ public void doInTransactionWithoutResult(final TransactionStatus status) { try { resourceStateTransitTo(host, ResourceState.Event.DeleteHost, _nodeId); } catch (final NoTransitionException e) { - s_logger.debug("Cannot transmit host " + host.getId() + " to Enabled state", e); + s_logger.debug(String.format("Cannot transit %s to Enabled state", host), e); } // Delete the associated entries in host ref table @@ -947,7 +948,7 @@ public void doInTransactionWithoutResult(final TransactionStatus status) { storagePool.setClusterId(null); _storagePoolDao.update(poolId, storagePool); _storagePoolDao.remove(poolId); - s_logger.debug("Local storage id=" + poolId + " is removed as a part of host removal id=" + hostId); + s_logger.debug(String.format("Local storage [id: %s] is removed as a part of %s removal", poolId, hostRemoved.toString())); } } @@ -1278,7 +1279,7 @@ private boolean doMaintain(final long hostId) { try { resourceStateTransitTo(host, ResourceState.Event.AdminAskMaintenance, _nodeId); } catch (final NoTransitionException e) { - final String err = "Cannot transmit resource state of host " + host.getId() + " to " + ResourceState.Maintenance; + final String err = String.format("Cannot transit resource state of %s to %s", host, ResourceState.Maintenance); s_logger.debug(err, e); throw new CloudRuntimeException(err + e.getMessage()); } @@ -1530,7 +1531,7 @@ protected boolean setHostIntoPrepareForMaintenanceAfterErrorsFixed(HostVO host) protected boolean attemptMaintain(HostVO host) throws NoTransitionException { final long hostId = host.getId(); - s_logger.info("Attempting maintenance for host " + host.getName()); + s_logger.info(String.format("Attempting maintenance for %s", host)); // Step 0: First gather if VMs have pending HAWork for migration with retries left. final List allVmsOnHost = _vmDao.listByHostId(hostId); @@ -1538,7 +1539,7 @@ protected boolean attemptMaintain(HostVO host) throws NoTransitionException { boolean hasPendingMigrationRetries = false; for (VMInstanceVO vmInstanceVO : allVmsOnHost) { if (_haMgr.hasPendingMigrationsWork(vmInstanceVO.getId())) { - s_logger.info("Attempting maintenance for " + host + " found pending migration for VM " + vmInstanceVO); + s_logger.info(String.format("Attempting maintenance for %s found pending migration for %s.", host, vmInstanceVO)); hasPendingMigrationRetries = true; break; } @@ -1595,7 +1596,7 @@ public boolean checkAndMaintain(final long hostId) { hostInMaintenance = attemptMaintain(host); } } catch (final NoTransitionException e) { - s_logger.debug("Cannot transmit host " + host.getId() + " to Maintenance state", e); + s_logger.warn(String.format("Cannot transit %s from %s to Maintenance state.", host, host.getResourceState()), e); } return hostInMaintenance; } @@ -2062,12 +2063,12 @@ protected HostVO createHostVO(final StartupCommand[] cmds, final ServerResource /* Agent goes to Connecting status */ _agentMgr.agentStatusTransitTo(host, Status.Event.AgentConnected, _nodeId); } catch (final Exception e) { - s_logger.debug("Cannot transmit host " + host.getId() + " to Creating state", e); + s_logger.debug(String.format("Cannot transit %s to Creating state", host), e); _agentMgr.agentStatusTransitTo(host, Status.Event.Error, _nodeId); try { resourceStateTransitTo(host, ResourceState.Event.Error, _nodeId); } catch (final NoTransitionException e1) { - s_logger.debug("Cannot transmit host " + host.getId() + "to Error state", e); + s_logger.debug(String.format("Cannot transit %s to Error state", host), e); } } @@ -2202,7 +2203,7 @@ private Host createHostAndAgent(final ServerResource resource, final Map " + host.getUuid() + " / " + host.getId() + ". Please make sure you are still able to connect to your hosts."); + throw new CloudRuntimeException( + String.format("CloudStack failed to update the password of %s. Please make sure you are still able to connect to your hosts.", host)); } } } @@ -2797,8 +2799,7 @@ public boolean migrateAwayFailed(final long hostId, final long vmId) { ". Emitting event UnableToMigrate."); return resourceStateTransitTo(host, ResourceState.Event.UnableToMigrate, _nodeId); } catch (final NoTransitionException e) { - s_logger.debug("No next resource state for host " + host.getId() + " while current state is " + host.getResourceState() + " with event " + - ResourceState.Event.UnableToMigrate, e); + s_logger.debug(String.format("No next resource state for %s while current state is [%s] with event %s", host, host.getResourceState(), ResourceState.Event.UnableToMigrate), e); return false; } } @@ -3117,7 +3118,7 @@ public HashMap> getGPUStatistics(final Ho return null; } if (answer == null || !answer.getResult()) { - final String msg = "Unable to obtain GPU stats for host " + host.getName(); + final String msg = String.format("Unable to obtain GPU stats for %s", host); s_logger.warn(msg); return null; } else { diff --git a/server/src/main/java/com/cloud/resource/RollingMaintenanceManagerImpl.java b/server/src/main/java/com/cloud/resource/RollingMaintenanceManagerImpl.java index 0bc88276fad7..80a243156aa0 100644 --- a/server/src/main/java/com/cloud/resource/RollingMaintenanceManagerImpl.java +++ b/server/src/main/java/com/cloud/resource/RollingMaintenanceManagerImpl.java @@ -395,7 +395,7 @@ private Ternary performMaintenanceStageOnHost(Host hos * @throws AgentUnavailableException */ private void putHostIntoMaintenance(Host host) throws InterruptedException, AgentUnavailableException { - s_logger.debug("Trying to set the host " + host.getId() + " into maintenance"); + s_logger.debug(String.format("Trying to set %s into maintenance", host)); PrepareForMaintenanceCmd cmd = new PrepareForMaintenanceCmd(); cmd.setId(host.getId()); resourceManager.maintain(cmd); @@ -423,9 +423,9 @@ private void enableClusterIfDisabled(Cluster cluster, Set disabledClusters private Ternary reCheckCapacityBeforeMaintenanceOnHost(Cluster cluster, Host host, Boolean forced, List hostsSkipped) { Pair capacityCheckBeforeMaintenance = performCapacityChecksBeforeHostInMaintenance(host, cluster); if (!capacityCheckBeforeMaintenance.first()) { - String errorMsg = "Capacity check failed for host " + host.getUuid() + ": " + capacityCheckBeforeMaintenance.second(); + String errorMsg = String.format("Capacity check failed for %s: %s", host, capacityCheckBeforeMaintenance.second()); if (forced) { - s_logger.info("Skipping host " + host.getUuid() + " as: " + errorMsg); + s_logger.info(String.format("Skipping %s as: %s", host, errorMsg)); hostsSkipped.add(new HostSkipped(host, errorMsg)); return new Ternary<>(true, true, capacityCheckBeforeMaintenance.second()); } @@ -439,9 +439,9 @@ private Ternary reCheckCapacityBeforeMaintenanceOnHost */ private boolean isMaintenanceStageAvoided(Host host, Map hostsToAvoidMaintenance, List hostsSkipped) { if (hostsToAvoidMaintenance.containsKey(host.getId())) { - s_logger.debug("Host " + host.getId() + " is not being put into maintenance, skipping it"); HostSkipped hostSkipped = new HostSkipped(host, hostsToAvoidMaintenance.get(host.getId())); hostsSkipped.add(hostSkipped); + s_logger.debug(String.format("%s is in avoid maintenance list [hosts skipped: %d], skipping its maintenance.", host, hostsSkipped.size())); return true; } return false; @@ -468,7 +468,7 @@ private Ternary performPreMaintenanceStageOnHost(Host return new Ternary<>(true, false, result.second()); } if (result.third() && !hostsToAvoidMaintenance.containsKey(host.getId())) { - s_logger.debug("Host " + host.getId() + " added to the avoid maintenance set"); + logHostAddedToAvoidMaintenanceSet(host); hostsToAvoidMaintenance.put(host.getId(), "Pre-maintenance stage set to avoid maintenance"); } return new Ternary<>(false, false, result.second()); @@ -491,7 +491,7 @@ private boolean isMaintenanceScriptDefinedOnHost(Host host, List ho RollingMaintenanceAnswer answer = (RollingMaintenanceAnswer) agentManager.send(host.getId(), new RollingMaintenanceCommand(true)); return answer.isMaintenaceScriptDefined(); } catch (AgentUnavailableException | OperationTimedoutException e) { - String msg = "Could not check for maintenance script on host " + host.getId() + " due to: " + e.getMessage(); + String msg = String.format("Could not check for maintenance script on %s due to: %s", host, e.getMessage()); s_logger.error(msg, e); return false; } @@ -537,8 +537,8 @@ private Ternary sendRollingMaintenanceCommandToHost(Ho answer = agentManager.send(host.getId(), cmd); } catch (AgentUnavailableException | OperationTimedoutException e) { // Agent may be restarted on the scripts - continue polling until it is up - String msg = "Cannot send command to host: " + host.getId() + ", waiting " + pingInterval + "ms - " + e.getMessage(); - s_logger.warn(msg); + String msg = String.format("Cannot send command to %s, waiting %sms - %s", host, pingInterval, e.getMessage()); + s_logger.warn(msg, e); cmd.setStarted(true); Thread.sleep(pingInterval); timeSpent += pingInterval; @@ -571,12 +571,16 @@ private void performPreFlightChecks(List hosts, int timeout, String payloa for (Host host : hosts) { Ternary result = performStageOnHost(host, Stage.PreFlight, timeout, payload, forced); if (result.third() && !hostsToAvoidMaintenance.containsKey(host.getId())) { - s_logger.debug("Host " + host.getId() + " added to the avoid maintenance set"); + logHostAddedToAvoidMaintenanceSet(host); hostsToAvoidMaintenance.put(host.getId(), "Pre-flight stage set to avoid maintenance"); } } } + private void logHostAddedToAvoidMaintenanceSet(Host host) { + s_logger.debug(String.format("%s added to the avoid maintenance set.", host)); + } + /** * Capacity checks on hosts */ @@ -584,7 +588,7 @@ private void performCapacityChecks(Cluster cluster, List hosts, Boolean fo for (Host host : hosts) { Pair result = performCapacityChecksBeforeHostInMaintenance(host, cluster); if (!result.first() && !forced) { - throw new CloudRuntimeException("Capacity check failed for host " + host.getUuid() + ": " + result.second()); + throw new CloudRuntimeException(String.format("Capacity check failed for %s : %s", host, result.second())); } } } @@ -616,8 +620,7 @@ private Pair performCapacityChecksBeforeHostInMaintenance(Host ServiceOfferingVO serviceOffering = serviceOfferingDao.findById(runningVM.getServiceOfferingId()); for (Host hostInCluster : hostsInCluster) { if (!checkHostTags(hostTags, hostTagsDao.gethostTags(hostInCluster.getId()), serviceOffering.getHostTag())) { - s_logger.debug("Host tags mismatch between host " + host.getUuid() + " and host " + hostInCluster.getUuid() + - ". Skipping it from the capacity check"); + s_logger.debug(String.format("Host tags mismatch between %s and %s Skipping it from the capacity check", host, hostInCluster)); continue; } DeployDestination deployDestination = new DeployDestination(null, null, null, host); @@ -627,8 +630,7 @@ private Pair performCapacityChecksBeforeHostInMaintenance(Host affinityChecks = affinityChecks && affinityProcessor.check(vmProfile, deployDestination); } if (!affinityChecks) { - s_logger.debug("Affinity check failed between host " + host.getUuid() + " and host " + hostInCluster.getUuid() + - ". Skipping it from the capacity check"); + s_logger.debug(String.format("Affinity check failed between %s and %s Skipping it from the capacity check", host, hostInCluster)); continue; } boolean maxGuestLimit = capacityManager.checkIfHostReachMaxGuestLimit(host); @@ -647,15 +649,15 @@ private Pair performCapacityChecksBeforeHostInMaintenance(Host } } if (!canMigrateVm) { - String msg = "VM " + runningVM.getUuid() + " cannot be migrated away from host " + host.getUuid() + - " to any other host in the cluster"; + String msg = String.format("%s cannot be migrated away from %s to any other host in the cluster", runningVM, host); s_logger.error(msg); return new Pair<>(false, msg); } sucessfullyCheckedVmMigrations++; } if (sucessfullyCheckedVmMigrations != vmsRunning.size()) { - return new Pair<>(false, "Host " + host.getId() + " cannot enter maintenance mode as capacity check failed for hosts in cluster " + cluster.getUuid()); + String migrationCheckDetails = String.format("%s cannot enter maintenance mode as capacity check failed for hosts in cluster %s", host, cluster); + return new Pair<>(false, migrationCheckDetails); } return new Pair<>(true, "OK"); } @@ -735,4 +737,4 @@ public String getConfigComponentName() { public ConfigKey[] getConfigKeys() { return new ConfigKey[] {KvmRollingMaintenanceStageTimeout, KvmRollingMaintenancePingInterval, KvmRollingMaintenanceWaitForMaintenanceTimeout}; } -} \ No newline at end of file +} diff --git a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java index c1743e74623d..4ba6591a6cf9 100644 --- a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java @@ -5255,7 +5255,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) { } }); } catch (Exception e) { - s_logger.warn("Unable to update vm disk statistics for vm: " + userVm.getId() + " from host: " + hostId, e); + s_logger.warn(String.format("Unable to update VM disk statistics for %s from %s", userVm.getInstanceName(), host), e); } } } diff --git a/server/src/main/java/org/apache/cloudstack/agent/lb/IndirectAgentLBServiceImpl.java b/server/src/main/java/org/apache/cloudstack/agent/lb/IndirectAgentLBServiceImpl.java index a25575cd175a..003664cc5e7c 100644 --- a/server/src/main/java/org/apache/cloudstack/agent/lb/IndirectAgentLBServiceImpl.java +++ b/server/src/main/java/org/apache/cloudstack/agent/lb/IndirectAgentLBServiceImpl.java @@ -221,7 +221,7 @@ public void propagateMSListToAgents() { final SetupMSListCommand cmd = new SetupMSListCommand(msList, lbAlgorithm, lbCheckInterval); final Answer answer = agentManager.easySend(host.getId(), cmd); if (answer == null || !answer.getResult()) { - LOG.warn("Failed to setup management servers list to the agent of host id=" + host.getId()); + LOG.warn(String.format("Failed to setup management servers list to the agent of %s", host)); } } } diff --git a/server/src/main/java/org/apache/cloudstack/outofbandmanagement/OutOfBandManagementServiceImpl.java b/server/src/main/java/org/apache/cloudstack/outofbandmanagement/OutOfBandManagementServiceImpl.java index 89f6ae718ee6..a956cf6727b5 100644 --- a/server/src/main/java/org/apache/cloudstack/outofbandmanagement/OutOfBandManagementServiceImpl.java +++ b/server/src/main/java/org/apache/cloudstack/outofbandmanagement/OutOfBandManagementServiceImpl.java @@ -189,7 +189,7 @@ private void sendAuthError(final Host host, final String message) { if (sentCount != null && sentCount <= 0) { boolean concurrentUpdateResult = hostAlertCache.asMap().replace(host.getId(), sentCount, sentCount+1L); if (concurrentUpdateResult) { - final String subject = String.format("Out-of-band management auth-error detected for host:%d in cluster:%d, zone:%d", host.getId(), host.getClusterId(), host.getDataCenterId()); + final String subject = String.format("Out-of-band management auth-error detected for %s in cluster [id: %d] and zone [id: %d].", host, host.getClusterId(), host.getDataCenterId()); LOG.error(subject + ": " + message); alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_OOBM_AUTH_ERROR, host.getDataCenterId(), host.getPodId(), subject, message); } @@ -203,11 +203,12 @@ private boolean transitionPowerState(OutOfBandManagement.PowerState.Event event, return false; } OutOfBandManagement.PowerState currentPowerState = outOfBandManagementHost.getPowerState(); + Host host = hostDao.findById(outOfBandManagementHost.getHostId()); try { OutOfBandManagement.PowerState newPowerState = OutOfBandManagement.PowerState.getStateMachine().getNextState(currentPowerState, event); boolean result = OutOfBandManagement.PowerState.getStateMachine().transitTo(outOfBandManagementHost, event, null, outOfBandManagementDao); if (result) { - final String message = String.format("Transitioned out-of-band management power state from:%s to:%s due to event:%s for the host id:%d", currentPowerState, newPowerState, event, outOfBandManagementHost.getHostId()); + final String message = String.format("Transitioned out-of-band management power state from %s to %s due to event: %s for %s", currentPowerState, newPowerState, event, host); LOG.debug(message); if (newPowerState == OutOfBandManagement.PowerState.Unknown) { ActionEventUtils.onActionEvent(CallContext.current().getCallingUserId(), CallContext.current().getCallingAccountId(), Domain.ROOT_DOMAIN, @@ -216,7 +217,7 @@ private boolean transitionPowerState(OutOfBandManagement.PowerState.Event event, } return result; } catch (NoTransitionException ignored) { - LOG.trace(String.format("Unable to transition out-of-band management power state for host id=%s for the event=%s and current power state=%s", outOfBandManagementHost.getHostId(), event, currentPowerState)); + LOG.trace(String.format("Unable to transition out-of-band management power state for %s for the event: %s and current power state: %s", host, event, currentPowerState)); } return false; } @@ -372,13 +373,14 @@ public OutOfBandManagementResponse configure(final Host host, final ImmutableMap } boolean updatedConfig = outOfBandManagementDao.update(outOfBandManagementConfig.getId(), (OutOfBandManagementVO) outOfBandManagementConfig); - CallContext.current().setEventDetails("host id:" + host.getId() + " configuration:" + outOfBandManagementConfig.getAddress() + ":" + outOfBandManagementConfig.getPort()); + String eventDetails = String.format("Configuring %s out-of-band with address [%s] and port [%s]", host, outOfBandManagementConfig.getAddress(), outOfBandManagementConfig.getPort()); + CallContext.current().setEventDetails(eventDetails); if (!updatedConfig) { - throw new CloudRuntimeException("Failed to update out-of-band management config for the host in the database."); + throw new CloudRuntimeException(String.format("Failed to update out-of-band management config for %s in the database.", host)); } - String result = "Out-of-band management successfully configured for the host"; + String result = String.format("Out-of-band management successfully configured for %s.", host); LOG.debug(result); final OutOfBandManagementResponse response = new OutOfBandManagementResponse(outOfBandManagementDao.findByHost(host.getId())); @@ -404,7 +406,7 @@ public OutOfBandManagementResponse executePowerOperation(final Host host, final final OutOfBandManagementDriverResponse driverResponse = driver.execute(cmd); if (driverResponse == null) { - throw new CloudRuntimeException(String.format("Out-of-band Management action (%s) on host (%s) failed due to no response from the driver", powerOperation, host.getUuid())); + throw new CloudRuntimeException(String.format("Out-of-band Management action [%s] on %s failed due to no response from the driver", powerOperation, host)); } if (powerOperation.equals(OutOfBandManagement.PowerOperation.STATUS)) { @@ -412,9 +414,9 @@ public OutOfBandManagementResponse executePowerOperation(final Host host, final } if (!driverResponse.isSuccess()) { - String errorMessage = String.format("Out-of-band Management action (%s) on host (%s) failed with error: %s", powerOperation, host.getUuid(), driverResponse.getError()); + String errorMessage = String.format("Out-of-band Management action [%s] on %s failed with error: %s", powerOperation, host, driverResponse.getError()); if (driverResponse.hasAuthFailure()) { - errorMessage = String.format("Out-of-band Management action (%s) on host (%s) failed due to authentication error: %s. Please check configured credentials.", powerOperation, host.getUuid(), driverResponse.getError()); + errorMessage = String.format("Out-of-band Management action [%s] on %s failed due to authentication error: %s. Please check configured credentials.", powerOperation, host, driverResponse.getError()); sendAuthError(host, errorMessage); } if (!powerOperation.equals(OutOfBandManagement.PowerOperation.STATUS)) { @@ -436,13 +438,13 @@ public OutOfBandManagementResponse executePowerOperation(final Host host, final public OutOfBandManagementResponse changePassword(final Host host, final String newPassword) { checkOutOfBandManagementEnabledByZoneClusterHost(host); if (Strings.isNullOrEmpty(newPassword)) { - throw new CloudRuntimeException(String.format("Cannot change out-of-band management password as provided new-password is null or empty for the host %s.", host.getUuid())); + throw new CloudRuntimeException(String.format("Cannot change out-of-band management password as provided new-password is null or empty for %s.", host)); } final OutOfBandManagement outOfBandManagementConfig = outOfBandManagementDao.findByHost(host.getId()); final ImmutableMap options = getOptions(outOfBandManagementConfig); if (!(options.containsKey(OutOfBandManagement.Option.PASSWORD) && !Strings.isNullOrEmpty(options.get(OutOfBandManagement.Option.PASSWORD)))) { - throw new CloudRuntimeException(String.format("Cannot change out-of-band management password as we've no previously configured password for the host %s.", host.getUuid())); + throw new CloudRuntimeException(String.format("Cannot change out-of-band management password as we've no previously configured password for %s.", host)); } final OutOfBandManagementDriver driver = getDriver(outOfBandManagementConfig); final OutOfBandManagementDriverChangePasswordCommand changePasswordCmd = new OutOfBandManagementDriverChangePasswordCommand(options, ActionTimeout.valueIn(host.getClusterId()), newPassword); @@ -455,7 +457,7 @@ public Boolean doInTransaction(TransactionStatus status) { boolean result = outOfBandManagementDao.update(updatedOutOfBandManagementConfig.getId(), (OutOfBandManagementVO) updatedOutOfBandManagementConfig); if (!result) { - throw new CloudRuntimeException(String.format("Failed to change out-of-band management password for host (%s) in the database.", host.getUuid())); + throw new CloudRuntimeException(String.format("Failed to change out-of-band management password for %s in the database.", host)); } final OutOfBandManagementDriverResponse driverResponse; @@ -463,11 +465,11 @@ public Boolean doInTransaction(TransactionStatus status) { driverResponse = driver.execute(changePasswordCmd); } catch (Exception e) { LOG.error("Out-of-band management change password failed due to driver error: " + e.getMessage()); - throw new CloudRuntimeException(String.format("Failed to change out-of-band management password for host (%s) due to driver error: %s", host.getUuid(), e.getMessage())); + throw new CloudRuntimeException(String.format("Failed to change out-of-band management password for %s due to driver error: %s", host, e.getMessage())); } if (!driverResponse.isSuccess()) { - throw new CloudRuntimeException(String.format("Failed to change out-of-band management password for host (%s) with error: %s", host.getUuid(), driverResponse.getError())); + throw new CloudRuntimeException(String.format("Failed to change out-of-band management password for %s with error: %s", host, driverResponse.getError())); } return result && driverResponse.isSuccess(); @@ -566,7 +568,7 @@ protected void runInContext() { } else if (outOfBandManagementHost.getPowerState() != OutOfBandManagement.PowerState.Disabled) { if (transitionPowerStateToDisabled(Collections.singletonList(host))) { if (LOG.isDebugEnabled()) { - LOG.debug("Out-of-band management was disabled in zone/cluster/host, disabled power state for host id:" + host.getId()); + LOG.debug(String.format("Out-of-band management was disabled in zone/cluster/host, disabled power state for %s", host)); } } }