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));
}
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());
}
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);
}
}
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));
}
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"));
}
Aggregations