Search in sources :

Example 51 with InstanceGroup

use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.

the class StackCreatorService method createStack.

public StackResponse createStack(IdentityUser user, StackRequest stackRequest, boolean publicInAccount) throws Exception {
    stackRequest.setAccount(user.getAccount());
    stackRequest.setOwner(user.getUserId());
    stackRequest.setOwnerEmail(user.getUsername());
    long start = System.currentTimeMillis();
    Stack stack = conversionService.convert(stackRequest, Stack.class);
    String stackName = stack.getName();
    LOGGER.info("Stack request converted to stack in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
    MDCBuilder.buildMdcContext(stack);
    start = System.currentTimeMillis();
    stack = stackSensitiveDataPropagator.propagate(stackRequest.getCredentialSource(), stack, user);
    LOGGER.info("Stack propagated with sensitive data in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
    start = System.currentTimeMillis();
    stack = stackDecorator.decorate(stack, stackRequest, user);
    LOGGER.info("Stack object has been decorated in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
    stack.setPublicInAccount(publicInAccount);
    start = System.currentTimeMillis();
    validateAccountPreferences(stack, user);
    LOGGER.info("Account preferences has been validated in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
    if (stack.getOrchestrator() != null && stack.getOrchestrator().getApiEndpoint() != null) {
        stackService.validateOrchestrator(stack.getOrchestrator());
    }
    for (InstanceGroup instanceGroup : stack.getInstanceGroups()) {
        templateValidator.validateTemplateRequest(stack.getCredential(), instanceGroup.getTemplate(), stack.getRegion(), stack.getAvailabilityZone(), stack.getPlatformVariant());
    }
    Blueprint blueprint = null;
    if (stackRequest.getClusterRequest() != null) {
        start = System.currentTimeMillis();
        StackValidationRequest stackValidationRequest = conversionService.convert(stackRequest, StackValidationRequest.class);
        LOGGER.info("Stack validation request has been created in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        start = System.currentTimeMillis();
        StackValidation stackValidation = conversionService.convert(stackValidationRequest, StackValidation.class);
        LOGGER.info("Stack validation object has been created in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        blueprint = stackValidation.getBlueprint();
        start = System.currentTimeMillis();
        stackService.validateStack(stackValidation, stackRequest.getClusterRequest().getValidateBlueprint());
        LOGGER.info("Stack has been validated in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        CloudCredential cloudCredential = credentialToCloudCredentialConverter.convert(stack.getCredential());
        start = System.currentTimeMillis();
        fileSystemValidator.validateFileSystem(stackValidationRequest.getPlatform(), cloudCredential, stackValidationRequest.getFileSystem());
        LOGGER.info("Filesystem has been validated in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        start = System.currentTimeMillis();
        clusterCreationService.validate(stackRequest.getClusterRequest(), cloudCredential, stack, user);
        LOGGER.info("Cluster has been validated in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
    }
    start = System.currentTimeMillis();
    stack = stackService.create(user, stack, stackRequest.getImageCatalog(), Optional.ofNullable(stackRequest.getImageId()), Optional.ofNullable(blueprint));
    LOGGER.info("Stack object and its dependencies has been created in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
    createClusterIfNeed(user, stackRequest, stack, stackName, blueprint);
    start = System.currentTimeMillis();
    StackResponse response = conversionService.convert(stack, StackResponse.class);
    LOGGER.info("Stack response has been created in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
    start = System.currentTimeMillis();
    flowManager.triggerProvisioning(stack.getId());
    LOGGER.info("Stack provision triggered in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
    return response;
}
Also used : StackValidationRequest(com.sequenceiq.cloudbreak.api.model.StackValidationRequest) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) StackValidation(com.sequenceiq.cloudbreak.domain.StackValidation) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse) Stack(com.sequenceiq.cloudbreak.domain.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup)

Example 52 with InstanceGroup

use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.

the class NetworkConfigurationValidator method validateNetworkForStack.

public boolean validateNetworkForStack(Network network, Iterable<InstanceGroup> instanceGroups) {
    if (network.getSubnetCIDR() != null) {
        SubnetUtils utils = new SubnetUtils(network.getSubnetCIDR());
        int addressCount = utils.getInfo().getAddressCount();
        int nodeCount = 0;
        for (InstanceGroup instanceGroup : instanceGroups) {
            nodeCount += instanceGroup.getNodeCount();
        }
        if (addressCount < nodeCount) {
            LOGGER.error("Cannot assign more than {} addresses in the selected subnet.", addressCount);
            throw new BadRequestException(String.format("Cannot assign more than %s addresses in the selected subnet.", addressCount));
        }
    }
    return true;
}
Also used : SubnetUtils(org.apache.commons.net.util.SubnetUtils) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup)

Example 53 with InstanceGroup

use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.

the class StackDownscaleActions method stackDownscaleCollectResourcesAction.

@Bean(name = "DOWNSCALE_COLLECT_RESOURCES_STATE")
public Action<?, ?> stackDownscaleCollectResourcesAction() {
    return new AbstractStackDownscaleAction<StackDownscaleTriggerEvent>(StackDownscaleTriggerEvent.class) {

        @Override
        protected void doExecute(StackScalingFlowContext context, StackDownscaleTriggerEvent payload, Map<Object, Object> variables) {
            stackDownscaleService.startStackDownscale(context, payload);
            Stack stack = context.getStack();
            LOGGER.debug("Assembling downscale stack event for stack: {}", stack);
            List<CloudResource> resources = cloudResourceConverter.convert(stack.getResources());
            variables.put(RESOURCES, resources);
            List<CloudInstance> instances = new ArrayList<>();
            InstanceGroup group = stack.getInstanceGroupByInstanceGroupName(context.getInstanceGroupName());
            for (InstanceMetaData metaData : group.getAllInstanceMetaData()) {
                if (context.getInstanceIds().contains(metaData.getInstanceId())) {
                    CloudInstance cloudInstance = metadataConverter.convert(metaData);
                    instances.add(cloudInstance);
                }
            }
            variables.put(INSTANCES, instances);
            Selectable request = new DownscaleStackCollectResourcesRequest(context.getCloudContext(), context.getCloudCredential(), context.getCloudStack(), resources, instances);
            sendEvent(context.getFlowId(), request);
        }
    };
}
Also used : DownscaleStackCollectResourcesRequest(com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackCollectResourcesRequest) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Stack(com.sequenceiq.cloudbreak.domain.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) Selectable(com.sequenceiq.cloudbreak.cloud.event.Selectable) StackDownscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackDownscaleTriggerEvent) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 54 with InstanceGroup

use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.

the class AccountPreferencesValidatorTest method testValidateShouldNotThrowExceptionWhenTheStackContainsOnlyAllowedInstanceTypes.

@Test
public void testValidateShouldNotThrowExceptionWhenTheStackContainsOnlyAllowedInstanceTypes() throws AccountPreferencesValidationException {
    String n1St4Type = "n1-standard-4";
    String n1St6Type = "n1-standard-8";
    List<String> allowedInstanceTypes = Arrays.asList(n1St4Type, n1St6Type, "n1-standard-16");
    when(preferences.getAllowedInstanceTypes()).thenReturn(allowedInstanceTypes);
    InstanceGroup cbgateway = Mockito.mock(InstanceGroup.class, Mockito.RETURNS_DEEP_STUBS);
    InstanceGroup master = Mockito.mock(InstanceGroup.class, Mockito.RETURNS_DEEP_STUBS);
    InstanceGroup slave = Mockito.mock(InstanceGroup.class, Mockito.RETURNS_DEEP_STUBS);
    when(cbgateway.getTemplate().getInstanceType()).thenReturn(n1St4Type);
    when(master.getTemplate().getInstanceType()).thenReturn(n1St4Type);
    when(slave.getTemplate().getInstanceType()).thenReturn(n1St6Type);
    when(stack.getInstanceGroups()).thenReturn(Sets.newHashSet(cbgateway, master, slave));
    underTest.validate(stack, EMPTY_STRING, EMPTY_STRING);
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Test(org.junit.Test)

Example 55 with InstanceGroup

use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.

the class ComponentLocatorServiceTest method createHostGroup.

private HostGroup createHostGroup(String name, String hostname) {
    HostGroup hg = new HostGroup();
    hg.setName(name);
    Constraint constraint = new Constraint();
    hg.setConstraint(constraint);
    InstanceGroup ig = new InstanceGroup();
    constraint.setInstanceGroup(ig);
    InstanceMetaData im = new InstanceMetaData();
    im.setDiscoveryFQDN(hostname);
    ig.setInstanceMetaData(ImmutableSet.of(im));
    return hg;
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) Constraint(com.sequenceiq.cloudbreak.domain.Constraint) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup)

Aggregations

InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)89 Test (org.junit.Test)32 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)27 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)27 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)24 HashSet (java.util.HashSet)16 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 Stack (com.sequenceiq.cloudbreak.domain.Stack)14 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)9 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)8 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)8 Constraint (com.sequenceiq.cloudbreak.domain.Constraint)8 Matchers.anyString (org.mockito.Matchers.anyString)8 Orchestrator (com.sequenceiq.cloudbreak.domain.Orchestrator)6 StackAuthentication (com.sequenceiq.cloudbreak.domain.StackAuthentication)6 Template (com.sequenceiq.cloudbreak.domain.Template)6 ArrayList (java.util.ArrayList)6 InstanceGroupRequest (com.sequenceiq.cloudbreak.api.model.InstanceGroupRequest)5 StackAuthenticationRequest (com.sequenceiq.cloudbreak.api.model.StackAuthenticationRequest)5 FailurePolicy (com.sequenceiq.cloudbreak.domain.FailurePolicy)5