Skip to content

Commit 5ffd233

Browse files
committed
Made all project commands except list* to be Async
1 parent 8ba007b commit 5ffd233

12 files changed

Lines changed: 147 additions & 18 deletions

‎api/src/com/cloud/api/commands/ActivateProjectCmd.java‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,20 @@
2121
import org.apache.log4j.Logger;
2222

2323
import com.cloud.api.ApiConstants;
24+
import com.cloud.api.BaseAsyncCmd;
2425
import com.cloud.api.BaseCmd;
26+
import com.cloud.api.BaseCmd.CommandType;
2527
import com.cloud.api.Implementation;
2628
import com.cloud.api.Parameter;
2729
import com.cloud.api.ServerApiException;
2830
import com.cloud.api.response.ProjectResponse;
31+
import com.cloud.event.EventTypes;
2932
import com.cloud.exception.InvalidParameterValueException;
3033
import com.cloud.projects.Project;
3134
import com.cloud.user.UserContext;
3235

3336
@Implementation(description="Activates a project", responseObject=ProjectResponse.class)
34-
public class ActivateProjectCmd extends BaseCmd {
37+
public class ActivateProjectCmd extends BaseAsyncCmd {
3538
public static final Logger s_logger = Logger.getLogger(ActivateProjectCmd.class.getName());
3639

3740
private static final String s_name = "activaterojectresponse";
@@ -84,4 +87,14 @@ public void execute(){
8487
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to activate a project");
8588
}
8689
}
90+
91+
@Override
92+
public String getEventType() {
93+
return EventTypes.EVENT_PROJECT_ACTIVATE;
94+
}
95+
96+
@Override
97+
public String getEventDescription() {
98+
return "Activating project: " + id;
99+
}
87100
}

‎api/src/com/cloud/api/commands/AddAccountToProjectCmd.java‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,19 @@
2121
import org.apache.log4j.Logger;
2222

2323
import com.cloud.api.ApiConstants;
24+
import com.cloud.api.BaseAsyncCmd;
2425
import com.cloud.api.BaseCmd;
2526
import com.cloud.api.Implementation;
2627
import com.cloud.api.Parameter;
2728
import com.cloud.api.ServerApiException;
2829
import com.cloud.api.response.SuccessResponse;
30+
import com.cloud.event.EventTypes;
2931
import com.cloud.exception.InvalidParameterValueException;
3032
import com.cloud.projects.Project;
3133
import com.cloud.user.UserContext;
3234

3335
@Implementation(description="Adds acoount to a project", responseObject=SuccessResponse.class)
34-
public class AddAccountToProjectCmd extends BaseCmd {
36+
public class AddAccountToProjectCmd extends BaseAsyncCmd {
3537
public static final Logger s_logger = Logger.getLogger(AddAccountToProjectCmd.class.getName());
3638

3739
private static final String s_name = "addaccounttoprojectresponse";
@@ -78,6 +80,10 @@ public String getCommandName() {
7880

7981
@Override
8082
public void execute(){
83+
if (accountName == null && email == null) {
84+
throw new InvalidParameterValueException("Either accountName or email is required");
85+
}
86+
8187
UserContext.current().setEventDetails("Project id: "+ projectId + "; accountName " + accountName);
8288
boolean result = _projectService.addAccountToProject(getProjectId(), getAccountName(), getEmail());
8389
if (result) {
@@ -98,4 +104,18 @@ public long getEntityOwnerId() {
98104

99105
return _projectService.getProjectOwner(projectId).getId();
100106
}
107+
108+
@Override
109+
public String getEventType() {
110+
return EventTypes.EVENT_PROJECT_ACCOUNT_ADD;
111+
}
112+
113+
@Override
114+
public String getEventDescription() {
115+
if (accountName != null) {
116+
return "Adding account " + accountName + " to project: " + projectId;
117+
} else {
118+
return "Sending invitation to email " + email + " to join project: " + projectId;
119+
}
120+
}
101121
}

‎api/src/com/cloud/api/commands/CreateProjectCmd.java‎

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,21 @@
2121
import org.apache.log4j.Logger;
2222

2323
import com.cloud.api.ApiConstants;
24+
import com.cloud.api.BaseAsyncCreateCmd;
2425
import com.cloud.api.BaseCmd;
2526
import com.cloud.api.Implementation;
2627
import com.cloud.api.Parameter;
2728
import com.cloud.api.ServerApiException;
2829
import com.cloud.api.response.ProjectResponse;
30+
import com.cloud.event.EventTypes;
2931
import com.cloud.exception.InvalidParameterValueException;
3032
import com.cloud.exception.ResourceAllocationException;
3133
import com.cloud.projects.Project;
3234
import com.cloud.user.Account;
3335
import com.cloud.user.UserContext;
3436

3537
@Implementation(description="Creates a project", responseObject=ProjectResponse.class)
36-
public class CreateProjectCmd extends BaseCmd {
38+
public class CreateProjectCmd extends BaseAsyncCreateCmd {
3739
public static final Logger s_logger = Logger.getLogger(CreateProjectCmd.class.getName());
3840

3941
private static final String s_name = "createprojectresponse";
@@ -59,11 +61,20 @@ public class CreateProjectCmd extends BaseCmd {
5961
/////////////////////////////////////////////////////
6062

6163
public String getAccountName() {
62-
return accountName;
64+
if (accountName != null) {
65+
return accountName;
66+
} else {
67+
return UserContext.current().getCaller().getAccountName();
68+
}
6369
}
6470

6571
public Long getDomainId() {
66-
return domainId;
72+
if (domainId != null) {
73+
return domainId;
74+
} else {
75+
return UserContext.current().getCaller().getDomainId();
76+
}
77+
6778
}
6879

6980
public String getName() {
@@ -100,9 +111,8 @@ public long getEntityOwnerId() {
100111
/////////////////////////////////////////////////////
101112

102113
@Override
103-
public void execute() throws ResourceAllocationException{
104-
UserContext.current().setEventDetails("Project Name: "+ getName());
105-
Project project = _projectService.createProject(getName(), getDisplayText(), getAccountName(), getDomainId());
114+
public void execute(){
115+
Project project = _projectService.enableProject(this.getEntityId());
106116
if (project != null) {
107117
ProjectResponse response = _responseGenerator.createProjectResponse(project);
108118
response.setResponseName(getCommandName());
@@ -111,4 +121,25 @@ public void execute() throws ResourceAllocationException{
111121
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create a project");
112122
}
113123
}
124+
125+
@Override
126+
public void create() throws ResourceAllocationException{
127+
UserContext.current().setEventDetails("Project Name: "+ getName());
128+
Project project = _projectService.createProject(getName(), getDisplayText(), getAccountName(), getDomainId());
129+
if (project != null) {
130+
this.setEntityId(project.getId());
131+
} else {
132+
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create a project");
133+
}
134+
}
135+
136+
@Override
137+
public String getEventType() {
138+
return EventTypes.EVENT_PROJECT_CREATE;
139+
}
140+
141+
@Override
142+
public String getEventDescription() {
143+
return "creating project";
144+
}
114145
}

‎api/src/com/cloud/api/commands/DeleteAccountFromProjectCmd.java‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,19 @@
2121
import org.apache.log4j.Logger;
2222

2323
import com.cloud.api.ApiConstants;
24+
import com.cloud.api.BaseAsyncCmd;
2425
import com.cloud.api.BaseCmd;
2526
import com.cloud.api.Implementation;
2627
import com.cloud.api.Parameter;
2728
import com.cloud.api.ServerApiException;
2829
import com.cloud.api.response.SuccessResponse;
30+
import com.cloud.event.EventTypes;
2931
import com.cloud.exception.InvalidParameterValueException;
3032
import com.cloud.projects.Project;
3133
import com.cloud.user.UserContext;
3234

3335
@Implementation(description="Deletes account from the project", responseObject=SuccessResponse.class)
34-
public class DeleteAccountFromProjectCmd extends BaseCmd {
36+
public class DeleteAccountFromProjectCmd extends BaseAsyncCmd {
3537
public static final Logger s_logger = Logger.getLogger(DeleteProjectCmd.class.getName());
3638

3739
private static final String s_name = "deleteaccountfromprojectresponse";
@@ -92,4 +94,14 @@ public long getEntityOwnerId() {
9294

9395
return _projectService.getProjectOwner(projectId).getId();
9496
}
97+
98+
@Override
99+
public String getEventType() {
100+
return EventTypes.EVENT_PROJECT_ACCOUNT_REMOVE;
101+
}
102+
103+
@Override
104+
public String getEventDescription() {
105+
return "Removing account " + accountName + " from project: " + projectId;
106+
}
95107
}

‎api/src/com/cloud/api/commands/JoinProjectCmd.java‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,18 @@
2020
import org.apache.log4j.Logger;
2121

2222
import com.cloud.api.ApiConstants;
23+
import com.cloud.api.BaseAsyncCmd;
2324
import com.cloud.api.BaseCmd;
2425
import com.cloud.api.Implementation;
2526
import com.cloud.api.Parameter;
2627
import com.cloud.api.ServerApiException;
2728
import com.cloud.api.response.SuccessResponse;
29+
import com.cloud.event.EventTypes;
2830
import com.cloud.user.Account;
2931
import com.cloud.user.UserContext;
3032

3133
@Implementation(description="Makes account to join the project", responseObject=SuccessResponse.class)
32-
public class JoinProjectCmd extends BaseCmd {
34+
public class JoinProjectCmd extends BaseAsyncCmd {
3335
public static final Logger s_logger = Logger.getLogger(JoinProjectCmd.class.getName());
3436
private static final String s_name = "joinprojectresponse";
3537

@@ -87,4 +89,14 @@ public void execute(){
8789
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to join the project");
8890
}
8991
}
92+
93+
@Override
94+
public String getEventType() {
95+
return EventTypes.EVENT_PROJECT_JOIN;
96+
}
97+
98+
@Override
99+
public String getEventDescription() {
100+
return "Account " + accountName + " joining the project: " + projectId;
101+
}
90102
}

‎api/src/com/cloud/api/commands/SuspendProjectCmd.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import com.cloud.api.Parameter;
2828
import com.cloud.api.ServerApiException;
2929
import com.cloud.api.response.ProjectResponse;
30-
import com.cloud.api.response.SuccessResponse;
3130
import com.cloud.event.EventTypes;
3231
import com.cloud.exception.ConcurrentOperationException;
3332
import com.cloud.exception.InvalidParameterValueException;

‎api/src/com/cloud/api/commands/UpdateProjectCmd.java‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,20 @@
2121
import org.apache.log4j.Logger;
2222

2323
import com.cloud.api.ApiConstants;
24+
import com.cloud.api.BaseAsyncCmd;
2425
import com.cloud.api.BaseCmd;
26+
import com.cloud.api.BaseCmd.CommandType;
2527
import com.cloud.api.Implementation;
2628
import com.cloud.api.Parameter;
2729
import com.cloud.api.ServerApiException;
2830
import com.cloud.api.response.ProjectResponse;
31+
import com.cloud.event.EventTypes;
2932
import com.cloud.exception.InvalidParameterValueException;
3033
import com.cloud.projects.Project;
3134
import com.cloud.user.UserContext;
3235

3336
@Implementation(description="Updates a project", responseObject=ProjectResponse.class)
34-
public class UpdateProjectCmd extends BaseCmd {
37+
public class UpdateProjectCmd extends BaseAsyncCmd {
3538
public static final Logger s_logger = Logger.getLogger(UpdateProjectCmd.class.getName());
3639

3740
private static final String s_name = "updateprojectresponse";
@@ -98,4 +101,14 @@ public void execute(){
98101
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update a project");
99102
}
100103
}
104+
105+
@Override
106+
public String getEventType() {
107+
return EventTypes.EVENT_PROJECT_UPDATE;
108+
}
109+
110+
@Override
111+
public String getEventDescription() {
112+
return "Updating project: " + id;
113+
}
101114
}

‎api/src/com/cloud/event/EventTypes.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,5 +210,6 @@ public class EventTypes {
210210
public static final String EVENT_PROJECT_ACTIVATE = "PROJECT.ACTIVATE";
211211
public static final String EVENT_PROJECT_SUSPEND = "PROJECT.SUSPEND";
212212
public static final String EVENT_PROJECT_ACCOUNT_ADD = "PROJECT.ACCOUNT.ADD";
213+
public static final String EVENT_PROJECT_JOIN = "PROJECT.JOIN";
213214
public static final String EVENT_PROJECT_ACCOUNT_REMOVE = "PROJECT.ACCOUNT.REMOVE";
214215
}

‎api/src/com/cloud/projects/ProjectService.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,6 @@ public interface ProjectService {
6565
Project activateProject(long projectId);
6666

6767
Project suspendProject(long projectId) throws ConcurrentOperationException, ResourceUnavailableException;
68+
69+
Project enableProject(long projectId);
6870
}

‎client/tomcatconf/commands.properties.in‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ addAccountToProject=com.cloud.api.commands.AddAccountToProjectCmd;15
276276
deleteAccountFromProject=com.cloud.api.commands.DeleteAccountFromProjectCmd;15
277277
listProjectAccounts=com.cloud.api.commands.ListProjectAccountsCmd;15
278278
listProjectInvitations=com.cloud.api.commands.ListProjectInvitationsCmd;15
279-
280279
joinProject=com.cloud.api.commands.JoinProjectCmd;15
281280

282281
####

0 commit comments

Comments
 (0)