Search in sources :

Example 6 with Consumption

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;
}
Also used : Consumption(com.sequenceiq.consumption.domain.Consumption)

Example 7 with 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;
}
Also used : Consumption(com.sequenceiq.consumption.domain.Consumption) CDPConsumptionStructuredFlowEvent(com.sequenceiq.cloudbreak.structuredevent.event.cdp.consumption.CDPConsumptionStructuredFlowEvent) CDPOperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails)

Example 8 with Consumption

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);
}
Also used : Consumption(com.sequenceiq.consumption.domain.Consumption) InternalOnly(com.sequenceiq.authorization.annotation.InternalOnly)

Example 9 with 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());
}
Also used : Consumption(com.sequenceiq.consumption.domain.Consumption) StorageConsumptionCollectionHandlerEvent(com.sequenceiq.consumption.flow.consumption.storage.event.StorageConsumptionCollectionHandlerEvent) ConsumptionContext(com.sequenceiq.consumption.flow.consumption.ConsumptionContext) StorageConsumptionCollectionEvent(com.sequenceiq.consumption.flow.consumption.storage.event.StorageConsumptionCollectionEvent) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) HandlerEvent(com.sequenceiq.flow.reactor.api.handler.HandlerEvent) StorageConsumptionCollectionHandlerEvent(com.sequenceiq.consumption.flow.consumption.storage.event.StorageConsumptionCollectionHandlerEvent) Test(org.junit.jupiter.api.Test)

Example 10 with Consumption

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();
}
Also used : StorageConsumptionCollectionHandlerEvent(com.sequenceiq.consumption.flow.consumption.storage.event.StorageConsumptionCollectionHandlerEvent) Consumption(com.sequenceiq.consumption.domain.Consumption) Credential(com.sequenceiq.consumption.dto.Credential)

Aggregations

Consumption (com.sequenceiq.consumption.domain.Consumption)10 Test (org.junit.jupiter.api.Test)4 ConsumptionCreationDto (com.sequenceiq.consumption.dto.ConsumptionCreationDto)3 StorageConsumptionCollectionHandlerEvent (com.sequenceiq.consumption.flow.consumption.storage.event.StorageConsumptionCollectionHandlerEvent)2 InternalOnly (com.sequenceiq.authorization.annotation.InternalOnly)1 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)1 CDPOperationDetails (com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails)1 CDPConsumptionStructuredFlowEvent (com.sequenceiq.cloudbreak.structuredevent.event.cdp.consumption.CDPConsumptionStructuredFlowEvent)1 Credential (com.sequenceiq.consumption.dto.Credential)1 ConsumptionContext (com.sequenceiq.consumption.flow.consumption.ConsumptionContext)1 StorageConsumptionCollectionEvent (com.sequenceiq.consumption.flow.consumption.storage.event.StorageConsumptionCollectionEvent)1 HandlerEvent (com.sequenceiq.flow.reactor.api.handler.HandlerEvent)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1