use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.
the class BinaryKeyedJDBCStoreResourceDefinition 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.setCustomResourceTransformer(new ResourceTransformer() {
@Override
public void transformResource(ResourceTransformationContext context, PathAddress address, Resource resource) throws OperationFailedException {
final ModelNode model = resource.getModel();
final ModelNode binaryTableModel = Resource.Tools.readModel(resource.removeChild(BinaryTableResourceDefinition.PATH));
if (binaryTableModel != null && binaryTableModel.isDefined()) {
model.get(DeprecatedAttribute.TABLE.getName()).set(binaryTableModel);
}
final ModelNode properties = model.remove(StoreResourceDefinition.Attribute.PROPERTIES.getName());
final ResourceTransformationContext childContext = context.addTransformedResource(PathAddress.EMPTY_ADDRESS, resource);
LegacyPropertyResourceTransformer.transformPropertiesToChildrenResources(properties, address, childContext);
context.processChildren(resource);
}
});
}
BinaryTableResourceDefinition.buildTransformation(version, builder);
JDBCStoreResourceDefinition.buildTransformation(version, builder);
}
use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.
the class NamingBindingResourceDefinition method registerOperations.
@Override
public void registerOperations(ManagementResourceRegistration resourceRegistration) {
super.registerOperations(resourceRegistration);
SimpleOperationDefinitionBuilder builder = new SimpleOperationDefinitionBuilder(NamingSubsystemModel.REBIND, getResourceDescriptionResolver()).addParameter(BINDING_TYPE).addParameter(TYPE).addParameter(VALUE).addParameter(CLASS).addParameter(MODULE).addParameter(LOOKUP).addParameter(ENVIRONMENT);
resourceRegistration.registerOperationHandler(builder.build(), new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
context.addStep(new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
validateResourceModel(operation, false);
Resource resource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS);
ModelNode model = resource.getModel();
for (AttributeDefinition attr : ATTRIBUTES) {
attr.validateAndSet(operation, model);
}
context.addStep(new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
final String name = context.getCurrentAddressValue();
final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(name);
ServiceController<ManagedReferenceFactory> service = (ServiceController<ManagedReferenceFactory>) context.getServiceRegistry(false).getService(bindInfo.getBinderServiceName());
if (service == null) {
context.reloadRequired();
return;
}
NamingBindingAdd.INSTANCE.doRebind(context, operation, (BinderService) service.getService());
}
}, OperationContext.Stage.RUNTIME);
}
}, OperationContext.Stage.MODEL);
}
});
}
use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.
the class MixedKeyedJDBCStoreResourceDefinition 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);
BinaryTableResourceDefinition.buildTransformation(version, builder);
StringTableResourceDefinition.buildTransformation(version, builder);
JDBCStoreResourceDefinition.buildTransformation(version, builder);
if (InfinispanModel.VERSION_4_0_0.requiresTransformation(version)) {
builder.setCustomResourceTransformer(new ResourceTransformer() {
@Override
public void transformResource(ResourceTransformationContext context, PathAddress address, Resource resource) throws OperationFailedException {
final ModelNode model = resource.getModel();
final ModelNode binaryTableModel = Resource.Tools.readModel(resource.removeChild(BinaryTableResourceDefinition.PATH));
if (binaryTableModel != null && binaryTableModel.isDefined()) {
model.get(DeprecatedAttribute.BINARY_TABLE.getName()).set(binaryTableModel);
}
final ModelNode stringTableModel = Resource.Tools.readModel(resource.removeChild(StringTableResourceDefinition.PATH));
if (stringTableModel != null && stringTableModel.isDefined()) {
model.get(DeprecatedAttribute.STRING_TABLE.getName()).set(stringTableModel);
}
final ModelNode properties = model.remove(StoreResourceDefinition.Attribute.PROPERTIES.getName());
final ResourceTransformationContext childContext = context.addTransformedResource(PathAddress.EMPTY_ADDRESS, resource);
LegacyPropertyResourceTransformer.transformPropertiesToChildrenResources(properties, address, childContext);
context.processChildren(resource);
}
});
}
if (InfinispanModel.VERSION_3_0_0.requiresTransformation(version)) {
builder.addRawOperationTransformationOverride(MapOperations.MAP_GET_DEFINITION.getName(), new SimpleOperationTransformer(new LegacyPropertyMapGetOperationTransformer()));
for (String opName : Operations.getAllWriteAttributeOperationNames()) {
builder.addOperationTransformationOverride(opName).inheritResourceAttributeDefinitions().setCustomOperationTransformer(new LegacyPropertyWriteOperationTransformer());
}
}
}
use of org.jboss.as.controller.registry.Resource 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.registry.Resource in project wildfly by wildfly.
the class InfinispanSubsystemInitialization method initializeExtraSubystemsAndModel.
@Override
protected void initializeExtraSubystemsAndModel(ExtensionRegistry registry, Resource root, ManagementResourceRegistration registration, RuntimeCapabilityRegistry capabilityRegistry) {
new DataSourcesExtension().initialize(registry.getExtensionContext("datasources", registration, ExtensionRegistryType.MASTER));
Resource subsystem = Resource.Factory.create();
root.registerChild(PathElement.pathElement(SUBSYSTEM, DataSourcesExtension.SUBSYSTEM_NAME), subsystem);
Resource dataSource = Resource.Factory.create();
subsystem.registerChild(PathElement.pathElement("data-source", "ExampleDS"), dataSource);
dataSource.getModel().get("jndi-name").set("java:jboss/jdbc/store");
super.initializeExtraSubystemsAndModel(registry, root, registration, capabilityRegistry);
}
Aggregations