Search in sources :

Example 11 with InstanceGroupV4Request

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());
        }
    }
}
Also used : InstanceGroupV1Request(com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.InstanceGroupV1Request) InstanceTemplateV1Request(com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.template.InstanceTemplateV1Request) SecurityGroupV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.securitygroup.SecurityGroupV4Request) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) InstanceGroupV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 12 with InstanceGroupV4Request

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);
}
Also used : InstanceGroupV1Request(com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.InstanceGroupV1Request) InstanceGroupV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 13 with InstanceGroupV4Request

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);
}
Also used : InstanceTemplateV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.template.InstanceTemplateV4Request) InstanceGroupV1Request(com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.InstanceGroupV1Request) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) InstanceGroupV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with InstanceGroupV4Request

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);
}
Also used : InstanceGroupV1Request(com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.InstanceGroupV1Request) InstanceGroupV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request) NetworkV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.network.NetworkV4Request) InstanceGroupNetworkV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.network.InstanceGroupNetworkV4Request) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 15 with InstanceGroupV4Request

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);
}
Also used : StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) SdxClusterRequest(com.sequenceiq.sdx.api.model.SdxClusterRequest) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) Supplier(java.util.function.Supplier) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) InstanceGroupV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Aggregations

InstanceGroupV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request)51 Test (org.junit.jupiter.api.Test)28 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)27 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)22 InstanceTemplateV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.template.InstanceTemplateV4Request)18 ArrayList (java.util.ArrayList)8 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)5 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)5 InstanceGroupNetworkV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.network.InstanceGroupNetworkV4Request)4 SecurityGroupV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.securitygroup.SecurityGroupV4Request)4 InstanceGroupV1Request (com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.InstanceGroupV1Request)4 MethodSource (org.junit.jupiter.params.provider.MethodSource)4 AwsInstanceTemplateV4Parameters (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.template.AwsInstanceTemplateV4Parameters)2 NetworkV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.network.NetworkV4Request)2 SecurityRuleV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.util.requests.SecurityRuleV4Request)2 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)2 InstanceGroupType (com.sequenceiq.common.api.type.InstanceGroupType)2 List (java.util.List)2 Test (org.junit.Test)2 Strings (com.google.common.base.Strings)1