Search in sources :

Example 6 with VlException

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

the class TestWebWAVFS method testFileConsistency.

// 
@Test
public void testFileConsistency() throws VlException, IOException {
    if (quckTest) {
        return;
    }
    System.err.println("testFileConsistency");
    String testFileURI1 = uri.toASCIIString() + TestSettings.TEST_FILE_NAME1;
    try {
        int from;
        int size;
        if (this.root.contains("localhost")) {
            from = 100;
            size = 200;
        } else {
            from = 10;
            size = 20;
        }
        for (int j = from; j < size; j += 5) {
            File file = new File("/tmp/" + TestSettings.TEST_FILE_NAME1);
            FileOutputStream fos = new FileOutputStream(file);
            // 1MB
            byte[] buffer = new byte[1024 * 1024];
            Random r = new Random();
            for (int i = 0; i < j; i++) {
                r.nextBytes(buffer);
                fos.write(buffer);
                if (i % 100 == 0) {
                    System.err.println(i + " of " + j);
                }
            }
            fos.flush();
            fos.close();
            utils.postFile(file, uri.toASCIIString());
            String localChecksum = utils.getChecksum(file, "SHA1");
            Thread.sleep(40000);
            GetMethod get = new GetMethod(testFileURI1);
            client1.executeMethod(get);
            int status = get.getStatusCode();
            assertEquals(HttpStatus.SC_OK, status);
            InputStream in = get.getResponseBodyAsStream();
            File fromLob = new File("/tmp/fromLob");
            fos = new FileOutputStream(fromLob);
            byte[] buf = new byte[1024];
            int len;
            while ((len = in.read(buf)) > 0) {
                fos.write(buf, 0, len);
            }
            fos.close();
            in.close();
            String fromLobChecksum = utils.getChecksum(fromLob, "SHA1");
            assertEquals(fromLobChecksum, localChecksum);
            System.out.println(j + " of " + size);
        }
    } catch (Exception ex) {
        fail(ex.getMessage());
        Logger.getLogger(TestWebWAVFS.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        utils.deleteResource(testFileURI1, false);
    }
}
Also used : Random(java.util.Random) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) GetMethod(org.apache.commons.httpclient.methods.GetMethod) File(java.io.File) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) VlException(nl.uva.vlet.exception.VlException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) Test(org.junit.Test)

Example 7 with VlException

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

the class VPDRI method upload.

// private void debug(String msg) {
// if (debug) {
// //            System.err.println(this.getClass().getName() + ": " + msg);
// log.debug(msg);
// }
// }
private void upload(PDRI source) throws VlException, IOException {
    VFile file = getVfsClient().createFile(vrl, true);
    try {
        if (file instanceof CloudFile) {
            CloudFile uFile = (CloudFile) file;
            VFile sourceFile = getVfsClient().openFile(new VRL(source.getURI()));
            uFile.uploadFrom(sourceFile);
        } else if (file instanceof WebdavFile) {
            WebdavFile wFile = (WebdavFile) file;
            VFile sourceFile = getVfsClient().openFile(new VRL(source.getURI()));
            wFile.uploadFrom(sourceFile);
        }
        reconnectAttemts = 0;
    } catch (Exception ex) {
        if (reconnectAttemts < Constants.RECONNECT_NTRY) {
            reconnect();
            upload(source);
        } else {
            throw ex;
        }
    } catch (Throwable ex) {
        if (reconnectAttemts < Constants.RECONNECT_NTRY) {
            reconnect();
            upload(source);
        } else {
            throw ex;
        }
    }
}
Also used : VRL(nl.uva.vlet.vrl.VRL) CloudFile(nl.uva.vlet.vfs.cloud.CloudFile) WebdavFile(nl.uva.vlet.vfs.webdavfs.WebdavFile) URISyntaxException(java.net.URISyntaxException) ResourceNotFoundException(nl.uva.vlet.exception.ResourceNotFoundException) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) JAXBException(javax.xml.bind.JAXBException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) VlException(nl.uva.vlet.exception.VlException) VRLSyntaxException(nl.uva.vlet.exception.VRLSyntaxException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) CertificateException(java.security.cert.CertificateException) UnknownHostException(java.net.UnknownHostException) BadPaddingException(javax.crypto.BadPaddingException)

Example 8 with VlException

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

the class VPDRI method putData.

@Override
public void putData(InputStream in) throws IOException {
    OutputStream out = null;
    double start = System.currentTimeMillis();
    // VFile tmpFile = null;
    try {
        // upload(in);
        VRL parentVrl = vrl.getParent();
        VDir remoteDir = getVfsClient().mkdirs(parentVrl, true);
        getVfsClient().createFile(vrl, true);
        out = getVfsClient().getFile(vrl).getOutputStream();
        if (!getEncrypted()) {
            // CircularStreamBufferTransferer cBuff = new CircularStreamBufferTransferer((Constants.BUF_SIZE), in, out);
            // cBuff.startTransfer(new Long(-1));
            int read;
            byte[] copyBuffer = new byte[Constants.BUF_SIZE];
            while ((read = in.read(copyBuffer, 0, copyBuffer.length)) != -1) {
                out.write(copyBuffer, 0, read);
            }
        } else {
            DesEncrypter encrypter = new DesEncrypter(getKeyInt());
            encrypter.encrypt(in, out);
        }
        reconnectAttemts = 0;
    } catch (nl.uva.vlet.exception.VlAuthenticationException | NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | InvalidAlgorithmParameterException ex) {
        throw new IOException(ex);
    } catch (VlException ex) {
        if (ex.getMessage() != null) {
            Logger.getLogger(VPDRI.class.getName()).log(Level.FINE, "\tVlException {0}", ex.getMessage());
        }
        if (reconnectAttemts <= 2) {
            Logger.getLogger(VPDRI.class.getName()).log(Level.FINE, "\treconnectAttemts {0}", reconnectAttemts);
            reconnect();
            putData(in);
        } else {
            throw new IOException(ex);
        }
    // if (ex instanceof ResourceNotFoundException || ex.getMessage().contains("not found") || ex.getMessage().contains("Couldn open location") || ex.getMessage().contains("not found in container")) {
    // try {
    // vfsClient.mkdirs(vrl.getParent(), true);
    // vfsClient.createFile(vrl, true);
    // putData(in);
    // } catch (VlException ex1) {
    // throw new IOException(ex1);
    // }
    // }
    } finally {
        if (out != null) {
            try {
                out.flush();
                out.close();
            } catch (java.io.IOException ex) {
            }
        }
        if (in != null) {
            in.close();
        }
    }
    double elapsed = System.currentTimeMillis() - start;
    double speed = ((getLength() * 8.0) * 1000.0) / (elapsed * 1000.0);
    try {
        String msg = "File: " + this.getFileName() + " Destination: " + new URI(getURI()).getScheme() + "://" + getHost() + " Rx_Speed: " + speed + " Kbites/sec Rx_Size: " + (getLength()) + " bytes Elapsed_Time: " + elapsed + " ms";
        Logger.getLogger(VPDRI.class.getName()).log(Level.INFO, msg);
    } catch (URISyntaxException ex) {
    }
}
Also used : InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) java.io(java.io) VlException(nl.uva.vlet.exception.VlException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) DesEncrypter(nl.uva.cs.lobcder.util.DesEncrypter) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) URISyntaxException(java.net.URISyntaxException) InvalidKeyException(java.security.InvalidKeyException) URI(java.net.URI) VRL(nl.uva.vlet.vrl.VRL)

Example 9 with VlException

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

the class GridHelper method initGridProxy.

public static void initGridProxy(String vo, String password, VRSContext context, boolean destroyCert) throws Exception {
    InitGlobalVFS();
    if (context == null) {
        context = new VFSClient().getVRSContext();
    // context = VRS.getDefaultVRSContext();
    }
    GridProxy gridProxy = context.getGridProxy();
    if (destroyCert) {
        gridProxy.destroy();
        gridProxy = null;
    }
    if (gridProxy == null) {
        // || gridProxy.isValid() == false) {
        // context.setProperty("grid.proxy.location", Constants.PROXY_FILE);
        // context.setProperty("grid.certificate.location", Global.getUserHome() + "/.globus");
        // context.setProperty("grid.proxy.lifetime", "100");
        // context.setProperty("grid.proxy.voName", vo);
        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!");
        // }
        }
    }
    if (!new File(Constants.PROXY_FILE).exists()) {
        gridProxy.saveProxyTo(Constants.PROXY_FILE);
    }
}
Also used : VFSClient(nl.uva.vlet.vfs.VFSClient) GridProxy(nl.uva.vlet.util.cog.GridProxy) VlException(nl.uva.vlet.exception.VlException) File(java.io.File)

Example 10 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)

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