Search in sources :

Example 1 with LoadBalancerRuleVmMapResponse

use of com.cloud.api.response.LoadBalancerRuleVmMapResponse in project cosmic by MissionCriticalCloud.

the class ListLoadBalancerRuleInstancesCmdByAdmin method execute.

@Override
public void execute() {
    final Pair<List<? extends UserVm>, List<String>> vmServiceMap = _lbService.listLoadBalancerInstances(this);
    final List<? extends UserVm> result = vmServiceMap.first();
    final List<String> serviceStates = vmServiceMap.second();
    if (!isListLbVmip()) {
        // list lb instances
        final ListResponse<UserVmResponse> response = new ListResponse<>();
        List<UserVmResponse> vmResponses = new ArrayList<>();
        if (result != null) {
            vmResponses = _responseGenerator.createUserVmResponse(ResponseView.Restricted, "loadbalancerruleinstance", result.toArray(new UserVm[result.size()]));
            for (int i = 0; i < result.size(); i++) {
                vmResponses.get(i).setServiceState(serviceStates.get(i));
            }
        }
        response.setResponses(vmResponses);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        final ListResponse<LoadBalancerRuleVmMapResponse> lbRes = new ListResponse<>();
        List<UserVmResponse> vmResponses = new ArrayList<>();
        final List<LoadBalancerRuleVmMapResponse> listlbVmRes = new ArrayList<>();
        if (result != null) {
            vmResponses = _responseGenerator.createUserVmResponse(ResponseView.Full, "loadbalancerruleinstance", result.toArray(new UserVm[result.size()]));
            final List<String> ipaddr = null;
            for (int i = 0; i < result.size(); i++) {
                final LoadBalancerRuleVmMapResponse lbRuleVmIpResponse = new LoadBalancerRuleVmMapResponse();
                vmResponses.get(i).setServiceState(serviceStates.get(i));
                lbRuleVmIpResponse.setUserVmResponse(vmResponses.get(i));
                // get vm id from the uuid
                final VirtualMachine lbvm = _entityMgr.findByUuid(VirtualMachine.class, vmResponses.get(i).getId());
                lbRuleVmIpResponse.setIpAddr(_lbService.listLbVmIpAddress(getId(), lbvm.getId()));
                lbRuleVmIpResponse.setObjectName("lbrulevmidip");
                listlbVmRes.add(lbRuleVmIpResponse);
            }
        }
        lbRes.setResponseName(getCommandName());
        lbRes.setResponses(listlbVmRes);
        setResponseObject(lbRes);
    }
}
Also used : ListResponse(com.cloud.api.response.ListResponse) ArrayList(java.util.ArrayList) LoadBalancerRuleVmMapResponse(com.cloud.api.response.LoadBalancerRuleVmMapResponse) UserVmResponse(com.cloud.api.response.UserVmResponse) UserVm(com.cloud.uservm.UserVm) ArrayList(java.util.ArrayList) List(java.util.List) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 2 with LoadBalancerRuleVmMapResponse

use of com.cloud.api.response.LoadBalancerRuleVmMapResponse in project cosmic by MissionCriticalCloud.

the class ListLoadBalancerRuleInstancesCmd method execute.

@Override
public void execute() {
    final Pair<List<? extends UserVm>, List<String>> vmServiceMap = _lbService.listLoadBalancerInstances(this);
    final List<? extends UserVm> result = vmServiceMap.first();
    final List<String> serviceStates = vmServiceMap.second();
    if (!isListLbVmip()) {
        // list lb instances
        final ListResponse<UserVmResponse> response = new ListResponse<>();
        List<UserVmResponse> vmResponses = new ArrayList<>();
        if (result != null) {
            vmResponses = _responseGenerator.createUserVmResponse(ResponseView.Restricted, "loadbalancerruleinstance", result.toArray(new UserVm[result.size()]));
            for (int i = 0; i < result.size(); i++) {
                vmResponses.get(i).setServiceState(serviceStates.get(i));
            }
        }
        response.setResponses(vmResponses);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        final ListResponse<LoadBalancerRuleVmMapResponse> lbRes = new ListResponse<>();
        List<UserVmResponse> vmResponses = new ArrayList<>();
        final List<LoadBalancerRuleVmMapResponse> listlbVmRes = new ArrayList<>();
        if (result != null) {
            vmResponses = _responseGenerator.createUserVmResponse(ResponseView.Full, "loadbalancerruleinstance", result.toArray(new UserVm[result.size()]));
            final List<String> ipaddr = null;
            for (int i = 0; i < result.size(); i++) {
                final LoadBalancerRuleVmMapResponse lbRuleVmIpResponse = new LoadBalancerRuleVmMapResponse();
                vmResponses.get(i).setServiceState(serviceStates.get(i));
                lbRuleVmIpResponse.setUserVmResponse(vmResponses.get(i));
                // get vm id from the uuid
                final VirtualMachine lbvm = _entityMgr.findByUuid(VirtualMachine.class, vmResponses.get(i).getId());
                lbRuleVmIpResponse.setIpAddr(_lbService.listLbVmIpAddress(getId(), lbvm.getId()));
                lbRuleVmIpResponse.setObjectName("lbrulevmidip");
                listlbVmRes.add(lbRuleVmIpResponse);
            }
        }
        lbRes.setResponseName(getCommandName());
        lbRes.setResponses(listlbVmRes);
        setResponseObject(lbRes);
    }
}
Also used : ListResponse(com.cloud.api.response.ListResponse) ArrayList(java.util.ArrayList) LoadBalancerRuleVmMapResponse(com.cloud.api.response.LoadBalancerRuleVmMapResponse) UserVmResponse(com.cloud.api.response.UserVmResponse) UserVm(com.cloud.uservm.UserVm) ArrayList(java.util.ArrayList) List(java.util.List) VirtualMachine(com.cloud.vm.VirtualMachine)

Aggregations

ListResponse (com.cloud.api.response.ListResponse)2 LoadBalancerRuleVmMapResponse (com.cloud.api.response.LoadBalancerRuleVmMapResponse)2 UserVmResponse (com.cloud.api.response.UserVmResponse)2 UserVm (com.cloud.uservm.UserVm)2 VirtualMachine (com.cloud.vm.VirtualMachine)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2