Search in sources :

Example 16 with NotFoundException

use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.

the class UserKeytabService method validateFreeIpaState.

private void validateFreeIpaState(String workloadUsername, String environmentCrn) {
    String accountId = Crn.safeFromString(environmentCrn).getAccountId();
    FreeIpaClient freeIpaClient;
    try {
        freeIpaClient = freeIpaClientFactory.getFreeIpaClientByAccountAndEnvironment(environmentCrn, accountId);
        if (!FreeIpaCapabilities.hasSetPasswordHashSupport(freeIpaClient.getConfig())) {
            throw new UnsupportedException("User keytab retrieval requires a newer environment and FreeIPA version");
        }
        Optional<User> user = freeIpaClient.userFind(workloadUsername);
        if (user.isEmpty()) {
            throw new NotFoundException(String.format("Workload user %s has not been synced into environment %s", workloadUsername, environmentCrn));
        }
    } catch (FreeIpaClientException e) {
        throw new RuntimeException(e);
    }
}
Also used : UnsupportedException(com.sequenceiq.freeipa.controller.exception.UnsupportedException) User(com.sequenceiq.freeipa.client.model.User) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException)

Example 17 with NotFoundException

use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.

the class StackServiceTest method getByIdWithListsInTransactionNotFound.

@Test
void getByIdWithListsInTransactionNotFound() {
    when(stackRepository.findOneWithLists(STACK_ID)).thenReturn(Optional.empty());
    NotFoundException notFoundException = assertThrows(NotFoundException.class, () -> underTest.getByIdWithListsInTransaction(STACK_ID));
    assertEquals("FreeIPA stack [" + STACK_ID + "] not found", notFoundException.getMessage());
}
Also used : NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) Test(org.junit.jupiter.api.Test)

Example 18 with NotFoundException

use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.

the class StackServiceTest method getByEnvironmentCrnNotFound.

@Test
void getByEnvironmentCrnNotFound() {
    when(stackRepository.findByEnvironmentCrnAndAccountId(ENVIRONMENT_CRN, ACCOUNT_ID)).thenReturn(Optional.empty());
    when(childEnvironmentService.findParentByEnvironmentCrnAndAccountId(ENVIRONMENT_CRN, ACCOUNT_ID)).thenReturn(Optional.empty());
    NotFoundException notFoundException = assertThrows(NotFoundException.class, () -> underTest.getByEnvironmentCrnAndAccountId(ENVIRONMENT_CRN, ACCOUNT_ID));
    assertEquals("FreeIPA stack by environment [" + ENVIRONMENT_CRN + "] not found", notFoundException.getMessage());
}
Also used : NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) Test(org.junit.jupiter.api.Test)

Example 19 with NotFoundException

use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.

the class DefaultModelService method createInstances.

public List<CloudVmMetaDataStatus> createInstances(String name, SpiDto spiDto, List<Group> groups) {
    List<CloudVmMetaDataStatus> ret = new ArrayList<>();
    String prefix = "192";
    for (int groupIndex = 0; groupIndex < groups.size(); groupIndex++) {
        List<Group> existedGroups = spiDto.getCloudStack().getGroups();
        Group group = groups.get(groupIndex);
        Optional<Group> existedGroupOpt = existedGroups.stream().filter(g -> group.getName().equals(g.getName())).findFirst();
        if (existedGroupOpt.isEmpty()) {
            throw new NotFoundException("Cannot find group with name: " + group.getName());
        }
        Group existedGroup = existedGroupOpt.get();
        int indexOfExistedGroup = existedGroups.indexOf(existedGroup);
        for (int instanceIndex = 0; instanceIndex < group.getInstances().size(); instanceIndex++) {
            CloudInstance cloudInstance = group.getInstances().get(instanceIndex);
            String address = generateAddress(prefix, spiDto, indexOfExistedGroup, ret);
            String instanceId = String.format("instance-%s", address + "-" + UUID.randomUUID());
            CloudInstance cloudInstanceWithId = new CloudInstance(instanceId, getTemplateCreated(cloudInstance), cloudInstance.getAuthentication(), cloudInstance.getSubnetId(), cloudInstance.getAvailabilityZone());
            CloudVmInstanceStatus cloudVmInstanceStatus = new CloudVmInstanceStatus(cloudInstanceWithId, InstanceStatus.STARTED);
            String publicIp = mockInfrastructureHost + ":10090/" + name;
            CloudInstanceMetaData cloudInstanceMetaData = new CloudInstanceMetaData(address, publicIp, SSH_PORT, "MOCK");
            CloudVmMetaDataStatus cloudVmMetaDataStatus = new CloudVmMetaDataStatus(cloudVmInstanceStatus, cloudInstanceMetaData);
            ret.add(cloudVmMetaDataStatus);
        }
    }
    return ret;
}
Also used : Logger(org.slf4j.Logger) CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) LoggerFactory(org.slf4j.LoggerFactory) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) UUID(java.util.UUID) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) List(java.util.List) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) Service(org.springframework.stereotype.Service) Group(com.sequenceiq.cloudbreak.cloud.model.Group) SpiDto(com.sequenceiq.mock.spi.SpiDto) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) Group(com.sequenceiq.cloudbreak.cloud.model.Group) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) ArrayList(java.util.ArrayList) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus)

Example 20 with NotFoundException

use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.

the class SaltOrchestrator method selectNewMasterReplacement.

private void selectNewMasterReplacement(SaltConnector sc, GatewayConfig primaryGateway, Set<String> unassignedHostnames, Set<String> existingFreeIpaReplicaHostnames, Set<Node> allNodes, ExitCriteriaModel exitCriteriaModel, Set<String> freeIpaMasterHostnames) throws Exception {
    freeIpaMasterHostnames.add(unassignedHostnames.stream().findFirst().orElseGet(() -> choosePrimaryGatewayAsMasterReplacement(primaryGateway, existingFreeIpaReplicaHostnames).orElseThrow(() -> new NotFoundException("A primary FreeIPA instance is required and there are no unassigned roles to assign as a primary"))));
    LOGGER.debug("Replacement primary FreeIPA: {}", freeIpaMasterHostnames);
    saltCommandRunner.runModifyGrainCommand(sc, new GrainAddRunner(freeIpaMasterHostnames, allNodes, FREEIPA_MASTER_REPLACEMENT_ROLE), exitCriteriaModel, exitCriteria);
    saltCommandRunner.runModifyGrainCommand(sc, new GrainRemoveRunner(freeIpaMasterHostnames, allNodes, FREEIPA_REPLICA_ROLE), exitCriteriaModel, exitCriteria);
}
Also used : GrainRemoveRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainRemoveRunner) GrainAddRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainAddRunner) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException)

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