Skip to content

Commit 785c064

Browse files
committed
Improve logging to include more identifiable information for Cmd classes
1 parent 9146221 commit 785c064

File tree

9 files changed

+26
-20
lines changed

9 files changed

+26
-20
lines changed

api/src/main/java/org/apache/cloudstack/api/command/admin/host/UpdateHostCmd.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,9 @@ public void execute() {
125125
hostResponse.setResponseName(getCommandName());
126126
this.setResponseObject(hostResponse);
127127
} catch (Exception e) {
128-
logger.debug("Failed to update host:" + getId(), e);
129-
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update host:" + getId() + "," + e.getMessage());
128+
Host host = _entityMgr.findById(Host.class, getId());
129+
logger.debug("Failed to update host: {} with id {}", host, getId(), e);
130+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("Failed to update host: %s with id %d, %s", host, getId(), e.getMessage()));
130131
}
131132
}
132133
}

api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotFromVMSnapshotCmd.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ public long getEntityOwnerId() {
124124
if (account.getType() == Account.Type.PROJECT) {
125125
Project project = _projectService.findByProjectAccountId(vmsnapshot.getAccountId());
126126
if (project == null) {
127-
throw new InvalidParameterValueException("Unable to find project by account id=" + account.getUuid());
127+
throw new InvalidParameterValueException(String.format("Unable to find project by account %s", account));
128128
}
129129
if (project.getState() != Project.State.Active) {
130-
throw new PermissionDeniedException("Can't add resources to the project id=" + project.getUuid() + " in state=" + project.getState() + " as it's no longer active");
130+
throw new PermissionDeniedException(String.format("Can't add resources to the project %s in state=%s as it's no longer active", project, project.getState()));
131131
}
132132
} else if (account.getState() == Account.State.DISABLED) {
133133
throw new PermissionDeniedException("The owner of template is disabled: " + account);
@@ -164,8 +164,9 @@ public void create() throws ResourceAllocationException {
164164

165165
@Override
166166
public void execute() {
167-
logger.info("CreateSnapshotFromVMSnapshotCmd with vm snapshot id:" + getVMSnapshotId() + " and snapshot id:" + getEntityId() + " starts:" + System.currentTimeMillis());
168-
CallContext.current().setEventDetails("Vm Snapshot Id: "+ this._uuidMgr.getUuid(VMSnapshot.class, getVMSnapshotId()));
167+
VMSnapshot vmSnapshot = _vmSnapshotService.getVMSnapshotById(getVMSnapshotId());
168+
logger.info("CreateSnapshotFromVMSnapshotCmd with vm snapshot {} with id {} and snapshot [id: {}, uuid: {}] starts: {}", vmSnapshot, getVMSnapshotId(), getEntityId(), getEntityUuid(), System.currentTimeMillis());
169+
CallContext.current().setEventDetails("Vm Snapshot Id: "+ vmSnapshot.getUuid());
169170
Snapshot snapshot = null;
170171
try {
171172
snapshot = _snapshotService.backupSnapshotFromVmSnapshot(getEntityId(), getVmId(), getVolumeId(), getVMSnapshotId());
@@ -174,19 +175,19 @@ public void execute() {
174175
response.setResponseName(getCommandName());
175176
this.setResponseObject(response);
176177
} else {
177-
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create snapshot due to an internal error creating snapshot from vm snapshot " + getVMSnapshotId());
178+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("Failed to create snapshot due to an internal error creating snapshot from vm snapshot %s", vmSnapshot));
178179
}
179180
} catch (InvalidParameterValueException ex) {
180181
throw ex;
181182
} catch (Exception e) {
182183
logger.debug("Failed to create snapshot", e);
183-
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create snapshot due to an internal error creating snapshot from vm snapshot " + getVMSnapshotId());
184+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("Failed to create snapshot due to an internal error creating snapshot from vm snapshot %s", vmSnapshot));
184185
} finally {
185186
if (snapshot == null) {
186187
try {
187188
_snapshotService.deleteSnapshot(getEntityId(), null);
188189
} catch (Exception e) {
189-
logger.debug("Failed to clean failed snapshot" + getEntityId());
190+
logger.debug("Failed to clean failed snapshot {} with id {}", () -> _entityMgr.findById(Snapshot.class, getEntityId()), this::getEntityId);
190191
}
191192
}
192193
}

plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/DeleteKubernetesClusterCmd.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ public Boolean getExpunge() {
9393
public void execute() throws ServerApiException, ConcurrentOperationException {
9494
try {
9595
if (!kubernetesClusterService.deleteKubernetesCluster(this)) {
96-
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("Failed to delete Kubernetes cluster ID: %d", getId()));
96+
KubernetesCluster cluster = kubernetesClusterService.findById(getId());
97+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("Failed to delete Kubernetes cluster %s with id: %d", cluster, getId()));
9798
}
9899
SuccessResponse response = new SuccessResponse(getCommandName());
99100
setResponseObject(response);

plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/ScaleKubernetesClusterCmd.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ public ApiCommandResourceType getApiResourceType() {
158158
public void execute() throws ServerApiException, ConcurrentOperationException {
159159
try {
160160
if (!kubernetesClusterService.scaleKubernetesCluster(this)) {
161-
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("Failed to scale Kubernetes cluster ID: %d", getId()));
161+
KubernetesCluster cluster = kubernetesClusterService.findById(getId());
162+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("Failed to scale Kubernetes cluster %s with id %d", cluster, getId()));
162163
}
163164
final KubernetesClusterResponse response = kubernetesClusterService.createKubernetesClusterResponse(getId());
164165
response.setResponseName(getCommandName());

plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/StopKubernetesClusterCmd.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ public ApiCommandResourceType getApiResourceType() {
100100
public void execute() throws ServerApiException, ConcurrentOperationException {
101101
try {
102102
if (!kubernetesClusterService.stopKubernetesCluster(this)) {
103-
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("Failed to start Kubernetes cluster ID: %d", getId()));
103+
KubernetesCluster cluster = kubernetesClusterService.findById(getId());
104+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("Failed to start Kubernetes cluster %s with id %d", cluster, getId()));
104105
}
105106
final SuccessResponse response = new SuccessResponse(getCommandName());
106107
setResponseObject(response);

plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/UpgradeKubernetesClusterCmd.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ public ApiCommandResourceType getApiResourceType() {
110110
public void execute() throws ServerApiException, ConcurrentOperationException {
111111
try {
112112
if (!kubernetesClusterService.upgradeKubernetesCluster(this)) {
113-
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("Failed to upgrade Kubernetes cluster ID: %d", getId()));
113+
KubernetesCluster cluster = kubernetesClusterService.findById(getId());
114+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("Failed to upgrade Kubernetes cluster %s with id %d", cluster, getId()));
114115
}
115116
final KubernetesClusterResponse response = kubernetesClusterService.createKubernetesClusterResponse(getId());
116117
response.setResponseName(getCommandName());

plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LdapImportUsersCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private void createCloudstackUserAccount(LdapUser user, String accountName, Doma
117117
_accountService.createUser(user.getUsername(), generatePassword(), user.getFirstname(), user.getLastname(), user.getEmail(), timezone, accountName, domain.getId(),
118118
UUID.randomUUID().toString(), User.Source.LDAP);
119119
} else {
120-
logger.debug("Account [name=%s] and user [name=%s] already exist in CloudStack. Executing the user update.");
120+
logger.debug("Account [name={}] and user [name={}] already exist in CloudStack. Executing the user update.", account, csuser);
121121

122122
UpdateUserCmd updateUserCmd = new UpdateUserCmd();
123123
updateUserCmd.setId(csuser.getId());

plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LinkAccountToLdapCmd.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ public void execute() throws ServerApiException {
9191
.createUserAccount(admin, "", ldapUser.getFirstname(), ldapUser.getLastname(), ldapUser.getEmail(), null, admin, Account.Type.DOMAIN_ADMIN, RoleType.DomainAdmin.getId(), domainId, null, null, UUID.randomUUID().toString(),
9292
UUID.randomUUID().toString(), User.Source.LDAP);
9393
response.setAdminId(String.valueOf(userAccount.getAccountId()));
94-
logger.info("created an account with name " + admin + " in the given domain " + domainId);
94+
logger.info("created an account with name {} in the given domain {} with id {}", admin, _domainService.getDomain(domainId), domainId);
9595
} catch (Exception e) {
96-
logger.info("an exception occurred while creating account with name " + admin + " in domain " + domainId, e);
96+
logger.info("an exception occurred while creating account with name {} in domain {} with id {}", admin, _domainService.getDomain(domainId), domainId, e);
9797
}
9898
} else {
99-
logger.debug("an account with name " + admin + " already exists in the domain " + domainId);
99+
logger.debug("an account with name {} already exists in the domain {} with id {}", admin, _domainService.getDomain(domainId), domainId);
100100
}
101101
} else {
102102
logger.debug("ldap user with username " + admin + " is disabled in the given group/ou");

plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LinkDomainToLdapCmd.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,12 @@ public void execute() throws ServerApiException {
107107
UserAccount userAccount = _accountService.createUserAccount(admin, "", ldapUser.getFirstname(), ldapUser.getLastname(), ldapUser.getEmail(), null,
108108
admin, Account.Type.DOMAIN_ADMIN, RoleType.DomainAdmin.getId(), domainId, null, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), User.Source.LDAP);
109109
response.setAdminId(String.valueOf(userAccount.getAccountId()));
110-
logger.info("created an account with name " + admin + " in the given domain " + domainId);
110+
logger.info("created an account with name {} in the given domain {} with id {}", admin, _domainService.getDomain(domainId), domainId);
111111
} catch (Exception e) {
112-
logger.info("an exception occurred while creating account with name " + admin +" in domain " + domainId, e);
112+
logger.info("an exception occurred while creating account with name {} in domain {} with id {}", admin, _domainService.getDomain(domainId), domainId, e);
113113
}
114114
} else {
115-
logger.debug("an account with name " + admin + " already exists in the domain " + domainId);
115+
logger.debug("an account with name {} already exists in the domain {} with id {}", admin, _domainService.getDomain(domainId), domainId);
116116
}
117117
} else {
118118
logger.debug("ldap user with username "+admin+" is disabled in the given group/ou");

0 commit comments

Comments
 (0)