Permalink
Browse files

AS7-5753 implement write handler for deprecated virtual-nodes not to …

…break mgmt API
  • Loading branch information...
1 parent 27dffbf commit 3fe47f1c56e56d1f38d6419895eb79a4f858f128 @rhusar committed Nov 20, 2012
@@ -190,4 +190,13 @@
@Message(id = 10303, value = "cannot remove alias % from empty list.")
OperationFailedException cannotRemoveAliasFromEmptyList(String aliasName);
+ /**
+ * Creates an exception indicating that an attribute has been deprecated.
+ *
+ * @param attributeName the name of the deprecated attribute
+ * @return an {@link OperationFailedException} for the error
+ */
+ @Message(id = 10304, value = "Attribute '%s' has been deprecated.")
+ OperationFailedException attributeDeprecated(String attributeName);
+
}
@@ -22,8 +22,14 @@
package org.jboss.as.clustering.infinispan.subsystem;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.VALUE;
+
+import org.jboss.as.clustering.infinispan.InfinispanMessages;
import org.jboss.as.controller.AttributeDefinition;
+import org.jboss.as.controller.ModelOnlyWriteAttributeHandler;
import org.jboss.as.controller.ModelVersion;
+import org.jboss.as.controller.OperationContext;
+import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.OperationStepHandler;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.ReloadRequiredWriteAttributeHandler;
@@ -40,6 +46,7 @@
* Resource description for the addressable resource /subsystem=infinispan/cache-container=X/distributed-cache=*
*
* @author Richard Achmatowicz (c) 2011 Red Hat Inc.
+ * @author Radoslav Husar
*/
public class DistributedCacheResource extends SharedCacheResource {
@@ -101,7 +108,18 @@ public void registerAttributes(ManagementResourceRegistration resourceRegistrati
resourceRegistration.registerReadWriteAttribute(attr, null, writeHandler);
}
+ // Attribute virtual-nodes has been deprecated, so not to break management API, attempt to use it will fail.
+ final OperationStepHandler virtualNodesWriteHandler = new ModelOnlyWriteAttributeHandler(VIRTUAL_NODES) {
+ @Override
+ public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
+ if (operation.hasDefined(VALUE) && operation.get(VALUE).asInt() != 1) {
+ throw InfinispanMessages.MESSAGES.attributeDeprecated(ModelKeys.VIRTUAL_NODES);
+ }
+ context.stepCompleted();
+ }
+ };
+
// Legacy attributes
- resourceRegistration.registerReadOnlyAttribute(VIRTUAL_NODES, null);
+ resourceRegistration.registerReadWriteAttribute(VIRTUAL_NODES, null, virtualNodesWriteHandler);
}
}
@@ -62,6 +62,9 @@ private void transformCache(final ModelNode model, final String containerName, f
if (cache.has(ModelKeys.SEGMENTS)) {
cache.remove(ModelKeys.SEGMENTS);
}
+ if (cache.has(ModelKeys.VIRTUAL_NODES)) {
+ cache.remove(ModelKeys.VIRTUAL_NODES);
+ }
model.get(ModelKeys.CACHE_CONTAINER, containerName, cacheType, c.getName()).set(cache);
}

0 comments on commit 3fe47f1

Please sign in to comment.