use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.
the class FlowService method getLastFlowProgressByResourceCrn.
public FlowProgressResponse getLastFlowProgressByResourceCrn(String resourceCrn) {
checkState(Crn.isCrn(resourceCrn));
LOGGER.info("Getting flow logs (progress) by resource crn {}", resourceCrn);
List<FlowLog> flowLogs = flowLogDBService.getFlowLogsByResourceCrnOrName(resourceCrn);
FlowProgressResponse response = flowProgressResponseConverter.convert(flowLogs, resourceCrn);
if (StringUtils.isBlank(response.getFlowId())) {
throw new NotFoundException(String.format("Not found any historical flow data for requested resource (crn: %s)", resourceCrn));
}
return flowProgressResponseConverter.convert(flowLogs, resourceCrn);
}
use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.
the class ClouderaManagerConfigService method getRoleConfigValueByServiceType.
public Optional<String> getRoleConfigValueByServiceType(ApiClient apiClient, String clusterName, String roleType, String serviceType, String configName) {
LOGGER.debug("Looking for configuration: {} for cluster {}, roleType {}, and serviceType {}", configName, clusterName, roleType, serviceType);
RoleConfigGroupsResourceApi roleConfigGroupsResourceApi = clouderaManagerApiFactory.getRoleConfigGroupsResourceApi(apiClient);
ServicesResourceApi servicesResourceApi = clouderaManagerApiFactory.getServicesResourceApi(apiClient);
try {
String serviceName = getServiceNameValue(clusterName, serviceType, servicesResourceApi);
String roleConfigGroupName = getRoleConfigGroupNameByTypeAndServiceName(roleType, clusterName, serviceName, roleConfigGroupsResourceApi);
ApiConfigList roleConfig = roleConfigGroupsResourceApi.readConfig(clusterName, roleConfigGroupName, serviceName, "full");
return roleConfig.getItems().stream().filter(apiConfig -> configName.equals(apiConfig.getName())).map(apiConfig -> Optional.ofNullable(apiConfig.getValue()).orElse(apiConfig.getDefault())).findFirst();
} catch (ApiException | NotFoundException e) {
LOGGER.debug("Failed to get configuration: {} for cluster {}, roleType {}, and serviceType {}", configName, clusterName, roleType, serviceType, e);
return Optional.empty();
}
}
use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.
the class KeytabCommonServiceTest method testRealmFreeIpaMissing.
@Test
public void testRealmFreeIpaMissing() {
Stack stack = new Stack();
when(freeIpaService.findByStack(stack)).thenThrow(new NotFoundException("expected"));
assertThrows(KeytabCreationException.class, () -> underTest.getRealm(stack));
}
use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.
the class CleanupServiceTest method testRemoveUsersWhenLdapConfigAlreadyDeleted.
@Test
public void testRemoveUsersWhenLdapConfigAlreadyDeleted() throws FreeIpaClientException {
Set<String> usersNames = Set.of("ldapbind-test-wl-1", "kerberosbind-test-wl-1");
Set<User> ipaUsers = Set.of(createUser("ldapbind-test-wl-1"), createUser("ldapbind-test-wl-2"), createUser("kerberosbind-test-wl-1"), createUser("kerberosbind-test-wl-2"), createUser("mockuser0"), createUser("csso_khorvath"));
FreeIpaClient freeIpaClient = mock(FreeIpaClient.class);
when(freeIpaClientFactory.getFreeIpaClientForStackId(STACK_ID)).thenReturn(freeIpaClient);
when(freeIpaClient.userFindAll()).thenReturn(ipaUsers);
when(stackService.getStackById(anyLong())).thenReturn(createStack());
doThrow(new NotFoundException("Ldap config not found")).when(ldapConfigService).delete("envCrn", "accountId", "test-wl-1");
Pair<Set<String>, Map<String, String>> result = cleanupService.removeUsers(STACK_ID, usersNames, "test-wl-1", ENV_CRN);
verify(freeIpaClient, times(1)).deleteUser("ldapbind-test-wl-1");
verify(freeIpaClient, times(1)).deleteUser("kerberosbind-test-wl-1");
verifyUserDeleteNotInvoked(freeIpaClient, "ldapbind-test-wl-2", "kerberosbind-test-wl-2", "mockuser0", "csso_khorvath");
assertEquals(2, result.getFirst().size());
assertTrue(result.getFirst().stream().anyMatch("ldapbind-test-wl-1"::equals));
assertTrue(result.getFirst().stream().anyMatch("kerberosbind-test-wl-1"::equals));
verify(kerberosConfigService, times(1)).delete("envCrn", "accountId", "test-wl-1");
verify(ldapConfigService, times(1)).delete("envCrn", "accountId", "test-wl-1");
}
use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.
the class CleanupService method removeUsers.
@Retryable(value = RetryableFreeIpaClientException.class, maxAttemptsExpression = RetryableFreeIpaClientException.MAX_RETRIES_EXPRESSION, backoff = @Backoff(delayExpression = RetryableFreeIpaClientException.DELAY_EXPRESSION, multiplierExpression = RetryableFreeIpaClientException.MULTIPLIER_EXPRESSION))
public Pair<Set<String>, Map<String, String>> removeUsers(Long stackId, Set<String> users, String clusterName, String environmentCrn) throws FreeIpaClientException {
FreeIpaClient client = getFreeIpaClient(stackId);
Set<String> userCleanupSuccess = new HashSet<>();
Map<String, String> userCleanupFailed = new HashMap<>();
Set<String> usersUid = client.userFindAll().stream().map(User::getUid).collect(Collectors.toSet());
users.stream().filter(usersUid::contains).forEach(userUid -> {
try {
client.deleteUser(userUid);
userCleanupSuccess.add(userUid);
} catch (FreeIpaClientException e) {
if (FreeIpaClientExceptionUtil.isNotFoundException(e)) {
userCleanupSuccess.add(userUid);
} else {
LOGGER.info("User delete failed for user: {}", userUid, e);
userCleanupFailed.put(userUid, e.getMessage());
}
}
});
if (StringUtils.isNotBlank(clusterName)) {
Stack stack = stackService.getStackById(stackId);
if (StringUtils.isEmpty(environmentCrn)) {
environmentCrn = stack.getEnvironmentCrn();
}
String accountId = stack.getAccountId();
try {
kerberosConfigService.delete(environmentCrn, accountId, clusterName);
} catch (NotFoundException e) {
LOGGER.warn("No kerberos config found for cluster [{}] to delete", clusterName);
}
try {
ldapConfigService.delete(environmentCrn, accountId, clusterName);
} catch (NotFoundException e) {
LOGGER.warn("No ldap config found for cluster [{}] to delete", clusterName);
}
}
return Pair.of(userCleanupSuccess, userCleanupFailed);
}
Aggregations