use of com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse in project cloudbreak by hortonworks.
the class NetworkDtoToResponseConverterTest method testConvertWithLoadBalancerEnabled.
@Test
void testConvertWithLoadBalancerEnabled() {
NetworkDto network = createNetworkDto().withAws(createAwsParams()).withLoadBalancerCreation(LoadBalancerCreation.ENABLED).build();
ProvidedSubnetIds providedSubnetIds = new ProvidedSubnetIds(PREFERRED_SUBNET_ID, Set.of(PREFERRED_SUBNET_ID));
when(subnetIdProvider.subnets(network, TUNNEL, network.getCloudPlatform(), true)).thenReturn(providedSubnetIds);
EnvironmentNetworkResponse actual = underTest.convert(network, TUNNEL, true);
assertEquals(network.getAws().getVpcId(), actual.getAws().getVpcId());
assertEquals(LoadBalancerCreation.ENABLED, actual.getLoadBalancerCreation());
assertNull(actual.getAzure());
assertNull(actual.getYarn());
assertNull(actual.getMock());
}
use of com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse in project cloudbreak by hortonworks.
the class InstanceGroupNetworkV1ToInstanceGroupNetworkV4Converter method convertToInstanceGroupNetworkV4Request.
public InstanceGroupNetworkV4Request convertToInstanceGroupNetworkV4Request(Pair<InstanceGroupNetworkV1Request, DetailedEnvironmentResponse> network) {
DetailedEnvironmentResponse value = network.getValue();
EnvironmentNetworkResponse environmentNetworkResponse = null;
if (value == null) {
environmentNetworkResponse = new EnvironmentNetworkResponse();
} else {
environmentNetworkResponse = value.getNetwork();
}
InstanceGroupNetworkV1Request key = network.getKey();
if (key == null) {
key = new InstanceGroupNetworkV1Request();
}
InstanceGroupNetworkV4Request request = new InstanceGroupNetworkV4Request();
if (value != null) {
CloudPlatform cloudPlatform = CloudPlatform.valueOf(value.getCloudPlatform());
request.setCloudPlatform(cloudPlatform);
request.setAws(instanceGroupNetworkParameterConverter.convert(key.getAws(), environmentNetworkResponse, cloudPlatform));
request.setAzure(instanceGroupNetworkParameterConverter.convert(key.getAzure(), environmentNetworkResponse, cloudPlatform));
request.setGcp(instanceGroupNetworkParameterConverter.convert(key.getGcp(), environmentNetworkResponse, cloudPlatform));
request.setYarn(instanceGroupNetworkParameterConverter.convert(key.getYarn(), environmentNetworkResponse, cloudPlatform));
request.setMock(instanceGroupNetworkParameterConverter.convert(key.getMock(), environmentNetworkResponse, cloudPlatform));
}
return request;
}
use of com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse in project cloudbreak by hortonworks.
the class NetworkV1ToNetworkV4Converter method convertToMockNetworkParams.
private MockNetworkV4Parameters convertToMockNetworkParams(Pair<MockNetworkV1Parameters, EnvironmentNetworkResponse> source) {
EnvironmentNetworkResponse value = source.getValue();
MockNetworkV1Parameters key = source.getKey();
MockNetworkV4Parameters params = new MockNetworkV4Parameters();
if (key != null) {
String subnetId = key.getSubnetId();
if (value != null) {
evaluateIfTrueDoOtherwise(subnetId, StringUtils::isNotEmpty, params::setSubnetId, s -> params.setSubnetId(value.getPreferedSubnetId()));
}
params.setInternetGatewayId(key.getInternetGatewayId());
params.setVpcId(key.getVpcId());
}
return params;
}
use of com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse in project cloudbreak by hortonworks.
the class NetworkV1ToNetworkV4Converter method convertToGcpStackRequest.
private GcpNetworkV4Parameters convertToGcpStackRequest(Pair<GcpNetworkV1Parameters, EnvironmentNetworkResponse> source) {
EnvironmentNetworkResponse value = source.getValue();
GcpNetworkV1Parameters key = source.getKey();
GcpNetworkV4Parameters response = new GcpNetworkV4Parameters();
if (key != null) {
response.setNetworkId(value.getGcp().getNetworkId());
response.setNoFirewallRules(value.getGcp().getNoFirewallRules());
response.setNoPublicIp(value.getGcp().getNoPublicIp());
response.setSharedProjectId(value.getGcp().getSharedProjectId());
String subnetId = key.getSubnetId();
if (!Strings.isNullOrEmpty(subnetId)) {
response.setSubnetId(subnetId);
} else {
response.setSubnetId(getFirstSubnetIdFromEnvironment(value));
}
}
return response;
}
use of com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse in project cloudbreak by hortonworks.
the class NetworkV1ToNetworkV4Converter method convertToAwsStackRequest.
private AwsNetworkV4Parameters convertToAwsStackRequest(Pair<AwsNetworkV1Parameters, EnvironmentNetworkResponse> source) {
EnvironmentNetworkResponse value = source.getValue();
AwsNetworkV1Parameters key = source.getKey();
AwsNetworkV4Parameters response = new AwsNetworkV4Parameters();
if (key != null) {
response.setVpcId(value.getAws().getVpcId());
String subnetId = key.getSubnetId();
if (!Strings.isNullOrEmpty(subnetId)) {
response.setSubnetId(key.getSubnetId());
} else if (value != null) {
response.setSubnetId(value.getPreferedSubnetId());
}
if (PublicEndpointAccessGateway.ENABLED.equals(value.getPublicEndpointAccessGateway())) {
ValidationResult validationResult = endpointGatewayNetworkValidator.validate(new ImmutablePair<>(response.getSubnetId(), value));
if (validationResult.getState() == ValidationResult.State.ERROR || validationResult.hasError()) {
throw new BadRequestException("Endpoint gateway subnet validation failed: " + validationResult.getFormattedErrors());
}
Optional<CloudSubnet> endpointGatewaySubnet = subnetSelector.chooseSubnetForEndpointGateway(value, response.getSubnetId());
if (endpointGatewaySubnet.isPresent()) {
response.setEndpointGatewaySubnetId(endpointGatewaySubnet.get().getId());
}
}
}
return response;
}
Aggregations