Search in sources :

Example 26 with GATEWAY

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceMetadataType.GATEWAY in project cloudbreak by hortonworks.

the class ClusterRequestToGatewayConverterTest method testWithEnableFalseAndDefinedTopologyInList.

@Test
public void testWithEnableFalseAndDefinedTopologyInList() {
    GatewayV4Request source = new GatewayV4Request();
    source.setTopologies(getTopologies());
    Gateway result = underTest.convert(source);
    assertNotNull(result);
    assertEquals("topologyName", result.getTopologies().iterator().next().getTopologyName());
}
Also used : GatewayV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.gateway.GatewayV4Request) Gateway(com.sequenceiq.cloudbreak.domain.stack.cluster.gateway.Gateway) Test(org.junit.Test)

Example 27 with GATEWAY

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceMetadataType.GATEWAY 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 28 with GATEWAY

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceMetadataType.GATEWAY in project cloudbreak by hortonworks.

the class SecurityAccessManifesterTest method overrideSecurityAccessWhenOneCidrRangeProvidedThenShouldUpdateTheCidrRange.

@Test
void overrideSecurityAccessWhenOneCidrRangeProvidedThenShouldUpdateTheCidrRange() {
    InstanceGroupType gateway = GATEWAY;
    List<InstanceGroupV4Request> instanceGroups = getInstanceGroups();
    String theWholeWorld = "0.0.0.0/0";
    securityAccessManifester.overrideSecurityAccess(gateway, instanceGroups, null, theWholeWorld);
    assertEquals(1, instanceGroups.get(0).getSecurityGroup().getSecurityRules().size());
    assertEquals(List.of(theWholeWorld), collectSubnets(instanceGroups));
}
Also used : InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) InstanceGroupV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request) Test(org.junit.jupiter.api.Test)

Example 29 with GATEWAY

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceMetadataType.GATEWAY in project cloudbreak by hortonworks.

the class SecurityAccessManifesterTest method overrideSecurityAccessWhenMultipleCidrRangeProvidedThenShouldUpdateTheCidrRanges.

@Test
void overrideSecurityAccessWhenMultipleCidrRangeProvidedThenShouldUpdateTheCidrRanges() {
    InstanceGroupType gateway = GATEWAY;
    List<InstanceGroupV4Request> instanceGroups = getInstanceGroups();
    String theWholeWorldAndASimpleCidr = "0.0.0.0/0,172.16.0.0/16";
    securityAccessManifester.overrideSecurityAccess(gateway, instanceGroups, null, theWholeWorldAndASimpleCidr);
    assertEquals(2, instanceGroups.get(0).getSecurityGroup().getSecurityRules().size());
    assertEquals(List.of(theWholeWorldAndASimpleCidr.split(",")), collectSubnets(instanceGroups));
}
Also used : InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) InstanceGroupV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request) Test(org.junit.jupiter.api.Test)

Example 30 with GATEWAY

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceMetadataType.GATEWAY in project cloudbreak by hortonworks.

the class GatewayManifester method configureGatewayForSdxCluster.

public StackV4Request configureGatewayForSdxCluster(StackV4Request stackV4Request) {
    if (stackV4Request.getCluster().getGateway() == null) {
        GatewayV4Request gatewayV4Request = new GatewayV4Request();
        gatewayV4Request.setTopologies(List.of(getGatewayTopologyV4Request()));
        gatewayV4Request.setSsoType(defaultSsoType);
        stackV4Request.getCluster().setGateway(gatewayV4Request);
        LOGGER.info("Configured gateway for SDX {}", stackV4Request.getName());
    }
    return stackV4Request;
}
Also used : GatewayV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.gateway.GatewayV4Request)

Aggregations

Gateway (com.sequenceiq.cloudbreak.domain.stack.cluster.gateway.Gateway)20 Test (org.junit.Test)18 GatewayV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.gateway.GatewayV4Request)16 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)16 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)15 Set (java.util.Set)15 Map (java.util.Map)14 List (java.util.List)13 Test (org.junit.jupiter.api.Test)12 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)10 Json (com.sequenceiq.cloudbreak.common.json.Json)9 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)9 Optional (java.util.Optional)9 Collectors (java.util.stream.Collectors)9 GatewayTopologyV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.gateway.topology.GatewayTopologyV4Request)8 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)8 InstanceGroupType (com.sequenceiq.common.api.type.InstanceGroupType)8 HashSet (java.util.HashSet)8 EntitlementService (com.sequenceiq.cloudbreak.auth.altus.EntitlementService)7 InstanceMetaDataService (com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService)7