Package com.sequenceiq.cloudbreak.service.stack.resource

Examples of com.sequenceiq.cloudbreak.service.stack.resource.ResourceBuilderInit


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


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

                        .getStatus().name()));
                stackUpdater.updateStackStatusReason(stack.getId(), stack.getStatus().name());
                if (!cloudPlatform.isWithTemplate()) {
                    stackUpdater.updateStackStatus(stack.getId(), Status.REQUESTED);
                    Set<Resource> resourceSet = new HashSet<>();
                    ResourceBuilderInit resourceBuilderInit = resourceBuilderInits.get(cloudPlatform);
                    final ProvisionContextObject pCO =
                            resourceBuilderInit.provisionInit(stack, userDataBuilder.build(cloudPlatform, stack.getHash(), userDataParams));
                    for (ResourceBuilder resourceBuilder : networkResourceBuilders.get(cloudPlatform)) {
                        List<Resource> resourceList = resourceBuilder.create(pCO, 0, new ArrayList<Resource>());
                        resourceSet.addAll(resourceList);
                        pCO.getNetworkResources().addAll(resourceList);
                    }
View Full Code Here

        if (cloudPlatform.isWithTemplate()) {
            return cloudPlatformConnectors.get(cloudPlatform).describeStackWithResources(stack, stack.getCredential());
        } else {
            try {
                DetailedStackDescription dSD = new DetailedStackDescription();
                ResourceBuilderInit resourceBuilderInit = resourceBuilderInits.get(cloudPlatform);
                final DescribeContextObject describeContextObject = resourceBuilderInit.describeInit(stack);
                for (ResourceBuilder resourceBuilder : networkResourceBuilders.get(cloudPlatform)) {
                    for (Resource resource : stack.getResourcesByType(resourceBuilder.resourceType())) {
                        Optional<String> describe = resourceBuilder.describe(resource, describeContextObject);
                        if (describe.isPresent()) {
                            dSD.getResources().add(describe.get());
View Full Code Here

        Stack stack = stackRepository.findOneWithLists(data.getStackId());
        MDCBuilder.buildMdcContext(stack);
        LOGGER.info("Accepted {} event.", ReactorConfig.DELETE_REQUEST_EVENT);
        try {
            if (!data.getCloudPlatform().isWithTemplate()) {
                ResourceBuilderInit resourceBuilderInit = resourceBuilderInits.get(data.getCloudPlatform());
                final DeleteContextObject dCO = resourceBuilderInit.deleteInit(stack);

                for (int i = instanceResourceBuilders.get(data.getCloudPlatform()).size() - 1; i >= 0; i--) {
                    List<Future<Boolean>> futures = new ArrayList<>();
                    final int index = i;
                    List<Resource> resourceByType = stack.getResourcesByType(instanceResourceBuilders.get(data.getCloudPlatform()).get(i).resourceType());
View Full Code Here

            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);
                    final StartStopContextObject sSCO = resourceBuilderInit.startStopInit(stack);

                    for (ResourceBuilder resourceBuilder : networkResourceBuilders.get(cloudPlatform)) {
                        for (Resource resource : stack.getResourcesByType(resourceBuilder.resourceType())) {
                            resourceBuilder.start(sSCO, resource);
                        }
View Full Code Here

TOP

Related Classes of com.sequenceiq.cloudbreak.service.stack.resource.ResourceBuilderInit

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.