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);
}
}
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;
}
}
}
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) {
}
}
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);
}
}
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;
}
}
Aggregations