Search in sources :

Example 6 with ApiService

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

the class ClouderaManagerServiceDiscoveryRepositoryTest method testAddRole.

@Test
public void testAddRole() throws Exception {
    final String serviceName = "HDFS-1";
    final String roleName = "NAMENODE-1";
    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();
    EasyMock.replay(service, role, roles);
    assertFalse(containsRole(service, roleName));
    repository.addService(serviceDiscoveryConfig, service);
    repository.addRoles(serviceDiscoveryConfig, service, roles);
    assertTrue(containsRole(service, roleName));
}
Also used : ApiRole(com.cloudera.api.swagger.model.ApiRole) ApiService(com.cloudera.api.swagger.model.ApiService) ApiRoleList(com.cloudera.api.swagger.model.ApiRoleList) Test(org.junit.Test)

Example 7 with ApiService

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

the class ClouderaManagerServiceDiscovery method getClusterServices.

private List<ApiService> getClusterServices(ServiceDiscoveryConfig serviceDiscoveryConfig, ServicesResourceApi servicesResourceApi) {
    log.lookupClusterServicesFromRepository();
    List<ApiService> services = repository.getServices(serviceDiscoveryConfig);
    if (services == null || services.isEmpty()) {
        try {
            log.lookupClusterServicesFromCM();
            final ApiServiceList serviceList = servicesResourceApi.readServices(serviceDiscoveryConfig.getCluster(), VIEW_SUMMARY);
            services = serviceList == null ? new ArrayList<>() : serviceList.getItems();
            // make sure that services are populated in the repository
            services.forEach(service -> repository.addService(serviceDiscoveryConfig, service));
        } catch (ApiException e) {
            log.failedToAccessServiceConfigs(serviceDiscoveryConfig.getCluster(), e);
        }
    }
    return services;
}
Also used : ApiService(com.cloudera.api.swagger.model.ApiService) ArrayList(java.util.ArrayList) ApiServiceList(com.cloudera.api.swagger.model.ApiServiceList) ApiException(com.cloudera.api.swagger.client.ApiException)

Example 8 with ApiService

use of com.cloudera.api.swagger.model.ApiService 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)

Example 9 with ApiService

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

the class ClouderaManagerServiceDiscoveryRepositoryTest method testAddService.

@Test
public void testAddService() throws Exception {
    final String serviceName = "HDFS-1";
    repository.registerCluster(serviceDiscoveryConfig);
    assertFalse(containsService(serviceName));
    final ApiService service = EasyMock.createNiceMock(ApiService.class);
    EasyMock.expect(service.getName()).andReturn(serviceName).anyTimes();
    EasyMock.replay(service);
    repository.addService(serviceDiscoveryConfig, service);
    assertTrue(containsService(serviceName));
}
Also used : ApiService(com.cloudera.api.swagger.model.ApiService) Test(org.junit.Test)

Example 10 with ApiService

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

the class ClouderaManagerServiceDiscoveryRepositoryTest method testAddServiceConfig.

@Test
public void testAddServiceConfig() throws Exception {
    final String serviceName = "HDFS-1";
    final String serviceConfigName = "myServiceConfigName";
    final String serviceConfigValue = "myServiceConfigValue";
    repository.registerCluster(serviceDiscoveryConfig);
    final ApiService service = EasyMock.createNiceMock(ApiService.class);
    EasyMock.expect(service.getName()).andReturn(serviceName).anyTimes();
    final ApiConfig serviceConfig = EasyMock.createNiceMock(ApiConfig.class);
    EasyMock.expect(serviceConfig.getName()).andReturn(serviceConfigName).anyTimes();
    EasyMock.expect(serviceConfig.getValue()).andReturn(serviceConfigValue).anyTimes();
    final ApiServiceConfig serviceConfigs = EasyMock.createNiceMock(ApiServiceConfig.class);
    EasyMock.expect(serviceConfigs.getItems()).andReturn(Collections.singletonList(serviceConfig)).anyTimes();
    EasyMock.replay(service, serviceConfig, serviceConfigs);
    assertFalse(containsServiceConfig(service, serviceConfigName, serviceConfigValue));
    repository.addService(serviceDiscoveryConfig, service);
    repository.addServiceConfig(serviceDiscoveryConfig, service, serviceConfigs);
    assertTrue(containsServiceConfig(service, serviceConfigName, serviceConfigValue));
}
Also used : ApiService(com.cloudera.api.swagger.model.ApiService) ApiConfig(com.cloudera.api.swagger.model.ApiConfig) ApiServiceConfig(com.cloudera.api.swagger.model.ApiServiceConfig) Test(org.junit.Test)

Aggregations

ApiService (com.cloudera.api.swagger.model.ApiService)10 ApiRole (com.cloudera.api.swagger.model.ApiRole)4 ApiRoleList (com.cloudera.api.swagger.model.ApiRoleList)4 Test (org.junit.Test)4 ApiConfigList (com.cloudera.api.swagger.model.ApiConfigList)3 ApiServiceConfig (com.cloudera.api.swagger.model.ApiServiceConfig)3 ApiServiceList (com.cloudera.api.swagger.model.ApiServiceList)3 ApiException (com.cloudera.api.swagger.client.ApiException)2 ApiConfig (com.cloudera.api.swagger.model.ApiConfig)2 ArrayList (java.util.ArrayList)2 RolesResourceApi (com.cloudera.api.swagger.RolesResourceApi)1 ServicesResourceApi (com.cloudera.api.swagger.ServicesResourceApi)1 ApiClusterRef (com.cloudera.api.swagger.model.ApiClusterRef)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)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 HadoopClusterService (org.talend.repository.hadoopcluster.configurator.HadoopClusterService)1 HadoopHostedService (org.talend.repository.hadoopcluster.configurator.HadoopHostedService)1