Search in sources :

Example 6 with IDataSpaceClient

use of org.ow2.proactive.scheduler.rest.ds.IDataSpaceClient in project scheduling by ow2-proactive.

the class DataTransferTest method testUploadArchiveFile.

private void testUploadArchiveFile(String archiveFileName, URL archiveFileSource, String testFolderName) throws Exception {
    File tmpZipFile = tmpDir.newFile(archiveFileName);
    FileUtils.copyInputStreamToFile(archiveFileSource.openStream(), tmpZipFile);
    // use standard client
    IDataSpaceClient client = clientInstance();
    LocalFileSource source = new LocalFileSource(tmpZipFile);
    RemoteDestination dest = new RemoteDestination(USER, testFolderName + "/" + archiveFileName);
    assertTrue(client.upload(source, dest));
    String destDirPath = URI.create(getScheduler().getUserSpaceURIs().get(0)).getPath();
    File destFile = new File(destDirPath, testFolderName + "/" + archiveFileName);
    assertTrue(Files.equal(tmpZipFile, destFile));
    // use RemoteSpace API
    FileUtils.deleteQuietly(destFile);
    client.getUserSpace().pushFile(tmpZipFile, testFolderName + "/" + archiveFileName);
    assertTrue(Files.equal(tmpZipFile, destFile));
}
Also used : ListFile(org.ow2.proactive_grid_cloud_portal.dataspace.dto.ListFile) File(java.io.File)

Example 7 with IDataSpaceClient

use of org.ow2.proactive.scheduler.rest.ds.IDataSpaceClient in project scheduling by ow2-proactive.

the class DataTransferTest method testCreateFile.

@Test
public void testCreateFile() throws Exception {
    URI srcDirPath = URI.create(getScheduler().getUserSpaceURIs().get(0));
    String filename = TEMP_FILE_TMP_NAME;
    RemoteSource source = new RemoteSource(USER, filename);
    source.setType(FileType.FILE);
    IDataSpaceClient client = clientInstance();
    assertTrue(client.create(source));
    File expectedFile = new File(srcDirPath.getPath(), filename);
    assertTrue(expectedFile.exists());
    assertTrue(expectedFile.isFile());
}
Also used : URI(java.net.URI) ListFile(org.ow2.proactive_grid_cloud_portal.dataspace.dto.ListFile) File(java.io.File) Test(org.junit.Test)

Example 8 with IDataSpaceClient

use of org.ow2.proactive.scheduler.rest.ds.IDataSpaceClient in project scheduling by ow2-proactive.

the class DataTransferTest method testDeleteFile.

@Test
public void testDeleteFile() throws Exception {
    URI srcDirPath = URI.create(getScheduler().getUserSpaceURIs().get(0));
    File srcFile = new File(new File(srcDirPath), TEMP_FILE_TMP_NAME);
    if (srcFile.exists()) {
        assertTrue(srcFile.delete());
    }
    Files.write(randomFileContents(), srcFile);
    // use standard client
    IDataSpaceClient client = clientInstance();
    RemoteSource source = new RemoteSource(USER, TEMP_FILE_TMP_NAME);
    assertTrue(client.delete(source));
    assertFalse(srcFile.exists());
    // use RemoteSpace API
    Files.write(randomFileContents(), srcFile);
    client.getUserSpace().deleteFile(TEMP_FILE_TMP_NAME);
    assertFalse(srcFile.exists());
}
Also used : URI(java.net.URI) ListFile(org.ow2.proactive_grid_cloud_portal.dataspace.dto.ListFile) File(java.io.File) Test(org.junit.Test)

Example 9 with IDataSpaceClient

use of org.ow2.proactive.scheduler.rest.ds.IDataSpaceClient in project scheduling by ow2-proactive.

the class DataTransferTest method clientInstance.

private IDataSpaceClient clientInstance() throws Exception {
    DataSpaceClient client = new DataSpaceClient();
    client.init(new ConnectionInfo(getRestServerUrl(), getLogin(), getPassword(), null, true));
    return client;
}
Also used : ConnectionInfo(org.ow2.proactive.authentication.ConnectionInfo)

Example 10 with IDataSpaceClient

use of org.ow2.proactive.scheduler.rest.ds.IDataSpaceClient in project scheduling by ow2-proactive.

the class DataTransferTest method testListFilesRecursive.

@Test
public void testListFilesRecursive() throws Exception {
    System.out.println("testListFilesRecursive");
    createFilesInUserSpace("testListFilesRecursive");
    // use standard client
    IDataSpaceClient client = clientInstance();
    RemoteSource source = new RemoteSource(USER, "testListFilesRecursive");
    source.setIncludes("**");
    ListFile listFile = client.list(source);
    List<String> directories = listFile.getDirectoryListing();
    System.out.println("Directories : " + directories);
    assertEquals(1, directories.size());
    assertEquals(DataTransferTest.TEMP_DIR_NAME, directories.get(0));
    List<String> files = listFile.getFileListing();
    System.out.println("Files : " + files);
    assertEquals(2, files.size());
    assertEquals(TEMP_FILE_TMP_PATH, files.get(0));
    assertEquals(TEMP_FILE_TXT_NAME, files.get(1));
    // use RemoteSpace API
    List<String> foundFiles = client.getUserSpace().listFiles("testListFilesRecursive", "**");
    System.out.println("Full : " + foundFiles);
    assertEquals(3, foundFiles.size());
    assertArrayEquals(new String[] { TEMP_DIR_NAME, TEMP_FILE_TMP_PATH, 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)15 Test (org.junit.Test)13 File (java.io.File)12 URI (java.net.URI)3 ConnectionInfo (org.ow2.proactive.authentication.ConnectionInfo)1