private Integer intAttribute( OperationContext context, ModelNode model, AttributeDefinition defn, Integer defaultValue) throws OperationFailedException { ModelNode value = defn.resolveModelAttribute(context, model); if (value == null || !value.isDefined()) return defaultValue; return value.asInt(); }
void updatePoolService(final OperationContext context, final ModelNode model) throws OperationFailedException { final ModelNode poolName = poolAttribute.resolveModelAttribute(context, model); final ServiceRegistry serviceRegistry = context.getServiceRegistry(true); ServiceController existingDefaultPoolConfigService = serviceRegistry.getService(poolConfigServiceName); // if a default MDB pool is already installed, then remove it first if (existingDefaultPoolConfigService != null) { context.removeService(existingDefaultPoolConfigService); } if (poolName.isDefined()) { // now install default pool config service which points to an existing pool config service final ValueInjectionService<PoolConfig> newDefaultPoolConfigService = new ValueInjectionService<PoolConfig>(); ServiceController<?> newController = context .getServiceTarget() .addService(poolConfigServiceName, newDefaultPoolConfigService) .addDependency( PoolConfigService.EJB_POOL_CONFIG_BASE_SERVICE_NAME.append(poolName.asString()), PoolConfig.class, newDefaultPoolConfigService.getInjector()) .install(); } }
// 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; }
/** * 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; }
private String getColumnProperty( OperationContext context, ModelNode table, String columnKey, AttributeDefinition columnAttribute, String defaultValue) throws OperationFailedException { if (!table.isDefined() || !table.hasDefined(columnKey)) return defaultValue; ModelNode column = table.get(columnKey); ModelNode resolvedValue = null; return ((resolvedValue = columnAttribute.resolveModelAttribute(context, column)).isDefined()) ? resolvedValue.asString() : defaultValue; }
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; }
@Override protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException { final PathAddress address = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)); final Resource web = context.readResourceFromRoot(address.subAddress(0, address.size()), false); final ModelNode subModel = web.getModel(); final String host = VIRTUAL_HOST.resolveModelAttribute(context, subModel).asString(); final String path = CONTEXT_ROOT.resolveModelAttribute(context, subModel).asString(); final String server = SERVER.resolveModelAttribute(context, subModel).asString(); final ServiceController<?> controller = context .getServiceRegistry(false) .getService(UndertowService.deploymentServiceName(server, host, path)); SessionStat stat = SessionStat.getStat(operation.require(ModelDescriptionConstants.NAME).asString()); if (stat == null) { context .getFailureDescription() .set( UndertowMessages.MESSAGES.unknownMetric( operation.require(ModelDescriptionConstants.NAME).asString())); } else { context.getResult().set("<not implemented>"); /*final Context webContext = Context.class.cast(controller.getValue()); ManagerBase sm = (ManagerBase) webContext.getManager(); ModelNode result = new ModelNode(); switch (stat) { case ACTIVE_SESSIONS: result.set(sm.getActiveSessions()); break; case EXPIRED_SESSIONS: result.set(sm.getExpiredSessions()); break; case MAX_ACTIVE_SESSIONS: result.set(sm.getMaxActive()); break; case SESSIONS_CREATED: result.set(sm.getSessionCounter()); break; case DUPLICATED_SESSION_IDS: result.set(sm.getDuplicates()); break; case SESSION_AVG_ALIVE_TIME: result.set(sm.getSessionAverageAliveTime()); break; case SESSION_MAX_ALIVE_TIME: result.set(sm.getSessionMaxAliveTime()); break; case REJECTED_SESSIONS: result.set(sm.getRejectedSessions()); break; default: throw new IllegalStateException(WebMessages.MESSAGES.unknownMetric(stat)); } context.getResult().set(result);*/ } context.stepCompleted(); }
private String attribute( OperationContext context, ModelNode model, AttributeDefinition defn, String defaultValue) throws OperationFailedException { ModelNode value = defn.resolveModelAttribute(context, model); return value.isDefined() ? value.asString() : defaultValue; }
private ModelNode attribute(OperationContext context, ModelNode model, AttributeDefinition defn) throws OperationFailedException { assert defn.getDefaultValue() != null && defn.getDefaultValue().isDefined(); return defn.resolveModelAttribute(context, model); }