Search in sources :

Example 71 with EnvironmentNetworkResponse

use of com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse in project cloudbreak by hortonworks.

the class EndpointGatewayNetworkValidatorTest method validateWhenClusterSubnetsAreInvalid.

@Test
public void validateWhenClusterSubnetsAreInvalid() {
    EnvironmentNetworkResponse network = new EnvironmentNetworkResponse();
    network.setPublicEndpointAccessGateway(PublicEndpointAccessGateway.ENABLED);
    CloudSubnet privateSubnet = getPrivateCloudSubnet(PRIVATE_ID_1, AZ_1);
    network.setSubnetMetas(Map.of(KEY, privateSubnet));
    when(subnetSelector.findSubnetById(any(), anyString())).thenReturn(Optional.of(privateSubnet));
    when(subnetSelector.chooseSubnetForEndpointGateway(any(), anyString())).thenReturn(Optional.empty());
    ValidationResult result = underTest.validate(new ImmutablePair<>(PRIVATE_ID_1, network));
    assert result.hasError();
    assertEquals(String.format(NO_USABLE_SUBNET_IN_CLUSTER, AZ_1), result.getErrors().get(0));
}
Also used : EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Test(org.junit.Test) SubnetTest(com.sequenceiq.cloudbreak.core.network.SubnetTest)

Example 72 with EnvironmentNetworkResponse

use of com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse in project cloudbreak by hortonworks.

the class InstanceGroupNetworkParameterConverter method convertToMockNetworkParams.

private InstanceGroupMockNetworkV4Parameters convertToMockNetworkParams(Pair<InstanceGroupMockNetworkV1Parameters, EnvironmentNetworkResponse> source) {
    EnvironmentNetworkResponse value = source.getValue();
    InstanceGroupMockNetworkV1Parameters key = source.getKey();
    InstanceGroupMockNetworkV4Parameters params = new InstanceGroupMockNetworkV4Parameters();
    if (key != null) {
        List<String> subnetIds = key.getSubnetIds();
        if (value != null) {
            if (subnetIdsDefined(subnetIds)) {
                params.setSubnetIds(subnetIds);
            } else {
                params.setSubnetIds(List.of(value.getPreferedSubnetId()));
            }
        }
    }
    return params;
}
Also used : InstanceGroupMockNetworkV4Parameters(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.instancegroup.network.mock.InstanceGroupMockNetworkV4Parameters) EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) InstanceGroupMockNetworkV1Parameters(com.sequenceiq.distrox.api.v1.distrox.model.network.mock.InstanceGroupMockNetworkV1Parameters)

Example 73 with EnvironmentNetworkResponse

use of com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse in project cloudbreak by hortonworks.

the class NetworkV1ToNetworkV4Converter method convertToNetworkV4Request.

public NetworkV4Request convertToNetworkV4Request(Pair<NetworkV1Request, DetailedEnvironmentResponse> network) {
    EnvironmentNetworkResponse value = network.getValue().getNetwork();
    NetworkV1Request key = network.getKey();
    if (key == null) {
        key = new NetworkV1Request();
    }
    NetworkV4Request request = new NetworkV4Request();
    if (network.getValue().getCloudPlatform() == null) {
        throw new IllegalStateException("Unable to determine cloud platform for network since it has not been set!");
    }
    switch(network.getValue().getCloudPlatform()) {
        case "AWS":
            request.setAws(getAwsNetworkParameters(Optional.ofNullable(key.getAws()), value));
            break;
        case "AZURE":
            request.setAzure(getAzureNetworkParameters(Optional.ofNullable(key.getAzure()), value));
            break;
        case "MOCK":
            request.setMock(getMockNetworkParameters(Optional.ofNullable(key.getMock()), value));
            break;
        case "GCP":
            request.setGcp(getGcpNetworkParameters(Optional.ofNullable(key.getGcp()), value));
            break;
        default:
            LOGGER.warn(NetworkV1ToNetworkV4Converter.class.getSimpleName() + " has no implemented action for cloud platform: " + network.getValue().getCloudPlatform());
    }
    return request;
}
Also used : EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) NetworkV1Request(com.sequenceiq.distrox.api.v1.distrox.model.network.NetworkV1Request) NetworkV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.network.NetworkV4Request)

Example 74 with EnvironmentNetworkResponse

use of com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse in project cloudbreak by hortonworks.

the class NetworkV1ToNetworkV4Converter method convertToAzureStackRequest.

private AzureNetworkV4Parameters convertToAzureStackRequest(Pair<AzureNetworkV1Parameters, EnvironmentNetworkResponse> source) {
    EnvironmentNetworkResponse value = source.getValue();
    AzureNetworkV1Parameters key = source.getKey();
    AzureNetworkV4Parameters response = new AzureNetworkV4Parameters();
    if (key != null) {
        response.setNetworkId(value.getAzure().getNetworkId());
        response.setNoPublicIp(value.getAzure().getNoPublicIp());
        response.setResourceGroupName(value.getAzure().getResourceGroupName());
        response.setDatabasePrivateDnsZoneId(value.getAzure().getDatabasePrivateDnsZoneId());
        String subnetId = key.getSubnetId();
        if (!Strings.isNullOrEmpty(subnetId)) {
            response.setSubnetId(subnetId);
        } else if (source.getValue() != null) {
            response.setSubnetId(source.getValue().getPreferedSubnetId());
        }
    }
    return response;
}
Also used : AzureNetworkV1Parameters(com.sequenceiq.distrox.api.v1.distrox.model.network.azure.AzureNetworkV1Parameters) AzureNetworkV4Parameters(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.network.AzureNetworkV4Parameters) EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse)

Example 75 with EnvironmentNetworkResponse

use of com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse in project cloudbreak by hortonworks.

the class StackDecoratorTest method setUp.

@Before
public void setUp() {
    String credentialName = "credentialName";
    MockitoAnnotations.initMocks(this);
    subject = new Stack();
    subject.setEnvironmentCrn("envCrn");
    Set<InstanceGroup> instanceGroups = createInstanceGroups(GATEWAY);
    subject.setInstanceGroups(instanceGroups);
    Cluster cluster = getCluster(instanceGroups);
    subject.setCluster(cluster);
    subject.setCloudPlatform("AZURE");
    subject.setParameters(new HashMap<>());
    when(cloudParameterCache.getPlatformParameters()).thenReturn(platformParametersMap);
    when(platformParametersMap.get(any(Platform.class))).thenReturn(pps);
    when(pps.specialParameters()).thenReturn(specialParameters);
    when(specialParameters.getSpecialParameters()).thenReturn(specialParametersMap);
    when(specialParametersMap.get(anyString())).thenReturn(false);
    when(cloudParameterService.getOrchestrators()).thenReturn(platformOrchestrators);
    when(platformOrchestrators.getDefaults()).thenReturn(defaultOrchestrator);
    when(defaultOrchestrator.get(any(Platform.class))).thenReturn(orchestrator);
    when(instanceGroupToInstanceGroupParameterRequestConverter.convert(any(InstanceGroup.class))).thenReturn(instanceGroupParameterRequest);
    when(request.getCluster()).thenReturn(clusterRequest);
    when(environmentSettingsRequest.getCredentialName()).thenReturn(credentialName);
    when(sharedServiceValidator.checkSharedServiceStackRequirements(any(StackV4Request.class), any(Workspace.class))).thenReturn(validationResult);
    DetailedEnvironmentResponse environmentResponse = new DetailedEnvironmentResponse();
    environmentResponse.setCredential(credentialResponse);
    CompactRegionResponse crr = new CompactRegionResponse();
    crr.setNames(Lists.newArrayList("region"));
    environmentResponse.setRegions(crr);
    EnvironmentNetworkResponse enr = new EnvironmentNetworkResponse();
    Map<String, CloudSubnet> subnetmetas = Maps.newHashMap("subnet", new CloudSubnet("id", "name", "availabilityzone", "cidr"));
    enr.setSubnetMetas(subnetmetas);
    environmentResponse.setNetwork(enr);
    environmentResponse.setAzure(AzureEnvironmentParameters.builder().withAzureResourceGroup(AzureResourceGroup.builder().withResourceGroupUsage(ResourceGroupUsage.SINGLE).withName("resource-group").build()).build());
    when(request.getCloudPlatform()).thenReturn(CloudPlatform.AZURE);
    when(environmentClientService.getByName(anyString())).thenReturn(environmentResponse);
    when(environmentClientService.getByCrn(anyString())).thenReturn(environmentResponse);
    Credential credential = Credential.builder().cloudPlatform(CloudPlatform.MOCK.name()).build();
    when(credentialClientService.getByCrn(anyString())).thenReturn(credential);
    when(credentialClientService.getByName(anyString())).thenReturn(credential);
    when(credentialConverter.convert(credentialResponse)).thenReturn(credential);
    ExtendedCloudCredential extendedCloudCredential = mock(ExtendedCloudCredential.class);
    when(extendedCloudCredentialConverter.convert(credential)).thenReturn(extendedCloudCredential);
}
Also used : CompactRegionResponse(com.sequenceiq.environment.api.v1.environment.model.response.CompactRegionResponse) ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) Credential(com.sequenceiq.cloudbreak.dto.credential.Credential) Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace) Before(org.junit.Before)

Aggregations

EnvironmentNetworkResponse (com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse)70 Test (org.junit.jupiter.api.Test)40 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)27 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)24 SubnetTest (com.sequenceiq.cloudbreak.core.network.SubnetTest)22 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)8 NetworkV1Request (com.sequenceiq.distrox.api.v1.distrox.model.network.NetworkV1Request)8 NetworkV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.network.NetworkV4Request)7 Test (org.junit.Test)7 EnvironmentNetworkGcpParams (com.sequenceiq.environment.api.v1.environment.model.EnvironmentNetworkGcpParams)6 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)5 Network (com.sequenceiq.cloudbreak.domain.Network)5 NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)5 ProvidedSubnetIds (com.sequenceiq.environment.network.service.domain.ProvidedSubnetIds)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 InstanceGroupV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request)3 SubnetType (com.sequenceiq.cloudbreak.cloud.model.network.SubnetType)3 InstanceGroupType (com.sequenceiq.common.api.type.InstanceGroupType)3 Tunnel (com.sequenceiq.common.api.type.Tunnel)3 EnvironmentNetworkAwsParams (com.sequenceiq.environment.api.v1.environment.model.EnvironmentNetworkAwsParams)3