@Override protected void convertAttribute(PathAddress address, String attributeName, ModelNode attributeValue, TransformationContext context) { if (attributeValue.isDefined() && attributeValue.getType() != EXPRESSION) { attributeValue.set((int) Math.ceil(attributeValue.asDouble())); } } }, Attribute.DECAY.getDefinition())
@Override public ModelNode correct(ModelNode newValue, ModelNode currentValue) { if (newValue.isDefined() && newValue.getType() != ModelType.EXPRESSION) { try { long val = newValue.asLong(); if (val == 0) { return new ModelNode(-1); } } catch (Exception e) { // not convertible; let the validator that the caller will invoke later deal with this } } return newValue; } }
@Override public void validateParameter(String parameterName, ModelNode value) throws OperationFailedException { if (value.getType() != ModelType.EXPRESSION) { String str = value.asString(); if (!str.startsWith("java:/") && !str.startsWith("java:jboss/")) { throw AgroalLogger.SERVICE_LOGGER.jndiNameInvalidFormat(); } else if (str.endsWith("/") || str.contains("//")) { throw AgroalLogger.SERVICE_LOGGER.jndiNameShouldValidate(); } } } })
@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))); } };
protected Map<String, String> getEnvMap(String key) { Map<String, String> values = new HashMap<String, String>(); ModelNode source = node.get(getPath(key)); if (source.getType() == ModelType.LIST) { for (ModelNode value : source.asList()) { values.put(value.get("name").asString(), value.get("value").asString()); } } return values; }
@Override public void validateParameter(String parameterName, ModelNode value) throws OperationFailedException { super.validateParameter(parameterName, value); if (value.isDefined() && value.getType() != ModelType.EXPRESSION) { if (!this.allowedChannelOptTypes.contains(value)) { throw EjbLogger.ROOT_LOGGER.unknownChannelCreationOptionType(value.asString()); } } } }
@Override public ModelNode correct(final ModelNode newValue, final ModelNode currentValue) { if (newValue.getType() == ModelType.UNDEFINED) { return newValue; } if (newValue.getType() != ModelType.STRING || currentValue.getType() != ModelType.STRING) { return newValue; } final String stringValue = newValue.asString(); final String uCase = stringValue.toUpperCase(Locale.ENGLISH); if (!stringValue.equals(uCase)) { newValue.set(uCase); } return newValue; } };
@Override public void handleResult(OperationContext.ResultAction resultAction, OperationContext context, ModelNode operation) { ModelNode result = context.getResult(); if (result.getType() == ModelType.LIST) { List<ModelNode> list = result.asList(); if (list.size() == 1) { ModelNode entry = list.get(0); context.getResult().set(entry.get(RESULT)); } } } });
@Override public void validateParameter(String parameterName, ModelNode parameterValue) throws OperationFailedException { super.validateParameter(parameterName, parameterValue); if (parameterValue.isDefined() && parameterValue.getType() != ModelType.EXPRESSION) { double value = parameterValue.asDouble(); if (this.lowerBound != null) { double bound = this.lowerBound.getValue(); boolean exclusive = this.lowerBound.isExclusive(); if ((value < bound) || (exclusive && (value == bound))) { throw ClusteringLogger.ROOT_LOGGER.parameterValueOutOfBounds(parameterName, value, exclusive ? ">" : ">=", bound); } } if (this.upperBound != null) { double bound = this.upperBound.getValue(); boolean exclusive = this.upperBound.isExclusive(); if ((value > bound) || (exclusive && (value == bound))) { throw ClusteringLogger.ROOT_LOGGER.parameterValueOutOfBounds(parameterName, value, exclusive ? "<" : "<=", bound); } } } } }
@Override public boolean isMarshallable(AttributeDefinition attribute, ModelNode resourceModel) { // Unfortunately, the xsd says default is true while the mgmt API default is false. // So, only marshal if the value != 'true' return !resourceModel.has(attribute.getName()) || resourceModel.get(attribute.getName()).getType() != ModelType.BOOLEAN || !resourceModel.get(attribute.getName()).asBoolean(); }
@Override public void onSuccess(ModelNode outcome, ModelNode result) throws AdminProcessingException { if (result.getType().equals(ModelType.LIST)) { buildPropertyDefinitions(result.asList()); } else if (result.get("attributes").isDefined()) { buildPropertyDefinitions(result.get("attributes").asList()); } }
public static ModelNode parseBoundedIntegerAttribute(final XMLExtendedStreamReader reader, final int index, final int minInclusive, final int maxInclusive, boolean allowExpression) throws XMLStreamException { final String stringValue = reader.getAttributeValue(index); if (allowExpression) { ModelNode expression = parsePossibleExpression(stringValue); if (expression.getType() == ModelType.EXPRESSION) { return expression; } } try { final int value = Integer.parseInt(stringValue); if (value < minInclusive || value > maxInclusive) { throw ControllerLogger.ROOT_LOGGER.invalidAttributeValue(value, reader.getAttributeName(index), minInclusive, maxInclusive, reader.getLocation()); } return new ModelNode().set(value); } catch (NumberFormatException nfe) { throw ControllerLogger.ROOT_LOGGER.invalidAttributeValueInt(nfe, stringValue, reader.getAttributeName(index), reader.getLocation()); } }
static ModelNode transformModel(final ModelNode legacyModel) { final ModelNode model = new ModelNode(); for (Property property : legacyModel.asPropertyList()) { String name = property.getName(); ModelNode legacyValue = property.getValue(); if (legacyValue.isDefined()) { if(name.equals(JacORBSubsystemConstants.IOR_SETTINGS)){ transformIorSettings(model, legacyValue); if(legacyValue.getType()==ModelType.EXPRESSION){ expression = true; final Matcher matcher = Pattern.compile("\\A\\$\\{(.*):(.*)\\}\\Z").matcher(legacyValue.asExpression().getExpressionString()); expressionVariable = matcher.group(1); String abc = matcher.group(2); legacyValue = new ModelNode(abc); } else { model.get(name).set(legacyValue); continue; model.get(name).set(value); if(!legacyModel.get(JacORBSubsystemConstants.ORB_SOCKET_BINDING).isDefined()){ model.get(JacORBSubsystemConstants.ORB_SOCKET_BINDING).set(JacORBSubsystemDefinitions.ORB_SOCKET_BINDING.getDefaultValue());
@Override public Collection<String> getImages() { ModelNode node = get(SPEC_TEMPLATE_CONTAINERS); if (node.getType() != ModelType.LIST) { return new ArrayList<>(); } Collection<String> list = new ArrayList<>(); for (ModelNode entry : node.asList()) { list.add(entry.get(IMAGE).asString()); } return list; }
@Override public void validateParameter(String parameterName, ModelNode value) throws OperationFailedException { if (value.isDefined()) { if (value.getType() != ModelType.EXPRESSION) { String str = value.asString(); if (!str.startsWith("java:/") && !str.startsWith("java:jboss/")) { throw ConnectorLogger.ROOT_LOGGER.jndiNameInvalidFormat(); } else if (str.endsWith("/") || str.indexOf("//") != -1) { throw ConnectorLogger.ROOT_LOGGER.jndiNameShouldValidate(); } } } else { throw ConnectorLogger.ROOT_LOGGER.jndiNameRequired(); } }
@Override public ModelNode correct(final ModelNode newValue, final ModelNode currentValue) { if (newValue.getType() == ModelType.UNDEFINED) { return newValue; } if (newValue.getType() != ModelType.STRING || currentValue.getType() != ModelType.STRING) { return newValue; } final String stringValue = newValue.asString(); final String uCase = stringValue.toUpperCase(Locale.ENGLISH); if (!stringValue.equals(uCase)) { newValue.set(uCase); } return newValue; } };
@Override public void handleResult(OperationContext.ResultAction resultAction, OperationContext context, ModelNode operation) { ModelNode result = context.getResult(); if (result.getType() == ModelType.LIST) { List<ModelNode> list = result.asList(); if (list.size() == 1) { ModelNode entry = list.get(0); context.getResult().set(entry.get(RESULT)); } } } });
@Override public ModelNode correct(ModelNode newValue, ModelNode currentValue) { if (newValue.isDefined() && newValue.getType() != ModelType.EXPRESSION) { try { if (newValue.asLong() < -1) { return new ModelNode(-1); } } catch (Exception e) { // not convertible; let the validator that the caller will invoke later deal with this } } return newValue; } };