static MBeanServer getMBeanServer(OperationContext context) { final ServiceRegistry serviceRegistry = context.getServiceRegistry(false); final ServiceController<?> serviceController = serviceRegistry.getService(MBEAN_SERVER_SERVICE_NAME); if (serviceController == null) { throw TransactionLogger.ROOT_LOGGER.jmxSubsystemNotInstalled(); } return (MBeanServer) serviceController.getValue(); }
@Override public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException { ModelNode result = new ModelNode(); CachedConnectionManager ccm = (CachedConnectionManager) context.getServiceRegistry(false).getService(ConnectorServices.CCM_SERVICE).getValue(); ModelNode txResult = new ModelNode().set(ccm.getNumberOfConnections()); ccm = (CachedConnectionManager) context.getServiceRegistry(false).getService(ConnectorServices.NON_TX_CCM_SERVICE).getValue(); ModelNode nonTxResult = new ModelNode().set(ccm.getNumberOfConnections()); result.get(Constants.TX).set(txResult); result.get(Constants.NON_TX).set(nonTxResult); context.getResult().set(result); } }, OperationContext.Stage.RUNTIME);
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { final String driverName = model.get(DRIVER_NAME.getName()).asString(); final ServiceRegistry registry = context.getServiceRegistry(true); ServiceName jdbcServiceName = ServiceName.JBOSS.append("jdbc-driver", driverName.replaceAll("\\.", "_")); ServiceController<?> jdbcServiceController = registry.getService(jdbcServiceName); context.removeService(jdbcServiceController); }
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR)); final String jndiName = address.getLastElement().getValue(); final String attributeName = operation.require(NAME).asString(); final ServiceController<?> managementRepoService = context.getServiceRegistry(false).getService( ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE); if (managementRepoService != null) { try { final ManagementRepository repository = (ManagementRepository) managementRepoService.getValue(); final ModelNode result = context.getResult(); List<StatisticsPlugin> stats = getMatchingStats(jndiName, repository); for (StatisticsPlugin stat : stats) { result.set("" + stat.getValue(attributeName)); } } catch (Exception e) { throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToGetMetrics(e.getLocalizedMessage())); } } } }, OperationContext.Stage.RUNTIME);
@Override protected void executeRuntimeStep(final OperationContext context, final ModelNode operation) throws OperationFailedException { final String poolName = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue(); final ServiceName serviceName = StrictMaxPoolConfigService.EJB_POOL_CONFIG_BASE_SERVICE_NAME.append(poolName); final ServiceRegistry registry = context.getServiceRegistry(true); ServiceController<?> sc = registry.getService(serviceName); if (sc != null) { StrictMaxPoolConfigService smpc = (StrictMaxPoolConfigService) sc.getService(); if (smpc != null) { context.getResult().set(smpc.getDerivedSize()); return; } } throw EjbLogger.ROOT_LOGGER.cannotReadStrictMaxPoolDerivedSize(serviceName); } }
private void applyModelToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode model) throws OperationFailedException { String name = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue(); ServiceRegistry registry = context.getServiceRegistry(true); EJBSuspendHandlerService service = (EJBSuspendHandlerService) registry.getRequiredService(EJBSuspendHandlerService.SERVICE_NAME).getValue(); if (service!= null && this.gracefulTxnShutdownAttribute.getName().equals(attributeName)) { boolean enableGracefulTxnShutdown = this.gracefulTxnShutdownAttribute.resolveModelAttribute(context, model) .asBoolean(); service.enableGracefulTxnShutdown(enableGracefulTxnShutdown); } }
@Override public ModelNode execute(OperationContext context, Metric<Cache<?, ?>> metric) throws OperationFailedException { PathAddress address = context.getCurrentAddress(); String containerName = address.getParent().getLastElement().getValue(); String cacheName = address.getLastElement().getValue(); Cache<?, ?> cache = new PassiveServiceSupplier<Cache<?, ?>>(context.getServiceRegistry(true), InfinispanCacheRequirement.CACHE.getServiceName(context, containerName, cacheName)).get(); return (cache != null) ? metric.execute(cache) : null; } }
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { ServiceRegistry registry = context.getServiceRegistry(false); JdrReportCollector jdrCollector = JdrReportCollector.class.cast(registry.getRequiredService(JdrReportService.SERVICE_NAME).getValue()); ModelNode response = context.getResult(); JdrReport report = jdrCollector.collect(); if (report.getStartTime() != null) { response.get("start-time").set(report.getStartTime()); } if (report.getEndTime() != null) { response.get("end-time").set(report.getEndTime()); } response.get("report-location").set(report.getLocation()); context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER); } }, OperationContext.Stage.RUNTIME);
@Override protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode resolvedValue, ModelNode currentValue, HandbackHolder<Void> handbackHolder) throws OperationFailedException { ServiceController<?> controller = context.getServiceRegistry(false).getService(UndertowService.UNDERTOW); if (controller != null) { UndertowService service = (UndertowService) controller.getService(); if (service != null) { service.setStatisticsEnabled(resolvedValue.asBoolean()); } } return false; }
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final String attributeName = operation.require(NAME).asString(); final ServiceController<?> managementRepoService = context.getServiceRegistry(false).getService( ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE); if (managementRepoService != null) { try { setModelValue(context.getResult(), attributeName); } catch (Exception e) { throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToGetMetrics(e.getLocalizedMessage())); } } } }, OperationContext.Stage.RUNTIME);
private static AgroalDataSource getDataSource(OperationContext context) throws OperationFailedException { ServiceRegistry registry = context.getServiceRegistry(false); String dataSourceName = context.getCurrentAddressValue(); switch (context.getCurrentAddress().getLastElement().getKey()) { case DataSourceOperations.DATASOURCE_SERVICE_NAME: ServiceController<?> controller = registry.getRequiredService(AbstractDataSourceDefinition.DATA_SOURCE_CAPABILITY.getCapabilityServiceName(dataSourceName)); return ((AgroalDataSource) controller.getValue()); case XADataSourceOperations.XADATASOURCE_SERVICE_NAME: ServiceController<?> xaController = registry.getRequiredService(AbstractDataSourceDefinition.DATA_SOURCE_CAPABILITY.getCapabilityServiceName(dataSourceName)); return ((AgroalDataSource) xaController.getValue()); default: throw AgroalLogger.SERVICE_LOGGER.unknownDatasourceServiceType(context.getCurrentAddress().getLastElement().getKey()); } }
@Override protected void executeRuntimeStep(final OperationContext context, final ModelNode operation) throws OperationFailedException { final ServiceName componentServiceName = componentServiceName(context,operation); final EJBComponent component = (EJBComponent) context.getServiceRegistry(false).getRequiredService(componentServiceName).getValue(); executeReadMetricStep(context, operation, component); }
@Override protected void performRuntime(OperationContext context, ModelNode operation, ModelNode recoveryEnvModel) throws OperationFailedException { final String configPropertyValue = CONNECTION_PROPERTY_VALUE.resolveModelAttribute(context, recoveryEnvModel).asString(); final ModelNode address = operation.require(OP_ADDR); PathAddress path = PathAddress.pathAddress(address); final String jndiName = path.getElement(path.size() - 2).getValue(); final String configPropertyName = PathAddress.pathAddress(address).getLastElement().getValue(); ServiceName serviceName = DataSourceConfigService.SERVICE_NAME_BASE.append(jndiName).append("connection-properties").append(configPropertyName); final ServiceRegistry registry = context.getServiceRegistry(true); final ServiceName dataSourceConfigServiceName = DataSourceConfigService.SERVICE_NAME_BASE .append(jndiName); final ServiceController<?> dataSourceConfigController = registry .getService(dataSourceConfigServiceName); if (dataSourceConfigController == null || !((DataSource) dataSourceConfigController.getValue()).isEnabled()) { final ServiceTarget serviceTarget = context.getServiceTarget(); final ConnectionPropertiesService service = new ConnectionPropertiesService(configPropertyName, configPropertyValue); serviceTarget.addService(serviceName, service).setInitialMode(ServiceController.Mode.NEVER) .install(); } else { context.reloadRequired(); } }
@Override public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException { ModelNode result = new ModelNode(); CachedConnectionManager ccm = (CachedConnectionManager) context.getServiceRegistry(false).getService(ConnectorServices.CCM_SERVICE).getValue(); Map<String, String> map = ccm.listConnections(); ModelNode txResult = new ModelNode(); for (Map.Entry<String, String> entry : map.entrySet()) { txResult.add(entry.getKey(), entry.getValue()); } ccm = (CachedConnectionManager) context.getServiceRegistry(false).getService(ConnectorServices.NON_TX_CCM_SERVICE).getValue(); map= ccm.listConnections(); ModelNode nonTxResult = new ModelNode(); for (Map.Entry<String, String> entry : map.entrySet()) { nonTxResult.add(entry.getKey(), entry.getValue()); } result.get(Constants.TX).set(txResult); result.get(Constants.NON_TX).set(nonTxResult); context.getResult().set(result); } }, OperationContext.Stage.RUNTIME);
private void applyModelToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode model) throws OperationFailedException { final String poolName = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue(); final ServiceName serviceName = StrictMaxPoolConfigService.EJB_POOL_CONFIG_BASE_SERVICE_NAME.append(poolName); final ServiceRegistry registry = context.getServiceRegistry(true); ServiceController<?> sc = registry.getService(serviceName); if (sc != null) { StrictMaxPoolConfigService smpc = (StrictMaxPoolConfigService) sc.getService(); if (smpc != null) { if (StrictMaxPoolResourceDefinition.MAX_POOL_SIZE.getName().equals(attributeName)) { int maxPoolSize = StrictMaxPoolResourceDefinition.MAX_POOL_SIZE.resolveModelAttribute(context, model).asInt(-1); smpc.setMaxPoolSize(maxPoolSize); } else if (StrictMaxPoolResourceDefinition.DERIVE_SIZE.getName().equals(attributeName)) { StrictMaxPoolConfigService.Derive derive = StrictMaxPoolResourceDefinition.parseDeriveSize(context, model); smpc.setDerive(derive); } else if (StrictMaxPoolResourceDefinition.INSTANCE_ACQUISITION_TIMEOUT.getName().equals(attributeName)) { long timeout = StrictMaxPoolResourceDefinition.INSTANCE_ACQUISITION_TIMEOUT.resolveModelAttribute(context, model).asLong(); smpc.setTimeout(timeout); } else if (StrictMaxPoolResourceDefinition.INSTANCE_ACQUISITION_TIMEOUT_UNIT.getName().equals(attributeName)) { String timeoutUnit = StrictMaxPoolResourceDefinition.INSTANCE_ACQUISITION_TIMEOUT_UNIT.resolveModelAttribute(context, model).asString(); smpc.setTimeoutUnit(TimeUnit.valueOf(timeoutUnit)); } } } }
private void applyModelToRuntime(OperationContext context, final ModelNode model) throws OperationFailedException { final ServiceRegistry serviceRegistry = context.getServiceRegistry(true); ServiceController<IIOPSettingsService> controller = (ServiceController<IIOPSettingsService>) serviceRegistry.getService(IIOPSettingsService.SERVICE_NAME); if (controller != null) { IIOPSettingsService service = controller.getValue(); applySetting(service, context, model); } }
@Override public ModelNode execute(OperationContext context, Metric<Cache<?, ?>> metric) throws OperationFailedException { PathAddress cacheAddress = context.getCurrentAddress().getParent(); String containerName = cacheAddress.getParent().getLastElement().getValue(); String cacheName = cacheAddress.getLastElement().getValue(); Cache<?, ?> cache = new PassiveServiceSupplier<Cache<?, ?>>(context.getServiceRegistry(true), InfinispanCacheRequirement.CACHE.getServiceName(context, containerName, cacheName)).get(); return (cache != null) ? metric.execute(cache) : null; } }
@Override public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException { ServiceRegistry registry = context.getServiceRegistry(false); DriverRegistry driverRegistry = (DriverRegistry)registry.getRequiredService(ConnectorServices.JDBC_DRIVER_REGISTRY_SERVICE).getValue(); ServiceModuleLoader serviceModuleLoader = (ServiceModuleLoader)registry.getRequiredService(Services.JBOSS_SERVICE_MODULE_LOADER).getValue(); ModelNode result = new ModelNode(); InstalledDriver driver = driverRegistry.getInstalledDriver(name); ModelNode driverNode = new ModelNode(); driverNode.get(DRIVER_NAME.getName()).set(driver.getDriverName()); if (driver.isFromDeployment()) { driverNode.get(DEPLOYMENT_NAME.getName()).set(driver.getDriverName()); driverNode.get(DRIVER_MODULE_NAME.getName()); driverNode.get(MODULE_SLOT.getName()); driverNode.get(DRIVER_DATASOURCE_CLASS_NAME.getName());
@Override protected void revertUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode valueToRestore, ModelNode valueToRevert, Void handback) throws OperationFailedException { ServiceController<?> controller = context.getServiceRegistry(false).getService(UndertowService.UNDERTOW); if (controller != null) { UndertowService service = (UndertowService) controller.getService(); if (service != null) { service.setStatisticsEnabled(valueToRestore.asBoolean()); } } } });
@Override public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException { ServiceRegistry registry = context.getServiceRegistry(false); DriverRegistry driverRegistry = (DriverRegistry)registry.getRequiredService(ConnectorServices.JDBC_DRIVER_REGISTRY_SERVICE).getValue(); ServiceModuleLoader serviceModuleLoader = (ServiceModuleLoader)registry.getRequiredService(Services.JBOSS_SERVICE_MODULE_LOADER).getValue(); InstalledDriver driver = driverRegistry.getInstalledDriver(driverName); if (driver == null) { context.getResult().set(new ModelNode()); return; } ModelNode result = dsClsInfoNode(serviceModuleLoader, driver.getModuleName(), driver.getDataSourceClassName(), driver.getXaDataSourceClassName()); context.getResult().set(result); }