@Override protected void convertAttribute(PathAddress address, String attributeName, ModelNode attributeValue, TransformationContext context) { if (!attributeValue.isDefined()) { // Workaround legacy slaves not accepting null/empty values // JBAS014704: '' is an invalid value for parameter excluded-contexts. Values must have a minimum length of 1 characters attributeValue.set(" "); } } }, Attribute.EXCLUDED_CONTEXTS.getDefinition())
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 protected void convertAttribute(PathAddress address, String attributeName, ModelNode attributeValue, TransformationContext context) { if (attributeValue.isDefined()) { List<ModelNode> remoteServers = attributeValue.clone().asList(); ModelNode legacyListObject = new ModelNode(); for (ModelNode server : remoteServers) { ModelNode legacyListItem = new ModelNode(); legacyListItem.get("outbound-socket-binding").set(server); legacyListObject.add(legacyListItem); } attributeValue.set(legacyListObject); } } }, Attribute.SOCKET_BINDINGS.getDefinition());
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(); }
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; }
private void addOpenjdkSubsystem(final PathAddress address, final ModelNode model, final Map<PathAddress, ModelNode> migrateOperations) { final ModelNode operation = Util.createAddOperation(address); for (final Property property : model.asPropertyList()) { if (property.getValue().isDefined()) { operation.get(property.getName()).set(property.getValue()); } } migrateOperations.put(address, operation); }
private LoadBalanceFactorProvider getLoadProvider(String proxyName, final Set<LoadMetric> metrics, final OperationContext context, ModelNode model) throws OperationFailedException { LoadBalanceFactorProvider load = null; if (model.get(SimpleLoadProviderResourceDefinition.PATH.getKeyValuePair()).isDefined()) { ModelNode simpleProviderModel = model.get(SimpleLoadProviderResourceDefinition.PATH.getKeyValuePair()); int value = SimpleLoadProviderResourceDefinition.Attribute.FACTOR.resolveModelAttribute(context, simpleProviderModel).asInt(); SimpleLoadBalanceFactorProvider simpleLoadProvider = new SimpleLoadBalanceFactorProvider(); load = simpleLoadProvider; if (model.get(DynamicLoadProviderResourceDefinition.PATH.getKeyValuePair()).isDefined()) { ModelNode node = model.get(DynamicLoadProviderResourceDefinition.PATH.getKeyValuePair()); int decayFactor = DynamicLoadProviderResourceDefinition.Attribute.DECAY.resolveModelAttribute(context, node).asInt(); int history = DynamicLoadProviderResourceDefinition.Attribute.HISTORY.resolveModelAttribute(context, node).asInt(); if (node.hasDefined(LoadMetricResourceDefinition.WILDCARD_PATH.getKey())) { this.addLoadMetrics(metrics, node.get(LoadMetricResourceDefinition.WILDCARD_PATH.getKey()), context); if (node.hasDefined(CustomLoadMetricResourceDefinition.WILDCARD_PATH.getKey())) { this.addLoadMetrics(metrics, node.get(CustomLoadMetricResourceDefinition.WILDCARD_PATH.getKey()), context);
public static void checkMapResults(KernelServices services, ModelNode expected, ModelVersion version, ModelNode operation) throws Exception { ModelNode main = ModelTestUtils.checkOutcome(services.executeOperation(operation.clone())).get(ModelDescriptionConstants.RESULT); ModelNode legacyResult = services.executeOperation(version, services.transformOperation(version, operation.clone())); ModelNode legacy; if (expected.isDefined()) { legacy = ModelTestUtils.checkOutcome(legacyResult).get(ModelDescriptionConstants.RESULT); } else { ModelTestUtils.checkFailed(legacyResult); legacy = new ModelNode(); } Assert.assertEquals(main, legacy); Assert.assertEquals(expected, legacy); }
@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())
public static Boolean getBooleanIfSetOrGetDefault(final OperationContext context, final ModelNode dataSourceNode, final SimpleAttributeDefinition key) throws OperationFailedException { ModelNode resolvedNode = key.resolveModelAttribute(context, dataSourceNode); return resolvedNode.isDefined() ? resolvedNode.asBoolean() : null; }
/** * @return contextual discard policy if any resource attributes are undefined and has no children; {@link DiscardPolicy#SILENT} otherwise. */ @Override public DiscardPolicy checkResource(TransformationContext context, PathAddress address) { Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS); ImmutableManagementResourceRegistration registration = context.getResourceRegistration(PathAddress.EMPTY_ADDRESS); ModelNode model = resource.getModel(); if (model.isDefined()) { for (String attribute : registration.getAttributeNames(PathAddress.EMPTY_ADDRESS)) { if (model.hasDefined(attribute)) { return this.policy; } } } for (PathElement path : registration.getChildAddresses(PathAddress.EMPTY_ADDRESS)) { if (path.isWildcard() ? resource.hasChildren(path.getKey()) : resource.hasChild(path)) { return this.policy; } } return DiscardPolicy.SILENT; } }
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(); } }
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; }
final String jndiName = JNDINAME.resolveModelAttribute(context, operation).asString(); final String raName = path.getParent().getLastElement().getValue(); final boolean statsEnabled = STATISTICS_ENABLED.resolveModelAttribute(context, raModel).asBoolean(); if (!raModel.hasDefined(ARCHIVE.getName()) && !raModel.hasDefined(MODULE.getName())) { throw ConnectorLogger.ROOT_LOGGER.archiveOrModuleRequired(); final boolean elytronEnabled = ELYTRON_ENABLED.resolveModelAttribute(context, resourceModel).asBoolean(); final boolean elytronRecoveryEnabled = RECOVERY_ELYTRON_ENABLED.resolveModelAttribute(context, resourceModel).asBoolean(); final ModelNode credentialReference = RECOVERY_CREDENTIAL_REFERENCE.resolveModelAttribute(context, resourceModel); if (resourceModel.hasDefined(AUTHENTICATION_CONTEXT.getName()) && !elytronEnabled) { throw SUBSYSTEM_RA_LOGGER.attributeRequiresTrueAttribute(AUTHENTICATION_CONTEXT.getName(), ELYTRON_ENABLED.getName()); throw SUBSYSTEM_RA_LOGGER.attributeRequiresFalseOrUndefinedAttribute(RECOVERY_SECURITY_DOMAIN.getName(), RECOVERY_ELYTRON_ENABLED.getName()); if (raModel.get(ARCHIVE.getName()).isDefined()) { archiveOrModuleName = ARCHIVE.resolveModelAttribute(context, raModel).asString(); } else { archiveOrModuleName = MODULE.resolveModelAttribute(context, raModel).asString(); if (credentialReference.isDefined()) { service.getCredentialSourceSupplier().inject( CredentialReference.getCredentialSourceSupplier(context, RECOVERY_CREDENTIAL_REFERENCE, resourceModel, cdServiceBuilder)); throw new OperationFailedException(e, new ModelNode().set(ConnectorLogger.ROOT_LOGGER.failedToCreate("ConnectionDefinition", 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(); }
public static List<GlobalModule> createModuleList(final OperationContext context, final ModelNode globalMods) throws OperationFailedException { final List<GlobalModule> ret = new ArrayList<>(); if (globalMods.isDefined()) { for (final ModelNode module : globalMods.asList()) { String name = NAME_AD.resolveModelAttribute(context, module).asString(); String slot = SLOT_AD.resolveModelAttribute(context, module).asString(); boolean annotations = ANNOTATIONS_AD.resolveModelAttribute(context, module).asBoolean(); boolean services = SERVICES_AD.resolveModelAttribute(context, module).asBoolean(); boolean metaInf = META_INF_AD.resolveModelAttribute(context, module).asBoolean(); ret.add(new GlobalModule(ModuleIdentifier.create(name, slot), annotations, services, metaInf)); } } return ret; }
public static void transformPropertiesToChildrenResources(ModelNode properties, PathAddress address, ResourceTransformationContext parentContext) { if (properties.isDefined()) { for (final Property property : properties.asPropertyList()) { String key = property.getName(); ModelNode value = property.getValue(); Resource propertyResource = Resource.Factory.create(); propertyResource.getModel().get(VALUE).set(value); PathAddress absoluteAddress = address.append(PROPERTY, key); parentContext.addTransformedResourceFromRoot(absoluteAddress, propertyResource); } } } }