Search in sources :

Example 21 with ListResponse

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

the class ApiDiscoveryTest method verifyListSingleApi.

@Test
public void verifyListSingleApi() throws Exception {
    ListResponse<ApiDiscoveryResponse> responses = (ListResponse<ApiDiscoveryResponse>) s_discoveryService.listApis(testUser, testApiName);
    if (responses != null) {
        ApiDiscoveryResponse response = responses.getResponses().get(0);
        assertTrue("No. of response items should be one", responses.getCount() == 1);
        assertEquals("Error in api name", testApiName, response.getName());
        assertEquals("Error in api description", testApiDescription, response.getDescription());
        assertEquals("Error in api since", testApiSince, response.getSince());
        assertEquals("Error in api isAsync", testApiAsync, response.getAsync());
    }
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) ApiDiscoveryResponse(org.apache.cloudstack.api.response.ApiDiscoveryResponse) Test(org.junit.Test)

Example 22 with ListResponse

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

the class ApiDiscoveryTest method verifyListApis.

@Test
public void verifyListApis() throws Exception {
    ListResponse<ApiDiscoveryResponse> responses = (ListResponse<ApiDiscoveryResponse>) s_discoveryService.listApis(testUser, null);
    if (responses != null) {
        assertTrue("No. of response items > 1", responses.getCount().intValue() == 1);
        for (ApiDiscoveryResponse response : responses.getResponses()) {
            assertFalse("API name is empty", response.getName().isEmpty());
            assertFalse("API description is empty", response.getDescription().isEmpty());
        }
    }
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) ApiDiscoveryResponse(org.apache.cloudstack.api.response.ApiDiscoveryResponse) Test(org.junit.Test)

Example 23 with ListResponse

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

the class ListCiscoNexusVSMsCmd method execute.

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
// NOTE- The uuid that is sent in during the invocation of the API AddCiscoNexusVSM()
// automagically gets translated to the corresponding db id before this execute() method
// is invoked. That's the reason why we don't have any uuid-dbid translation code here.
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    List<? extends CiscoNexusVSMDevice> vsmDeviceList = _ciscoNexusVSMService.getCiscoNexusVSMs(this);
    if (vsmDeviceList.size() > 0) {
        ListResponse<CiscoNexusVSMResponse> response = new ListResponse<CiscoNexusVSMResponse>();
        List<CiscoNexusVSMResponse> vsmResponses = new ArrayList<CiscoNexusVSMResponse>();
        for (CiscoNexusVSMDevice vsmDevice : vsmDeviceList) {
            CiscoNexusVSMResponse vsmresponse = _ciscoNexusVSMService.createCiscoNexusVSMDetailedResponse(vsmDevice);
            vsmresponse.setObjectName("cisconexusvsm");
            response.setResponseName(getCommandName());
            vsmResponses.add(vsmresponse);
        }
        response.setResponses(vsmResponses);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "No VSM found.");
    }
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) CiscoNexusVSMDevice(com.cloud.network.CiscoNexusVSMDevice) ServerApiException(org.apache.cloudstack.api.ServerApiException) ArrayList(java.util.ArrayList) CiscoNexusVSMResponse(com.cloud.api.response.CiscoNexusVSMResponse)

Example 24 with ListResponse

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

the class ListSamlAuthorizationCmd method execute.

@Override
public void execute() {
    List<UserVO> users = new ArrayList<UserVO>();
    if (getUserId() != null) {
        UserVO user = _userDao.getUser(getUserId());
        if (user != null) {
            Account account = _accountService.getAccount(user.getAccountId());
            _accountService.checkAccess(CallContext.current().getCallingAccount(), SecurityChecker.AccessType.ListEntry, true, account);
            users.add(user);
        }
    } else if (CallContext.current().getCallingAccount().getType() == Account.ACCOUNT_TYPE_ADMIN) {
        users = _userDao.listAll();
    }
    ListResponse<SamlAuthorizationResponse> response = new ListResponse<SamlAuthorizationResponse>();
    List<SamlAuthorizationResponse> authorizationResponses = new ArrayList<SamlAuthorizationResponse>();
    for (User user : users) {
        SamlAuthorizationResponse authorizationResponse = new SamlAuthorizationResponse(user.getUuid(), user.getSource().equals(User.Source.SAML2), user.getExternalEntity());
        authorizationResponse.setObjectName("samlauthorization");
        authorizationResponses.add(authorizationResponse);
    }
    response.setResponses(authorizationResponses);
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : Account(com.cloud.user.Account) SamlAuthorizationResponse(org.apache.cloudstack.api.response.SamlAuthorizationResponse) User(com.cloud.user.User) UserVO(com.cloud.user.UserVO) ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList)

Example 25 with ListResponse

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

the class ListLBHealthCheckPoliciesCmd method execute.

@Override
public void execute() {
    List<LBHealthCheckResponse> hcpResponses = new ArrayList<LBHealthCheckResponse>();
    ListResponse<LBHealthCheckResponse> response = new ListResponse<LBHealthCheckResponse>();
    Long lbRuleId = getLbRuleId();
    Long hId = getId();
    if (lbRuleId == null) {
        if (hId != null) {
            lbRuleId = _lbService.findLBIdByHealtCheckPolicyId(hId);
        } else {
            throw new InvalidParameterValueException("Either load balancer rule ID or health check policy ID should be specified");
        }
    }
    LoadBalancer lb = _lbService.findById(lbRuleId);
    if (lb != null) {
        List<? extends HealthCheckPolicy> healthCheckPolicies = _lbService.searchForLBHealthCheckPolicies(this);
        LBHealthCheckResponse spResponse = _responseGenerator.createLBHealthCheckPolicyResponse(healthCheckPolicies, lb);
        hcpResponses.add(spResponse);
        response.setResponses(hcpResponses);
    }
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ArrayList(java.util.ArrayList) LoadBalancer(com.cloud.network.rules.LoadBalancer) LBHealthCheckResponse(org.apache.cloudstack.api.response.LBHealthCheckResponse)

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