Package com.sequenceiq.cloudbreak.domain

Examples of com.sequenceiq.cloudbreak.domain.CloudPlatform


    private ConcurrentTaskExecutor resourceBuilderExecutor;

    @Override
    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);

View Full Code Here


    private StackRepository stackRepository;

    @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

    private StackRepository stackRepository;

    @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

        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--) {
View Full Code Here

    private RetryingStackUpdater retryingStackUpdater;

    @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);
View Full Code Here

    }

    @Override
    public StackDescription getStackDescription(Stack stack) {
        MDCBuilder.buildMdcContext(stack);
        CloudPlatform cp = stack.getTemplate().cloudPlatform();
        LOGGER.debug("Getting stack description for cloud platform: {} ...", cp);
        StackDescription description = describeContext.describeStackWithResources(stack);
        LOGGER.debug("Found stack description {}", description.getClass());
        return description;
    }
View Full Code Here

    private StackRepository stackRepository;

    public StackDescription describeStackWithResources(Stack actualStack) {
        Stack stack = stackRepository.findById(actualStack.getId());
        Credential credential = stack.getCredential();
        final CloudPlatform cloudPlatform = credential.cloudPlatform();
        if (cloudPlatform.isWithTemplate()) {
            return cloudPlatformConnectors.get(cloudPlatform).describeStackWithResources(stack, stack.getCredential());
        } else {
            try {
                DetailedStackDescription dSD = new DetailedStackDescription();
                ResourceBuilderInit resourceBuilderInit = resourceBuilderInits.get(cloudPlatform);
View Full Code Here

    private CloudbreakEventService cloudbreakEventService;

    @Override
    public void accept(Event<StackStatusUpdateRequest> event) {
        StackStatusUpdateRequest statusUpdateRequest = event.getData();
        final CloudPlatform cloudPlatform = statusUpdateRequest.getCloudPlatform();

        StatusRequest statusRequest = statusUpdateRequest.getStatusRequest();
        long stackId = statusUpdateRequest.getStackId();
        Stack stack = stackRepository.findOneWithLists(stackId);
        MDCBuilder.buildMdcContext(stack);
        if (StatusRequest.STOPPED.equals(statusRequest)) {
            boolean stopped = true;
            if (cloudPlatform.isWithTemplate()) {
                CloudPlatformConnector connector = cloudPlatformConnectors.get(cloudPlatform);
                stopped = connector.stopAll(stack);
            } else {
                try {
                    ResourceBuilderInit resourceBuilderInit = resourceBuilderInits.get(cloudPlatform);
                    final StartStopContextObject sSCO = resourceBuilderInit.startStopInit(stack);

                    for (ResourceBuilder resourceBuilder : networkResourceBuilders.get(cloudPlatform)) {
                        for (Resource resource : stack.getResourcesByType(resourceBuilder.resourceType())) {
                            resourceBuilder.stop(sSCO, resource);
                        }
                    }
                    List<Future<Boolean>> futures = new ArrayList<>();
                    for (final ResourceBuilder resourceBuilder : instanceResourceBuilders.get(cloudPlatform)) {
                        List<Resource> resourceByType = stack.getResourcesByType(resourceBuilder.resourceType());
                        for (final Resource resource : resourceByType) {
                            Future<Boolean> submit = resourceBuilderExecutor.submit(new Callable<Boolean>() {
                                @Override
                                public Boolean call() throws Exception {
                                    return resourceBuilder.stop(sSCO, resource);
                                }
                            });
                            futures.add(submit);
                        }
                    }
                    for (Future<Boolean> future : futures) {
                        if (!future.get()) {
                            stopped = false;
                        }
                    }
                } catch (Exception ex) {
                    stopped = false;
                }
            }
            if (stopped) {
                LOGGER.info("Update stack state to: {}", Status.STOPPED);
                stackUpdater.updateStackStatus(stackId, Status.STOPPED);
                cloudbreakEventService.fireCloudbreakEvent(stackId, BillingStatus.BILLING_STOPPED.name(), "Stack stopped.");
            } else {
                LOGGER.info("Update stack state to: {}", Status.STOP_FAILED);
                stackUpdater.updateStackStatus(stackId, Status.STOP_FAILED);
            }
        } else {
            boolean started = true;
            if (cloudPlatform.isWithTemplate()) {
                CloudPlatformConnector connector = cloudPlatformConnectors.get(cloudPlatform);
                started = connector.startAll(stack);
            } else {
                try {
                    ResourceBuilderInit resourceBuilderInit = resourceBuilderInits.get(cloudPlatform);
View Full Code Here

    private CloudbreakEventService cloudbreakEventService;

    @Override
    public void accept(Event<ProvisionComplete> event) {
        ProvisionComplete stackCreateComplete = event.getData();
        CloudPlatform cloudPlatform = stackCreateComplete.getCloudPlatform();
        Long stackId = stackCreateComplete.getStackId();
        Stack stack = stackRepository.findById(stackId);
        MDCBuilder.buildMdcContext(stack);
        LOGGER.info("Accepted {} event on stack.", ReactorConfig.PROVISION_COMPLETE_EVENT);
        Set<Resource> resourcesSet = event.getData().getResources();
View Full Code Here

TOP

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

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.