use of com.cloud.domain.Domain in project CloudStack-archive by CloudStack-extras.
the class BaseCmd method finalyzeAccountId.
public Long finalyzeAccountId(String accountName, Long domainId, Long projectId, boolean enabledOnly) {
if (accountName != null) {
if (domainId == null) {
throw new InvalidParameterValueException("Account must be specified with domainId parameter");
}
Domain domain = _domainService.getDomain(domainId);
if (domain == null) {
throw new InvalidParameterValueException("Unable to find domain by id=" + domainId);
}
Account account = _accountService.getActiveAccountByName(accountName, domainId);
if (account != null && account.getType() != Account.ACCOUNT_TYPE_PROJECT) {
if (!enabledOnly || account.getState() == Account.State.enabled) {
return account.getId();
} else {
throw new PermissionDeniedException("Can't add resources to the account id=" + account.getId() + " in state=" + account.getState() + " as it's no longer active");
}
} else {
throw new InvalidParameterValueException("Unable to find account by name " + accountName + " in domain id=" + domainId);
}
}
if (projectId != null) {
Project project = _projectService.getProject(projectId);
if (project != null) {
if (!enabledOnly || project.getState() == Project.State.Active) {
return project.getProjectAccountId();
} else {
PermissionDeniedException ex = new PermissionDeniedException("Can't add resources to the project with specified projectId in state=" + project.getState() + " as it's no longer active");
ex.addProxyObject(project, projectId, "projectId");
throw ex;
}
} else {
InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find project with specified projectId");
ex.addProxyObject(project, projectId, "projectId");
throw ex;
}
}
return null;
}
use of com.cloud.domain.Domain in project CloudStack-archive by CloudStack-extras.
the class CreateDomainCmd method execute.
@Override
public void execute() {
UserContext.current().setEventDetails("Domain Name: " + getDomainName() + ((getParentDomainId() != null) ? ", Parent DomainId :" + getParentDomainId() : ""));
Domain domain = _domainService.createDomain(getDomainName(), getParentDomainId(), getNetworkDomain());
if (domain != null) {
DomainResponse response = _responseGenerator.createDomainResponse(domain);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create domain");
}
}
use of com.cloud.domain.Domain in project CloudStack-archive by CloudStack-extras.
the class ListDomainsCmd method execute.
@Override
public void execute() {
List<? extends Domain> result = _domainService.searchForDomains(this);
ListResponse<DomainResponse> response = new ListResponse<DomainResponse>();
List<DomainResponse> domainResponses = new ArrayList<DomainResponse>();
for (Domain domain : result) {
DomainResponse domainResponse = _responseGenerator.createDomainResponse(domain);
domainResponse.setObjectName("domain");
domainResponses.add(domainResponse);
}
response.setResponses(domainResponses);
response.setResponseName(getCommandName());
this.setResponseObject(response);
}
use of com.cloud.domain.Domain in project CloudStack-archive by CloudStack-extras.
the class UpdateDomainCmd method execute.
@Override
public void execute() {
UserContext.current().setEventDetails("Domain Id: " + getId());
Domain domain = _mgr.updateDomain(this);
if (domain != null) {
DomainResponse response = _responseGenerator.createDomainResponse(domain);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update domain");
}
}
use of com.cloud.domain.Domain in project cloudstack by apache.
the class CreateDomainCmd method execute.
@Override
public void execute() {
CallContext.current().setEventDetails("Domain Name: " + getDomainName() + ((getParentDomainId() != null) ? ", Parent DomainId :" + getParentDomainId() : ""));
Domain domain = _domainService.createDomain(getDomainName(), getParentDomainId(), getNetworkDomain(), getDomainUUID());
if (domain != null) {
DomainResponse response = _responseGenerator.createDomainResponse(domain);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create domain");
}
}
Aggregations