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);
}
}
}
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());
}
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());
}
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());
}
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();
}
Aggregations