use of org.finra.herd.model.dto.StorageUnitNotificationEventParamsDto in project herd by FINRAOS.
the class BusinessObjectDataNotificationJobActionServiceTest method testPerformNotificationActionInvalidParamsDto.
@Test
public void testPerformNotificationActionInvalidParamsDto() throws Exception {
// Get the notification action service for the business object data registration event.
NotificationActionService notificationActionService = notificationActionFactory.getNotificationActionHandler(NotificationTypeEntity.NOTIFICATION_TYPE_BDATA, NotificationEventTypeEntity.EventTypesBdata.BUS_OBJCT_DATA_RGSTN.name());
// Try to perform a notification action for the business object data registration event with an invalid type of the parameters DTO.
try {
notificationActionService.performNotificationAction(new StorageUnitNotificationEventParamsDto());
fail();
} catch (IllegalStateException e) {
assertEquals("Notification event parameters DTO passed to the method must be an instance of BusinessObjectDataNotificationEventParamsDto.", e.getMessage());
}
}
use of org.finra.herd.model.dto.StorageUnitNotificationEventParamsDto in project herd by FINRAOS.
the class BusinessObjectDataNotificationJobActionServiceTest method testGetIdentifyingInformationInvalidParamsDto.
@Test
public void testGetIdentifyingInformationInvalidParamsDto() {
// Get the notification action service for the business object data registration event.
NotificationActionService notificationActionService = notificationActionFactory.getNotificationActionHandler(NotificationTypeEntity.NOTIFICATION_TYPE_BDATA, NotificationEventTypeEntity.EventTypesBdata.BUS_OBJCT_DATA_RGSTN.name());
// Try to retrieve the identifying information for the notification event using an invalid type of the parameters DTO.
try {
notificationActionService.getIdentifyingInformation(new StorageUnitNotificationEventParamsDto(), businessObjectDataHelper);
fail();
} catch (IllegalStateException e) {
assertEquals("Notification event parameters DTO passed to the method must be an instance of BusinessObjectDataNotificationEventParamsDto.", e.getMessage());
}
}
use of org.finra.herd.model.dto.StorageUnitNotificationEventParamsDto in project herd by FINRAOS.
the class NotificationEventServiceImpl method processStorageUnitNotifications.
private List<Object> processStorageUnitNotifications(String notificationEventType, List<StorageUnitNotificationRegistrationEntity> storageUnitNotificationRegistrationEntities, BusinessObjectData businessObjectData, String storageName, String newStorageUnitStatus, String oldStorageUnitStatus) {
List<Object> notificationActions = new ArrayList<>();
// Build a list of partition value that includes primary and sub-partition values, if any are specified in the business object data key.
List<String> partitionValues = businessObjectDataHelper.getPrimaryAndSubPartitionValues(businessObjectData);
// Get a list of partition columns from the associated business object format.
List<String> partitionColumnNames = null;
BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDao.getBusinessObjectFormatByAltKey(new BusinessObjectFormatKey(businessObjectData.getNamespace(), businessObjectData.getBusinessObjectDefinitionName(), businessObjectData.getBusinessObjectFormatUsage(), businessObjectData.getBusinessObjectFormatFileType(), businessObjectData.getBusinessObjectFormatVersion()));
if (businessObjectFormatEntity != null) {
// Get business object format model object to directly access schema columns and partitions.
BusinessObjectFormat businessObjectFormat = businessObjectFormatHelper.createBusinessObjectFormatFromEntity(businessObjectFormatEntity);
// Proceed only if this format has schema with partition columns specified.
if (businessObjectFormat.getSchema() != null && !CollectionUtils.isEmpty(businessObjectFormat.getSchema().getPartitions())) {
// Do not provide more partition column names than there are primary and
// sub-partition values that this business object data is registered with.
partitionColumnNames = new ArrayList<>();
List<SchemaColumn> partitionColumns = businessObjectFormat.getSchema().getPartitions();
for (int i = 0; i < Math.min(partitionValues.size(), partitionColumns.size()); i++) {
partitionColumnNames.add(partitionColumns.get(i).getName());
}
}
}
for (StorageUnitNotificationRegistrationEntity storageUnitNotificationRegistration : storageUnitNotificationRegistrationEntities) {
// Retrieve the job notification actions needed to be triggered.
for (NotificationActionEntity notificationActionEntity : storageUnitNotificationRegistration.getNotificationActions()) {
// Trigger the job action.
if (notificationActionEntity instanceof NotificationJobActionEntity) {
NotificationJobActionEntity notificationJobActionEntity = (NotificationJobActionEntity) notificationActionEntity;
StorageUnitNotificationEventParamsDto notificationEventParams = new StorageUnitNotificationEventParamsDto();
notificationEventParams.setStorageUnitNotificationRegistration(storageUnitNotificationRegistration);
notificationEventParams.setNotificationJobAction(notificationJobActionEntity);
notificationEventParams.setEventType(notificationEventType);
notificationEventParams.setBusinessObjectData(businessObjectData);
notificationEventParams.setPartitionColumnNames(partitionColumnNames);
notificationEventParams.setStorageName(storageName);
notificationEventParams.setPartitionValues(partitionValues);
notificationEventParams.setNewStorageUnitStatus(newStorageUnitStatus);
notificationEventParams.setOldStorageUnitStatus(oldStorageUnitStatus);
notificationActions.add(triggerNotificationAction(NotificationTypeEntity.NOTIFICATION_TYPE_STORAGE_UNIT, notificationEventType, notificationEventParams));
}
}
}
return notificationActions;
}
use of org.finra.herd.model.dto.StorageUnitNotificationEventParamsDto in project herd by FINRAOS.
the class StorageUnitStatusChangeNotificationJobActionServiceImpl method performNotificationAction.
@Override
public Object performNotificationAction(NotificationEventParamsDto notificationEventParams) throws Exception {
if (notificationEventParams instanceof StorageUnitNotificationEventParamsDto) {
StorageUnitNotificationEventParamsDto storageUnitNotificationEventParams = (StorageUnitNotificationEventParamsDto) notificationEventParams;
JobCreateRequest request = new JobCreateRequest();
JobDefinitionEntity jobDefinitionEntity = storageUnitNotificationEventParams.getNotificationJobAction().getJobDefinition();
request.setNamespace(jobDefinitionEntity.getNamespace().getCode());
request.setJobName(jobDefinitionEntity.getName());
request.setParameters(buildJobParameters(storageUnitNotificationEventParams));
/*
* Log enough information so we can trace back what notification registration triggered what workflow.
* This also allows us to reproduce the workflow execution if needed by logging the entire jobCreateRequest in JSON format.
*/
if (LOGGER.isInfoEnabled()) {
StorageUnitNotificationRegistrationEntity storageUnitNotificationRegistration = storageUnitNotificationEventParams.getStorageUnitNotificationRegistration();
LOGGER.info("Starting a job due to a notification. notificationRegistrationKey={} jobCreateRequest={}", jsonHelper.objectToJson(notificationRegistrationHelper.getNotificationRegistrationKey(storageUnitNotificationRegistration)), jsonHelper.objectToJson(request));
}
return jobService.createAndStartJob(request);
} else {
throw new IllegalStateException("Notification event parameters DTO passed to the method must be an instance of StorageUnitNotificationEventParamsDto.");
}
}
use of org.finra.herd.model.dto.StorageUnitNotificationEventParamsDto in project herd by FINRAOS.
the class StorageUnitStatusChangeNotificationJobActionServiceTest method testGetIdentifyingInformation.
@Test
public void testGetIdentifyingInformation() throws Exception {
// Create a job definition.
JobDefinition jobDefinition = jobDefinitionServiceTestHelper.createJobDefinition(ACTIVITI_XML_LOG_VARIABLES_NO_REGEX_WITH_CLASSPATH);
// Create a job action.
List<JobAction> jobActions = new ArrayList<>();
jobActions.add(new JobAction(jobDefinition.getNamespace(), jobDefinition.getJobName(), CORRELATION_DATA));
// Create and persist a storage unit notification registration entity.
StorageUnitNotificationRegistrationEntity storageUnitNotificationRegistrationEntity = notificationRegistrationDaoTestHelper.createStorageUnitNotificationRegistrationEntity(new NotificationRegistrationKey(NAMESPACE, NOTIFICATION_NAME), NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG.name(), BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, STORAGE_NAME, STORAGE_UNIT_STATUS, STORAGE_UNIT_STATUS_2, jobActions, NotificationRegistrationStatusEntity.ENABLED);
// Create a business object data key.
BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION);
// Create a business object data entity.
BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, LATEST_VERSION_FLAG_SET, BDATA_STATUS);
// Create and initiate an instance of the storage unit notification event parameters DTO.
StorageUnitNotificationEventParamsDto storageUnitNotificationEventParamsDto = new StorageUnitNotificationEventParamsDto();
storageUnitNotificationEventParamsDto.setBusinessObjectData(businessObjectDataHelper.createBusinessObjectDataFromEntity(businessObjectDataEntity));
storageUnitNotificationEventParamsDto.setStorageUnitNotificationRegistration(storageUnitNotificationRegistrationEntity);
storageUnitNotificationEventParamsDto.setEventType(NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG.name());
storageUnitNotificationEventParamsDto.setNotificationJobAction((NotificationJobActionEntity) storageUnitNotificationRegistrationEntity.getNotificationActions().toArray()[0]);
storageUnitNotificationEventParamsDto.setStorageName(STORAGE_NAME);
// Get the notification action service for the storage unit status change event.
NotificationActionService notificationActionService = notificationActionFactory.getNotificationActionHandler(NotificationTypeEntity.NOTIFICATION_TYPE_STORAGE_UNIT, NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG.name());
// Validate the identifying information for the notification event.
String expectedValue = String.format("namespace: \"%s\", actionId: \"%s\" with " + businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey) + ", storageName: \"%s\"", storageUnitNotificationRegistrationEntity.getNamespace().getCode(), ((NotificationJobActionEntity) storageUnitNotificationRegistrationEntity.getNotificationActions().toArray()[0]).getId(), STORAGE_NAME);
assertEquals(expectedValue, notificationActionService.getIdentifyingInformation(storageUnitNotificationEventParamsDto, businessObjectDataHelper));
}
Aggregations