Search in sources :

Example 1 with TagResponse

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

the class StackV4RequestToStackConverterTest method setupForEndpointGateway.

private StackV4Request setupForEndpointGateway(boolean enabled) {
    initMocks();
    ReflectionTestUtils.setField(underTest, "defaultRegions", "AWS:eu-west-2");
    StackV4Request request = getRequest("stack-datalake-with-instancegroups.json");
    EnvironmentNetworkResponse networkResponse = new EnvironmentNetworkResponse();
    networkResponse.setPublicEndpointAccessGateway(enabled ? PublicEndpointAccessGateway.ENABLED : PublicEndpointAccessGateway.DISABLED);
    DetailedEnvironmentResponse environmentResponse = new DetailedEnvironmentResponse();
    environmentResponse.setCredential(credentialResponse);
    environmentResponse.setCloudPlatform("AWS");
    environmentResponse.setTunnel(Tunnel.DIRECT);
    environmentResponse.setTags(new TagResponse());
    environmentResponse.setNetwork(networkResponse);
    when(environmentClientService.getByName(anyString())).thenReturn(environmentResponse);
    when(environmentClientService.getByCrn(anyString())).thenReturn(environmentResponse);
    given(credentialClientService.getByCrn(anyString())).willReturn(credential);
    given(credentialClientService.getByName(anyString())).willReturn(credential);
    given(providerParameterCalculator.get(request)).willReturn(getMappable());
    given(clusterV4RequestToClusterConverter.convert(any(ClusterV4Request.class))).willReturn(new Cluster());
    given(telemetryConverter.convert(null, StackType.DATALAKE)).willReturn(new Telemetry());
    given(loadBalancerConfigService.getKnoxGatewayGroups(any(Stack.class))).willReturn(Set.of("master"));
    return request;
}
Also used : ClusterV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.ClusterV4Request) TagResponse(com.sequenceiq.environment.api.v1.environment.model.response.TagResponse) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) Telemetry(com.sequenceiq.common.api.telemetry.model.Telemetry) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 2 with TagResponse

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

the class StackV4RequestToStackConverterTest method setUp.

@BeforeEach
void setUp() {
    when(restRequestThreadLocalService.getCloudbreakUser()).thenReturn(cloudbreakUser);
    when(cloudbreakUser.getUsername()).thenReturn("username");
    when(restRequestThreadLocalService.getRequestedWorkspaceId()).thenReturn(1L);
    when(workspaceService.getForCurrentUser()).thenReturn(workspace);
    when(workspace.getId()).thenReturn(1L);
    DetailedEnvironmentResponse environmentResponse = new DetailedEnvironmentResponse();
    environmentResponse.setCredential(credentialResponse);
    environmentResponse.setCloudPlatform("AWS");
    environmentResponse.setTunnel(Tunnel.DIRECT);
    environmentResponse.setTags(new TagResponse());
    when(environmentClientService.getByName(anyString())).thenReturn(environmentResponse);
    when(environmentClientService.getByCrn(anyString())).thenReturn(environmentResponse);
    when(kerberosConfigService.get(anyString(), anyString())).thenReturn(Optional.empty());
    when(costTagging.mergeTags(any(CDPTagMergeRequest.class))).thenReturn(new HashMap<>());
    when(datalakeService.getDatalakeCrn(any(), any())).thenReturn("crn");
    when(targetedUpscaleSupportService.isUnboundEliminationSupported(anyString())).thenReturn(Boolean.FALSE);
    credential = Credential.builder().cloudPlatform("AWS").build();
}
Also used : TagResponse(com.sequenceiq.environment.api.v1.environment.model.response.TagResponse) CDPTagMergeRequest(com.sequenceiq.cloudbreak.tag.request.CDPTagMergeRequest) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with TagResponse

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

the class EnvironmentResponseConverter method environmentTagsToTagResponse.

private TagResponse environmentTagsToTagResponse(EnvironmentTags tags) {
    TagResponse tagResponse = new TagResponse();
    tagResponse.setDefaults(tags.getDefaultTags());
    tagResponse.setUserDefined(tags.getUserDefinedTags());
    return tagResponse;
}
Also used : TagResponse(com.sequenceiq.environment.api.v1.environment.model.response.TagResponse)

Example 4 with TagResponse

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

the class AllocateDatabaseServerV4RequestToDBStackConverterTest method conversionTestWhenOptionalElementsGenerated.

@Test
void conversionTestWhenOptionalElementsGenerated() throws IOException {
    setupAllocateRequest(false);
    when(databaseServerSslCertificateConfig.getNumberOfCertsByCloudPlatformAndRegion(AWS_CLOUD_PLATFORM.name(), REGION)).thenReturn(SINGLE_CERT);
    when(databaseServerSslCertificateConfig.getCertByCloudPlatformAndRegionAndVersion(AWS_CLOUD_PLATFORM.name(), REGION, VERSION_3)).thenReturn(sslCertificateEntryV3);
    List<CloudSubnet> cloudSubnets = List.of(new CloudSubnet("subnet-1", "", "az-a", ""), new CloudSubnet("subnet-2", "", "az-b", ""));
    DetailedEnvironmentResponse environment = DetailedEnvironmentResponse.builder().withCloudPlatform(AWS_CLOUD_PLATFORM.name()).withName(ENVIRONMENT_NAME).withCrn(ENVIRONMENT_CRN).withTag(new TagResponse()).withLocation(LocationResponse.LocationResponseBuilder.aLocationResponse().withName(REGION).build()).withSecurityAccess(SecurityAccessResponse.builder().withDefaultSecurityGroupId(DEFAULT_SECURITY_GROUP_ID).build()).withNetwork(EnvironmentNetworkResponse.builder().withSubnetMetas(Map.of("subnet-1", cloudSubnets.get(0), "subnet-2", cloudSubnets.get(1))).build()).build();
    when(environmentService.getByCrn(ENVIRONMENT_CRN)).thenReturn(environment);
    when(subnetListerService.listSubnets(any(), any())).thenReturn(cloudSubnets);
    when(subnetChooserService.chooseSubnets(any(), any(), any())).thenReturn(cloudSubnets);
    when(networkParameterAdder.addSubnetIds(any(), any(), any(), any())).thenReturn(SUBNET_ID_REQUEST_PARAMETERS);
    when(userGeneratorService.generateUserName()).thenReturn(USERNAME);
    when(passwordGeneratorService.generatePassword(any())).thenReturn(PASSWORD);
    DBStack dbStack = underTest.convert(allocateRequest, OWNER_CRN);
    assertEquals(ENVIRONMENT_NAME + "-dbstck-parts", dbStack.getName());
    assertEquals(PASSWORD, dbStack.getDatabaseServer().getRootPassword());
    assertEquals(USERNAME, dbStack.getDatabaseServer().getRootUserName());
    assertEquals("n-uuid", dbStack.getNetwork().getName());
    assertEquals(1, dbStack.getNetwork().getAttributes().getMap().size());
    assertEquals("netvalue", dbStack.getNetwork().getAttributes().getMap().get("netkey"));
    assertThat(dbStack.getDatabaseServer().getSecurityGroup().getSecurityGroupIds()).hasSize(1);
    assertEquals(dbStack.getDatabaseServer().getSecurityGroup().getSecurityGroupIds().iterator().next(), DEFAULT_SECURITY_GROUP_ID);
    assertEquals(dbStack.getTags().get(StackTags.class).getUserDefinedTags().get("DistroXKey1"), "DistroXValue1");
    verifySsl(dbStack, Set.of(CERT_PEM_V3), CLOUD_PROVIDER_IDENTIFIER_V3);
    verify(databaseServerSslCertificateConfig, never()).getCertsByCloudPlatformAndRegionAndVersions(anyString(), anyString(), any());
    verify(providerParameterCalculator).get(allocateRequest);
    verify(providerParameterCalculator, never()).get(networkRequest);
    verify(subnetListerService).listSubnets(any(), any());
    verify(subnetChooserService).chooseSubnets(anyList(), any(), any());
    verify(networkParameterAdder).addSubnetIds(any(), any(), any(), any());
    verify(userGeneratorService).generateUserName();
    verify(passwordGeneratorService).generatePassword(any());
}
Also used : StackTags(com.sequenceiq.cloudbreak.cloud.model.StackTags) TagResponse(com.sequenceiq.environment.api.v1.environment.model.response.TagResponse) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with TagResponse

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

the class AllocateDatabaseServerV4RequestToDBStackConverterTest method conversionTestWhenOptionalElementsAreProvided.

@Test
void conversionTestWhenOptionalElementsAreProvided() throws IOException {
    setupAllocateRequest(true);
    when(databaseServerSslCertificateConfig.getNumberOfCertsByCloudPlatformAndRegion(AWS_CLOUD_PLATFORM.name(), REGION)).thenReturn(SINGLE_CERT);
    when(databaseServerSslCertificateConfig.getCertByCloudPlatformAndRegionAndVersion(AWS_CLOUD_PLATFORM.name(), REGION, VERSION_3)).thenReturn(sslCertificateEntryV3);
    DetailedEnvironmentResponse environment = DetailedEnvironmentResponse.builder().withCloudPlatform(AWS_CLOUD_PLATFORM.name()).withCrn(ENVIRONMENT_CRN).withLocation(LocationResponse.LocationResponseBuilder.aLocationResponse().withName(REGION).build()).withName(ENVIRONMENT_NAME).withTag(new TagResponse()).build();
    when(environmentService.getByCrn(ENVIRONMENT_CRN)).thenReturn(environment);
    DBStack dbStack = underTest.convert(allocateRequest, OWNER_CRN);
    assertEquals(allocateRequest.getName(), dbStack.getName());
    assertEquals(allocateRequest.getEnvironmentCrn(), dbStack.getEnvironmentId());
    assertEquals(REGION, dbStack.getRegion());
    assertEquals(AWS_CLOUD_PLATFORM.name(), dbStack.getCloudPlatform());
    assertEquals(AWS_CLOUD_PLATFORM.name(), dbStack.getPlatformVariant());
    assertEquals(1, dbStack.getParameters().size());
    assertEquals("value", dbStack.getParameters().get("key"));
    assertEquals(Crn.safeFromString(OWNER_CRN), dbStack.getOwnerCrn());
    assertEquals(USER_EMAIL, dbStack.getUserName());
    assertEquals(Status.REQUESTED, dbStack.getStatus());
    assertEquals(DetailedDBStackStatus.PROVISION_REQUESTED, dbStack.getDbStackStatus().getDetailedDBStackStatus());
    assertEquals(NOW.toEpochMilli(), dbStack.getDbStackStatus().getCreated().longValue());
    assertEquals("n-uuid", dbStack.getNetwork().getName());
    assertEquals(1, dbStack.getNetwork().getAttributes().getMap().size());
    assertEquals("netvalue", dbStack.getNetwork().getAttributes().getMap().get("netkey"));
    assertEquals("dbsvr-uuid", dbStack.getDatabaseServer().getName());
    assertEquals(databaseServerRequest.getInstanceType(), dbStack.getDatabaseServer().getInstanceType());
    assertEquals(DatabaseVendor.fromValue(databaseServerRequest.getDatabaseVendor()), dbStack.getDatabaseServer().getDatabaseVendor());
    assertEquals("org.postgresql.Driver", dbStack.getDatabaseServer().getConnectionDriver());
    assertEquals(databaseServerRequest.getStorageSize(), dbStack.getDatabaseServer().getStorageSize());
    assertEquals(databaseServerRequest.getRootUserName(), dbStack.getDatabaseServer().getRootUserName());
    assertEquals(databaseServerRequest.getRootUserPassword(), dbStack.getDatabaseServer().getRootPassword());
    assertEquals(2, dbStack.getDatabaseServer().getAttributes().getMap().size());
    assertEquals("dbvalue", dbStack.getDatabaseServer().getAttributes().getMap().get("dbkey"));
    assertEquals(REDBEAMS_DB_MAJOR_VERSION, dbStack.getDatabaseServer().getAttributes().getMap().get("engineVersion"));
    assertEquals(securityGroupRequest.getSecurityGroupIds(), dbStack.getDatabaseServer().getSecurityGroup().getSecurityGroupIds());
    assertEquals(dbStack.getTags().get(StackTags.class).getUserDefinedTags().get("DistroXKey1"), "DistroXValue1");
    verifySsl(dbStack, Set.of(CERT_PEM_V3), CLOUD_PROVIDER_IDENTIFIER_V3);
    verify(databaseServerSslCertificateConfig, never()).getCertsByCloudPlatformAndRegionAndVersions(anyString(), anyString(), any());
    verify(providerParameterCalculator).get(allocateRequest);
    verify(providerParameterCalculator).get(networkRequest);
    verify(subnetListerService, never()).listSubnets(any(), any());
    verify(subnetChooserService, never()).chooseSubnets(anyList(), any(), any());
    verify(networkParameterAdder, never()).addSubnetIds(any(), any(), any(), any());
    verify(userGeneratorService, never()).generateUserName();
    verify(passwordGeneratorService, never()).generatePassword(any());
}
Also used : StackTags(com.sequenceiq.cloudbreak.cloud.model.StackTags) TagResponse(com.sequenceiq.environment.api.v1.environment.model.response.TagResponse) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

TagResponse (com.sequenceiq.environment.api.v1.environment.model.response.TagResponse)6 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)5 StackTags (com.sequenceiq.cloudbreak.cloud.model.StackTags)2 DBStack (com.sequenceiq.redbeams.domain.stack.DBStack)2 Test (org.junit.jupiter.api.Test)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)1 ClusterV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.ClusterV4Request)1 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)1 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)1 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)1 CDPTagMergeRequest (com.sequenceiq.cloudbreak.tag.request.CDPTagMergeRequest)1 Telemetry (com.sequenceiq.common.api.telemetry.model.Telemetry)1 EnvironmentNetworkResponse (com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1