Search in sources :

Example 31 with ISymmetricEngine

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

the class RestService method getPullData.

@ApiOperation(value = "Pull pending batches for the specified node for the specified engine")
@RequestMapping(value = "/engine/{engine}/pulldata", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public final PullDataResults getPullData(@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, @RequestParam(value = "useJdbcTimestampFormat", required = false, defaultValue = "true") boolean useJdbcTimestampFormat, @RequestParam(value = "useUpsertStatements", required = false, defaultValue = "false") boolean useUpsertStatements, @RequestParam(value = "useDelimitedIdentifiers", required = false, defaultValue = "true") boolean useDelimitedIdentifiers, @RequestParam(value = "hostName", required = false) String hostName) {
    ISymmetricEngine engine = getSymmetricEngine(engineName);
    IDataExtractorService dataExtractorService = engine.getDataExtractorService();
    IStatisticManager statisticManager = engine.getStatisticManager();
    INodeService nodeService = engine.getNodeService();
    org.jumpmind.symmetric.model.Node targetNode = nodeService.findNode(nodeId);
    if (securityVerified(nodeId, engine, securityToken)) {
        ProcessInfo processInfo = statisticManager.newProcessInfo(new ProcessInfoKey(nodeService.findIdentityNodeId(), nodeId, ProcessType.REST_PULL_HANLDER));
        try {
            PullDataResults results = new PullDataResults();
            List<OutgoingBatchWithPayload> extractedBatches = dataExtractorService.extractToPayload(processInfo, targetNode, PayloadType.SQL, useJdbcTimestampFormat, useUpsertStatements, useDelimitedIdentifiers);
            List<Batch> batches = new ArrayList<Batch>();
            for (OutgoingBatchWithPayload outgoingBatchWithPayload : extractedBatches) {
                if (outgoingBatchWithPayload.getStatus() == org.jumpmind.symmetric.model.OutgoingBatch.Status.LD || outgoingBatchWithPayload.getStatus() == org.jumpmind.symmetric.model.OutgoingBatch.Status.IG) {
                    Batch batch = new Batch();
                    batch.setBatchId(outgoingBatchWithPayload.getBatchId());
                    batch.setChannelId(outgoingBatchWithPayload.getChannelId());
                    batch.setSqlStatements(outgoingBatchWithPayload.getPayload());
                    batches.add(batch);
                }
            }
            results.setBatches(batches);
            results.setNbrBatches(batches.size());
            processInfo.setStatus(org.jumpmind.symmetric.model.ProcessInfo.Status.OK);
            if (engine.getParameterService().is(ParameterConstants.REST_HEARTBEAT_ON_PULL) && hostName != null) {
                Heartbeat heartbeat = new Heartbeat();
                heartbeat.setNodeId(nodeId);
                heartbeat.setHeartbeatTime(new Date());
                heartbeat.setHostName(hostName);
                this.heartbeatImpl(engine, heartbeat);
            }
            return results;
        } finally {
            if (processInfo.getStatus() != org.jumpmind.symmetric.model.ProcessInfo.Status.OK) {
                processInfo.setStatus(org.jumpmind.symmetric.model.ProcessInfo.Status.ERROR);
            }
        }
    } else {
        throw new NotAllowedException();
    }
}
Also used : OutgoingBatchWithPayload(org.jumpmind.symmetric.model.OutgoingBatchWithPayload) ArrayList(java.util.ArrayList) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) ProcessInfoKey(org.jumpmind.symmetric.model.ProcessInfoKey) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo) Date(java.util.Date) IStatisticManager(org.jumpmind.symmetric.statistic.IStatisticManager) PullDataResults(org.jumpmind.symmetric.web.rest.model.PullDataResults) IncomingBatch(org.jumpmind.symmetric.model.IncomingBatch) Batch(org.jumpmind.symmetric.web.rest.model.Batch) OutgoingBatch(org.jumpmind.symmetric.model.OutgoingBatch) INodeService(org.jumpmind.symmetric.service.INodeService) Heartbeat(org.jumpmind.symmetric.web.rest.model.Heartbeat) IDataExtractorService(org.jumpmind.symmetric.service.IDataExtractorService) 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)

Example 32 with ISymmetricEngine

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

the class RestService method postRegisterNode.

@ApiOperation(value = "Register the specified node for the specified engine")
@RequestMapping(value = "/engine/{engine}/registernode", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public final RegistrationInfo postRegisterNode(@PathVariable("engine") String engineName, @RequestParam(value = "externalId") String externalId, @RequestParam(value = "nodeGroupId") String nodeGroupId, @RequestParam(value = "databaseType") String databaseType, @RequestParam(value = "databaseVersion") String databaseVersion, @RequestParam(value = "hostName") String hostName) {
    ISymmetricEngine engine = getSymmetricEngine(engineName);
    IRegistrationService registrationService = engine.getRegistrationService();
    INodeService nodeService = engine.getNodeService();
    RegistrationInfo regInfo = new org.jumpmind.symmetric.web.rest.model.RegistrationInfo();
    try {
        org.jumpmind.symmetric.model.Node processedNode = registrationService.registerPullOnlyNode(externalId, nodeGroupId, databaseType, databaseVersion);
        regInfo.setRegistered(processedNode.isSyncEnabled());
        if (regInfo.isRegistered()) {
            regInfo.setNodeId(processedNode.getNodeId());
            NodeSecurity nodeSecurity = nodeService.findNodeSecurity(processedNode.getNodeId());
            regInfo.setNodePassword(nodeSecurity.getNodePassword());
            org.jumpmind.symmetric.model.Node modelNode = nodeService.findIdentity();
            regInfo.setSyncUrl(modelNode.getSyncUrl());
            // do an initial heartbeat
            Heartbeat heartbeat = new Heartbeat();
            heartbeat.setNodeId(regInfo.getNodeId());
            heartbeat.setHostName(hostName);
            Date now = new Date();
            heartbeat.setCreateTime(now);
            heartbeat.setLastRestartTime(now);
            heartbeat.setHeartbeatTime(now);
            this.heartbeatImpl(engine, heartbeat);
        }
    // TODO: Catch a RegistrationRedirectException and redirect.
    } catch (IOException e) {
        throw new IoException(e);
    }
    return regInfo;
}
Also used : RegistrationInfo(org.jumpmind.symmetric.web.rest.model.RegistrationInfo) NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) IRegistrationService(org.jumpmind.symmetric.service.IRegistrationService) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) IOException(java.io.IOException) Date(java.util.Date) INodeService(org.jumpmind.symmetric.service.INodeService) Heartbeat(org.jumpmind.symmetric.web.rest.model.Heartbeat) IoException(org.jumpmind.exception.IoException) 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)

Example 33 with ISymmetricEngine

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

the class SimpleIntegrationTest method test01CreateServer.

@Test(timeout = 240000)
public void test01CreateServer() {
    ISymmetricEngine server = getServer();
    assertNotNull(server);
    server.getParameterService().saveParameter(ParameterConstants.FILE_SYNC_ENABLE, false, "unit_test");
    checkForFailedTriggers(true, false);
}
Also used : ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) Test(org.junit.Test)

Example 34 with ISymmetricEngine

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

the class AbstractTest method test.

@Test(timeout = 240000)
public void test() throws Exception {
    ISymmetricEngine rootServer = getRegServer().getEngine();
    ISymmetricEngine clientServer = getWebServer("client").getEngine();
    test(rootServer, clientServer);
}
Also used : ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) Test(org.junit.Test)

Example 35 with ISymmetricEngine

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

the class AbstractTest method getWebServer.

protected SymmetricWebServer getWebServer(String name) {
    try {
        if (!webServers.containsKey(name)) {
            EnvironmentSpecificProperties properties = new EnvironmentSpecificProperties(new URL[] { getResource(DbTestUtils.DB_TEST_PROPERTIES) }, "test." + name, new String[] { name });
            properties.putAll(getProperties(name));
            File rootDir = new File("target/" + name);
            FileUtils.deleteDirectory(rootDir);
            rootDir.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();
            System.setProperty(SystemConstants.SYSPROP_WAIT_FOR_DATABASE, "false");
            System.setProperty(SystemConstants.SYSPROP_ENGINES_DIR, engineDir.getAbsolutePath());
            System.setProperty(SystemConstants.SYSPROP_WEB_DIR, "src/main/deploy/web");
            ISymmetricEngine engine = null;
            int tries = 2;
            do {
                /**
                 * Firebird is flaky.  Trying to work around it.
                 */
                try {
                    engine = new ClientSymmetricEngine(properties);
                } catch (Exception ex) {
                    log.warn("Failed to create engine on the first try.  Trying again.  The root cause of the first failure was: ", ex);
                    tries--;
                    AppUtils.sleep(30000);
                }
            } while (tries > 0 && engine == null);
            IDatabasePlatform platform = engine.getDatabasePlatform();
            engine.getStagingManager().clean(0);
            engine.uninstall();
            Database database = platform.getDdlReader().readTables(platform.getDefaultCatalog(), platform.getDefaultSchema(), new String[] { "TABLE" });
            platform.dropDatabase(database, true);
            Table[] tables = getTables(name);
            if (tables != null) {
                platform.alterCaseToMatchDatabaseDefaultCase(tables);
                platform.createTables(false, true, tables);
            }
            engine.destroy();
            SymmetricWebServer server = new SymmetricWebServer();
            server.setJmxEnabled(false);
            server.setHttpPort(port);
            log.info("Starting " + name + " on port " + port);
            server.setJoin(false);
            server.start();
            server.waitForEnginesToComeOnline(240000);
            webServers.put(name, server);
            port += 200;
        }
        return webServers.get(name);
    } catch (IOException e) {
        throw new IoException(e);
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : IDatabasePlatform(org.jumpmind.db.platform.IDatabasePlatform) Table(org.jumpmind.db.model.Table) EnvironmentSpecificProperties(org.jumpmind.properties.EnvironmentSpecificProperties) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) IOException(java.io.IOException) IoException(org.jumpmind.exception.IoException) InterruptedException(org.jumpmind.exception.InterruptedException) IOException(java.io.IOException) SymmetricWebServer(org.jumpmind.symmetric.SymmetricWebServer) FileOutputStream(java.io.FileOutputStream) ClientSymmetricEngine(org.jumpmind.symmetric.ClientSymmetricEngine) Database(org.jumpmind.db.model.Database) IoException(org.jumpmind.exception.IoException) File(java.io.File)

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