Search in sources :

Example 1 with OutgoingBatchWithPayload

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

the class DataExtractorService method extractToPayload.

public List<OutgoingBatchWithPayload> extractToPayload(ProcessInfo processInfo, Node targetNode, PayloadType payloadType, boolean useJdbcTimestampFormat, boolean useUpsertStatements, boolean useDelimiterIdentifiers) {
    OutgoingBatches batches = outgoingBatchService.getOutgoingBatches(targetNode.getNodeId(), false);
    if (batches.containsBatches()) {
        ChannelMap channelMap = configurationService.getSuspendIgnoreChannelLists(targetNode.getNodeId());
        List<OutgoingBatch> activeBatches = filterBatchesForExtraction(batches, channelMap);
        if (activeBatches.size() > 0) {
            IDdlBuilder builder = DdlBuilderFactory.createDdlBuilder(targetNode.getDatabaseType());
            if (builder == null) {
                throw new IllegalStateException("Could not find a ddl builder registered for the database type of " + targetNode.getDatabaseType() + ".  Please check the database type setting for node '" + targetNode.getNodeId() + "'");
            }
            StructureDataWriter writer = new StructureDataWriter(symmetricDialect.getPlatform(), targetNode.getDatabaseType(), payloadType, useDelimiterIdentifiers, symmetricDialect.getBinaryEncoding(), useJdbcTimestampFormat, useUpsertStatements);
            List<OutgoingBatch> extractedBatches = extract(processInfo, targetNode, activeBatches, writer, ExtractMode.FOR_PAYLOAD_CLIENT);
            List<OutgoingBatchWithPayload> batchesWithPayload = new ArrayList<OutgoingBatchWithPayload>();
            for (OutgoingBatch batch : extractedBatches) {
                OutgoingBatchWithPayload batchWithPayload = new OutgoingBatchWithPayload(batch, payloadType);
                batchWithPayload.setPayload(writer.getPayloadMap().get(batch.getBatchId()));
                batchWithPayload.setPayloadType(payloadType);
                batchesWithPayload.add(batchWithPayload);
            }
            return batchesWithPayload;
        }
    }
    return Collections.emptyList();
}
Also used : ChannelMap(org.jumpmind.symmetric.model.ChannelMap) OutgoingBatchWithPayload(org.jumpmind.symmetric.model.OutgoingBatchWithPayload) IDdlBuilder(org.jumpmind.db.platform.IDdlBuilder) ArrayList(java.util.ArrayList) OutgoingBatches(org.jumpmind.symmetric.model.OutgoingBatches) OutgoingBatch(org.jumpmind.symmetric.model.OutgoingBatch) StructureDataWriter(org.jumpmind.symmetric.io.data.writer.StructureDataWriter)

Example 2 with OutgoingBatchWithPayload

use of org.jumpmind.symmetric.model.OutgoingBatchWithPayload 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)

Aggregations

ArrayList (java.util.ArrayList)2 OutgoingBatch (org.jumpmind.symmetric.model.OutgoingBatch)2 OutgoingBatchWithPayload (org.jumpmind.symmetric.model.OutgoingBatchWithPayload)2 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)1 Date (java.util.Date)1 IDdlBuilder (org.jumpmind.db.platform.IDdlBuilder)1 ISymmetricEngine (org.jumpmind.symmetric.ISymmetricEngine)1 StructureDataWriter (org.jumpmind.symmetric.io.data.writer.StructureDataWriter)1 ChannelMap (org.jumpmind.symmetric.model.ChannelMap)1 IncomingBatch (org.jumpmind.symmetric.model.IncomingBatch)1 OutgoingBatches (org.jumpmind.symmetric.model.OutgoingBatches)1 ProcessInfo (org.jumpmind.symmetric.model.ProcessInfo)1 ProcessInfoKey (org.jumpmind.symmetric.model.ProcessInfoKey)1 IDataExtractorService (org.jumpmind.symmetric.service.IDataExtractorService)1 INodeService (org.jumpmind.symmetric.service.INodeService)1 IStatisticManager (org.jumpmind.symmetric.statistic.IStatisticManager)1 Batch (org.jumpmind.symmetric.web.rest.model.Batch)1 Heartbeat (org.jumpmind.symmetric.web.rest.model.Heartbeat)1 PullDataResults (org.jumpmind.symmetric.web.rest.model.PullDataResults)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1