Search in sources :

Example 6 with ApiRole

use of com.cloudera.api.swagger.model.ApiRole in project knox by apache.

the class ClouderaManagerServiceDiscovery method getRoles.

private ApiRoleList getRoles(ServiceDiscoveryConfig serviceDiscoveryConfig, RolesResourceApi rolesResourceApi, String clusterName, ApiService service) {
    log.lookupRolesFromRepository();
    // first, try in the service discovery repository
    ApiRoleList roles = repository.getRoles(serviceDiscoveryConfig, service);
    if (roles == null || roles.getItems() == null) {
        // no roles in the repository -> query CM
        final String serviceName = service.getName();
        try {
            log.lookupRolesFromCM();
            /* Populate roles for CM Service since they are not discoverable */
            if (CM_SERVICE_TYPE.equalsIgnoreCase(serviceName)) {
                roles = new ApiRoleList();
                final ApiRole cmRole = new ApiRole();
                cmRole.setName(CM_ROLE_TYPE);
                cmRole.setType(CM_ROLE_TYPE);
                roles.addItemsItem(cmRole);
            } else {
                roles = rolesResourceApi.readRoles(clusterName, serviceName, "", VIEW_SUMMARY);
            }
            // make sure that role is populated in the service discovery repository to avoid subsequent CM calls
            repository.addRoles(serviceDiscoveryConfig, service, roles);
        } catch (Exception e) {
            log.failedToAccessServiceRoleConfigs(serviceName, "N/A", clusterName, e);
        }
    }
    return roles;
}
Also used : ApiRole(com.cloudera.api.swagger.model.ApiRole) ApiRoleList(com.cloudera.api.swagger.model.ApiRoleList) ApiException(com.cloudera.api.swagger.client.ApiException)

Example 7 with ApiRole

use of com.cloudera.api.swagger.model.ApiRole in project knox by apache.

the class AbstractCMDiscoveryTest method createApiRoleMock.

protected static ApiRole createApiRoleMock(final String roleName, final String roleType) {
    ApiRole role = EasyMock.createNiceMock(ApiRole.class);
    EasyMock.expect(role.getName()).andReturn(roleName).anyTimes();
    EasyMock.expect(role.getType()).andReturn(roleType).anyTimes();
    ApiHostRef hostRef = EasyMock.createNiceMock(ApiHostRef.class);
    EasyMock.expect(hostRef.getHostname()).andReturn("localhost").anyTimes();
    EasyMock.replay(hostRef);
    EasyMock.expect(role.getHostRef()).andReturn(hostRef).anyTimes();
    EasyMock.replay(role);
    return role;
}
Also used : ApiRole(com.cloudera.api.swagger.model.ApiRole) ApiHostRef(com.cloudera.api.swagger.model.ApiHostRef)

Example 8 with ApiRole

use of com.cloudera.api.swagger.model.ApiRole in project knox by apache.

the class ClouderaManagerServiceDiscoveryRepositoryTest method testAddRoleConfig.

@Test
public void testAddRoleConfig() throws Exception {
    final String serviceName = "HDFS-1";
    final String roleName = "NAMENODE-1";
    final String roleConfigName = "myRoleConfig";
    final String roleConfigValue = "myRoleConfigValue";
    repository.registerCluster(serviceDiscoveryConfig);
    final ApiService service = EasyMock.createNiceMock(ApiService.class);
    EasyMock.expect(service.getName()).andReturn(serviceName).anyTimes();
    final ApiRole role = EasyMock.createNiceMock(ApiRole.class);
    EasyMock.expect(role.getName()).andReturn(roleName).anyTimes();
    final ApiRoleList roles = EasyMock.createNiceMock(ApiRoleList.class);
    EasyMock.expect(roles.getItems()).andReturn(Collections.singletonList(role)).anyTimes();
    final ApiConfig roleConfig = EasyMock.createNiceMock(ApiConfig.class);
    EasyMock.expect(roleConfig.getName()).andReturn(roleConfigName).anyTimes();
    EasyMock.expect(roleConfig.getValue()).andReturn(roleConfigValue).anyTimes();
    final ApiConfigList roleConfigs = EasyMock.createNiceMock(ApiConfigList.class);
    EasyMock.expect(roleConfigs.getItems()).andReturn(Collections.singletonList(roleConfig)).anyTimes();
    EasyMock.replay(service, role, roles, roleConfig, roleConfigs);
    assertFalse(containsRoleConfig(service, role, roleConfigName, roleConfigValue));
    repository.addService(serviceDiscoveryConfig, service);
    repository.addRoles(serviceDiscoveryConfig, service, roles);
    repository.addRoleConfigs(serviceDiscoveryConfig, service, role, roleConfigs);
    assertTrue(containsRoleConfig(service, role, roleConfigName, roleConfigValue));
}
Also used : ApiRole(com.cloudera.api.swagger.model.ApiRole) ApiConfigList(com.cloudera.api.swagger.model.ApiConfigList) ApiService(com.cloudera.api.swagger.model.ApiService) ApiRoleList(com.cloudera.api.swagger.model.ApiRoleList) ApiConfig(com.cloudera.api.swagger.model.ApiConfig) Test(org.junit.Test)

Aggregations

ApiRole (com.cloudera.api.swagger.model.ApiRole)8 ApiRoleList (com.cloudera.api.swagger.model.ApiRoleList)6 ApiConfigList (com.cloudera.api.swagger.model.ApiConfigList)4 ApiService (com.cloudera.api.swagger.model.ApiService)4 ApiServiceConfig (com.cloudera.api.swagger.model.ApiServiceConfig)3 RolesResourceApi (com.cloudera.api.swagger.RolesResourceApi)2 ServicesResourceApi (com.cloudera.api.swagger.ServicesResourceApi)2 ApiException (com.cloudera.api.swagger.client.ApiException)2 ApiHostRef (com.cloudera.api.swagger.model.ApiHostRef)2 Test (org.junit.Test)2 ApiClient (com.cloudera.api.swagger.client.ApiClient)1 ApiConfig (com.cloudera.api.swagger.model.ApiConfig)1 ApiServiceList (com.cloudera.api.swagger.model.ApiServiceList)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 GatewayConfig (org.apache.knox.gateway.config.GatewayConfig)1 ServiceDiscovery (org.apache.knox.gateway.topology.discovery.ServiceDiscovery)1 ServiceDiscoveryConfig (org.apache.knox.gateway.topology.discovery.ServiceDiscoveryConfig)1