Search in sources :

Example 1 with Credential

use of com.sequenceiq.consumption.dto.Credential in project cloudbreak by hortonworks.

the class CredentialService method getCredentialByEnvCrn.

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

Example 2 with Credential

use of com.sequenceiq.consumption.dto.Credential in project cloudbreak by hortonworks.

the class CredentialToCloudCredentialConverterTest method testConvert.

@Test
public void testConvert() {
    credential = new Credential(PLATFORM, NAME, "{ \"foo\": \"bar\" }", CRN, ACCOUNT_ID);
    CloudCredential cloudCredential = underTest.convert(credential);
    assertEquals(CRN, cloudCredential.getId());
    assertEquals(NAME, cloudCredential.getName());
    assertEquals(1, cloudCredential.getParameters().size());
    assertEquals("bar", cloudCredential.getParameters().get("foo"));
    assertEquals(ACCOUNT_ID, cloudCredential.getAccountId());
}
Also used : Credential(com.sequenceiq.consumption.dto.Credential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Test(org.junit.Test)

Example 3 with Credential

use of com.sequenceiq.consumption.dto.Credential in project cloudbreak by hortonworks.

the class CredentialToCloudCredentialConverterTest method testConvertNoAttributes.

@Test
public void testConvertNoAttributes() {
    credential = new Credential(PLATFORM, NAME, null, CRN, ACCOUNT_ID);
    CloudCredential cloudCredential = underTest.convert(credential);
    assertEquals(CRN, cloudCredential.getId());
    assertEquals(NAME, cloudCredential.getName());
    assertTrue(cloudCredential.getParameters().isEmpty());
    assertEquals(ACCOUNT_ID, cloudCredential.getAccountId());
}
Also used : Credential(com.sequenceiq.consumption.dto.Credential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Test(org.junit.Test)

Example 4 with Credential

use of com.sequenceiq.consumption.dto.Credential in project cloudbreak by hortonworks.

the class CredentialServiceTest method testGetCredentialByEnvCrnSuccessful.

@Test
public void testGetCredentialByEnvCrnSuccessful() {
    CredentialResponse credentialResponse = new CredentialResponse();
    credentialResponse.setCrn(CRN);
    credentialResponse.setName(NAME);
    credentialResponse.setAccountId(ACCOUNT_ID);
    credentialResponse.setCloudPlatform(CLOUD_PLATFORM);
    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(ACCOUNT_ID, credential.getAccountId());
    assertEquals(CLOUD_PLATFORM, credential.getCloudPlatform());
    assertEquals(ATTRIBUTES, credential.getAttributes());
}
Also used : Credential(com.sequenceiq.consumption.dto.Credential) CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse) Test(org.junit.Test)

Example 5 with Credential

use of com.sequenceiq.consumption.dto.Credential in project cloudbreak by hortonworks.

the class StorageConsumptionCollectionHandler method executeOperation.

@Override
public Selectable executeOperation(HandlerEvent<StorageConsumptionCollectionHandlerEvent> event) throws Exception {
    StorageConsumptionCollectionHandlerEvent data = event.getData();
    Consumption consumption = data.getContext().getConsumption();
    String environmentCrn = consumption.getEnvironmentCrn();
    LOGGER.debug("Getting credential for environment with CRN [{}].", environmentCrn);
    Credential credential = credentialService.getCredentialByEnvCrn(environmentCrn);
    credentialConverter.convert(credential);
    Long resourceId = data.getResourceId();
    String resourceCrn = data.getResourceCrn();
    LOGGER.debug("Storage consumption collection started. resourceCrn: '{}'", resourceCrn);
    return StorageConsumptionCollectionEvent.builder().withResourceCrn(resourceCrn).withResourceId(resourceId).withSelector(SEND_CONSUMPTION_EVENT_EVENT.selector()).build();
}
Also used : StorageConsumptionCollectionHandlerEvent(com.sequenceiq.consumption.flow.consumption.storage.event.StorageConsumptionCollectionHandlerEvent) Consumption(com.sequenceiq.consumption.domain.Consumption) Credential(com.sequenceiq.consumption.dto.Credential)

Aggregations

Credential (com.sequenceiq.consumption.dto.Credential)5 Test (org.junit.Test)3 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)2 CredentialResponse (com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse)2 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)1 SecretResponse (com.sequenceiq.cloudbreak.service.secret.model.SecretResponse)1 Consumption (com.sequenceiq.consumption.domain.Consumption)1 StorageConsumptionCollectionHandlerEvent (com.sequenceiq.consumption.flow.consumption.storage.event.StorageConsumptionCollectionHandlerEvent)1 BadRequestException (javax.ws.rs.BadRequestException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Response (javax.ws.rs.core.Response)1