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));
}
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;
}
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;
}
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;
}
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);
}
Aggregations