Skip to content

Commit

Permalink
WFLY-5145 Add return types description to migrate operations, make re…
Browse files Browse the repository at this point in the history
…sult messages uniform
  • Loading branch information
tadamski committed Aug 28, 2015
1 parent a162b1f commit a1aba5e
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 18 deletions.
Expand Up @@ -22,6 +22,7 @@


package org.jboss.as.jacorb; package org.jboss.as.jacorb;


import java.util.List;
import java.util.Properties; import java.util.Properties;


import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.AttributeDefinition;
Expand Down Expand Up @@ -74,7 +75,15 @@ protected void populateModel(final OperationContext context, final ModelNode ope
// domain controller in normal mode works normally - it may send old parameters to legacy hosts - such configuration is // domain controller in normal mode works normally - it may send old parameters to legacy hosts - such configuration is
// valid // valid
if (adminOnly || !hostController) { if (adminOnly || !hostController) {
TransformUtils.checkLegacyModel(model, !adminOnly); final List<String> unsupportedProperites = TransformUtils.checkLegacyModel(model);
if(!unsupportedProperites.isEmpty()) {
if (adminOnly) {
final String warning = JacORBLogger.ROOT_LOGGER.cannotEmulatePropertiesWarning(unsupportedProperites);
JacORBLogger.ROOT_LOGGER.warn(warning);
} else {
throw JacORBLogger.ROOT_LOGGER.cannotEmulateProperties(unsupportedProperites);
}
}
} }
} }


Expand Down
Expand Up @@ -32,6 +32,7 @@


import java.util.Collection; import java.util.Collection;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map; import java.util.Map;


import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationContext;
Expand All @@ -40,6 +41,7 @@
import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.PathElement; import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.RunningMode; import org.jboss.as.controller.RunningMode;
import org.jboss.as.controller.SimpleMapAttributeDefinition;
import org.jboss.as.controller.SimpleOperationDefinitionBuilder; import org.jboss.as.controller.SimpleOperationDefinitionBuilder;
import org.jboss.as.controller.descriptions.ResourceDescriptionResolver; import org.jboss.as.controller.descriptions.ResourceDescriptionResolver;
import org.jboss.as.controller.operations.MultistepUtil; import org.jboss.as.controller.operations.MultistepUtil;
Expand All @@ -49,6 +51,7 @@
import org.jboss.as.controller.registry.Resource; import org.jboss.as.controller.registry.Resource;
import org.jboss.as.jacorb.logging.JacORBLogger; import org.jboss.as.jacorb.logging.JacORBLogger;
import org.jboss.dmr.ModelNode; import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
import org.jboss.dmr.Property; import org.jboss.dmr.Property;


/** /**
Expand All @@ -64,14 +67,20 @@ public class MigrateOperation implements OperationStepHandler {
public static final String MIGRATION_OPERATIONS = "migration-operations"; public static final String MIGRATION_OPERATIONS = "migration-operations";
public static final String MIGRATION_ERROR = "migration-error"; public static final String MIGRATION_ERROR = "migration-error";


public static final SimpleMapAttributeDefinition MIGRATION_ERROR_ATTR = new SimpleMapAttributeDefinition.Builder(MIGRATION_ERROR, ModelType.OBJECT, true)
.setValueType(ModelType.OBJECT)
.setAllowNull(true)
.build();


static void registerOperation(final ManagementResourceRegistration registry, final ResourceDescriptionResolver resourceDescriptionResolver) { static void registerOperation(final ManagementResourceRegistration registry, final ResourceDescriptionResolver resourceDescriptionResolver) {
registry.registerOperationHandler(new SimpleOperationDefinitionBuilder(MIGRATE, resourceDescriptionResolver) registry.registerOperationHandler(new SimpleOperationDefinitionBuilder(MIGRATE, resourceDescriptionResolver)
.setRuntimeOnly() .setRuntimeOnly()
.setReplyParameters(MIGRATION_ERROR_ATTR)
.build(), .build(),
new MigrateOperation(false)); new MigrateOperation(false));
registry.registerOperationHandler(new SimpleOperationDefinitionBuilder(DESCRIBE_MIGRATION, resourceDescriptionResolver) registry.registerOperationHandler(new SimpleOperationDefinitionBuilder(DESCRIBE_MIGRATION, resourceDescriptionResolver)
.setRuntimeOnly() .setRuntimeOnly()
.setReplyParameters(MIGRATION_ERROR_ATTR)
.build(), .build(),
new MigrateOperation(true)); new MigrateOperation(true));


Expand Down Expand Up @@ -109,10 +118,20 @@ public void execute(final OperationContext context, final ModelNode operation) t
context.addStep(new OperationStepHandler() { context.addStep(new OperationStepHandler() {
@Override @Override
public void execute(OperationContext operationContext, ModelNode modelNode) throws OperationFailedException { public void execute(OperationContext operationContext, ModelNode modelNode) throws OperationFailedException {

final Resource jacorbResource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS); final Resource jacorbResource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS);
final ModelNode jacorbModel = Resource.Tools.readModel(jacorbResource).clone(); final ModelNode jacorbModel = Resource.Tools.readModel(jacorbResource).clone();


TransformUtils.checkLegacyModel(jacorbModel, true); List<String> unsupportedProperties = TransformUtils.checkLegacyModel(jacorbModel);
if (!unsupportedProperties.isEmpty()) {
context.setRollbackOnly();

ModelNode result = new ModelNode();
final String error =JacORBLogger.ROOT_LOGGER.cannotEmulatePropertiesWarning(unsupportedProperties);
result.get(MIGRATION_ERROR).set(error);
context.getResult().set(result);
return;
}


final ModelNode openjdkModel = TransformUtils.transformModel(jacorbModel); final ModelNode openjdkModel = TransformUtils.transformModel(jacorbModel);


Expand Down
Expand Up @@ -5,7 +5,6 @@


import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.jacorb.logging.JacORBLogger;
import org.jboss.dmr.ModelNode; import org.jboss.dmr.ModelNode;
import org.jboss.dmr.Property; import org.jboss.dmr.Property;
import org.wildfly.iiop.openjdk.Constants; import org.wildfly.iiop.openjdk.Constants;
Expand All @@ -18,7 +17,7 @@ public class TransformUtils {
private TransformUtils() { private TransformUtils() {
} }


static List<String> checkLegacyModel(final ModelNode model, final boolean failOnErrors) throws OperationFailedException { static List<String> checkLegacyModel(final ModelNode model) throws OperationFailedException {
final List<String> propertiesToReject = new LinkedList<>(); final List<String> propertiesToReject = new LinkedList<>();
for (final AttributeDefinition attribute : JacORBSubsystemDefinitions.ON_OFF_ATTRIBUTES_TO_REJECT) { for (final AttributeDefinition attribute : JacORBSubsystemDefinitions.ON_OFF_ATTRIBUTES_TO_REJECT) {
if (model.hasDefined(attribute.getName()) if (model.hasDefined(attribute.getName())
Expand All @@ -31,13 +30,6 @@ static List<String> checkLegacyModel(final ModelNode model, final boolean failOn
propertiesToReject.add(attribute.getName()); propertiesToReject.add(attribute.getName());
} }
} }
if (!propertiesToReject.isEmpty()) {
if(failOnErrors) {
throw JacORBLogger.ROOT_LOGGER.cannotEmulateProperties(propertiesToReject);
} else {
JacORBLogger.ROOT_LOGGER.cannotEmulatePropertiesWarning(propertiesToReject);
}
}
return propertiesToReject; return propertiesToReject;
} }


Expand Down
Expand Up @@ -455,9 +455,9 @@ public interface JacORBLogger extends BasicLogger {
+ "using OpenJDK ORB will be removed in future.") + "using OpenJDK ORB will be removed in future.")
void jacorbEmulationWarning(); void jacorbEmulationWarning();


@LogMessage(level = WARN)
@Message(id = 134, value = "Properties %s cannot be emulated using OpenJDK ORB and are not supported") @Message(id = 134, value = "Properties %s cannot be emulated using OpenJDK ORB and are not supported")
void cannotEmulatePropertiesWarning(List<String> property); String cannotEmulatePropertiesWarning(List<String> property);


@Message(id = 135, value = "Migration failed, see results for more details.") @Message(id = 135, value = "Migration failed, see results for more details.")
String migrationFailed(); String migrationFailed();
Expand Down
Expand Up @@ -2,7 +2,9 @@ jacorb=The JacORB subsystem configuration.
jacorb.add=Adds the JacORB subsystem. jacorb.add=Adds the JacORB subsystem.
jacorb.remove=Removes the JacORB subsystem. jacorb.remove=Removes the JacORB subsystem.
jacorb.migrate=Migrate to new OpenJDK subsystem. jacorb.migrate=Migrate to new OpenJDK subsystem.
jacorb.migrate.migration-error=The error that occured during migration.
jacorb.describe-migration=Describes the steps that will be taken to migrate this configuration to OpenJDK ORB jacorb.describe-migration=Describes the steps that will be taken to migrate this configuration to OpenJDK ORB
jacorb.describe-migration.migration-error=The error that occured during describe-migration operation.
jacorb.deprecated=The JacORB subsystem is deprecated and may be removed or limited to managed domain legacy server use in future versions. jacorb.deprecated=The JacORB subsystem is deprecated and may be removed or limited to managed domain legacy server use in future versions.


# orb configuration properties. # orb configuration properties.
Expand Down
Expand Up @@ -5,6 +5,8 @@
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;


import java.util.List;

/** /**
* @author <a href=mailto:tadamski@redhat.com>Tomasz Adamski</a> * @author <a href=mailto:tadamski@redhat.com>Tomasz Adamski</a>
* */ * */
Expand Down Expand Up @@ -35,21 +37,24 @@ public void testTransformation() {
public void testRejectedOnOffAttributeTurnedOff() throws Exception { public void testRejectedOnOffAttributeTurnedOff() throws Exception {
ModelNode model = new ModelNode(); ModelNode model = new ModelNode();
model.get("iona").set("off"); model.get("iona").set("off");
TransformUtils.checkLegacyModel(model, true); List<String> result =TransformUtils.checkLegacyModel(model);
Assert.assertTrue(result.isEmpty());
} }


@Test(expected = OperationFailedException.class) @Test
public void testRejectedOnOffAttribute() throws Exception { public void testRejectedOnOffAttribute() throws Exception {
ModelNode model = new ModelNode(); ModelNode model = new ModelNode();
model.get("iona").set("on"); model.get("iona").set("on");
TransformUtils.checkLegacyModel(model, true); List<String> result = TransformUtils.checkLegacyModel(model);
Assert.assertFalse(result.isEmpty());
} }


@Test(expected = OperationFailedException.class) @Test
public void testRejectedAttribute() throws Exception { public void testRejectedAttribute() throws Exception {
ModelNode model = new ModelNode(); ModelNode model = new ModelNode();
model.get("queue-min").set(5); model.get("queue-min").set(5);
TransformUtils.checkLegacyModel(model, true); List<String> result = TransformUtils.checkLegacyModel(model);
Assert.assertFalse(result.isEmpty());
} }


} }

0 comments on commit a1aba5e

Please sign in to comment.