Search in sources :

Example 1 with StorageUnitNotificationEventParamsDto

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());
    }
}
Also used : StorageUnitNotificationEventParamsDto(org.finra.herd.model.dto.StorageUnitNotificationEventParamsDto) Test(org.junit.Test)

Example 2 with StorageUnitNotificationEventParamsDto

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());
    }
}
Also used : StorageUnitNotificationEventParamsDto(org.finra.herd.model.dto.StorageUnitNotificationEventParamsDto) Test(org.junit.Test)

Example 3 with StorageUnitNotificationEventParamsDto

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;
}
Also used : ArrayList(java.util.ArrayList) SchemaColumn(org.finra.herd.model.api.xml.SchemaColumn) StorageUnitNotificationEventParamsDto(org.finra.herd.model.dto.StorageUnitNotificationEventParamsDto) NotificationJobActionEntity(org.finra.herd.model.jpa.NotificationJobActionEntity) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) BusinessObjectFormat(org.finra.herd.model.api.xml.BusinessObjectFormat) BusinessObjectFormatKey(org.finra.herd.model.api.xml.BusinessObjectFormatKey) StorageUnitNotificationRegistrationEntity(org.finra.herd.model.jpa.StorageUnitNotificationRegistrationEntity) NotificationActionEntity(org.finra.herd.model.jpa.NotificationActionEntity)

Example 4 with StorageUnitNotificationEventParamsDto

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.");
    }
}
Also used : JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) StorageUnitNotificationEventParamsDto(org.finra.herd.model.dto.StorageUnitNotificationEventParamsDto) StorageUnitNotificationRegistrationEntity(org.finra.herd.model.jpa.StorageUnitNotificationRegistrationEntity) JobCreateRequest(org.finra.herd.model.api.xml.JobCreateRequest)

Example 5 with 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));
}
Also used : JobAction(org.finra.herd.model.api.xml.JobAction) ArrayList(java.util.ArrayList) StorageUnitNotificationEventParamsDto(org.finra.herd.model.dto.StorageUnitNotificationEventParamsDto) StorageUnitNotificationRegistrationEntity(org.finra.herd.model.jpa.StorageUnitNotificationRegistrationEntity) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) JobDefinition(org.finra.herd.model.api.xml.JobDefinition) NotificationRegistrationKey(org.finra.herd.model.api.xml.NotificationRegistrationKey) Test(org.junit.Test)

Aggregations

StorageUnitNotificationEventParamsDto (org.finra.herd.model.dto.StorageUnitNotificationEventParamsDto)5 StorageUnitNotificationRegistrationEntity (org.finra.herd.model.jpa.StorageUnitNotificationRegistrationEntity)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)1 BusinessObjectFormat (org.finra.herd.model.api.xml.BusinessObjectFormat)1 BusinessObjectFormatKey (org.finra.herd.model.api.xml.BusinessObjectFormatKey)1 JobAction (org.finra.herd.model.api.xml.JobAction)1 JobCreateRequest (org.finra.herd.model.api.xml.JobCreateRequest)1 JobDefinition (org.finra.herd.model.api.xml.JobDefinition)1 NotificationRegistrationKey (org.finra.herd.model.api.xml.NotificationRegistrationKey)1 SchemaColumn (org.finra.herd.model.api.xml.SchemaColumn)1 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)1 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)1 JobDefinitionEntity (org.finra.herd.model.jpa.JobDefinitionEntity)1 NotificationActionEntity (org.finra.herd.model.jpa.NotificationActionEntity)1 NotificationJobActionEntity (org.finra.herd.model.jpa.NotificationJobActionEntity)1