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