Search in sources :

Example 1 with NetworkScaleDetails

use of com.sequenceiq.cloudbreak.core.flow2.dto.NetworkScaleDetails in project cloudbreak by hortonworks.

the class StackUpscaleActionsTest method prevalidateTestCreateContextWhenTriggeredVariantNotSet.

@Test
void prevalidateTestCreateContextWhenTriggeredVariantNotSet() {
    NetworkScaleDetails networkScaleDetails = new NetworkScaleDetails();
    UpdateDomainDnsResolverResult payload = new UpdateDomainDnsResolverResult(STACK_ID);
    Map<Object, Object> variables = createVariables(Map.of(INSTANCE_GROUP_NAME, ADJUSTMENT_ZERO), Map.of(INSTANCE_GROUP_NAME, Set.of("hostname")), networkScaleDetails, null, null);
    new AbstractActionTestSupport<>(getPrevalidateAction()).prepareExecution(payload, variables);
    Assertions.assertEquals(Map.of(INSTANCE_GROUP_NAME, ADJUSTMENT_ZERO), variables.get(HOST_GROUP_WITH_ADJUSTMENT));
    Assertions.assertEquals(Map.of(INSTANCE_GROUP_NAME, Set.of("hostname")), variables.get(HOST_GROUP_WITH_HOSTNAMES));
    Assertions.assertEquals(false, variables.get(REPAIR));
    Assertions.assertNull(variables.get(TRIGGERED_VARIANT));
    Assertions.assertEquals(networkScaleDetails, variables.get(NETWORK_SCALE_DETAILS));
}
Also used : NetworkScaleDetails(com.sequenceiq.cloudbreak.core.flow2.dto.NetworkScaleDetails) UpdateDomainDnsResolverResult(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverResult) Test(org.junit.jupiter.api.Test)

Example 2 with NetworkScaleDetails

use of com.sequenceiq.cloudbreak.core.flow2.dto.NetworkScaleDetails in project cloudbreak by hortonworks.

the class MultiAzCalculatorServiceTest method calculateByRoundRobinTestWhenCloudInstanceAndPreferredAvailabilityZones.

@ParameterizedTest(name = "calculateByRoundRobinTestWhenCloudInstance " + "with {0} platform when {1} subnets, {2} instances, {3} subnet counts and preferred subnets {6} should result in {5} subnet / AZ")
@MethodSource("calculateByRoundRobinTestWhenCloudInstanceDataAndPreferredAvailabilityZones")
public void calculateByRoundRobinTestWhenCloudInstanceAndPreferredAvailabilityZones(CloudPlatform cloudPlatform, int subnetCount, int instanceCount, List<Integer> existingCounts, boolean supported, Set<Integer> expectedPermissibleSubnetIdIndexes, Set<Integer> preferredSubnetIdIndexes) {
    if (supported) {
        when(multiAzValidator.supportedForInstanceMetadataGeneration(any(InstanceGroup.class))).thenReturn(true);
    }
    InstanceGroup instanceGroup = instanceGroup(cloudPlatform, instanceCount, subnetCount);
    initSubnetIdAndAvailabilityZoneForInstances(existingCounts, instanceGroup);
    InstanceMetaData instanceMetaData = new InstanceMetaData();
    List<String> preferredSubnetIds = preferredSubnetIdIndexes.stream().map(index -> cloudSubnet(index).getName()).collect(Collectors.toList());
    NetworkScaleDetails networkScaleDetails = new NetworkScaleDetails(preferredSubnetIds);
    underTest.calculateByRoundRobin(subnetAzPairs(subnetCount), instanceGroup, instanceMetaData, networkScaleDetails);
    verifyCloudInstance(expectedPermissibleSubnetIdIndexes, instanceMetaData);
    verifySubnetIdAndAvailabilityZoneForInstancesAreUnchanged(existingCounts, instanceGroup, Set.of());
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Arrays(java.util.Arrays) Mock(org.mockito.Mock) EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Map(java.util.Map) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) InstanceGroupNetwork(com.sequenceiq.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork) MethodSource(org.junit.jupiter.params.provider.MethodSource) InjectMocks(org.mockito.InjectMocks) NetworkScaleDetails(com.sequenceiq.cloudbreak.core.flow2.dto.NetworkScaleDetails) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) MultiAzValidator(com.sequenceiq.cloudbreak.controller.validation.network.MultiAzValidator) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) Set(java.util.Set) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) Json(com.sequenceiq.cloudbreak.common.json.Json) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CollectionUtils(org.springframework.util.CollectionUtils) Assertions(org.junit.jupiter.api.Assertions) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) Queue(java.util.Queue) ArrayDeque(java.util.ArrayDeque) NetworkConstants(com.sequenceiq.cloudbreak.common.network.NetworkConstants) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Collections(java.util.Collections) NetworkScaleDetails(com.sequenceiq.cloudbreak.core.flow2.dto.NetworkScaleDetails) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with NetworkScaleDetails

use of com.sequenceiq.cloudbreak.core.flow2.dto.NetworkScaleDetails in project cloudbreak by hortonworks.

the class AbstractStackUpscaleAction method createFlowContext.

@Override
protected StackScalingFlowContext createFlowContext(FlowParameters flowParameters, StateContext<StackUpscaleState, StackUpscaleEvent> stateContext, P payload) {
    Map<Object, Object> variables = stateContext.getExtendedState().getVariables();
    Stack stack = stackService.getByIdWithListsInTransaction(payload.getResourceId());
    stack.setResources(new HashSet<>(resourceService.getAllByStackId(payload.getResourceId())));
    MDCBuilder.buildMdcContext(stack);
    Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
    CloudContext cloudContext = CloudContext.Builder.builder().withId(stack.getId()).withName(stack.getName()).withCrn(stack.getResourceCrn()).withPlatform(stack.getCloudPlatform()).withVariant(getTriggeredVariantOrStackVariant(variables, stack)).withLocation(location).withWorkspaceId(stack.getWorkspace().getId()).withAccountId(Crn.safeFromString(stack.getResourceCrn()).getAccountId()).withTenantId(stack.getTenant().getId()).build();
    CloudCredential cloudCredential = stackUtil.getCloudCredential(stack);
    CloudStack cloudStack = cloudStackConverter.convert(stack);
    if (payload instanceof StackScaleTriggerEvent) {
        StackScaleTriggerEvent stackScaleTriggerEvent = (StackScaleTriggerEvent) payload;
        boolean repair = stackScaleTriggerEvent.isRepair();
        Map<String, Set<String>> hostgroupsWithHostnames = stackScaleTriggerEvent.getHostGroupsWithHostNames();
        Map<String, Integer> hostGroupsWithAdjustment = stackScaleTriggerEvent.getHostGroupsWithAdjustment();
        Map<String, Set<Long>> hostGroupsWithPrivateIds = stackScaleTriggerEvent.getHostGroupsWithPrivateIds();
        NetworkScaleDetails networkScaleDetails = stackScaleTriggerEvent.getNetworkScaleDetails();
        AdjustmentTypeWithThreshold adjustmentTypeWithThreshold = stackScaleTriggerEvent.getAdjustmentTypeWithThreshold();
        variables.put(REPAIR, repair);
        variables.put(HOST_GROUP_WITH_ADJUSTMENT, hostGroupsWithAdjustment);
        variables.put(HOST_GROUP_WITH_HOSTNAMES, hostgroupsWithHostnames);
        variables.put(NETWORK_SCALE_DETAILS, networkScaleDetails);
        variables.put(ADJUSTMENT_WITH_THRESHOLD, adjustmentTypeWithThreshold);
        return new StackScalingFlowContext(flowParameters, stack, cloudContext, cloudCredential, cloudStack, hostGroupsWithAdjustment, hostGroupsWithPrivateIds, hostgroupsWithHostnames, repair, networkScaleDetails, adjustmentTypeWithThreshold);
    } else {
        Map<String, Integer> hostGroupWithAdjustment = getHostGroupWithAdjustment(variables);
        Map<String, Set<String>> hostgroupWithHostnames = getHostGroupWithHostnames(variables);
        NetworkScaleDetails stackNetworkScaleDetails = getStackNetworkScaleDetails(variables);
        AdjustmentTypeWithThreshold adjustmentWithThreshold = getAdjustmentWithThreshold(variables);
        return new StackScalingFlowContext(flowParameters, stack, cloudContext, cloudCredential, cloudStack, hostGroupWithAdjustment, null, hostgroupWithHostnames, isRepair(variables), stackNetworkScaleDetails, adjustmentWithThreshold);
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) StackScaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackScaleTriggerEvent) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) NetworkScaleDetails(com.sequenceiq.cloudbreak.core.flow2.dto.NetworkScaleDetails) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) StackScalingFlowContext(com.sequenceiq.cloudbreak.core.flow2.stack.downscale.StackScalingFlowContext) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Example 4 with NetworkScaleDetails

use of com.sequenceiq.cloudbreak.core.flow2.dto.NetworkScaleDetails in project cloudbreak by hortonworks.

the class StackUpscaleActionsTest method prevalidateTestCreateContextWhenTriggeredVariantSet.

@Test
void prevalidateTestCreateContextWhenTriggeredVariantSet() {
    NetworkScaleDetails networkScaleDetails = new NetworkScaleDetails();
    UpdateDomainDnsResolverResult payload = new UpdateDomainDnsResolverResult(STACK_ID);
    Map<Object, Object> variables = createVariables(Map.of(INSTANCE_GROUP_NAME, ADJUSTMENT_ZERO), Map.of(INSTANCE_GROUP_NAME, Set.of("hostname")), networkScaleDetails, null, VARIANT);
    new AbstractActionTestSupport<>(getPrevalidateAction()).prepareExecution(payload, variables);
    Assertions.assertEquals(Map.of(INSTANCE_GROUP_NAME, ADJUSTMENT_ZERO), variables.get(HOST_GROUP_WITH_ADJUSTMENT));
    Assertions.assertEquals(Map.of(INSTANCE_GROUP_NAME, Set.of("hostname")), variables.get(HOST_GROUP_WITH_HOSTNAMES));
    Assertions.assertEquals(false, variables.get(REPAIR));
    Assertions.assertEquals(VARIANT, variables.get(TRIGGERED_VARIANT));
    Assertions.assertEquals(networkScaleDetails, variables.get(NETWORK_SCALE_DETAILS));
}
Also used : NetworkScaleDetails(com.sequenceiq.cloudbreak.core.flow2.dto.NetworkScaleDetails) UpdateDomainDnsResolverResult(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverResult) Test(org.junit.jupiter.api.Test)

Example 5 with NetworkScaleDetails

use of com.sequenceiq.cloudbreak.core.flow2.dto.NetworkScaleDetails in project cloudbreak by hortonworks.

the class InstanceMetadataServiceComponentTest method saveInstanceAndGetUpdatedStackWhenPreferredSubnetSet.

@Test
public void saveInstanceAndGetUpdatedStackWhenPreferredSubnetSet() {
    DetailedEnvironmentResponse detailedEnvResponse = DetailedEnvironmentResponse.builder().withCrn(ENV_CRN).withNetwork(EnvironmentNetworkResponse.builder().withSubnetMetas(Map.of("sub1", cloudSubnet("az", "sub1"), "sub2", cloudSubnet("az", "sub2"), "sub3", cloudSubnet("az", "sub3"), "sub4", cloudSubnet("az1", "sub4"))).build()).build();
    Stack stack = new Stack();
    stack.setEnvironmentCrn(ENV_CRN);
    InstanceGroup workerInstanceGroup = new InstanceGroup();
    workerInstanceGroup.setGroupName("worker");
    InstanceGroupNetwork instanceGroupNetwork = new InstanceGroupNetwork();
    instanceGroupNetwork.setCloudPlatform("AWS");
    instanceGroupNetwork.setAttributes(new Json(Map.of(SUBNET_IDS, List.of("sub1", "sub2", "sub3", "sub4"))));
    workerInstanceGroup.setInstanceGroupNetwork(instanceGroupNetwork);
    stack.setInstanceGroups(Set.of(workerInstanceGroup));
    when(environmentClientService.getByCrn(ENV_CRN)).thenReturn(detailedEnvResponse);
    NetworkScaleDetails networkScaleDetails = new NetworkScaleDetails(List.of("sub1", "sub2"));
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn:cdp:freeipa:us-west-1:altus:user:__internal__actor__");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    instanceMetaDataService.saveInstanceAndGetUpdatedStack(stack, Map.of("worker", 42), Map.of(), false, false, networkScaleDetails);
    Map<String, List<InstanceMetaData>> groupBySub = workerInstanceGroup.getInstanceMetaDataSet().stream().collect(Collectors.groupingBy(InstanceMetaData::getSubnetId, Collectors.mapping(Function.identity(), Collectors.toList())));
    Map<String, List<InstanceMetaData>> groupByAz = workerInstanceGroup.getInstanceMetaDataSet().stream().collect(Collectors.groupingBy(InstanceMetaData::getAvailabilityZone, Collectors.mapping(Function.identity(), Collectors.toList())));
    Assertions.assertEquals(1, groupByAz.size());
    Assertions.assertEquals(42, groupByAz.get("az").size());
    Assertions.assertNull(groupByAz.get("az1"));
    Assertions.assertEquals(2, groupBySub.size());
    Assertions.assertEquals(21, groupBySub.get("sub1").size());
    Assertions.assertEquals(21, groupBySub.get("sub2").size());
    Assertions.assertNull(groupBySub.get("sub3"));
    Assertions.assertNull(groupBySub.get("sub4"));
}
Also used : DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) List(java.util.List) Json(com.sequenceiq.cloudbreak.common.json.Json) NetworkScaleDetails(com.sequenceiq.cloudbreak.core.flow2.dto.NetworkScaleDetails) InstanceGroupNetwork(com.sequenceiq.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

NetworkScaleDetails (com.sequenceiq.cloudbreak.core.flow2.dto.NetworkScaleDetails)5 Test (org.junit.jupiter.api.Test)4 Json (com.sequenceiq.cloudbreak.common.json.Json)2 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)2 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)2 InstanceGroupNetwork (com.sequenceiq.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork)2 UpdateDomainDnsResolverResult (com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverResult)2 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Set (java.util.Set)2 InstanceStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus)1 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)1 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)1 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)1 Location (com.sequenceiq.cloudbreak.cloud.model.Location)1 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)1 CloudPlatform (com.sequenceiq.cloudbreak.common.mappable.CloudPlatform)1 NetworkConstants (com.sequenceiq.cloudbreak.common.network.NetworkConstants)1