use of org.syncany.plugins.transfer.StorageException in project syncany by syncany.
the class UploadInterruptedTest method testUnreliableUpload_Test4_1_FailsAtSecondMultiChunkUpload.
@Test
public void testUnreliableUpload_Test4_1_FailsAtSecondMultiChunkUpload() throws Exception {
/*
* This test fails when trying to upload the second multichunk, but succeeds on retry
*
* 1. upload(action-up-987, actions/action-up-987)
* 2. upload(transaction-123, transactions/transaction-123)
* 3. upload(multichunk-1, temp-1)
* 4. upload(multichunk-2, temp-2) <<< FAILS HERE
* 5. upload(database-123, temp-3) 6. move(temp-1, multichunks/multichunk-1)
* 7. move(temp-2, multichunks/multichunk-2)
* 8. move(temp-3, databases/database-123)
*/
// Setup
UnreliableLocalTransferSettings testConnection = TestConfigUtil.createTestUnreliableLocalConnection(Arrays.asList(new String[] { "rel=[456].+upload.+multichunk" }));
TestClient clientA = new TestClient("A", testConnection);
// << larger than one multichunk!
clientA.createNewFile("A-original", 5 * 1024 * 1024);
boolean upFailed = false;
try {
clientA.up();
} catch (StorageException e) {
upFailed = true;
logger.log(Level.INFO, e.getMessage());
}
assertTrue(upFailed);
assertEquals(0, new File(testConnection.getPath() + "/databases/").listFiles().length);
assertEquals(0, new File(testConnection.getPath() + "/multichunks/").listFiles().length);
assertEquals(1, new File(testConnection.getPath() + "/actions/").listFiles().length);
assertEquals(1, new File(testConnection.getPath() + "/transactions/").listFiles().length);
File[] tempFiles = new File(testConnection.getPath() + "/temporary/").listFiles();
assertEquals(1, tempFiles.length);
// 1 MC with 1 MB, 1 with 4 MB; must be larger than 500 KB
assertTrue(tempFiles[0].length() > 500 * 1024);
File transactionFile = new File(testConnection.getPath() + "/transactions/").listFiles()[0];
TransactionTO transactionTO = new Persister().read(TransactionTO.class, transactionFile);
assertEquals(3, transactionTO.getActions().size());
assertTrue(transactionTO.getActions().get(0).getRemoteFile().getName().contains("multichunk-"));
assertTrue(transactionTO.getActions().get(1).getRemoteFile().getName().contains("multichunk-"));
assertTrue(transactionTO.getActions().get(2).getRemoteFile().getName().contains("database-"));
// 2. Second try succeeds and must clean up the transactions
clientA.up();
assertEquals(1, new File(testConnection.getPath() + "/databases/").listFiles().length);
assertEquals(2, new File(testConnection.getPath() + "/multichunks/").listFiles().length);
assertEquals(0, new File(testConnection.getPath() + "/actions/").listFiles().length);
assertEquals(0, new File(testConnection.getPath() + "/transactions/").listFiles().length);
assertEquals(0, new File(testConnection.getPath() + "/temporary/").listFiles().length);
// Tear down
clientA.deleteTestData();
}
use of org.syncany.plugins.transfer.StorageException in project syncany by syncany.
the class ApplicationLink method createTransferSettings.
private TransferSettings createTransferSettings(byte[] plaintextPluginSettingsBytes) throws StorageException, IOException {
// Find plugin ID and settings XML
int pluginIdentifierLength = Ints.fromByteArray(Arrays.copyOfRange(plaintextPluginSettingsBytes, 0, INTEGER_BYTES));
String pluginId = new String(Arrays.copyOfRange(plaintextPluginSettingsBytes, INTEGER_BYTES, INTEGER_BYTES + pluginIdentifierLength));
byte[] gzippedPluginSettingsByteArray = Arrays.copyOfRange(plaintextPluginSettingsBytes, INTEGER_BYTES + pluginIdentifierLength, plaintextPluginSettingsBytes.length);
String pluginSettings = IOUtils.toString(new GZIPInputStream(new ByteArrayInputStream(gzippedPluginSettingsByteArray)));
// Create transfer settings object
try {
TransferPlugin plugin = Plugins.get(pluginId, TransferPlugin.class);
if (plugin == null) {
throw new StorageException("Link contains unknown connection type '" + pluginId + "'. Corresponding plugin not found.");
}
Class<? extends TransferSettings> pluginTransferSettingsClass = TransferPluginUtil.getTransferSettingsClass(plugin.getClass());
TransferSettings transferSettings = new Persister().read(pluginTransferSettingsClass, pluginSettings);
logger.log(Level.INFO, "(Decrypted) link contains: " + pluginId + " -- " + pluginSettings);
return transferSettings;
} catch (Exception e) {
throw new StorageException(e);
}
}
use of org.syncany.plugins.transfer.StorageException in project syncany by syncany.
the class ApplicationLink method resolveLink.
private String resolveLink(String httpApplicationLink, int redirectCount) throws IllegalArgumentException, StorageException {
if (redirectCount >= LINK_HTTP_MAX_REDIRECT_COUNT) {
throw new IllegalArgumentException("Max. redirect count of " + LINK_HTTP_MAX_REDIRECT_COUNT + " for URL reached. Cannot find syncany:// link.");
}
try {
logger.log(Level.INFO, "- Retrieving HTTP HEAD for " + httpApplicationLink + " ...");
HttpHead headMethod = new HttpHead(httpApplicationLink);
HttpResponse httpResponse = createHttpClient().execute(headMethod);
// Find syncany:// link
Header locationHeader = httpResponse.getLastHeader("Location");
if (locationHeader == null) {
throw new Exception("Link does not redirect to a syncany:// link.");
}
String locationHeaderUrl = locationHeader.getValue();
Matcher locationHeaderMatcher = LINK_PATTERN.matcher(locationHeaderUrl);
boolean isApplicationLink = locationHeaderMatcher.find();
if (isApplicationLink) {
String applicationLink = locationHeaderMatcher.group(0);
logger.log(Level.INFO, "Resolved application link is: " + applicationLink);
return applicationLink;
} else {
return resolveLink(locationHeaderUrl, ++redirectCount);
}
} catch (StorageException | IllegalArgumentException e) {
throw e;
} catch (Exception e) {
throw new StorageException(e.getMessage(), e);
}
}
use of org.syncany.plugins.transfer.StorageException in project syncany by syncany.
the class AbstractInitCommand method askGenericChildPluginSettings.
/**
* Queries the user for a plugin (which plugin to use?) and then
* asks for all of the plugin's settings.
*
* <p>This case is triggered by a field looking like this:
* <tt>private TransferSettings childPluginSettings;</tt>
*/
private void askGenericChildPluginSettings(TransferSettings settings, TransferPluginOption option, Map<String, String> knownPluginSettings, String nestPrefix) throws StorageException, IllegalAccessException, InstantiationException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
TransferPluginOptionCallback optionCallback = createOptionCallback(settings, option.getCallback());
if (isInteractive) {
callAndPrintPreQueryCallback(optionCallback);
out.println();
out.println(option.getDescription() + ":");
}
TransferPlugin childPlugin = null;
Class<? extends TransferPlugin> pluginClass = TransferPluginUtil.getTransferPluginClass(settings.getClass());
// Non-interactive: Plugin settings might be given via command line
try {
childPlugin = initPlugin(knownPluginSettings.get(nestPrefix + option.getName() + GENERIC_PLUGIN_TYPE_IDENTIFIER));
} catch (Exception e) {
if (!isInteractive) {
throw new IllegalArgumentException("Missing nested plugin type (" + nestPrefix + option.getName() + GENERIC_PLUGIN_TYPE_IDENTIFIER + ") in non-interactive mode.");
}
}
// Interactive mode: Ask for sub-plugin
while (childPlugin == null) {
childPlugin = askPlugin(pluginClass);
}
if (isInteractive) {
out.println();
}
// Create nested/child settings
TransferSettings childSettings = childPlugin.createEmptySettings();
settings.setField(option.getField().getName(), childSettings);
nestPrefix = nestPrefix + option.getName() + NESTED_OPTIONS_SEPARATOR;
for (TransferPluginOption nestedOption : TransferPluginOptions.getOrderedOptions(childSettings.getClass())) {
askPluginSettings(childSettings, nestedOption, knownPluginSettings, nestPrefix);
}
if (isInteractive) {
callAndPrintPostQueryCallback(optionCallback, null);
}
}
use of org.syncany.plugins.transfer.StorageException in project syncany by syncany.
the class LocalTransferManager method move.
@Override
public void move(RemoteFile sourceFile, RemoteFile targetFile) throws StorageException {
connect();
File sourceRemoteFile = getRemoteFile(sourceFile);
File targetRemoteFile = getRemoteFile(targetFile);
if (!sourceRemoteFile.exists()) {
throw new StorageMoveException("Unable to move file " + sourceFile + " because it does not exist.");
}
try {
FileUtils.moveFile(sourceRemoteFile, targetRemoteFile);
} catch (IOException ex) {
throw new StorageException("Unable to move file " + sourceRemoteFile + " to destination " + targetRemoteFile, ex);
}
}
Aggregations