Copilot commented on code in PR #13775:
URL: https://github.com/apache/cloudstack/pull/13775#discussion_r3702720535
##########
server/src/main/java/com/cloud/vm/UserVmManagerImpl.java:
##########
@@ -2862,10 +2862,10 @@ private void updateVmStateForFailedVmCreation(Long
vmId, Long hostId) {
volumeMgr.destroyVolume(volume);
}
}
- String subject = String.format("Failed to deploy Instance [ID:
%s]", vm.getUuid());
+ String subject = String.format("Failed to deploy Instance
[%s]", vm);
String body = String.format("Failed to deploy [%s]%s. To
troubleshoot, please check the logs with [logid:%s].",
vm,
- hostId != null ? String.format(" on host [%s]",
hostId) : "",
+ hostId != null ? String.format(" on host [%s]", host)
: "",
ThreadContext.get("logcontextid"));
Review Comment:
The conditional uses `hostId != null` but formats the message using `host`,
which can be `null` even when `hostId` is set (leading to alerts like `on host
[null]`). Prefer conditioning on `host != null` (or falling back to `hostId`)
so the alert always contains a usable identifier.
##########
server/src/main/java/com/cloud/vm/UserVmManagerImpl.java:
##########
@@ -7760,15 +7760,23 @@ public void checkHostsDedication(VMInstanceVO vm, long
srcHostId, long destHostI
//if hosts are dedicated to different account/domains, raise an alert
if (srcExplDedicated && destExplDedicated) {
- if (!((accountOfDedicatedHost(srcHost) == null) ||
(accountOfDedicatedHost(srcHost).equals(accountOfDedicatedHost(destHost))))) {
- String msg = String.format("VM is being migrated from host %s
explicitly dedicated to account %d to host %s explicitly dedicated to account
%d",
- srcHost, accountOfDedicatedHost(srcHost), destHost,
accountOfDedicatedHost(destHost));
+ Long srcAccountId = accountOfDedicatedHost(srcHost);
+ Long destAccountId = accountOfDedicatedHost(destHost);
+ if (!((srcAccountId == null) ||
(srcAccountId.equals(destAccountId)))) {
+ Account srcAccount = _accountDao.findById(srcAccountId);
+ Account destAccount = _accountDao.findById(destAccountId);
+ String msg = String.format("VM is being migrated from host %s
explicitly dedicated to account %s to host %s explicitly dedicated to account
%s",
+ srcHost, srcAccount, destHost, destAccount);
Review Comment:
`destAccountId` can be `null` and still enter the `if` (when `srcAccountId`
is non-null and `!srcAccountId.equals(null)`), causing
`_accountDao.findById(destAccountId)` with a null argument. This can throw or
generate misleading output; guard the lookup and message formatting so null
destination dedication is handled explicitly (e.g., print 'none' / 'not
dedicated' without calling `findById(null)`). The same issue exists for the
domain block below.
##########
server/src/main/java/com/cloud/resourcelimit/ResourceLimitManagerImpl.java:
##########
@@ -1008,12 +1008,12 @@ public ResourceLimitVO updateResourceLimit(Long
accountId, Long domainId, Intege
if (Domain.ROOT_DOMAIN == domainId) {
// no one can add limits on ROOT domain, disallow...
- throw new PermissionDeniedException("Cannot update resource
limit for ROOT domain " + domainId + ", permission denied");
+ throw new PermissionDeniedException("Cannot update resource
limit for ROOT domain " + domain + ", permission denied");
}
if ((caller.getDomainId() == domainId) && caller.getType() ==
Account.Type.DOMAIN_ADMIN || caller.getType() ==
Account.Type.RESOURCE_DOMAIN_ADMIN) {
// if the admin is trying to update their own domain,
disallow...
- throw new PermissionDeniedException("Unable to update resource
limit for domain " + domainId + ", permission denied");
+ throw new PermissionDeniedException("Unable to update resource
limit for domain " + domain + ", permission denied");
Review Comment:
These exceptions previously included `domainId`, but now concatenate
`domain`, which can be `null` (especially in the ROOT-domain check) and also
hides the numeric identifier. Consider including `domainId` (and optionally the
resolved `domain` display) so the error remains actionable even when the domain
entity isn't available.
##########
server/src/main/java/com/cloud/alert/AlertManagerImpl.java:
##########
@@ -815,7 +815,7 @@ public void sendAlert(AlertType alertType, DataCenter
dataCenter, Pod pod, Clust
Long clusterId = cluster == null ? null : cluster.getId();
Long podId = pod == null ? null : pod.getId();
long dcId = dataCenter == null ? 0L : dataCenter.getId();
- logger.warn(String.format("alertType=[%s] dataCenterId=[%s] podId=[%s]
clusterId=[%s] message=[%s].", alertType, dcId, podId, clusterId, subject));
+ logger.warn("alertType=[{}] dataCenter=[{}] pod=[{}] cluster=[{}]
message=[{}].", alertType, dataCenter, pod, cluster, subject);
Review Comment:
This log line switched from IDs to logging full `dataCenter/pod/cluster`
objects. Depending on their `toString()` implementations, this can become
overly verbose, unstable for log parsing, and potentially include unexpected
fields. Consider logging stable identifiers (e.g., ids + names) rather than
full objects, while keeping structured logging.
##########
engine/storage/src/main/java/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java:
##########
@@ -248,7 +248,7 @@ protected Void
createTemplateAsyncCallback(AsyncCallbackDispatcher<? extends Bas
result.setSuccess(false);
result.setResult(answer.getErrorString());
caller.complete(result);
- String msg = "Failed to register template: " + obj.getUuid() + "
with error: " + answer.getErrorString();
+ String msg = "Failed to register template: " + obj + " with error:
" + answer.getErrorString();
Review Comment:
Alerts for upload/register/copy failures are typically used by operators to
quickly identify the affected resource. Using `obj` relies on `toString()`
output, which may not include the UUID (or may be overly verbose). Prefer
including explicit stable identifiers (e.g., uuid/id + name) in these alert
messages so they remain actionable and consistent across object implementations.
##########
engine/storage/src/main/java/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java:
##########
@@ -352,7 +352,7 @@ protected Void
createSnapshotAsyncCallback(AsyncCallbackDispatcher<? extends Bas
result.setSuccess(false);
result.setResult(answer.getErrorString());
caller.complete(result);
- String msg = "Failed to copy snapshot: " + obj.getUuid() + " with
error: " + answer.getErrorString();
+ String msg = "Failed to copy snapshot: " + obj + " with error: " +
answer.getErrorString();
Review Comment:
Alerts for upload/register/copy failures are typically used by operators to
quickly identify the affected resource. Using `obj` relies on `toString()`
output, which may not include the UUID (or may be overly verbose). Prefer
including explicit stable identifiers (e.g., uuid/id + name) in these alert
messages so they remain actionable and consistent across object implementations.
##########
engine/storage/src/main/java/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java:
##########
@@ -306,7 +306,7 @@ protected Void
createTemplateAsyncCallback(AsyncCallbackDispatcher<? extends Bas
result.setSuccess(false);
result.setResult(answer.getErrorString());
caller.complete(result);
- String msg = "Failed to upload volume: " + obj.getUuid() + " with
error: " + answer.getErrorString();
+ String msg = "Failed to upload volume: " + obj + " with error: " +
answer.getErrorString();
Review Comment:
Alerts for upload/register/copy failures are typically used by operators to
quickly identify the affected resource. Using `obj` relies on `toString()`
output, which may not include the UUID (or may be overly verbose). Prefer
including explicit stable identifiers (e.g., uuid/id + name) in these alert
messages so they remain actionable and consistent across object implementations.
##########
server/src/main/java/com/cloud/resourcelimit/ResourceLimitManagerImpl.java:
##########
@@ -1008,12 +1008,12 @@ public ResourceLimitVO updateResourceLimit(Long
accountId, Long domainId, Intege
if (Domain.ROOT_DOMAIN == domainId) {
// no one can add limits on ROOT domain, disallow...
- throw new PermissionDeniedException("Cannot update resource
limit for ROOT domain " + domainId + ", permission denied");
+ throw new PermissionDeniedException("Cannot update resource
limit for ROOT domain " + domain + ", permission denied");
Review Comment:
These exceptions previously included `domainId`, but now concatenate
`domain`, which can be `null` (especially in the ROOT-domain check) and also
hides the numeric identifier. Consider including `domainId` (and optionally the
resolved `domain` display) so the error remains actionable even when the domain
entity isn't available.
##########
engine/components-api/src/main/java/com/cloud/alert/AlertFormatUtils.java:
##########
@@ -0,0 +1,39 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.alert;
+
+import com.cloud.dc.DataCenter;
+import com.cloud.dc.Pod;
+import com.cloud.host.Host;
+
+/**
+ * Shared formatting for the host/zone/pod description that recurs,
independently
+ * hand-rolled and inconsistently worded (and occasionally mislabelled),
across the
+ * HA and agent-management alert call sites. See CLOUDSTACK-7297.
+ */
Review Comment:
The PR description is still the default template (no selected change type,
severity, or testing notes). Since automation relies on the description for
labeling/documentation (as noted in the template), please fill in the PR
description fields (type, severity/scale, and how it was tested) to match the
changes introduced here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]