Search in sources :

Example 1 with InitOperation

use of org.syncany.operations.init.InitOperation in project syncany by syncany.

the class InitCommand method execute.

@Override
public int execute(String[] operationArgs) throws Exception {
    boolean retryNeeded = true;
    boolean performOperation = true;
    operationOptions = parseOptions(operationArgs);
    while (retryNeeded && performOperation) {
        InitOperationResult operationResult = new InitOperation(operationOptions, this).execute();
        printResults(operationResult);
        retryNeeded = operationResult.getResultCode() != InitResultCode.OK;
        if (retryNeeded) {
            performOperation = isInteractive && askRetryConnection();
            if (performOperation) {
                updateTransferSettings(operationOptions.getConfigTO().getTransferSettings());
            }
        }
    }
    return 0;
}
Also used : InitOperationResult(org.syncany.operations.init.InitOperationResult) InitOperation(org.syncany.operations.init.InitOperation)

Example 2 with InitOperation

use of org.syncany.operations.init.InitOperation in project syncany by syncany.

the class ConnectOperationTest method testConnectOperationFailureNoConnection.

@Test
public void testConnectOperationFailureNoConnection() throws Exception {
    // A.init()
    InitOperationOptions initOperationOptionsA = TestConfigUtil.createTestInitOperationOptions("A");
    InitOperation initOperationA = new InitOperation(initOperationOptionsA, null);
    InitOperationResult initOperationResultA = initOperationA.execute();
    String connectLinkA = initOperationResultA.getGenLinkResult().getShareLink();
    assertNotNull(connectLinkA);
    // B.connect()
    File localDirB = TestFileUtil.createTempDirectoryInSystemTemp(TestConfigUtil.createUniqueName("client-B", initOperationOptionsA));
    File localConnectDirB = new File(localDirB, Config.DIR_APPLICATION);
    File repoDir = ((LocalTransferSettings) initOperationOptionsA.getConfigTO().getTransferSettings()).getPath();
    ConfigTO connectionConfigToB = initOperationOptionsA.getConfigTO();
    // <<< Point to non-existing repo
    ((LocalTransferSettings) connectionConfigToB.getTransferSettings()).setPath(new File("/does/not/exist"));
    connectionConfigToB.setMachineName("client-B" + Math.abs(new Random().nextInt()));
    connectionConfigToB.setMasterKey(null);
    ConnectOperationOptions connectOperationOptionsB = new ConnectOperationOptions();
    connectOperationOptionsB.setStrategy(ConnectOptionsStrategy.CONNECTION_TO);
    connectOperationOptionsB.setConfigTO(connectionConfigToB);
    connectOperationOptionsB.setPassword(initOperationOptionsA.getPassword());
    connectOperationOptionsB.setLocalDir(localDirB);
    ConnectOperation connectOperationB = new ConnectOperation(connectOperationOptionsB, null);
    ConnectOperationResult connectOperationResultB = connectOperationB.execute();
    assertEquals(ConnectResultCode.NOK_TEST_FAILED, connectOperationResultB.getResultCode());
    assertFalse(new File(localConnectDirB, Config.DIR_DATABASE).exists());
    assertFalse(new File(localConnectDirB, Config.DIR_CACHE).exists());
    assertFalse(new File(localConnectDirB, Config.FILE_CONFIG).exists());
    assertFalse(new File(localConnectDirB, Config.DIR_LOG).exists());
    assertFalse(new File(localConnectDirB, Config.FILE_REPO).exists());
    // Tear down
    TestFileUtil.deleteDirectory(repoDir);
    TestFileUtil.deleteDirectory(localConnectDirB);
    TestFileUtil.deleteDirectory(initOperationOptionsA.getLocalDir());
    TestFileUtil.deleteDirectory(connectOperationOptionsB.getLocalDir());
}
Also used : ConnectOperationResult(org.syncany.operations.init.ConnectOperationResult) InitOperationResult(org.syncany.operations.init.InitOperationResult) InitOperation(org.syncany.operations.init.InitOperation) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) Random(java.util.Random) InitOperationOptions(org.syncany.operations.init.InitOperationOptions) ConnectOperation(org.syncany.operations.init.ConnectOperation) ConfigTO(org.syncany.config.to.ConfigTO) File(java.io.File) ConnectOperationOptions(org.syncany.operations.init.ConnectOperationOptions) Test(org.junit.Test)

Example 3 with InitOperation

use of org.syncany.operations.init.InitOperation in project syncany by syncany.

the class InitOperationTest method testInitOperation.

@Test
public void testInitOperation() throws Exception {
    InitOperationOptions operationOptions = TestConfigUtil.createTestInitOperationOptions("A");
    InitOperation op = new InitOperation(operationOptions, null);
    InitOperationResult res = op.execute();
    File repoDir = ((LocalTransferSettings) operationOptions.getConfigTO().getTransferSettings()).getPath();
    File localDir = new File(operationOptions.getLocalDir(), ".syncany");
    // Test the repository
    assertTrue((new File(repoDir, "databases").exists()));
    assertTrue((new File(repoDir, "syncany").exists()));
    assertTrue((new File(repoDir, "multichunks").exists()));
    assertEquals((new File(repoDir, "master").exists()), TestConfigUtil.getCrypto());
    // Test the local folder
    assertTrue((new File(localDir, Config.DIR_DATABASE).exists()));
    assertTrue((new File(localDir, Config.DIR_CACHE).exists()));
    assertTrue((new File(localDir, Config.FILE_CONFIG).exists()));
    assertTrue((new File(localDir, Config.DIR_LOG).exists()));
    assertTrue((new File(localDir, Config.FILE_REPO).exists()));
    assertEquals((new File(localDir, Config.FILE_MASTER).exists()), TestConfigUtil.getCrypto());
    // Test the existance of generated link
    String link = res.getGenLinkResult().getShareLink();
    assertNotNull(link);
    TestFileUtil.deleteDirectory(repoDir);
    TestFileUtil.deleteDirectory(operationOptions.getLocalDir());
}
Also used : InitOperationResult(org.syncany.operations.init.InitOperationResult) InitOperation(org.syncany.operations.init.InitOperation) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) UnreliableLocalTransferSettings(org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings) InitOperationOptions(org.syncany.operations.init.InitOperationOptions) File(java.io.File) Test(org.junit.Test)

Example 4 with InitOperation

use of org.syncany.operations.init.InitOperation in project syncany by syncany.

the class InitManagementRequestHandler method handleRequest.

@Override
public Response handleRequest(final ManagementRequest request) {
    final InitManagementRequest concreteRequest = (InitManagementRequest) request;
    logger.log(Level.SEVERE, "Executing InitOperation for folder " + concreteRequest.getOptions().getLocalDir() + " ...");
    Thread initThread = new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                InitOperation initOperation = new InitOperation(concreteRequest.getOptions(), new EventUserInteractionListener());
                InitOperationResult operationResult = initOperation.execute();
                switch(operationResult.getResultCode()) {
                    case OK:
                        eventBus.post(new InitManagementResponse(InitManagementResponse.OK, operationResult, request.getId()));
                        break;
                    case NOK_TEST_FAILED:
                        eventBus.post(new InitManagementResponse(InitManagementResponse.NOK_FAILED_TEST, operationResult, request.getId()));
                        break;
                    default:
                        eventBus.post(new InitManagementResponse(InitManagementResponse.NOK_FAILED_UNKNOWN, operationResult, request.getId()));
                        break;
                }
            } catch (Exception e) {
                logger.log(Level.WARNING, "Error adding watch to daemon config.", e);
                eventBus.post(new InitManagementResponse(InitManagementResponse.NOK_OPERATION_FAILED, new InitOperationResult(), request.getId()));
            }
        }
    }, "IntRq/" + concreteRequest.getOptions().getLocalDir().getName());
    initThread.start();
    return null;
}
Also used : InitOperationResult(org.syncany.operations.init.InitOperationResult) InitOperation(org.syncany.operations.init.InitOperation) EventUserInteractionListener(org.syncany.operations.daemon.EventUserInteractionListener)

Example 5 with InitOperation

use of org.syncany.operations.init.InitOperation in project syncany by syncany.

the class ConnectOperationTest method testConnectOperationSuccess.

@Test
public void testConnectOperationSuccess() throws Exception {
    // A.init()
    InitOperationOptions initOperationOptionsA = TestConfigUtil.createTestInitOperationOptions("A");
    InitOperation initOperationA = new InitOperation(initOperationOptionsA, null);
    InitOperationResult initOperationResultA = initOperationA.execute();
    String connectLinkA = initOperationResultA.getGenLinkResult().getShareLink();
    assertNotNull(connectLinkA);
    // B.connect()
    File localDirB = TestFileUtil.createTempDirectoryInSystemTemp(TestConfigUtil.createUniqueName("clientB", initOperationOptionsA));
    File localConnectDirB = new File(localDirB, Config.DIR_APPLICATION);
    ConfigTO connectionConfigToB = initOperationOptionsA.getConfigTO();
    connectionConfigToB.setMachineName("clientB" + Math.abs(new Random().nextInt()));
    connectionConfigToB.setMasterKey(null);
    ConnectOperationOptions connectOperationOptionsB = new ConnectOperationOptions();
    connectOperationOptionsB.setStrategy(ConnectOptionsStrategy.CONNECTION_TO);
    connectOperationOptionsB.setConfigTO(connectionConfigToB);
    connectOperationOptionsB.setPassword(initOperationOptionsA.getPassword());
    connectOperationOptionsB.setLocalDir(localDirB);
    ConnectOperation connectOperationB = new ConnectOperation(connectOperationOptionsB, null);
    ConnectOperationResult connectOperationResultB = connectOperationB.execute();
    assertEquals(ConnectResultCode.OK, connectOperationResultB.getResultCode());
    assertTrue(new File(localConnectDirB, Config.DIR_DATABASE).exists());
    assertTrue(new File(localConnectDirB, Config.DIR_CACHE).exists());
    assertTrue(new File(localConnectDirB, Config.FILE_CONFIG).exists());
    assertTrue(new File(localConnectDirB, Config.DIR_LOG).exists());
    assertTrue(new File(localConnectDirB, Config.FILE_REPO).exists());
    assertEquals(new File(localConnectDirB, Config.FILE_MASTER).exists(), TestConfigUtil.getCrypto());
    File repoDir = ((LocalTransferSettings) initOperationOptionsA.getConfigTO().getTransferSettings()).getPath();
    // Tear down
    TestFileUtil.deleteDirectory(repoDir);
    TestFileUtil.deleteDirectory(localConnectDirB);
    TestFileUtil.deleteDirectory(initOperationOptionsA.getLocalDir());
    TestFileUtil.deleteDirectory(connectOperationOptionsB.getLocalDir());
}
Also used : ConnectOperationResult(org.syncany.operations.init.ConnectOperationResult) InitOperationResult(org.syncany.operations.init.InitOperationResult) InitOperation(org.syncany.operations.init.InitOperation) Random(java.util.Random) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) InitOperationOptions(org.syncany.operations.init.InitOperationOptions) ConnectOperation(org.syncany.operations.init.ConnectOperation) ConfigTO(org.syncany.config.to.ConfigTO) File(java.io.File) ConnectOperationOptions(org.syncany.operations.init.ConnectOperationOptions) Test(org.junit.Test)

Aggregations

InitOperation (org.syncany.operations.init.InitOperation)7 InitOperationResult (org.syncany.operations.init.InitOperationResult)6 File (java.io.File)5 Test (org.junit.Test)5 InitOperationOptions (org.syncany.operations.init.InitOperationOptions)5 LocalTransferSettings (org.syncany.plugins.local.LocalTransferSettings)4 Random (java.util.Random)3 ConfigTO (org.syncany.config.to.ConfigTO)3 ConnectOperation (org.syncany.operations.init.ConnectOperation)3 ConnectOperationOptions (org.syncany.operations.init.ConnectOperationOptions)3 ConnectOperationResult (org.syncany.operations.init.ConnectOperationResult)3 UnreliableLocalTransferSettings (org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings)2 EventUserInteractionListener (org.syncany.operations.daemon.EventUserInteractionListener)1 StorageException (org.syncany.plugins.transfer.StorageException)1