Skip to content

Commit

Permalink
TEIID-5574 adding full backwards compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Dec 20, 2018
1 parent b0f2cd1 commit faa6203
Show file tree
Hide file tree
Showing 8 changed files with 258 additions and 22 deletions.
13 changes: 13 additions & 0 deletions jboss-integration/src/main/java/org/teiid/jboss/Element.java
Expand Up @@ -51,18 +51,31 @@ enum Element {
PREPARSER_MODULE_ELEMENT("preparser-module", "preparser-module"),

// buffer manager
@Deprecated
BUFFER_SERVICE_ELEMENT("buffer-service"),
@Deprecated
USE_DISK_ATTRIBUTE("use-disk", "buffer-service-use-disk"),
@Deprecated
PROCESSOR_BATCH_SIZE_ATTRIBUTE("processor-batch-size", "buffer-service-processor-batch-size"),
@Deprecated
MAX_PROCESSING_KB_ATTRIBUTE("max-processing-kb", "buffer-service-max-processing-kb"),
@Deprecated
MAX_RESERVED_KB_ATTRIBUTE("max-reserve-kb", "buffer-service-max-reserve-kb"),
@Deprecated
MAX_FILE_SIZE_ATTRIBUTE("max-file-size", "buffer-service-max-file-size"),
@Deprecated
MAX_BUFFER_SPACE_ATTRIBUTE("max-buffer-space", "buffer-service-max-buffer-space"),
@Deprecated
MAX_OPEN_FILES_ATTRIBUTE("max-open-files", "buffer-service-max-open-files"),
@Deprecated
MEMORY_BUFFER_SPACE_ATTRIBUTE("memory-buffer-space", "buffer-service-memory-buffer-space"),
@Deprecated
MEMORY_BUFFER_OFFHEAP_ATTRIBUTE("memory-buffer-off-heap", "buffer-service-memory-buffer-off-heap"),
@Deprecated
MAX_STORAGE_OBJECT_SIZE_ATTRIBUTE("max-storage-object-size", "buffer-service-max-storage-object-size"),
@Deprecated
INLINE_LOBS("inline-lobs", "buffer-service-inline-lobs"),
@Deprecated
ENCRYPT_FILES_ATTRIBUTE("encrypt-files", "buffer-service-encrypt-files"),

BUFFER_MANAGER_ELEMENT("buffer-manager"),
Expand Down
38 changes: 38 additions & 0 deletions jboss-integration/src/main/java/org/teiid/jboss/TeiidAdd.java
Expand Up @@ -145,6 +145,20 @@ class TeiidAdd extends AbstractAddStepHandler {

// object replicator
TeiidConstants.DC_STACK_ATTRIBUTE,

// Buffer Service
TeiidConstants.USE_DISK_ATTRIBUTE,
TeiidConstants.INLINE_LOBS,
TeiidConstants.PROCESSOR_BATCH_SIZE_ATTRIBUTE,
TeiidConstants.MAX_PROCESSING_KB_ATTRIBUTE,
TeiidConstants.MAX_RESERVED_KB_ATTRIBUTE,
TeiidConstants.MAX_FILE_SIZE_ATTRIBUTE,
TeiidConstants.MAX_BUFFER_SPACE_ATTRIBUTE,
TeiidConstants.MAX_OPEN_FILES_ATTRIBUTE,
TeiidConstants.MEMORY_BUFFER_SPACE_ATTRIBUTE,
TeiidConstants.MEMORY_BUFFER_OFFHEAP_ATTRIBUTE,
TeiidConstants.MAX_STORAGE_OBJECT_SIZE_ATTRIBUTE,
TeiidConstants.ENCRYPT_FILES_ATTRIBUTE,

// Buffer Manager
TeiidConstants.BUFFER_MANAGER_USE_DISK_ATTRIBUTE,
Expand Down Expand Up @@ -698,39 +712,63 @@ private BufferManagerService buildBufferManager(final OperationContext context,

if (isDefined(BUFFER_MANAGER_USE_DISK_ATTRIBUTE, node, context)) {
bufferManger.setUseDisk(asBoolean(BUFFER_MANAGER_USE_DISK_ATTRIBUTE, node, context));
} else if (isDefined(USE_DISK_ATTRIBUTE, node, context)) {
bufferManger.setUseDisk(asBoolean(USE_DISK_ATTRIBUTE, node, context));
}
if (isDefined(BUFFER_MANAGER_PROCESSOR_BATCH_SIZE_ATTRIBUTE, node, context)) {
bufferManger.setProcessorBatchSize(asInt(BUFFER_MANAGER_PROCESSOR_BATCH_SIZE_ATTRIBUTE, node, context));
} else if (isDefined(PROCESSOR_BATCH_SIZE_ATTRIBUTE, node, context)) {
bufferManger.setProcessorBatchSize(asInt(PROCESSOR_BATCH_SIZE_ATTRIBUTE, node, context));
}
if (isDefined(BUFFER_MANAGER_MAX_PROCESSING_KB_ATTRIBUTE, node, context)) {
bufferManger.setMaxProcessingKb(asInt(BUFFER_MANAGER_MAX_PROCESSING_KB_ATTRIBUTE, node, context));
} else if (isDefined(MAX_PROCESSING_KB_ATTRIBUTE, node, context)) {
bufferManger.setMaxProcessingKb(asInt(MAX_PROCESSING_KB_ATTRIBUTE, node, context));
}
if (isDefined(BUFFER_MANAGER_MAX_RESERVED_MB_ATTRIBUTE, node, context)) {
bufferManger.setMaxReservedHeapMb(asInt(BUFFER_MANAGER_MAX_RESERVED_MB_ATTRIBUTE, node, context));
} else if (isDefined(MAX_RESERVED_KB_ATTRIBUTE, node, context)) {
bufferManger.setMaxReserveKb(asInt(MAX_RESERVED_KB_ATTRIBUTE, node, context));
}
if (isDefined(BUFFER_MANAGER_MAX_FILE_SIZE_ATTRIBUTE, node, context)) {
bufferManger.setMaxFileSize(asLong(BUFFER_MANAGER_MAX_FILE_SIZE_ATTRIBUTE, node, context));
} else if (isDefined(MAX_FILE_SIZE_ATTRIBUTE, node, context)) {
bufferManger.setMaxFileSize(asLong(MAX_FILE_SIZE_ATTRIBUTE, node, context));
}
if (isDefined(BUFFER_MANAGER_MAX_BUFFER_SPACE_ATTRIBUTE, node, context)) {
bufferManger.setMaxDiskBufferSpaceMb(asLong(BUFFER_MANAGER_MAX_BUFFER_SPACE_ATTRIBUTE, node, context));
} else if (isDefined(MAX_BUFFER_SPACE_ATTRIBUTE, node, context)) {
bufferManger.setMaxDiskBufferSpaceMb(asLong(MAX_BUFFER_SPACE_ATTRIBUTE, node, context));
}
if (isDefined(BUFFER_MANAGER_MAX_OPEN_FILES_ATTRIBUTE, node, context)) {
bufferManger.setMaxOpenFiles(asInt(BUFFER_MANAGER_MAX_OPEN_FILES_ATTRIBUTE, node, context));
} else if (isDefined(MAX_OPEN_FILES_ATTRIBUTE, node, context)) {
bufferManger.setMaxOpenFiles(asInt(MAX_OPEN_FILES_ATTRIBUTE, node, context));
}
if (isDefined(BUFFER_MANAGER_MEMORY_BUFFER_SPACE_ATTRIBUTE, node, context)) {
bufferManger.setFixedMemoryBufferSpaceMb(asInt(BUFFER_MANAGER_MEMORY_BUFFER_SPACE_ATTRIBUTE, node, context));
} else if (isDefined(MEMORY_BUFFER_SPACE_ATTRIBUTE, node, context)) {
bufferManger.setFixedMemoryBufferSpaceMb(asInt(MEMORY_BUFFER_SPACE_ATTRIBUTE, node, context));
}
if (isDefined(BUFFER_MANAGER_MEMORY_BUFFER_OFFHEAP_ATTRIBUTE, node, context)) {
bufferManger.setFixedMemoryBufferOffHeap(asBoolean(BUFFER_MANAGER_MEMORY_BUFFER_OFFHEAP_ATTRIBUTE, node, context));
} else if (isDefined(MEMORY_BUFFER_OFFHEAP_ATTRIBUTE, node, context)) {
bufferManger.setFixedMemoryBufferOffHeap(asBoolean(MEMORY_BUFFER_OFFHEAP_ATTRIBUTE, node, context));
}
if (isDefined(BUFFER_MANAGER_MAX_STORAGE_OBJECT_SIZE_ATTRIBUTE, node, context)) {
bufferManger.setMaxStorageObjectSizeKb(asInt(BUFFER_MANAGER_MAX_STORAGE_OBJECT_SIZE_ATTRIBUTE, node, context));
} else if (isDefined(MAX_STORAGE_OBJECT_SIZE_ATTRIBUTE, node, context)) {
bufferManger.setMaxStorageObjectSize(asInt(MAX_STORAGE_OBJECT_SIZE_ATTRIBUTE, node, context));
}
if (isDefined(BUFFER_MANAGER_INLINE_LOBS, node, context)) {
bufferManger.setInlineLobs(asBoolean(BUFFER_MANAGER_INLINE_LOBS, node, context));
} else if (isDefined(INLINE_LOBS, node, context)) {
bufferManger.setInlineLobs(asBoolean(INLINE_LOBS, node, context));
}
if (isDefined(BUFFER_MANAGER_ENCRYPT_FILES_ATTRIBUTE, node, context)) {
bufferManger.setEncryptFiles(asBoolean(BUFFER_MANAGER_ENCRYPT_FILES_ATTRIBUTE, node, context));
} else if (isDefined(ENCRYPT_FILES_ATTRIBUTE, node, context)) {
bufferManger.setEncryptFiles(asBoolean(ENCRYPT_FILES_ATTRIBUTE, node, context));
}
return bufferManger;
}
Expand Down
108 changes: 108 additions & 0 deletions jboss-integration/src/main/java/org/teiid/jboss/TeiidConstants.java
Expand Up @@ -17,6 +17,7 @@
*/
package org.teiid.jboss;

import org.jboss.as.controller.ModelVersion;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.SimpleAttributeDefinition;
Expand All @@ -32,6 +33,8 @@

@SuppressWarnings("nls")
public class TeiidConstants {
private static final ModelVersion BUFFER_SERVICE_VERSION = ModelVersion.create(1, 2);

// Non persistent attributes
public static SimpleAttributeDefinition ACTIVE_SESSION_COUNT = new SimpleAttributeDefinitionBuilder("active-session-count", ModelType.INT)
.setXmlName("active-session-count")
Expand Down Expand Up @@ -176,6 +179,111 @@ public class TeiidConstants {
.setAllowExpression(false)
.build();

/*
* Deprecated buffer-service attributes
*/
@Deprecated
public static SimpleAttributeDefinition USE_DISK_ATTRIBUTE = new SimpleAttributeDefinitionBuilder(Element.USE_DISK_ATTRIBUTE.getModelName(), ModelType.BOOLEAN)
.setXmlName(Element.BUFFER_MANAGER_USE_DISK_ATTRIBUTE.getXMLName())
.setRequired(false)
.setAllowExpression(false)
.setDeprecated(BUFFER_SERVICE_VERSION)
.build();

@Deprecated
public static SimpleAttributeDefinition PROCESSOR_BATCH_SIZE_ATTRIBUTE = new SimpleAttributeDefinitionBuilder(Element.PROCESSOR_BATCH_SIZE_ATTRIBUTE.getModelName(), ModelType.INT)
.setXmlName(Element.BUFFER_MANAGER_PROCESSOR_BATCH_SIZE_ATTRIBUTE.getXMLName())
.setRequired(false)
.setAllowExpression(false)
.setDeprecated(BUFFER_SERVICE_VERSION)
.build();

@Deprecated
public static SimpleAttributeDefinition MAX_PROCESSING_KB_ATTRIBUTE = new SimpleAttributeDefinitionBuilder(Element.MAX_PROCESSING_KB_ATTRIBUTE.getModelName(), ModelType.INT)
.setXmlName(Element.BUFFER_MANAGER_MAX_PROCESSING_KB_ATTRIBUTE.getXMLName())
.setRequired(false)
.setAllowExpression(false)
.setMeasurementUnit(MeasurementUnit.KILOBYTES)
.setDeprecated(BUFFER_SERVICE_VERSION)
.build();

@Deprecated
public static SimpleAttributeDefinition MAX_RESERVED_KB_ATTRIBUTE = new SimpleAttributeDefinitionBuilder(Element.MAX_RESERVED_KB_ATTRIBUTE.getModelName(), ModelType.INT)
.setXmlName(Element.BUFFER_MANAGER_MAX_RESERVED_MB_ATTRIBUTE.getXMLName())
.setRequired(false)
.setAllowExpression(false)
.setMeasurementUnit(MeasurementUnit.KILOBYTES)
.setDeprecated(BUFFER_SERVICE_VERSION)
.build();

@Deprecated
public static SimpleAttributeDefinition MAX_FILE_SIZE_ATTRIBUTE = new SimpleAttributeDefinitionBuilder(Element.MAX_FILE_SIZE_ATTRIBUTE.getModelName(), ModelType.LONG)
.setXmlName(Element.BUFFER_MANAGER_MAX_FILE_SIZE_ATTRIBUTE.getXMLName())
.setRequired(false)
.setAllowExpression(false)
.setDeprecated(BUFFER_SERVICE_VERSION)
.build();

@Deprecated
public static SimpleAttributeDefinition MAX_BUFFER_SPACE_ATTRIBUTE = new SimpleAttributeDefinitionBuilder(Element.MAX_BUFFER_SPACE_ATTRIBUTE.getModelName(), ModelType.LONG)
.setXmlName(Element.BUFFER_MANAGER_MAX_BUFFER_SPACE_ATTRIBUTE.getXMLName())
.setRequired(false)
.setAllowExpression(false)
.setMeasurementUnit(MeasurementUnit.MEGABYTES)
.setDeprecated(BUFFER_SERVICE_VERSION)
.build();

@Deprecated
public static SimpleAttributeDefinition MAX_OPEN_FILES_ATTRIBUTE = new SimpleAttributeDefinitionBuilder(Element.MAX_OPEN_FILES_ATTRIBUTE.getModelName(), ModelType.INT)
.setXmlName(Element.BUFFER_MANAGER_MAX_OPEN_FILES_ATTRIBUTE.getXMLName())
.setRequired(false)
.setAllowExpression(false)
.setDeprecated(BUFFER_SERVICE_VERSION)
.build();

@Deprecated
public static SimpleAttributeDefinition MEMORY_BUFFER_SPACE_ATTRIBUTE = new SimpleAttributeDefinitionBuilder(Element.MEMORY_BUFFER_SPACE_ATTRIBUTE.getModelName(), ModelType.INT)
.setXmlName(Element.BUFFER_MANAGER_MEMORY_BUFFER_SPACE_ATTRIBUTE.getXMLName())
.setRequired(false)
.setAllowExpression(false)
.setMeasurementUnit(MeasurementUnit.MEGABYTES)
.setDeprecated(BUFFER_SERVICE_VERSION)
.build();

@Deprecated
public static SimpleAttributeDefinition MEMORY_BUFFER_OFFHEAP_ATTRIBUTE = new SimpleAttributeDefinitionBuilder(Element.MEMORY_BUFFER_OFFHEAP_ATTRIBUTE.getModelName(), ModelType.BOOLEAN)
.setXmlName(Element.BUFFER_MANAGER_MEMORY_BUFFER_OFFHEAP_ATTRIBUTE.getXMLName())
.setRequired(false)
.setAllowExpression(false)
.setDefaultValue(new ModelNode(false))
.setDeprecated(BUFFER_SERVICE_VERSION)
.build();

@Deprecated
public static SimpleAttributeDefinition MAX_STORAGE_OBJECT_SIZE_ATTRIBUTE = new SimpleAttributeDefinitionBuilder(Element.MAX_STORAGE_OBJECT_SIZE_ATTRIBUTE.getModelName(), ModelType.INT)
.setXmlName(Element.BUFFER_MANAGER_MAX_STORAGE_OBJECT_SIZE_ATTRIBUTE.getXMLName())
.setRequired(false)
.setAllowExpression(false)
.setMeasurementUnit(MeasurementUnit.BYTES)
.setDeprecated(BUFFER_SERVICE_VERSION)
.build();

@Deprecated
public static SimpleAttributeDefinition INLINE_LOBS = new SimpleAttributeDefinitionBuilder(Element.INLINE_LOBS.getModelName(), ModelType.BOOLEAN)
.setXmlName(Element.BUFFER_MANAGER_INLINE_LOBS.getXMLName())
.setRequired(false)
.setAllowExpression(false)
.setDeprecated(BUFFER_SERVICE_VERSION)
.build();

@Deprecated
public static SimpleAttributeDefinition ENCRYPT_FILES_ATTRIBUTE = new SimpleAttributeDefinitionBuilder(Element.ENCRYPT_FILES_ATTRIBUTE.getModelName(), ModelType.BOOLEAN)
.setXmlName(Element.BUFFER_MANAGER_ENCRYPT_FILES_ATTRIBUTE.getXMLName())
.setRequired(false)
.setAllowExpression(false)
.setDeprecated(BUFFER_SERVICE_VERSION)
.build();

// buffer manager
public static SimpleAttributeDefinition BUFFER_MANAGER_USE_DISK_ATTRIBUTE = new SimpleAttributeDefinitionBuilder(Element.BUFFER_MANAGER_USE_DISK_ATTRIBUTE.getModelName(), ModelType.BOOLEAN)
.setXmlName(Element.BUFFER_MANAGER_USE_DISK_ATTRIBUTE.getXMLName())
Expand Down
Expand Up @@ -40,6 +40,8 @@
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.SimpleOperationDefinitionBuilder;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.controller.operations.common.Util;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
Expand Down Expand Up @@ -276,6 +278,37 @@ class AttributeWrite extends AbstractWriteAttributeHandler<Void> {
public AttributeWrite(AttributeDefinition... attr) {
super(attr);
}

@Override
public void execute(OperationContext context, ModelNode operation)
throws OperationFailedException {
final String attributeName = operation.require(NAME).asString();
System.out.println(attributeName);
if (attributeName.startsWith("buffer-service")) { //$NON-NLS-1$
final AttributeDefinition attributeDefinition = getAttributeDefinition(attributeName);
String newAttribute = "buffer-manager-" + attributeDefinition.getXmlName(); //$NON-NLS-1$
boolean defined = operation.hasDefined(VALUE);
ModelNode newValue = defined ? operation.get(VALUE) : new ModelNode();

if (defined &&
(newAttribute.equals(Element.BUFFER_MANAGER_MAX_STORAGE_OBJECT_SIZE_ATTRIBUTE.getModelName())
|| newAttribute.equals(Element.BUFFER_MANAGER_MAX_RESERVED_MB_ATTRIBUTE.getModelName()))) {
int value = newValue.asInt();
if (value > 0) {
value = value/1024;
}
newValue = new ModelNode(value);
}

PathAddress currentAddress = context.getCurrentAddress();
operation = Util.createOperation(ModelDescriptionConstants.WRITE_ATTRIBUTE_OPERATION, currentAddress);
operation.get(ModelDescriptionConstants.NAME).set(newAttribute);
operation.get(ModelDescriptionConstants.VALUE).set(newValue);
super.execute(context, operation);
return;
}
super.execute(context, operation);
}

@Override
protected boolean applyUpdateToRuntime(OperationContext context,ModelNode operation,String attributeName,ModelNode resolvedValue,
Expand Down
Expand Up @@ -28,6 +28,7 @@
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;

import org.jboss.as.controller.SimpleAttributeDefinition;
import org.jboss.as.controller.parsing.ParseUtils;
import org.jboss.as.controller.persistence.SubsystemMarshallingContext;
import org.jboss.dmr.ModelNode;
Expand Down Expand Up @@ -55,7 +56,7 @@ public void writeContent(final XMLExtendedStreamWriter writer, final SubsystemMa
writer.writeEndElement();
}

if (like(node, Element.BUFFER_MANAGER_ELEMENT)){
if (like(node, Element.BUFFER_MANAGER_ELEMENT) || like(node, Element.BUFFER_SERVICE_ELEMENT)){
writer.writeStartElement(Element.BUFFER_MANAGER_ELEMENT.getLocalName());
writeBufferManager(writer, node);
writer.writeEndElement();
Expand Down Expand Up @@ -196,6 +197,21 @@ private void writeTransportConfiguration( XMLExtendedStreamWriter writer, ModelN
}

private void writeBufferManager(XMLExtendedStreamWriter writer, ModelNode node) throws XMLStreamException {
//if using a cli add, we end up here - the xml name has already been changed
USE_DISK_ATTRIBUTE.marshallAsAttribute(node, false, writer);
INLINE_LOBS.marshallAsAttribute(node, false, writer);
PROCESSOR_BATCH_SIZE_ATTRIBUTE.marshallAsAttribute(node, false, writer);
MAX_PROCESSING_KB_ATTRIBUTE.marshallAsAttribute(node, false, writer);
MAX_FILE_SIZE_ATTRIBUTE.marshallAsAttribute(node, false, writer);
MAX_BUFFER_SPACE_ATTRIBUTE.marshallAsAttribute(node, false, writer);
MAX_OPEN_FILES_ATTRIBUTE.marshallAsAttribute(node, false, writer);
MEMORY_BUFFER_SPACE_ATTRIBUTE.marshallAsAttribute(node, false, writer);
MEMORY_BUFFER_OFFHEAP_ATTRIBUTE.marshallAsAttribute(node, false, writer);
ENCRYPT_FILES_ATTRIBUTE.marshallAsAttribute(node, false, writer);
//values need adjusted
writeAdjustedValue(writer, node, MAX_RESERVED_KB_ATTRIBUTE);
writeAdjustedValue(writer, node, MAX_STORAGE_OBJECT_SIZE_ATTRIBUTE);

BUFFER_MANAGER_USE_DISK_ATTRIBUTE.marshallAsAttribute(node, false, writer);
BUFFER_MANAGER_INLINE_LOBS.marshallAsAttribute(node, false, writer);
BUFFER_MANAGER_PROCESSOR_BATCH_SIZE_ATTRIBUTE.marshallAsAttribute(node, false, writer);
Expand All @@ -210,6 +226,18 @@ private void writeBufferManager(XMLExtendedStreamWriter writer, ModelNode node)
BUFFER_MANAGER_ENCRYPT_FILES_ATTRIBUTE.marshallAsAttribute(node, false, writer);
}

private void writeAdjustedValue(XMLExtendedStreamWriter writer,
ModelNode node, SimpleAttributeDefinition element) throws XMLStreamException {
String name = element.getName();
if (node.hasDefined(name)) {
int value = node.get(name).asInt();
if (value > 0) {
value = value/1024;
}
writer.writeAttribute(element.getXmlName(), String.valueOf(value));
}
}

private void writeResultsetCacheConfiguration(XMLExtendedStreamWriter writer, ModelNode node) throws XMLStreamException {
RSC_NAME_ATTRIBUTE.marshallAsAttribute(node, false, writer);
RSC_CONTAINER_NAME_ATTRIBUTE.marshallAsAttribute(node, false, writer);
Expand Down

0 comments on commit faa6203

Please sign in to comment.