use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request in project cloudbreak by hortonworks.
the class InstanceGroupV1ToInstanceGroupV4ConverterTest method createSecurityGroupFromEnvironmentTestForConvertTo.
// CHECKSTYLE:ON
// @formatter:on
@ParameterizedTest(name = "{0}")
@MethodSource("securityAccessDataProviderForConvertTo")
void createSecurityGroupFromEnvironmentTestForConvertTo(String testCaseName, InstanceGroupType instanceGroupType, boolean environmentSet, boolean securityAccessSet, String cidr, String defaultSecurityGroupId, String securityGroupIdKnox, boolean securityGroupExpected, boolean cidrExpected, Set<String> expectedSecurityGroups) {
when(instanceGroupParameterConverter.convert(AWS_INSTANCE_GROUP_V1_PARAMETERS)).thenReturn(AWS_INSTANCE_GROUP_V4_PARAMETERS);
DetailedEnvironmentResponse environment = environmentSet ? prepareEnvironment(securityAccessSet, cidr, defaultSecurityGroupId, securityGroupIdKnox) : null;
if (environmentSet) {
when(instanceTemplateConverter.convert(any(InstanceTemplateV1Request.class), eq(environment))).thenReturn(INSTANCE_TEMPLATE_V4_REQUEST);
}
Set<InstanceGroupV1Request> instanceGroups = prepareInstanceGroupV1Requests(instanceGroupType);
List<InstanceGroupV4Request> results = underTest.convertTo(null, instanceGroups, environment);
assertThat(results).hasSameSizeAs(instanceGroups);
InstanceGroupV4Request first = results.get(0);
assertThat(first.getType()).isEqualTo(instanceGroupType);
SecurityGroupV4Request securityGroup = first.getSecurityGroup();
assertThat(securityGroup != null).isEqualTo(securityGroupExpected);
if (securityGroupExpected) {
if (securityGroup.getSecurityGroupIds() != null) {
assertThat(securityGroup.getSecurityGroupIds()).hasSameElementsAs(expectedSecurityGroups);
assertThat(securityGroup.getSecurityRules()).usingFieldByFieldElementComparator().hasSameElementsAs(cidrExpected ? List.of(generateRule(instanceGroupType, cidr)) : List.of());
}
}
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request in project cloudbreak by hortonworks.
the class InstanceGroupV1ToInstanceGroupV4ConverterTest method createSecurityGroupFromEnvironmentTestForConvertFrom.
// CHECKSTYLE:ON
// @formatter:on
@ParameterizedTest(name = "{0}")
@MethodSource("securityAccessDataProviderForConvertFrom")
void createSecurityGroupFromEnvironmentTestForConvertFrom(String testCaseName, InstanceGroupType instanceGroupType) {
when(instanceGroupParameterConverter.convert(AWS_INSTANCE_GROUP_V4_PARAMETERS)).thenReturn(AWS_INSTANCE_GROUP_V1_PARAMETERS);
List<InstanceGroupV4Request> instanceGroups = prepareInstanceGroupV4Requests(instanceGroupType);
Set<InstanceGroupV1Request> results = underTest.convertFrom(null, instanceGroups, null);
assertThat(results).hasSameSizeAs(instanceGroups);
InstanceGroupV1Request first = results.iterator().next();
assertThat(first.getType()).isEqualTo(instanceGroupType);
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request in project cloudbreak by hortonworks.
the class InstanceGroupV1ToInstanceGroupV4ConverterTest method convertFromAwsWithoutSecurityGroupsHappyPathTest.
@Test
void convertFromAwsWithoutSecurityGroupsHappyPathTest() {
when(instanceGroupParameterConverter.convert(AWS_INSTANCE_GROUP_V4_PARAMETERS)).thenReturn(AWS_INSTANCE_GROUP_V1_PARAMETERS);
when(instanceTemplateConverter.convert(any(InstanceTemplateV4Request.class), any())).thenReturn(INSTANCE_TEMPLATE_V1_REQUEST);
List<InstanceGroupV4Request> instanceGroups = prepareInstanceGroupV4Requests(InstanceGroupType.CORE);
DetailedEnvironmentResponse environment = new DetailedEnvironmentResponse();
Set<InstanceGroupV1Request> results = underTest.convertFrom(null, instanceGroups, environment);
assertThat(results).hasSameSizeAs(instanceGroups);
InstanceGroupV1Request first = results.iterator().next();
assertThat(first.getAws()).isEqualTo(AWS_INSTANCE_GROUP_V1_PARAMETERS);
assertThat(first.getCloudPlatform()).isEqualTo(CloudPlatform.AWS);
assertThat(first.getName()).isEqualTo(INSTANCE_GROUP_NAME);
assertThat(first.getNodeCount()).isEqualTo(NODE_COUNT_1);
assertThat(first.getRecipeNames()).isEqualTo(RECIPE_NAMES);
assertThat(first.getRecoveryMode()).isEqualTo(RecoveryMode.AUTO);
assertThat(first.getTemplate()).isEqualTo(INSTANCE_TEMPLATE_V1_REQUEST);
assertThat(first.getType()).isEqualTo(InstanceGroupType.CORE);
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request in project cloudbreak by hortonworks.
the class InstanceGroupV1ToInstanceGroupV4ConverterTest method convertToAwsWithoutEnvironmentHappyPathTest.
@Test
void convertToAwsWithoutEnvironmentHappyPathTest() {
NetworkV4Request networkV4Request = getNetworkV4Request();
when(instanceGroupParameterConverter.convert(AWS_INSTANCE_GROUP_V1_PARAMETERS)).thenReturn(AWS_INSTANCE_GROUP_V4_PARAMETERS);
Set<InstanceGroupV1Request> instanceGroups = prepareInstanceGroupV1Requests(InstanceGroupType.CORE);
List<InstanceGroupV4Request> results = underTest.convertTo(networkV4Request, instanceGroups, null);
assertThat(results).hasSameSizeAs(instanceGroups);
InstanceGroupV4Request first = results.get(0);
assertThat(first.getAws()).isEqualTo(AWS_INSTANCE_GROUP_V4_PARAMETERS);
assertThat(first.getCloudPlatform()).isEqualTo(CloudPlatform.AWS);
assertThat(first.getName()).isEqualTo(INSTANCE_GROUP_NAME);
assertThat(first.getNodeCount()).isEqualTo(NODE_COUNT_1);
assertThat(first.getRecipeNames()).isEqualTo(RECIPE_NAMES);
assertThat(first.getRecoveryMode()).isEqualTo(RecoveryMode.AUTO);
assertThat(first.getTemplate()).isNull();
assertThat(first.getType()).isEqualTo(InstanceGroupType.CORE);
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request in project cloudbreak by hortonworks.
the class SdxServiceTest method testCreateNOTInternalSdxClusterFromLightDutyTemplateShouldTriggerSdxCreationFlow.
@Test
void testCreateNOTInternalSdxClusterFromLightDutyTemplateShouldTriggerSdxCreationFlow() throws IOException, TransactionExecutionException {
CrnTestUtil.mockCrnGenerator(regionAwareCrnGenerator);
when(transactionService.required(isA(Supplier.class))).thenAnswer(invocation -> invocation.getArgument(0, Supplier.class).get());
String lightDutyJson = FileReaderUtils.readFileFromClasspath("/duties/7.1.0/aws/light_duty.json");
when(cdpConfigService.getConfigForKey(any())).thenReturn(JsonUtil.readValue(lightDutyJson, StackV4Request.class));
SdxClusterRequest sdxClusterRequest = createSdxClusterRequest(null, LIGHT_DUTY);
when(sdxClusterRepository.findByAccountIdAndEnvNameAndDeletedIsNullAndDetachedIsFalse(anyString(), anyString())).thenReturn(new ArrayList<>());
withCloudStorage(sdxClusterRequest);
long id = 10L;
when(sdxClusterRepository.save(any(SdxCluster.class))).thenAnswer(invocation -> {
SdxCluster sdxWithId = invocation.getArgument(0, SdxCluster.class);
sdxWithId.setId(id);
return sdxWithId;
});
when(clock.getCurrentTimeMillis()).thenReturn(1L);
mockEnvironmentCall(sdxClusterRequest, CloudPlatform.AZURE, null);
Pair<SdxCluster, FlowIdentifier> result = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.createSdx(USER_CRN, CLUSTER_NAME, sdxClusterRequest, null));
SdxCluster createdSdxCluster = result.getLeft();
assertEquals(id, createdSdxCluster.getId());
ArgumentCaptor<SdxCluster> captor = ArgumentCaptor.forClass(SdxCluster.class);
verify(sdxClusterRepository, times(1)).save(captor.capture());
SdxCluster capturedSdx = captor.getValue();
assertEquals("tagecske", capturedSdx.getTags().getValue("mytag"));
assertEquals(CLUSTER_NAME, capturedSdx.getClusterName());
assertEquals(LIGHT_DUTY, capturedSdx.getClusterShape());
assertEquals("envir", capturedSdx.getEnvName());
assertEquals("hortonworks", capturedSdx.getAccountId());
assertEquals(USER_CRN, capturedSdx.getInitiatorUserCrn());
verify(sdxStatusService, times(1)).setStatusForDatalakeAndNotify(DatalakeStatusEnum.REQUESTED, "Datalake requested", createdSdxCluster);
assertEquals(1L, capturedSdx.getCreated());
assertFalse(capturedSdx.isCreateDatabase());
assertTrue(createdSdxCluster.getCrn().matches("crn:cdp:datalake:us-west-1:hortonworks:datalake:.*"));
StackV4Request stackV4Request = JsonUtil.readValue(capturedSdx.getStackRequest(), StackV4Request.class);
assertEquals(2L, stackV4Request.getInstanceGroups().size());
InstanceGroupV4Request core = getGroup(stackV4Request, CORE);
assertEquals(1L, core.getSecurityGroup().getSecurityRules().size());
assertEquals("0.0.0.0/0", core.getSecurityGroup().getSecurityRules().get(0).getSubnet());
assertEquals("22", core.getSecurityGroup().getSecurityRules().get(0).getPorts().get(0));
InstanceGroupV4Request gateway = getGroup(stackV4Request, GATEWAY);
assertEquals(2L, gateway.getSecurityGroup().getSecurityRules().size());
assertEquals("0.0.0.0/0", gateway.getSecurityGroup().getSecurityRules().get(0).getSubnet());
assertEquals("443", gateway.getSecurityGroup().getSecurityRules().get(0).getPorts().get(0));
assertEquals("0.0.0.0/0", gateway.getSecurityGroup().getSecurityRules().get(1).getSubnet());
assertEquals("22", gateway.getSecurityGroup().getSecurityRules().get(1).getPorts().get(0));
verify(sdxReactorFlowManager).triggerSdxCreation(createdSdxCluster);
}
Aggregations