Search in sources :

Example 11 with ISymmetricEngine

use of org.jumpmind.symmetric.ISymmetricEngine in project symmetric-ds by JumpMind.

the class RestServiceTest method testRestPullApi.

protected void testRestPullApi() throws Exception {
    loadConfigAtRegistrationServer();
    RestService restService = getRegServer().getRestService();
    ISymmetricEngine engine = getRegServer().getEngine();
    IParameterService parameterService = engine.getParameterService();
    INodeService nodeService = engine.getNodeService();
    parameterService.saveParameter(ParameterConstants.REST_API_ENABLED, Boolean.TRUE, "unit_test");
    assertNotNull("Could not find the rest service in the application context", restService);
    List<Node> nodes = nodeService.findAllNodes();
    assertEquals("Expected there to only be one node registered", 1, nodes.size());
    assertEquals("The only node we expected to be registered is a server node", "server", nodes.get(0).getNodeGroupId());
    RegistrationInfo registrationInfo = restService.postRegisterNode("client", "client", DatabaseNamesConstants.SQLITE, "3.0", "hostName");
    assertNotNull("Registration should have returned a result object", registrationInfo);
    assertFalse("Registration should not have been open", registrationInfo.isRegistered());
    assertEquals("Expected there to only be one node registered", 1, nodes.size());
    engine.openRegistration("client", "client");
    registrationInfo = restService.postRegisterNode("client", "client", DatabaseNamesConstants.SQLITE, "3.0", "hostName");
    assertNotNull("Registration should have returned a result object", registrationInfo);
    assertTrue("Registration should have been open", registrationInfo.isRegistered());
    assertEquals("client", registrationInfo.getNodeId());
    try {
        restService.getPullData(registrationInfo.getNodeId(), "wrong password", false, false, true, null);
        fail("We should have received an exception");
    } catch (NotAllowedException ex) {
    }
    PullDataResults results = null;
    assertPullReturnsNoData(restService, registrationInfo);
    engine.getSqlTemplate().update("insert into a values(?, ?, ?)", 1, "this is a test", FormatUtils.parseDate("2013-06-08 00:00:00.000", FormatUtils.TIMESTAMP_PATTERNS));
    engine.route();
    results = restService.getPullData("server", registrationInfo.getNodeId(), registrationInfo.getNodePassword(), false, false, true, null);
    assertNotNull("Should have a non null results object", results);
    assertEquals(1, results.getNbrBatches());
    assertEquals(4, results.getBatches().get(0).getBatchId());
    log.info(results.getBatches().get(0).getSqlStatements().get(0));
    // pull a second time without acking.  should get the same results
    results = restService.getPullData("server", registrationInfo.getNodeId(), registrationInfo.getNodePassword(), false, false, false, null);
    assertNotNull("Should have a non null results object", results);
    assertEquals(1, results.getNbrBatches());
    // test that when we don't request jdbc timestamp format sql statements come back in that format
    assertFalse(results.getBatches().get(0).getSqlStatements().get(0).contains("{ts '"));
    // make sure we have no delimited identifiers
    assertFalse(results.getBatches().get(0).getSqlStatements().get(0).contains("\""));
    engine.getSqlTemplate().update("update a set notes=? where id=?", "changed", 1);
    engine.getSqlTemplate().update("update a set notes=? where id=?", "changed again", 1);
    engine.route();
    results = restService.getPullData("server", registrationInfo.getNodeId(), registrationInfo.getNodePassword(), true, false, true, null);
    assertNotNull("Should have a non null results object", results);
    assertEquals(2, results.getNbrBatches());
    assertNotSame(results.getBatches().get(1).getBatchId(), results.getBatches().get(0).getBatchId());
    assertEquals(2, results.getBatches().get(1).getSqlStatements().size());
    // test that when we request jdbc timestamp format sql statements come back in that format
    String testSql = results.getBatches().get(1).getSqlStatements().get(0);
    assertTrue("The following sql was supposed to contain '{ts '" + testSql, testSql.contains("{ts '"));
    // make sure we have delimited identifiers
    assertTrue(results.getBatches().get(1).getSqlStatements().get(0).contains("\""));
    log.info(results.getBatches().get(1).getSqlStatements().get(0));
    log.info(results.getBatches().get(1).getSqlStatements().get(1));
    ackBatches(restService, registrationInfo, results, buildBatchResults(registrationInfo, results));
    engine.getSqlTemplate().update("insert into a values(?, ?, ?)", 2, "this is a test", FormatUtils.parseDate("2073-06-08 00:00:00.000", FormatUtils.TIMESTAMP_PATTERNS));
    engine.getSqlTemplate().update("insert into a values(?, ?, ?)", 3, "this is a test", FormatUtils.parseDate("2073-06-08 00:00:00.000", FormatUtils.TIMESTAMP_PATTERNS));
    engine.getSqlTemplate().update("update a set notes=? where id=?", "update to 2", 2);
    engine.getSqlTemplate().update("update a set notes=? where id=?", "update to 3", 3);
    engine.getSqlTemplate().update("update a set notes=? where id=?", "update 2 again", 2);
    engine.route();
    results = restService.getPullData("server", registrationInfo.getNodeId(), registrationInfo.getNodePassword(), false, true, true, null);
    assertNotNull("Should have a non null results object", results);
    assertEquals(1, results.getNbrBatches());
    List<String> sqls = results.getBatches().get(0).getSqlStatements();
    assertEquals(5, sqls.size());
    for (String sql : sqls) {
        log.info(sql);
        assertTrue(sql, sql.toLowerCase().startsWith("insert or replace"));
    }
    ackBatches(restService, registrationInfo, results, buildBatchResults(registrationInfo, results));
    Channel channel = engine.getConfigurationService().getChannel("default");
    channel.setBatchAlgorithm("nontransactional");
    channel.setMaxBatchSize(1);
    engine.getConfigurationService().saveChannel(channel, true);
    engine.getSqlTemplate().update("delete from a");
    engine.route();
    results = restService.getPullData("server", registrationInfo.getNodeId(), registrationInfo.getNodePassword(), false, false, true, null);
    assertNotNull("Should have a non null results object", results);
    assertEquals(3, results.getNbrBatches());
    List<Batch> batches = results.getBatches();
    for (Batch batch : batches) {
        assertEquals(1, batch.getSqlStatements().size());
        assertTrue(batch.getSqlStatements().get(0).toLowerCase().startsWith("delete from"));
    }
    ackBatches(restService, registrationInfo, results, buildBatchResults(registrationInfo, results));
}
Also used : RegistrationInfo(org.jumpmind.symmetric.web.rest.model.RegistrationInfo) NotAllowedException(org.jumpmind.symmetric.web.rest.NotAllowedException) Node(org.jumpmind.symmetric.model.Node) Channel(org.jumpmind.symmetric.model.Channel) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) IParameterService(org.jumpmind.symmetric.service.IParameterService) PullDataResults(org.jumpmind.symmetric.web.rest.model.PullDataResults) Batch(org.jumpmind.symmetric.web.rest.model.Batch) INodeService(org.jumpmind.symmetric.service.INodeService) RestService(org.jumpmind.symmetric.web.rest.RestService)

Example 12 with ISymmetricEngine

use of org.jumpmind.symmetric.ISymmetricEngine in project symmetric-ds by JumpMind.

the class SimpleIntegrationTest method test02RegisterClientWithRoot.

@Test(timeout = 240000)
public void test02RegisterClientWithRoot() {
    logTestRunning();
    ISymmetricEngine rootEngine = getServer();
    INodeService rootNodeService = rootEngine.getNodeService();
    rootEngine.openRegistration(TestConstants.TEST_CLIENT_NODE_GROUP, TestConstants.TEST_CLIENT_EXTERNAL_ID);
    assertTrue("The registration for the client should be opened now", rootNodeService.findNodeSecurity(TestConstants.TEST_CLIENT_EXTERNAL_ID).isRegistrationEnabled());
    getClient().start();
    getClient().getParameterService().saveParameter(ParameterConstants.FILE_SYNC_ENABLE, false, "unit_test");
    clientPull();
    assertTrue("The client did not register", getClient().isRegistered());
    assertFalse("The registration for the client should be closed now", rootNodeService.findNodeSecurity(TestConstants.TEST_CLIENT_EXTERNAL_ID).isRegistrationEnabled());
    IStatisticManager statMgr = getClient().getStatisticManager();
    statMgr.flush();
    checkForFailedTriggers(true, true);
}
Also used : IStatisticManager(org.jumpmind.symmetric.statistic.IStatisticManager) INodeService(org.jumpmind.symmetric.service.INodeService) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) Test(org.junit.Test)

Example 13 with ISymmetricEngine

use of org.jumpmind.symmetric.ISymmetricEngine in project symmetric-ds by JumpMind.

the class AbstractIntegrationTest method getWebServer.

protected SymmetricWebServer getWebServer() {
    try {
        if (server == null) {
            EnvironmentSpecificProperties properties = new EnvironmentSpecificProperties(new URL[] { TestSetupUtil.getResource(DbTestUtils.DB_TEST_PROPERTIES), TestSetupUtil.getResource("/symmetric-test.properties") }, "test.root", new String[] { "root" });
            properties.setProperty(ParameterConstants.AUTO_CONFIGURE_REG_SVR_SQL_SCRIPT, "/test-integration-root-setup.sql");
            serverDatabase = properties.getProperty("test.root");
            File rootDir = new File("target/root");
            FileUtils.deleteDirectory(rootDir);
            rootDir.mkdirs();
            File rootdbs = new File("target/rootdbs");
            FileUtils.deleteDirectory(rootdbs);
            rootdbs.mkdirs();
            File clientdbs = new File("target/clientdbs");
            FileUtils.deleteDirectory(clientdbs);
            clientdbs.mkdirs();
            File engineDir = new File(rootDir, "engines");
            engineDir.mkdirs();
            File rootPropertiesFile = new File(engineDir, "root.properties");
            FileOutputStream fos = new FileOutputStream(rootPropertiesFile);
            properties.store(fos, "unit tests");
            fos.close();
            ISymmetricEngine engine = TestSetupUtil.prepareRoot();
            engine.destroy();
            System.setProperty(SystemConstants.SYSPROP_ENGINES_DIR, engineDir.getAbsolutePath());
            System.setProperty(SystemConstants.SYSPROP_WEB_DIR, "src/main/deploy/web");
            SymmetricWebServer server = new SymmetricWebServer();
            server.setJmxEnabled(false);
            server.setJoin(false);
            server.start(Integer.parseInt(AppUtils.getPortNumber()));
            server.waitForEnginesToComeOnline(240000);
            serverTestService = new TestTablesService(server.getEngine());
            AbstractIntegrationTest.server = server;
        }
    } catch (Exception e) {
        logger.error("", e);
        fail(e.getMessage());
    }
    return server != null ? server : null;
}
Also used : EnvironmentSpecificProperties(org.jumpmind.properties.EnvironmentSpecificProperties) FileOutputStream(java.io.FileOutputStream) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) File(java.io.File) InterruptedException(org.jumpmind.exception.InterruptedException) SymmetricWebServer(org.jumpmind.symmetric.SymmetricWebServer)

Example 14 with ISymmetricEngine

use of org.jumpmind.symmetric.ISymmetricEngine in project symmetric-ds by JumpMind.

the class AbstractTest method loadConfigAtRegistrationServer.

/**
 * Loads configuration in the format of classname.csv at the registration
 * server
 */
protected void loadConfigAtRegistrationServer() throws Exception {
    ISymmetricEngine regEngine = getRegServer().getEngine();
    IDataLoaderService dataLoaderService = regEngine.getDataLoaderService();
    boolean inError = false;
    String fileName = getClass().getSimpleName() + ".csv";
    log.info("Loading " + fileName + " on " + regEngine.getEngineName());
    InputStream is = getClass().getResourceAsStream(fileName);
    assertNotNull("Could not find configuration as a resource", is);
    List<IncomingBatch> batches = dataLoaderService.loadDataBatch(IOUtils.toString(is));
    for (IncomingBatch batch : batches) {
        if (batch.getStatus() == Status.ER) {
            inError = true;
        }
    }
    assertFalse("Failed to load configuration", inError);
}
Also used : IDataLoaderService(org.jumpmind.symmetric.service.IDataLoaderService) InputStream(java.io.InputStream) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) IncomingBatch(org.jumpmind.symmetric.model.IncomingBatch)

Example 15 with ISymmetricEngine

use of org.jumpmind.symmetric.ISymmetricEngine in project symmetric-ds by JumpMind.

the class RestService method getOutgoingBatchSummary.

@ApiOperation(value = "Outgoing summary of batches and data counts waiting for a node")
@RequestMapping(value = "/engine/{engine}/outgoingBatchSummary", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public final BatchSummaries getOutgoingBatchSummary(@PathVariable("engine") String engineName, @RequestParam(value = WebConstants.NODE_ID) String nodeId, @ApiParam(value = "This the password for the nodeId being passed in.  The password is stored in the node_security table.") @RequestParam(value = WebConstants.SECURITY_TOKEN) String securityToken) {
    ISymmetricEngine engine = getSymmetricEngine(engineName);
    if (securityVerified(nodeId, engine, securityToken)) {
        BatchSummaries summaries = new BatchSummaries();
        summaries.setNodeId(nodeId);
        IOutgoingBatchService outgoingBatchService = engine.getOutgoingBatchService();
        List<OutgoingBatchSummary> list = outgoingBatchService.findOutgoingBatchSummary(OutgoingBatch.Status.RQ, OutgoingBatch.Status.QY, OutgoingBatch.Status.NE, OutgoingBatch.Status.SE, OutgoingBatch.Status.LD, OutgoingBatch.Status.ER);
        for (OutgoingBatchSummary sum : list) {
            if (sum.getNodeId().equals(nodeId)) {
                BatchSummary summary = new BatchSummary();
                summary.setBatchCount(sum.getBatchCount());
                summary.setDataCount(sum.getDataCount());
                summary.setOldestBatchCreateTime(sum.getOldestBatchCreateTime());
                summary.setStatus(sum.getStatus().name());
                summaries.getBatchSummaries().add(summary);
            }
        }
        return summaries;
    } else {
        throw new NotAllowedException();
    }
}
Also used : BatchSummary(org.jumpmind.symmetric.web.rest.model.BatchSummary) OutgoingBatchSummary(org.jumpmind.symmetric.model.OutgoingBatchSummary) OutgoingBatchSummary(org.jumpmind.symmetric.model.OutgoingBatchSummary) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) IOutgoingBatchService(org.jumpmind.symmetric.service.IOutgoingBatchService) BatchSummaries(org.jumpmind.symmetric.web.rest.model.BatchSummaries) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

ISymmetricEngine (org.jumpmind.symmetric.ISymmetricEngine)35 IOException (java.io.IOException)12 INodeService (org.jumpmind.symmetric.service.INodeService)8 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)7 InputStream (java.io.InputStream)7 IDatabasePlatform (org.jumpmind.db.platform.IDatabasePlatform)7 Node (org.jumpmind.symmetric.model.Node)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)7 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)7 OutputStream (java.io.OutputStream)6 PipedInputStream (java.io.PipedInputStream)6 PipedOutputStream (java.io.PipedOutputStream)6 NotImplementedException (org.apache.commons.lang.NotImplementedException)6 DatabaseInfo (org.jumpmind.db.platform.DatabaseInfo)6 IExtensionService (org.jumpmind.symmetric.service.IExtensionService)6 File (java.io.File)5 ISqlTransaction (org.jumpmind.db.sql.ISqlTransaction)5 ProcessInfo (org.jumpmind.symmetric.model.ProcessInfo)5 IParameterService (org.jumpmind.symmetric.service.IParameterService)5