Search in sources :

Example 46 with StackV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request 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)

Example 47 with StackV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request in project cloudbreak by hortonworks.

the class SdxServiceTest method testCreateInternalSdxClusterWithCustomInstanceGroupShouldFail.

@Test
void testCreateInternalSdxClusterWithCustomInstanceGroupShouldFail() {
    when(sdxClusterRepository.findByAccountIdAndEnvNameAndDeletedIsNullAndDetachedIsFalse(anyString(), anyString())).thenReturn(new ArrayList<>());
    StackV4Request stackV4Request = new StackV4Request();
    ClusterV4Request clusterV4Request = new ClusterV4Request();
    stackV4Request.setCluster(clusterV4Request);
    SdxClusterRequest sdxClusterRequest = createSdxClusterRequest("7.2.12", CUSTOM);
    withCustomInstanceGroups(sdxClusterRequest);
    mockEnvironmentCall(sdxClusterRequest, CloudPlatform.AWS, null);
    BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> underTest.createSdx(USER_CRN, CLUSTER_NAME, sdxClusterRequest, stackV4Request));
    assertEquals("Custom instance group is not accepted on SDX Internal API.", badRequestException.getMessage());
}
Also used : ClusterV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.ClusterV4Request) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) SdxClusterRequest(com.sequenceiq.sdx.api.model.SdxClusterRequest) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 48 with StackV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request in project cloudbreak by hortonworks.

the class GatewayManifesterTest method prepareGatewayWhenRequestedHasValueForGatewayShouldReturnWithoutModifications.

@Test
void prepareGatewayWhenRequestedHasValueForGatewayShouldReturnWithoutModifications() {
    GatewayV4Request gatewayV4Request = getGatewayV4Request();
    StackV4Request stackV4Request = new StackV4Request();
    stackV4Request.setCluster(new ClusterV4Request());
    stackV4Request.getCluster().setGateway(gatewayV4Request);
    underTest.configureGatewayForSdxCluster(stackV4Request);
    isTrue(stackV4Request.getCluster().getGateway().equals(gatewayV4Request));
}
Also used : GatewayV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.gateway.GatewayV4Request) ClusterV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.ClusterV4Request) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) Test(org.junit.jupiter.api.Test)

Example 49 with StackV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request in project cloudbreak by hortonworks.

the class GatewayManifesterTest method prepareGatewayWhenRequestedHasNullValueForGatewayShouldReturnWithFullGateConfig.

@Test
void prepareGatewayWhenRequestedHasNullValueForGatewayShouldReturnWithFullGateConfig() {
    StackV4Request stackV4Request = new StackV4Request();
    stackV4Request.setCluster(new ClusterV4Request());
    StackV4Request result = underTest.configureGatewayForSdxCluster(stackV4Request);
    isTrue(result.getCluster() != null);
    isTrue(result.getCluster().getGateway() != null);
    isTrue(result.getCluster().getGateway().getSsoType().equals(SSOType.SSO_PROVIDER_FROM_UMS));
}
Also used : ClusterV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.ClusterV4Request) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) Test(org.junit.jupiter.api.Test)

Example 50 with StackV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request in project cloudbreak by hortonworks.

the class MultiAzDecoratorTest method decorateStackRequestWithMultiAzShouldUseTheSingleEnvironmentPreferredSubnetIdWhenClusterShapeIsNotHA.

@Test
void decorateStackRequestWithMultiAzShouldUseTheSingleEnvironmentPreferredSubnetIdWhenClusterShapeIsNotHA() {
    StackV4Request stackV4Request = new StackV4Request();
    stackV4Request.setInstanceGroups(List.of(getInstanceGroupV4Request(InstanceGroupType.GATEWAY), getInstanceGroupV4Request(InstanceGroupType.CORE)));
    EnvironmentNetworkResponse network = new EnvironmentNetworkResponse();
    network.setPreferedSubnetId(PREFERRED_SUBNET_ID);
    DetailedEnvironmentResponse environment = new DetailedEnvironmentResponse();
    environment.setNetwork(network);
    underTest.decorateStackRequestWithMultiAz(stackV4Request, environment, SdxClusterShape.LIGHT_DUTY);
    Assertions.assertTrue(stackV4Request.getInstanceGroups().stream().allMatch(ig -> ig.getNetwork().getAws().getSubnetIds().stream().allMatch(PREFERRED_SUBNET_ID::equals)));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) SdxClusterShape(com.sequenceiq.sdx.api.model.SdxClusterShape) EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) Set(java.util.Set) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) Test(org.junit.jupiter.api.Test) List(java.util.List) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) SubnetType(com.sequenceiq.cloudbreak.cloud.model.network.SubnetType) Map(java.util.Map) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) Assertions(org.junit.jupiter.api.Assertions) InstanceGroupV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request) Tunnel(com.sequenceiq.common.api.type.Tunnel) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) Test(org.junit.jupiter.api.Test)

Aggregations

StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)105 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)66 Test (org.junit.jupiter.api.Test)58 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)52 InstanceGroupV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request)36 Test (org.junit.Test)36 LoadBalancer (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer)34 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)33 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)33 SubnetTest (com.sequenceiq.cloudbreak.core.network.SubnetTest)32 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)31 ClusterV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.ClusterV4Request)17 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)14 Map (java.util.Map)13 Set (java.util.Set)13 Optional (java.util.Optional)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)12 CloudPlatform (com.sequenceiq.cloudbreak.common.mappable.CloudPlatform)11 HashMap (java.util.HashMap)11 List (java.util.List)11