/** * Creates and persists a new storage unit entity. * * @param storageEntity the storage entity * @param businessObjectDataEntity the business object data entity * @param storageUnitStatusEntity the storage unit status entity * @param directoryPath the storage directory path * * @return the newly created storage unit entity. */ public StorageUnitEntity createStorageUnitEntity(StorageEntity storageEntity, BusinessObjectDataEntity businessObjectDataEntity, StorageUnitStatusEntity storageUnitStatusEntity, String directoryPath) { StorageUnitEntity storageUnitEntity = new StorageUnitEntity(); storageUnitEntity.setStorage(storageEntity); storageUnitEntity.setBusinessObjectData(businessObjectDataEntity); storageUnitEntity.setDirectoryPath(directoryPath); storageUnitEntity.setStatus(storageUnitStatusEntity); return storageUnitDao.saveAndRefresh(storageUnitEntity); }
/** * Creates and populates a business object data storage unit create response. * * @param storageUnitEntity the storage unit entity * * @return the business object data storage unit create response */ protected BusinessObjectDataStorageUnitCreateResponse createBusinessObjectDataStorageUnitCreateResponse(StorageUnitEntity storageUnitEntity) { // Get business object data key from the business object data entity. BusinessObjectDataKey businessObjectDataKey = businessObjectDataHelper.createBusinessObjectDataKeyFromEntity(storageUnitEntity.getBusinessObjectData()); // Create a business object data storage unit create response. BusinessObjectDataStorageUnitCreateResponse response = new BusinessObjectDataStorageUnitCreateResponse(); // Add business object data storage unit key. response.setBusinessObjectDataStorageUnitKey( storageUnitHelper.createBusinessObjectDataStorageUnitKey(businessObjectDataKey, storageUnitEntity.getStorage().getName())); // Add storage directory. if (storageUnitEntity.getDirectoryPath() != null) { response.setStorageDirectory(new StorageDirectory(storageUnitEntity.getDirectoryPath())); } // Add storage files. if (CollectionUtils.isNotEmpty(storageUnitEntity.getStorageFiles())) { response.setStorageFiles(storageFileHelper.createStorageFilesFromEntities(storageUnitEntity.getStorageFiles())); } // Return the response. return response; }
/** * Creates a list of storage unit ids from a list of storage unit entities. * * @param storageUnitEntities the list of storage unit entities * * @return the list of storage unit ids */ public List<Integer> getStorageUnitIds(List<StorageUnitEntity> storageUnitEntities) { List<Integer> storageUnitIds = new ArrayList<>(storageUnitEntities.size()); for (StorageUnitEntity storageUnitEntity : storageUnitEntities) { storageUnitIds.add(storageUnitEntity.getId()); } return storageUnitIds; }
/** * Asserts that the given storage unit entity contains exactly one storage file. * * @param storageUnitEntity - storage unit to check * * @throws IllegalArgumentException when the number of storage files is not 1 */ private void assertHasOneStorageFile(StorageUnitEntity storageUnitEntity) { Assert.isTrue(storageUnitEntity.getStorageFiles().size() == 1, String .format("Found %d registered storage files when expecting one in \"%s\" storage for the business object data {%s}.", storageUnitEntity.getStorageFiles().size(), storageUnitEntity.getStorage().getName(), businessObjectDataHelper.businessObjectDataEntityAltKeyToString(storageUnitEntity.getBusinessObjectData()))); }
/** * Sets storage unit status value for a storage unit. This method also generates a storage unit status change notification event as per system * configuration. * * @param storageUnitEntity the storage unit entity * @param storageUnitStatusEntity the storage unit status entity */ public void setStorageUnitStatus(StorageUnitEntity storageUnitEntity, StorageUnitStatusEntity storageUnitStatusEntity) { // Set the storage unit status value. storageUnitEntity.setStatus(storageUnitStatusEntity); // Send a storage unit status change notification as per system configuration. messageNotificationEventService .processStorageUnitStatusChangeNotificationEvent(businessObjectDataHelper.getBusinessObjectDataKey(storageUnitEntity.getBusinessObjectData()), storageUnitEntity.getStorage().getName(), storageUnitStatusEntity.getCode(), null); }
storageUnit.setStorage(storage); StorageEntity storageEntity = storageUnitEntity.getStorage(); storage.setName(storageEntity.getName()); storage.setStoragePlatformName(storageEntity.getStoragePlatform().getName()); if (storageUnitEntity.getDirectoryPath() != null) storageDirectory.setDirectoryPath(storageUnitEntity.getDirectoryPath()); if (!storageUnitEntity.getStorageFiles().isEmpty()) for (StorageFileEntity storageFileEntity : storageUnitEntity.getStorageFiles()) storageUnit.setStorageUnitStatus(storageUnitEntity.getStatus().getCode()); for (StorageUnitStatusHistoryEntity storageUnitStatusHistoryEntity : storageUnitEntity.getHistoricalStatuses()) storageUnit.setStoragePolicyTransitionFailedAttempts(storageUnitEntity.getStoragePolicyTransitionFailedAttempts()); if (storageUnitEntity.getRestoreExpirationOn() != null) storageUnit.setRestoreExpirationOn(HerdDateUtils.getXMLGregorianCalendarValue(storageUnitEntity.getRestoreExpirationOn()));
StorageUnitEntity storageUnitEntity = new StorageUnitEntity(); storageUnitEntity.setBusinessObjectData(businessObjectDataEntity); storageUnitEntity.setStorage(storageEntity); storageUnitEntity.setStatus(oldStorageUnitStatusEntity); storageUnitEntity.setHistoricalStatuses(new ArrayList<>()); assertEquals(STORAGE_UNIT_STATUS_2, storageUnitEntity.getStatus().getCode());
.format("Storage directory \"%s\" in \"%s\" storage is already registered by the business object data {%s}.", directoryPath, storageEntity.getName(), businessObjectDataHelper.businessObjectDataEntityAltKeyToString(alreadyRegisteredStorageUnitEntity.getBusinessObjectData()))); StorageUnitEntity storageUnitEntity = new StorageUnitEntity(); storageUnitEntity.setStorage(storageEntity); storageUnitEntity.setBusinessObjectData(businessObjectDataEntity); storageUnitDaoHelper.setStorageUnitStatus(storageUnitEntity, storageUnitStatusEntity); storageUnitEntity.setDirectoryPath(directoryPath);
String oldStatus = storageUnitEntity.getStatus().getCode(); storageUnitEntity.setStatus(storageUnitStatusEntity); storageUnitEntity.getHistoricalStatuses().add(storageUnitStatusHistoryEntity); storageUnitStatusHistoryEntity.setStorageUnit(storageUnitEntity); storageUnitStatusHistoryEntity.setStatus(storageUnitStatusEntity); .processStorageUnitStatusChangeNotificationEvent(businessObjectDataHelper.getBusinessObjectDataKey(storageUnitEntity.getBusinessObjectData()), storageUnitEntity.getStorage().getName(), storageUnitStatusEntity.getCode(), oldStatus);
BusinessObjectDataKey businessObjectDataKey = businessObjectDataHelper.getBusinessObjectDataKey(storageUnitEntity.getBusinessObjectData()); String s3KeyPrefix = s3KeyPrefixHelper .buildS3KeyPrefix(storageUnitEntity.getStorage(), storageUnitEntity.getBusinessObjectData().getBusinessObjectFormat(), businessObjectDataKey); if (storageUnitEntity.getDirectoryPath() != null) Assert.isTrue(storageUnitEntity.getDirectoryPath().equals(s3KeyPrefix), String.format( "Storage directory path \"%s\" registered with business object data {%s} " + "in \"%s\" storage does not match the expected S3 key prefix \"%s\".", storageUnitEntity.getDirectoryPath(), businessObjectDataHelper.businessObjectDataEntityAltKeyToString(storageUnitEntity.getBusinessObjectData()), storageUnitEntity.getStorage().getName(), s3KeyPrefix)); storageFilePaths = storageUnitIdToStorageFilePathsMap.containsKey(storageUnitEntity.getId()) ? storageUnitIdToStorageFilePathsMap.get(storageUnitEntity.getId()) : new ArrayList<>(); storageFileHelper.validateStorageFilePaths(storageFilePaths, s3KeyPrefix, storageUnitEntity.getBusinessObjectData(), storageUnitEntity.getStorage().getName()); Assert.isTrue(storageUnitEntity.getDirectoryPath() != null && storageUnitEntity.getDirectoryPath().startsWith(s3KeyPrefix), String.format( "Storage directory path \"%s\" registered with business object data {%s} " + "in \"%s\" storage does not match the expected S3 key prefix \"%s\".", storageUnitEntity.getDirectoryPath(), businessObjectDataHelper.businessObjectDataEntityAltKeyToString(storageUnitEntity.getBusinessObjectData()), storageUnitEntity.getStorage().getName(), s3KeyPrefix)); storageFilePaths.add(storageUnitEntity.getDirectoryPath() + "/"); String s3BucketName = getS3BucketName(storageUnitEntity.getStorage(), generateDdlRequest.s3BucketNames); storageFilePaths, storageUnitEntity.getBusinessObjectData(), storageUnitEntity.getStorage().getName()))
StorageUnitEntity storageUnitEntity = new StorageUnitEntity(); storageUnitEntity.setBusinessObjectData(businessObjectDataEntity); storageUnitEntity.setStorage(storageEntity); storageUnitEntity.setDirectoryPath(STORAGE_DIRECTORY_PATH); storageUnitEntity.setStorageFiles(storageFileEntities);
Map<String, StorageFileEntity> storageFileEntities = storageFileHelper.getStorageFileEntitiesMap(storageUnitEntity.getStorageFiles()); Assert.hasText(storageUnitEntity.getDirectoryPath(), "Business object data has no storage directory path which is required for auto-discovery of storage files."); String directoryPath = storageUnitEntity.getDirectoryPath(); storageFileDao.getStorageFilesByStorageAndFilePathPrefix(storageUnitEntity.getStorage().getName(), directoryPathWithTrailingSlash); "Number of storage files (%d) already registered for the business object data in \"%s\" storage is not equal to " + "the number of registered storage files (%d) matching \"%s\" S3 key prefix in the same storage.", storageFileEntities.size(), storageUnitEntity.getStorage().getName(), registeredStorageFilePaths.size(), directoryPathWithTrailingSlash)); S3FileTransferRequestParamsDto params = storageHelper.getS3BucketAccessParams(storageUnitEntity.getStorage()); params.setS3KeyPrefix(directoryPathWithTrailingSlash);
StorageUnitEntity storageUnitEntity = new StorageUnitEntity(); storageUnitEntity.setStorage(storageEntity); storageUnitEntity.setBusinessObjectData(businessObjectDataEntity); storageUnitDaoHelper.setStorageUnitStatus(storageUnitEntity, storageUnitStatusEntity); businessObjectDataEntity.setStorageUnits(Collections.singletonList(storageUnitEntity));
StorageUnitEntity storageUnitEntity = new StorageUnitEntity(); storageUnitEntity.setBusinessObjectData(businessObjectDataEntity); storageUnitEntity.setStorage(storageEntity); assertEquals(STORAGE_UNIT_STATUS, storageUnitEntity.getStatus().getCode());
@Test public void testGetStorageUnitsByStorageAndBusinessObjectData() { // Create database entities required for testing. StorageUnitEntity storageUnitEntity = storageUnitDaoTestHelper .createStorageUnitEntity(STORAGE_NAME, NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, INITIAL_DATA_VERSION, LATEST_VERSION_FLAG_SET, BDATA_STATUS, STORAGE_UNIT_STATUS, TEST_S3_KEY_PREFIX); // Retrieve storage unit entities by storage and business object data. List<StorageUnitEntity> resultStorageUnitEntities = storageUnitDao.getStorageUnitsByStorageAndBusinessObjectData(storageUnitEntity.getStorage(), Collections.singletonList(storageUnitEntity.getBusinessObjectData())); // Validate the results. assertNotNull(resultStorageUnitEntities); assertEquals(1, resultStorageUnitEntities.size()); assertEquals(TEST_S3_KEY_PREFIX, resultStorageUnitEntities.get(0).getDirectoryPath()); }
@Test public void testCreateStorageUnitsFromEntities() { // Create a business object data storage unit key. BusinessObjectDataStorageUnitKey businessObjectDataStorageUnitKey = new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME); Timestamp restoredExpirationOn = new Timestamp(new Date().getTime()); // Create a storage unit entity. StorageUnitEntity storageUnitEntity = storageUnitDaoTestHelper.createStorageUnitEntity(businessObjectDataStorageUnitKey, STORAGE_UNIT_STATUS); storageUnitEntity.setDirectoryPath(STORAGE_DIRECTORY_PATH); storageUnitEntity.setStoragePolicyTransitionFailedAttempts(STORAGE_POLICY_TRANSITION_FAILED_ATTEMPTS); storageUnitEntity.setRestoreExpirationOn(restoredExpirationOn); // Call the method under test. List<StorageUnit> result = storageUnitHelper.createStorageUnitsFromEntities(Arrays.asList(storageUnitEntity), NO_INCLUDE_STORAGE_UNIT_STATUS_HISTORY); // Verify the external calls. verifyNoMoreInteractionsHelper(); // Validate the results. assertEquals(Arrays.asList( new StorageUnit(new Storage(STORAGE_NAME, StoragePlatformEntity.S3, null), new StorageDirectory(STORAGE_DIRECTORY_PATH), null, STORAGE_UNIT_STATUS, NO_STORAGE_UNIT_STATUS_HISTORY, STORAGE_POLICY_TRANSITION_FAILED_ATTEMPTS, HerdDateUtils.getXMLGregorianCalendarValue(restoredExpirationOn))), result); }
String storageName = storageUnitEntity.getStorage().getName(); .getStorageAttributeValueByName(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), storageUnitEntity.getStorage(), true); s3KeyPrefixHelper.buildS3KeyPrefix(storageUnitEntity.getStorage(), businessObjectDataEntity.getBusinessObjectFormat(), businessObjectDataKey); storageUnitEntity.setRestoreExpirationOn(HerdDateUtils.addDays(currentTime, localExpirationInDays)); String oldOriginStorageUnitStatus = storageUnitEntity.getStatus().getCode();
@Test public void testGetStorageUnitByBusinessObjectDataAndStorage() { StorageUnitEntity storageUnitEntity = storageUnitDaoTestHelper .createStorageUnitEntity(STORAGE_NAME, NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, INITIAL_DATA_VERSION, LATEST_VERSION_FLAG_SET, BDATA_STATUS, STORAGE_UNIT_STATUS, STORAGE_DIRECTORY_PATH); BusinessObjectDataEntity businessObjectDataEntity = storageUnitEntity.getBusinessObjectData(); StorageEntity storageEntity = storageUnitEntity.getStorage(); // Test retrieval by entities. assertEquals(storageUnitEntity, storageUnitDao.getStorageUnitByBusinessObjectDataAndStorage(businessObjectDataEntity, storageEntity)); // Test retrieval failures. assertNull( storageUnitDao.getStorageUnitByBusinessObjectDataAndStorage(businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(), storageEntity)); assertNull(storageUnitDao.getStorageUnitByBusinessObjectDataAndStorage(businessObjectDataEntity, storageDaoTestHelper.createStorageEntity())); }
@Test public void testGetStorageUnitMultipleStorageUnitsExist() { // Create a business object data entity. BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity(); // Create a list of storage unit entities. List<StorageUnitEntity> storageUnitEntities = Arrays.asList(new StorageUnitEntity(), new StorageUnitEntity()); // Mock the external calls. when(storageUnitDao.getStorageUnitsByStoragePlatformAndBusinessObjectData(StoragePlatformEntity.S3, businessObjectDataEntity)) .thenReturn(storageUnitEntities); when(businessObjectDataHelper.businessObjectDataEntityAltKeyToString(businessObjectDataEntity)).thenReturn(BUSINESS_OBJECT_DATA_KEY_AS_STRING); // Try to call the method under test. try { businessObjectDataInitiateRestoreHelperServiceImpl.getStorageUnit(businessObjectDataEntity); fail(); } catch (IllegalArgumentException e) { assertEquals(String.format("Business object data has multiple (%d) S3 storage units. Business object data: {%s}", storageUnitEntities.size(), BUSINESS_OBJECT_DATA_KEY_AS_STRING), e.getMessage()); } // Verify the external calls. verify(storageUnitDao).getStorageUnitsByStoragePlatformAndBusinessObjectData(StoragePlatformEntity.S3, businessObjectDataEntity); verify(businessObjectDataHelper).businessObjectDataEntityAltKeyToString(businessObjectDataEntity); verifyNoMoreInteractionsHelper(); }
/** * Excludes storage units from the list with primary and sub-partition values matching one of the excluded partitions. * * @param storageUnitEntities the list of storage unit entities * @param excludedPartitions list of excluded partitions, where each partition consists of primary and optional sub-partition values * * @return the updated list of storage units */ public List<StorageUnitEntity> excludePartitions(List<StorageUnitEntity> storageUnitEntities, List<List<String>> excludedPartitions) { List<StorageUnitEntity> result = new ArrayList<>(); for (StorageUnitEntity storageUnitEntity : storageUnitEntities) { if (!excludedPartitions.contains(businessObjectDataHelper.getPrimaryAndSubPartitionValues(storageUnitEntity.getBusinessObjectData()))) { result.add(storageUnitEntity); } } return result; }