use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.
the class EnvironmentNetworkServiceTest method testGetNetworkCidrWhenNetworkConnectorNull.
@Test
void testGetNetworkCidrWhenNetworkConnectorNull() {
Credential credential = mock(Credential.class);
Network network = mock(Network.class);
when(cloudConnector.networkConnector()).thenReturn(null);
NetworkConnectorNotFoundException exception = assertThrows(NetworkConnectorNotFoundException.class, () -> underTest.getNetworkCidr(network, "AWS", credential));
assertEquals("No network connector for cloud platform: AWS", exception.getMessage());
}
use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.
the class NetworkServiceTest method testRefreshMetadataFromGoogleCloudProviderMustUseSubnetName.
@Test
public void testRefreshMetadataFromGoogleCloudProviderMustUseSubnetName() {
NetworkDto networkDto = mock(NetworkDto.class);
AuthenticationDto authenticationDto = mock(AuthenticationDto.class);
EnvironmentTelemetry environmentTelemetry = mock(EnvironmentTelemetry.class);
EnvironmentBackup environmentBackup = mock(EnvironmentBackup.class);
SecurityAccessDto securityAccessDto = mock(SecurityAccessDto.class);
ParametersDto parametersDto = mock(ParametersDto.class);
EnvironmentNetworkConverter environmentNetworkConverter = mock(EnvironmentNetworkConverter.class);
Network network = mock(Network.class);
Credential credential = mock(Credential.class);
BaseNetwork baseNetwork = new GcpNetwork();
baseNetwork.setRegistrationType(RegistrationType.EXISTING);
Environment environment = new Environment();
environment.setCloudPlatform("GCP");
environment.setCredential(credential);
EnvironmentEditDto environmentEditDto = new EnvironmentEditDto("description", "accountId", networkDto, authenticationDto, environmentTelemetry, environmentBackup, securityAccessDto, Tunnel.CCMV2, IdBrokerMappingSource.MOCK, CloudStorageValidation.ENABLED, "adminGroupName", parametersDto);
when(environmentNetworkConverterMap.get(any(CloudPlatform.class))).thenReturn(environmentNetworkConverter);
when(environmentNetworkConverter.convertToDto(baseNetwork)).thenReturn(networkDto);
when(cloudNetworkService.retrieveSubnetMetadata(any(Environment.class), any(NetworkDto.class))).thenReturn(Map.of("s1", cloudSubnet("s1", "subnet1")));
when(cloudNetworkService.retrieveEndpointGatewaySubnetMetadata(any(Environment.class), any(NetworkDto.class))).thenReturn(Map.of("s1", cloudSubnet("s1", "subnet1")));
when(environmentNetworkConverter.convertToNetwork(any(BaseNetwork.class))).thenReturn(network);
when(environmentNetworkService.getNetworkCidr(any(Network.class), anyString(), any(Credential.class))).thenReturn(new NetworkCidr("10.0.0.0", new ArrayList<>()));
BaseNetwork result = underTest.refreshMetadataFromCloudProvider(baseNetwork, environmentEditDto, environment);
Assertions.assertEquals(result.getSubnetMetas().keySet().stream().findFirst().get(), "subnet1");
Assertions.assertEquals(result.getSubnetMetas().keySet().size(), 1);
}
use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.
the class AwsEnvironmentNetworkConverterTest method createEnvironment.
private Environment createEnvironment() {
Environment environment = new Environment();
environment.setName(ENV_NAME);
environment.setId(1L);
environment.setAccountId("2");
environment.setDescription("description");
environment.setCloudPlatform("AWS");
environment.setCredential(new Credential());
environment.setLatitude(2.4);
environment.setLongitude(3.5);
environment.setLocation(LOCATION);
environment.setLocationDisplayName("London");
environment.setNetwork(new AwsNetwork());
environment.setRegions(Collections.singleton(new Region()));
return environment;
}
use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.
the class CloudStorageLocationValidatorTest method setUp.
@BeforeEach
public void setUp() {
when(environment.getLocation()).thenReturn(ENV_REGION);
when(environment.getCloudPlatform()).thenReturn(CLOUD_PLATFORM);
when(environment.getCredential()).thenReturn(new Credential());
when(environment.getTelemetry()).thenReturn(environmentTelemetry);
when(environmentTelemetry.getLogging()).thenReturn(environmentLogging);
when(credentialToCloudCredentialConverter.convert(any(Credential.class))).thenReturn(CLOUD_CREDENTIAL);
}
use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.
the class CloudStorageValidatorTest method validateCloudStorageSetLocationBaseWhenLoggingIsConfigured.
@Test
public void validateCloudStorageSetLocationBaseWhenLoggingIsConfigured() {
when(credentialService.getByCrnForAccountId(anyString(), anyString(), any(), anyBoolean())).thenReturn(new Credential());
when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
EnvironmentCloudStorageValidationRequest request = new EnvironmentCloudStorageValidationRequest();
TelemetryRequest telemetryRequest = new TelemetryRequest();
LoggingRequest loggingRequest = new LoggingRequest();
loggingRequest.setStorageLocation("s3://mybucket/location");
S3CloudStorageV1Parameters s3CloudStorageV1Parameters = new S3CloudStorageV1Parameters();
s3CloudStorageV1Parameters.setInstanceProfile("instanceProfile");
loggingRequest.setS3(s3CloudStorageV1Parameters);
telemetryRequest.setLogging(loggingRequest);
request.setTelemetry(telemetryRequest);
request.setCredentialCrn("credential");
ArgumentCaptor<ObjectStorageValidateRequest> requestCaptor = ArgumentCaptor.forClass(ObjectStorageValidateRequest.class);
when(cloudProviderServicesV4Endpoint.validateObjectStorage(requestCaptor.capture())).thenReturn(ObjectStorageValidateResponse.builder().withStatus(ResponseStatus.OK).build());
ObjectStorageValidateResponse response = underTest.validateCloudStorage("1234", request);
assertEquals(ResponseStatus.OK, response.getStatus());
assertNull(response.getError());
ObjectStorageValidateRequest objectStorageValidateRequest = requestCaptor.getValue();
assertEquals("s3://mybucket/location", objectStorageValidateRequest.getLogsLocationBase());
List<StorageIdentityBase> storageIdentities = objectStorageValidateRequest.getCloudStorageRequest().getIdentities();
assertEquals(1, storageIdentities.size());
StorageIdentityBase storageIdentity = storageIdentities.get(0);
assertEquals(CloudIdentityType.LOG, storageIdentity.getType());
assertEquals("instanceProfile", storageIdentity.getS3().getInstanceProfile());
}
Aggregations