Search in sources :

Example 31 with CredentialResponse

use of com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse 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);
}
Also used : CompactRegionResponse(com.sequenceiq.environment.api.v1.environment.model.response.CompactRegionResponse) ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) Credential(com.sequenceiq.cloudbreak.dto.credential.Credential) Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace) Before(org.junit.Before)

Example 32 with CredentialResponse

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

the class CredentialServiceTest method testNonAzureCredential.

@Test
public void testNonAzureCredential() {
    CredentialResponse credentialResponse = new CredentialResponse();
    credentialResponse.setCrn(CRN);
    credentialResponse.setName(NAME);
    credentialResponse.setAttributes(secretResponse);
    when(credentialEndpoint.getByEnvironmentCrn(ENVIRONMENT_CRN)).thenReturn(credentialResponse);
    Credential credential = underTest.getCredentialByEnvCrn(ENVIRONMENT_CRN);
    assertEquals(CRN, credential.getCrn());
    assertEquals(NAME, credential.getName());
    assertEquals(ATTRIBUTES, credential.getAttributes());
    assertFalse(credential.getAzure().isPresent());
}
Also used : Credential(com.sequenceiq.redbeams.dto.Credential) CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse) Test(org.junit.Test)

Example 33 with CredentialResponse

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

the class CredentialService method getCredentialByEnvCrn.

public Credential getCredentialByEnvCrn(String envCrn) {
    CredentialResponse credentialResponse = null;
    try {
        credentialResponse = credentialEndpoint.getByEnvironmentCrn(envCrn);
    } catch (ClientErrorException e) {
        try (Response response = e.getResponse()) {
            if (Response.Status.NOT_FOUND.getStatusCode() == response.getStatus()) {
                throw new BadRequestException(String.format("Credential not found by environment CRN: %s", envCrn), e);
            }
            String errorMessage = webApplicationExceptionMessageExtractor.getErrorMessage(e);
            throw new CloudbreakServiceException(String.format("Failed to get credential: %s", errorMessage), e);
        }
    }
    SecretResponse secretResponse = credentialResponse.getAttributes();
    String attributes = secretService.getByResponse(secretResponse);
    return new Credential(credentialResponse.getCloudPlatform(), credentialResponse.getName(), attributes, credentialResponse.getCrn(), credentialResponse.getAccountId());
}
Also used : Response(javax.ws.rs.core.Response) SecretResponse(com.sequenceiq.cloudbreak.service.secret.model.SecretResponse) CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse) SecretResponse(com.sequenceiq.cloudbreak.service.secret.model.SecretResponse) Credential(com.sequenceiq.freeipa.dto.Credential) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) ClientErrorException(javax.ws.rs.ClientErrorException) BadRequestException(javax.ws.rs.BadRequestException) CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse)

Aggregations

CredentialResponse (com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse)29 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)12 Test (org.junit.jupiter.api.Test)10 InteractiveCredentialResponse (com.sequenceiq.environment.api.v1.credential.model.response.InteractiveCredentialResponse)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)5 CompactRegionResponse (com.sequenceiq.environment.api.v1.environment.model.response.CompactRegionResponse)5 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)4 EnvironmentNetworkResponse (com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse)4 BadRequestException (javax.ws.rs.BadRequestException)4 NameOrCrn (com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn)3 StackViewV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response)3 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)3 Before (org.junit.Before)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)2 Json (com.sequenceiq.cloudbreak.common.json.Json)2 Credential (com.sequenceiq.cloudbreak.dto.credential.Credential)2 SecretResponse (com.sequenceiq.cloudbreak.service.secret.model.SecretResponse)2 BackupResponse (com.sequenceiq.common.api.backup.response.BackupResponse)2