mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Events for adding/removing project users
This commit is contained in:
parent
a623b2824b
commit
eda1b53c76
@ -26,7 +26,10 @@ import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.response.SuccessResponse;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.projects.Project;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.UserContext;
|
||||
|
||||
@Implementation(description="Adds acoount to a project", responseObject=SuccessResponse.class)
|
||||
public class AddAccountToProjectCmd extends BaseCmd {
|
||||
@ -72,6 +75,7 @@ public class AddAccountToProjectCmd extends BaseCmd {
|
||||
|
||||
@Override
|
||||
public void execute(){
|
||||
UserContext.current().setEventDetails("Project id: "+ projectId + "; accountName " + accountName);
|
||||
boolean result = _projectService.addAccountToProject(getProjectId(), getAccountName());
|
||||
if (result) {
|
||||
SuccessResponse response = new SuccessResponse(getCommandName());
|
||||
@ -83,7 +87,12 @@ public class AddAccountToProjectCmd extends BaseCmd {
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
//TODO - return project entity ownerId
|
||||
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
|
||||
Project project= _projectService.getProject(projectId);
|
||||
//verify input parameters
|
||||
if (project == null) {
|
||||
throw new InvalidParameterValueException("Unable to find project by id " + projectId);
|
||||
}
|
||||
|
||||
return _projectService.getProjectOwner(projectId).getId();
|
||||
}
|
||||
}
|
||||
@ -26,6 +26,7 @@ import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.response.ProjectResponse;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.projects.Project;
|
||||
import com.cloud.user.Account;
|
||||
@ -80,8 +81,17 @@ public class CreateProjectCmd extends BaseCmd {
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
//TODO - return project entity ownerId
|
||||
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
|
||||
Account caller = UserContext.current().getCaller();
|
||||
|
||||
if ((accountName != null && domainId == null) || (domainId != null && accountName == null)) {
|
||||
throw new InvalidParameterValueException("Account name and domain id must be specified together");
|
||||
}
|
||||
|
||||
if (accountName != null) {
|
||||
return _accountService.finalizeOwner(caller, accountName, domainId).getId();
|
||||
}
|
||||
|
||||
return caller.getId();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -26,7 +26,9 @@ import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.response.SuccessResponse;
|
||||
import com.cloud.user.Account;
|
||||
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 {
|
||||
@ -69,6 +71,7 @@ public class DeleteAccountFromProjectCmd extends BaseCmd {
|
||||
|
||||
@Override
|
||||
public void execute(){
|
||||
UserContext.current().setEventDetails("Project id: "+ projectId + "; accountName " + accountName);
|
||||
boolean result = _projectService.deleteAccountFromProject(projectId, accountName);
|
||||
if (result) {
|
||||
SuccessResponse response = new SuccessResponse(getCommandName());
|
||||
@ -81,7 +84,12 @@ public class DeleteAccountFromProjectCmd extends BaseCmd {
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
//TODO - return project entity ownerId
|
||||
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
|
||||
Project project= _projectService.getProject(projectId);
|
||||
//verify input parameters
|
||||
if (project == null) {
|
||||
throw new InvalidParameterValueException("Unable to find project by id " + projectId);
|
||||
}
|
||||
|
||||
return _projectService.getProjectOwner(projectId).getId();
|
||||
}
|
||||
}
|
||||
@ -28,7 +28,8 @@ 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.exception.InvalidParameterValueException;
|
||||
import com.cloud.projects.Project;
|
||||
import com.cloud.user.UserContext;
|
||||
|
||||
@Implementation(description="Deletes a project", responseObject=SuccessResponse.class)
|
||||
@ -86,7 +87,13 @@ public class DeleteProjectCmd extends BaseAsyncCmd {
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
//TODO - return project entity ownerId
|
||||
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
|
||||
Project project= _projectService.getProject(id);
|
||||
//verify input parameters
|
||||
if (project == null) {
|
||||
throw new InvalidParameterValueException("Unable to find project by id " + id);
|
||||
}
|
||||
|
||||
return _projectService.getProjectOwner(id).getId();
|
||||
}
|
||||
|
||||
}
|
||||
@ -26,6 +26,7 @@ import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.response.SuccessResponse;
|
||||
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 {
|
||||
@ -71,6 +72,7 @@ public class JoinProjectCmd extends BaseCmd {
|
||||
|
||||
@Override
|
||||
public void execute(){
|
||||
UserContext.current().setEventDetails("Project id: "+ projectId + "; accountName " + accountName);
|
||||
boolean result = _projectService.joinProject(projectId, accountName);
|
||||
if (result) {
|
||||
SuccessResponse response = new SuccessResponse(getCommandName());
|
||||
|
||||
@ -26,8 +26,8 @@ import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.response.ProjectResponse;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.projects.Project;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.UserContext;
|
||||
|
||||
@Implementation(description="Updates a project", responseObject=ProjectResponse.class)
|
||||
@ -72,9 +72,13 @@ public class UpdateProjectCmd extends BaseCmd {
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
//TODO - return project entity ownerId
|
||||
|
||||
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
|
||||
Project project= _projectService.getProject(id);
|
||||
//verify input parameters
|
||||
if (project == null) {
|
||||
throw new InvalidParameterValueException("Unable to find project by id " + id);
|
||||
}
|
||||
|
||||
return _projectService.getProjectOwner(id).getId();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -205,6 +205,8 @@ public class EventTypes {
|
||||
|
||||
//Projects
|
||||
public static final String EVENT_PROJECT_CREATE = "PROJECT.CREATE";
|
||||
public static final String EVENT_PROJECT_UPDATE = "PROJECT.UPDATE";
|
||||
public static final String EVENT_PROJECT_DELETE = "PROJECT.DELETE";
|
||||
|
||||
public static final String EVENT_PROJECT_ACCOUNT_ADD = "PROJECT.ACCOUNT.ADD";
|
||||
public static final String EVENT_PROJECT_ACCOUNT_REMOVE = "PROJECT.ACCOUNT.REMOVE";
|
||||
}
|
||||
|
||||
@ -648,4 +648,8 @@ public class ApiDBUtils {
|
||||
public static Project findProjectById(long projectId) {
|
||||
return _projectMgr.getProject(projectId);
|
||||
}
|
||||
|
||||
public static long getProjectOwnwerId(long projectId) {
|
||||
return _projectMgr.getProjectOwner(projectId).getId();
|
||||
}
|
||||
}
|
||||
|
||||
@ -138,8 +138,6 @@ public class ProjectManagerImpl implements ProjectManager, Manager{
|
||||
throw new InvalidParameterValueException("Project with name " + name + " already exists in domain id=" + owner.getDomainId());
|
||||
}
|
||||
|
||||
Domain ownerDomain = _domainDao.findById(owner.getDomainId());
|
||||
|
||||
//do resource limit check
|
||||
_resourceLimitMgr.checkResourceLimit(owner, ResourceType.project);
|
||||
|
||||
@ -227,7 +225,7 @@ public class ProjectManagerImpl implements ProjectManager, Manager{
|
||||
|
||||
//Delete project's domain
|
||||
s_logger.debug("Deleting projects " + project + " internal domain id=" + project.getProjectDomainId() + " as a part of project cleanup...");
|
||||
result = result && _domainMgr.deleteDomain(project.getProjectDomainId(), true);
|
||||
result = result && _domainMgr.deleteDomain(_domainDao.findById(project.getProjectDomainId()), true);
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -335,6 +333,7 @@ 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));
|
||||
}
|
||||
@ -386,6 +385,7 @@ public class ProjectManagerImpl implements ProjectManager, Manager{
|
||||
}
|
||||
|
||||
@Override @DB
|
||||
@ActionEvent(eventType = EventTypes.EVENT_PROJECT_UPDATE, eventDescription = "updating project")
|
||||
public Project updateProject(long projectId, String displayText, String newOwnerName) {
|
||||
Account caller = UserContext.current().getCaller();
|
||||
|
||||
@ -486,6 +486,7 @@ public class ProjectManagerImpl implements ProjectManager, Manager{
|
||||
}
|
||||
|
||||
@Override
|
||||
@ActionEvent(eventType = EventTypes.EVENT_PROJECT_ACCOUNT_REMOVE, eventDescription = "removing account from project")
|
||||
public boolean deleteAccountFromProject(long projectId, String accountName) {
|
||||
Account caller = UserContext.current().getCaller();
|
||||
|
||||
|
||||
@ -595,6 +595,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
|
||||
@Override
|
||||
@DB
|
||||
@ActionEvent(eventType = EventTypes.EVENT_ACCOUNT_CREATE, eventDescription = "creating Account")
|
||||
public UserAccount createUserAccount(String userName, String password, String firstName, String lastName, String email, String timezone, String accountName, short accountType, Long domainId, String networkDomain) {
|
||||
|
||||
if (accountName == null) {
|
||||
@ -1277,7 +1278,6 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
}
|
||||
|
||||
@Override @DB
|
||||
@ActionEvent(eventType = EventTypes.EVENT_ACCOUNT_CREATE, eventDescription = "creating Account")
|
||||
public Account createAccount(String accountName, short accountType, Long domainId, String networkDomain) {
|
||||
//Validate domain
|
||||
Domain domain = _domainMgr.getDomain(domainId);
|
||||
|
||||
@ -21,12 +21,13 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.cloud.domain.Domain;
|
||||
import com.cloud.domain.Domain.Type;
|
||||
import com.cloud.domain.DomainVO;
|
||||
|
||||
public interface DomainManager extends DomainService{
|
||||
Set<Long> getDomainChildrenIds(String parentDomainPath);
|
||||
|
||||
Domain createDomain(String name, Long parentId, Long ownerId, String networkDomain, Domain.Type domainType);
|
||||
Domain createDomain(String name, Long parentId, Long ownerId, String networkDomain, Type domainType);
|
||||
|
||||
/**
|
||||
* find the domain by its path
|
||||
@ -42,4 +43,7 @@ public interface DomainManager extends DomainService{
|
||||
boolean removeDomain(long domainId);
|
||||
|
||||
List<? extends Domain> findInactiveDomains();
|
||||
|
||||
boolean deleteDomain(DomainVO domain, Boolean cleanup);
|
||||
|
||||
}
|
||||
|
||||
@ -31,6 +31,7 @@ import org.apache.log4j.Logger;
|
||||
import com.cloud.configuration.ResourceLimit;
|
||||
import com.cloud.configuration.dao.ResourceCountDao;
|
||||
import com.cloud.domain.Domain;
|
||||
import com.cloud.domain.Domain.Type;
|
||||
import com.cloud.domain.DomainVO;
|
||||
import com.cloud.domain.dao.DomainDao;
|
||||
import com.cloud.event.ActionEvent;
|
||||
@ -118,7 +119,7 @@ public class DomainManagerImpl implements DomainManager, DomainService, Manager{
|
||||
}
|
||||
|
||||
@Override
|
||||
@DB
|
||||
@ActionEvent(eventType = EventTypes.EVENT_DOMAIN_CREATE, eventDescription = "creating Domain")
|
||||
public Domain createDomain(String name, Long parentId, String networkDomain) {
|
||||
Account caller = UserContext.current().getCaller();
|
||||
|
||||
@ -143,9 +144,8 @@ public class DomainManagerImpl implements DomainManager, DomainService, Manager{
|
||||
}
|
||||
|
||||
@Override
|
||||
@ActionEvent(eventType = EventTypes.EVENT_DOMAIN_CREATE, eventDescription = "creating Domain")
|
||||
@DB
|
||||
public Domain createDomain(String name, Long parentId, Long ownerId, String networkDomain, Domain.Type domainType) {
|
||||
public Domain createDomain(String name, Long parentId, Long ownerId, String networkDomain, Type domainType) {
|
||||
//Verify network domain
|
||||
if (networkDomain != null) {
|
||||
if (!NetUtils.verifyDomainName(networkDomain)) {
|
||||
@ -154,6 +154,7 @@ public class DomainManagerImpl implements DomainManager, DomainService, Manager{
|
||||
+ "and the hyphen ('-'); can't start or end with \"-\"");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//verify domainType
|
||||
if (domainType != null && !(domainType == Domain.Type.Project || domainType == Domain.Type.Normal)) {
|
||||
@ -180,6 +181,7 @@ public class DomainManagerImpl implements DomainManager, DomainService, Manager{
|
||||
return domain;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public DomainVO findDomainByPath(String domainPath) {
|
||||
return _domainDao.findDomainByPath(domainPath);
|
||||
@ -215,23 +217,28 @@ public class DomainManagerImpl implements DomainManager, DomainService, Manager{
|
||||
|
||||
_accountMgr.checkAccess(caller, domain, null);
|
||||
|
||||
return deleteDomain(domain, cleanup);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteDomain(DomainVO domain, Boolean cleanup) {
|
||||
//mark domain as inactive
|
||||
s_logger.debug("Marking domain id=" + domainId + " as " + Domain.State.Inactive + " before actually deleting it");
|
||||
s_logger.debug("Marking domain id=" + domain.getId() + " as " + Domain.State.Inactive + " before actually deleting it");
|
||||
domain.setState(Domain.State.Inactive);
|
||||
_domainDao.update(domainId, domain);
|
||||
_domainDao.update(domain.getId(), domain);
|
||||
|
||||
try {
|
||||
long ownerId = domain.getAccountId();
|
||||
if ((cleanup != null) && cleanup.booleanValue()) {
|
||||
if (!cleanupDomain(domainId, ownerId)) {
|
||||
s_logger.error("Failed to clean up domain resources and sub domains, delete failed on domain " + domain.getName() + " (id: " + domainId + ").");
|
||||
if (!cleanupDomain(domain.getId(), ownerId)) {
|
||||
s_logger.error("Failed to clean up domain resources and sub domains, delete failed on domain " + domain.getName() + " (id: " + domain.getId() + ").");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
List<AccountVO> accountsForCleanup = _accountDao.findCleanupsForRemovedAccounts(domainId);
|
||||
List<AccountVO> accountsForCleanup = _accountDao.findCleanupsForRemovedAccounts(domain.getId());
|
||||
if (accountsForCleanup.isEmpty()) {
|
||||
if (!_domainDao.remove(domainId)) {
|
||||
s_logger.error("Delete failed on domain " + domain.getName() + " (id: " + domainId
|
||||
if (!_domainDao.remove(domain.getId())) {
|
||||
s_logger.error("Delete failed on domain " + domain.getName() + " (id: " + domain.getId()
|
||||
+ "); please make sure all users and sub domains have been removed from the domain before deleting");
|
||||
return false;
|
||||
}
|
||||
@ -241,10 +248,10 @@ public class DomainManagerImpl implements DomainManager, DomainService, Manager{
|
||||
}
|
||||
}
|
||||
|
||||
cleanupDomainOfferings(domainId);
|
||||
cleanupDomainOfferings(domain.getId());
|
||||
return true;
|
||||
} catch (Exception ex) {
|
||||
s_logger.error("Exception deleting domain with id " + domainId, ex);
|
||||
s_logger.error("Exception deleting domain with id " + domain.getId(), ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user