Search in sources :

Example 61 with ListResponse

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

the class ListCfgCmdTest method testCreateSuccess.

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

Example 62 with ListResponse

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

the class ListApisCmd method execute.

@Override
public void execute() throws ServerApiException {
    if (_apiDiscoveryService != null) {
        final User user = CallContext.current().getCallingUser();
        final ListResponse<ApiDiscoveryResponse> response = (ListResponse<ApiDiscoveryResponse>) _apiDiscoveryService.listApis(user, name);
        if (response == null) {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Api Discovery plugin was unable to find an api by that name or process any apis");
        }
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    }
}
Also used : User(com.cloud.user.User) ListResponse(com.cloud.api.response.ListResponse) ServerApiException(com.cloud.api.ServerApiException) ApiDiscoveryResponse(com.cloud.api.response.ApiDiscoveryResponse)

Example 63 with ListResponse

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

the class LDAPConfigCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    if (getListAll()) {
        // return the existing conf
        final LdapListConfigurationCmd listConfigurationCmd = new LdapListConfigurationCmd(_ldapManager);
        final Pair<List<? extends LdapConfigurationVO>, Integer> result = _ldapManager.listConfigurations(listConfigurationCmd);
        final ListResponse<LDAPConfigResponse> response = new ListResponse<>();
        final List<LDAPConfigResponse> responses = new ArrayList<>();
        if (result.second() > 0) {
            final boolean useSSlConfig = _ldapConfiguration.getSSLStatus();
            final String searchBaseConfig = _ldapConfiguration.getBaseDn();
            final String bindDnConfig = _ldapConfiguration.getBindPrincipal();
            for (final LdapConfigurationVO ldapConfigurationVO : result.first()) {
                responses.add(createLDAPConfigResponse(ldapConfigurationVO.getHostname(), ldapConfigurationVO.getPort(), useSSlConfig, null, searchBaseConfig, bindDnConfig));
            }
        }
        response.setResponses(responses);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else if (getHostname() == null || getPort() == null) {
        throw new InvalidParameterValueException("You need to provide hostname, port to configure your LDAP server");
    } else {
        final boolean result = updateLDAP();
        if (result) {
            final LDAPConfigResponse lr = createLDAPConfigResponse(getHostname(), getPort(), getUseSSL(), getQueryFilter(), getSearchBase(), getBindDN());
            lr.setResponseName(getCommandName());
            setResponseObject(lr);
        }
    }
}
Also used : ListResponse(com.cloud.api.response.ListResponse) ArrayList(java.util.ArrayList) LdapConfigurationVO(com.cloud.ldap.LdapConfigurationVO) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) LDAPConfigResponse(com.cloud.api.response.LDAPConfigResponse) ArrayList(java.util.ArrayList) List(java.util.List)

Example 64 with ListResponse

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

the class ApiDiscoveryServiceImpl method listApis.

@Override
public ListResponse<? extends BaseResponse> listApis(final User user, final String name) {
    final ListResponse<ApiDiscoveryResponse> response = new ListResponse<>();
    final List<ApiDiscoveryResponse> responseList = new ArrayList<>();
    if (user == null) {
        return null;
    }
    if (name != null) {
        if (!s_apiNameDiscoveryResponseMap.containsKey(name)) {
            return null;
        }
        for (final APIChecker apiChecker : _apiAccessCheckers) {
            try {
                apiChecker.checkAccess(user, name);
            } catch (final Exception ex) {
                s_logger.debug("API discovery access check failed for " + name + " with " + ex.getMessage());
                return null;
            }
        }
        responseList.add(s_apiNameDiscoveryResponseMap.get(name));
    } else {
        for (final String apiName : s_apiNameDiscoveryResponseMap.keySet()) {
            boolean isAllowed = true;
            for (final APIChecker apiChecker : _apiAccessCheckers) {
                try {
                    apiChecker.checkAccess(user, apiName);
                } catch (final Exception ex) {
                    isAllowed = false;
                }
            }
            if (isAllowed) {
                responseList.add(s_apiNameDiscoveryResponseMap.get(apiName));
            }
        }
    }
    response.setResponses(responseList);
    return response;
}
Also used : ListResponse(com.cloud.api.response.ListResponse) ArrayList(java.util.ArrayList) ApiDiscoveryResponse(com.cloud.api.response.ApiDiscoveryResponse) APIChecker(com.cloud.acl.APIChecker)

Example 65 with ListResponse

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

the class ApiDiscoveryTest method verifyListApis.

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

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