Search in sources :

Example 91 with ListResponse

use of com.cloud.api.response.ListResponse in project CloudStack-archive by CloudStack-extras.

the class RegisterIsoCmd method execute.

@Override
public void execute() throws ResourceAllocationException {
    VirtualMachineTemplate template = _templateService.registerIso(this);
    if (template != null) {
        ListResponse<TemplateResponse> response = new ListResponse<TemplateResponse>();
        List<TemplateResponse> templateResponses = _responseGenerator.createIsoResponses(template.getId(), zoneId, false);
        response.setResponses(templateResponses);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to register iso");
    }
}
Also used : VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) ListResponse(com.cloud.api.response.ListResponse) ServerApiException(com.cloud.api.ServerApiException) TemplateResponse(com.cloud.api.response.TemplateResponse)

Example 92 with ListResponse

use of com.cloud.api.response.ListResponse in project CloudStack-archive by CloudStack-extras.

the class ListVpnUsersCmd method execute.

@Override
public void execute() {
    List<? extends VpnUser> vpnUsers = _ravService.searchForVpnUsers(this);
    ListResponse<VpnUsersResponse> response = new ListResponse<VpnUsersResponse>();
    List<VpnUsersResponse> vpnResponses = new ArrayList<VpnUsersResponse>();
    for (VpnUser vpnUser : vpnUsers) {
        vpnResponses.add(_responseGenerator.createVpnUserResponse(vpnUser));
    }
    response.setResponses(vpnResponses);
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : VpnUser(com.cloud.network.VpnUser) ListResponse(com.cloud.api.response.ListResponse) ArrayList(java.util.ArrayList) VpnUsersResponse(com.cloud.api.response.VpnUsersResponse)

Example 93 with ListResponse

use of com.cloud.api.response.ListResponse in project CloudStack-archive by CloudStack-extras.

the class ListSupportedNetworkServicesCmd method execute.

@Override
public void execute() {
    List<? extends Network.Service> services;
    if (getServiceName() != null) {
        Network.Service service = null;
        if (serviceName != null) {
            service = Network.Service.getService(serviceName);
            if (service == null) {
                throw new InvalidParameterValueException("Invalid Network Service=" + serviceName);
            }
        }
        List<Network.Service> serviceList = new ArrayList<Network.Service>();
        serviceList.add(service);
        services = serviceList;
    } else {
        services = _networkService.listNetworkServices(getProviderName());
    }
    ListResponse<ServiceResponse> response = new ListResponse<ServiceResponse>();
    List<ServiceResponse> servicesResponses = new ArrayList<ServiceResponse>();
    for (Network.Service service : services) {
        //skip gateway service
        if (service == Service.Gateway) {
            continue;
        }
        ServiceResponse serviceResponse = _responseGenerator.createNetworkServiceResponse(service);
        servicesResponses.add(serviceResponse);
    }
    response.setResponses(servicesResponses);
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : ServiceResponse(com.cloud.api.response.ServiceResponse) ListResponse(com.cloud.api.response.ListResponse) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Network(com.cloud.network.Network) ArrayList(java.util.ArrayList) Service(com.cloud.network.Network.Service) Service(com.cloud.network.Network.Service)

Example 94 with ListResponse

use of com.cloud.api.response.ListResponse in project CloudStack-archive by CloudStack-extras.

the class ListSwiftsCmd method execute.

@Override
public void execute() {
    List<? extends Swift> result = _resourceService.listSwifts(this);
    ListResponse<SwiftResponse> response = new ListResponse<SwiftResponse>();
    List<SwiftResponse> swiftResponses = new ArrayList<SwiftResponse>();
    if (result != null) {
        SwiftResponse swiftResponse = null;
        for (Swift swift : result) {
            swiftResponse = _responseGenerator.createSwiftResponse(swift);
            swiftResponse.setResponseName(getCommandName());
            swiftResponse.setObjectName("swift");
            swiftResponses.add(swiftResponse);
        }
    }
    response.setResponses(swiftResponses);
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : ListResponse(com.cloud.api.response.ListResponse) SwiftResponse(com.cloud.api.response.SwiftResponse) ArrayList(java.util.ArrayList) Swift(com.cloud.storage.Swift)

Example 95 with ListResponse

use of com.cloud.api.response.ListResponse in project CloudStack-archive by CloudStack-extras.

the class AddClusterCmd method execute.

@Override
public void execute() {
    try {
        List<? extends Cluster> result = _resourceService.discoverCluster(this);
        ListResponse<ClusterResponse> response = new ListResponse<ClusterResponse>();
        List<ClusterResponse> clusterResponses = new ArrayList<ClusterResponse>();
        if (result != null) {
            for (Cluster cluster : result) {
                ClusterResponse clusterResponse = _responseGenerator.createClusterResponse(cluster, false);
                clusterResponses.add(clusterResponse);
            }
        } else {
            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add cluster");
        }
        response.setResponses(clusterResponses);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } catch (DiscoveryException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
    } catch (ResourceInUseException ex) {
        s_logger.warn("Exception: ", ex);
        ServerApiException e = new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
        for (IdentityProxy proxyObj : ex.getIdProxyList()) {
            e.addProxyObject(proxyObj.getTableName(), proxyObj.getValue(), proxyObj.getidFieldName());
        }
        throw e;
    }
}
Also used : IdentityProxy(com.cloud.utils.IdentityProxy) ListResponse(com.cloud.api.response.ListResponse) ServerApiException(com.cloud.api.ServerApiException) ResourceInUseException(com.cloud.exception.ResourceInUseException) ArrayList(java.util.ArrayList) ClusterResponse(com.cloud.api.response.ClusterResponse) Cluster(com.cloud.org.Cluster) DiscoveryException(com.cloud.exception.DiscoveryException)

Aggregations

ListResponse (com.cloud.api.response.ListResponse)156 ArrayList (java.util.ArrayList)139 List (java.util.List)60 ServerApiException (com.cloud.api.ServerApiException)30 TemplateResponse (com.cloud.api.response.TemplateResponse)13 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)11 ResponseView (com.cloud.api.ResponseObject.ResponseView)10 Network (com.cloud.network.Network)9 DedicatedResources (com.cloud.dc.DedicatedResources)8 VirtualMachineTemplate (com.cloud.template.VirtualMachineTemplate)8 DomainResponse (com.cloud.api.response.DomainResponse)7 DedicatedResourceVO (com.cloud.dc.DedicatedResourceVO)7 Domain (com.cloud.domain.Domain)7 VirtualMachine (com.cloud.vm.VirtualMachine)7 StoragePoolResponse (com.cloud.api.response.StoragePoolResponse)6 UserResponse (com.cloud.api.response.UserResponse)6 UserVmResponse (com.cloud.api.response.UserVmResponse)6 Host (com.cloud.host.Host)6 AccountResponse (com.cloud.api.response.AccountResponse)5 HostResponse (com.cloud.api.response.HostResponse)5