Skip to content

Commit

Permalink
WFLY-9965 Create Infinispan subsystem transformer tests for EAP 7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
pferraro committed Mar 9, 2018
1 parent b0288e9 commit 9dd9c5f
Show file tree
Hide file tree
Showing 19 changed files with 186 additions and 60 deletions.
Expand Up @@ -27,6 +27,7 @@
import org.jboss.as.clustering.controller.ParentResourceServiceHandler;
import org.jboss.as.clustering.controller.ResourceDescriptor;
import org.jboss.as.clustering.controller.SimpleResourceRegistration;
import org.jboss.as.clustering.controller.transform.RequiredChildResourceDiscardPolicy;
import org.jboss.as.clustering.controller.ResourceServiceBuilderFactory;
import org.jboss.as.clustering.controller.ResourceServiceHandler;
import org.jboss.as.controller.ModelVersion;
Expand All @@ -53,7 +54,7 @@ public PathAddress transform(PathElement current, Builder builder) {
return builder.next();
}
};
ResourceTransformationDescriptionBuilder builder = InfinispanModel.VERSION_4_0_0.requiresTransformation(version) ? parent.addChildRedirection(PATH, addressTransformer) : parent.addChildResource(PATH);
ResourceTransformationDescriptionBuilder builder = InfinispanModel.VERSION_4_0_0.requiresTransformation(version) ? parent.addChildRedirection(PATH, addressTransformer, RequiredChildResourceDiscardPolicy.REJECT_AND_WARN) : parent.addChildResource(PATH);

BackupResourceDefinition.buildTransformation(version, builder);
}
Expand Down
Expand Up @@ -58,7 +58,7 @@ public class BinaryKeyedJDBCStoreResourceDefinition extends JDBCStoreResourceDef

@Deprecated
enum DeprecatedAttribute implements org.jboss.as.clustering.controller.Attribute {
TABLE("binary-keyed-table", BinaryTableResourceDefinition.Attribute.values(), TableResourceDefinition.Attribute.values(), TableResourceDefinition.ColumnAttribute.values()),
TABLE("binary-keyed-table", BinaryTableResourceDefinition.Attribute.values(), TableResourceDefinition.Attribute.values(), TableResourceDefinition.DeprecatedAttribute.values(), TableResourceDefinition.ColumnAttribute.values()),
;
private final AttributeDefinition definition;

Expand Down Expand Up @@ -93,13 +93,16 @@ static void buildTransformation(ModelVersion version, ResourceTransformationDesc

if (InfinispanModel.VERSION_4_0_0.requiresTransformation(version)) {
builder.setCustomResourceTransformer(new ResourceTransformer() {
@SuppressWarnings("deprecation")
@Override
public void transformResource(ResourceTransformationContext context, PathAddress address, Resource resource) throws OperationFailedException {
final ModelNode model = resource.getModel();
final ModelNode maxBatchSize = model.remove(StoreResourceDefinition.Attribute.MAX_BATCH_SIZE.getName());

final ModelNode binaryTableModel = Resource.Tools.readModel(resource.removeChild(BinaryTableResourceDefinition.PATH));
if (binaryTableModel != null && binaryTableModel.isDefined()) {
model.get(DeprecatedAttribute.TABLE.getName()).set(binaryTableModel);
model.get(DeprecatedAttribute.TABLE.getName()).get(TableResourceDefinition.DeprecatedAttribute.BATCH_SIZE.getName()).set((maxBatchSize != null) ? maxBatchSize : new ModelNode());
}

final ModelNode properties = model.remove(StoreResourceDefinition.Attribute.PROPERTIES.getName());
Expand Down Expand Up @@ -140,11 +143,12 @@ public void execute(OperationContext context, ModelNode operation) throws Operat
};

static final OperationStepHandler LEGACY_WRITE_TABLE_HANDLER = new OperationStepHandler() {
@SuppressWarnings("deprecation")
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
PathAddress address = context.getCurrentAddress().append(BinaryTableResourceDefinition.PATH);
ModelNode table = Operations.getAttributeValue(operation);
for (Class<? extends org.jboss.as.clustering.controller.Attribute> attributeClass : Arrays.asList(BinaryTableResourceDefinition.Attribute.class, TableResourceDefinition.Attribute.class)) {
for (Class<? extends org.jboss.as.clustering.controller.Attribute> attributeClass : Arrays.asList(BinaryTableResourceDefinition.Attribute.class, TableResourceDefinition.Attribute.class, TableResourceDefinition.DeprecatedAttribute.class)) {
for (org.jboss.as.clustering.controller.Attribute attribute : attributeClass.getEnumConstants()) {
ModelNode writeAttributeOperation = Operations.createWriteAttributeOperation(address, attribute, table.get(attribute.getName()));
context.addStep(writeAttributeOperation, context.getResourceRegistration().getAttributeAccess(PathAddress.pathAddress(BinaryTableResourceDefinition.PATH), attribute.getName()).getWriteHandler(), context.getCurrentStage());
Expand Down
Expand Up @@ -28,9 +28,11 @@
import org.infinispan.eviction.EvictionType;
import org.jboss.as.clustering.controller.validation.EnumValidator;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.ModelVersion;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.registry.AttributeAccess;
import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;

Expand Down Expand Up @@ -61,6 +63,12 @@ public AttributeDefinition getDefinition() {
}
}

static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder parent) {
if (InfinispanModel.VERSION_6_0_0.requiresTransformation(version)) {
parent.rejectChildResource(PATH);
}
}

BinaryMemoryResourceDefinition() {
super(StorageType.BINARY, PATH, descriptor -> descriptor.addAttributes(Attribute.class));
}
Expand Down
Expand Up @@ -70,6 +70,8 @@ public AttributeDefinition getDefinition() {
static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder parent) {
ResourceTransformationDescriptionBuilder builder = parent.addChildResource(PATH);

TableResourceDefinition.buildTransformation(version, builder);

if (InfinispanModel.VERSION_4_0_0.requiresTransformation(version)) {
OperationTransformer addTransformer = new OperationTransformer() {
@Override
Expand Down
Expand Up @@ -172,13 +172,9 @@ public void transformResource(ResourceTransformationContext context, PathAddress
builder.setCustomResourceTransformer(batchingTransformer);
}


BinaryMemoryResourceDefinition.buildTransformation(version, builder);
ObjectMemoryResourceDefinition.buildTransformation(version, builder);

if (InfinispanModel.VERSION_6_0_0.requiresTransformation(version)) {
builder.rejectChildResource(BinaryMemoryResourceDefinition.PATH);
builder.rejectChildResource(OffHeapMemoryResourceDefinition.PATH);
}
OffHeapMemoryResourceDefinition.buildTransformation(version, builder);

LockingResourceDefinition.buildTransformation(version, builder);
ExpirationResourceDefinition.buildTransformation(version, builder);
Expand Down
Expand Up @@ -610,6 +610,9 @@ private void parseCacheElement(XMLExtendedStreamReader reader, PathAddress cache
break;
}
case STRING_KEYED_JDBC_STORE: {
if (this.schema.since(InfinispanSchema.VERSION_5_0)) {
throw ParseUtils.unexpectedElement(reader);
}
if (this.schema.since(InfinispanSchema.VERSION_1_2)) {
this.parseStringKeyedJDBCStore(reader, cacheAddress, operations);
break;
Expand Down Expand Up @@ -1483,12 +1486,10 @@ private void parseJDBCStoreTableAttribute(XMLExtendedStreamReader reader, int in
break;
}
case BATCH_SIZE: {
/*
if (this.schema.since(InfinispanSchema.VERSION_5_0)) {
throw ParseUtils.unexpectedAttribute(reader, index);
}
*/
readAttribute(reader, index, operation, TableResourceDefinition.Attribute.BATCH_SIZE);
readAttribute(reader, index, operation, TableResourceDefinition.DeprecatedAttribute.BATCH_SIZE);
break;
}
default: {
Expand Down
Expand Up @@ -72,18 +72,22 @@ static void buildTransformation(ModelVersion version, ResourceTransformationDesc

if (InfinispanModel.VERSION_4_0_0.requiresTransformation(version)) {
builder.setCustomResourceTransformer(new ResourceTransformer() {
@SuppressWarnings("deprecation")
@Override
public void transformResource(ResourceTransformationContext context, PathAddress address, Resource resource) throws OperationFailedException {
final ModelNode model = resource.getModel();
final ModelNode maxBatchSize = model.remove(StoreResourceDefinition.Attribute.MAX_BATCH_SIZE.getName());

final ModelNode binaryTableModel = Resource.Tools.readModel(resource.removeChild(BinaryTableResourceDefinition.PATH));
if (binaryTableModel != null && binaryTableModel.isDefined()) {
model.get(DeprecatedAttribute.BINARY_TABLE.getName()).set(binaryTableModel);
model.get(DeprecatedAttribute.BINARY_TABLE.getName()).get(TableResourceDefinition.DeprecatedAttribute.BATCH_SIZE.getName()).set((maxBatchSize != null) ? maxBatchSize : new ModelNode());
}

final ModelNode stringTableModel = Resource.Tools.readModel(resource.removeChild(StringTableResourceDefinition.PATH));
if (stringTableModel != null && stringTableModel.isDefined()) {
model.get(DeprecatedAttribute.STRING_TABLE.getName()).set(stringTableModel);
model.get(DeprecatedAttribute.STRING_TABLE.getName()).get(TableResourceDefinition.DeprecatedAttribute.BATCH_SIZE.getName()).set((maxBatchSize != null) ? maxBatchSize : new ModelNode());
}

final ModelNode properties = model.remove(StoreResourceDefinition.Attribute.PROPERTIES.getName());
Expand Down
Expand Up @@ -74,14 +74,15 @@ public AttributeDefinition getDefinition() {
}
}

@SuppressWarnings("deprecation")
static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder parent) {
ResourceTransformationDescriptionBuilder builder = InfinispanModel.VERSION_4_0_0.requiresTransformation(version) ? parent.addChildRedirection(PATH, LEGACY_PATH, RequiredChildResourceDiscardPolicy.NEVER) : InfinispanModel.VERSION_6_0_0.requiresTransformation(version) ? parent.addChildRedirection(PATH, EVICTION_PATH, RequiredChildResourceDiscardPolicy.NEVER) : parent.addChildResource(PATH);

if (InfinispanModel.VERSION_6_0_0.requiresTransformation(version)) {
builder.getAttributeBuilder()
.addRename(Attribute.SIZE.getDefinition(), DeprecatedAttribute.MAX_ENTRIES.getName())
.setValueConverter(new SimpleAttributeConverter((address, name, value, model, context) -> {
// Set legacy eviction strategy to NONE is size is negative, otherwise set to LRU
// Set legacy eviction strategy to NONE if size is negative, otherwise set to LRU
if (model.hasDefined(Attribute.SIZE.getName()) && (model.get(Attribute.SIZE.getName()).asLong() < 0)) {
value.set(EvictionStrategy.NONE.name());
} else {
Expand Down
Expand Up @@ -26,9 +26,11 @@

import org.infinispan.configuration.cache.StorageType;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.ModelVersion;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.registry.AttributeAccess;
import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;

Expand Down Expand Up @@ -59,6 +61,12 @@ public AttributeDefinition getDefinition() {
}
}

static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder parent) {
if (InfinispanModel.VERSION_6_0_0.requiresTransformation(version)) {
parent.rejectChildResource(PATH);
}
}

OffHeapMemoryResourceDefinition() {
super(StorageType.OFF_HEAP, PATH, descriptor -> descriptor
.addAttributes(Attribute.class)
Expand Down
Expand Up @@ -135,12 +135,6 @@ static void buildTransformation(ModelVersion version, ResourceTransformationDesc
builder.getAttributeBuilder().setDiscard(DiscardAttributeChecker.ALWAYS, Attribute.MAX_BATCH_SIZE.getDefinition());
}

if (InfinispanModel.VERSION_4_0_0.requiresTransformation(version)) {
builder.discardChildResource(StoreWriteThroughResourceDefinition.PATH);
} else {
StoreWriteThroughResourceDefinition.buildTransformation(version, builder);
}

if (InfinispanModel.VERSION_3_0_0.requiresTransformation(version)) {
builder.addOperationTransformationOverride(ModelDescriptionConstants.ADD)
.setCustomOperationTransformer(new SimpleOperationTransformer(new LegacyPropertyAddOperationTransformer()))
Expand All @@ -158,6 +152,7 @@ static void buildTransformation(ModelVersion version, ResourceTransformationDesc
}
}

StoreWriteThroughResourceDefinition.buildTransformation(version, builder);
StoreWriteBehindResourceDefinition.buildTransformation(version, builder);
}

Expand Down
Expand Up @@ -38,8 +38,10 @@ public class StoreWriteThroughResourceDefinition extends StoreWriteResourceDefin

static final PathElement PATH = pathElement("through");

static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder builder) {
// Do nothing
static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder parent) {
if (InfinispanModel.VERSION_4_0_0.requiresTransformation(version)) {
parent.discardChildResource(StoreWriteThroughResourceDefinition.PATH);
}
}

StoreWriteThroughResourceDefinition() {
Expand Down
Expand Up @@ -63,7 +63,7 @@ public class StringKeyedJDBCStoreResourceDefinition extends JDBCStoreResourceDef

@Deprecated
enum DeprecatedAttribute implements org.jboss.as.clustering.controller.Attribute {
TABLE("string-keyed-table", StringTableResourceDefinition.Attribute.values(), TableResourceDefinition.Attribute.values(), TableResourceDefinition.ColumnAttribute.values()),
TABLE("string-keyed-table", StringTableResourceDefinition.Attribute.values(), TableResourceDefinition.Attribute.values(), TableResourceDefinition.DeprecatedAttribute.values(), TableResourceDefinition.ColumnAttribute.values()),
;
private final AttributeDefinition definition;

Expand Down Expand Up @@ -98,13 +98,16 @@ static void buildTransformation(ModelVersion version, ResourceTransformationDesc

if (InfinispanModel.VERSION_4_0_0.requiresTransformation(version)) {
builder.setCustomResourceTransformer(new ResourceTransformer() {
@SuppressWarnings("deprecation")
@Override
public void transformResource(ResourceTransformationContext context, PathAddress address, Resource resource) throws OperationFailedException {
final ModelNode model = resource.getModel();
final ModelNode maxBatchSize = model.remove(StoreResourceDefinition.Attribute.MAX_BATCH_SIZE.getName());

final ModelNode stringTableModel = Resource.Tools.readModel(resource.removeChild(StringTableResourceDefinition.PATH));
if (stringTableModel != null && stringTableModel.isDefined()) {
model.get(DeprecatedAttribute.TABLE.getName()).set(stringTableModel);
model.get(DeprecatedAttribute.TABLE.getName()).get(TableResourceDefinition.DeprecatedAttribute.BATCH_SIZE.getName()).set((maxBatchSize != null) ? maxBatchSize : new ModelNode());
}

final ModelNode properties = model.remove(StoreResourceDefinition.Attribute.PROPERTIES.getName());
Expand Down Expand Up @@ -150,11 +153,12 @@ public void execute(OperationContext context, ModelNode operation) throws Operat
};

static final OperationStepHandler LEGACY_WRITE_TABLE_HANDLER = new OperationStepHandler() {
@SuppressWarnings("deprecation")
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
PathAddress address = context.getCurrentAddress().append(StringTableResourceDefinition.PATH);
ModelNode table = Operations.getAttributeValue(operation);
for (Class<? extends org.jboss.as.clustering.controller.Attribute> attributeClass : Arrays.asList(StringTableResourceDefinition.Attribute.class, TableResourceDefinition.Attribute.class)) {
for (Class<? extends org.jboss.as.clustering.controller.Attribute> attributeClass : Arrays.asList(StringTableResourceDefinition.Attribute.class, TableResourceDefinition.Attribute.class, TableResourceDefinition.DeprecatedAttribute.class)) {
for (org.jboss.as.clustering.controller.Attribute attribute : attributeClass.getEnumConstants()) {
ModelNode writeAttributeOperation = Operations.createWriteAttributeOperation(address, attribute, table.get(attribute.getName()));
context.addStep(writeAttributeOperation, context.getResourceRegistration().getAttributeAccess(PathAddress.pathAddress(StringTableResourceDefinition.PATH), attribute.getName()).getWriteHandler(), context.getCurrentStage());
Expand Down
Expand Up @@ -69,6 +69,8 @@ public AttributeDefinition getDefinition() {
static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder parent) {
ResourceTransformationDescriptionBuilder builder = parent.addChildResource(PATH);

TableResourceDefinition.buildTransformation(version, builder);

if (InfinispanModel.VERSION_4_0_0.requiresTransformation(version)) {
OperationTransformer addTransformer = new OperationTransformer() {
@Override
Expand Down

0 comments on commit 9dd9c5f

Please sign in to comment.