Search in sources :

Example 81 with BadRequestException

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

the class AmbariClusterModificationService method installServices.

private Map<String, Integer> installServices(List<String> hosts, Stack stack, AmbariClient ambariClient, String hostGroup) {
    try {
        String blueprintName = stack.getCluster().getBlueprint().getAmbariName();
        // In case If we changed the blueprintName field we need to query the validation name information from ambari
        Map<String, String> blueprintsMap = ambariClient.getBlueprintsMap();
        if (!blueprintsMap.entrySet().isEmpty()) {
            blueprintName = blueprintsMap.keySet().iterator().next();
        }
        return singletonMap("UPSCALE_REQUEST", ambariClient.addHostsWithBlueprint(blueprintName, hostGroup, hosts));
    } catch (HttpResponseException e) {
        if ("Conflict".equals(e.getMessage())) {
            throw new BadRequestException("Host already exists.", e);
        } else {
            String errorMessage = AmbariClientExceptionUtil.getErrorMessage(e);
            throw new CloudbreakServiceException("Ambari could not install services. " + errorMessage, e);
        }
    }
}
Also used : CloudbreakServiceException(com.sequenceiq.cloudbreak.service.CloudbreakServiceException) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) HttpResponseException(groovyx.net.http.HttpResponseException)

Example 82 with BadRequestException

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

the class CollectDownscaleCandidatesHandler method accept.

@Override
public void accept(Event<CollectDownscaleCandidatesRequest> event) {
    CollectDownscaleCandidatesRequest request = event.getData();
    CollectDownscaleCandidatesResult result;
    try {
        Stack stack = stackService.getByIdWithLists(request.getStackId());
        Set<String> hostNames;
        if (request.getHostNames() == null || request.getHostNames().isEmpty()) {
            hostNames = ambariDecommissioner.collectDownscaleCandidates(stack, request.getHostGroupName(), request.getScalingAdjustment());
        } else {
            hostNames = request.getHostNames();
            String hostName = hostNames.stream().findFirst().orElseThrow(() -> new BadRequestException("Unable to find host name"));
            ambariDecommissioner.verifyNodeCount(stack, stack.getCluster(), hostName);
        }
        result = new CollectDownscaleCandidatesResult(request, hostNames);
    } catch (Exception e) {
        result = new CollectDownscaleCandidatesResult(e.getMessage(), e, request);
    }
    eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result));
}
Also used : CollectDownscaleCandidatesRequest(com.sequenceiq.cloudbreak.reactor.api.event.resource.CollectDownscaleCandidatesRequest) CollectDownscaleCandidatesResult(com.sequenceiq.cloudbreak.reactor.api.event.resource.CollectDownscaleCandidatesResult) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Example 83 with BadRequestException

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

the class InteractiveCredentialCreationHandler method accept.

@Override
public void accept(Event<InteractiveCredentialCreationRequest> interactiveCredentialCreationRequestEvent) {
    InteractiveCredentialCreationRequest interactiveCredentialCreationRequest = interactiveCredentialCreationRequestEvent.getData();
    ExtendedCloudCredential extendedCloudCredential = interactiveCredentialCreationRequest.getExtendedCloudCredential();
    Credential credential = extendedCloudCredentialToCredentialConverter.convert(extendedCloudCredential);
    try {
        credentialService.createWithRetry(extendedCloudCredential.getOwner(), extendedCloudCredential.getAccount(), credential);
    } catch (DuplicateKeyValueException e) {
        sendErrorNotification(extendedCloudCredential.getOwner(), extendedCloudCredential.getAccount(), extendedCloudCredential.getCloudPlatform(), DuplicatedKeyValueExceptionMapper.errorMessage(e));
    } catch (BadRequestException e) {
        sendErrorNotification(extendedCloudCredential.getOwner(), extendedCloudCredential.getAccount(), extendedCloudCredential.getCloudPlatform(), e.getMessage());
    }
}
Also used : ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) Credential(com.sequenceiq.cloudbreak.domain.Credential) ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) InteractiveCredentialCreationRequest(com.sequenceiq.cloudbreak.cloud.event.credential.InteractiveCredentialCreationRequest) DuplicateKeyValueException(com.sequenceiq.cloudbreak.service.DuplicateKeyValueException)

Example 84 with BadRequestException

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

the class StackRequestToStackConverterTest method testConvertWithNoGateway.

@SuppressFBWarnings(value = "DLS_DEAD_LOCAL_STORE")
@Test
public void testConvertWithNoGateway() throws CloudbreakException {
    InstanceGroup instanceGroup = mock(InstanceGroup.class);
    when(instanceGroup.getInstanceGroupType()).thenReturn(InstanceGroupType.CORE);
    // GIVEN
    ReflectionTestUtils.setField(underTest, "defaultRegions", "AWS:eu-west-2");
    given(conversionService.convert(any(Object.class), any(TypeDescriptor.class), any(TypeDescriptor.class))).willReturn(new HashSet<>(Collections.singletonList(instanceGroup)));
    given(conversionService.convert(any(Object.class), any(TypeDescriptor.class), any(TypeDescriptor.class))).willReturn(new HashSet<>(Collections.singletonList(instanceGroup)));
    given(conversionService.convert(any(StackAuthenticationRequest.class), eq(StackAuthentication.class))).willReturn(new StackAuthentication());
    given(conversionService.convert(any(FailurePolicyRequest.class), eq(FailurePolicy.class))).willReturn(new FailurePolicy());
    given(conversionService.convert(any(InstanceGroupRequest.class), eq(InstanceGroup.class))).willReturn(instanceGroup);
    given(conversionService.convert(any(OrchestratorRequest.class), eq(Orchestrator.class))).willReturn(new Orchestrator());
    given(orchestratorTypeResolver.resolveType(any(String.class))).willReturn(OrchestratorType.HOST);
    // WHEN
    try {
        Stack stack = underTest.convert(getRequest("stack/stack.json"));
    } catch (BadRequestException e) {
        // THEN
        Assert.assertEquals("Ambari server must be specified", e.getMessage());
    }
}
Also used : StackAuthenticationRequest(com.sequenceiq.cloudbreak.api.model.StackAuthenticationRequest) StackAuthentication(com.sequenceiq.cloudbreak.domain.StackAuthentication) InstanceGroupRequest(com.sequenceiq.cloudbreak.api.model.InstanceGroupRequest) Matchers.anyString(org.mockito.Matchers.anyString) Orchestrator(com.sequenceiq.cloudbreak.domain.Orchestrator) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Stack(com.sequenceiq.cloudbreak.domain.Stack) TypeDescriptor(org.springframework.core.convert.TypeDescriptor) OrchestratorRequest(com.sequenceiq.cloudbreak.api.model.OrchestratorRequest) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) FailurePolicyRequest(com.sequenceiq.cloudbreak.api.model.FailurePolicyRequest) FailurePolicy(com.sequenceiq.cloudbreak.domain.FailurePolicy) Test(org.junit.Test) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 85 with BadRequestException

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

the class TemplateService method delete.

private void delete(Template template) {
    authorizationService.hasWritePermission(template);
    LOGGER.debug("Deleting template. {} - {}", new Object[] { template.getId(), template.getName() });
    List<Stack> allStackForTemplate = stackRepository.findAllStackForTemplate(template.getId());
    if (allStackForTemplate.isEmpty()) {
        template.setTopology(null);
        if (ResourceStatus.USER_MANAGED.equals(template.getStatus())) {
            templateRepository.delete(template);
        } else {
            template.setName(NameUtil.postfixWithTimestamp(template.getName()));
            template.setStatus(ResourceStatus.DEFAULT_DELETED);
            templateRepository.save(template);
        }
    } else if (isRunningStackReferToTemplate(allStackForTemplate)) {
        throw new BadRequestException(String.format("There are stacks associated with template '%s'. Please remove these before deleting the template.", template.getName()));
    } else {
        template.setName(NameUtil.postfixWithTimestamp(template.getName()));
        template.setTopology(null);
        template.setDeleted(true);
        if (ResourceStatus.DEFAULT.equals(template.getStatus())) {
            template.setStatus(ResourceStatus.DEFAULT_DELETED);
        }
        templateRepository.save(template);
    }
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Aggregations

BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)87 Stack (com.sequenceiq.cloudbreak.domain.Stack)16 Transactional (javax.transaction.Transactional)13 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)12 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)12 Json (com.sequenceiq.cloudbreak.domain.json.Json)12 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)12 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)11 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)9 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)9 IOException (java.io.IOException)7 Credential (com.sequenceiq.cloudbreak.domain.Credential)6 HashMap (java.util.HashMap)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 Constraint (com.sequenceiq.cloudbreak.domain.Constraint)5 BlueprintParameterJson (com.sequenceiq.cloudbreak.api.model.BlueprintParameterJson)4 Platform (com.sequenceiq.cloudbreak.cloud.model.Platform)4 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)4 HashSet (java.util.HashSet)4 BlueprintInputJson (com.sequenceiq.cloudbreak.api.model.BlueprintInputJson)3