Skip to content

Commit e32d08e

Browse files
authored
Create new generic method for resource UUID obtention in event's descriptions (#12502)
1 parent a5b6bc3 commit e32d08e

File tree

364 files changed

+769
-622
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

364 files changed

+769
-622
lines changed

api/src/main/java/org/apache/cloudstack/api/BaseCmd.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.Iterator;
2828
import java.util.List;
2929
import java.util.Map;
30+
import java.util.UUID;
3031
import java.util.regex.Pattern;
3132

3233
import javax.inject.Inject;
@@ -498,4 +499,14 @@ public Map<String, String> convertExternalDetailsToMap(Map externalDetails) {
498499
}
499500
return details;
500501
}
502+
503+
public String getResourceUuid(String parameterName) {
504+
UUID resourceUuid = CallContext.current().getApiResourceUuid(parameterName);
505+
506+
if (resourceUuid != null) {
507+
return resourceUuid.toString();
508+
}
509+
510+
return null;
511+
}
501512
}

api/src/main/java/org/apache/cloudstack/api/command/admin/account/CreateAccountCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public long getEntityOwnerId() {
177177
@Override
178178
public void execute() {
179179
validateParams();
180-
CallContext.current().setEventDetails("Account Name: " + getUsername() + ", Domain Id:" + getDomainId());
180+
CallContext.current().setEventDetails("Account Name: " + getUsername() + ", Domain ID:" + getResourceUuid(ApiConstants.DOMAIN_ID));
181181
UserAccount userAccount =
182182
_accountService.createUserAccount(this);
183183
if (userAccount != null) {

api/src/main/java/org/apache/cloudstack/api/command/admin/account/DisableAccountCmd.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,20 @@ public long getEntityOwnerId() {
108108

109109
@Override
110110
public String getEventDescription() {
111-
return "Disabling Account: " + getAccountName() + " in domain: " + getDomainId();
111+
String message = "Disabling Account ";
112+
113+
if (getId() != null) {
114+
message += "with ID: " + getResourceUuid(ApiConstants.ID);
115+
} else {
116+
message += getAccountName() + " in Domain: " + getResourceUuid(ApiConstants.DOMAIN_ID);
117+
}
118+
119+
return message;
112120
}
113121

114122
@Override
115123
public void execute() throws ConcurrentOperationException, ResourceUnavailableException {
116-
CallContext.current().setEventDetails("Account Name: " + getAccountName() + ", Domain Id:" + getDomainId());
124+
CallContext.current().setEventDetails("Account Name: " + getAccountName() + ", Domain Id:" + getResourceUuid(ApiConstants.DOMAIN_ID));
117125
Account result = _regionService.disableAccount(this);
118126
if (result != null){
119127
AccountResponse response = _responseGenerator.createAccountResponse(ResponseView.Full, result);

api/src/main/java/org/apache/cloudstack/api/command/admin/acl/CreateRolePermissionCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void execute() {
8181
if (role == null) {
8282
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Invalid role id provided");
8383
}
84-
CallContext.current().setEventDetails("Role id: " + role.getId() + ", rule:" + getRule() + ", permission: " + getPermission() + ", description: " + getDescription());
84+
CallContext.current().setEventDetails("Role ID: " + role.getUuid() + ", rule:" + getRule() + ", permission: " + getPermission() + ", description: " + getDescription());
8585
final RolePermission rolePermission = roleService.createRolePermission(role, getRule(), getPermission(), getDescription());
8686
if (rolePermission == null) {
8787
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create role permission");

api/src/main/java/org/apache/cloudstack/api/command/admin/acl/DeleteRoleCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void execute() {
7070
if (role == null) {
7171
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Cannot find the role with provided id");
7272
}
73-
CallContext.current().setEventDetails("Role id: " + role.getId());
73+
CallContext.current().setEventDetails("Role ID: " + role.getUuid());
7474
boolean result = roleService.deleteRole(role);
7575
SuccessResponse response = new SuccessResponse(getCommandName());
7676
response.setSuccess(result);

api/src/main/java/org/apache/cloudstack/api/command/admin/acl/DeleteRolePermissionCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void execute() {
6868
if (rolePermission == null) {
6969
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Invalid role permission id provided");
7070
}
71-
CallContext.current().setEventDetails("Role permission id: " + rolePermission.getId());
71+
CallContext.current().setEventDetails("Role permission ID: " + rolePermission.getUuid());
7272
boolean result = roleService.deleteRolePermission(rolePermission);
7373
SuccessResponse response = new SuccessResponse(getCommandName());
7474
response.setSuccess(result);

api/src/main/java/org/apache/cloudstack/api/command/admin/acl/DisableRoleCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE
5555
if (role == null) {
5656
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Cannot find the role with provided id");
5757
}
58-
CallContext.current().setEventDetails("Role id: " + role.getId());
58+
CallContext.current().setEventDetails("Role ID: " + role.getUuid());
5959
boolean result = roleService.disableRole(role);
6060
SuccessResponse response = new SuccessResponse(getCommandName());
6161
response.setSuccess(result);

api/src/main/java/org/apache/cloudstack/api/command/admin/acl/EnableRoleCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE
5555
if (role == null) {
5656
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Cannot find the role with provided id");
5757
}
58-
CallContext.current().setEventDetails("Role id: " + role.getId());
58+
CallContext.current().setEventDetails("Role ID: " + role.getUuid());
5959
boolean result = roleService.enableRole(role);
6060
SuccessResponse response = new SuccessResponse(getCommandName());
6161
response.setSuccess(result);

api/src/main/java/org/apache/cloudstack/api/command/admin/acl/UpdateRolePermissionCmd.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public void execute() {
111111
if (getRuleId() != null || getRulePermission() != null) {
112112
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Parameters permission and ruleid must be mutually exclusive with ruleorder");
113113
}
114-
CallContext.current().setEventDetails("Reordering permissions for role id: " + role.getId());
114+
CallContext.current().setEventDetails("Reordering permissions for role with ID: " + role.getUuid());
115115
final List<RolePermission> rolePermissionsOrder = new ArrayList<>();
116116
for (Long rolePermissionId : getRulePermissionOrder()) {
117117
final RolePermission rolePermission = roleService.findRolePermission(rolePermissionId);
@@ -129,7 +129,7 @@ public void execute() {
129129
if (rolePermission == null) {
130130
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Invalid rule id provided");
131131
}
132-
CallContext.current().setEventDetails("Updating permission for rule id: " + getRuleId() + " to: " + getRulePermission().toString());
132+
CallContext.current().setEventDetails("Updating permission for rule with ID: " + getResourceUuid(ApiConstants.RULE_ID) + " to: " + getRulePermission().toString());
133133
result = roleService.updateRolePermission(role, rolePermission, getRulePermission());
134134
}
135135
SuccessResponse response = new SuccessResponse(getCommandName());

api/src/main/java/org/apache/cloudstack/api/command/admin/acl/project/CreateProjectRolePermissionCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public void execute() {
7272
if (projectRole == null) {
7373
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Invalid project role ID provided");
7474
}
75-
CallContext.current().setEventDetails("Project Role ID: " + projectRole.getId() + ", Rule:" + getRule() + ", Permission: " + getPermission() + ", Description: " + getDescription());
75+
CallContext.current().setEventDetails("Project Role ID: " + projectRole.getUuid() + ", Rule:" + getRule() + ", Permission: " + getPermission() + ", Description: " + getDescription());
7676
final ProjectRolePermission projectRolePermission = projRoleService.createProjectRolePermission(this);
7777
if (projectRolePermission == null) {
7878
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create project role permission");

0 commit comments

Comments
 (0)