Package com.sequenceiq.cloudbreak.domain

Examples of com.sequenceiq.cloudbreak.domain.Stack


    @Override
    public void accept(Event<MetadataUpdateComplete> event) {
        MetadataUpdateComplete data = event.getData();
        Long stackId = data.getStackId();
        Set<CoreInstanceMetaData> coreInstanceMetaData = data.getCoreInstanceMetaData();
        Stack stack = stackRepository.findById(stackId);
        MDCBuilder.buildMdcContext(stack);
        LOGGER.info("Accepted {} event.", ReactorConfig.METADATA_UPDATE_COMPLETE_EVENT, stackId);
        ambariRoleAllocator.updateInstanceMetadata(stackId, coreInstanceMetaData);
    }
View Full Code Here


    public void accept(Event<UpdateInstancesRequest> event) {
        UpdateInstancesRequest request = event.getData();
        final CloudPlatform cloudPlatform = request.getCloudPlatform();
        Long stackId = request.getStackId();
        Integer scalingAdjustment = request.getScalingAdjustment();
        final Stack stack = stackRepository.findOneWithLists(stackId);
        MDCBuilder.buildMdcContext(stack);
        try {
            LOGGER.info("Accepted {} event on stack.", ReactorConfig.UPDATE_INSTANCES_REQUEST_EVENT);
            stackUpdater.updateMetadataReady(stackId, false);
            if (scalingAdjustment > 0) {
                if (cloudPlatform.isWithTemplate()) {
                    cloudPlatformConnectors.get(cloudPlatform)
                            .addInstances(stack, userDataBuilder.build(cloudPlatform, stack.getHash(), new HashMap<String, String>()), scalingAdjustment);
                } else {
                    ResourceBuilderInit resourceBuilderInit = resourceBuilderInits.get(cloudPlatform);
                    final ProvisionContextObject pCO =
                            resourceBuilderInit.provisionInit(stack, userDataBuilder.build(cloudPlatform, stack.getHash(), new HashMap<String, String>()));
                    for (ResourceBuilder resourceBuilder : networkResourceBuilders.get(cloudPlatform)) {
                        pCO.getNetworkResources().addAll(stack.getResourcesByType(resourceBuilder.resourceType()));
                    }
                    List<Future<List<Resource>>> futures = new ArrayList<>();
                    Set<Resource> resourceSet = new HashSet<>();
                    for (int i = stack.getNodeCount(); i < stack.getNodeCount() + scalingAdjustment; i++) {
                        final int index = i;
                        Future<List<Resource>> submit = resourceBuilderExecutor.submit(new Callable<List<Resource>>() {
                            @Override
                            public List<Resource> call() throws Exception {
                                List<Resource> resources = new ArrayList<>();
                                for (final ResourceBuilder resourceBuilder : instanceResourceBuilders.get(cloudPlatform)) {
                                    List<Resource> resourceList = resourceBuilder.create(pCO, index, resources);
                                    resources.addAll(resourceList);
                                }
                                return resources;
                            }
                        });
                        futures.add(submit);
                    }
                    for (Future<List<Resource>> future : futures) {
                        try {
                            resourceSet.addAll(future.get());
                        } catch (Exception e) {
                            throw new BuildStackFailureException(e.getMessage(), e, resourceSet);
                        }
                    }
                    LOGGER.info("Publishing {} event.", ReactorConfig.ADD_INSTANCES_COMPLETE_EVENT);
                    reactor.notify(ReactorConfig.ADD_INSTANCES_COMPLETE_EVENT,
                            Event.wrap(new AddInstancesComplete(cloudPlatform, stack.getId(), resourceSet)));
                }
            } else {
                Set<String> instanceIds = new HashSet<>();
                int i = 0;
                for (InstanceMetaData metadataEntry : stack.getInstanceMetaData()) {
                    if (metadataEntry.isRemovable()) {
                        instanceIds.add(metadataEntry.getInstanceId());
                        if (++i >= scalingAdjustment * -1) {
                            break;
                        }
                    }
                }
                if (cloudPlatform.isWithTemplate()) {
                    cloudPlatformConnectors.get(cloudPlatform).removeInstances(stack, instanceIds);
                } else {
                    ResourceBuilderInit resourceBuilderInit = resourceBuilderInits.get(cloudPlatform);
                    final DeleteContextObject dCO = resourceBuilderInit.deleteInit(stack);

                    for (int j = instanceResourceBuilders.get(cloudPlatform).size() - 1; j >= 0; j--) {
                        List<Future<Boolean>> futures = new ArrayList<>();
                        final int index = j;
                        for (final String instanceId : instanceIds) {
                            Future<Boolean> submit = resourceBuilderExecutor.submit(new Callable<Boolean>() {
                                @Override
                                public Boolean call() throws Exception {
                                    Resource resource =
                                            new Resource(instanceResourceBuilders.get(cloudPlatform).get(index).resourceType(), instanceId, stack);
                                    Boolean delete = false;
                                    try {
                                        delete = instanceResourceBuilders.get(cloudPlatform).get(index).delete(resource, dCO);
                                    } catch (HttpResponseException ex) {
                                        LOGGER.error(String.format("Error occurred on stack under the instance remove"), ex);
                                        throw new InternalServerException(
                                                String.format("Error occurred while removing instance '%s' on stack. Message: '%s'",
                                                instanceId, ex.getResponse().toString()), ex);
                                    } catch (Exception ex) {
                                        throw new InternalServerException(
                                                String.format("Error occurred while removing instance '%s' on stack. Message: '%s'",
                                                instanceId, ex.getMessage()), ex);
                                    }
                                    return delete;
                                }
                            });
                            futures.add(submit);
                        }
                        for (Future<Boolean> future : futures) {
                            try {
                                future.get();
                            } catch (Exception ex) {
                                throw ex;
                            }
                        }
                    }
                    LOGGER.info("Terminated instances in stack: '{}'", instanceIds);
                    LOGGER.info("Publishing {} event.", ReactorConfig.STACK_UPDATE_SUCCESS_EVENT);
                    reactor.notify(ReactorConfig.STACK_UPDATE_SUCCESS_EVENT, Event.wrap(new StackUpdateSuccess(stack.getId(), true, instanceIds)));
                }
            }
        } catch (AddInstancesFailedException e) {
            LOGGER.error(e.getMessage(), e);
            notifyUpdateFailed(stack, e.getMessage());
View Full Code Here

    @Override
    public void accept(Event<ProvisionRequest> event) {
        ProvisionRequest provisionRequest = event.getData();
        CloudPlatform cloudPlatform = provisionRequest.getCloudPlatform();
        Long stackId = provisionRequest.getStackId();
        Stack stack = stackRepository.findById(stackId);
        MDCBuilder.buildMdcContext(stack);
        LOGGER.info("Accepted {} event.", ReactorConfig.PROVISION_REQUEST_EVENT, stackId);
        provisionSetupContext.setupProvisioning(cloudPlatform, stackId);
    }
View Full Code Here

    @Override
    public void accept(Event<ProvisionSetupComplete> event) {
        ProvisionSetupComplete provisionSetupComplete = event.getData();
        CloudPlatform cloudPlatform = provisionSetupComplete.getCloudPlatform();
        Long stackId = provisionSetupComplete.getStackId();
        Stack stack = stackRepository.findById(stackId);
        MDCBuilder.buildMdcContext(stack);
        LOGGER.info("Accepted {} event.", ReactorConfig.PROVISION_SETUP_COMPLETE_EVENT, stackId);
        provisionContext.buildStack(cloudPlatform, stackId, provisionSetupComplete.getSetupProperties(), provisionSetupComplete.getUserDataParams());
    }
View Full Code Here

    @Override
    public void accept(Event<MetadataSetupComplete> event) {
        MetadataSetupComplete metadataSetupComplete = event.getData();
        Long stackId = metadataSetupComplete.getStackId();
        Stack stack = stackRepository.findById(stackId);
        MDCBuilder.buildMdcContext(stack);
        Set<CoreInstanceMetaData> coreInstanceMetaData = metadataSetupComplete.getCoreInstanceMetaData();
        LOGGER.info("Accepted {} event.", ReactorConfig.METADATA_SETUP_COMPLETE_EVENT, stackId);
        ambariRoleAllocator.allocateRoles(stackId, coreInstanceMetaData);
    }
View Full Code Here

    public void accept(Event<StackOperationFailure> event) {
        StackOperationFailure stackCreationFailure = event.getData();
        Long stackId = stackCreationFailure.getStackId();
        String detailedMessage = stackCreationFailure.getDetailedMessage();
        stackUpdater.updateStackStatus(stackId, Status.CREATE_FAILED, detailedMessage);
        Stack stack = stackRepository.findOneWithLists(stackId);
        MDCBuilder.buildMdcContext(stack);
        LOGGER.info("Accepted {} event.", ReactorConfig.STACK_CREATE_FAILED_EVENT, stackId);
        if (stack.getCluster().getEmailNeeded()) {
            ambariClusterInstallerMailSenderService.sendFailEmail(stack.getOwner());
        }
        final CloudPlatform cloudPlatform = stack.getTemplate().cloudPlatform();
        try {
            if (cloudPlatform.isWithTemplate()) {
                cloudPlatformConnectors.get(cloudPlatform).rollback(stackRepository.findOneWithLists(stackId), stack.getResources());
            } else {
                ResourceBuilderInit resourceBuilderInit = resourceBuilderInits.get(cloudPlatform);
                final DeleteContextObject dCO = resourceBuilderInit.deleteInit(stack);
                for (int i = instanceResourceBuilders.get(cloudPlatform).size() - 1; i >= 0; i--) {
                    List<Future<Boolean>> futures = new ArrayList<>();
                    final int index = i;
                    List<Resource> resourceByType =
                            stack.getResourcesByType(instanceResourceBuilders.get(cloudPlatform).get(i).resourceType());
                    for (final Resource resource : resourceByType) {
                        Future<Boolean> submit = resourceBuilderExecutor.submit(new Callable<Boolean>() {
                            @Override
                            public Boolean call() throws Exception {
                                return instanceResourceBuilders.get(cloudPlatform).get(index).rollback(resource, dCO);
                            }
                        });
                        futures.add(submit);
                    }
                    for (Future<Boolean> future : futures) {
                        future.get();
                    }
                }
                for (int i = instanceResourceBuilders.get(cloudPlatform).size() - 1; i >= 0; i--) {
                    for (Resource resource
                            : stack.getResourcesByType(networkResourceBuilders.get(cloudPlatform).get(i).resourceType())) {
                        networkResourceBuilders.get(cloudPlatform).get(i).rollback(resource, dCO);
                    }
                }
            }
        } catch (Exception ex) {
            LOGGER.error(String.format("Stack rollback failed on {} stack: ", stack.getId()), ex);
        }
        websocketService.sendToTopicUser(stack.getOwner(), WebsocketEndPoint.STACK,
                new StatusMessage(stackId, stack.getName(), Status.CREATE_FAILED.name(), detailedMessage));
        stackUpdater.updateStackStatusReason(stackId, detailedMessage);
        cloudbreakEventService.fireCloudbreakEvent(stackId, BillingStatus.BILLING_STOPPED.name(), "Stack creation failed.");
    }
View Full Code Here

    @Override
    public void accept(Event<StackDeleteComplete> stackDeleteComplete) {
        StackDeleteComplete data = stackDeleteComplete.getData();
        retryingStackUpdater.updateStackStatus(data.getStackId(), Status.DELETE_COMPLETED);
        cloudbreakEventService.fireCloudbreakEvent(data.getStackId(), BillingStatus.BILLING_STOPPED.name(), "Stack delete completed");
        Stack oneWithLists = stackRepository.findOneWithLists(data.getStackId());
        MDCBuilder.buildMdcContext(oneWithLists);
        LOGGER.info("Accepted {} event.", ReactorConfig.DELETE_COMPLETE_EVENT);
        stackRepository.delete(oneWithLists);
        websocketService.sendToTopicUser(oneWithLists.getOwner(), WebsocketEndPoint.TERMINATE,
                new StatusMessage(oneWithLists.getId(), oneWithLists.getName(), Status.DELETE_COMPLETED.name(), String.format("Stack delete completed")));
        retryingStackUpdater.updateStackStatusReason(oneWithLists.getId(), String.format("Stack delete completed"));
    }
View Full Code Here

    @Override
    public void accept(Event<AddInstancesComplete> event) {
        AddInstancesComplete data = event.getData();
        CloudPlatform cloudPlatform = data.getCloudPlatform();
        Long stackId = data.getStackId();
        Stack stack = stackRepository.findOneWithLists(stackId);
        Set<Resource> resourcesSet = event.getData().getResources();
        MDCBuilder.buildMdcContext(stack);
        LOGGER.info("Accepted {} event.", ReactorConfig.ADD_INSTANCES_COMPLETE_EVENT);
        if (resourcesSet != null) {
            Set<Resource> resources = stack.getResources();
            resources.addAll(resourcesSet);
            retryingStackUpdater.updateStackResources(stackId, resources);
        }
        metadataSetupContext.updateMetadata(cloudPlatform, stackId, resourcesSet);
    }
View Full Code Here

    @Autowired
    private StackRepository stackRepository;

    @Override
    public List<Resource> create(AzureProvisionContextObject po, int index, List<Resource> resources) throws Exception {
        Stack stack = stackRepository.findById(po.getStackId());
        AzureTemplate azureTemplate = (AzureTemplate) stack.getTemplate();
        AzureCredential azureCredential = (AzureCredential) stack.getCredential();
        Map<String, String> props = new HashMap<>();
        String name = filterResourcesByType(resources, ResourceType.AZURE_CLOUD_SERVICE).get(0).getResourceName();
        props.put(NAME, name);
        X509Certificate sshCert = null;
        try {
View Full Code Here

        UpdateAmbariHostsSuccess data = event.getData();
        Cluster cluster = clusterRepository.findById(data.getClusterId());
        Set<String> hostNames = data.getHostNames();
        MDCBuilder.buildMdcContext(cluster);
        LOGGER.info("Accepted {} event.", ReactorConfig.UPDATE_AMBARI_HOSTS_SUCCESS_EVENT);
        Stack stack = stackRepository.findStackWithListsForCluster(data.getClusterId());
        for (String hostName : hostNames) {
            InstanceMetaData metadataEntry = metadataRepository.findHostInStack(stack.getId(), hostName);
            if (data.isDecommision()) {
                metadataEntry.setRemovable(true);
            } else {
                metadataEntry.setRemovable(false);
            }
            metadataRepository.save(metadataEntry);
        }
        stackUpdater.updateStackStatus(stack.getId(), Status.AVAILABLE, "");
        websocketService.sendToTopicUser(cluster.getOwner(), WebsocketEndPoint.CLUSTER,
                new StatusMessage(data.getClusterId(), cluster.getName(), Status.AVAILABLE.name()));
    }
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.