Search in sources :

Example 16 with InstanceGroup

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

the class StackUpscaleService method finishExtendMetadata.

@Transactional
public Set<String> finishExtendMetadata(Stack stack, String instanceGroupName, CollectMetadataResult payload) {
    List<CloudVmMetaDataStatus> coreInstanceMetaData = payload.getResults();
    int newinstances = metadataSetupService.saveInstanceMetaData(stack, coreInstanceMetaData, CREATED);
    Set<String> upscaleCandidateAddresses = new HashSet<>();
    for (CloudVmMetaDataStatus cloudVmMetaDataStatus : coreInstanceMetaData) {
        upscaleCandidateAddresses.add(cloudVmMetaDataStatus.getMetaData().getPrivateIp());
    }
    InstanceGroup instanceGroup = instanceGroupRepository.findOneByGroupNameInStack(stack.getId(), instanceGroupName);
    int nodeCount = instanceGroup.getNodeCount() + newinstances;
    if (newinstances != 0) {
        instanceGroup.setNodeCount(nodeCount);
        instanceGroupRepository.save(instanceGroup);
    }
    clusterService.updateClusterStatusByStackIdOutOfTransaction(stack.getId(), AVAILABLE);
    eventService.fireCloudbreakEvent(stack.getId(), BillingStatus.BILLING_CHANGED.name(), messagesService.getMessage("stack.metadata.setup.billing.changed"));
    flowMessageService.fireEventAndLog(stack.getId(), Msg.STACK_METADATA_EXTEND, AVAILABLE.name());
    usageService.scaleUsagesForStack(stack.getId(), instanceGroupName, nodeCount);
    return upscaleCandidateAddresses;
}
Also used : CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) HashSet(java.util.HashSet) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Transactional(org.springframework.transaction.annotation.Transactional)

Example 17 with InstanceGroup

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

the class StackUpscaleActions method addInstances.

@Bean(name = "ADD_INSTANCES_STATE")
public Action<?, ?> addInstances() {
    return new AbstractStackUpscaleAction<StackScaleTriggerEvent>(StackScaleTriggerEvent.class) {

        @Override
        protected void prepareExecution(StackScaleTriggerEvent payload, Map<Object, Object> variables) {
            variables.put(INSTANCEGROUPNAME, payload.getInstanceGroup());
            variables.put(ADJUSTMENT, payload.getAdjustment());
            variables.put(HOSTNAMES, payload.getHostNames());
        }

        @Override
        protected void doExecute(StackScalingFlowContext context, StackScaleTriggerEvent payload, Map<Object, Object> variables) {
            stackUpscaleService.startAddInstances(context.getStack(), payload.getAdjustment());
            sendEvent(context);
        }

        @Override
        protected Selectable createRequest(StackScalingFlowContext context) {
            LOGGER.debug("Assembling upscale stack event for stack: {}", context.getStack());
            InstanceGroup group = context.getStack().getInstanceGroupByInstanceGroupName(context.getInstanceGroupName());
            group.setNodeCount(group.getNodeCount() + context.getAdjustment());
            CloudStack cloudStack = cloudStackConverter.convert(context.getStack());
            instanceMetadataService.saveInstanceRequests(context.getStack(), cloudStack.getGroups());
            List<CloudResource> resources = cloudResourceConverter.convert(context.getStack().getResources());
            return new UpscaleStackRequest<UpscaleStackResult>(context.getCloudContext(), context.getCloudCredential(), cloudStack, resources);
        }
    };
}
Also used : StackScaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackScaleTriggerEvent) UpscaleStackRequest(com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Map(java.util.Map) StackScalingFlowContext(com.sequenceiq.cloudbreak.core.flow2.stack.downscale.StackScalingFlowContext) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Bean(org.springframework.context.annotation.Bean)

Example 18 with InstanceGroup

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

the class StackUpscaleActions method finishExtendMetadata.

@Bean(name = "EXTEND_METADATA_FINISHED_STATE")
public Action<?, ?> finishExtendMetadata() {
    return new AbstractStackUpscaleAction<CollectMetadataResult>(CollectMetadataResult.class) {

        @Override
        protected void doExecute(StackScalingFlowContext context, CollectMetadataResult payload, Map<Object, Object> variables) {
            Set<String> upscaleCandidateAddresses = stackUpscaleService.finishExtendMetadata(context.getStack(), context.getInstanceGroupName(), payload);
            variables.put(UPSCALE_CANDIDATE_ADDRESSES, upscaleCandidateAddresses);
            InstanceGroup ig = instanceGroupRepository.findOneByGroupNameInStack(payload.getStackId(), context.getInstanceGroupName());
            if (InstanceGroupType.GATEWAY == ig.getInstanceGroupType()) {
                InstanceMetaData gatewayMetaData = context.getStack().getPrimaryGatewayInstance();
                CloudInstance gatewayInstance = metadataConverter.convert(gatewayMetaData);
                Selectable sshFingerPrintReq = new GetSSHFingerprintsRequest<GetSSHFingerprintsResult>(context.getCloudContext(), context.getCloudCredential(), gatewayInstance);
                sendEvent(context.getFlowId(), sshFingerPrintReq);
            } else {
                BootstrapNewNodesEvent bootstrapPayload = new BootstrapNewNodesEvent(context.getStack().getId(), upscaleCandidateAddresses);
                sendEvent(context.getFlowId(), StackUpscaleEvent.BOOTSTRAP_NEW_NODES_EVENT.event(), bootstrapPayload);
            }
        }
    };
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) GetSSHFingerprintsRequest(com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsRequest) Selectable(com.sequenceiq.cloudbreak.cloud.event.Selectable) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CollectMetadataResult(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult) Map(java.util.Map) StackScalingFlowContext(com.sequenceiq.cloudbreak.core.flow2.stack.downscale.StackScalingFlowContext) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Bean(org.springframework.context.annotation.Bean)

Example 19 with InstanceGroup

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

the class DependecyDeletionService method deleteDependencies.

public void deleteDependencies(Stack stack) {
    deleteNetwork(stack.getNetwork());
    deleteCredential(stack.getCredential());
    for (InstanceGroup instanceGroup : stack.getInstanceGroups()) {
        deleteSecurityGroup(instanceGroup.getSecurityGroup());
        deleteTemplate(instanceGroup.getTemplate());
    }
    if (stack.getCluster() != null) {
        Cluster cluster = stack.getCluster();
        deleteBlueprint(cluster.getBlueprint());
        Set<HostGroup> hostGroupsInCluster = hostGroupRepository.findHostGroupsInCluster(cluster.getId());
        for (HostGroup hostGroup : hostGroupsInCluster) {
            hostGroup.getRecipes().forEach(this::deleteRecipe);
        }
    }
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.Cluster) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup)

Example 20 with InstanceGroup

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

the class TestUtil method generateGcpInstanceGroups.

public static Set<InstanceGroup> generateGcpInstanceGroups(int count) {
    Set<InstanceGroup> instanceGroups = new HashSet<>();
    instanceGroups.add(instanceGroup(1L, InstanceGroupType.GATEWAY, openstackTemplate(1L)));
    for (int i = 2; i < count + 1; i++) {
        instanceGroups.add(instanceGroup(Integer.toUnsignedLong(i), InstanceGroupType.CORE, openstackTemplate(1L)));
    }
    return instanceGroups;
}
Also used : Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) Constraint(com.sequenceiq.cloudbreak.domain.Constraint) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) HashSet(java.util.HashSet)

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