/** * Expires a restored S3 storage unit. * * @param storageUnitKey the storage unit key */ protected void expireS3StorageUnitImpl(BusinessObjectDataStorageUnitKey storageUnitKey) { // Build the business object data restore DTO. BusinessObjectDataRestoreDto businessObjectDataRestoreDto = expireRestoredBusinessObjectDataHelperService.prepareToExpireStorageUnit(storageUnitKey); // Create storage unit notification for the storage unit. notificationEventService.processStorageUnitNotificationEventAsync(NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG, businessObjectDataRestoreDto.getBusinessObjectDataKey(), businessObjectDataRestoreDto.getStorageName(), businessObjectDataRestoreDto.getNewStorageUnitStatus(), businessObjectDataRestoreDto.getOldStorageUnitStatus()); // Execute the S3 specific steps required to expire business object data. expireRestoredBusinessObjectDataHelperService.executeS3SpecificSteps(businessObjectDataRestoreDto); // Execute the after step. expireRestoredBusinessObjectDataHelperService.completeStorageUnitExpiration(businessObjectDataRestoreDto); // Create storage unit notification for the storage unit. notificationEventService.processStorageUnitNotificationEventAsync(NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG, businessObjectDataRestoreDto.getBusinessObjectDataKey(), businessObjectDataRestoreDto.getStorageName(), businessObjectDataRestoreDto.getNewStorageUnitStatus(), businessObjectDataRestoreDto.getOldStorageUnitStatus()); }
/** * Expires a restored S3 storage unit. * * @param storageUnitKey the storage unit key */ protected void expireS3StorageUnitImpl(BusinessObjectDataStorageUnitKey storageUnitKey) { // Build the business object data restore DTO. BusinessObjectDataRestoreDto businessObjectDataRestoreDto = expireRestoredBusinessObjectDataHelperService.prepareToExpireStorageUnit(storageUnitKey); // Create storage unit notification for the storage unit. notificationEventService.processStorageUnitNotificationEventAsync(NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG, businessObjectDataRestoreDto.getBusinessObjectDataKey(), businessObjectDataRestoreDto.getStorageName(), businessObjectDataRestoreDto.getNewStorageUnitStatus(), businessObjectDataRestoreDto.getOldStorageUnitStatus()); // Execute the S3 specific steps required to expire business object data. expireRestoredBusinessObjectDataHelperService.executeS3SpecificSteps(businessObjectDataRestoreDto); // Execute the after step. expireRestoredBusinessObjectDataHelperService.completeStorageUnitExpiration(businessObjectDataRestoreDto); // Create storage unit notification for the storage unit. notificationEventService.processStorageUnitNotificationEventAsync(NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG, businessObjectDataRestoreDto.getBusinessObjectDataKey(), businessObjectDataRestoreDto.getStorageName(), businessObjectDataRestoreDto.getNewStorageUnitStatus(), businessObjectDataRestoreDto.getOldStorageUnitStatus()); }
@Test public void testPrepareToInitiateRestoreLowerCaseParameters() { // 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, NO_SUBPARTITION_VALUES, DATA_VERSION); // Create database entities required for testing. businessObjectDataServiceTestHelper.createDatabaseEntitiesForInitiateRestoreTesting(businessObjectDataKey); // Execute a before step for the initiate a business object data restore request // using lower case input parameters (except for case-sensitive partition values). BusinessObjectDataRestoreDto storagePolicyTransitionParamsDto = businessObjectDataInitiateRestoreHelperService.prepareToInitiateRestore( new BusinessObjectDataKey(BDEF_NAMESPACE.toLowerCase(), BDEF_NAME.toLowerCase(), FORMAT_USAGE_CODE.toLowerCase(), FORMAT_FILE_TYPE_CODE.toLowerCase(), FORMAT_VERSION, PARTITION_VALUE, NO_SUBPARTITION_VALUES, DATA_VERSION), EXPIRATION_IN_DAYS); // Validate the returned object. assertEquals(businessObjectDataKey, storagePolicyTransitionParamsDto.getBusinessObjectDataKey()); }
@Test public void testPrepareToInitiateRestoreUpperCaseParameters() { // 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, NO_SUBPARTITION_VALUES, DATA_VERSION); // Create database entities required for testing. businessObjectDataServiceTestHelper.createDatabaseEntitiesForInitiateRestoreTesting(businessObjectDataKey); // Execute a before step for the initiate a business object data restore request // using upper case input parameters (except for case-sensitive partition values). BusinessObjectDataRestoreDto storagePolicyTransitionParamsDto = businessObjectDataInitiateRestoreHelperService.prepareToInitiateRestore( new BusinessObjectDataKey(BDEF_NAMESPACE.toUpperCase(), BDEF_NAME.toUpperCase(), FORMAT_USAGE_CODE.toUpperCase(), FORMAT_FILE_TYPE_CODE.toUpperCase(), FORMAT_VERSION, PARTITION_VALUE, NO_SUBPARTITION_VALUES, DATA_VERSION), EXPIRATION_IN_DAYS); // Validate the returned object. assertEquals(businessObjectDataKey, storagePolicyTransitionParamsDto.getBusinessObjectDataKey()); } }
/** * Finalizes restore of an S3 storage unit. * * @param storageUnitKey the storage unit key */ protected void finalizeRestoreImpl(BusinessObjectDataStorageUnitKey storageUnitKey) { // Build the business object data restore DTO. BusinessObjectDataRestoreDto businessObjectDataRestoreDto = businessObjectDataFinalizeRestoreHelperService.prepareToFinalizeRestore(storageUnitKey); // Execute the S3 specific steps required to finalize the business object data restore. businessObjectDataFinalizeRestoreHelperService.executeS3SpecificSteps(businessObjectDataRestoreDto); // Execute the after step regardless if the above step failed or not. Please note that the after step returns true on success and false otherwise. businessObjectDataFinalizeRestoreHelperService.completeFinalizeRestore(businessObjectDataRestoreDto); // Create storage unit notification for the origin storage unit. notificationEventService.processStorageUnitNotificationEventAsync(NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG, businessObjectDataRestoreDto.getBusinessObjectDataKey(), businessObjectDataRestoreDto.getStorageName(), businessObjectDataRestoreDto.getNewStorageUnitStatus(), businessObjectDataRestoreDto.getOldStorageUnitStatus()); }
/** * Finalizes restore of an S3 storage unit. * * @param storageUnitKey the storage unit key */ protected void finalizeRestoreImpl(BusinessObjectDataStorageUnitKey storageUnitKey) { // Build the business object data restore DTO. BusinessObjectDataRestoreDto businessObjectDataRestoreDto = businessObjectDataFinalizeRestoreHelperService.prepareToFinalizeRestore(storageUnitKey); // Execute the S3 specific steps required to finalize the business object data restore. businessObjectDataFinalizeRestoreHelperService.executeS3SpecificSteps(businessObjectDataRestoreDto); // Execute the after step regardless if the above step failed or not. Please note that the after step returns true on success and false otherwise. businessObjectDataFinalizeRestoreHelperService.completeFinalizeRestore(businessObjectDataRestoreDto); // Create storage unit notification for the origin storage unit. notificationEventService.processStorageUnitNotificationEventAsync(NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG, businessObjectDataRestoreDto.getBusinessObjectDataKey(), businessObjectDataRestoreDto.getStorageName(), businessObjectDataRestoreDto.getNewStorageUnitStatus(), businessObjectDataRestoreDto.getOldStorageUnitStatus()); }
businessObjectDataRestoreDto.getBusinessObjectDataKey(), businessObjectDataRestoreDto.getStorageName(), businessObjectDataRestoreDto.getNewStorageUnitStatus(), businessObjectDataRestoreDto.getOldStorageUnitStatus()); businessObjectDataRestoreDto.getBusinessObjectDataKey(), businessObjectDataRestoreDto.getStorageName(), businessObjectDataRestoreDto.getNewStorageUnitStatus(), businessObjectDataRestoreDto.getOldStorageUnitStatus());
businessObjectDataRestoreDto.getBusinessObjectDataKey(), businessObjectDataRestoreDto.getStorageName(), businessObjectDataRestoreDto.getNewStorageUnitStatus(), businessObjectDataRestoreDto.getOldStorageUnitStatus()); businessObjectDataRestoreDto.getBusinessObjectDataKey(), businessObjectDataRestoreDto.getStorageName(), businessObjectDataRestoreDto.getNewStorageUnitStatus(), businessObjectDataRestoreDto.getOldStorageUnitStatus());
businessObjectDataRestoreDto.getBusinessObjectDataKey());
businessObjectDataRestoreDto.getBusinessObjectDataKey());
businessObjectDataRestoreDto.getBusinessObjectDataKey());
@Test public void testPrepareToInitiateRestore() throws Exception { // 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, NO_SUBPARTITION_VALUES, DATA_VERSION); // Create database entities required for testing. BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataServiceTestHelper.createDatabaseEntitiesForInitiateRestoreTesting(businessObjectDataKey); // Get the current time and compute the expected timestamp value. Timestamp currentTime = new Timestamp(System.currentTimeMillis()); Timestamp expectedTimestamp = HerdDateUtils.addDays(currentTime, EXPIRATION_IN_DAYS); // Execute a before step for the initiate a business object data restore request. BusinessObjectDataRestoreDto storagePolicyTransitionParamsDto = businessObjectDataInitiateRestoreHelperService.prepareToInitiateRestore(businessObjectDataKey, EXPIRATION_IN_DAYS); // Validate the returned object. assertEquals(businessObjectDataKey, storagePolicyTransitionParamsDto.getBusinessObjectDataKey()); // Validate that restore expiration time is set correctly on the storage unit. StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity); assertNotNull(storageUnitEntity.getRestoreExpirationOn()); Long differenceInMilliseconds = storageUnitEntity.getRestoreExpirationOn().getTime() - expectedTimestamp.getTime(); assertTrue(Math.abs(differenceInMilliseconds) < 1000); }
/** * Completes the expiration of a storage unit. * * @param businessObjectDataRestoreDto the DTO that holds various parameters needed to expire business object data */ protected void completeStorageUnitExpirationImpl(BusinessObjectDataRestoreDto businessObjectDataRestoreDto) { // Retrieve the business object data and ensure it exists. BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataRestoreDto.getBusinessObjectDataKey()); // Retrieve the storage unit and ensure it exists. StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(businessObjectDataRestoreDto.getStorageName(), businessObjectDataEntity); // Update the storage unit status. String oldStorageUnitStatus = storageUnitEntity.getStatus().getCode(); String reason = StorageUnitStatusEntity.ARCHIVED; storageUnitDaoHelper.updateStorageUnitStatus(storageUnitEntity, StorageUnitStatusEntity.ARCHIVED, reason); // Update the new and old storage unit status values in the DTO. businessObjectDataRestoreDto.setNewStorageUnitStatus(storageUnitEntity.getStatus().getCode()); businessObjectDataRestoreDto.setOldStorageUnitStatus(oldStorageUnitStatus); }
/** * Completes the expiration of a storage unit. * * @param businessObjectDataRestoreDto the DTO that holds various parameters needed to expire business object data */ protected void completeStorageUnitExpirationImpl(BusinessObjectDataRestoreDto businessObjectDataRestoreDto) { // Retrieve the business object data and ensure it exists. BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataRestoreDto.getBusinessObjectDataKey()); // Retrieve the storage unit and ensure it exists. StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(businessObjectDataRestoreDto.getStorageName(), businessObjectDataEntity); // Update the storage unit status. String oldStorageUnitStatus = storageUnitEntity.getStatus().getCode(); String reason = StorageUnitStatusEntity.ARCHIVED; storageUnitDaoHelper.updateStorageUnitStatus(storageUnitEntity, StorageUnitStatusEntity.ARCHIVED, reason); // Update the new and old storage unit status values in the DTO. businessObjectDataRestoreDto.setNewStorageUnitStatus(storageUnitEntity.getStatus().getCode()); businessObjectDataRestoreDto.setOldStorageUnitStatus(oldStorageUnitStatus); }
/** * Completes the finalize restore operation. * * @param businessObjectDataRestoreDto the DTO that holds various parameters needed to perform a business object data restore */ protected void completeFinalizeRestoreImpl(BusinessObjectDataRestoreDto businessObjectDataRestoreDto) { // Retrieve the business object data and ensure it exists. BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataRestoreDto.getBusinessObjectDataKey()); // Retrieve the storage unit and ensure it exists. StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(businessObjectDataRestoreDto.getStorageName(), businessObjectDataEntity); // Retrieve and ensure the RESTORED storage unit status entity exists. StorageUnitStatusEntity newStorageUnitStatusEntity = storageUnitStatusDaoHelper.getStorageUnitStatusEntity(StorageUnitStatusEntity.RESTORED); // Save the old storage unit status value. String oldStorageUnitStatus = storageUnitEntity.getStatus().getCode(); // Update the storage unit status to RESTORED. String reason = StorageUnitStatusEntity.RESTORED; storageUnitDaoHelper.updateStorageUnitStatus(storageUnitEntity, newStorageUnitStatusEntity, reason); // Update the new and old storage unit status values in the business object data restore DTO. businessObjectDataRestoreDto.setNewStorageUnitStatus(newStorageUnitStatusEntity.getCode()); businessObjectDataRestoreDto.setOldStorageUnitStatus(oldStorageUnitStatus); }
/** * Completes the finalize restore operation. * * @param businessObjectDataRestoreDto the DTO that holds various parameters needed to perform a business object data restore */ protected void completeFinalizeRestoreImpl(BusinessObjectDataRestoreDto businessObjectDataRestoreDto) { // Retrieve the business object data and ensure it exists. BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataRestoreDto.getBusinessObjectDataKey()); // Retrieve the storage unit and ensure it exists. StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(businessObjectDataRestoreDto.getStorageName(), businessObjectDataEntity); // Retrieve and ensure the RESTORED storage unit status entity exists. StorageUnitStatusEntity newStorageUnitStatusEntity = storageUnitStatusDaoHelper.getStorageUnitStatusEntity(StorageUnitStatusEntity.RESTORED); // Save the old storage unit status value. String oldStorageUnitStatus = storageUnitEntity.getStatus().getCode(); // Update the storage unit status to RESTORED. String reason = StorageUnitStatusEntity.RESTORED; storageUnitDaoHelper.updateStorageUnitStatus(storageUnitEntity, newStorageUnitStatusEntity, reason); // Update the new and old storage unit status values in the business object data restore DTO. businessObjectDataRestoreDto.setNewStorageUnitStatus(newStorageUnitStatusEntity.getCode()); businessObjectDataRestoreDto.setOldStorageUnitStatus(oldStorageUnitStatus); }
@Test public void testPrepareToInitiateRestoreMissingOptionalParameters() throws Exception { // Create a business object data key without sub-partition values. BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, NO_SUBPARTITION_VALUES, DATA_VERSION); // Create database entities required for testing. BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataServiceTestHelper.createDatabaseEntitiesForInitiateRestoreTesting(businessObjectDataKey); // Execute a before step for the initiate a business object data restore request for business object data without sub-partition values. BusinessObjectDataRestoreDto storagePolicyTransitionParamsDto = businessObjectDataInitiateRestoreHelperService.prepareToInitiateRestore(businessObjectDataKey, NO_EXPIRATION_IN_DAYS); // Validate the returned object. assertEquals(businessObjectDataKey, storagePolicyTransitionParamsDto.getBusinessObjectDataKey()); // Validate that restore expiration time is set correctly on the storage unit. StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity); assertNotNull(storageUnitEntity.getRestoreExpirationOn()); Long differenceInDays = TimeUnit.DAYS.convert(storageUnitEntity.getRestoreExpirationOn().getTime() - storageUnitEntity.getCreatedOn().getTime(), TimeUnit.MILLISECONDS); assertTrue((Integer) ConfigurationValue.BDATA_RESTORE_EXPIRATION_IN_DAYS_DEFAULT.getDefaultValue() - differenceInDays <= 1); }
businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataRestoreDto.getBusinessObjectDataKey());
businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataRestoreDto.getBusinessObjectDataKey());
@Test public void testPrepareToInitiateRestoreTrimParameters() { // 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, NO_SUBPARTITION_VALUES, DATA_VERSION); // Create database entities required for testing. businessObjectDataServiceTestHelper.createDatabaseEntitiesForInitiateRestoreTesting(businessObjectDataKey); // Execute a before step for the initiate a business object data restore request using input parameters with leading and trailing empty spaces. BusinessObjectDataRestoreDto storagePolicyTransitionParamsDto = businessObjectDataInitiateRestoreHelperService.prepareToInitiateRestore( new BusinessObjectDataKey(addWhitespace(BDEF_NAMESPACE), addWhitespace(BDEF_NAME), addWhitespace(FORMAT_USAGE_CODE), addWhitespace(FORMAT_FILE_TYPE_CODE), FORMAT_VERSION, addWhitespace(PARTITION_VALUE), NO_SUBPARTITION_VALUES, DATA_VERSION), EXPIRATION_IN_DAYS); // Validate the returned object. assertEquals(businessObjectDataKey, storagePolicyTransitionParamsDto.getBusinessObjectDataKey()); }