Search in sources :

Example 1 with ManagedOperation

use of org.springframework.jmx.export.annotation.ManagedOperation in project symmetric-ds by JumpMind.

the class NodeManagementService method extractBatcheRange.

@ManagedOperation(description = "Extract multiple batches to a file for a time range")
@ManagedOperationParameters({ @ManagedOperationParameter(name = "fileName", description = "The file to write the batch output to"), @ManagedOperationParameter(name = "nodeId", description = "The target node id whose batches need extracted"), @ManagedOperationParameter(name = "startTime", description = "The start time range to extract.  The format is yyyy-MM-dd hh:mm"), @ManagedOperationParameter(name = "endTime", description = "The start time range to extract.  The format is yyyy-MM-dd hh:mm"), @ManagedOperationParameter(name = "channelIdList", description = "A comma separated list of channels to extract") })
public boolean extractBatcheRange(String fileName, String nodeId, String startTime, String endTime, String channelIdList) {
    File file = new File(fileName);
    file.getParentFile().mkdirs();
    Date startBatchTime = FormatUtils.parseDate(startTime, FormatUtils.TIMESTAMP_PATTERNS);
    Date endBatchTime = FormatUtils.parseDate(endTime, FormatUtils.TIMESTAMP_PATTERNS);
    String[] channelIds = channelIdList.split(",");
    IDataExtractorService dataExtractorService = engine.getDataExtractorService();
    BufferedWriter writer = null;
    try {
        writer = new BufferedWriter(new FileWriter(file));
        dataExtractorService.extractBatchRange(writer, nodeId, startBatchTime, endBatchTime, channelIds);
        return true;
    } catch (Exception ex) {
        log.error("Failed to write batch range to file", ex);
        return false;
    } finally {
        IOUtils.closeQuietly(writer);
    }
}
Also used : FileWriter(java.io.FileWriter) File(java.io.File) Date(java.util.Date) IDataExtractorService(org.jumpmind.symmetric.service.IDataExtractorService) BufferedWriter(java.io.BufferedWriter) ManagedOperationParameters(org.springframework.jmx.export.annotation.ManagedOperationParameters) ManagedOperation(org.springframework.jmx.export.annotation.ManagedOperation)

Example 2 with ManagedOperation

use of org.springframework.jmx.export.annotation.ManagedOperation in project symmetric-ds by JumpMind.

the class NodeManagementService method setSyncEnabledForNode.

@ManagedOperation(description = "Enable or disable synchronization completely for a node")
@ManagedOperationParameters({ @ManagedOperationParameter(name = "nodeId", description = "The node to enable or disable"), @ManagedOperationParameter(name = "syncEnabled", description = "true is enabled, false is disabled") })
public boolean setSyncEnabledForNode(String nodeId, boolean syncEnabled) {
    Node node = engine.getNodeService().findNode(nodeId);
    if (node != null) {
        node.setSyncEnabled(syncEnabled);
        engine.getNodeService().save(node);
        return true;
    } else {
        return false;
    }
}
Also used : Node(org.jumpmind.symmetric.model.Node) ManagedOperationParameters(org.springframework.jmx.export.annotation.ManagedOperationParameters) ManagedOperation(org.springframework.jmx.export.annotation.ManagedOperation)

Example 3 with ManagedOperation

use of org.springframework.jmx.export.annotation.ManagedOperation in project spring-boot by spring-projects.

the class LoggersEndpointMBean method setLogLevel.

@ManagedOperation(description = "Set log level for a given logger")
public void setLogLevel(String loggerName, String logLevel) {
    Assert.notNull(logLevel, "LogLevel must not be null");
    LogLevel level = LogLevel.valueOf(logLevel.toUpperCase());
    getEndpoint().setLogLevel(loggerName, level);
}
Also used : LogLevel(org.springframework.boot.logging.LogLevel) ManagedOperation(org.springframework.jmx.export.annotation.ManagedOperation)

Example 4 with ManagedOperation

use of org.springframework.jmx.export.annotation.ManagedOperation in project symmetric-ds by JumpMind.

the class NodeManagementService method writeBatchRangeToFile.

@ManagedOperation(description = "Write a range of batches to a file in SymmetricDS Data Format.")
@ManagedOperationParameters({ @ManagedOperationParameter(name = "nodeId", description = "The node id for the batches which will be written"), @ManagedOperationParameter(name = "startBatchId", description = "Starting batch ID of range"), @ManagedOperationParameter(name = "endBatchId", description = "Ending batch ID of range"), @ManagedOperationParameter(name = "fileName", description = "File name to write batches") })
public void writeBatchRangeToFile(String nodeId, String startBatchId, String endBatchId, String fileName) throws Exception {
    Writer writer = new FileWriter(new File(fileName));
    engine.getDataExtractorService().extractBatchRange(writer, nodeId, Long.valueOf(startBatchId), Long.valueOf(endBatchId));
    IOUtils.closeQuietly(writer);
}
Also used : FileWriter(java.io.FileWriter) File(java.io.File) BufferedWriter(java.io.BufferedWriter) FileWriter(java.io.FileWriter) Writer(java.io.Writer) ManagedOperationParameters(org.springframework.jmx.export.annotation.ManagedOperationParameters) ManagedOperation(org.springframework.jmx.export.annotation.ManagedOperation)

Example 5 with ManagedOperation

use of org.springframework.jmx.export.annotation.ManagedOperation in project symmetric-ds by JumpMind.

the class AbstractXmlPublisherExtensionPoint method resend.

@ManagedOperation(description = "Looks up rows in the database and resends them to the publisher")
@ManagedOperationParameters({ @ManagedOperationParameter(name = "args", description = "A pipe deliminated list of key values to use to look up the tables to resend") })
public boolean resend(String args) {
    try {
        String[] argArray = args != null ? args.split("\\|") : new String[0];
        DataContext context = new DataContext();
        IDatabasePlatform platform = engine.getDatabasePlatform();
        for (String tableName : tableNamesToPublishAsGroup) {
            Table table = platform.getTableFromCache(tableName, false);
            List<String[]> dataRowsForTable = readData(table, argArray);
            for (String[] values : dataRowsForTable) {
                Batch batch = new Batch();
                batch.setBinaryEncoding(engine.getSymmetricDialect().getBinaryEncoding());
                batch.setSourceNodeId("republish");
                context.setBatch(batch);
                CsvData data = new CsvData(DataEventType.INSERT);
                data.putParsedData(CsvData.ROW_DATA, values);
                Element xml = getXmlFromCache(context, context.getBatch().getBinaryEncoding(), table.getColumnNames(), data.getParsedData(CsvData.ROW_DATA), table.getPrimaryKeyColumnNames(), data.getParsedData(CsvData.PK_DATA));
                if (xml != null) {
                    toXmlElement(data.getDataEventType(), xml, table.getCatalog(), table.getSchema(), table.getName(), table.getColumnNames(), data.getParsedData(CsvData.ROW_DATA), table.getPrimaryKeyColumnNames(), data.getParsedData(CsvData.PK_DATA));
                }
            }
        }
        if (doesXmlExistToPublish(context)) {
            finalizeXmlAndPublish(context);
            return true;
        } else {
            log.warn(String.format("Failed to resend message for tables %s, columns %s, and args %s", tableNamesToPublishAsGroup, groupByColumnNames, args));
        }
    } catch (RuntimeException ex) {
        log.error(String.format("Failed to resend message for tables %s, columns %s, and args %s", tableNamesToPublishAsGroup, groupByColumnNames, args), ex);
    }
    return false;
}
Also used : DataContext(org.jumpmind.symmetric.io.data.DataContext) IDatabasePlatform(org.jumpmind.db.platform.IDatabasePlatform) Table(org.jumpmind.db.model.Table) Batch(org.jumpmind.symmetric.io.data.Batch) Element(org.jdom.Element) CsvData(org.jumpmind.symmetric.io.data.CsvData) ManagedOperationParameters(org.springframework.jmx.export.annotation.ManagedOperationParameters) ManagedOperation(org.springframework.jmx.export.annotation.ManagedOperation)

Aggregations

ManagedOperation (org.springframework.jmx.export.annotation.ManagedOperation)5 ManagedOperationParameters (org.springframework.jmx.export.annotation.ManagedOperationParameters)4 BufferedWriter (java.io.BufferedWriter)2 File (java.io.File)2 FileWriter (java.io.FileWriter)2 Writer (java.io.Writer)1 Date (java.util.Date)1 Element (org.jdom.Element)1 Table (org.jumpmind.db.model.Table)1 IDatabasePlatform (org.jumpmind.db.platform.IDatabasePlatform)1 Batch (org.jumpmind.symmetric.io.data.Batch)1 CsvData (org.jumpmind.symmetric.io.data.CsvData)1 DataContext (org.jumpmind.symmetric.io.data.DataContext)1 Node (org.jumpmind.symmetric.model.Node)1 IDataExtractorService (org.jumpmind.symmetric.service.IDataExtractorService)1 LogLevel (org.springframework.boot.logging.LogLevel)1