Search in sources :

Example 31 with Domain

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;
}
Also used : Account(com.cloud.user.Account) Project(com.cloud.projects.Project) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) Domain(com.cloud.domain.Domain)

Example 32 with Domain

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");
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) DomainResponse(com.cloud.api.response.DomainResponse) Domain(com.cloud.domain.Domain)

Example 33 with 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);
}
Also used : ListResponse(com.cloud.api.response.ListResponse) DomainResponse(com.cloud.api.response.DomainResponse) ArrayList(java.util.ArrayList) Domain(com.cloud.domain.Domain)

Example 34 with Domain

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");
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) DomainResponse(com.cloud.api.response.DomainResponse) Domain(com.cloud.domain.Domain)

Example 35 with 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");
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) DomainResponse(org.apache.cloudstack.api.response.DomainResponse) Domain(com.cloud.domain.Domain)

Aggregations

Domain (com.cloud.domain.Domain)81 Account (com.cloud.user.Account)42 ArrayList (java.util.ArrayList)23 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)20 Test (org.junit.Test)20 DeployDestination (com.cloud.deploy.DeployDestination)17 Network (com.cloud.network.Network)17 ReservationContext (com.cloud.vm.ReservationContext)17 DataCenter (com.cloud.dc.DataCenter)16 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)16 NetworkOffering (com.cloud.offering.NetworkOffering)16 HostVO (com.cloud.host.HostVO)15 NetworkVO (com.cloud.network.dao.NetworkVO)15 UserAccount (com.cloud.user.UserAccount)15 URI (java.net.URI)12 DomainVO (com.cloud.domain.DomainVO)11 ProjectAccount (com.cloud.projects.ProjectAccount)11 Project (com.cloud.projects.Project)10 NiciraNvpDeviceVO (com.cloud.network.NiciraNvpDeviceVO)8 DB (com.cloud.utils.db.DB)8