Search in sources :

Example 11 with FileInfo

use of com.intellij.openapi.util.io.win32.FileInfo in project cloudstack by apache.

the class DatastoreMO method searchFileInSubFolders.

public String searchFileInSubFolders(String fileName, boolean caseInsensitive, String excludeFolders) throws Exception {
    String datastorePath = "[" + getName() + "]";
    String rootDirectoryFilePath = String.format("%s %s", datastorePath, fileName);
    String[] searchExcludedFolders = getSearchExcludedFolders(excludeFolders);
    if (fileExists(rootDirectoryFilePath)) {
        return rootDirectoryFilePath;
    }
    String parentFolderPath;
    String absoluteFileName = null;
    s_logger.info("Searching file " + fileName + " in " + datastorePath);
    HostDatastoreBrowserMO browserMo = getHostDatastoreBrowserMO();
    ArrayList<HostDatastoreBrowserSearchResults> results = browserMo.searchDatastoreSubFolders("[" + getName() + "]", fileName, caseInsensitive);
    if (results != null && results.size() > 1) {
        s_logger.warn("Multiple files with name " + fileName + " exists in datastore " + datastorePath + ". Trying to choose first file found in search attempt.");
    } else if (results == null) {
        String msg = "No file found with name " + fileName + " found in datastore " + datastorePath;
        s_logger.error(msg);
        throw new CloudException(msg);
    }
    for (HostDatastoreBrowserSearchResults result : results) {
        List<FileInfo> info = result.getFile();
        if (info != null && info.size() > 0) {
            for (FileInfo fi : info) {
                absoluteFileName = parentFolderPath = result.getFolderPath();
                s_logger.info("Found file " + fileName + " in datastore at " + absoluteFileName);
                if (parentFolderPath.endsWith("]"))
                    absoluteFileName += " ";
                else if (!parentFolderPath.endsWith("/"))
                    absoluteFileName += "/";
                absoluteFileName += fi.getPath();
                if (isValidCloudStackFolderPath(parentFolderPath, searchExcludedFolders)) {
                    return absoluteFileName;
                }
                break;
            }
        }
    }
    return absoluteFileName;
}
Also used : HostDatastoreBrowserSearchResults(com.vmware.vim25.HostDatastoreBrowserSearchResults) FileInfo(com.vmware.vim25.FileInfo) CloudException(com.cloud.exception.CloudException)

Example 12 with FileInfo

use of com.intellij.openapi.util.io.win32.FileInfo in project cloudstack by apache.

the class DatastoreMOTest method setUp.

@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);
}
Also used : HostDatastoreBrowserSearchResults(com.vmware.vim25.HostDatastoreBrowserSearchResults) FileInfo(com.vmware.vim25.FileInfo) ArrayList(java.util.ArrayList) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) Before(org.junit.Before)

Aggregations

FileInfo (com.vmware.vim25.FileInfo)8 HostDatastoreBrowserSearchResults (com.vmware.vim25.HostDatastoreBrowserSearchResults)8 FileInfo (com.intellij.openapi.util.io.win32.FileInfo)4 FileAttributes (com.intellij.openapi.util.io.FileAttributes)2 VirtualFileWithId (com.intellij.openapi.vfs.VirtualFileWithId)2 FileQueryFlags (com.vmware.vim25.FileQueryFlags)2 HostDatastoreBrowserSearchSpec (com.vmware.vim25.HostDatastoreBrowserSearchSpec)2 THashMap (gnu.trove.THashMap)2 NotNull (org.jetbrains.annotations.NotNull)2 CloudException (com.cloud.exception.CloudException)1 DatastoreFile (com.cloud.hypervisor.vmware.mo.DatastoreFile)1 DatastoreMO (com.cloud.hypervisor.vmware.mo.DatastoreMO)1 HostDatastoreBrowserMO (com.cloud.hypervisor.vmware.mo.HostDatastoreBrowserMO)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Nullable (org.jetbrains.annotations.Nullable)1 Before (org.junit.Before)1