Skip to content

Commit

Permalink
[WFLY-8855]: Deny CLI export/import journal if JDBC persistence stora…
Browse files Browse the repository at this point in the history
…ge is configured.

Checking if we are using a jdbc journal and failing the operation if this is the case.
  • Loading branch information
ehsavoie committed May 29, 2017
1 parent 76a7b94 commit 910b4ce
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
Expand Up @@ -22,6 +22,7 @@

package org.wildfly.extension.messaging.activemq;

import static org.jboss.as.controller.AbstractControllerService.PATH_MANAGER_CAPABILITY;
import static org.jboss.as.controller.PathAddress.EMPTY_ADDRESS;
import static org.jboss.as.controller.RunningMode.ADMIN_ONLY;
import static org.wildfly.extension.messaging.activemq.MessagingExtension.BINDINGS_DIRECTORY_PATH;
Expand All @@ -45,7 +46,6 @@
import org.jboss.as.controller.registry.Resource;
import org.jboss.as.controller.services.path.AbsolutePathService;
import org.jboss.as.controller.services.path.PathManager;
import org.jboss.as.controller.services.path.PathManagerService;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
import org.jboss.msc.service.ServiceController;
Expand All @@ -60,6 +60,7 @@
*/
public class ExportJournalOperation extends AbstractRuntimeOnlyHandler {

private static final String OPERATION_NAME = "export-journal";
static final ExportJournalOperation INSTANCE = new ExportJournalOperation();

// name file of the dump follows the format journal-yyyyMMdd-HHmmssSSSTZ-dump.xml
Expand All @@ -70,7 +71,7 @@ private ExportJournalOperation() {
}

static void registerOperation(final ManagementResourceRegistration registry, final ResourceDescriptionResolver resourceDescriptionResolver) {
registry.registerOperationHandler(new SimpleOperationDefinitionBuilder("export-journal", resourceDescriptionResolver)
registry.registerOperationHandler(new SimpleOperationDefinitionBuilder(OPERATION_NAME, resourceDescriptionResolver)
.setRuntimeOnly()
.setReplyValueType(ModelType.STRING)
.build(),
Expand All @@ -80,10 +81,11 @@ static void registerOperation(final ManagementResourceRegistration registry, fin
@Override
protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
if (context.getRunningMode() != ADMIN_ONLY) {
throw MessagingLogger.ROOT_LOGGER.managementOperationAllowedOnlyInRunningMode("export-journal", ADMIN_ONLY);
throw MessagingLogger.ROOT_LOGGER.managementOperationAllowedOnlyInRunningMode(OPERATION_NAME, ADMIN_ONLY);
}
checkAllowedOnJournal(context, OPERATION_NAME);

final ServiceController<PathManager> service = (ServiceController<PathManager>) context.getServiceRegistry(false).getService(PathManagerService.SERVICE_NAME);
final ServiceController<PathManager> service = (ServiceController<PathManager>) context.getServiceRegistry(false).getService(PATH_MANAGER_CAPABILITY.getCapabilityServiceName());
final PathManager pathManager = service.getService().getValue();

final String journal = resolvePath(context, pathManager, JOURNAL_DIRECTORY_PATH);
Expand Down Expand Up @@ -122,4 +124,11 @@ private static String resolvePath(OperationContext context, PathManager pathMana
final String relativeTo = AbsolutePathService.isAbsoluteUnixOrWindowsPath(path) ? null : relativeToPath;
return pathManager.resolveRelativePathEntry(path, relativeTo);
}

static void checkAllowedOnJournal(OperationContext context, String operationName) throws OperationFailedException {
ModelNode journalDatasource = ServerDefinition.JOURNAL_DATASOURCE.resolveModelAttribute(context, context.readResource(EMPTY_ADDRESS).getModel());
if (journalDatasource.isDefined() && journalDatasource.asString() != null && !"".equals(journalDatasource.asString())) {
throw MessagingLogger.ROOT_LOGGER.operationNotAllowedOnJdbcStore(operationName);
}
}
}
Expand Up @@ -54,6 +54,8 @@
import org.jboss.dmr.ModelType;
import org.wildfly.extension.messaging.activemq.logging.MessagingLogger;

import static org.wildfly.extension.messaging.activemq.ExportJournalOperation.checkAllowedOnJournal;

/**
* Import a dump of Artemis journal in a running Artemis server.
* WildFly must be running in NORMAL mode to perform this operation.
Expand All @@ -68,6 +70,7 @@ public class ImportJournalOperation extends AbstractRuntimeOnlyHandler {
.setAllowExpression(false)
.setRequired(true)
.build();
private static final String OPERATION_NAME = "import-journal";

static final ImportJournalOperation INSTANCE = new ImportJournalOperation();

Expand All @@ -76,7 +79,7 @@ private ImportJournalOperation() {
}

static void registerOperation(final ManagementResourceRegistration registry, final ResourceDescriptionResolver resourceDescriptionResolver) {
registry.registerOperationHandler(new SimpleOperationDefinitionBuilder("import-journal", resourceDescriptionResolver)
registry.registerOperationHandler(new SimpleOperationDefinitionBuilder(OPERATION_NAME, resourceDescriptionResolver)
.addParameter(FILE)
.setRuntimeOnly()
.setReplyValueType(ModelType.BOOLEAN)
Expand All @@ -87,8 +90,9 @@ static void registerOperation(final ManagementResourceRegistration registry, fin
@Override
protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
if (context.getRunningMode() != NORMAL) {
throw MessagingLogger.ROOT_LOGGER.managementOperationAllowedOnlyInRunningMode("import-journal", NORMAL);
throw MessagingLogger.ROOT_LOGGER.managementOperationAllowedOnlyInRunningMode(OPERATION_NAME, NORMAL);
}
checkAllowedOnJournal(context, OPERATION_NAME);

String file = FILE.resolveModelAttribute(context, operation).asString();

Expand Down
Expand Up @@ -851,4 +851,7 @@ public interface MessagingLogger extends BasicLogger {
@LogMessage(level = WARN)
@Message(id = 95, value = "Multiple client-mapping found in [%s] socket binding used by ActiveMQ [%s] transport configuration. Using address: [host: %s, port %s]")
void multipleClientMappingsFound(String socketBindingName, String transportConfigName, String host, int port);

@Message(id = 96, value = "The %s operation can not be performed on a JDBC store journal")
OperationFailedException operationNotAllowedOnJdbcStore(String operationName);
}

0 comments on commit 910b4ce

Please sign in to comment.