Search in sources :

Example 1 with ListFile

use of org.ow2.proactive_grid_cloud_portal.dataspace.dto.ListFile in project scheduling by ow2-proactive.

the class DataSpaceClient method list.

@Override
public ListFile list(IRemoteSource source) throws NotConnectedException, PermissionException {
    StringBuffer uriTmpl = (new StringBuffer()).append(restDataspaceUrl).append(source.getDataspace().value());
    ResteasyClient client = new ResteasyClientBuilder().providerFactory(providerFactory).httpEngine(httpEngine).build();
    ResteasyWebTarget target = client.target(uriTmpl.toString()).path(source.getPath()).queryParam("comp", "list");
    List<String> includes = source.getIncludes();
    if (includes != null && !includes.isEmpty()) {
        target = target.queryParam("includes", includes.toArray(new Object[includes.size()]));
    }
    List<String> excludes = source.getExcludes();
    if (excludes != null && !excludes.isEmpty()) {
        target = target.queryParam("excludes", excludes.toArray(new Object[excludes.size()]));
    }
    Response response = null;
    try {
        response = target.request().header("sessionid", sessionId).get();
        if (response.getStatus() != HttpURLConnection.HTTP_OK) {
            if (response.getStatus() == HttpURLConnection.HTTP_UNAUTHORIZED) {
                throw new NotConnectedException("User not authenticated or session timeout.");
            } else {
                throw new RuntimeException(String.format("Cannot list the specified location: %s", source.getPath()));
            }
        }
        return response.readEntity(ListFile.class);
    } finally {
        if (response != null) {
            response.close();
        }
    }
}
Also used : ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget)

Example 2 with ListFile

use of org.ow2.proactive_grid_cloud_portal.dataspace.dto.ListFile in project scheduling by ow2-proactive.

the class SchedulerRestClient method list.

public ListFile list(String sessionId, String dataspacePath, String pathname) throws Exception {
    StringBuffer uriTmpl = (new StringBuffer()).append(restEndpointURL).append(addSlashIfMissing(restEndpointURL)).append("data/").append(dataspacePath).append('/');
    ResteasyClient client = buildResteasyClient(providerFactory);
    ResteasyWebTarget target = client.target(uriTmpl.toString()).path(pathname).queryParam("comp", "list");
    Response response = null;
    try {
        response = target.request().header("sessionid", sessionId).get();
        if (response.getStatus() != HttpURLConnection.HTTP_OK) {
            if (response.getStatus() == HttpURLConnection.HTTP_UNAUTHORIZED) {
                throw new NotConnectedRestException("User not authenticated or session timeout.");
            } else {
                throwException(String.format("Cannot list the specified location: %s", pathname), response);
            }
        }
        return response.readEntity(ListFile.class);
    } finally {
        if (response != null) {
            response.close();
        }
    }
}
Also used : ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)

Example 3 with ListFile

use of org.ow2.proactive_grid_cloud_portal.dataspace.dto.ListFile in project scheduling by ow2-proactive.

the class FileSystem method list.

public static ListFile list(FileObject fo, List<String> includes, List<String> excludes) throws FileSystemException {
    fo.refresh();
    ListFile answer = new ListFile();
    List<String> dirList = Lists.newArrayList();
    List<String> fileList = Lists.newArrayList();
    List<String> fullList = Lists.newArrayList();
    List<FileObject> foundFileObjects = new LinkedList<>();
    if (isNullOrEmpty(includes) && isNullOrEmpty(excludes)) {
        fo.findFiles(Selectors.SELECT_CHILDREN, false, foundFileObjects);
    } else {
        FileSelector selector = new org.objectweb.proactive.extensions.dataspaces.vfs.selector.FileSelector(includes, excludes);
        fo.findFiles(selector, false, foundFileObjects);
    }
    for (FileObject child : foundFileObjects) {
        FileType type = child.getType();
        FileName childName = child.getName();
        switch(type) {
            case FOLDER:
                if (!child.equals(fo)) {
                    // exclude root directory from the list
                    String relativePath = fo.getName().getRelativeName(childName);
                    dirList.add(relativePath);
                    fullList.add(relativePath);
                }
                break;
            case FILE:
                String relativePath = fo.getName().getRelativeName(childName);
                fileList.add(relativePath);
                fullList.add(relativePath);
                break;
            default:
                throw new RuntimeException("Unknown : " + type);
        }
    }
    Collections.sort(dirList);
    Collections.sort(fileList);
    Collections.sort(fullList);
    answer.setDirectoryListing(dirList);
    answer.setFileListing(fileList);
    answer.setFullListing(fullList);
    return answer;
}
Also used : LinkedList(java.util.LinkedList) ListFile(org.ow2.proactive_grid_cloud_portal.dataspace.dto.ListFile)

Example 4 with ListFile

use of org.ow2.proactive_grid_cloud_portal.dataspace.dto.ListFile in project scheduling by ow2-proactive.

the class DataTransferTest method testListFilesRecursiveWithPattern.

@Test
public void testListFilesRecursiveWithPattern() throws Exception {
    String testFolderName = "testListFilesRecursiveWithPattern";
    System.out.println(testFolderName);
    createFilesInUserSpace(testFolderName);
    // use standard client
    IDataSpaceClient client = clientInstance();
    RemoteSource source = new RemoteSource(USER, testFolderName);
    source.setIncludes("**/*.tmp");
    ListFile listFile = client.list(source);
    List<String> directories = listFile.getDirectoryListing();
    System.out.println("Directories : " + directories);
    assertEquals(0, directories.size());
    List<String> files = listFile.getFileListing();
    System.out.println("Files : " + files);
    assertEquals(1, files.size());
    assertEquals(TEMP_FILE_TMP_PATH, files.get(0));
    // use RemoteSpace API
    List<String> foundFiles = client.getUserSpace().listFiles(testFolderName, "**/*.tmp");
    System.out.println("Full : " + foundFiles);
    assertEquals(1, foundFiles.size());
    assertArrayEquals(new String[] { TEMP_FILE_TMP_PATH }, foundFiles.toArray(new String[0]));
}
Also used : ListFile(org.ow2.proactive_grid_cloud_portal.dataspace.dto.ListFile) Test(org.junit.Test)

Example 5 with ListFile

use of org.ow2.proactive_grid_cloud_portal.dataspace.dto.ListFile in project scheduling by ow2-proactive.

the class DataTransferTest method testListFilesNonRecursive.

@Test
public void testListFilesNonRecursive() throws Exception {
    String testFolderName = "testListFilesNonRecursive";
    System.out.println(testFolderName);
    createFilesInUserSpace(testFolderName);
    // use standard client
    IDataSpaceClient client = clientInstance();
    RemoteSource source = new RemoteSource(USER, testFolderName);
    source.setIncludes("*");
    ListFile listFile = client.list(source);
    List<String> directories = listFile.getDirectoryListing();
    System.out.println("Directories : " + directories);
    assertEquals(1, directories.size());
    assertEquals(TEMP_DIR_NAME, directories.get(0));
    List<String> files = listFile.getFileListing();
    System.out.println("Files : " + files);
    assertEquals(1, files.size());
    assertEquals(TEMP_FILE_TXT_NAME, files.get(0));
    // use RemoteSpace API
    List<String> foundFiles = client.getUserSpace().listFiles(testFolderName, "*");
    System.out.println("Full : " + foundFiles);
    assertEquals(2, foundFiles.size());
    assertArrayEquals(new String[] { TEMP_DIR_NAME, TEMP_FILE_TXT_NAME }, foundFiles.toArray(new String[0]));
}
Also used : ListFile(org.ow2.proactive_grid_cloud_portal.dataspace.dto.ListFile) Test(org.junit.Test)

Aggregations

ListFile (org.ow2.proactive_grid_cloud_portal.dataspace.dto.ListFile)4 Test (org.junit.Test)3 ResteasyClient (org.jboss.resteasy.client.jaxrs.ResteasyClient)2 ResteasyWebTarget (org.jboss.resteasy.client.jaxrs.ResteasyWebTarget)2 LinkedList (java.util.LinkedList)1 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)1 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)1 NotConnectedRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)1