Search in sources :

Example 1 with SimpleEnvironmentResponse

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

the class EnvironmentServiceDecorator method prepareEnvironments.

public void prepareEnvironments(Set<ClusterTemplateViewV4Response> clusterTemplateViewV4Responses) {
    LOGGER.debug("Decorating with environment name the following cluster definition(s): {}", clusterTemplateViewV4Responses.stream().map(CompactViewV4Response::getName).collect(toSet()));
    Collection<SimpleEnvironmentResponse> responses = environmentClientService.list().getResponses();
    for (ClusterTemplateViewV4Response clusterTemplateViewV4Response : clusterTemplateViewV4Responses) {
        Optional<SimpleEnvironmentResponse> first = responses.stream().filter(x -> x.getCrn().equals(clusterTemplateViewV4Response.getEnvironmentCrn())).findFirst();
        first.ifPresentOrElse(simpleEnvironmentResponse -> clusterTemplateViewV4Response.setEnvironmentName(simpleEnvironmentResponse.getName()), () -> LOGGER.info("Unable to find environment name for cluster definition \"{}\"", clusterTemplateViewV4Response.getName()));
    }
}
Also used : Logger(org.slf4j.Logger) ClusterTemplateViewV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.clustertemplate.responses.ClusterTemplateViewV4Response) CompactViewV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.common.CompactViewV4Response) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) EnvironmentClientService(com.sequenceiq.cloudbreak.service.environment.EnvironmentClientService) ClusterTemplateV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.clustertemplate.responses.ClusterTemplateV4Response) StackViewV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response) CredentialViewResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialViewResponse) NameOrCrn(com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn) CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse) Inject(javax.inject.Inject) SimpleEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.SimpleEnvironmentResponse) Service(org.springframework.stereotype.Service) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) Optional(java.util.Optional) Collectors.toSet(java.util.stream.Collectors.toSet) StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) SimpleEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.SimpleEnvironmentResponse) CompactViewV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.common.CompactViewV4Response) ClusterTemplateViewV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.clustertemplate.responses.ClusterTemplateViewV4Response)

Example 2 with SimpleEnvironmentResponse

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

the class EnvironmentResponseConverterTest method testDtoToSimpleResponse.

@ParameterizedTest
@EnumSource(value = CloudPlatform.class, names = { "AWS", "AZURE" })
void testDtoToSimpleResponse(CloudPlatform cloudPlatform) {
    EnvironmentDto environmentDto = createEnvironmentDto(cloudPlatform);
    CredentialViewResponse credentialResponse = mock(CredentialViewResponse.class);
    FreeIpaResponse freeIpaResponse = mock(FreeIpaResponse.class);
    CompactRegionResponse compactRegionResponse = mock(CompactRegionResponse.class);
    TelemetryResponse telemetryResponse = mock(TelemetryResponse.class);
    ProxyViewResponse proxyResponse = mock(ProxyViewResponse.class);
    EnvironmentNetworkResponse environmentNetworkResponse = mock(EnvironmentNetworkResponse.class);
    when(credentialViewConverter.convertResponse(environmentDto.getCredential())).thenReturn(credentialResponse);
    when(freeIpaConverter.convert(environmentDto.getFreeIpaCreation())).thenReturn(freeIpaResponse);
    when(regionConverter.convertRegions(environmentDto.getRegions())).thenReturn(compactRegionResponse);
    when(telemetryApiConverter.convert(environmentDto.getTelemetry())).thenReturn(telemetryResponse);
    when(proxyConfigToProxyResponseConverter.convertToView(environmentDto.getProxyConfig())).thenReturn(proxyResponse);
    when(networkDtoToResponseConverter.convert(environmentDto.getNetwork(), environmentDto.getExperimentalFeatures().getTunnel(), false)).thenReturn(environmentNetworkResponse);
    SimpleEnvironmentResponse actual = underTest.dtoToSimpleResponse(environmentDto, true, true);
    assertEquals(environmentDto.getResourceCrn(), actual.getCrn());
    assertEquals(environmentDto.getName(), actual.getName());
    assertEquals(environmentDto.getOriginalName(), actual.getOriginalName());
    assertEquals(environmentDto.getDescription(), actual.getDescription());
    assertEquals(environmentDto.getCloudPlatform(), actual.getCloudPlatform());
    assertEquals(credentialResponse, actual.getCredential());
    assertEquals(environmentDto.getStatus().getResponseStatus(), actual.getEnvironmentStatus());
    assertEquals(environmentDto.getCreator(), actual.getCreator());
    assertLocation(environmentDto.getLocation(), actual.getLocation());
    assertTrue(actual.getCreateFreeIpa());
    assertEquals(freeIpaResponse, actual.getFreeIpa());
    assertEquals(environmentDto.getStatusReason(), actual.getStatusReason());
    assertEquals(environmentDto.getCreated(), actual.getCreated());
    assertEquals(environmentDto.getExperimentalFeatures().getTunnel(), actual.getTunnel());
    assertEquals(environmentDto.getExperimentalFeatures().getCcmV2TlsType(), actual.getCcmV2TlsType());
    assertEquals(environmentDto.getAdminGroupName(), actual.getAdminGroupName());
    assertEquals(environmentDto.getTags().getUserDefinedTags(), actual.getTags().getUserDefined());
    assertEquals(environmentDto.getTags().getDefaultTags(), actual.getTags().getDefaults());
    assertEquals(telemetryResponse, actual.getTelemetry());
    assertEquals(compactRegionResponse, actual.getRegions());
    assertParameters(environmentDto, actual, cloudPlatform);
    assertEquals(environmentDto.getParentEnvironmentName(), actual.getParentEnvironmentName());
    assertEquals(proxyResponse, actual.getProxyConfig());
    assertEquals(environmentNetworkResponse, actual.getNetwork());
    verify(credentialViewConverter).convertResponse(environmentDto.getCredential());
    verify(freeIpaConverter).convert(environmentDto.getFreeIpaCreation());
    verify(regionConverter).convertRegions(environmentDto.getRegions());
    verify(telemetryApiConverter).convert(environmentDto.getTelemetry());
    verify(proxyConfigToProxyResponseConverter).convertToView(environmentDto.getProxyConfig());
    verify(networkDtoToResponseConverter).convert(environmentDto.getNetwork(), environmentDto.getExperimentalFeatures().getTunnel(), false);
}
Also used : CredentialViewResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialViewResponse) TelemetryResponse(com.sequenceiq.common.api.telemetry.response.TelemetryResponse) CompactRegionResponse(com.sequenceiq.environment.api.v1.environment.model.response.CompactRegionResponse) ProxyViewResponse(com.sequenceiq.environment.api.v1.proxy.model.response.ProxyViewResponse) SimpleEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.SimpleEnvironmentResponse) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) FreeIpaResponse(com.sequenceiq.environment.api.v1.environment.model.response.FreeIpaResponse) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with SimpleEnvironmentResponse

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

the class EnvironmentTestDto method delete.

@Override
public void delete(TestContext testContext, SimpleEnvironmentResponse entity, EnvironmentClient client) {
    LOGGER.info("Delete resource with name: {}", entity.getName());
    EnvironmentEndpoint credentialEndpoint = client.getDefaultClient().environmentV1Endpoint();
    credentialEndpoint.deleteByName(entity.getName(), true, false);
    setName(entity.getName());
    testContext.await(this, Map.of("status", ARCHIVED));
}
Also used : EnvironmentEndpoint(com.sequenceiq.environment.api.v1.environment.endpoint.EnvironmentEndpoint)

Example 4 with SimpleEnvironmentResponse

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

the class EnvironmentDeleteAction method action.

@Override
public EnvironmentTestDto action(TestContext testContext, EnvironmentTestDto testDto, EnvironmentClient environmentClient) throws Exception {
    SimpleEnvironmentResponse delete = environmentClient.getDefaultClient().environmentV1Endpoint().deleteByCrn(testDto.getResponse().getCrn(), true, false);
    testDto.setResponseSimpleEnv(delete);
    Log.whenJson("Environment delete response: ", delete);
    return testDto;
}
Also used : SimpleEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.SimpleEnvironmentResponse)

Example 5 with SimpleEnvironmentResponse

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

the class EnvironmentServiceDecoratorTest method testPrepareEnvironmentsAndCredentialWithoutNameAndCrnWhenNameProvidedThenShouldCallGetEnvironmentList.

@Test
void testPrepareEnvironmentsAndCredentialWithoutNameAndCrnWhenNameProvidedThenShouldCallGetEnvironmentList() {
    SimpleEnvironmentResponses simpleEnvironmentResponses = new SimpleEnvironmentResponses();
    SimpleEnvironmentResponse simpleEnvironmentResponse = new SimpleEnvironmentResponse();
    CredentialViewResponse credentialViewResponse = new CredentialViewResponse();
    NameOrCrn nameOrCrn = mock(NameOrCrn.class);
    StackViewV4Response stackViewV4Response = new StackViewV4Response();
    stackViewV4Response.setEnvironmentCrn("env-crn");
    Set<StackViewV4Response> stackViewResponses = Set.of(stackViewV4Response);
    when(nameOrCrn.hasCrn()).thenReturn(false);
    when(nameOrCrn.hasName()).thenReturn(false);
    credentialViewResponse.setName("credential-name");
    simpleEnvironmentResponse.setCredential(credentialViewResponse);
    simpleEnvironmentResponse.setName("env-name");
    simpleEnvironmentResponse.setCrn("env-crn");
    simpleEnvironmentResponses.setResponses(Set.of(simpleEnvironmentResponse));
    when(environmentClientService.list()).thenReturn(simpleEnvironmentResponses);
    underTest.prepareEnvironmentsAndCredentialName(stackViewResponses, nameOrCrn);
    verify(environmentClientService, times(1)).list();
    assertEquals(stackViewResponses.iterator().next().getEnvironmentName(), "env-name");
    assertEquals(stackViewResponses.iterator().next().getCredentialName(), "credential-name");
    assertEquals(stackViewResponses.iterator().next().isGovCloud(), false);
}
Also used : CredentialViewResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialViewResponse) StackViewV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response) SimpleEnvironmentResponses(com.sequenceiq.environment.api.v1.environment.model.response.SimpleEnvironmentResponses) SimpleEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.SimpleEnvironmentResponse) NameOrCrn(com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn) Test(org.junit.jupiter.api.Test)

Aggregations

SimpleEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.SimpleEnvironmentResponse)8 CredentialViewResponse (com.sequenceiq.environment.api.v1.credential.model.response.CredentialViewResponse)3 NameOrCrn (com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn)2 StackViewV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response)2 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)2 ClusterTemplateV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.clustertemplate.responses.ClusterTemplateV4Response)1 ClusterTemplateViewV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.clustertemplate.responses.ClusterTemplateViewV4Response)1 CompactViewV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.common.CompactViewV4Response)1 StackV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response)1 ResourceCrnPayload (com.sequenceiq.cloudbreak.common.event.ResourceCrnPayload)1 EnvironmentClientService (com.sequenceiq.cloudbreak.service.environment.EnvironmentClientService)1 TelemetryResponse (com.sequenceiq.common.api.telemetry.response.TelemetryResponse)1 CredentialResponse (com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse)1 EnvironmentEndpoint (com.sequenceiq.environment.api.v1.environment.endpoint.EnvironmentEndpoint)1 CompactRegionResponse (com.sequenceiq.environment.api.v1.environment.model.response.CompactRegionResponse)1 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)1 EnvironmentNetworkResponse (com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse)1 FreeIpaResponse (com.sequenceiq.environment.api.v1.environment.model.response.FreeIpaResponse)1 SimpleEnvironmentResponses (com.sequenceiq.environment.api.v1.environment.model.response.SimpleEnvironmentResponses)1 ProxyViewResponse (com.sequenceiq.environment.api.v1.proxy.model.response.ProxyViewResponse)1