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; }
/** 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; }
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); } }
protected Map<String, AttributeDefinition> getAttributeMap() { Map<String, AttributeDefinition> res = new HashMap<>(); for (AttributeDefinition def : getAttributes()) { res.put(def.getName(), def); } return res; }
@Override public void registerMetric(AttributeDefinition definition, OperationStepHandler metricHandler) { checkPermission(); AttributeAccess aa = new AttributeAccess( AccessType.METRIC, AttributeAccess.Storage.RUNTIME, metricHandler, null, definition, definition.getFlags()); if (attributesUpdater.putIfAbsent(this, definition.getName(), aa) != null) { throw alreadyRegistered("attribute", definition.getName()); } registerAttributeAccessConstraints(definition); }
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); } }
// 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; }
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 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(); }
/** * 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); } }
private void registerAttributeAccessConstraints(AttributeDefinition ad) { if (constraintUtilizationRegistry != null) { for (AccessConstraintDefinition acd : ad.getAccessConstraints()) { constraintUtilizationRegistry.registerAccessConstraintAttributeUtilization( acd.getKey(), getPathAddress(), ad.getName()); } } }
/** * 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; }
// TODO move this kind of logic into AttributeDefinition itself private static void validateAndSet( final AttributeDefinition definition, final ModelNode operation, final ModelNode subModel) throws OperationFailedException { final String attributeName = definition.getName(); final boolean has = operation.has(attributeName); if (!has && definition.isRequired(operation)) { throw ServerMessages.MESSAGES.attributeIsRequired(attributeName); } if (has) { if (!definition.isAllowed(operation)) { throw ServerMessages.MESSAGES.attributeIsInvalid(attributeName); } definition.validateAndSet(operation, subModel); } else { // create the undefined node subModel.get(definition.getName()); } }
/** * Creates a copy of unresolvedConfig with all expressions resolved and all undefined attributes * that have a default value set to the default. * * @param context the operation context * @param unresolvedConfig the raw configuration model * @return the resolved configuration model * @throws OperationFailedException if there is a problem resolving an attribute */ private ModelNode resolveConfig(OperationContext context, ModelNode unresolvedConfig) throws OperationFailedException { final ModelNode resolved = new ModelNode(); // First the simple core attributes for (AttributeDefinition coreAttr : ModClusterConfigResourceDefinition.ATTRIBUTES) { resolved .get(coreAttr.getName()) .set(coreAttr.resolveModelAttribute(context, unresolvedConfig)); } // Next SSL // Use ModClusterExtension.sslConfigurationPath here so if we change the PathElement components, // we don't have to change this code final ModelNode unresolvedSSL = unresolvedConfig.get( ModClusterExtension.sslConfigurationPath.getKey(), ModClusterExtension.sslConfigurationPath.getValue()); if (unresolvedSSL.isDefined()) { final ModelNode resolvedSSL = resolved.get( ModClusterExtension.sslConfigurationPath.getKey(), ModClusterExtension.sslConfigurationPath.getValue()); for (AttributeDefinition sslAttr : ModClusterConfigResourceDefinition.ATTRIBUTES) { resolvedSSL .get(sslAttr.getName()) .set(sslAttr.resolveModelAttribute(context, unresolvedSSL)); } } // Finally the load-provider stuff // TODO AS7-4050 properly handle these for (Property property : unresolvedConfig.asPropertyList()) { String key = property.getName(); if (!ModClusterConfigResourceDefinition.ATTRIBUTES_BY_NAME.containsKey(key) && !key.equals(ModClusterExtension.sslConfigurationPath.getKey())) { resolved.get(key).set(context.resolveExpressions(property.getValue())); } } return resolved; }
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 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; }
/** * Record any new {@link org.jboss.as.controller.capability.RuntimeCapability capabilities} that * are no longer available as a result of this operation, as well as any requirements for other * capabilities that no longer exist. This method is invoked during {@link * org.jboss.as.controller.OperationContext.Stage#MODEL}. * * <p>Any changes made by this method will automatically be discarded if the operation rolls back. * * <p>This default implementation deregisters any capabilities passed to the constructor. * * @param context the context. Will not be {@code null} * @param operation the operation that is executing Will not be {@code null} * @param resource the resource that will be removed. Will <strong>not</strong> reflect any * updates made by {@link #performRemove(OperationContext, org.jboss.dmr.ModelNode, * org.jboss.dmr.ModelNode)} as this method is invoked before that method is. Will not be * {@code null} */ protected void recordCapabilitiesAndRequirements( OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException { for (RuntimeCapability capability : capabilities) { if (capability.isDynamicallyNamed()) { context.deregisterCapability(capability.getDynamicName(context.getCurrentAddressValue())); } else { context.deregisterCapability(capability.getName()); } } ModelNode model = resource.getModel(); ImmutableManagementResourceRegistration mrr = context.getResourceRegistration(); for (String attr : mrr.getAttributeNames(PathAddress.EMPTY_ADDRESS)) { AttributeAccess aa = mrr.getAttributeAccess(PathAddress.EMPTY_ADDRESS, attr); if (aa != null) { AttributeDefinition ad = aa.getAttributeDefinition(); if (ad != null && model.hasDefined(ad.getName())) { ad.removeCapabilityRequirements(context, model.get(ad.getName())); } } } }
@Override public void updateModel( OperationContext context, ModelNode model, AttributeDefinition attributeDefinition, ModelNode attribute) throws OperationFailedException { if (attribute.getType() != ModelType.LIST && attributeDefinition.getType() != ModelType.LIST) { throw ControllerLogger.MGMT_OP_LOGGER.attributeIsWrongType( attributeDefinition.getName(), ModelType.LIST, attributeDefinition.getType()); } updateModel(context, model, attribute); }
ModelNode toModelNode() { ModelNode node = new ModelNode(); node.get(RESOURCE_PATH.getName()).set(resourcePath); ModelNode consumeNode = node.get(CONSUMES.getName()); if (consumeTypes != null && consumeTypes.length > 0) { for (MediaType consume : consumeTypes) { consumeNode.add(consume.toString()); } } ModelNode produceNode = node.get(PRODUCES.getName()); if (produceTypes != null && produceTypes.length > 0) { for (MediaType produce : produceTypes) { produceNode.add(produce.toString()); } } node.get(JAVA_METHOD.getName()).set(formatJavaMethod()); for (final String servletMapping : servletMappings) { for (final String httpMethod : httpMethods) { node.get(RESOURCE_METHODS.getName()) .add(httpMethod + " " + formatPath(servletMapping, contextPath, resourcePath)); } } return node; }
public ModelNode toModelNode() { ModelNode node = new ModelNode(); node.get(RESOURCE_CLASS.getName()).set(resourceClass.getCanonicalName()); ModelNode resPathNode = node.get(RESOURCE_PATHS.getName()); Collections.sort(methodsDescriptions); for (JaxrsResourceMethodDescription methodRes : methodsDescriptions) { resPathNode.add(methodRes.toModelNode()); } ModelNode subResNode = node.get(SUB_RESOURCE_LOCATORS.getName()); Collections.sort(subLocatorDescriptions); for (JaxrsResourceLocatorDescription subLocator : subLocatorDescriptions) { subResNode.add(subLocator.toModelNode()); } return node; }
@Override public void marshallAsElement( AttributeDefinition attribute, ModelNode resourceModel, boolean marshallDefault, XMLStreamWriter writer) throws XMLStreamException { resourceModel = resourceModel.get(attribute.getName()); if (wrapElement) { writer.writeStartElement(wrapperElement == null ? attribute.getName() : wrapperElement); } for (ModelNode property : resourceModel.asList()) { writer.writeEmptyElement(attribute.getXmlName()); writer.writeAttribute( org.jboss.as.controller.parsing.Attribute.NAME.getLocalName(), property.asProperty().getName()); writer.writeAttribute( org.jboss.as.controller.parsing.Attribute.VALUE.getLocalName(), property.asProperty().getValue().asString()); } if (wrapElement) { writer.writeEndElement(); } }
@Override public void marshallAsElement( final AttributeDefinition attribute, final ModelNode resourceModel, final boolean marshallDefault, final XMLStreamWriter writer) throws XMLStreamException { for (ModelNode property : resourceModel.get(attribute.getName()).asList()) { writer.writeStartElement(attribute.getXmlName()); writer.writeAttribute( org.jboss.as.controller.parsing.Attribute.NAME.getLocalName(), property.asProperty().getName()); writer.writeCharacters(property.asProperty().getValue().asString()); writer.writeEndElement(); } }
@Override public void marshallAsElement( AttributeDefinition attribute, ModelNode resourceModel, boolean marshallDefault, XMLStreamWriter writer) throws XMLStreamException { resourceModel = resourceModel.get(attribute.getName()); if (resourceModel.isDefined()) { for (ModelNode property : resourceModel.asList()) { writer.writeEmptyElement(REALM_MAPPING); writer.writeAttribute(FROM, property.asProperty().getName()); writer.writeAttribute(TO, property.asProperty().getValue().asString()); } } }
@Override public void registerReadOnlyAttribute( final AttributeDefinition definition, final OperationStepHandler readHandler) { checkPermission(); final EnumSet<AttributeAccess.Flag> flags = definition.getFlags(); final String attributeName = definition.getName(); AttributeAccess.Storage storage = (flags != null && flags.contains(AttributeAccess.Flag.STORAGE_RUNTIME)) ? Storage.RUNTIME : Storage.CONFIGURATION; AttributeAccess aa = new AttributeAccess(AccessType.READ_ONLY, storage, readHandler, null, definition, flags); if (attributesUpdater.putIfAbsent(this, attributeName, aa) != null) { throw alreadyRegistered("attribute", attributeName); } registerAttributeAccessConstraints(definition); }
@Override public void marshallAsElement( final AttributeDefinition attribute, final ModelNode resourceModel, final boolean marshallDefault, final XMLStreamWriter writer) throws XMLStreamException { if (isMarshallable(attribute, resourceModel, marshallDefault)) { writer.writeStartElement(attribute.getXmlName()); String content = resourceModel .get(attribute.getName()) .asString() .toLowerCase(Locale.ENGLISH); writer.writeAttribute("value", content); writer.writeEndElement(); } }
@Override public void marshallAsElement( AttributeDefinition attribute, ModelNode resourceModel, boolean marshallDefault, XMLStreamWriter writer) throws XMLStreamException { ModelNode properties = resourceModel.get(attribute.getName()); if (properties.isDefined()) { for (Property property : properties.asPropertyList()) { writer.writeStartElement( org.jboss.as.controller.parsing.Element.PROPERTY.getLocalName()); writer.writeAttribute( org.jboss.as.controller.parsing.Element.NAME.getLocalName(), property.getName()); writer.writeCharacters(property.getValue().asString()); writer.writeEndElement(); } } }
Element(final List<AttributeDefinition> definitions) { this.definition = null; this.definitions = new HashMap<String, AttributeDefinition>(); String ourName = null; for (AttributeDefinition def : definitions) { if (ourName == null) { ourName = def.getXmlName(); } else if (!ourName.equals(def.getXmlName())) { // TODO: throw correct exception // throw MESSAGES.attributeDefinitionsMustMatch(def.getXmlName(), // ourName); } if (this.definitions.put(def.getName(), def) != null) { // TODO: throw correct exception // throw MESSAGES.attributeDefinitionsNotUnique(def.getName()); } } this.name = ourName; }
@Override public void marshallAsElement( final AttributeDefinition attribute, final ModelNode resourceModel, final boolean marshallDefault, final XMLStreamWriter writer) throws XMLStreamException { if (isMarshallable(attribute, resourceModel, marshallDefault)) { writer.writeStartElement(attribute.getXmlName()); final ModelNode handlers = resourceModel.get(attribute.getName()); for (ModelNode handler : handlers.asList()) { if (handler.isDefined()) { writer.writeStartElement(CommonAttributes.HANDLER.getXmlName()); writer.writeAttribute(CommonAttributes.HANDLER_NAME.getXmlName(), handler.asString()); writer.writeEndElement(); } } writer.writeEndElement(); } }
private ModelNode resolveConfiguration(OperationContext context, ModelNode model) throws OperationFailedException { ModelNode res = new ModelNode(); ModelNode unresolvedContainer = model.get(Constants.CONTAINER); for (AttributeDefinition attr : WebContainerDefinition.CONTAINER_ATTRIBUTES) { res.get(Constants.CONTAINER) .get(attr.getName()) .set(attr.resolveModelAttribute(context, unresolvedContainer)); } ModelNode unresolvedStaticResources = model.get(Constants.STATIC_RESOURCES); for (SimpleAttributeDefinition attr : WebStaticResources.STATIC_ATTRIBUTES) { res.get(Constants.STATIC_RESOURCES) .get(attr.getName()) .set(attr.resolveModelAttribute(context, unresolvedStaticResources)); } ModelNode unresolvedJspConf = model.get(Constants.JSP_CONFIGURATION); for (SimpleAttributeDefinition attr : WebJSPDefinition.JSP_ATTRIBUTES) { res.get(Constants.JSP_CONFIGURATION) .get(attr.getName()) .set(attr.resolveModelAttribute(context, unresolvedJspConf)); } return res; }