Java 类com.vmware.vim25.FileInfo 实例源码

项目:cloudstack    文件:DatastoreMO.java   
public long fileDiskSize(String fileFullPath) throws Exception {
    long size = 0;
    DatastoreFile file = new DatastoreFile(fileFullPath);
    DatastoreFile dirFile = new DatastoreFile(file.getDatastoreName(), file.getDir());

    HostDatastoreBrowserMO browserMo = getHostDatastoreBrowserMO();

    HostDatastoreBrowserSearchSpec searchSpec = new HostDatastoreBrowserSearchSpec();
    FileQueryFlags fqf = new FileQueryFlags();
    fqf.setFileSize(true);
    fqf.setFileOwner(true);
    fqf.setModification(true);
    searchSpec.setDetails(fqf);
    searchSpec.setSearchCaseInsensitive(false);
    searchSpec.getMatchPattern().add(file.getFileName());
    s_logger.debug("Search file " + file.getFileName() + " on " + dirFile.getPath()); //ROOT-2.vmdk, [3ecf7a579d3b3793b86d9d019a97ae27] s-2-VM
    HostDatastoreBrowserSearchResults result = browserMo.searchDatastore(dirFile.getPath(), searchSpec);
    if (result != null) {
        List<FileInfo> info = result.getFile();
        for (FileInfo fi : info) {
            if (file.getFileName().equals(fi.getPath())) {
                s_logger.debug("File found = " + fi.getPath() + ", size=" + fi.getFileSize());
                return fi.getFileSize();
            }
        }
    }
    s_logger.debug("File " + fileFullPath + " does not exist on datastore");
    return size;
}
项目:cloudstack    文件:DatastoreMO.java   
public boolean folderExists(String folderParentDatastorePath, String folderName) throws Exception {
    HostDatastoreBrowserMO browserMo = getHostDatastoreBrowserMO();

    HostDatastoreBrowserSearchResults results = browserMo.searchDatastore(folderParentDatastorePath, folderName, true);
    if (results != null) {
        List<FileInfo> info = results.getFile();
        if (info != null && info.size() > 0) {
            s_logger.info("Folder " + folderName + " exists on datastore");
            return true;
        }
    }

    s_logger.info("Folder " + folderName + " does not exist on datastore");
    return false;
}
项目:cloudstack    文件:DatastoreMOTest.java   
@Before
public void setUp() throws Exception {

    datastoreMO = new DatastoreMO(_context, _mor);
    PowerMockito.whenNew(HostDatastoreBrowserMO.class).withAnyArguments().thenReturn(browserMo);
    when(_context.getVimClient()).thenReturn(_client);
    when(_client.getDynamicProperty(any(ManagedObjectReference.class), eq("name"))).thenReturn("252d36c96cfb32f48ce7756ccb79ae37");

    ArrayList<HostDatastoreBrowserSearchResults> results = new ArrayList<>();

    HostDatastoreBrowserSearchResults r1 =  new HostDatastoreBrowserSearchResults();
    FileInfo f1 = new FileInfo();
    f1.setPath(fileName);
    r1.getFile().add(f1);
    r1.setFolderPath("[252d36c96cfb32f48ce7756ccb79ae37] .snapshot/hourly.2017-02-23_1705/i-2-5-VM/");

    HostDatastoreBrowserSearchResults r2 =  new HostDatastoreBrowserSearchResults();
    FileInfo f2 = new FileInfo();
    f2.setPath(fileName);
    r2.getFile().add(f2);
    r2.setFolderPath("[252d36c96cfb32f48ce7756ccb79ae37] .snapshot/hourly.2017-02-23_1605/i-2-5-VM/");

    HostDatastoreBrowserSearchResults r3 =  new HostDatastoreBrowserSearchResults();
    FileInfo f3 = new FileInfo();
    f3.setPath(fileName);
    r3.getFile().add(f3);
    r3.setFolderPath("[252d36c96cfb32f48ce7756ccb79ae37] i-2-5-VM/");

    results.add(r1);
    results.add(r2);
    results.add(r3);

    when(browserMo.searchDatastore(any(String.class), any(String.class), eq(true))).thenReturn(null);
    when(browserMo.searchDatastoreSubFolders(any(String.class),any(String.class), any(Boolean.class) )).thenReturn(results);
}
项目:cloudstack    文件:VmwareStorageManagerImpl.java   
private long getVMSnapshotChainSize(VmwareContext context, VmwareHypervisorHost hyperHost, String fileName, ManagedObjectReference morDs, String exceptFileName)
        throws Exception {
    long size = 0;
    DatastoreMO dsMo = new DatastoreMO(context, morDs);
    HostDatastoreBrowserMO browserMo = dsMo.getHostDatastoreBrowserMO();
    String datastorePath = "[" + dsMo.getName() + "]";
    HostDatastoreBrowserSearchSpec searchSpec = new HostDatastoreBrowserSearchSpec();
    FileQueryFlags fqf = new FileQueryFlags();
    fqf.setFileSize(true);
    fqf.setFileOwner(true);
    fqf.setModification(true);
    searchSpec.setDetails(fqf);
    searchSpec.setSearchCaseInsensitive(false);
    searchSpec.getMatchPattern().add(fileName);
    ArrayList<HostDatastoreBrowserSearchResults> results = browserMo.searchDatastoreSubFolders(datastorePath, searchSpec);
    for (HostDatastoreBrowserSearchResults result : results) {
        if (result != null) {
            List<FileInfo> info = result.getFile();
            for (FileInfo fi : info) {
                if (exceptFileName != null && fi.getPath().contains(exceptFileName)) {
                    continue;
                } else {
                    size = size + fi.getFileSize();
                }
            }
        }
    }
    return size;
}