use of org.finra.herd.model.jpa.StorageEntity in project herd by FINRAOS.
the class StorageUnitNotificationRegistrationServiceImpl method createStorageUnitNotificationRegistration.
@NamespacePermissions({ @NamespacePermission(fields = "#request?.storageUnitNotificationRegistrationKey?.namespace", permissions = NamespacePermissionEnum.WRITE), @NamespacePermission(fields = "#request?.storageUnitNotificationFilter?.namespace", permissions = NamespacePermissionEnum.READ), @NamespacePermission(fields = "#request?.jobActions?.![namespace]", permissions = NamespacePermissionEnum.EXECUTE) })
@Override
public StorageUnitNotificationRegistration createStorageUnitNotificationRegistration(StorageUnitNotificationRegistrationCreateRequest request) {
// Validate and trim the request parameters.
validateStorageUnitNotificationRegistrationCreateRequest(request);
// Get the notification registration key.
NotificationRegistrationKey notificationRegistrationKey = request.getStorageUnitNotificationRegistrationKey();
// Retrieve and ensure that notification registration namespace exists.
NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(notificationRegistrationKey.getNamespace());
// Retrieve and validate the notification event type entity.
NotificationEventTypeEntity notificationEventTypeEntity = getAndValidateNotificationEventTypeEntity(request.getStorageUnitEventType());
// Validate the notification event type.
Assert.isTrue(NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG.name().equalsIgnoreCase(request.getStorageUnitEventType()), String.format("Notification event type \"%s\" is not supported for storage unit notification registration.", request.getStorageUnitEventType()));
// Get the storage unit notification filter.
StorageUnitNotificationFilter filter = request.getStorageUnitNotificationFilter();
// Retrieve and ensure that business object definition exists.
BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoHelper.getBusinessObjectDefinitionEntity(new BusinessObjectDefinitionKey(filter.getNamespace(), filter.getBusinessObjectDefinitionName()));
// If specified, retrieve and ensure that file type exists.
FileTypeEntity fileTypeEntity = null;
if (StringUtils.isNotBlank(filter.getBusinessObjectFormatFileType())) {
fileTypeEntity = fileTypeDaoHelper.getFileTypeEntity(filter.getBusinessObjectFormatFileType());
}
// Retrieve and ensure that storage exists.
StorageEntity storageEntity = storageDaoHelper.getStorageEntity(filter.getStorageName());
// If specified, retrieve and ensure that new storage unit status exists.
StorageUnitStatusEntity newStorageUnitStatus = null;
if (StringUtils.isNotBlank(filter.getNewStorageUnitStatus())) {
newStorageUnitStatus = storageUnitStatusDaoHelper.getStorageUnitStatusEntity(filter.getNewStorageUnitStatus());
}
// If specified, retrieve and ensure that old storage unit status exists.
StorageUnitStatusEntity oldStorageUnitStatus = null;
if (StringUtils.isNotBlank(filter.getOldStorageUnitStatus())) {
oldStorageUnitStatus = storageUnitStatusDaoHelper.getStorageUnitStatusEntity(filter.getOldStorageUnitStatus());
}
// TODO: We need to add a null/empty list check here, if/when list of job actions will become optional (due to addition of other action types).
for (JobAction jobAction : request.getJobActions()) {
// Ensure that job definition exists.
jobDefinitionDaoHelper.getJobDefinitionEntity(jobAction.getNamespace(), jobAction.getJobName());
}
// If specified, retrieve and validate the notification registration status entity. Otherwise, default it to ENABLED.
NotificationRegistrationStatusEntity notificationRegistrationStatusEntity = notificationRegistrationStatusDaoHelper.getNotificationRegistrationStatusEntity(StringUtils.isNotBlank(request.getNotificationRegistrationStatus()) ? request.getNotificationRegistrationStatus() : NotificationRegistrationStatusEntity.ENABLED);
// Ensure a storage unit notification with the specified name doesn't already exist for the specified namespace.
StorageUnitNotificationRegistrationEntity storageUnitNotificationRegistrationEntity = storageUnitNotificationRegistrationDao.getStorageUnitNotificationRegistrationByAltKey(notificationRegistrationKey);
if (storageUnitNotificationRegistrationEntity != null) {
throw new AlreadyExistsException(String.format("Unable to create storage unit notification with name \"%s\" because it already exists for namespace \"%s\".", notificationRegistrationKey.getNotificationName(), notificationRegistrationKey.getNamespace()));
}
// Create a storage unit notification registration entity from the request information.
storageUnitNotificationRegistrationEntity = createStorageUnitNotificationEntity(namespaceEntity, notificationEventTypeEntity, businessObjectDefinitionEntity, fileTypeEntity, storageEntity, newStorageUnitStatus, oldStorageUnitStatus, request.getStorageUnitNotificationRegistrationKey(), request.getStorageUnitNotificationFilter(), request.getJobActions(), notificationRegistrationStatusEntity);
// Persist the new entity.
storageUnitNotificationRegistrationEntity = storageUnitNotificationRegistrationDao.saveAndRefresh(storageUnitNotificationRegistrationEntity);
// Create and return the storage unit notification object from the persisted entity.
return createStorageUnitNotificationFromEntity(storageUnitNotificationRegistrationEntity);
}
use of org.finra.herd.model.jpa.StorageEntity in project herd by FINRAOS.
the class UploadDownloadServiceImpl method initiateDownloadSingleSampleFile.
@Override
public DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationResponse initiateDownloadSingleSampleFile(DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationRequest request) {
// Validate and trim the request parameters.
validateDownloadBusinessObjectDefinitionSampleDataFileSingleInitiationRequest(request);
// Get the business object definition sample data file key.
BusinessObjectDefinitionSampleDataFileKey businessObjectDefinitionSampleDataFileKey = request.getBusinessObjectDefinitionSampleDataFileKey();
// Get the business object definition key.
BusinessObjectDefinitionKey businessObjectDefinitionKey = new BusinessObjectDefinitionKey(businessObjectDefinitionSampleDataFileKey.getNamespace(), businessObjectDefinitionSampleDataFileKey.getBusinessObjectDefinitionName());
// Get the business object definition entity and ensure it exists.
BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoHelper.getBusinessObjectDefinitionEntity(businessObjectDefinitionKey);
// Get the sample data file exists for the business object definition and ensure it exists.
BusinessObjectDefinitionSampleDataFileEntity businessObjectDefinitionSampleDataFileEntity = getBusinessObjectDefinitionSampleDataFileEntity(businessObjectDefinitionEntity, businessObjectDefinitionSampleDataFileKey);
// Retrieve the storage related information.
StorageEntity storageEntity = businessObjectDefinitionSampleDataFileEntity.getStorage();
String s3BucketName = storageHelper.getStorageBucketName(storageEntity);
String s3ObjectKey = businessObjectDefinitionSampleDataFileKey.getDirectoryPath() + businessObjectDefinitionSampleDataFileKey.getFileName();
String sessionID = UUID.randomUUID().toString();
// Get the temporary credentials.
Credentials downloaderCredentials = getDownloaderCredentialsNoKmsKey(storageEntity, sessionID, s3ObjectKey);
// Generate a pre-signed URL.
Date expiration = downloaderCredentials.getExpiration();
S3FileTransferRequestParamsDto s3BucketAccessParams = storageHelper.getS3BucketAccessParams(storageEntity);
String presignedUrl = s3Dao.generateGetObjectPresignedUrl(s3BucketName, s3ObjectKey, expiration, s3BucketAccessParams);
// Create the download business object definition sample data file single initiation response.
DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationResponse response = new DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationResponse();
response.setBusinessObjectDefinitionSampleDataFileKey(new BusinessObjectDefinitionSampleDataFileKey(businessObjectDefinitionEntity.getNamespace().getCode(), businessObjectDefinitionEntity.getName(), businessObjectDefinitionSampleDataFileEntity.getDirectoryPath(), businessObjectDefinitionSampleDataFileEntity.getFileName()));
response.setAwsS3BucketName(s3BucketName);
response.setAwsAccessKey(downloaderCredentials.getAccessKeyId());
response.setAwsSecretKey(downloaderCredentials.getSecretAccessKey());
response.setAwsSessionToken(downloaderCredentials.getSessionToken());
response.setAwsSessionExpirationTime(HerdDateUtils.getXMLGregorianCalendarValue(expiration));
response.setPreSignedUrl(presignedUrl);
// Return the response.
return response;
}
use of org.finra.herd.model.jpa.StorageEntity in project herd by FINRAOS.
the class UploadDownloadServiceImpl method extendUploadSingleCredentials.
@NamespacePermission(fields = "#namespace", permissions = NamespacePermissionEnum.WRITE)
@Override
public UploadSingleCredentialExtensionResponse extendUploadSingleCredentials(String namespace, String businessObjectDefinitionName, String businessObjectFormatUsage, String businessObjectFormatFileType, Integer businessObjectFormatVersion, String partitionValue, Integer businessObjectDataVersion) {
// Create the business object data key.
BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(namespace, businessObjectDefinitionName, businessObjectFormatUsage, businessObjectFormatFileType, businessObjectFormatVersion, partitionValue, null, businessObjectDataVersion);
// Validate and trim the business object data key.
businessObjectDataHelper.validateBusinessObjectDataKey(businessObjectDataKey, true, true);
// Get the business object data for the key.
BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey);
// Ensure the status of the business object data is "uploading" in order to extend credentials.
if (!(businessObjectDataEntity.getStatus().getCode().equals(BusinessObjectDataStatusEntity.UPLOADING))) {
throw new IllegalArgumentException(String.format(String.format("Business object data {%s} has a status of \"%s\" and must be \"%s\" to extend " + "credentials.", businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey), businessObjectDataEntity.getStatus().getCode(), BusinessObjectDataStatusEntity.UPLOADING)));
}
// Get the S3 managed "loading dock" storage entity and make sure it exists.
StorageEntity storageEntity = storageDaoHelper.getStorageEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE);
String s3BucketName = storageHelper.getStorageBucketName(storageEntity);
// Get the storage unit entity for this business object data in the S3 managed "loading dock" storage and make sure it exists.
StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE, businessObjectDataEntity);
// Validate that the storage unit contains exactly one storage file.
assertHasOneStorageFile(storageUnitEntity);
// Get the storage file entity.
StorageFileEntity storageFileEntity = IterableUtils.get(storageUnitEntity.getStorageFiles(), 0);
// Get the storage file path.
String storageFilePath = storageFileEntity.getPath();
String awsRoleArn = getStorageUploadRoleArn(storageEntity);
Integer awsRoleDurationSeconds = getStorageUploadSessionDuration(storageEntity);
String awsKmsKeyId = storageHelper.getStorageKmsKeyId(storageEntity);
// Get the temporary security credentials to access S3_MANAGED_STORAGE.
Credentials assumedSessionCredentials = stsDao.getTemporarySecurityCredentials(awsHelper.getAwsParamsDto(), String.valueOf(businessObjectDataEntity.getId()), awsRoleArn, awsRoleDurationSeconds, createUploaderPolicy(s3BucketName, storageFilePath, awsKmsKeyId));
// Create the response.
UploadSingleCredentialExtensionResponse response = new UploadSingleCredentialExtensionResponse();
response.setAwsAccessKey(assumedSessionCredentials.getAccessKeyId());
response.setAwsSecretKey(assumedSessionCredentials.getSecretAccessKey());
response.setAwsSessionToken(assumedSessionCredentials.getSessionToken());
response.setAwsSessionExpirationTime(HerdDateUtils.getXMLGregorianCalendarValue(assumedSessionCredentials.getExpiration()));
return response;
}
use of org.finra.herd.model.jpa.StorageEntity in project herd by FINRAOS.
the class StorageServiceImpl method createStorage.
@Override
public Storage createStorage(StorageCreateRequest storageCreateRequest) {
// Perform validation and trim.
validateAndTrimStorageCreateRequest(storageCreateRequest);
// Retrieve storage platform.
StoragePlatformEntity storagePlatformEntity = storagePlatformHelper.getStoragePlatformEntity(storageCreateRequest.getStoragePlatformName());
// See if a storage with the specified name already exists.
StorageEntity storageEntity = storageDao.getStorageByName(storageCreateRequest.getName());
if (storageEntity != null) {
throw new AlreadyExistsException(String.format("Storage with name \"%s\" already exists.", storageCreateRequest.getName()));
}
// Create a storage entity.
storageEntity = new StorageEntity();
storageEntity.setName(storageCreateRequest.getName());
storageEntity.setStoragePlatform(storagePlatformEntity);
// Create attributes if they are specified.
if (!CollectionUtils.isEmpty(storageCreateRequest.getAttributes())) {
List<StorageAttributeEntity> attributeEntities = new ArrayList<>();
storageEntity.setAttributes(attributeEntities);
for (Attribute attribute : storageCreateRequest.getAttributes()) {
StorageAttributeEntity attributeEntity = new StorageAttributeEntity();
attributeEntities.add(attributeEntity);
attributeEntity.setStorage(storageEntity);
attributeEntity.setName(attribute.getName());
attributeEntity.setValue(attribute.getValue());
}
}
// Persist the storage entity.
storageEntity = storageDao.saveAndRefresh(storageEntity);
// Return the storage information.
return createStorageFromEntity(storageEntity);
}
use of org.finra.herd.model.jpa.StorageEntity in project herd by FINRAOS.
the class StorageServiceImpl method getStorage.
@Override
public Storage getStorage(StorageKey storageKey) {
// Perform validation and trim.
validateAndTrimStorageKey(storageKey);
// Retrieve and ensure that a storage exists.
StorageEntity storageEntity = storageDaoHelper.getStorageEntity(storageKey);
// Return the storage information.
return createStorageFromEntity(storageEntity);
}
Aggregations