Search in sources :

Example 66 with NotFoundException

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);
}
Also used : FlowLog(com.sequenceiq.flow.domain.FlowLog) FlowProgressResponse(com.sequenceiq.flow.api.model.FlowProgressResponse) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException)

Example 67 with NotFoundException

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();
    }
}
Also used : RoleConfigGroupsResourceApi(com.cloudera.api.swagger.RoleConfigGroupsResourceApi) ServicesResourceApi(com.cloudera.api.swagger.ServicesResourceApi) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) Arrays(java.util.Arrays) ApiClient(com.cloudera.api.swagger.client.ApiClient) LoggerFactory(org.slf4j.LoggerFactory) ApiService(com.cloudera.api.swagger.model.ApiService) ServicesResourceApi(com.cloudera.api.swagger.ServicesResourceApi) ApiException(com.cloudera.api.swagger.client.ApiException) Inject(javax.inject.Inject) RoleConfigGroupsResourceApi(com.cloudera.api.swagger.RoleConfigGroupsResourceApi) Service(org.springframework.stereotype.Service) Map(java.util.Map) ClouderaManagerResourceApi(com.cloudera.api.swagger.ClouderaManagerResourceApi) CMRepositoryVersionUtil.isVersionNewerOrEqualThanLimited(com.sequenceiq.cloudbreak.cmtemplate.CMRepositoryVersionUtil.isVersionNewerOrEqualThanLimited) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) ApiRoleConfigGroupList(com.cloudera.api.swagger.model.ApiRoleConfigGroupList) ApiConfig(com.cloudera.api.swagger.model.ApiConfig) Logger(org.slf4j.Logger) Versioned(com.sequenceiq.cloudbreak.common.type.Versioned) ApiConfigList(com.cloudera.api.swagger.model.ApiConfigList) ApiVersionInfo(com.cloudera.api.swagger.model.ApiVersionInfo) Objects(java.util.Objects) Consumer(java.util.function.Consumer) ApiServiceConfig(com.cloudera.api.swagger.model.ApiServiceConfig) Optional(java.util.Optional) ApiServiceList(com.cloudera.api.swagger.model.ApiServiceList) ClouderaManagerApiFactory(com.sequenceiq.cloudbreak.cm.client.retry.ClouderaManagerApiFactory) ApiConfigList(com.cloudera.api.swagger.model.ApiConfigList) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) ApiException(com.cloudera.api.swagger.client.ApiException)

Example 68 with NotFoundException

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));
}
Also used : NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 69 with NotFoundException

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");
}
Also used : User(com.sequenceiq.freeipa.client.model.User) Set(java.util.Set) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Map(java.util.Map) Test(org.junit.Test)

Example 70 with NotFoundException

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);
}
Also used : HashMap(java.util.HashMap) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) RetryableFreeIpaClientException(com.sequenceiq.freeipa.client.RetryableFreeIpaClientException) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) HashSet(java.util.HashSet) Stack(com.sequenceiq.freeipa.entity.Stack) Retryable(org.springframework.retry.annotation.Retryable)

Aggregations

NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)73 Test (org.junit.jupiter.api.Test)33 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)11 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)10 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)10 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)9 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)8 Map (java.util.Map)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 NameOrCrn (com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn)6 List (java.util.List)6 TransactionExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException)5 TransactionRuntimeExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)5 Workspace (com.sequenceiq.cloudbreak.workspace.model.Workspace)5 Optional (java.util.Optional)5 CloudbreakImageCatalogException (com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)4 Set (java.util.Set)4 CheckPermissionByResourceName (com.sequenceiq.authorization.annotation.CheckPermissionByResourceName)3 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)3