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;
}
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;
}
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));
}
Aggregations