use of com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse in project cloudbreak by hortonworks.
the class NetworkV1ToNetworkV4ConverterTest method createEnvironmentNetworkResponseForGcp.
private EnvironmentNetworkResponse createEnvironmentNetworkResponseForGcp() {
EnvironmentNetworkResponse environmentNetworkResponse = new EnvironmentNetworkResponse();
environmentNetworkResponse.setSubnetIds(SUBNET_IDS);
environmentNetworkResponse.setPreferedSubnetId(SUBNET_ID);
environmentNetworkResponse.setGcp(createEnvironmentNetworkGcpParams());
return environmentNetworkResponse;
}
use of com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse in project cloudbreak by hortonworks.
the class NetworkV1ToNetworkV4ConverterTest method testConvertToStackRequestWhenYarnPresented.
@Test
public void testConvertToStackRequestWhenYarnPresented() {
NetworkV1Request networkV1Request = yarnNetworkV1Request();
DetailedEnvironmentResponse environmentNetworkResponse = yarnEnvironmentNetwork();
NetworkV4Request networkV4Request = underTest.convertToNetworkV4Request(new ImmutablePair<>(networkV1Request, environmentNetworkResponse));
assertTrue(networkV4Request.createYarn().asMap().size() == 1);
}
use of com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse in project cloudbreak by hortonworks.
the class StackV4RequestToStackConverter method setNetworkIfApplicable.
private void setNetworkIfApplicable(StackV4Request source, Stack stack, DetailedEnvironmentResponse environment) {
if (source.getNetwork() != null) {
source.getNetwork().setCloudPlatform(source.getCloudPlatform());
Network network = networkV4RequestToNetworkConverter.convert(source.getNetwork());
EnvironmentNetworkResponse envNetwork = environment == null ? null : environment.getNetwork();
if (envNetwork != null) {
network.setNetworkCidrs(envNetwork.getNetworkCidrs());
network.setOutboundInternetTraffic(envNetwork.getOutboundInternetTraffic());
}
stack.setNetwork(network);
} else {
EnvironmentNetworkConverter environmentNetworkConverter = environmentNetworkConverterMap.get(source.getCloudPlatform());
String availabilityZone = source.getPlacement() != null ? source.getPlacement().getAvailabilityZone() : null;
if (environmentNetworkConverter != null && environment != null) {
Network network = environmentNetworkConverter.convertToLegacyNetwork(environment.getNetwork(), availabilityZone);
stack.setNetwork(network);
}
}
}
use of com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse in project cloudbreak by hortonworks.
the class StackV4RequestToStackConverter method setupEndpointGatewayNetwork.
private void setupEndpointGatewayNetwork(InstanceGroupNetworkV4Request instanceGroupNetworkV4Request, Stack stack, String instanceGroupName, DetailedEnvironmentResponse environment) {
if (CloudPlatform.AWS.name().equals(stack.getCloudPlatform()) && instanceGroupNetworkV4Request != null && instanceGroupNetworkV4Request.getAws() != null) {
EnvironmentNetworkResponse envNetwork = environment == null ? null : environment.getNetwork();
if (envNetwork != null) {
if (PublicEndpointAccessGateway.ENABLED.equals(envNetwork.getPublicEndpointAccessGateway())) {
LOGGER.info("Found AWS stack with endpoint gatewy enabled. Selecting endpoint gateway subnet ids.");
List<String> subnetIds = instanceGroupNetworkV4Request.getAws().getSubnetIds();
LOGGER.debug("Endpoint gateway selection: Found instance group network subnet list of {} for instance group {}", subnetIds, instanceGroupName);
List<String> allAvailabilityZones = envNetwork.getSubnetMetas().values().stream().filter(subnetMeta -> subnetIds.contains(subnetMeta.getId())).map(CloudSubnet::getAvailabilityZone).collect(Collectors.toList());
LOGGER.debug("Endpoint gatway selection: Instance group network has availability zones {}", allAvailabilityZones);
List<String> endpointGatewaySubnetIds = envNetwork.getGatewayEndpointSubnetMetas().values().stream().filter(subnetMeta -> allAvailabilityZones.contains(subnetMeta.getAvailabilityZone())).map(CloudSubnet::getId).collect(Collectors.toList());
if (endpointGatewaySubnetIds.isEmpty()) {
String endpointGatewaySubnetId = getStackEndpointGatwaySubnetIdIfExists(stack);
LOGGER.info("Unable to find endpoint gateway subnet metas to match AZs {}. Falling back to subnet {}.", allAvailabilityZones, endpointGatewaySubnetId);
instanceGroupNetworkV4Request.getAws().setEndpointGatewaySubnetIds(List.of(endpointGatewaySubnetId));
} else {
LOGGER.info("Selected endpoint gateway subnets {} for instance group {}", endpointGatewaySubnetIds, instanceGroupName);
instanceGroupNetworkV4Request.getAws().setEndpointGatewaySubnetIds(endpointGatewaySubnetIds);
}
}
}
}
}
use of com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse in project cloudbreak by hortonworks.
the class EndpointGatewayNetworkValidatorTest method validateWhenEndpointGatewaySubnetsAreInvalid.
@Test
public void validateWhenEndpointGatewaySubnetsAreInvalid() {
EnvironmentNetworkResponse network = new EnvironmentNetworkResponse();
network.setPublicEndpointAccessGateway(PublicEndpointAccessGateway.ENABLED);
CloudSubnet publicSubnet = getPublicCloudSubnet(PUBLIC_ID_1, AZ_1);
network.setGatewayEndpointSubnetMetas(Map.of(KEY, publicSubnet));
when(subnetSelector.findSubnetById(any(), anyString())).thenReturn(Optional.of(getPrivateCloudSubnet(PRIVATE_ID_1, AZ_1)));
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_ENDPOINT_GATEWAY, AZ_1), result.getErrors().get(0));
}
Aggregations