Search in sources :

Example 1 with VlException

use of nl.uva.vlet.exception.VlException in project lobcder by skoulouzis.

the class VPDRI method replicate.

@Override
public void replicate(PDRI source) throws IOException {
    try {
        VRL sourceVRL = new VRL(source.getURI());
        String sourceScheme = sourceVRL.getScheme();
        String desteScheme = vrl.getScheme();
        Logger.getLogger(VPDRI.class.getName()).log(Level.INFO, "Start replicating {0} to {1}", new Object[] { source.getURI(), getURI() });
        double start = System.currentTimeMillis();
        if (!vfsClient.existsDir(vrl.getParent())) {
            VDir remoteDir = vfsClient.mkdirs(vrl.getParent(), true);
        }
        if (desteScheme.equals("swift") && sourceScheme.equals("file") || desteScheme.startsWith("webdav") && sourceScheme.equals("file")) {
            upload(source);
        } else {
            VFile destFile = getVfsClient().createFile(vrl, true);
            VFile sourceFile = getVfsClient().openFile(sourceVRL);
            getVfsClient().copy(sourceFile, destFile);
        }
        // putData(source.getData());
        double elapsed = System.currentTimeMillis() - start;
        double speed = ((source.getLength() * 8.0) * 1000.0) / (elapsed * 1000.0);
        Stats stats = new Stats();
        stats.setSource(source.getHost());
        stats.setDestination(getHost());
        stats.setSpeed(speed);
        stats.setSize(getLength());
        try {
            setSpeed(stats);
        } catch (JAXBException ex) {
            Logger.getLogger(VPDRI.class.getName()).log(Level.WARNING, null, ex);
        }
        String msg = "Source: " + source.getHost() + " Destination: " + vrl.getScheme() + "://" + getHost() + " Replication_Speed: " + speed + " Kbites/sec Repl_Size: " + (getLength()) + " bytes";
        Logger.getLogger(VPDRI.class.getName()).log(Level.INFO, msg);
    // getAsyncDelete(getVfsClient(), vrl).run();
    } catch (VlException ex) {
        throw new IOException(ex);
    }
}
Also used : VRL(nl.uva.vlet.vrl.VRL) JAXBException(javax.xml.bind.JAXBException) Stats(nl.uva.cs.lobcder.rest.wrappers.Stats) VlException(nl.uva.vlet.exception.VlException)

Example 2 with VlException

use of nl.uva.vlet.exception.VlException in project lobcder by skoulouzis.

the class GridHelper method isGridProxyInt.

public static boolean isGridProxyInt() {
    try {
        File proxyFile = new File(Constants.PROXY_FILE);
        if (!proxyFile.exists()) {
            return false;
        }
        GridProxy p = GridProxy.loadFrom(Constants.PROXY_FILE);
        return p.isValid();
    } catch (VlException ex) {
        return false;
    }
}
Also used : GridProxy(nl.uva.vlet.util.cog.GridProxy) VlException(nl.uva.vlet.exception.VlException) File(java.io.File)

Example 3 with VlException

use of nl.uva.vlet.exception.VlException in project lobcder by skoulouzis.

the class Assimilator method main.

public static void main(String[] args) throws SQLException, MalformedURLException, VlException, NoSuchAlgorithmException, Exception {
    try {
        importingOwner = "admin";
        List<StorageSite> sites = new ArrayList<>();
        Credential credential = new Credential();
        credential.setStorageSiteUsername("fake");
        credential.setStorageSitePassword("fake");
        // StorageSite ss1 = new StorageSite();
        // ss1.setCredential(credential);
        // ss1.setResourceURI("swift://somewhere:8443/auth/v1.0/uploadContainer/");
        // ss1.setCurrentNum(Long.valueOf("-1"));
        // ss1.setCurrentSize(Long.valueOf("-1"));
        // ss1.setEncrypt(false);
        // ss1.setQuotaNum(Long.valueOf("-1"));
        // ss1.setQuotaSize(Long.valueOf("-1"));
        // sites.add(ss1);
        // 
        // 
        // StorageSite ss2 = new StorageSite();
        // ss2.setCredential(credential);
        // ss2.setResourceURI("file:///" + System.getProperty("user.home") + "/Downloads");
        // ss2.setCurrentNum(Long.valueOf("-1"));
        // ss2.setCurrentSize(Long.valueOf("-1"));
        // ss2.setEncrypt(false);
        // ss2.setQuotaNum(Long.valueOf("-1"));
        // ss2.setQuotaSize(Long.valueOf("-1"));
        // sites.add(ss2);
        // StorageSite ss3 = new StorageSite();
        // ss3.setCredential(credential);
        // ss3.setResourceURI("file:///" + System.getProperty("user.home") + "/Downloads/lobcderUsageData");
        // //            ss3.setResourceURI("srm://tbn18.nikhef.nl:8446/dpm/nikhef.nl/home/biomed/lobcder");
        // ss3.setCurrentNum(Long.valueOf("-1"));
        // ss3.setCurrentSize(Long.valueOf("-1"));
        // ss3.setEncrypt(false);
        // ss3.setQuotaNum(Long.valueOf("-1"));
        // ss3.setQuotaSize(Long.valueOf("-1"));
        // sites.add(ss3);
        StorageSite ss4 = new StorageSite();
        ss4.setCredential(credential);
        ss4.setResourceURI("http://data.sdss3.org/sas/dr12/apogee/spectro/redux/r5/apo1m/calibration/56357/plots/");
        ss4.setCurrentNum(Long.valueOf("-1"));
        ss4.setCurrentSize(Long.valueOf("-1"));
        ss4.setEncrypt(false);
        ss4.setQuotaNum(Long.valueOf("-1"));
        ss4.setQuotaSize(Long.valueOf("-1"));
        ss4.setPrivateSite(false);
        ss4.setReadOnly(true);
        sites.add(ss4);
        Assimilator a = new Assimilator();
        a.assimilate(sites);
    } catch (Exception ex) {
        ex.printStackTrace();
        Logger.getLogger(Assimilator.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        VRS.exit();
        System.exit(0);
    }
}
Also used : Credential(nl.uva.cs.lobcder.resources.Credential) StorageSite(nl.uva.cs.lobcder.resources.StorageSite) ArrayList(java.util.ArrayList) MalformedURLException(java.net.MalformedURLException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) VlException(nl.uva.vlet.exception.VlException)

Example 4 with VlException

use of nl.uva.vlet.exception.VlException in project lobcder by skoulouzis.

the class TestWebWAVFS method getVFSClient.

private VFSClient getVFSClient(String vrl, String username, String password) throws VlException {
    VFSClient vfsClient = new VFSClient();
    VRSContext context = vfsClient.getVRSContext();
    // Bug in sftp: We have to put the username in the url
    ServerInfo info = context.getServerInfoFor(new VRL(vrl), true);
    String authScheme = info.getAuthScheme();
    if (StringUtil.equals(authScheme, ServerInfo.GSI_AUTH)) {
        // copyVomsAndCerts();
        GridProxy gridProxy = null;
        if (gridProxy == null) {
            // context.setProperty("grid.proxy.location", Constants.PROXY_FILE);
            // Default to $HOME/.globus
            context.setProperty("grid.certificate.location", Global.getUserHome() + "/.globus");
            String vo = username;
            context.setProperty("grid.proxy.voName", vo);
            context.setProperty("grid.proxy.lifetime", "200");
            // gridProxy = GridProxy.loadFrom(context, proxyFile);
            gridProxy = context.getGridProxy();
            if (gridProxy.isValid() == false) {
                gridProxy.setEnableVOMS(true);
                gridProxy.setDefaultVOName(vo);
                gridProxy.createWithPassword(password);
                if (gridProxy.isValid() == false) {
                    throw new VlException("Created Proxy is not Valid!");
                }
            // gridProxy.saveProxyTo(Constants.PROXY_FILE);
            }
        }
    }
    if (StringUtil.equals(authScheme, ServerInfo.PASSWORD_AUTH) || StringUtil.equals(authScheme, ServerInfo.PASSWORD_OR_PASSPHRASE_AUTH) || StringUtil.equals(authScheme, ServerInfo.PASSPHRASE_AUTH)) {
        // String username = storageSite.getCredential().getStorageSiteUsername();
        if (username == null) {
            throw new NullPointerException("Username is null!");
        }
        info.setUsername(username);
        // String password = storageSite.getCredential().getStorageSitePassword();
        if (password == null) {
            throw new NullPointerException("password is null!");
        }
        info.setPassword(password);
    }
    info.setAttribute(ServerInfo.ATTR_DEFAULT_YES_NO_ANSWER, true);
    // if(getVrl().getScheme().equals(VRS.SFTP_SCHEME)){
    // patch for bug with ssh driver
    info.setAttribute("sshKnownHostsFile", System.getProperty("user.home") + "/.ssh/known_hosts");
    // }
    // context.setProperty("chunk.upload", doChunked);
    // info.setAttribute(new VAttribute("chunk.upload", true));
    info.store();
    return vfsClient;
}
Also used : VRSContext(nl.uva.vlet.vrs.VRSContext) VRL(nl.uva.vlet.vrl.VRL) VFSClient(nl.uva.vlet.vfs.VFSClient) ServerInfo(nl.uva.vlet.vrs.ServerInfo) GridProxy(nl.uva.vlet.util.cog.GridProxy) VlException(nl.uva.vlet.exception.VlException)

Example 5 with VlException

use of nl.uva.vlet.exception.VlException in project lobcder by skoulouzis.

the class TestWebWAVFS method testInconsistency.

@Test
public void testInconsistency() throws VlException, IOException {
    System.err.println("testInconsistency");
    String testFileURI1 = uri.toASCIIString() + TestSettings.TEST_FILE_NAME1 + ".txt";
    try {
        PutMethod put = new PutMethod(testFileURI1);
        put.setRequestEntity(new StringRequestEntity(TestSettings.TEST_DATA, "text/plain", "UTF-8"));
        int status = client1.executeMethod(put);
        assertEquals(HttpStatus.SC_CREATED, status);
        Set<PDRIDesc> pdris = null;
        // Wait for replication
        utils.waitForReplication(testFileURI1);
        pdris = getPdris(TestSettings.TEST_FILE_NAME1 + ".txt");
        // Delete the physical data
        deletePhysicalData(pdris);
        GetMethod get = new GetMethod(testFileURI1);
        status = client1.executeMethod(get);
        String cont = get.getResponseBodyAsString();
        // There is no offical status to get from this but  confilct seems apropriate:
        // Status code (409) indicating that the request could not be
        // completed due to a conflict with the current state of the resource.
        // Meaning at this time we have no physical data
        assertEquals(HttpStatus.SC_CONFLICT, status);
    } catch (Exception ex) {
        Logger.getLogger(TestWebWAVFS.class.getName()).log(Level.SEVERE, null, ex);
        fail(ex.getMessage());
    } finally {
        utils.deleteResource(testFileURI1, false);
    }
}
Also used : StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) PDRIDesc(nl.uva.cs.lobcder.tests.TestREST.PDRIDesc) GetMethod(org.apache.commons.httpclient.methods.GetMethod) PutMethod(org.apache.jackrabbit.webdav.client.methods.PutMethod) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) VlException(nl.uva.vlet.exception.VlException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

VlException (nl.uva.vlet.exception.VlException)14 File (java.io.File)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)6 GridProxy (nl.uva.vlet.util.cog.GridProxy)5 IOException (java.io.IOException)4 MalformedURLException (java.net.MalformedURLException)4 VRL (nl.uva.vlet.vrl.VRL)4 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)3 InvalidKeyException (java.security.InvalidKeyException)3 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)3 VFSClient (nl.uva.vlet.vfs.VFSClient)3 FileNotFoundException (java.io.FileNotFoundException)2 FileOutputStream (java.io.FileOutputStream)2 URISyntaxException (java.net.URISyntaxException)2 JAXBException (javax.xml.bind.JAXBException)2 DesEncrypter (nl.uva.cs.lobcder.util.DesEncrypter)2 GetMethod (org.apache.commons.httpclient.methods.GetMethod)2 Test (org.junit.Test)2 java.io (java.io)1 InputStream (java.io.InputStream)1