Search in sources :

Example 16 with FileInfo

use of org.smartdata.model.FileInfo in project SSM by Intel-bigdata.

the class MetaStore method listFileActions.

public List<DetailedFileAction> listFileActions(long rid, long start, long offset) throws MetaStoreException {
    if (mapStoragePolicyIdName == null) {
        updateCache();
    }
    List<ActionInfo> actionInfos = getActions(rid, start, offset);
    List<DetailedFileAction> detailedFileActions = new ArrayList<>();
    for (ActionInfo actionInfo : actionInfos) {
        DetailedFileAction detailedFileAction = new DetailedFileAction(actionInfo);
        String filePath = actionInfo.getArgs().get("-file");
        FileInfo fileInfo = getFile(filePath);
        if (fileInfo == null) {
            // LOG.debug("Namespace is not sync! File {} not in file table!", filePath);
            // Add a mock fileInfo
            fileInfo = new FileInfo(filePath, 0L, 0L, false, (short) 0, 0L, 0L, 0L, (short) 0, "root", "root", (byte) 0, (byte) 0);
        }
        detailedFileAction.setFileLength(fileInfo.getLength());
        detailedFileAction.setFilePath(filePath);
        if (actionInfo.getActionName().contains("allssd") || actionInfo.getActionName().contains("onessd") || actionInfo.getActionName().contains("archive") || actionInfo.getActionName().contains("alldisk") || actionInfo.getActionName().contains("onedisk") || actionInfo.getActionName().contains("ramdisk")) {
            detailedFileAction.setTarget(actionInfo.getActionName());
            detailedFileAction.setSrc(mapStoragePolicyIdName.get((int) fileInfo.getStoragePolicy()));
        } else {
            detailedFileAction.setSrc(actionInfo.getArgs().get("-src"));
            detailedFileAction.setTarget(actionInfo.getArgs().get("-dest"));
        }
        detailedFileActions.add(detailedFileAction);
    }
    return detailedFileActions;
}
Also used : FileInfo(org.smartdata.model.FileInfo) DetailedFileAction(org.smartdata.model.DetailedFileAction) ArrayList(java.util.ArrayList) ActionInfo(org.smartdata.model.ActionInfo)

Example 17 with FileInfo

use of org.smartdata.model.FileInfo in project SSM by Intel-bigdata.

the class TestTableAggregator method prepareFiles.

private void prepareFiles(MetaStore metaStore) throws MetaStoreException {
    List<FileInfo> statusInternals = new ArrayList<>();
    for (int id = 1; id < 6; id++) {
        statusInternals.add(new FileInfo("/file" + id, id + 100, 123L, false, (short) 1, 128 * 1024L, 123123123L, 123123120L, (short) 1, "root", "admin", (byte) 0, (byte) 0));
    }
    metaStore.insertFiles(statusInternals.toArray(new FileInfo[0]));
}
Also used : FileInfo(org.smartdata.model.FileInfo) ArrayList(java.util.ArrayList)

Example 18 with FileInfo

use of org.smartdata.model.FileInfo in project SSM by Intel-bigdata.

the class AlluxioEntryApplier method getPathByFileId.

public String getPathByFileId(long fid) throws MetaStoreException {
    FileInfo fileInfo = metaStore.getFile(fid);
    String path = "";
    if (fileInfo != null) {
        path = fileInfo.getPath();
    }
    return path;
}
Also used : FileInfo(org.smartdata.model.FileInfo)

Example 19 with FileInfo

use of org.smartdata.model.FileInfo in project SSM by Intel-bigdata.

the class SmallFilePlugin method preSubmitCmdletDescriptor.

@Override
public CmdletDescriptor preSubmitCmdletDescriptor(final RuleInfo ruleInfo, TranslateResult tResult, CmdletDescriptor descriptor) {
    for (int i = 0; i < descriptor.getActionSize(); i++) {
        if (COMPACT_ACTION_NAME.equals(descriptor.getActionName(i))) {
            String smallFiles = descriptor.getActionArgs(i).get(HdfsAction.FILE_PATH);
            if (smallFiles != null && !smallFiles.isEmpty()) {
                // Check if small file list is empty
                ArrayList<String> smallFileList = new Gson().fromJson(smallFiles, new TypeToken<ArrayList<String>>() {
                }.getType());
                if (smallFileList == null || smallFileList.isEmpty()) {
                    continue;
                }
                // Get the first small file info
                String firstFile = smallFileList.get(0);
                FileInfo firstFileInfo;
                if (firstFileInfoCache.containsKey(firstFile)) {
                    firstFileInfo = firstFileInfoCache.get(firstFile);
                } else {
                    try {
                        firstFileInfo = metaStore.getFile(firstFile);
                        if (firstFileInfo == null) {
                            LOG.debug("{} is not exist!!!", firstFile);
                            continue;
                        }
                    } catch (MetaStoreException e) {
                        LOG.error(String.format("Failed to get file info of: %s.", firstFile), e);
                        continue;
                    }
                }
                // Get valid compact action arguments
                SmartFilePermission firstFilePermission = new SmartFilePermission(firstFileInfo);
                String firstFileDir = firstFile.substring(0, firstFile.lastIndexOf("/") + 1);
                CompactActionArgs args = getCompactActionArgs(ruleInfo, firstFileDir, firstFilePermission, smallFileList);
                // Set container file path and its permission, file path of this action
                descriptor.addActionArg(i, SmallFileCompactAction.CONTAINER_FILE, args.containerFile);
                descriptor.addActionArg(i, SmallFileCompactAction.CONTAINER_FILE_PERMISSION, new Gson().toJson(args.containerFilePermission));
                descriptor.addActionArg(i, HdfsAction.FILE_PATH, new Gson().toJson(args.smartFiles));
            }
        }
    }
    return descriptor;
}
Also used : MetaStoreException(org.smartdata.metastore.MetaStoreException) FileInfo(org.smartdata.model.FileInfo) TypeToken(com.google.gson.reflect.TypeToken) Gson(com.google.gson.Gson) SmartFilePermission(org.smartdata.SmartFilePermission)

Example 20 with FileInfo

use of org.smartdata.model.FileInfo in project SSM by Intel-bigdata.

the class SmallFilePlugin method getCompactActionArgs.

/**
 * Get valid compact action arguments.
 */
private CompactActionArgs getCompactActionArgs(RuleInfo ruleInfo, String firstFileDir, SmartFilePermission firstFilePermission, List<String> smallFileList) {
    Map<String, FileInfo> containerFileMap = containerFileInfoCache.get(ruleInfo);
    for (Iterator<Map.Entry<String, FileInfo>> iter = containerFileMap.entrySet().iterator(); iter.hasNext(); ) {
        Map.Entry<String, FileInfo> entry = iter.next();
        String containerFilePath = entry.getKey();
        FileInfo containerFileInfo = entry.getValue();
        iter.remove();
        // Get compact action arguments
        String containerFileDir = containerFilePath.substring(0, containerFilePath.lastIndexOf("/") + 1);
        if (firstFileDir.equals(containerFileDir) && firstFilePermission.equals(new SmartFilePermission(containerFileInfo))) {
            List<String> validSmallFiles;
            try {
                validSmallFiles = getValidSmallFiles(containerFileInfo, smallFileList);
            } catch (MetaStoreException e) {
                LOG.error("Failed to get file info of small files.", e);
                continue;
            }
            if (validSmallFiles != null) {
                return new CompactActionArgs(containerFilePath, null, validSmallFiles);
            }
        }
    }
    return genCompactActionArgs(firstFileDir, firstFilePermission, smallFileList);
}
Also used : MetaStoreException(org.smartdata.metastore.MetaStoreException) FileInfo(org.smartdata.model.FileInfo) SmartFilePermission(org.smartdata.SmartFilePermission) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

FileInfo (org.smartdata.model.FileInfo)51 Test (org.junit.Test)17 ArrayList (java.util.ArrayList)15 FileDiff (org.smartdata.model.FileDiff)12 AlluxioURI (alluxio.AlluxioURI)10 HashMap (java.util.HashMap)10 URIStatus (alluxio.client.file.URIStatus)9 MetaStoreException (org.smartdata.metastore.MetaStoreException)9 BackUpInfo (org.smartdata.model.BackUpInfo)7 FileSystem (alluxio.client.file.FileSystem)6 JournalEntry (alluxio.proto.journal.Journal.JournalEntry)6 AlluxioEntryApplier (org.smartdata.alluxio.metric.fetcher.AlluxioEntryApplier)6 SmartFilePermission (org.smartdata.SmartFilePermission)5 Gson (com.google.gson.Gson)4 IOException (java.io.IOException)4 LinkedHashMap (java.util.LinkedHashMap)4 ActionInfo (org.smartdata.model.ActionInfo)4 AlluxioException (alluxio.exception.AlluxioException)3 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3