XMLElement(Attribute attribute) { this.name = attribute.getName(); }
XMLAttribute(Attribute attribute) { this.name = attribute.getName(); }
private static boolean hasDefined(ModelNode model, Collection<? extends Attribute> attributes) { for (Attribute attribute : attributes) { if (model.hasDefined(attribute.getName())) return true; } return false; }
public static ModelNode createMapClearOperation(PathAddress address, Attribute attribute) { ModelNode operation = Util.createOperation(MapOperations.MAP_CLEAR_DEFINITION, address); operation.get(ModelDescriptionConstants.NAME).set(attribute.getName()); return operation; }
<E extends Enum<E> & org.jboss.as.clustering.controller.Attribute> LegacyAddOperationTransformation(Class<E> attributeClass) { // If none of the specified attributes are defined, then this is a legacy operation this.legacy = operation -> { for (org.jboss.as.clustering.controller.Attribute attribute : EnumSet.allOf(attributeClass)) { if (operation.hasDefined(attribute.getName())) return false; } return true; }; }
/** * Creates a new reference between the specified capability and the specified requirement * @param capability the capability referencing the specified requirement * @param requirement the requirement of the specified capability * @param parentAttribute the attribute containing the value of the parent dynamic component of the requirement */ public CapabilityReference(Capability capability, BinaryRequirement requirement, Attribute parentAttribute) { this(capability, requirement, context -> context.readResource(PathAddress.EMPTY_ADDRESS, false).getModel().get(parentAttribute.getName()).asString(), parentAttribute.getName()); }
private static ModelNode createAttributeOperation(String operationName, PathAddress address, Attribute attribute) { ModelNode operation = Util.createOperation(operationName, address); operation.get(ModelDescriptionConstants.NAME).set(attribute.getName()); return operation; }
private static boolean hasDefined(ModelNode model, Iterable<? extends Attribute> attributes) { for (Attribute attribute : attributes) { if (model.hasDefined(attribute.getName())) return true; } return false; }
/** * Creates an add operation using the specified address and parameters * @param address a path address * @param parameters a map of values per attribute * @return an add operation */ public static ModelNode createAddOperation(PathAddress address, Map<Attribute, ModelNode> parameters) { ModelNode operation = Util.createAddOperation(address); for (Map.Entry<Attribute, ModelNode> entry : parameters.entrySet()) { operation.get(entry.getKey().getName()).set(entry.getValue()); } return operation; }
/** * Creates an indexed add operation using the specified address and parameters * @param address a path address * @param parameters a map of values per attribute * @return an add operation */ public static ModelNode createAddOperation(PathAddress address, int index, Map<Attribute, ModelNode> parameters) { ModelNode operation = Util.createAddOperation(address); operation.get(ModelDescriptionConstants.ADD_INDEX).set(index); for (Map.Entry<Attribute, ModelNode> entry : parameters.entrySet()) { operation.get(entry.getKey().getName()).set(entry.getValue()); } return operation; }
@Override public TransformedOperation transformOperation(TransformationContext context, PathAddress address, ModelNode operation) { ModelNode legacyOperation = this.transformer.transformOperation(operation); for (Attribute attribute: this.attributes) { String name = attribute.getName(); if (operation.hasDefined(name)) { legacyOperation.get(name).set(operation.get(name)); } } return new TransformedOperation(legacyOperation, OperationResultTransformer.ORIGINAL_RESULT); } }
@Override public ModelNode transformOperation(ModelNode operation) { PathAddress storeAddress = Operations.getPathAddress(operation).getParent(); ModelNode value = new ModelNode(); for (Class<? extends org.jboss.as.clustering.controller.Attribute> attributeClass : Arrays.asList(Attribute.class, TableResourceDefinition.Attribute.class, TableResourceDefinition.ColumnAttribute.class)) { for (org.jboss.as.clustering.controller.Attribute attribute : attributeClass.getEnumConstants()) { String name = attribute.getName(); if (operation.hasDefined(name)) { value.get(name).set(operation.get(name)); } } } return value.isDefined() ? Operations.createWriteAttributeOperation(storeAddress, StringKeyedJDBCStoreResourceDefinition.DeprecatedAttribute.TABLE, value) : Operations.createUndefineAttributeOperation(storeAddress, StringKeyedJDBCStoreResourceDefinition.DeprecatedAttribute.TABLE); } };
@Override public ModelNode transformOperation(ModelNode operation) { PathAddress storeAddress = Operations.getPathAddress(operation).getParent(); ModelNode value = new ModelNode(); for (Class<? extends org.jboss.as.clustering.controller.Attribute> attributeClass : Arrays.asList(Attribute.class, TableResourceDefinition.Attribute.class, TableResourceDefinition.ColumnAttribute.class)) { for (org.jboss.as.clustering.controller.Attribute attribute : attributeClass.getEnumConstants()) { String name = attribute.getName(); if (operation.hasDefined(name)) { value.get(name).set(operation.get(name)); } } } return value.isDefined() ? Operations.createWriteAttributeOperation(storeAddress, BinaryKeyedJDBCStoreResourceDefinition.DeprecatedAttribute.TABLE, value) : Operations.createUndefineAttributeOperation(storeAddress, BinaryKeyedJDBCStoreResourceDefinition.DeprecatedAttribute.TABLE); } };
@Override public DiscardPolicy checkResource(TransformationContext context, PathAddress address) { ModelNode model = Resource.Tools.readModel(context.readResourceFromRoot(address)); for (Attribute attribute : this.attributes) { if (model.hasDefined(attribute.getName())) { return DiscardPolicy.REJECT_AND_WARN; } } return DiscardPolicy.SILENT; } }
@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, 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()); } } } };
@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, 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()); } } } };
void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder parent) { ResourceTransformationDescriptionBuilder builder = parent.addChildResource(this.definition); if (JGroupsModel.VERSION_6_0_0.requiresTransformation(version)) { builder.getAttributeBuilder().setValueConverter(new DefaultValueAttributeConverter(this.queueLength.getDefinition()), this.queueLength.getName()); } if (JGroupsModel.VERSION_5_0_0.requiresTransformation(version)) { for (Attribute attribute : Arrays.asList(this.minThreads, this.maxThreads)) { builder.getAttributeBuilder().setValueConverter(new DefaultValueAttributeConverter(attribute.getDefinition()), attribute.getName()); } } } }
@Override public OperationStepHandler apply(OperationStepHandler handler) { return (context, operation) -> { if (operation.hasDefined(this.attribute.getName())) { // Translate deprecated table attribute into separate add table operation ModelNode addTableOperation = Util.createAddOperation(context.getCurrentAddress().append(this.path)); ModelNode parameters = operation.get(this.attribute.getName()); for (Property parameter : parameters.asPropertyList()) { addTableOperation.get(parameter.getName()).set(parameter.getValue()); } context.addStep(addTableOperation, context.getResourceRegistration().getOperationHandler(PathAddress.pathAddress(this.path), ModelDescriptionConstants.ADD), context.getCurrentStage()); } handler.execute(context, operation); }; }
private static void require(XMLExtendedStreamReader reader, ModelNode operation, Attribute... attributes) throws XMLStreamException { for (Attribute attribute : attributes) { if (!operation.hasDefined(attribute.getName())) { AttributeDefinition definition = attribute.getDefinition(); Set<String> names = Collections.singleton(definition.getXmlName()); throw definition.getParser().isParseAsElement() ? ParseUtils.missingRequiredElement(reader, names) : ParseUtils.missingRequired(reader, names); } } }
@Override void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder parent) { ResourceTransformationDescriptionBuilder builder = parent.addChildResource(this.getDefinition()); if (JGroupsModel.VERSION_6_0_0.requiresTransformation(version)) { for (Attribute attribute : Arrays.asList(this.getMinThreads(), this.getMaxThreads(), this.getQueueLength())) { builder.getAttributeBuilder().setValueConverter(new DefaultValueAttributeConverter(attribute.getDefinition()), attribute.getName()); } } } },