Search in sources :

Example 16 with ListResponse

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

the class ListOvsElementsCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    List<? extends OvsProvider> providers = _service.get(0).searchForOvsElement(this);
    ListResponse<OvsProviderResponse> response = new ListResponse<OvsProviderResponse>();
    List<OvsProviderResponse> providerResponses = new ArrayList<OvsProviderResponse>();
    for (OvsProvider provider : providers) {
        OvsProviderResponse providerResponse = _responseGenerator.createOvsProviderResponse(provider);
        providerResponses.add(providerResponse);
    }
    response.setResponses(providerResponses);
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) OvsProvider(com.cloud.network.OvsProvider) ArrayList(java.util.ArrayList) OvsProviderResponse(org.apache.cloudstack.api.response.OvsProviderResponse)

Example 17 with ListResponse

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

the class ListCfgCmdTest method testCreateSuccess.

@Test
public void testCreateSuccess() {
    Configuration cfg = Mockito.mock(Configuration.class);
    listCfgsByCmd._mgr = mgr;
    listCfgsByCmd._responseGenerator = responseGenerator;
    List<Configuration> configList = new ArrayList<Configuration>();
    configList.add(cfg);
    Pair<List<? extends Configuration>, Integer> result = new Pair<List<? extends Configuration>, Integer>(configList, 1);
    try {
        Mockito.when(mgr.searchForConfigurations(listCfgsByCmd)).thenReturn(result);
    } catch (Exception e) {
        Assert.fail("Received exception when success expected " + e.getMessage());
    }
    ConfigurationResponse cfgResponse = new ConfigurationResponse();
    cfgResponse.setName("Test case");
    Mockito.when(responseGenerator.createConfigurationResponse(cfg)).thenReturn(cfgResponse);
    listCfgsByCmd.execute();
    Mockito.verify(responseGenerator).createConfigurationResponse(cfg);
    ListResponse<ConfigurationResponse> actualResponse = (ListResponse<ConfigurationResponse>) listCfgsByCmd.getResponseObject();
    Assert.assertEquals(cfgResponse, actualResponse.getResponses().get(0));
}
Also used : ConfigurationResponse(org.apache.cloudstack.api.response.ConfigurationResponse) Configuration(org.apache.cloudstack.config.Configuration) ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ExpectedException(org.junit.rules.ExpectedException) Pair(com.cloud.utils.Pair) Test(org.junit.Test)

Example 18 with ListResponse

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

the class ListVpnGatewaysCmd method execute.

@Override
public void execute() {
    Pair<List<? extends Site2SiteVpnGateway>, Integer> gws = _s2sVpnService.searchForVpnGateways(this);
    ListResponse<Site2SiteVpnGatewayResponse> response = new ListResponse<Site2SiteVpnGatewayResponse>();
    List<Site2SiteVpnGatewayResponse> gwResponses = new ArrayList<Site2SiteVpnGatewayResponse>();
    for (Site2SiteVpnGateway gw : gws.first()) {
        if (gw == null) {
            continue;
        }
        Site2SiteVpnGatewayResponse site2SiteVpnGatewayRes = _responseGenerator.createSite2SiteVpnGatewayResponse(gw);
        site2SiteVpnGatewayRes.setObjectName("vpngateway");
        gwResponses.add(site2SiteVpnGatewayRes);
    }
    response.setResponses(gwResponses, gws.second());
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : Site2SiteVpnGateway(com.cloud.network.Site2SiteVpnGateway) ListResponse(org.apache.cloudstack.api.response.ListResponse) Site2SiteVpnGatewayResponse(org.apache.cloudstack.api.response.Site2SiteVpnGatewayResponse) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 19 with ListResponse

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

the class ListVpnUsersCmd method execute.

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

Example 20 with ListResponse

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

the class ListRemoteAccessVpnsCmd method execute.

@Override
public void execute() {
    Pair<List<? extends RemoteAccessVpn>, Integer> vpns = _ravService.searchForRemoteAccessVpns(this);
    ListResponse<RemoteAccessVpnResponse> response = new ListResponse<RemoteAccessVpnResponse>();
    List<RemoteAccessVpnResponse> vpnResponses = new ArrayList<RemoteAccessVpnResponse>();
    if (vpns.first() != null && !vpns.first().isEmpty()) {
        for (RemoteAccessVpn vpn : vpns.first()) {
            vpnResponses.add(_responseGenerator.createRemoteAccessVpnResponse(vpn));
        }
    }
    response.setResponses(vpnResponses, vpns.second());
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) RemoteAccessVpnResponse(org.apache.cloudstack.api.response.RemoteAccessVpnResponse) RemoteAccessVpn(com.cloud.network.RemoteAccessVpn)

Aggregations

ListResponse (org.apache.cloudstack.api.response.ListResponse)149 ArrayList (java.util.ArrayList)134 List (java.util.List)62 ServerApiException (org.apache.cloudstack.api.ServerApiException)44 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)29 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)21 Network (com.cloud.network.Network)9 DedicatedResources (com.cloud.dc.DedicatedResources)8 NetworkResponse (org.apache.cloudstack.api.response.NetworkResponse)8 ResponseView (org.apache.cloudstack.api.ResponseObject.ResponseView)7 TemplateResponse (org.apache.cloudstack.api.response.TemplateResponse)7 Host (com.cloud.host.Host)6 Domain (com.cloud.domain.Domain)5 VirtualMachineTemplate (com.cloud.template.VirtualMachineTemplate)5 DedicatedResourceVO (com.cloud.dc.DedicatedResourceVO)4 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)4 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)4 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)4 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)4 Account (com.cloud.user.Account)4