public static Integer getIntIfSetOrGetDefault(final OperationContext context, final ModelNode dataSourceNode, final SimpleAttributeDefinition key) throws OperationFailedException { ModelNode resolvedNode = key.resolveModelAttribute(context, dataSourceNode); return resolvedNode.isDefined() ? resolvedNode.asInt() : null; }
public WebSocketInfo getConfig(final OperationContext context, final ModelNode model) throws OperationFailedException { if (!model.isDefined()) { return null; } boolean dispatchToWorker = DISPATCH_TO_WORKER.resolveModelAttribute(context, model).asBoolean(); String bufferPool = BUFFER_POOL.resolveModelAttribute(context, model).asString(); String worker = WORKER.resolveModelAttribute(context, model).asString(); boolean perMessageDeflate = PER_MESSAGE_DEFLATE.resolveModelAttribute(context, model).asBoolean(); int deflaterLevel = DEFLATER_LEVEL.resolveModelAttribute(context, model).asInt(); return new WebSocketInfo(worker, bufferPool, dispatchToWorker, perMessageDeflate, deflaterLevel); }
@Override public HttpHandler createHttpHandler(Predicate predicate, ModelNode model, HttpHandler next) { int code = model.get(CODE.getName()).asInt(); String path = model.get(PATH.getName()).asString(); FileErrorPageHandler handler = new FileErrorPageHandler(Paths.get(path), code); handler.setNext(next); if(predicate == null) { return handler; } else { return Handlers.predicate(predicate, handler, next); } }
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(); simpleLoadProvider.setLoadBalanceFactor(value); 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);
@Override protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode resolvedValue, ModelNode currentValue, HandbackHolder<AgroalConnectionPoolConfiguration> handbackHolder) throws OperationFailedException { ModelNode newBlockingTimeout = resolvedValue.remove(AbstractDataSourceDefinition.BLOCKING_TIMEOUT_MILLIS_ATTRIBUTE.getName()); ModelNode newMaxSize = resolvedValue.remove(AbstractDataSourceDefinition.MAX_SIZE_ATTRIBUTE.getName()); ModelNode newMinSize = resolvedValue.remove(AbstractDataSourceDefinition.MIN_SIZE_ATTRIBUTE.getName()); for (String attribute : resolvedValue.keys()) { if (!currentValue.hasDefined(attribute) || !resolvedValue.get(attribute).equals(currentValue.get(attribute))) { // Other attributes changed. Restart required return true; } } if (newBlockingTimeout != null) { getDataSource(context).getConfiguration().connectionPoolConfiguration().setAcquisitionTimeout(Duration.ofMillis(newBlockingTimeout.asInt())); } if (newMaxSize != null) { getDataSource(context).getConfiguration().connectionPoolConfiguration().setMaxSize(newMaxSize.asInt()); // if max-size decreases Agroal will gracefully destroy connections when they are returned to the pool, so there is nothing to do here } if (newMinSize != null) { getDataSource(context).getConfiguration().connectionPoolConfiguration().setMinSize(newMinSize.asInt()); // if min-size increases Agroal will create new connections when looking into the (shared) pool. FlushMode.FILL could be used here to enforce the new min-size } return false; }
.setAdvertise(ADVERTISE.resolveModelAttribute(context, model).asBoolean()) .setProxyURL(PROXY_URL.resolveModelAttribute(context, model).asString()) .setAutoEnableContexts(AUTO_ENABLE_CONTEXTS.resolveModelAttribute(context, model).asBoolean()) .setStopContextTimeout(STOP_CONTEXT_TIMEOUT.resolveModelAttribute(context, model).asInt()) .setStopContextTimeoutUnit(TimeUnit.valueOf(STOP_CONTEXT_TIMEOUT.getDefinition().getMeasurementUnit().getName())) .setSocketTimeout(SOCKET_TIMEOUT.resolveModelAttribute(context, model).asInt() * 1000) .setSessionDrainingStrategy(Enum.valueOf(SessionDrainingStrategyEnum.class, SESSION_DRAINING_STRATEGY.resolveModelAttribute(context, model).asString())) .setStickySession(STICKY_SESSION.resolveModelAttribute(context, model).asBoolean()) .setWorkerTimeout(WORKER_TIMEOUT.resolveModelAttribute(context, model).asInt()) .setMaxAttempts(MAX_ATTEMPTS.resolveModelAttribute(context, model).asInt()) .setFlushWait(FLUSH_WAIT.resolveModelAttribute(context, model).asInt()) .setPing(PING.resolveModelAttribute(context, model).asInt()) .setSmax(SMAX.resolveModelAttribute(context, model).asInt()) .setTtl(TTL.resolveModelAttribute(context, model).asInt()) .setNodeTimeout(NODE_TIMEOUT.resolveModelAttribute(context, model).asInt()) if (node.isDefined()) { if (node.isDefined()) { if (node.isDefined()) { if (model.get(SSLResourceDefinition.PATH.getKeyValuePair()).isDefined()) { ModelNode sslModel = model.get(SSLResourceDefinition.PATH.getKeyValuePair());
@Override public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException { this.passivation = PASSIVATION.resolveModelAttribute(context, model).asBoolean(); this.fetchState = FETCH_STATE.resolveModelAttribute(context, model).asBoolean(); this.preload = PRELOAD.resolveModelAttribute(context, model).asBoolean(); this.purge = PURGE.resolveModelAttribute(context, model).asBoolean(); this.shared = SHARED.resolveModelAttribute(context, model).asBoolean(); this.maxBatchSize = MAX_BATCH_SIZE.resolveModelAttribute(context, model).asInt(); this.properties.clear(); for (Property property : ModelNodes.optionalPropertyList(PROPERTIES.resolveModelAttribute(context, model)).orElse(Collections.emptyList())) { this.properties.setProperty(property.getName(), property.getValue().asString()); } return this; }
@Override public ModelNode execute(ExpressionResolver expressionResolver, ModelNode operation, ModClusterServiceMBean service) throws OperationFailedException { String host = HOST.resolveModelAttribute(expressionResolver, operation).asString(); int port = PORT.resolveModelAttribute(expressionResolver, operation).asInt(); service.addProxy(host, port); return null; } },
@Override public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException { this.backups.clear(); if (model.hasDefined(BackupResourceDefinition.WILDCARD_PATH.getKey())) { SitesConfigurationBuilder builder = new ConfigurationBuilder().sites(); for (Property property : model.get(BackupResourceDefinition.WILDCARD_PATH.getKey()).asPropertyList()) { String siteName = property.getName(); ModelNode backup = property.getValue(); BackupConfigurationBuilder backupBuilder = builder.addBackup(); backupBuilder.site(siteName) .enabled(ENABLED.resolveModelAttribute(context, backup).asBoolean()) .backupFailurePolicy(ModelNodes.asEnum(FAILURE_POLICY.resolveModelAttribute(context, backup), BackupFailurePolicy.class)) .replicationTimeout(TIMEOUT.resolveModelAttribute(context, backup).asLong()) .strategy(ModelNodes.asEnum(STRATEGY.resolveModelAttribute(context, backup), BackupStrategy.class)) .takeOffline() .afterFailures(AFTER_FAILURES.resolveModelAttribute(context, backup).asInt()) .minTimeToWait(MIN_WAIT.resolveModelAttribute(context, backup).asLong()) ; this.backups.put(siteName, backupBuilder.create()); } } return this; }
private void writeAuthenticationJaspi(XMLExtendedStreamWriter writer, ModelNode modelNode) throws XMLStreamException { if (modelNode.isDefined() && modelNode.asInt() > 0) { writer.writeStartElement(Element.AUTHENTICATION_JASPI.getLocalName()); ModelNode moduleStack = modelNode.get(LOGIN_MODULE_STACK); writeLoginModuleStack(writer, moduleStack); writeLoginModule(writer, modelNode, Constants.AUTH_MODULE, Element.AUTH_MODULE.getLocalName()); writer.writeEndElement(); } }
@Override protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { final ModelNode bufferSizeModel = BUFFER_SIZE.resolveModelAttribute(context, model); final ModelNode maxPoolSizeModel = MAX_POOL_SIZE.resolveModelAttribute(context, model); final ModelNode directModel = DIRECT.resolveModelAttribute(context, model); final int threadLocalCacheSize = THREAD_LOCAL_CACHE_SIZE.resolveModelAttribute(context, model).asInt(); final int leakDetectionPercent = LEAK_DETECTION_PERCENT.resolveModelAttribute(context, model).asInt(); final int bufferSize = bufferSizeModel.asInt(defaultBufferSize); final int maxPoolSize = maxPoolSizeModel.asInt(-1); final boolean direct = directModel.asBoolean(defaultDirectBuffers); final ByteBufferPoolService service = new ByteBufferPoolService(direct, bufferSize, maxPoolSize, threadLocalCacheSize, leakDetectionPercent); context.getCapabilityServiceTarget().addCapability(UNDERTOW_BUFFER_POOL_RUNTIME_CAPABILITY, service) .setInitialMode(ServiceController.Mode.ACTIVE) .install(); } }
@Override protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR)); final String name = address.getLastElement().getValue(); int bufferSize = BufferCacheDefinition.BUFFER_SIZE.resolveModelAttribute(context, model).asInt(); int buffersPerRegions = BufferCacheDefinition.BUFFERS_PER_REGION.resolveModelAttribute(context, model).asInt(); int maxRegions = BufferCacheDefinition.MAX_REGIONS.resolveModelAttribute(context, model).asInt(); final BufferCacheService service = new BufferCacheService(bufferSize, buffersPerRegions, maxRegions); final ServiceTarget target = context.getServiceTarget(); target.addService(BufferCacheService.SERVICE_NAME.append(name), service) .setInitialMode(ServiceController.Mode.ON_DEMAND) .install(); } }
@Override protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { super.performRuntime(context, operation, model); String name = context.getCurrentAddressValue(); int ordinal = ORDINAL.resolveModelAttribute(context, model).asInt(); ModelNode props = PROPERTIES.resolveModelAttribute(context, model); ModelNode classModel = CLASS.resolveModelAttribute(context, model); ModelNode dirModel = DIR.resolveModelAttribute(context, model); final ConfigSource configSource; if (classModel.isDefined()) { Class configSourceClass = unwrapClass(classModel); try { configSource = ConfigSource.class.cast(configSourceClass.newInstance()); MicroProfileConfigLogger.ROOT_LOGGER.loadConfigSourceFromClass(configSourceClass); ConfigSourceService.install(context, name, configSource); } catch (Exception e) { throw new OperationFailedException(e); } } else if (dirModel.isDefined()) { String path = PATH.resolveModelAttribute(context, dirModel).asString(); String relativeTo = RELATIVE_TO.resolveModelAttribute(context, dirModel).asStringOrNull(); DirConfigSourceService.install(context, name, path, relativeTo, ordinal); } else { Map<String, String> properties = PropertiesAttributeDefinition.unwrapModel(context, props); configSource = new PropertiesConfigSource(properties, name, ordinal); ConfigSourceService.install(context, name, configSource); } } }, new AbstractRemoveStepHandler() {
private void updatePoolConfigs(List<PoolConfiguration> poolConfigs, String parameterName, ModelNode newValue) { for (PoolConfiguration pc : poolConfigs) { if (MAX_POOL_SIZE.getName().equals(parameterName)) { pc.setMaxSize(newValue.asInt()); } if (MIN_POOL_SIZE.getName().equals(parameterName)) { pc.setMinSize(newValue.asInt()); } if (INITIAL_POOL_SIZE.getName().equals(parameterName)) { pc.setInitialSize(newValue.isDefined()? newValue.asInt(): 0); } if (BLOCKING_TIMEOUT_WAIT_MILLIS.getName().equals(parameterName)) { pc.setBlockingTimeout(newValue.isDefined()? newValue.asLong(): 0); } if (POOL_USE_STRICT_MIN.getName().equals(parameterName)) { pc.setStrictMin(newValue.asBoolean()); } if (USE_FAST_FAIL.getName().equals(parameterName)) { pc.setUseFastFail(newValue.asBoolean()); } if (VALIDATE_ON_MATCH.getName().equals(parameterName)) { pc.setValidateOnMatch(newValue.asBoolean()); } if (POOL_FAIR.getName().equals(parameterName)) { pc.setFair(newValue.asBoolean()); } } }
@Override public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException { for (ColumnAttribute column : EnumSet.allOf(ColumnAttribute.class)) { ModelNode columnModel = column.resolveModelAttribute(context, model); String name = column.getColumnName().resolveModelAttribute(context, columnModel).asString(); String type = column.getColumnType().resolveModelAttribute(context, columnModel).asString(); this.columns.put(column, new AbstractMap.SimpleImmutableEntry<>(name, type)); } this.fetchSize = FETCH_SIZE.resolveModelAttribute(context, model).asInt(); this.prefix = this.prefixAttribute.resolveModelAttribute(context, model).asString(); return this; }
@Override public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException { this.timeout = ACQUIRE_TIMEOUT.resolveModelAttribute(context, model).asLong(); this.concurrency = CONCURRENCY.resolveModelAttribute(context, model).asInt(); this.isolation = ModelNodes.asEnum(ISOLATION.resolveModelAttribute(context, model), IsolationLevel.class); this.striping = STRIPING.resolveModelAttribute(context, model).asBoolean(); return this; } }
@Override public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException { String containerName = CACHE_CONTAINER.resolveModelAttribute(context, model).asString(); String cacheName = CACHE.resolveModelAttribute(context, model).asStringOrNull(); this.factory = new ServiceSupplierDependency<>(ClusteringCacheRequirement.SINGLETON_SERVICE_BUILDER_FACTORY.getServiceName(context, containerName, cacheName)); this.quorum = QUORUM.resolveModelAttribute(context, model).asInt(); return this; }
protected void executeWriteAttribute(String attributeName, OperationContext context, ModelNode operation, T component, PathAddress address) throws OperationFailedException { if (componentType.hasPool() && POOL_MAX_SIZE.getName().equals(attributeName)) { int newSize = POOL_MAX_SIZE.resolveValue(context, operation.get(VALUE)).asInt(); final Pool<?> pool = componentType.getPool(component); final int oldSize = pool.getMaxSize(); componentType.getPool(component).setMaxSize(newSize); context.completeStep(new OperationContext.RollbackHandler() { @Override public void handleRollback(OperationContext context, ModelNode operation) { pool.setMaxSize(oldSize); } }); } else { // Bug; we were registered for an attribute but there is no code for handling it throw EjbLogger.ROOT_LOGGER.unknownAttribute(attributeName); } }
@Override public ModelNode execute(ExpressionResolver expressionResolver, ModelNode operation, ModClusterServiceMBean service) throws OperationFailedException { int waitTime = WAIT_TIME.resolveModelAttribute(expressionResolver, operation).asInt(); boolean success = service.stop(waitTime, TimeUnit.SECONDS); return new ModelNode(success); } },