Search in sources :

Example 1 with StorageConsumptionCollectionHandlerEvent

use of com.sequenceiq.consumption.flow.consumption.storage.event.StorageConsumptionCollectionHandlerEvent in project cloudbreak by hortonworks.

the class SendConsumptionEventHandler method executeOperation.

@Override
public Selectable executeOperation(HandlerEvent<StorageConsumptionCollectionHandlerEvent> event) throws Exception {
    StorageConsumptionCollectionHandlerEvent data = event.getData();
    Long resourceId = data.getResourceId();
    String resourceCrn = data.getResourceCrn();
    LOGGER.debug("Sending storage consumption event started. resourceCrn: '{}'", resourceCrn);
    return StorageConsumptionCollectionEvent.builder().withResourceCrn(resourceCrn).withResourceId(resourceId).withSelector(STORAGE_CONSUMPTION_COLLECTION_FINISH_EVENT.selector()).build();
}
Also used : StorageConsumptionCollectionHandlerEvent(com.sequenceiq.consumption.flow.consumption.storage.event.StorageConsumptionCollectionHandlerEvent)

Example 2 with StorageConsumptionCollectionHandlerEvent

use of com.sequenceiq.consumption.flow.consumption.storage.event.StorageConsumptionCollectionHandlerEvent in project cloudbreak by hortonworks.

the class StorageConsumptionCollectionActions method storageConsumptionCollectionAction.

@Bean(name = "STORAGE_CONSUMPTION_COLLECTION_STATE")
public Action<?, ?> storageConsumptionCollectionAction() {
    return new AbstractStorageConsumptionCollectionAction<>(StorageConsumptionCollectionEvent.class) {

        @Override
        protected void doExecute(ConsumptionContext context, StorageConsumptionCollectionEvent payload, Map<Object, Object> variables) {
            String resourceCrn = payload.getResourceCrn();
            LOGGER.debug("Flow entered into STORAGE_CONSUMPTION_COLLECTION_STATE. resourceCrn: '{}'", resourceCrn);
            StorageConsumptionCollectionHandlerEvent event = new StorageConsumptionCollectionHandlerEvent(StorageConsumptionCollectionHandlerSelectors.STORAGE_CONSUMPTION_COLLECTION_HANDLER.selector(), payload.getResourceId(), resourceCrn, context);
            sendEvent(context, event);
        }
    };
}
Also used : 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) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 3 with StorageConsumptionCollectionHandlerEvent

use of com.sequenceiq.consumption.flow.consumption.storage.event.StorageConsumptionCollectionHandlerEvent in project cloudbreak by hortonworks.

the class StorageConsumptionCollectionActions method sendConsumptionEventAction.

@Bean(name = "SEND_CONSUMPTION_EVENT_STATE")
public Action<?, ?> sendConsumptionEventAction() {
    return new AbstractStorageConsumptionCollectionAction<>(StorageConsumptionCollectionEvent.class) {

        @Override
        protected void doExecute(ConsumptionContext context, StorageConsumptionCollectionEvent payload, Map<Object, Object> variables) {
            String resourceCrn = payload.getResourceCrn();
            LOGGER.debug("Flow entered into SEND_CONSUMPTION_EVENT_STATE. resourceCrn: '{}'", resourceCrn);
            StorageConsumptionCollectionHandlerEvent event = new StorageConsumptionCollectionHandlerEvent(StorageConsumptionCollectionHandlerSelectors.SEND_CONSUMPTION_EVENT_HANDLER.selector(), payload.getResourceId(), resourceCrn, context);
            sendEvent(context, event);
        }
    };
}
Also used : 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) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 4 with StorageConsumptionCollectionHandlerEvent

use of com.sequenceiq.consumption.flow.consumption.storage.event.StorageConsumptionCollectionHandlerEvent in project cloudbreak by hortonworks.

the class SendConsumptionEventHandlerTest method testExecuteOperation.

@Test
public void testExecuteOperation() {
    String resourceCrn = "consumptionCrn";
    Long resourceId = 1L;
    StorageConsumptionCollectionHandlerEvent event = new StorageConsumptionCollectionHandlerEvent(SEND_CONSUMPTION_EVENT_HANDLER.selector(), resourceId, resourceCrn, null);
    StorageConsumptionCollectionEvent result = (StorageConsumptionCollectionEvent) underTest.doAccept(new HandlerEvent<>(new Event<>(event)));
    assertEquals(resourceCrn, result.getResourceCrn());
    assertEquals(resourceId, result.getResourceId());
    assertEquals(STORAGE_CONSUMPTION_COLLECTION_FINISH_EVENT.selector(), result.selector());
}
Also used : StorageConsumptionCollectionHandlerEvent(com.sequenceiq.consumption.flow.consumption.storage.event.StorageConsumptionCollectionHandlerEvent) StorageConsumptionCollectionEvent(com.sequenceiq.consumption.flow.consumption.storage.event.StorageConsumptionCollectionEvent) StorageConsumptionCollectionHandlerEvent(com.sequenceiq.consumption.flow.consumption.storage.event.StorageConsumptionCollectionHandlerEvent) HandlerEvent(com.sequenceiq.flow.reactor.api.handler.HandlerEvent) Test(org.junit.jupiter.api.Test)

Example 5 with StorageConsumptionCollectionHandlerEvent

use of com.sequenceiq.consumption.flow.consumption.storage.event.StorageConsumptionCollectionHandlerEvent 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)

Aggregations

StorageConsumptionCollectionHandlerEvent (com.sequenceiq.consumption.flow.consumption.storage.event.StorageConsumptionCollectionHandlerEvent)6 StorageConsumptionCollectionEvent (com.sequenceiq.consumption.flow.consumption.storage.event.StorageConsumptionCollectionEvent)4 ConsumptionContext (com.sequenceiq.consumption.flow.consumption.ConsumptionContext)3 Consumption (com.sequenceiq.consumption.domain.Consumption)2 HandlerEvent (com.sequenceiq.flow.reactor.api.handler.HandlerEvent)2 Map (java.util.Map)2 Test (org.junit.jupiter.api.Test)2 Bean (org.springframework.context.annotation.Bean)2 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)1 Credential (com.sequenceiq.consumption.dto.Credential)1