Search in sources :

Example 1 with FSItem

use of bio.terra.service.filedata.FSItem in project jade-data-repo by DataBiosphere.

the class FireStoreDao method makeFSDir.

private FSItem makeFSDir(Firestore firestore, String collectionId, int level, FireStoreDirectoryEntry fireStoreDirectoryEntry) {
    if (fireStoreDirectoryEntry.getIsFileRef()) {
        throw new IllegalStateException("Expected directory; got file!");
    }
    String fullPath = fireStoreUtils.getFullPath(fireStoreDirectoryEntry.getPath(), fireStoreDirectoryEntry.getName());
    FSDir fsDir = new FSDir();
    fsDir.fileId(UUID.fromString(fireStoreDirectoryEntry.getFileId())).collectionId(UUID.fromString(collectionId)).createdDate(Instant.parse(fireStoreDirectoryEntry.getFileCreatedDate())).path(fullPath).checksumCrc32c(fireStoreDirectoryEntry.getChecksumCrc32c()).checksumMd5(fireStoreDirectoryEntry.getChecksumMd5()).size(fireStoreDirectoryEntry.getSize()).description(StringUtils.EMPTY);
    if (level != 0) {
        List<FSItem> fsContents = new ArrayList<>();
        List<FireStoreDirectoryEntry> dirContents = directoryDao.enumerateDirectory(firestore, collectionId, fullPath);
        for (FireStoreDirectoryEntry fso : dirContents) {
            if (fso.getIsFileRef()) {
                // Files that are in the middle of being ingested can have a directory entry, but not yet have
                // a file entry. We do not return files that do not yet have a file entry.
                FSItem fsFile = makeFSFile(firestore, collectionId, fso);
                if (fsFile != null) {
                    fsContents.add(fsFile);
                }
            } else {
                fsContents.add(makeFSDir(firestore, collectionId, level - 1, fso));
            }
        }
        fsDir.contents(fsContents);
    }
    return fsDir;
}
Also used : FSDir(bio.terra.service.filedata.FSDir) FSItem(bio.terra.service.filedata.FSItem) ArrayList(java.util.ArrayList)

Example 2 with FSItem

use of bio.terra.service.filedata.FSItem in project jade-data-repo by DataBiosphere.

the class GcsPdao method fileAclOp.

private void fileAclOp(AclOp op, Dataset dataset, List<String> fileIds, String readersPolicyEmail) {
    Acl.Group readerGroup = new Acl.Group(readersPolicyEmail);
    Acl acl = Acl.newBuilder(readerGroup, Acl.Role.READER).build();
    for (String fileId : fileIds) {
        FSItem fsItem = fileDao.retrieveById(dataset, fileId, 0, true);
        if (fsItem instanceof FSFile) {
            FSFile fsFile = (FSFile) fsItem;
            GoogleBucketResource bucketForFile = dataLocationService.lookupBucket(fsFile.getBucketResourceId());
            Storage storage = storageForBucket(bucketForFile);
            URI gsUri = URI.create(fsFile.getGspath());
            String bucketPath = StringUtils.removeStart(gsUri.getPath(), "/");
            BlobId blobId = BlobId.of(bucketForFile.getName(), bucketPath);
            switch(op) {
                case ACL_OP_CREATE:
                    storage.createAcl(blobId, acl);
                    break;
                case ACL_OP_DELETE:
                    storage.deleteAcl(blobId, readerGroup);
                    break;
            }
        }
    }
}
Also used : GoogleBucketResource(bio.terra.service.resourcemanagement.google.GoogleBucketResource) Storage(com.google.cloud.storage.Storage) FSItem(bio.terra.service.filedata.FSItem) Acl(com.google.cloud.storage.Acl) URI(java.net.URI) BlobId(com.google.cloud.storage.BlobId) FSFile(bio.terra.service.filedata.FSFile)

Example 3 with FSItem

use of bio.terra.service.filedata.FSItem in project jade-data-repo by DataBiosphere.

the class IngestFileFileStep method doStep.

@Override
public StepResult doStep(FlightContext context) {
    FlightMap workingMap = context.getWorkingMap();
    Boolean loadComplete = workingMap.get(FileMapKeys.LOAD_COMPLETED, Boolean.class);
    if (loadComplete == null || !loadComplete) {
        FlightMap inputParameters = context.getInputParameters();
        FileLoadModel fileLoadModel = inputParameters.get(JobMapKeys.REQUEST.getKeyName(), FileLoadModel.class);
        FSFileInfo fsFileInfo = workingMap.get(FileMapKeys.FILE_INFO, FSFileInfo.class);
        String fileId = workingMap.get(FileMapKeys.FILE_ID, String.class);
        FireStoreFile newFile = new FireStoreFile().fileId(fileId).mimeType(fileLoadModel.getMimeType()).description(fileLoadModel.getDescription()).bucketResourceId(fsFileInfo.getBucketResourceId()).fileCreatedDate(fsFileInfo.getCreatedDate()).gspath(fsFileInfo.getGspath()).checksumCrc32c(fsFileInfo.getChecksumCrc32c()).checksumMd5(fsFileInfo.getChecksumMd5()).size(fsFileInfo.getSize()).loadTag(fileLoadModel.getLoadTag());
        try {
            fileDao.createFileMetadata(dataset, newFile);
            // Retrieve to build the complete FSItem
            FSItem fsItem = fileDao.retrieveById(dataset, fileId, 1, true);
            workingMap.put(JobMapKeys.RESPONSE.getKeyName(), fileService.fileModelFromFSItem(fsItem));
        } catch (FileSystemAbortTransactionException rex) {
            return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, rex);
        }
    }
    return StepResult.getStepResultSuccess();
}
Also used : FireStoreFile(bio.terra.service.filedata.google.firestore.FireStoreFile) FSFileInfo(bio.terra.service.filedata.FSFileInfo) FSItem(bio.terra.service.filedata.FSItem) FlightMap(bio.terra.stairway.FlightMap) FileLoadModel(bio.terra.model.FileLoadModel) FileSystemAbortTransactionException(bio.terra.service.filedata.exception.FileSystemAbortTransactionException) StepResult(bio.terra.stairway.StepResult)

Aggregations

FSItem (bio.terra.service.filedata.FSItem)3 FileLoadModel (bio.terra.model.FileLoadModel)1 FSDir (bio.terra.service.filedata.FSDir)1 FSFile (bio.terra.service.filedata.FSFile)1 FSFileInfo (bio.terra.service.filedata.FSFileInfo)1 FileSystemAbortTransactionException (bio.terra.service.filedata.exception.FileSystemAbortTransactionException)1 FireStoreFile (bio.terra.service.filedata.google.firestore.FireStoreFile)1 GoogleBucketResource (bio.terra.service.resourcemanagement.google.GoogleBucketResource)1 FlightMap (bio.terra.stairway.FlightMap)1 StepResult (bio.terra.stairway.StepResult)1 Acl (com.google.cloud.storage.Acl)1 BlobId (com.google.cloud.storage.BlobId)1 Storage (com.google.cloud.storage.Storage)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1