use of com.sequenceiq.consumption.domain.Consumption in project cloudbreak by hortonworks.
the class ConsumptionDtoConverter method creationDtoToConsumption.
public Consumption creationDtoToConsumption(ConsumptionCreationDto creationDto) {
Consumption consumption = new Consumption();
consumption.setName(creationDto.getName());
consumption.setDescription(creationDto.getDescription());
consumption.setAccountId(creationDto.getAccountId());
consumption.setResourceCrn(creationDto.getResourceCrn());
consumption.setEnvironmentCrn(creationDto.getEnvironmentCrn());
consumption.setMonitoredResourceType(creationDto.getMonitoredResourceType());
consumption.setMonitoredResourceCrn(creationDto.getMonitoredResourceCrn());
consumption.setConsumptionType(creationDto.getConsumptionType());
consumption.setStorageLocation(creationDto.getStorageLocation());
return consumption;
}
use of com.sequenceiq.consumption.domain.Consumption in project cloudbreak by hortonworks.
the class ConsumptionStructuredFlowEventFactory method createStructuredFlowEvent.
@Override
public CDPStructuredFlowEvent createStructuredFlowEvent(Long resourceId, FlowDetails flowDetails, Exception exception) {
Consumption consumption = consumptionService.findConsumptionById(resourceId);
CDPOperationDetails operationDetails = new CDPOperationDetails(clock.getCurrentTimeMillis(), FLOW, CloudbreakEventService.CONSUMPTION_RESOURCE_TYPE, consumption.getId(), consumption.getName(), nodeConfig.getId(), serviceVersion, consumption.getAccountId(), consumption.getResourceCrn(), ThreadBasedUserCrnProvider.getUserCrn(), null, null);
CDPConsumptionStructuredFlowEvent event = new CDPConsumptionStructuredFlowEvent(operationDetails, flowDetails, null, null, null);
if (exception != null) {
event.setException(ExceptionUtils.getStackTrace(exception));
}
return event;
}
use of com.sequenceiq.consumption.domain.Consumption in project cloudbreak by hortonworks.
the class ConsumptionInternalV1Controller method unscheduleStorageConsumptionCollection.
@Override
@InternalOnly
public void unscheduleStorageConsumptionCollection(@AccountId String accountId, @NotNull @ValidCrn(resource = { CrnResourceDescriptor.ENVIRONMENT, CrnResourceDescriptor.DATALAKE }) String monitoredResourceCrn, @NotEmpty String storageLocation) {
Consumption consumption = consumptionService.findStorageConsumptionByMonitoredResourceCrnAndLocation(monitoredResourceCrn, storageLocation);
consumptionService.delete(consumption);
}
use of com.sequenceiq.consumption.domain.Consumption in project cloudbreak by hortonworks.
the class StorageConsumptionCollectionHandlerTest method testExecuteOperation.
@Test
public void testExecuteOperation() {
String resourceCrn = "consumptionCrn";
Long resourceId = 1L;
String envCrn = "envCrn";
Consumption consumption = new Consumption();
consumption.setResourceCrn(resourceCrn);
consumption.setId(resourceId);
consumption.setEnvironmentCrn(envCrn);
ConsumptionContext context = new ConsumptionContext(null, consumption);
StorageConsumptionCollectionHandlerEvent event = new StorageConsumptionCollectionHandlerEvent(STORAGE_CONSUMPTION_COLLECTION_HANDLER.selector(), resourceId, resourceCrn, context);
when(credentialService.getCredentialByEnvCrn(envCrn)).thenReturn(credential);
when(credentialConverter.convert(credential)).thenReturn(new CloudCredential());
StorageConsumptionCollectionEvent result = (StorageConsumptionCollectionEvent) underTest.doAccept(new HandlerEvent<>(new Event<>(event)));
verify(credentialService).getCredentialByEnvCrn(envCrn);
verify(credentialConverter).convert(credential);
assertEquals(resourceCrn, result.getResourceCrn());
assertEquals(resourceId, result.getResourceId());
assertEquals(SEND_CONSUMPTION_EVENT_EVENT.selector(), result.selector());
}
use of com.sequenceiq.consumption.domain.Consumption 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