Search in sources :

Example 46 with BadRequestException

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

the class UpdateStackRequestV2ToUpdateClusterRequestConverter method convert.

@Override
public UpdateClusterJson convert(StackScaleRequestV2 source) {
    UpdateClusterJson updateStackJson = new UpdateClusterJson();
    Cluster oneByStackId = clusterRepository.findOneByStackId(source.getStackId());
    HostGroup hostGroup = hostGroupRepository.findHostGroupInClusterByName(oneByStackId.getId(), source.getGroup());
    if (hostGroup != null) {
        HostGroupAdjustmentJson hostGroupAdjustmentJson = new HostGroupAdjustmentJson();
        hostGroupAdjustmentJson.setWithStackUpdate(true);
        hostGroupAdjustmentJson.setValidateNodeCount(true);
        hostGroupAdjustmentJson.setHostGroup(source.getGroup());
        int scaleNumber = source.getDesiredCount() - hostGroup.getHostMetadata().size();
        hostGroupAdjustmentJson.setScalingAdjustment(scaleNumber);
        updateStackJson.setHostGroupAdjustment(hostGroupAdjustmentJson);
    } else {
        throw new BadRequestException(String.format("Group '%s' not available on stack", source.getGroup()));
    }
    return updateStackJson;
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.Cluster) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) HostGroupAdjustmentJson(com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson) UpdateClusterJson(com.sequenceiq.cloudbreak.api.model.UpdateClusterJson)

Example 47 with BadRequestException

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

the class StackService method triggerStackStopIfNeeded.

private void triggerStackStopIfNeeded(Stack stack, Cluster cluster, boolean updateCluster) {
    if (!isStopNeeded(stack)) {
        return;
    }
    if (cluster != null && !cluster.isStopped() && !stack.isStopFailed()) {
        if (!updateCluster) {
            throw new BadRequestException(String.format("Cannot update the status of stack '%s' to STOPPED, because the cluster is not in STOPPED state.", stack.getName()));
        } else if (cluster.isClusterReadyForStop() || cluster.isStopFailed()) {
            setStackStatusToStopRequested(stack);
            ambariClusterService.updateStatus(stack.getId(), StatusRequest.STOPPED);
        } else {
            throw new BadRequestException(String.format("Cannot update the status of cluster '%s' to STOPPED, because the cluster's state is %s.", cluster.getName(), cluster.getStatus()));
        }
    } else {
        stackUpdater.updateStackStatus(stack.getId(), DetailedStackStatus.STOP_REQUESTED);
        flowManager.triggerStackStop(stack.getId());
    }
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException)

Example 48 with BadRequestException

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

the class StackService method validateHostGroupAdjustment.

private void validateHostGroupAdjustment(InstanceGroupAdjustmentJson instanceGroupAdjustmentJson, Stack stack, Integer adjustment) {
    Blueprint blueprint = stack.getCluster().getBlueprint();
    Optional<HostGroup> hostGroup = stack.getCluster().getHostGroups().stream().filter(input -> input.getConstraint().getInstanceGroup().getGroupName().equals(instanceGroupAdjustmentJson.getInstanceGroup())).findFirst();
    if (!hostGroup.isPresent()) {
        throw new BadRequestException(String.format("Instancegroup '%s' not found or not part of stack '%s'", instanceGroupAdjustmentJson.getInstanceGroup(), stack.getName()));
    }
    blueprintValidator.validateHostGroupScalingRequest(blueprint, hostGroup.get(), adjustment);
}
Also used : StackView(com.sequenceiq.cloudbreak.domain.view.StackView) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) IdentityUserRole(com.sequenceiq.cloudbreak.common.model.user.IdentityUserRole) ComponentType(com.sequenceiq.cloudbreak.common.type.ComponentType) StackValidation(com.sequenceiq.cloudbreak.domain.StackValidation) Component(com.sequenceiq.cloudbreak.domain.Component) IdentityUser(com.sequenceiq.cloudbreak.common.model.user.IdentityUser) InstanceMetaDataRepository(com.sequenceiq.cloudbreak.repository.InstanceMetaDataRepository) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) LoggerFactory(org.slf4j.LoggerFactory) PasswordUtil(com.sequenceiq.cloudbreak.util.PasswordUtil) Autowired(org.springframework.beans.factory.annotation.Autowired) ServiceProviderConnectorAdapter(com.sequenceiq.cloudbreak.service.stack.connector.adapter.ServiceProviderConnectorAdapter) Orchestrator(com.sequenceiq.cloudbreak.domain.Orchestrator) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) CloudbreakMessagesService(com.sequenceiq.cloudbreak.service.messages.CloudbreakMessagesService) ImageService(com.sequenceiq.cloudbreak.service.image.ImageService) Strings(com.google.api.client.repackaged.com.google.common.base.Strings) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) AuthorizationService(com.sequenceiq.cloudbreak.service.AuthorizationService) SqlUtil.getProperSqlErrorMessage(com.sequenceiq.cloudbreak.util.SqlUtil.getProperSqlErrorMessage) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) OrchestratorRepository(com.sequenceiq.cloudbreak.repository.OrchestratorRepository) AmbariClusterService(com.sequenceiq.cloudbreak.service.cluster.AmbariClusterService) TxType(javax.transaction.Transactional.TxType) StackViewRepository(com.sequenceiq.cloudbreak.repository.StackViewRepository) Transactional(javax.transaction.Transactional) StackStatus(com.sequenceiq.cloudbreak.domain.StackStatus) TlsSecurityService(com.sequenceiq.cloudbreak.service.TlsSecurityService) Collection(java.util.Collection) StackTemplate(com.sequenceiq.cloudbreak.cloud.model.StackTemplate) InstanceGroupRepository(com.sequenceiq.cloudbreak.repository.InstanceGroupRepository) Set(java.util.Set) BlueprintValidator(com.sequenceiq.cloudbreak.blueprint.validation.BlueprintValidator) NotFoundException(com.sequenceiq.cloudbreak.controller.NotFoundException) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) ClusterRepository(com.sequenceiq.cloudbreak.repository.ClusterRepository) List(java.util.List) STOPPED(com.sequenceiq.cloudbreak.api.model.Status.STOPPED) STOP_REQUESTED(com.sequenceiq.cloudbreak.api.model.Status.STOP_REQUESTED) InstanceStatus(com.sequenceiq.cloudbreak.api.model.InstanceStatus) SecurityConfig(com.sequenceiq.cloudbreak.domain.SecurityConfig) ComponentConfigProvider(com.sequenceiq.cloudbreak.service.ComponentConfigProvider) Optional(java.util.Optional) CloudbreakApiException(com.sequenceiq.cloudbreak.controller.CloudbreakApiException) StackStatusRepository(com.sequenceiq.cloudbreak.repository.StackStatusRepository) StackRepository(com.sequenceiq.cloudbreak.repository.StackRepository) InstanceGroupAdjustmentJson(com.sequenceiq.cloudbreak.api.model.InstanceGroupAdjustmentJson) ReactorFlowManager(com.sequenceiq.cloudbreak.core.flow2.service.ReactorFlowManager) ContainerOrchestratorResolver(com.sequenceiq.cloudbreak.core.bootstrap.service.container.ContainerOrchestratorResolver) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) TypeDescriptor(org.springframework.core.convert.TypeDescriptor) Service(org.springframework.stereotype.Service) OrchestrationCredential(com.sequenceiq.cloudbreak.orchestrator.model.OrchestrationCredential) Objects.requireNonNull(java.util.Objects.requireNonNull) StackResponseDecorator(com.sequenceiq.cloudbreak.service.decorator.StackResponseDecorator) Qualifier(org.springframework.beans.factory.annotation.Qualifier) Json(com.sequenceiq.cloudbreak.domain.json.Json) Stack(com.sequenceiq.cloudbreak.domain.Stack) Nonnull(javax.annotation.Nonnull) ConversionService(org.springframework.core.convert.ConversionService) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) Logger(org.slf4j.Logger) ContainerOrchestrator(com.sequenceiq.cloudbreak.orchestrator.container.ContainerOrchestrator) CloudbreakDetails(com.sequenceiq.cloudbreak.cloud.model.CloudbreakDetails) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) AVAILABLE(com.sequenceiq.cloudbreak.api.model.Status.AVAILABLE) DetailedStackStatus(com.sequenceiq.cloudbreak.api.model.DetailedStackStatus) AutoscaleStackResponse(com.sequenceiq.cloudbreak.api.model.AutoscaleStackResponse) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) SecurityConfigRepository(com.sequenceiq.cloudbreak.repository.SecurityConfigRepository) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) StackUpdater(com.sequenceiq.cloudbreak.repository.StackUpdater) OpenSshPublicKeyValidator(com.sequenceiq.cloudbreak.service.credential.OpenSshPublicKeyValidator) APIResourceType(com.sequenceiq.cloudbreak.common.type.APIResourceType) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse) NetworkConfigurationValidator(com.sequenceiq.cloudbreak.controller.validation.network.NetworkConfigurationValidator) StackV2Request(com.sequenceiq.cloudbreak.api.model.v2.StackV2Request) CloudbreakEventService(com.sequenceiq.cloudbreak.service.events.CloudbreakEventService) StatusRequest(com.sequenceiq.cloudbreak.api.model.StatusRequest) StopRestrictionReason(com.sequenceiq.cloudbreak.domain.StopRestrictionReason) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException)

Example 49 with BadRequestException

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

the class StackService method isStopNeeded.

private boolean isStopNeeded(Stack stack) {
    boolean result = true;
    StopRestrictionReason reason = stack.isInfrastructureStoppable();
    if (stack.isStopped()) {
        String statusDesc = cloudbreakMessagesService.getMessage(Msg.STACK_STOP_IGNORED.code());
        LOGGER.info(statusDesc);
        eventService.fireCloudbreakEvent(stack.getId(), STOPPED.name(), statusDesc);
        result = false;
    } else if (reason != StopRestrictionReason.NONE) {
        throw new BadRequestException(String.format("Cannot stop a stack '%s'. Reason: %s", stack.getName(), reason.getReason()));
    } else if (!stack.isAvailable() && !stack.isStopFailed()) {
        throw new BadRequestException(String.format("Cannot update the status of stack '%s' to STOPPED, because it isn't in AVAILABLE state.", stack.getName()));
    }
    return result;
}
Also used : StopRestrictionReason(com.sequenceiq.cloudbreak.domain.StopRestrictionReason) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException)

Example 50 with BadRequestException

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

the class NetworkService method create.

@Transactional(TxType.NEVER)
public Network create(IdentityUser user, Network network) {
    LOGGER.info("Creating network: [User: '{}', Account: '{}']", user.getUsername(), user.getAccount());
    network.setOwner(user.getUserId());
    network.setAccount(user.getAccount());
    try {
        return networkRepository.save(network);
    } catch (DataIntegrityViolationException ex) {
        String msg = String.format("Error with resource [%s], error: [%s]", APIResourceType.NETWORK, getProperSqlErrorMessage(ex));
        throw new BadRequestException(msg);
    }
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Transactional(javax.transaction.Transactional)

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