Search in sources :

Example 1 with XmlDataExporter

use of org.apache.activemq.artemis.cli.commands.tools.XmlDataExporter in project wildfly by wildfly.

the class ExportJournalOperation method executeRuntimeStep.

@Override
protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
    if (context.getRunningMode() != ADMIN_ONLY) {
        throw MessagingLogger.ROOT_LOGGER.managementOperationAllowedOnlyInRunningMode("export-journal", ADMIN_ONLY);
    }
    final ServiceController<PathManager> service = (ServiceController<PathManager>) context.getServiceRegistry(false).getService(PathManagerService.SERVICE_NAME);
    final PathManager pathManager = service.getService().getValue();
    final String journal = resolvePath(context, pathManager, JOURNAL_DIRECTORY_PATH);
    final String bindings = resolvePath(context, pathManager, BINDINGS_DIRECTORY_PATH);
    final String paging = resolvePath(context, pathManager, PAGING_DIRECTORY_PATH);
    final String largeMessages = resolvePath(context, pathManager, LARGE_MESSAGES_DIRECTORY_PATH);
    final XmlDataExporter exporter = new XmlDataExporter();
    String name = String.format(FILE_NAME_FORMAT, new Date());
    // write the exported dump at the same level than the journal directory
    File dump = new File(new File(journal).getParent(), name);
    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(dump);
        exporter.process(fos, bindings, journal, paging, largeMessages);
        context.getResult().set(dump.getAbsolutePath());
    } catch (Exception e) {
        throw new OperationFailedException(e);
    } finally {
        if (fos != null) {
            try {
                fos.close();
            } catch (IOException e) {
            }
        }
    }
}
Also used : PathManager(org.jboss.as.controller.services.path.PathManager) FileOutputStream(java.io.FileOutputStream) OperationFailedException(org.jboss.as.controller.OperationFailedException) ServiceController(org.jboss.msc.service.ServiceController) IOException(java.io.IOException) File(java.io.File) XmlDataExporter(org.apache.activemq.artemis.cli.commands.tools.XmlDataExporter) Date(java.util.Date) IOException(java.io.IOException) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Aggregations

File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 Date (java.util.Date)1 XmlDataExporter (org.apache.activemq.artemis.cli.commands.tools.XmlDataExporter)1 OperationFailedException (org.jboss.as.controller.OperationFailedException)1 PathManager (org.jboss.as.controller.services.path.PathManager)1 ServiceController (org.jboss.msc.service.ServiceController)1