mirror of https://github.com/apache/cloudstack.git
Made all project commands except list* to be Async
This commit is contained in:
parent
8ba007b923
commit
5ffd233bb4
|
|
@ -21,17 +21,20 @@ package com.cloud.api.commands;
|
|||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.api.BaseAsyncCmd;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.BaseCmd.CommandType;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.response.ProjectResponse;
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.projects.Project;
|
||||
import com.cloud.user.UserContext;
|
||||
|
||||
@Implementation(description="Activates a project", responseObject=ProjectResponse.class)
|
||||
public class ActivateProjectCmd extends BaseCmd {
|
||||
public class ActivateProjectCmd extends BaseAsyncCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(ActivateProjectCmd.class.getName());
|
||||
|
||||
private static final String s_name = "activaterojectresponse";
|
||||
|
|
@ -84,4 +87,14 @@ public class ActivateProjectCmd extends BaseCmd {
|
|||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to activate a project");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventType() {
|
||||
return EventTypes.EVENT_PROJECT_ACTIVATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventDescription() {
|
||||
return "Activating project: " + id;
|
||||
}
|
||||
}
|
||||
|
|
@ -21,17 +21,19 @@ package com.cloud.api.commands;
|
|||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.api.BaseAsyncCmd;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.response.SuccessResponse;
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.projects.Project;
|
||||
import com.cloud.user.UserContext;
|
||||
|
||||
@Implementation(description="Adds acoount to a project", responseObject=SuccessResponse.class)
|
||||
public class AddAccountToProjectCmd extends BaseCmd {
|
||||
public class AddAccountToProjectCmd extends BaseAsyncCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(AddAccountToProjectCmd.class.getName());
|
||||
|
||||
private static final String s_name = "addaccounttoprojectresponse";
|
||||
|
|
@ -78,6 +80,10 @@ public class AddAccountToProjectCmd extends BaseCmd {
|
|||
|
||||
@Override
|
||||
public void execute(){
|
||||
if (accountName == null && email == null) {
|
||||
throw new InvalidParameterValueException("Either accountName or email is required");
|
||||
}
|
||||
|
||||
UserContext.current().setEventDetails("Project id: "+ projectId + "; accountName " + accountName);
|
||||
boolean result = _projectService.addAccountToProject(getProjectId(), getAccountName(), getEmail());
|
||||
if (result) {
|
||||
|
|
@ -98,4 +104,18 @@ public class AddAccountToProjectCmd extends BaseCmd {
|
|||
|
||||
return _projectService.getProjectOwner(projectId).getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventType() {
|
||||
return EventTypes.EVENT_PROJECT_ACCOUNT_ADD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventDescription() {
|
||||
if (accountName != null) {
|
||||
return "Adding account " + accountName + " to project: " + projectId;
|
||||
} else {
|
||||
return "Sending invitation to email " + email + " to join project: " + projectId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -21,11 +21,13 @@ package com.cloud.api.commands;
|
|||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.api.BaseAsyncCreateCmd;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.response.ProjectResponse;
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.projects.Project;
|
||||
|
|
@ -33,7 +35,7 @@ import com.cloud.user.Account;
|
|||
import com.cloud.user.UserContext;
|
||||
|
||||
@Implementation(description="Creates a project", responseObject=ProjectResponse.class)
|
||||
public class CreateProjectCmd extends BaseCmd {
|
||||
public class CreateProjectCmd extends BaseAsyncCreateCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(CreateProjectCmd.class.getName());
|
||||
|
||||
private static final String s_name = "createprojectresponse";
|
||||
|
|
@ -59,11 +61,20 @@ public class CreateProjectCmd extends BaseCmd {
|
|||
/////////////////////////////////////////////////////
|
||||
|
||||
public String getAccountName() {
|
||||
return accountName;
|
||||
if (accountName != null) {
|
||||
return accountName;
|
||||
} else {
|
||||
return UserContext.current().getCaller().getAccountName();
|
||||
}
|
||||
}
|
||||
|
||||
public Long getDomainId() {
|
||||
return domainId;
|
||||
if (domainId != null) {
|
||||
return domainId;
|
||||
} else {
|
||||
return UserContext.current().getCaller().getDomainId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
|
@ -100,9 +111,8 @@ public class CreateProjectCmd extends BaseCmd {
|
|||
/////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public void execute() throws ResourceAllocationException{
|
||||
UserContext.current().setEventDetails("Project Name: "+ getName());
|
||||
Project project = _projectService.createProject(getName(), getDisplayText(), getAccountName(), getDomainId());
|
||||
public void execute(){
|
||||
Project project = _projectService.enableProject(this.getEntityId());
|
||||
if (project != null) {
|
||||
ProjectResponse response = _responseGenerator.createProjectResponse(project);
|
||||
response.setResponseName(getCommandName());
|
||||
|
|
@ -111,4 +121,25 @@ public class CreateProjectCmd extends BaseCmd {
|
|||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create a project");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create() throws ResourceAllocationException{
|
||||
UserContext.current().setEventDetails("Project Name: "+ getName());
|
||||
Project project = _projectService.createProject(getName(), getDisplayText(), getAccountName(), getDomainId());
|
||||
if (project != null) {
|
||||
this.setEntityId(project.getId());
|
||||
} else {
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create a project");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventType() {
|
||||
return EventTypes.EVENT_PROJECT_CREATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventDescription() {
|
||||
return "creating project";
|
||||
}
|
||||
}
|
||||
|
|
@ -21,17 +21,19 @@ package com.cloud.api.commands;
|
|||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.api.BaseAsyncCmd;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.response.SuccessResponse;
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.projects.Project;
|
||||
import com.cloud.user.UserContext;
|
||||
|
||||
@Implementation(description="Deletes account from the project", responseObject=SuccessResponse.class)
|
||||
public class DeleteAccountFromProjectCmd extends BaseCmd {
|
||||
public class DeleteAccountFromProjectCmd extends BaseAsyncCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(DeleteProjectCmd.class.getName());
|
||||
|
||||
private static final String s_name = "deleteaccountfromprojectresponse";
|
||||
|
|
@ -92,4 +94,14 @@ public class DeleteAccountFromProjectCmd extends BaseCmd {
|
|||
|
||||
return _projectService.getProjectOwner(projectId).getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventType() {
|
||||
return EventTypes.EVENT_PROJECT_ACCOUNT_REMOVE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventDescription() {
|
||||
return "Removing account " + accountName + " from project: " + projectId;
|
||||
}
|
||||
}
|
||||
|
|
@ -20,16 +20,18 @@ package com.cloud.api.commands;
|
|||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.api.BaseAsyncCmd;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.response.SuccessResponse;
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.UserContext;
|
||||
|
||||
@Implementation(description="Makes account to join the project", responseObject=SuccessResponse.class)
|
||||
public class JoinProjectCmd extends BaseCmd {
|
||||
public class JoinProjectCmd extends BaseAsyncCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(JoinProjectCmd.class.getName());
|
||||
private static final String s_name = "joinprojectresponse";
|
||||
|
||||
|
|
@ -87,4 +89,14 @@ public class JoinProjectCmd extends BaseCmd {
|
|||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to join the project");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventType() {
|
||||
return EventTypes.EVENT_PROJECT_JOIN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventDescription() {
|
||||
return "Account " + accountName + " joining the project: " + projectId;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ import com.cloud.api.Implementation;
|
|||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.response.ProjectResponse;
|
||||
import com.cloud.api.response.SuccessResponse;
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
|
|
|
|||
|
|
@ -21,17 +21,20 @@ package com.cloud.api.commands;
|
|||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.api.BaseAsyncCmd;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.BaseCmd.CommandType;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.response.ProjectResponse;
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.projects.Project;
|
||||
import com.cloud.user.UserContext;
|
||||
|
||||
@Implementation(description="Updates a project", responseObject=ProjectResponse.class)
|
||||
public class UpdateProjectCmd extends BaseCmd {
|
||||
public class UpdateProjectCmd extends BaseAsyncCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(UpdateProjectCmd.class.getName());
|
||||
|
||||
private static final String s_name = "updateprojectresponse";
|
||||
|
|
@ -98,4 +101,14 @@ public class UpdateProjectCmd extends BaseCmd {
|
|||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update a project");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventType() {
|
||||
return EventTypes.EVENT_PROJECT_UPDATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventDescription() {
|
||||
return "Updating project: " + id;
|
||||
}
|
||||
}
|
||||
|
|
@ -210,5 +210,6 @@ public class EventTypes {
|
|||
public static final String EVENT_PROJECT_ACTIVATE = "PROJECT.ACTIVATE";
|
||||
public static final String EVENT_PROJECT_SUSPEND = "PROJECT.SUSPEND";
|
||||
public static final String EVENT_PROJECT_ACCOUNT_ADD = "PROJECT.ACCOUNT.ADD";
|
||||
public static final String EVENT_PROJECT_JOIN = "PROJECT.JOIN";
|
||||
public static final String EVENT_PROJECT_ACCOUNT_REMOVE = "PROJECT.ACCOUNT.REMOVE";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,4 +65,6 @@ public interface ProjectService {
|
|||
Project activateProject(long projectId);
|
||||
|
||||
Project suspendProject(long projectId) throws ConcurrentOperationException, ResourceUnavailableException;
|
||||
|
||||
Project enableProject(long projectId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -276,7 +276,6 @@ addAccountToProject=com.cloud.api.commands.AddAccountToProjectCmd;15
|
|||
deleteAccountFromProject=com.cloud.api.commands.DeleteAccountFromProjectCmd;15
|
||||
listProjectAccounts=com.cloud.api.commands.ListProjectAccountsCmd;15
|
||||
listProjectInvitations=com.cloud.api.commands.ListProjectInvitationsCmd;15
|
||||
|
||||
joinProject=com.cloud.api.commands.JoinProjectCmd;15
|
||||
|
||||
####
|
||||
|
|
|
|||
|
|
@ -154,7 +154,7 @@ public class ProjectManagerImpl implements ProjectManager, Manager{
|
|||
}
|
||||
|
||||
@Override
|
||||
@ActionEvent(eventType = EventTypes.EVENT_PROJECT_CREATE, eventDescription = "creating project")
|
||||
@ActionEvent(eventType = EventTypes.EVENT_PROJECT_CREATE, eventDescription = "creating project", create=true)
|
||||
@DB
|
||||
public Project createProject(String name, String displayText, String accountName, Long domainId) throws ResourceAllocationException{
|
||||
Account caller = UserContext.current().getCaller();
|
||||
|
|
@ -203,6 +203,29 @@ public class ProjectManagerImpl implements ProjectManager, Manager{
|
|||
return project;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@ActionEvent(eventType = EventTypes.EVENT_PROJECT_CREATE, eventDescription = "creating project", async=true)
|
||||
@DB
|
||||
public Project enableProject(long projectId){
|
||||
Account caller = UserContext.current().getCaller();
|
||||
|
||||
ProjectVO project= getProject(projectId);
|
||||
//verify input parameters
|
||||
if (project == null) {
|
||||
throw new InvalidParameterValueException("Unable to find project by id " + projectId);
|
||||
}
|
||||
|
||||
_accountMgr.checkAccess(caller, _domainDao.findById(project.getDomainId()), AccessType.ModifyProject);
|
||||
|
||||
//at this point enabling project doesn't require anything, so just update the state
|
||||
project.setState(State.Active);
|
||||
_projectDao.update(projectId, project);
|
||||
|
||||
return project;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@ActionEvent(eventType = EventTypes.EVENT_PROJECT_DELETE, eventDescription = "deleting project", async = true)
|
||||
@DB
|
||||
|
|
@ -382,7 +405,6 @@ public class ProjectManagerImpl implements ProjectManager, Manager{
|
|||
}
|
||||
|
||||
@Override
|
||||
@ActionEvent(eventType = EventTypes.EVENT_PROJECT_ACCOUNT_ADD, eventDescription = "adding account to project")
|
||||
public ProjectAccount assignAccountToProject(Project project, long accountId, ProjectAccount.Role accountRole) {
|
||||
return _projectAccountDao.persist(new ProjectAccountVO(project, accountId, accountRole));
|
||||
}
|
||||
|
|
@ -436,7 +458,7 @@ public class ProjectManagerImpl implements ProjectManager, Manager{
|
|||
}
|
||||
|
||||
@Override @DB
|
||||
@ActionEvent(eventType = EventTypes.EVENT_PROJECT_UPDATE, eventDescription = "updating project")
|
||||
@ActionEvent(eventType = EventTypes.EVENT_PROJECT_UPDATE, eventDescription = "updating project", async=true)
|
||||
public Project updateProject(long projectId, String displayText, String newOwnerName) {
|
||||
Account caller = UserContext.current().getCaller();
|
||||
|
||||
|
|
@ -491,6 +513,7 @@ public class ProjectManagerImpl implements ProjectManager, Manager{
|
|||
}
|
||||
|
||||
@Override
|
||||
@ActionEvent(eventType = EventTypes.EVENT_PROJECT_ACCOUNT_ADD, eventDescription = "adding account to project", async=true)
|
||||
public boolean addAccountToProject(long projectId, String accountName, String email) {
|
||||
Account caller = UserContext.current().getCaller();
|
||||
|
||||
|
|
@ -523,6 +546,9 @@ public class ProjectManagerImpl implements ProjectManager, Manager{
|
|||
if (_invitationRequired) {
|
||||
return inviteAccountToProject(project, account, email);
|
||||
} else {
|
||||
if (account == null) {
|
||||
throw new InvalidParameterValueException("Account information is required for assigning account to the project");
|
||||
}
|
||||
if (assignAccountToProject(project, account.getId(), ProjectAccount.Role.Regular) != null) {
|
||||
return true;
|
||||
} else {
|
||||
|
|
@ -557,7 +583,7 @@ public class ProjectManagerImpl implements ProjectManager, Manager{
|
|||
}
|
||||
|
||||
@Override
|
||||
@ActionEvent(eventType = EventTypes.EVENT_PROJECT_ACCOUNT_REMOVE, eventDescription = "removing account from project")
|
||||
@ActionEvent(eventType = EventTypes.EVENT_PROJECT_ACCOUNT_REMOVE, eventDescription = "removing account from project", async=true)
|
||||
public boolean deleteAccountFromProject(long projectId, String accountName) {
|
||||
Account caller = UserContext.current().getCaller();
|
||||
|
||||
|
|
@ -755,6 +781,7 @@ public class ProjectManagerImpl implements ProjectManager, Manager{
|
|||
}
|
||||
|
||||
@Override @DB
|
||||
@ActionEvent(eventType = EventTypes.EVENT_PROJECT_JOIN, eventDescription = "account joining from project", async=true)
|
||||
public boolean joinProject(long projectId, String accountName, String token) {
|
||||
Account caller = UserContext.current().getCaller();
|
||||
Long accountId = null;
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ public class ProjectVO implements Project{
|
|||
this.displayText = displayText;
|
||||
this.projectAccountId = projectAccountId;
|
||||
this.domainId = domainId;
|
||||
this.state = State.Active;
|
||||
this.state = State.Disabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Reference in New Issue