use of org.jboss.as.controller.transform.TransformationContext in project wildfly by wildfly.
the class RemoteStoreResourceDefinition method buildTransformation.
static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder parent) {
ResourceTransformationDescriptionBuilder builder = InfinispanModel.VERSION_4_0_0.requiresTransformation(version) ? parent.addChildRedirection(PATH, LEGACY_PATH) : parent.addChildResource(PATH);
if (InfinispanModel.VERSION_4_0_0.requiresTransformation(version)) {
builder.getAttributeBuilder().setValueConverter(new AttributeConverter.DefaultAttributeConverter() {
@Override
protected void convertAttribute(PathAddress address, String attributeName, ModelNode attributeValue, TransformationContext context) {
if (attributeValue.isDefined()) {
List<ModelNode> remoteServers = attributeValue.clone().asList();
ModelNode legacyListObject = new ModelNode();
for (ModelNode server : remoteServers) {
ModelNode legacyListItem = new ModelNode();
legacyListItem.get("outbound-socket-binding").set(server);
legacyListObject.add(legacyListItem);
}
attributeValue.set(legacyListObject);
}
}
}, Attribute.SOCKET_BINDINGS.getDefinition());
}
if (InfinispanModel.VERSION_3_0_0.requiresTransformation(version)) {
builder.addOperationTransformationOverride(ModelDescriptionConstants.ADD).setCustomOperationTransformer(new SimpleOperationTransformer(new LegacyPropertyAddOperationTransformer())).inheritResourceAttributeDefinitions();
builder.setCustomResourceTransformer(new LegacyPropertyResourceTransformer());
}
StoreResourceDefinition.buildTransformation(version, builder);
}
use of org.jboss.as.controller.transform.TransformationContext in project wildfly by wildfly.
the class JDBCStoreResourceDefinition method buildTransformation.
static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder builder) {
if (InfinispanModel.VERSION_4_2_0.requiresTransformation(version) && !InfinispanModel.VERSION_4_0_0.requiresTransformation(version)) {
// DATASOURCE attribute was only supported as an add operation parameter
builder.getAttributeBuilder().setDiscard(DiscardAttributeChecker.ALWAYS, DeprecatedAttribute.DATASOURCE.getDefinition());
}
if (InfinispanModel.VERSION_4_0_0.requiresTransformation(version)) {
// Converts pool name to its JNDI name
Converter converter = new Converter() {
@Override
public void convert(PathAddress address, String name, ModelNode value, ModelNode model, TransformationContext context) {
if (value.isDefined()) {
PathAddress rootAddress = address.subAddress(0, address.size() - 4);
PathAddress subsystemAddress = rootAddress.append(PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, "datasources"));
Resource subsystem = context.readResourceFromRoot(subsystemAddress);
String poolName = value.asString();
for (String type : Arrays.asList("data-source", "xa-data-source")) {
if (subsystem.hasChildren(type)) {
for (Resource.ResourceEntry entry : subsystem.getChildren(type)) {
if (entry.getName().equals(poolName)) {
value.set(entry.getModel().get("jndi-name"));
return;
}
}
}
}
}
}
};
builder.getAttributeBuilder().addRename(Attribute.DATA_SOURCE.getName(), DeprecatedAttribute.DATASOURCE.getName()).setValueConverter(new SimpleAttributeConverter(converter), Attribute.DATA_SOURCE.getDefinition());
}
if (InfinispanModel.VERSION_3_0_0.requiresTransformation(version)) {
builder.addOperationTransformationOverride(ModelDescriptionConstants.ADD).setCustomOperationTransformer(new SimpleOperationTransformer(new LegacyPropertyAddOperationTransformer())).inheritResourceAttributeDefinitions();
}
if (InfinispanModel.VERSION_2_0_0.requiresTransformation(version)) {
builder.getAttributeBuilder().setDiscard(DiscardAttributeChecker.UNDEFINED, Attribute.DIALECT.getDefinition()).addRejectCheck(RejectAttributeChecker.DEFINED, Attribute.DIALECT.getDefinition()).end();
}
StoreResourceDefinition.buildTransformation(version, builder);
}
use of org.jboss.as.controller.transform.TransformationContext in project wildfly by wildfly.
the class ChannelResourceDefinition method buildTransformation.
static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder parent) {
if (JGroupsModel.VERSION_3_0_0.requiresTransformation(version)) {
DynamicDiscardPolicy channelDiscardRejectPolicy = new DynamicDiscardPolicy() {
@Override
public DiscardPolicy checkResource(TransformationContext context, PathAddress address) {
// Check whether all channel resources are used by the infinispan subsystem, and transformed
// by its corresponding transformers; reject otherwise
// n.b. we need to hard-code the values because otherwise we would end up with cyclical dependency
String channelName = address.getLastElement().getValue();
PathAddress rootAddress = address.subAddress(0, address.size() - 2);
PathAddress subsystemAddress = rootAddress.append(PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, "infinispan"));
Resource infinispanResource;
try {
infinispanResource = context.readResourceFromRoot(subsystemAddress);
} catch (Resource.NoSuchResourceException ex) {
return DiscardPolicy.REJECT_AND_WARN;
}
ModelNode infinispanModel = Resource.Tools.readModel(infinispanResource);
if (infinispanModel.hasDefined("cache-container")) {
for (ModelNode container : infinispanModel.get("cache-container").asList()) {
ModelNode cacheContainer = container.get(0);
if (cacheContainer.hasDefined("transport")) {
ModelNode transport = cacheContainer.get("transport").get("jgroups");
if (transport.hasDefined("channel")) {
String channel = transport.get("channel").asString();
if (channel.equals(channelName)) {
return DiscardPolicy.SILENT;
}
} else {
// In that case, if this were the default channel, it can be discarded too
ModelNode subsystem = context.readResourceFromRoot(address.subAddress(0, address.size() - 1)).getModel();
if (subsystem.hasDefined(JGroupsSubsystemResourceDefinition.Attribute.DEFAULT_CHANNEL.getName())) {
if (subsystem.get(JGroupsSubsystemResourceDefinition.Attribute.DEFAULT_CHANNEL.getName()).asString().equals(channelName)) {
return DiscardPolicy.SILENT;
}
}
}
}
}
}
// No references to this channel, we need to reject it.
return DiscardPolicy.REJECT_AND_WARN;
}
};
parent.addChildResource(WILDCARD_PATH, channelDiscardRejectPolicy);
} else {
ResourceTransformationDescriptionBuilder builder = parent.addChildResource(WILDCARD_PATH);
if (JGroupsModel.VERSION_4_0_0.requiresTransformation(version)) {
DiscardAttributeChecker discarder = new DefaultDiscardAttributeChecker(false, true) {
@Override
protected boolean isValueDiscardable(PathAddress address, String attributeName, ModelNode attributeValue, TransformationContext context) {
return !attributeValue.isDefined() || attributeValue.equals(new ModelNode(address.getLastElement().getValue()));
}
};
builder.getAttributeBuilder().setDiscard(discarder, Attribute.CLUSTER.getDefinition()).addRejectCheck(RejectAttributeChecker.DEFINED, Attribute.CLUSTER.getDefinition());
}
ProtocolRegistration.buildTransformation(version, builder);
}
}
use of org.jboss.as.controller.transform.TransformationContext in project wildfly by wildfly.
the class XaDataSourceDefinition method registerTransformers200.
static void registerTransformers200(ResourceTransformationDescriptionBuilder parentBuilder) {
ResourceTransformationDescriptionBuilder builder = parentBuilder.addChildResource(PATH_XA_DATASOURCE);
builder.getAttributeBuilder().setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(new ModelNode(false)), CONNECTABLE).setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(false, false, new ModelNode(true)), STATISTICS_ENABLED).setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(new ModelNode(true)), ENLISTMENT_TRACE).setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(new ModelNode(LEGACY_MCP)), MCP).setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(false, true, new ModelNode(false)), Constants.ELYTRON_ENABLED, Constants.RECOVERY_ELYTRON_ENABLED).setDiscard(DiscardAttributeChecker.UNDEFINED, Constants.AUTHENTICATION_CONTEXT, RECOVERY_AUTHENTICATION_CONTEXT, CREDENTIAL_REFERENCE, RECOVERY_CREDENTIAL_REFERENCE).addRejectCheck(RejectAttributeChecker.DEFINED, ENLISTMENT_TRACE).addRejectCheck(RejectAttributeChecker.DEFINED, MCP).addRejectCheck(new RejectAttributeChecker.DefaultRejectAttributeChecker() {
@Override
public String getRejectionLogMessage(Map<String, ModelNode> attributes) {
return ConnectorLogger.ROOT_LOGGER.rejectAttributesMustBeTrue(attributes.keySet());
}
@Override
protected boolean rejectAttribute(PathAddress address, String attributeName, ModelNode attributeValue, TransformationContext context) {
//This will not get called if it was discarded, so reject if it is undefined (default==false) or if defined and != 'true'
return !attributeValue.isDefined() || !attributeValue.asString().equals("true");
}
}, STATISTICS_ENABLED).setDiscard(DiscardAttributeChecker.UNDEFINED, TRACKING).addRejectCheck(RejectAttributeChecker.DEFINED, TRACKING).addRejectCheck(RejectAttributeChecker.SIMPLE_EXPRESSIONS, ENABLED).addRejectCheck(RejectAttributeChecker.DEFINED, Constants.ELYTRON_ENABLED, Constants.RECOVERY_ELYTRON_ENABLED, AUTHENTICATION_CONTEXT, RECOVERY_AUTHENTICATION_CONTEXT, CREDENTIAL_REFERENCE, RECOVERY_CREDENTIAL_REFERENCE).end().addOperationTransformationOverride(DATASOURCE_ENABLE.getName()).end().addOperationTransformationOverride(DATASOURCE_DISABLE.getName()).end();
}
use of org.jboss.as.controller.transform.TransformationContext in project wildfly by wildfly.
the class DataSourceDefinition method registerTransformers130.
static void registerTransformers130(ResourceTransformationDescriptionBuilder parentBuilder) {
ResourceTransformationDescriptionBuilder builder = parentBuilder.addChildResource(PATH_DATASOURCE);
builder.getAttributeBuilder().setDiscard(new DiscardAttributeChecker.DefaultDiscardAttributeChecker() {
@Override
protected boolean isValueDiscardable(PathAddress address, String attributeName, ModelNode attributeValue, TransformationContext context) {
return attributeValue.equals(new ModelNode(false));
}
}, TRACKING).setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(false, true, new ModelNode(false)), ELYTRON_ENABLED, RECOVERY_ELYTRON_ENABLED).setDiscard(DiscardAttributeChecker.UNDEFINED, AUTHENTICATION_CONTEXT, RECOVERY_AUTHENTICATION_CONTEXT, CREDENTIAL_REFERENCE).addRejectCheck(RejectAttributeChecker.SIMPLE_EXPRESSIONS, ENABLED).addRejectCheck(RejectAttributeChecker.DEFINED, TRACKING).addRejectCheck(RejectAttributeChecker.DEFINED, ELYTRON_ENABLED, RECOVERY_ELYTRON_ENABLED, AUTHENTICATION_CONTEXT, RECOVERY_AUTHENTICATION_CONTEXT, CREDENTIAL_REFERENCE).addRejectCheck(createConnURLRejectChecker(), CONNECTION_URL).end();
}
Aggregations