Skip to content

Commit 856418e

Browse files
Alena ProkharchykAlena Prokharchyk
authored andcommitted
bug 13860: Added async job types to Account/User Async api commands and more logging.
Reviewed-by: Kelven Yang
1 parent b0f038c commit 856418e

5 files changed

Lines changed: 31 additions & 2 deletions

File tree

api/src/com/cloud/api/commands/DeleteAccountCmd.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.cloud.api.Parameter;
2929
import com.cloud.api.ServerApiException;
3030
import com.cloud.api.response.SuccessResponse;
31+
import com.cloud.async.AsyncJob;
3132
import com.cloud.event.EventTypes;
3233
import com.cloud.user.Account;
3334
import com.cloud.user.User;
@@ -102,4 +103,9 @@ public void execute(){
102103
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete user account and all corresponding users");
103104
}
104105
}
106+
107+
@Override
108+
public AsyncJob.Type getInstanceType() {
109+
return AsyncJob.Type.Account;
110+
}
105111
}

api/src/com/cloud/api/commands/DisableAccountCmd.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.cloud.api.Parameter;
2828
import com.cloud.api.ServerApiException;
2929
import com.cloud.api.response.AccountResponse;
30+
import com.cloud.async.AsyncJob;
3031
import com.cloud.event.EventTypes;
3132
import com.cloud.exception.ConcurrentOperationException;
3233
import com.cloud.exception.ResourceUnavailableException;
@@ -120,5 +121,10 @@ public void execute() throws ConcurrentOperationException, ResourceUnavailableEx
120121
} else {
121122
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, lockRequested == true ? "Failed to lock account" : "Failed to disable account" );
122123
}
124+
}
125+
126+
@Override
127+
public AsyncJob.Type getInstanceType() {
128+
return AsyncJob.Type.Account;
123129
}
124130
}

api/src/com/cloud/api/commands/DisableUserCmd.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.cloud.api.Parameter;
2828
import com.cloud.api.ServerApiException;
2929
import com.cloud.api.response.UserResponse;
30+
import com.cloud.async.AsyncJob;
3031
import com.cloud.event.EventTypes;
3132
import com.cloud.user.Account;
3233
import com.cloud.user.User;
@@ -95,5 +96,10 @@ public void execute(){
9596
} else {
9697
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to disable user");
9798
}
99+
}
100+
101+
@Override
102+
public AsyncJob.Type getInstanceType() {
103+
return AsyncJob.Type.User;
98104
}
99105
}

api/src/com/cloud/api/response/AsyncJobResponse.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
import java.util.Date;
2121

22+
import org.apache.log4j.Logger;
23+
2224
import com.cloud.api.ApiConstants;
2325
import com.cloud.api.IdentityProxy;
2426
import com.cloud.api.ResponseObject;
@@ -28,6 +30,8 @@
2830

2931
@SuppressWarnings("unused")
3032
public class AsyncJobResponse extends BaseResponse {
33+
private static final Logger s_logger = Logger.getLogger(AsyncJobResponse.class.getName());
34+
3135
@SerializedName("accountid") @Param(description="the account that executed the async command")
3236
private IdentityProxy accountId = new IdentityProxy("account");
3337

@@ -123,7 +127,12 @@ public void setJobInstanceType(String jobInstanceType) {
123127
this.jobInstanceId.setTableName("physical_network_service_providers");
124128
} else if (jobInstanceType.equalsIgnoreCase(AsyncJob.Type.FirewallRule.toString())) {
125129
this.jobInstanceId.setTableName("firewall_rules");
126-
} else if (!jobInstanceType.equalsIgnoreCase(AsyncJob.Type.None.toString())){
130+
} else if (jobInstanceType.equalsIgnoreCase(AsyncJob.Type.Account.toString())) {
131+
this.jobInstanceId.setTableName("account");
132+
} else if (jobInstanceType.equalsIgnoreCase(AsyncJob.Type.User.toString())) {
133+
this.jobInstanceId.setTableName("user");
134+
} else if (!jobInstanceType.equalsIgnoreCase(AsyncJob.Type.None.toString())){
135+
s_logger.warn("Failed to get async job instanceId for job instance type " + jobInstanceType);
127136
// TODO : when we hit here, we need to add instanceType -> UUID entity table mapping
128137
assert(false);
129138
}

api/src/com/cloud/async/AsyncJob.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ public enum Type {
3939
PhysicalNetwork,
4040
TrafficType,
4141
PhysicalNetworkServiceProvider,
42-
FirewallRule
42+
FirewallRule,
43+
Account,
44+
User
4345
}
4446

4547
Long getId();

0 commit comments

Comments
 (0)