static String getAuthenticationCacheType(ModelNode node) { String type = null; if (node.hasDefined(CACHE_TYPE)) { type = node.get(CACHE_TYPE).asString(); } return type; } }
static String asStringIfDefined(OperationContext context, SimpleAttributeDefinition attributeDefinition, ModelNode model) throws OperationFailedException { ModelNode value = attributeDefinition.resolveModelAttribute(context, model); if (value.isDefined()) { return value.asString(); } return null; } }
@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)
@Override public TransformedOperation transformOperation(TransformationContext context, PathAddress address, ModelNode operation) { if (operation != null && !(operation.hasDefined(OPERATION_HEADERS) && operation.get(OPERATION_HEADERS, "push-to-servers").asBoolean(false)) ){ operation = operation.clone(); String statefulCache = operation.get(DEFAULT_SFSB_CACHE).asString(); String statefulPassivationDisabledCache = operation.get(DEFAULT_SFSB_PASSIVATION_DISABLED_CACHE).asString(); operation.get(DEFAULT_SFSB_CACHE).set(statefulPassivationDisabledCache); operation.get(EJB3SubsystemModel.DEFAULT_CLUSTERED_SFSB_CACHE).set(statefulCache); operation.remove(DEFAULT_SFSB_PASSIVATION_DISABLED_CACHE); } return new TransformedOperation(operation, OperationResultTransformer.ORIGINAL_RESULT); } }
final String archiveOrModuleName; ModelNode raModel = context.readResourceFromRoot(path.subAddress(0, path.size() - 1), false).getModel(); final boolean statsEnabled = STATISTICS_ENABLED.resolveModelAttribute(context, raModel).asBoolean(); if (!raModel.hasDefined(ARCHIVE.getName()) && !raModel.hasDefined(MODULE.getName())) { throw ConnectorLogger.ROOT_LOGGER.archiveOrModuleRequired(); if (raModel.get(ARCHIVE.getName()).isDefined()) { archiveOrModuleName = ARCHIVE.resolveModelAttribute(context, raModel).asString(); } else { archiveOrModuleName = MODULE.resolveModelAttribute(context, raModel).asString(); adminObjectValue = RaOperationUtil.buildAdminObjects(context, operation, poolName); } catch (ValidateException e) { throw new OperationFailedException(e, new ModelNode().set(ConnectorLogger.ROOT_LOGGER.failedToCreate("AdminObject", operation, e.getLocalizedMessage())));
@Override public boolean rejectOperationParameter(PathAddress address, String attributeName, ModelNode attributeValue, ModelNode operation, TransformationContext context) { return operation.get(ModelDescriptionConstants.OP).asString().equals(ModelDescriptionConstants.ADD) && !attributeValue.isDefined(); }
@Override public ModelNode transformOperation(ModelNode operation) { if (operation.get(NAME).asString().equals(PROPERTIES)) { String key = operation.get("key").asString(); PathAddress address = Operations.getPathAddress(operation); ModelNode transformedOperation = Util.createOperation(READ_ATTRIBUTE_OPERATION, address.append(PathElement.pathElement(PROPERTY, key))); transformedOperation.get(NAME).set(VALUE); return transformedOperation; } return operation; } }
@Override public ModelNode transformOperation(ModelNode operation) { ModelNode mode = Operations.getAttributeValue(operation); boolean batching = (mode.isDefined() && (mode.getType() == ModelType.STRING)) ? (TransactionMode.valueOf(mode.asString()) == TransactionMode.BATCH) : false; if (batching) { mode.set(TransactionMode.NONE.name()); } PathAddress address = Operations.getPathAddress(operation); return Operations.createCompositeOperation(operation, Operations.createWriteAttributeOperation(cacheAddress(address), CacheResourceDefinition.DeprecatedAttribute.BATCHING, new ModelNode(batching))); } };
@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(); } }
public static List<StaticEjbDiscovery> createStaticEjbList(final OperationContext context, final ModelNode ejbList) throws OperationFailedException { final List<StaticEjbDiscovery> ret = new ArrayList<>(); if (ejbList.isDefined()) { for (final ModelNode disc : ejbList.asList()) { ModelNode app = APP_AD.resolveModelAttribute(context, disc); String module = MODULE_AD.resolveModelAttribute(context, disc).asString(); ModelNode distinct = DISTINCT_AD.resolveModelAttribute(context, disc); String url = URI_AD.resolveModelAttribute(context, disc).asString(); ret.add(new StaticEjbDiscovery(app.isDefined() ? app.asString() : null, module, distinct.isDefined() ? distinct.asString() : null, url)); } } return ret; }
@Override public AttributeValueTranslator getWriteTranslator() { return (context, value) -> { String jndiName = value.asString(); PathAddress address = context.getCurrentAddress(); PathAddress rootAddress = address.subAddress(0, address.size() - 4); PathAddress subsystemAddress = rootAddress.append(PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, "datasources")); Resource subsystem = context.readResourceFromRoot(subsystemAddress); for (String type : Arrays.asList("data-source", "xa-data-source")) { if (subsystem.hasChildren(type)) { for (Resource.ResourceEntry entry : subsystem.getChildren(type)) { ModelNode model = entry.getModel(); if (model.get("jndi-name").asString().equals(jndiName)) { return new ModelNode(entry.getName()); } } } } throw InfinispanLogger.ROOT_LOGGER.dataSourceJndiNameNotFound(jndiName); }; } };
private static String extractCode(OperationContext context, ModelNode node, Map<String, String> substitutions) throws OperationFailedException { String code = LoginModuleResourceDefinition.CODE.resolveModelAttribute(context, node).asString(); if (substitutions.containsKey(code)) { code = substitutions.get(code); } return code; }
@Override public ModelNode execute(ExpressionResolver expressionResolver, ModelNode operation, ModClusterServiceMBean service) throws OperationFailedException { String virtualHost = VIRTUAL_HOST.resolveModelAttribute(expressionResolver, operation).asString(); String webContext = CONTEXT.resolveModelAttribute(expressionResolver, operation).asString(); try { boolean enabled = service.enableContext(virtualHost, webContext); return new ModelNode(enabled); } catch (IllegalArgumentException e) { throw new OperationFailedException(ModClusterLogger.ROOT_LOGGER.contextOrHostNotFound(virtualHost, webContext)); } } },
@Override protected void finishModelStage(final OperationContext context, final ModelNode operation, final String attributeName, final ModelNode newValue, ModelNode oldValue, Resource model) throws OperationFailedException { // Make sure that security=on becomes security=identity if (attributeName.equals(JacORBSubsystemConstants.ORB_INIT_SECURITY) && newValue.asString().equals(JacORBSubsystemConstants.ON)) { newValue.set(JacORBSubsystemConstants.IDENTITY); } super.finishModelStage(context, operation, attributeName, newValue, oldValue, model); } }
static Properties resolvePropertyValue(final OperationContext context, final ModelNode operation, final AttributeDefinition attribute) throws OperationFailedException { // Get the properties final Properties properties = new Properties(); if (operation.hasDefined(attribute.getName())) { for (Property p : resolveValue(context, operation, attribute).asPropertyList()) { properties.put(p.getName(), p.getValue().asString()); } } return properties; }
private void populateModelWithObjectStoreConfig(ModelNode operation, ModelNode objectStoreModel) throws OperationFailedException { TransactionSubsystemRootResourceDefinition.OBJECT_STORE_RELATIVE_TO.validateAndSet(operation, objectStoreModel); TransactionSubsystemRootResourceDefinition.OBJECT_STORE_PATH.validateAndSet(operation, objectStoreModel); ModelNode relativeVal = objectStoreModel.get(TransactionSubsystemRootResourceDefinition.OBJECT_STORE_RELATIVE_TO.getName()); ModelNode pathVal = objectStoreModel.get(TransactionSubsystemRootResourceDefinition.OBJECT_STORE_PATH.getName()); if (!relativeVal.isDefined() && (!pathVal.isDefined() || pathVal.asString().equals(TransactionSubsystemRootResourceDefinition.OBJECT_STORE_PATH.getDefaultValue().asString()))) { relativeVal.set(new ModelNode().set("jboss.server.data.dir")); TransactionLogger.ROOT_LOGGER.objectStoreRelativeToIsSetToDefault(); } }
@Override public void marshallAsAttribute(AttributeDefinition attribute, ModelNode resourceModel, boolean marshallDefault, XMLStreamWriter writer) throws XMLStreamException { if (attribute.isMarshallable(resourceModel, marshallDefault)) { resourceModel = resourceModel.get(attribute.getName()); if (resourceModel.hasDefined(Constants.ALGORITHM)) { writer.writeAttribute(attribute.getName() + "-factory-" + Constants.ALGORITHM, resourceModel.get(Constants.ALGORITHM).asString()); } if (resourceModel.hasDefined(Constants.PROVIDER)) { writer.writeAttribute(attribute.getName() + "-factory-" + Constants.PROVIDER, resourceModel.get(Constants.PROVIDER).asString()); } } } }
public static String getResolvedStringIfSetOrGetDefault(final OperationContext context, final ModelNode dataSourceNode, final SimpleAttributeDefinition key) throws OperationFailedException { ModelNode resolvedNode = key.resolveModelAttribute(context, dataSourceNode); String resolvedString = resolvedNode.isDefined() ? resolvedNode.asString() : null; if (resolvedString != null && resolvedString.trim().length() == 0) { resolvedString = null; } return resolvedString; }
@Override public boolean rejectOperationParameter(PathAddress address, String attributeName, ModelNode attributeValue, ModelNode operation, TransformationContext context) { return operation.get(ModelDescriptionConstants.OP).asString().equals(ModelDescriptionConstants.ADD) && !attributeValue.isDefined(); }
@Override public void transformResource(ResourceTransformationContext context, PathAddress address, Resource resource) throws OperationFailedException { Resource untransformedResource = context.readResource(PathAddress.EMPTY_ADDRESS); ModelNode untransformedModel = Resource.Tools.readModel(untransformedResource); String statefulCache = untransformedModel.get(DEFAULT_SFSB_CACHE).asString(); String statefulPassivationDisabledCache = untransformedModel.get(DEFAULT_SFSB_PASSIVATION_DISABLED_CACHE).asString(); ModelNode transformed = resource.getModel(); transformed.get(DEFAULT_SFSB_CACHE).set(statefulPassivationDisabledCache); transformed.get(EJB3SubsystemModel.DEFAULT_CLUSTERED_SFSB_CACHE).set(statefulCache); transformed.remove(DEFAULT_SFSB_PASSIVATION_DISABLED_CACHE); final ResourceTransformationContext childContext = context.addTransformedResource(PathAddress.EMPTY_ADDRESS, resource); childContext.processChildren(resource); } }