Package com.sequenceiq.cloudbreak.domain

Examples of com.sequenceiq.cloudbreak.domain.Stack


        return stackJson;
    }

    @Override
    public Stack convert(StackJson json) {
        Stack stack = new Stack();
        stack.setNodeCount(json.getNodeCount());
        stack.setName(json.getName());
        try {
            stack.setCredential(credentialRepository.findOne(json.getCredentialId()));
        } catch (AccessDeniedException e) {
            throw new AccessDeniedException(String.format("Access to credential '%s' is denied or credential doesn't exist.", json.getCredentialId()), e);
        }
        try {
            stack.setTemplate(templateRepository.findOne(Long.valueOf(json.getTemplateId())));
        } catch (AccessDeniedException e) {
            throw new AccessDeniedException(String.format("Access to template '%s' is denied or template doesn't exist.", json.getTemplateId()), e);
        }
        stack.setStatus(Status.REQUESTED);
        return stack;
    }
View Full Code Here


        }
    }

    @Override
    public void updateNodeCount(Long stackId, Integer scalingAdjustment) {
        Stack stack = stackRepository.findOne(stackId);
        MDCBuilder.buildMdcContext(stack);
        if (!Status.AVAILABLE.equals(stack.getStatus())) {
            throw new BadRequestException(String.format("Stack '%s' is currently in '%s' state. Node count can only be updated if it's running.", stackId,
                    stack.getStatus()));
        }
        if (0 == scalingAdjustment) {
            throw new BadRequestException(String.format("Requested scaling adjustment on stack '%s' is 0. Nothing to do.", stackId));
        }
        if (0 > scalingAdjustment) {
            if (-1 * scalingAdjustment > stack.getNodeCount()) {
                throw new BadRequestException(String.format("There are %s instances in stack '%s'. Cannot remove %s instances.", stack.getNodeCount(), stackId,
                        -1 * scalingAdjustment));
            }
            int removeableHosts = 0;
            for (InstanceMetaData metadataEntry : stack.getInstanceMetaData()) {
                if (metadataEntry.isRemovable()) {
                    removeableHosts++;
                }
            }
            if (removeableHosts < -1 * scalingAdjustment) {
                throw new BadRequestException(
                        String.format("There are %s removable hosts on stack '%s' but %s were requested. Decomission nodes from the cluster first!",
                                removeableHosts, stackId, scalingAdjustment * -1));
            }
        }
        stackUpdater.updateStackStatus(stack.getId(), Status.UPDATE_IN_PROGRESS);
        LOGGER.info("Publishing {} event [scalingAdjustment: '{}']", ReactorConfig.UPDATE_INSTANCES_REQUEST_EVENT, scalingAdjustment);
        reactor.notify(ReactorConfig.UPDATE_INSTANCES_REQUEST_EVENT,
                Event.wrap(new UpdateInstancesRequest(stack.getTemplate().cloudPlatform(), stack.getId(), scalingAdjustment)));
    }
View Full Code Here

        return description;
    }

    @Override
    public Set<InstanceMetaData> getMetaData(String hash) {
        Stack stack = stackRepository.findStackByHash(hash);
        if (stack != null) {
            if (!stack.isMetadataReady()) {
                throw new MetadataIncompleteException("Instance metadata is incomplete.");
            }
            if (!stack.getInstanceMetaData().isEmpty()) {
                return stack.getInstanceMetaData();
            }
        }
        throw new NotFoundException("Metadata not found on stack.");
    }
View Full Code Here

    private StackRepository stackRepository;

    @Override
    public void accept(Event<UpdateAmbariHostsRequest> event) {
        UpdateAmbariHostsRequest request = event.getData();
        Stack stack = stackRepository.findById(request.getStackId());
        MDCBuilder.buildMdcContext(stack);
        LOGGER.info("Accepted {} event.", ReactorConfig.UPDATE_AMBARI_HOSTS_REQUEST_EVENT);
        if (request.isDecommision()) {
            ambariClusterConnector.decommisionAmbariNodes(request.getStackId(), request.getHosts());
        } else {
View Full Code Here

    private boolean isStackDeleteCompleteMessage(Map<String, String> cfMessage) {
        return "AWS::CloudFormation::Stack".equals(cfMessage.get("ResourceType")) && "DELETE_COMPLETE".equals(cfMessage.get("ResourceStatus"));
    }

    private synchronized void handleCfStackCreateComplete(Map<String, String> cfMessage) {
        Stack stack = stackRepository.findByStackResourceName(cfMessage.get("StackName"));
        MDCBuilder.buildMdcContext(stack);
        if (stack == null) {
            LOGGER.info(
                    "Got message that CloudFormation stack created, but no matching stack found in the database [CFStackId: '{}']. Ignoring message.",
                    cfMessage.get("StackId"));
        } else if (!stack.isStackCompleted()) {
            stack = stackUpdater.updateStackCreateComplete(stack.getId());
            LOGGER.info("CloudFormation stack creation completed.");
            LOGGER.info("Publishing {} event.", ReactorConfig.PROVISION_COMPLETE_EVENT);
            Set<Resource> resourceSet = new HashSet<>();
            resourceSet.add(new Resource(ResourceType.CLOUDFORMATION_STACK, cfMessage.get("StackName"), stack));
            reactor.notify(ReactorConfig.PROVISION_COMPLETE_EVENT, Event.wrap(new ProvisionComplete(CloudPlatform.AWS, stack.getId(), resourceSet)));
        }
    }
View Full Code Here

            reactor.notify(ReactorConfig.PROVISION_COMPLETE_EVENT, Event.wrap(new ProvisionComplete(CloudPlatform.AWS, stack.getId(), resourceSet)));
        }
    }

    private synchronized void handleCfStackCreateFailed(Map<String, String> cfMessage) {
        Stack stack = stackRepository.findByStackResourceName(cfMessage.get("StackName"));
        MDCBuilder.buildMdcContext(stack);
        if (stack == null) {
            LOGGER.info("Got message that CloudFormation stack creation failed, but no matching stack found in the db. [CFStackId: '{}']. Ignoring message.",
                    cfMessage.get("StackId"));
        } else if (!stack.isStackCompleted() && !Status.CREATE_FAILED.equals(stack.getStatus())) {
            LOGGER.info("CloudFormation stack creation failed. [Id: '{}']", stack.getId());
            StackOperationFailure stackCreationFailure = new StackOperationFailure(stack.getId(), "Error while creating CloudFormation stack: "
                    + cfMessage.get("ResourceStatusReason"));
            LOGGER.info("Publishing {} event [StackId: '{}']", ReactorConfig.STACK_CREATE_FAILED_EVENT, stack.getId());
            reactor.notify(ReactorConfig.STACK_CREATE_FAILED_EVENT, Event.wrap(stackCreationFailure));
        } else {
            LOGGER.info("Got message that CloudFormation stack creation failed, but its status is already FAILED [CFStackId: '{}']. Ignoring message.",
                    cfMessage.get("StackId"));
        }
View Full Code Here

                    cfMessage.get("StackId"));
        }
    }

    private synchronized void handleCfStackDeleteComplete(Map<String, String> cfMessage) {
        Stack stack = stackRepository.findByStackResourceName(cfMessage.get("StackName"));
        MDCBuilder.buildMdcContext(stack);
        if (stack == null) {
            LOGGER.info("Got message that CloudFormation stack creation failed, but no matching stack found in the db. [CFStackId: '{}']. Ignoring message.",
                    cfMessage.get("StackId"));
        } else {
            LOGGER.info("CloudFormation stack delete completed.");
            LOGGER.info("Publishing {} event.", ReactorConfig.DELETE_COMPLETE_EVENT);
            reactor.notify(ReactorConfig.DELETE_COMPLETE_EVENT, Event.wrap(new StackDeleteComplete(stack.getId())));
        }
    }
View Full Code Here

    public Stack updateStackStatus(Long stackId, Status status) {
        return updateStackStatus(stackId, status, null);
    }

    public Stack updateStackStatus(Long stackId, Status status, String statusReason) {
        Stack stack = stackRepository.findById(stackId);
        MDCBuilder.buildMdcContext(stack);
        int attempt = 1;
        try {
            return doUpdateStackStatus(stackId, status, statusReason);
        } catch (OptimisticLockException | OptimisticLockingFailureException e) {
View Full Code Here

            }
        }
    }

    public Stack updateStackStatusReason(Long stackId, String statusReason) {
        Stack stack = stackRepository.findById(stackId);
        MDCBuilder.buildMdcContext(stack);
        int attempt = 1;
        try {
            return doUpdateStackStatusReason(stackId, statusReason);
        } catch (OptimisticLockException | OptimisticLockingFailureException e) {
View Full Code Here

            }
        }
    }

    public Stack updateStackMetaData(Long stackId, Set<InstanceMetaData> instanceMetaData) {
        Stack stack = stackRepository.findById(stackId);
        MDCBuilder.buildMdcContext(stack);
        int attempt = 1;
        try {
            return doUpdateMetaData(stackId, instanceMetaData);
        } catch (OptimisticLockException | OptimisticLockingFailureException e) {
View Full Code Here

TOP

Related Classes of com.sequenceiq.cloudbreak.domain.Stack

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.