Search in sources :

Example 1 with DomainResponse

use of org.apache.cloudstack.api.response.DomainResponse in project cloudstack by apache.

the class DomainJoinDaoImpl method newDomainResponse.

@Override
public DomainResponse newDomainResponse(ResponseView view, DomainJoinVO domain) {
    DomainResponse domainResponse = new DomainResponse();
    domainResponse.setDomainName(domain.getName());
    domainResponse.setId(domain.getUuid());
    domainResponse.setLevel(domain.getLevel());
    domainResponse.setNetworkDomain(domain.getNetworkDomain());
    Domain parentDomain = ApiDBUtils.findDomainById(domain.getParent());
    if (parentDomain != null) {
        domainResponse.setParentDomainId(parentDomain.getUuid());
    }
    StringBuilder domainPath = new StringBuilder("ROOT");
    (domainPath.append(domain.getPath())).deleteCharAt(domainPath.length() - 1);
    domainResponse.setPath(domainPath.toString());
    if (domain.getParent() != null) {
        domainResponse.setParentDomainName(ApiDBUtils.findDomainById(domain.getParent()).getName());
    }
    if (domain.getChildCount() > 0) {
        domainResponse.setHasChild(true);
    }
    domainResponse.setState(domain.getState().toString());
    domainResponse.setNetworkDomain(domain.getNetworkDomain());
    boolean fullView = (view == ResponseView.Full && domain.getId() == Domain.ROOT_DOMAIN);
    setResourceLimits(domain, fullView, domainResponse);
    //get resource limits for projects
    long projectLimit = ApiDBUtils.findCorrectResourceLimitForDomain(domain.getProjectLimit(), fullView, ResourceType.project, domain.getId());
    String projectLimitDisplay = (fullView || projectLimit == -1) ? "Unlimited" : String.valueOf(projectLimit);
    long projectTotal = (domain.getProjectTotal() == null) ? 0 : domain.getProjectTotal();
    String projectAvail = (fullView || projectLimit == -1) ? "Unlimited" : String.valueOf(projectLimit - projectTotal);
    domainResponse.setProjectLimit(projectLimitDisplay);
    domainResponse.setProjectTotal(projectTotal);
    domainResponse.setProjectAvailable(projectAvail);
    domainResponse.setObjectName("domain");
    return domainResponse;
}
Also used : DomainResponse(org.apache.cloudstack.api.response.DomainResponse) Domain(com.cloud.domain.Domain)

Example 2 with DomainResponse

use of org.apache.cloudstack.api.response.DomainResponse 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)

Example 3 with DomainResponse

use of org.apache.cloudstack.api.response.DomainResponse in project cloudstack by apache.

the class ListDomainChildrenCmd method execute.

@Override
public void execute() {
    Pair<List<? extends Domain>, Integer> result = _domainService.searchForDomainChildren(this);
    ListResponse<DomainResponse> response = new ListResponse<DomainResponse>();
    List<DomainResponse> domainResponses = new ArrayList<DomainResponse>();
    for (Domain domain : result.first()) {
        DomainResponse domainResponse = _responseGenerator.createDomainResponse(domain);
        domainResponse.setObjectName("domain");
        domainResponses.add(domainResponse);
    }
    response.setResponses(domainResponses, result.second());
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) DomainResponse(org.apache.cloudstack.api.response.DomainResponse) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Domain(com.cloud.domain.Domain)

Example 4 with DomainResponse

use of org.apache.cloudstack.api.response.DomainResponse in project cloudstack by apache.

the class UpdateDomainCmd method execute.

@Override
public void execute() {
    CallContext.current().setEventDetails("Domain Id: " + getId());
    Domain domain = _regionService.updateDomain(this);
    if (domain != null) {
        DomainResponse response = _responseGenerator.createDomainResponse(domain);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update domain");
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) DomainResponse(org.apache.cloudstack.api.response.DomainResponse) Domain(com.cloud.domain.Domain)

Example 5 with DomainResponse

use of org.apache.cloudstack.api.response.DomainResponse in project cloudstack by apache.

the class ApiResponseHelper method createDomainResponse.

@Override
public DomainResponse createDomainResponse(Domain domain) {
    DomainResponse domainResponse = new DomainResponse();
    domainResponse.setDomainName(domain.getName());
    domainResponse.setId(domain.getUuid());
    domainResponse.setLevel(domain.getLevel());
    domainResponse.setNetworkDomain(domain.getNetworkDomain());
    Domain parentDomain = ApiDBUtils.findDomainById(domain.getParent());
    if (parentDomain != null) {
        domainResponse.setParentDomainId(parentDomain.getUuid());
    }
    StringBuilder domainPath = new StringBuilder("ROOT");
    (domainPath.append(domain.getPath())).deleteCharAt(domainPath.length() - 1);
    domainResponse.setPath(domainPath.toString());
    if (domain.getParent() != null) {
        domainResponse.setParentDomainName(ApiDBUtils.findDomainById(domain.getParent()).getName());
    }
    if (domain.getChildCount() > 0) {
        domainResponse.setHasChild(true);
    }
    domainResponse.setObjectName("domain");
    return domainResponse;
}
Also used : DomainResponse(org.apache.cloudstack.api.response.DomainResponse) Domain(com.cloud.domain.Domain)

Aggregations

DomainResponse (org.apache.cloudstack.api.response.DomainResponse)6 Domain (com.cloud.domain.Domain)5 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ServerApiException (org.apache.cloudstack.api.ServerApiException)2 ListResponse (org.apache.cloudstack.api.response.ListResponse)2 DomainJoinVO (com.cloud.api.query.vo.DomainJoinVO)1 ResponseView (org.apache.cloudstack.api.ResponseObject.ResponseView)1 ListDomainsCmdByAdmin (org.apache.cloudstack.api.command.admin.domain.ListDomainsCmdByAdmin)1