@Override public void registerAttributes(ManagementResourceRegistration registry) { super.registerAttributes(registry); AttributeDefinition[] attributes = deployed ? getDeploymentAttributes() : ATTRIBUTES; for (AttributeDefinition attr : attributes) { if (registerRuntimeOnly || !attr.getFlags().contains(AttributeAccess.Flag.STORAGE_RUNTIME)) { if (deployed) { registry.registerReadOnlyAttribute(attr, JMSQueueConfigurationRuntimeHandler.INSTANCE); } else { if (attr == CommonAttributes.DESTINATION_ENTRIES) { registry.registerReadWriteAttribute( attr, null, JMSQueueConfigurationWriteHandler.INSTANCE); } else { registry.registerReadOnlyAttribute(attr, null); } } } } if (registerRuntimeOnly) { for (AttributeDefinition attr : READONLY_ATTRIBUTES) { registry.registerReadOnlyAttribute(attr, JMSQueueReadAttributeHandler.INSTANCE); } for (AttributeDefinition metric : METRICS) { registry.registerMetric(metric, JMSQueueReadAttributeHandler.INSTANCE); } } }
@Override protected void populateModel(ModelNode operation, ModelNode model) throws OperationFailedException { for (AttributeDefinition def : ATTRIBUTES) { def.validateAndSet(operation, model); } }
public void registerAttributes(final ManagementResourceRegistration registry) { final EnumSet<AttributeAccess.Flag> flags = EnumSet.of(AttributeAccess.Flag.RESTART_ALL_SERVICES); for (AttributeDefinition attr : CommonAttributes.DIVERT_ATTRIBUTES) { registry.registerReadWriteAttribute(attr.getName(), null, this, flags); } }
private static Set<String> namesFromDefinitions(AttributeDefinition... attributes) { final Set<String> names = new HashSet<String>(); for (final AttributeDefinition def : attributes) { names.add(def.getName()); } return names; }
@Override public void persist(XMLExtendedStreamWriter writer, ModelNode model) throws XMLStreamException { boolean wildcard = getPathElement().isWildcard(); model = wildcard ? model.get(getPathElement().getKey()) : model.get(getPathElement().getKeyValuePair()); if (!model.isDefined()) { return; } boolean writeWrapper = getXmlWrapperElement() != null; if (writeWrapper) { writer.writeStartElement(getXmlWrapperElement()); } writer.writeStartElement(getXmlElementName()); if (wildcard) { for (Property p : model.asPropertyList()) { writer.writeAttribute(NAME, p.getName()); for (AttributeDefinition def : getAttributes()) { def.getAttributeMarshaller().marshallAsAttribute(def, p.getValue(), false, writer); } persistChildren(writer, p.getValue()); } } else { for (AttributeDefinition def : getAttributes()) { def.getAttributeMarshaller().marshallAsAttribute(def, model, false, writer); } persistChildren(writer, model); } writer.writeEndElement(); if (writeWrapper) { writer.writeEndElement(); } }
protected Map<String, AttributeDefinition> getAttributeMap() { Map<String, AttributeDefinition> res = new HashMap<>(); for (AttributeDefinition def : getAttributes()) { res.put(def.getName(), def); } return res; }
@Override protected void populateModel(ModelNode operation, ModelNode model) throws OperationFailedException { for (AttributeDefinition attr : listenerDefinition.getAttributes()) { attr.validateAndSet(operation, model); } }
@Override public void execute(final OperationContext context, final ModelNode ignored) throws OperationFailedException { final Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS); final ModelNode model = resource.getModel(); for (final AttributeDefinition definition : InterfaceDescription.ROOT_ATTRIBUTES) { final String attributeName = definition.getName(); final boolean has = model.hasDefined(attributeName); if (!has && isRequired(definition, model)) { throw new OperationFailedException(new ModelNode().set(MESSAGES.required(attributeName))); } if (has) { if (!isAllowed(definition, model)) { // TODO probably move this into AttributeDefinition String[] alts = definition.getAlternatives(); StringBuilder sb = null; if (alts != null) { for (String alt : alts) { if (model.hasDefined(alt)) { if (sb == null) { sb = new StringBuilder(); } else { sb.append(", "); } sb.append(alt); } } } throw new OperationFailedException( new ModelNode().set(MESSAGES.invalidAttributeCombo(attributeName, sb))); } } } context.completeStep(); }
@Override protected void populateModel(ModelNode operation, ModelNode model) throws OperationFailedException { for (final AttributeDefinition attribute : CommonAttributes.RESOURCE_ADAPTER_ATTRIBUTE) { attribute.validateAndSet(operation, model); } }
private static void writeConnectorServices(XMLExtendedStreamWriter writer, ModelNode node) throws XMLStreamException { if (!node.isDefined()) { return; } List<Property> properties = node.asPropertyList(); if (!properties.isEmpty()) { writer.writeStartElement(Element.CONNECTOR_SERVICES.getLocalName()); for (final Property property : node.asPropertyList()) { writer.writeStartElement(Element.CONNECTOR_SERVICE.getLocalName()); writer.writeAttribute(Attribute.NAME.getLocalName(), property.getName()); final ModelNode service = property.getValue(); for (AttributeDefinition attribute : ConnectorServiceDefinition.ATTRIBUTES) { attribute.marshallAsElement(property.getValue(), writer); } // TODO use a custom attribute marshaller if (service.hasDefined(CommonAttributes.PARAM)) { for (Property param : service.get(CommonAttributes.PARAM).asPropertyList()) { writer.writeEmptyElement(Element.PARAM.getLocalName()); writer.writeAttribute(Attribute.KEY.getLocalName(), param.getName()); writer.writeAttribute( Attribute.VALUE.getLocalName(), param.getValue().get(ConnectorServiceParamDefinition.VALUE.getName()).asString()); } } writer.writeEndElement(); } writer.writeEndElement(); writeNewLine(writer); } }
// TODO move this kind of logic into AttributeDefinition itself private static ModelNode validateResolvedModel( final AttributeDefinition definition, final OperationContext context, final ModelNode subModel) throws OperationFailedException { final String attributeName = definition.getName(); final boolean has = subModel.has(attributeName); if (!has && definition.isRequired(subModel)) { throw ServerMessages.MESSAGES.attributeIsRequired(attributeName); } ModelNode result; if (has) { if (!definition.isAllowed(subModel)) { if (subModel.hasDefined(attributeName)) { throw ServerMessages.MESSAGES.attributeNotAllowedWhenAlternativeIsPresent( attributeName, Arrays.asList(definition.getAlternatives())); } else { // create the undefined node result = new ModelNode(); } } else { result = definition.resolveModelAttribute(context, subModel); } } else { // create the undefined node result = new ModelNode(); } return result; }
@Override protected void populateModel(ModelNode operation, ModelNode model) throws OperationFailedException { for (AttributeDefinition attribute : KeyStoreProviderResourceDefinition.INSTANCE.getAttributes()) { attribute.validateAndSet(operation, model); } }
/** * Test whether the operation has a defined criteria attribute. * * @param operation the operation * @return */ public static boolean isOperationDefined(final ModelNode operation) { for (final AttributeDefinition def : ROOT_ATTRIBUTES) { if (operation.hasDefined(def.getName())) { return true; } } return false; }
/** * Populate the given node in the persistent configuration model based on the values in the given * operation. * * @param operation the operation * @param model persistent configuration model node that corresponds to the address of {@code * operation} * @throws org.jboss.as.controller.OperationFailedException if {@code operation} is invalid or * populating the model otherwise fails */ @Override protected void populateModel(ModelNode operation, ModelNode model) throws OperationFailedException { for (AttributeDefinition attribute : ModClusterConfigResourceDefinition.ATTRIBUTES) { attribute.validateAndSet(operation, model); } ModClusterConfigResourceDefinition.SIMPLE_LOAD_PROVIDER.validateAndSet(operation, model); }
private void registerAttributeAccessConstraints(AttributeDefinition ad) { if (constraintUtilizationRegistry != null) { for (AccessConstraintDefinition acd : ad.getAccessConstraints()) { constraintUtilizationRegistry.registerAccessConstraintAttributeUtilization( acd.getKey(), getPathAddress(), ad.getName()); } } }
/** * Creates a handler that doesn't validate values. * * @param attributes all persistent attributes of the * @param runtimeAttributes attributes whose updated value can immediately be applied to the * runtime */ public ThreadsWriteAttributeOperationHandler( AttributeDefinition[] attributes, AttributeDefinition[] runtimeAttributes) { super(attributes); this.attributes = attributes; for (AttributeDefinition attr : runtimeAttributes) { this.runtimeAttributes.put(attr.getName(), attr); } }
@Override protected void populateModel(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException { checkNoOtherProtocol(context, operation); ModelNode model = resource.getModel(); for (AttributeDefinition def : attributes) { def.validateAndSet(operation, model); } }
@Override public void registerAttributes(ManagementResourceRegistration registry) { OperationStepHandler writeHandler = new ConnectorServiceWriteAttributeHandler(ATTRIBUTES); for (AttributeDefinition attr : ATTRIBUTES) { if (!attr.getFlags().contains(STORAGE_RUNTIME)) { registry.registerReadWriteAttribute(attr, null, writeHandler); } } }
public static ModelNode createKeystoreAddOperation( final PathAddress storeAddress, final ModelNode store) { ModelNode storeAdd = Util.createAddOperation(storeAddress); for (AttributeDefinition def : TlsKeyStore.CLIENT_CERT_ATTRIBUTES) { storeAdd.get(def.getName()).set(store.get(def.getName())); } return storeAdd; }
protected void populateModel(final ModelNode operation, final ModelNode model) throws OperationFailedException { NAME.validateAndSet(operation, model); for (AttributeDefinition attr : attributes) { if (attr == VALUE) { // don't validate VALUE attribute WFCORE-826 model.get(VALUE.getName()).set(operation.get(VALUE.getName())); } else { attr.validateAndSet(operation, model); } } }
/** Create an "add" operation using the existing model */ public static ModelNode getAddOperation(final ModelNode address, ModelNode subModel) { final ModelNode operation = org.jboss.as.controller.operations.common.Util.getEmptyOperation(ADD, address); for (AttributeDefinition attr : CommonAttributes.CONNECTOR_SERVICE_ATTRIBUTES) { if (subModel.hasDefined(attr.getName())) { operation.get(attr.getName()).set(subModel.get(attr.getName())); } } return operation; }
@Override public void registerAttributes(ManagementResourceRegistration registry) { super.registerAttributes(registry); OperationStepHandler attributeHandler = new ReloadRequiredWriteAttributeHandler(ATTRIBUTES); for (AttributeDefinition attr : ATTRIBUTES) { if (registerRuntimeOnly || !attr.getFlags().contains(AttributeAccess.Flag.STORAGE_RUNTIME)) { registry.registerReadWriteAttribute(attr, null, attributeHandler); } } }
public void marshallAsAttribute( AttributeDefinition attribute, ModelNode resourceModel, boolean marshallDefault, XMLStreamWriter writer) throws javax.xml.stream.XMLStreamException { if (isMarshallable(attribute, resourceModel)) { writer.writeAttribute( attribute.getXmlName(), resourceModel.get(attribute.getName()).asString()); } }
@Override protected void populateModel(ModelNode operation, ModelNode model) throws OperationFailedException { model.setEmptyObject(); for (final AttributeDefinition attributeDefinition : CommonAttributes.CONNECTOR_SERVICE_ATTRIBUTES) { attributeDefinition.validateAndSet(operation, model); } }
@Override public TransformedOperation transformOperation( TransformationContext context, PathAddress address, ModelNode operation) { ModelNode legacyOperation = this.transformer.transformOperation(operation); for (AttributeDefinition 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); }
/** * Wrap a simple attribute def as list. * * @param def the attribute definition * @return the list attribute def */ @Deprecated private static ListAttributeDefinition wrapAsList(final AttributeDefinition def) { final ListAttributeDefinition list = new ListAttributeDefinition(def.getName(), true, def.getValidator()) { @Override public ModelNode getNoTextDescription(boolean forOperation) { final ModelNode model = super.getNoTextDescription(forOperation); setValueType(model); return model; } @Override protected void addValueTypeDescription( final ModelNode node, final ResourceBundle bundle) { setValueType(node); } @Override public void marshallAsElement( final ModelNode resourceModel, final boolean marshalDefault, final XMLStreamWriter writer) throws XMLStreamException { throw new RuntimeException(); } @Override protected void addAttributeValueTypeDescription( ModelNode node, ResourceDescriptionResolver resolver, Locale locale, ResourceBundle bundle) { setValueType(node); } @Override protected void addOperationParameterValueTypeDescription( ModelNode node, String operationName, ResourceDescriptionResolver resolver, Locale locale, ResourceBundle bundle) { setValueType(node); } private void setValueType(ModelNode node) { node.get(ModelDescriptionConstants.VALUE_TYPE).set(ModelType.STRING); } }; return list; }
@Override protected void populateModel(ModelNode operation, ModelNode model) throws OperationFailedException { // attributes for (AttributeDefinition attribute : ModelAttributes.REPOSITORY_ATTRIBUTES) { attribute.validateAndSet(operation, model); } // metrics for (final AttributeDefinition metric : ModelMetrics.ALL_METRICS) { metric.validateAndSet(operation, model); } }
@Override public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException { final Resource resource = context.createResource(PathAddress.EMPTY_ADDRESS); final ModelNode model = resource.getModel(); final String path = PathAddress.pathAddress(operation.require(OP_ADDR)).getLastElement().getValue(); for (AttributeDefinition attribute : getAttributes(path)) { attribute.validateAndSet(operation, model); } reloadRequiredStep(context); context.stepCompleted(); }
public void persist(XMLExtendedStreamWriter writer, ModelNode model, String namespaceURI) throws XMLStreamException { boolean wildcard = getPathElement().isWildcard(); model = wildcard ? model.get(getPathElement().getKey()) : model.get(getPathElement().getKeyValuePair()); if (!model.isDefined() && !useValueAsElementName()) { return; } boolean isSubsystem = getPathElement().getKey().equals(ModelDescriptionConstants.SUBSYSTEM); boolean writeWrapper = getXmlWrapperElement() != null; if (writeWrapper) { writeStartElement(writer, namespaceURI, getXmlWrapperElement()); } if (wildcard) { for (Property p : model.asPropertyList()) { if (useValueAsElementName()) { writeStartElement(writer, namespaceURI, p.getName()); } else { writeStartElement(writer, namespaceURI, getXmlElementName()); writer.writeAttribute(NAME, p.getName()); } for (AttributeDefinition def : getAttributes()) { def.getAttributeMarshaller().marshallAsAttribute(def, p.getValue(), false, writer); } persistChildren(writer, p.getValue()); writer.writeEndElement(); } } else { if (useValueAsElementName()) { writeStartElement(writer, namespaceURI, getPathElement().getValue()); } else if (isSubsystem) { startSubsystemElement(writer, namespaceURI, getChildren().isEmpty()); } else { writeStartElement(writer, namespaceURI, getXmlElementName()); } for (AttributeDefinition def : getAttributes()) { def.getAttributeMarshaller().marshallAsAttribute(def, model, false, writer); } persistChildren(writer, model); writer.writeEndElement(); } if (writeWrapper) { writer.writeEndElement(); } }
private static void configureAttributes( Map<String, FailedOperationTransformationConfig.PathAddressConfig> map, AttributeDefinition[] rejectedExpression, AttributeDefinition[] newAttributes) { RejectExpressionsConfig rejectExpressionsConfig = new RejectExpressionsConfig(rejectedExpression); for (AttributeDefinition attr : rejectedExpression) { map.put(attr.getName(), rejectExpressionsConfig); } NewAttributesConfig newAttributesConfig = new NewAttributesConfig(newAttributes); for (AttributeDefinition attr : newAttributes) { map.put(attr.getName(), newAttributesConfig); } }