Search in sources :

Example 11 with NotFoundException

use of com.sequenceiq.cloudbreak.controller.NotFoundException in project cloudbreak by hortonworks.

the class StackSyncService method deleteHostFromCluster.

private void deleteHostFromCluster(Stack stack, InstanceMetaData instanceMetaData) {
    try {
        if (stack.getCluster() != null) {
            HostMetadata hostMetadata = hostMetadataRepository.findHostInClusterByName(stack.getCluster().getId(), instanceMetaData.getDiscoveryFQDN());
            if (hostMetadata == null) {
                if (instanceMetaData.getInstanceStatus() != InstanceStatus.TERMINATED) {
                    throw new NotFoundException(String.format("Host not found with id '%s'", instanceMetaData.getDiscoveryFQDN()));
                }
            } else {
                if (ambariClusterConnector.available(stack)) {
                    if (ambariDecommissioner.deleteHostFromAmbari(stack, hostMetadata)) {
                        hostMetadataRepository.delete(hostMetadata.getId());
                        eventService.fireCloudbreakEvent(stack.getId(), AVAILABLE.name(), cloudbreakMessagesService.getMessage(Msg.STACK_SYNC_HOST_DELETED.code(), Collections.singletonList(instanceMetaData.getDiscoveryFQDN())));
                    } else {
                        eventService.fireCloudbreakEvent(stack.getId(), AVAILABLE.name(), cloudbreakMessagesService.getMessage(Msg.STACK_SYNC_INSTANCE_REMOVAL_FAILED.code(), Collections.singletonList(instanceMetaData.getDiscoveryFQDN())));
                    }
                } else {
                    hostMetadata.setHostMetadataState(HostMetadataState.UNHEALTHY);
                    hostMetadataRepository.save(hostMetadata);
                    eventService.fireCloudbreakEvent(stack.getId(), AVAILABLE.name(), cloudbreakMessagesService.getMessage(Msg.STACK_SYNC_HOST_UPDATED.code(), Arrays.asList(instanceMetaData.getDiscoveryFQDN(), HostMetadataState.UNHEALTHY.name())));
                }
            }
        }
    } catch (Exception e) {
        LOGGER.error("Host cannot be deleted from cluster: ", e);
        eventService.fireCloudbreakEvent(stack.getId(), AVAILABLE.name(), cloudbreakMessagesService.getMessage(Msg.STACK_SYNC_INSTANCE_TERMINATED.code(), Collections.singletonList(instanceMetaData.getDiscoveryFQDN())));
    }
}
Also used : NotFoundException(com.sequenceiq.cloudbreak.controller.NotFoundException) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) NotFoundException(com.sequenceiq.cloudbreak.controller.NotFoundException) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata)

Example 12 with NotFoundException

use of com.sequenceiq.cloudbreak.controller.NotFoundException in project cloudbreak by hortonworks.

the class StackService method getPublicStack.

public Stack getPublicStack(String name, IdentityUser identityUser) {
    Stack stack = stackRepository.findByNameInAccount(name, identityUser.getAccount());
    if (stack == null) {
        throw new NotFoundException(String.format(STACK_NOT_FOUND_EXCEPTION_FORMAT_TEXT, name));
    }
    authorizationService.hasReadPermission(stack);
    return stack;
}
Also used : NotFoundException(com.sequenceiq.cloudbreak.controller.NotFoundException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Example 13 with NotFoundException

use of com.sequenceiq.cloudbreak.controller.NotFoundException in project cloudbreak by hortonworks.

the class StackService method getPublicStackJsonByName.

public StackResponse getPublicStackJsonByName(String name, IdentityUser identityUser, Collection<String> entries) {
    Stack stack = stackRepository.findByNameInAccountWithLists(name, identityUser.getAccount());
    if (stack == null) {
        throw new NotFoundException(String.format(STACK_NOT_FOUND_EXCEPTION_FORMAT_TEXT, name));
    }
    authorizationService.hasReadPermission(stack);
    StackResponse stackResponse = conversionService.convert(stack, StackResponse.class);
    stackResponse = stackResponseDecorator.decorate(stackResponse, stack, entries);
    return stackResponse;
}
Also used : NotFoundException(com.sequenceiq.cloudbreak.controller.NotFoundException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) AutoscaleStackResponse(com.sequenceiq.cloudbreak.api.model.AutoscaleStackResponse) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Example 14 with NotFoundException

use of com.sequenceiq.cloudbreak.controller.NotFoundException in project cloudbreak by hortonworks.

the class StackService method delete.

public void delete(String name, IdentityUser user, Boolean forced, Boolean deleteDependencies) {
    Stack stack = stackRepository.findByNameInAccountOrOwner(name, user.getAccount(), user.getUserId());
    if (stack == null) {
        throw new NotFoundException(String.format(STACK_NOT_FOUND_EXCEPTION_FORMAT_TEXT, name));
    }
    delete(stack, forced, deleteDependencies);
}
Also used : NotFoundException(com.sequenceiq.cloudbreak.controller.NotFoundException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Example 15 with NotFoundException

use of com.sequenceiq.cloudbreak.controller.NotFoundException in project cloudbreak by hortonworks.

the class StackService method delete.

public void delete(Long id, IdentityUser user, Boolean forced, Boolean deleteDependencies) {
    Stack stack = stackRepository.findByIdInAccount(id, user.getAccount());
    if (stack == null) {
        throw new NotFoundException(String.format(STACK_NOT_FOUND_EXCEPTION_FORMAT_TEXT, id));
    }
    delete(stack, forced, deleteDependencies);
}
Also used : NotFoundException(com.sequenceiq.cloudbreak.controller.NotFoundException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Aggregations

NotFoundException (com.sequenceiq.cloudbreak.controller.NotFoundException)50 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)9 Stack (com.sequenceiq.cloudbreak.domain.Stack)8 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)5 ProxyConfig (com.sequenceiq.cloudbreak.domain.ProxyConfig)5 ClusterTemplate (com.sequenceiq.cloudbreak.domain.ClusterTemplate)4 ConstraintTemplate (com.sequenceiq.cloudbreak.domain.ConstraintTemplate)4 RDSConfig (com.sequenceiq.cloudbreak.domain.RDSConfig)4 Template (com.sequenceiq.cloudbreak.domain.Template)4 LdapConfig (com.sequenceiq.cloudbreak.domain.LdapConfig)3 AmbariClient (com.sequenceiq.ambari.client.AmbariClient)2 AutoscaleStackResponse (com.sequenceiq.cloudbreak.api.model.AutoscaleStackResponse)2 StackResponse (com.sequenceiq.cloudbreak.api.model.StackResponse)2 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)2 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)2 Recipe (com.sequenceiq.cloudbreak.domain.Recipe)2 SecurityGroup (com.sequenceiq.cloudbreak.domain.SecurityGroup)2 CertificateResponse (com.sequenceiq.cloudbreak.api.model.CertificateResponse)1 HttpClientConfig (com.sequenceiq.cloudbreak.client.HttpClientConfig)1 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)1