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 public final OperationFailedException jndiNameInvalidFormat() { final OperationFailedException result = new OperationFailedException(String.format(getLoggingLocale(), jndiNameInvalidFormat$str())); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String jndiNameShouldValidate = "WFLYAG0304: JNDI name shouldn't include '//' or end with '/'";
private static JdrReport standaloneCollect(CLI cli, String protocol, String host, int port) { // Unable to connect to a running server, so proceed without it JdrReportService reportService = new JdrReportService(); JdrReport report = null; try { report = reportService.standaloneCollect(cli, protocol, host, port); } catch (OperationFailedException e) { System.out.println("Failed to complete the JDR report: " + e.getMessage()); } return report; }
@Override protected void performRuntime(OperationContext context, ModelNode operation, final Resource resource) throws OperationFailedException { if (!raModel.hasDefined(ARCHIVE.getName()) && !raModel.hasDefined(MODULE.getName())) { throw ConnectorLogger.ROOT_LOGGER.archiveOrModuleRequired(); archiveOrModuleName = MODULE.resolveModelAttribute(context, raModel).asString(); final String poolName = PathAddress.pathAddress(address).getLastElement().getValue(); adminObjectValue = RaOperationUtil.buildAdminObjects(context, operation, poolName); } catch (ValidateException e) { throw new OperationFailedException(e, new ModelNode().set(ConnectorLogger.ROOT_LOGGER.failedToCreate("AdminObject", operation, e.getLocalizedMessage()))); ServiceName raServiceName = ServiceName.of(ConnectorServices.RA_SERVICE, raName); final ServiceTarget serviceTarget = context.getServiceTarget(); .install(); PathElement peAO = PathElement.pathElement(Constants.STATISTICS_NAME, "extended"); resource.registerChild(peAO, aoResource);
protected void checkCanRemove(OperationContext context, ModelNode operation) throws OperationFailedException { final String deploymentName = PathAddress.pathAddress(operation.require(OP_ADDR)).getLastElement().getValue(); final Resource root = context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS); if(root.hasChild(PathElement.pathElement(SERVER_GROUP))) { final List<String> badGroups = new ArrayList<String>(); for(final Resource.ResourceEntry entry : root.getChildren(SERVER_GROUP)) { if(entry.hasChild(PathElement.pathElement(DEPLOYMENT, deploymentName))) { badGroups.add(entry.getName()); } } if (badGroups.size() > 0) { throw new OperationFailedException(new ModelNode().set(MESSAGES.cannotRemoveDeploymentInUse(deploymentName, badGroups))); } } }
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { final ModelNode address = operation.require(OP_ADDR); final String driverName = PathAddress.pathAddress(address).getLastElement().getValue(); if (operation.get(DRIVER_NAME.getName()).isDefined() && !driverName.equals(operation.get(DRIVER_NAME.getName()).asString())) { throw ConnectorLogger.ROOT_LOGGER.driverNameAndResourceNameNotEquals(operation.get(DRIVER_NAME.getName()).asString(), driverName); String moduleName = DRIVER_MODULE_NAME.resolveModelAttribute(context, model).asString(); final String xaDataSourceClassName = model.hasDefined(DRIVER_XA_DATASOURCE_CLASS_NAME.getName()) ? DRIVER_XA_DATASOURCE_CLASS_NAME.resolveModelAttribute(context, model).asString() : null; final ServiceTarget target = context.getServiceTarget(); module = Module.getCallerModuleLoader().loadModule(moduleId); } catch (ModuleNotFoundException e) { throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.missingDependencyInModuleDriver(moduleName, e.getMessage()), e); } catch (ModuleLoadException e) { throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToLoadModuleDriver(moduleName), e); } catch (Exception e) { SUBSYSTEM_DATASOURCES_LOGGER.cannotInstantiateDriverClass(driverClassName, e); throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.cannotInstantiateDriverClass(driverClassName));
protected void installServices(final OperationContext context, final PathAddress address, final ModelNode profileNode) throws OperationFailedException { try { final String profileName = address.getLastElement().getValue(); final ServiceName profileServiceName = RemotingProfileService.BASE_SERVICE_NAME.append(profileName); final ModelNode staticEjbDiscoery = StaticEJBDiscoveryDefinition.INSTANCE.resolveModelAttribute(context, profileNode); final RemotingProfileService profileService = new RemotingProfileService(urls, map); final ServiceBuilder<RemotingProfileService> builder = context.getServiceTarget().addService(profileServiceName, profileService); if (profileNode.hasDefined(EJB3SubsystemModel.REMOTING_EJB_RECEIVER)) { for (final Property receiverProperty : profileNode.get(EJB3SubsystemModel.REMOTING_EJB_RECEIVER) .asPropertyList()) { final ModelNode receiverNode = receiverProperty.getValue(); final String connectionRef = RemotingEjbReceiverDefinition.OUTBOUND_CONNECTION_REF.resolveModelAttribute(context, receiverNode).asString(); final long timeout = RemotingEjbReceiverDefinition.CONNECT_TIMEOUT.resolveModelAttribute(context, receiverNode).asLong(); .resolveModelAttribute(context, profileNode).asBoolean(); throw new OperationFailedException(e.getLocalizedMessage());
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR)); final PathElement element = address.getLastElement(); final String serverName = element.getValue(); final ModelNode subModel = context.readResource(PathAddress.EMPTY_ADDRESS, false).getModel(); final boolean isStart = ServerConfigResourceDefinition.AUTO_START.resolveModelAttribute(context, subModel).asBoolean(); ServerStatus status = serverInventory.determineServerStatus(serverName); if (status == ServerStatus.STOPPED) { status = isStart ? status : ServerStatus.DISABLED; } if(status != null) { context.getResult().set(status.toString()); } else { throw new OperationFailedException(HostControllerLogger.ROOT_LOGGER.failedToGetServerStatus()); } }
private static void checkNull(final ModelNode operation, final Object toCheck) throws OperationFailedException { if (toCheck == null) { String msg = String.format("No handler for %s at address %s", operation.require(OP).asString(), PathAddress.pathAddress(operation.get(OP_ADDR))); throw new OperationFailedException(new ModelNode().set(msg)); } }
@Override protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model, ServiceVerificationHandler verificationHandler, List<ServiceController<?>> newControllers) throws OperationFailedException { PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR)); String name = address.getLastElement().getValue(); try { newControllers.add(installBindingService(context, model, name, verificationHandler)); } catch (UnknownHostException e) { throw new OperationFailedException(new ModelNode().set(e.getLocalizedMessage())); } }
@Override protected boolean applyUpdateToRuntime(final OperationContext context, final ModelNode operation, final String parameterName, final ModelNode newValue, final ModelNode currentValue, final HandbackHolder<List<ConnectionManager>> handbackHolder) throws OperationFailedException { final String jndiName = context.readResource(PathAddress.EMPTY_ADDRESS).getModel().get(Constants.JNDINAME.getName()).asString(); final ServiceController<?> managementRepoService = context.getServiceRegistry(false).getService( ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE); Boolean boolValue = Constants.ENLISTMENT_TRACE.resolveValue(context, newValue).asBoolean(); try { final ManagementRepository repository = (ManagementRepository) managementRepoService.getValue(); if (repository.getConnectors() != null) { List<ConnectionManager> handback = new LinkedList<>(); for (Connector connector : repository.getConnectors()) { for (ConnectionManager cm : connector.getConnectionManagers()) { if (jndiName.equalsIgnoreCase(cm.getUniqueId())) { cm.setEnlistmentTrace(boolValue); handback.add(cm); } } } handbackHolder.setHandback(handback); } } catch (Exception e) { throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToSetAttribute(e.getLocalizedMessage())); } return false; }
static void secondRuntimeStep(OperationContext context, ModelNode operation, ManagementResourceRegistration datasourceRegistration, ModelNode model, boolean isXa) throws OperationFailedException { final ServiceTarget serviceTarget = context.getServiceTarget(); final boolean elytronEnabled = ELYTRON_ENABLED.resolveModelAttribute(context, model).asBoolean(); final ServiceName dataSourceServiceName = context.getCapabilityServiceName(Capabilities.DATA_SOURCE_CAPABILITY_NAME, dsName, DataSource.class); final ServiceController<?> dataSourceController = registry.getService(dataSourceServiceName); dataSourceConfig = xaFrom(context, model, dsName, credentialSourceExceptionExceptionSupplier, recoveryCredentialSourceExceptionExceptionSupplier); } catch (ValidateException e) { throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToCreate("XaDataSource", operation, e.getLocalizedMessage())); throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.serviceAlreadyStarted("Data-source.xa-config-property", name)); dataSourceConfig = from(context, model, dsName, credentialSourceExceptionExceptionSupplier); } catch (ValidateException e) { throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToCreate("DataSource", operation, e.getLocalizedMessage())); throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.serviceAlreadyStarted("Data-source.connectionProperty", name)); dataSourceController.setMode(ServiceController.Mode.ACTIVE); } else { throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.serviceAlreadyStarted("Data-source", dsName)); throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.serviceNotAvailable("Data-source", dsName));
@Override public ModelNode execute(ExpressionResolver expressionResolver, ModelNode operation, ModClusterServiceMBean service) throws OperationFailedException { String virtualHost = VIRTUAL_HOST.resolveModelAttribute(expressionResolver, operation).asString(); String webContext = CONTEXT.resolveModelAttribute(expressionResolver, operation).asString(); try { boolean enabled = service.enableContext(virtualHost, webContext); return new ModelNode(enabled); } catch (IllegalArgumentException e) { throw new OperationFailedException(ModClusterLogger.ROOT_LOGGER.contextOrHostNotFound(virtualHost, webContext)); } } },
/** * Directly handles the op in the standard way the default prepare step handler would * @param context the operation execution context * @param operation the operation * @throws OperationFailedException if no handler is registered for the operation */ private void addBasicStep(OperationContext context, ModelNode operation) throws OperationFailedException { final String operationName = operation.require(OP).asString(); final OperationStepHandler stepHandler = context.getResourceRegistration().getOperationHandler(PathAddress.EMPTY_ADDRESS, operationName); if(stepHandler != null) { context.addStep(operation, stepHandler, OperationContext.Stage.MODEL); } else { throw new OperationFailedException(new ModelNode(ControllerMessages.MESSAGES.noHandlerForOperation(operationName, PathAddress.pathAddress(operation.get(OP_ADDR))))); } }
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { MBeanServer mbs = TransactionExtension.getMBeanServer(context); final Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS); try { final ObjectName on = LogStoreResource.getObjectName(resource); final ModelNode model = resource.getModel().clone(); AttributeList attributes = mbs.getAttributes(on, LogStoreConstants.PARTICIPANT_JMX_NAMES); for (javax.management.Attribute attribute : attributes.asList()) { String modelName = LogStoreConstants.jmxNameToModelName(LogStoreConstants.MODEL_TO_JMX_PARTICIPANT_NAMES, attribute.getName()); if (modelName != null) { ModelNode aNode = model.get(modelName); Object value = attribute.getValue(); if (aNode != null) aNode.set(value == null ? "" : value.toString()); } } // Replace the model resource.writeModel(model); } catch (Exception e) { throw new OperationFailedException("JMX error: " + e.getMessage()); } context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER); } }
public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException { final ServiceRegistry serviceRegistry = context.getServiceRegistry(false); final ModelNode contextsNode = resultNode.get("java: contexts"); addEntries(contextsNode.get("java:"), new NamingContext(javaContextNamingStore, null)); } catch (NamingException e) { throw new OperationFailedException(e, new ModelNode().set(NamingLogger.ROOT_LOGGER.failedToReadContextEntries("java:"))); addEntries(contextsNode.get("java:jboss"), new NamingContext(jbossContextNamingStore, null)); } catch (NamingException e) { throw new OperationFailedException(e, new ModelNode().set(NamingLogger.ROOT_LOGGER.failedToReadContextEntries("java:jboss"))); addEntries(contextsNode.get("java:jboss/exported"), new NamingContext(exportedContextNamingStore, null)); } catch (NamingException e) { throw new OperationFailedException(e, new ModelNode().set(NamingLogger.ROOT_LOGGER.failedToReadContextEntries("java:jboss/exported"))); addEntries(contextsNode.get("java:global"), new NamingContext(globalContextNamingStore, null)); } catch (NamingException e) { throw new OperationFailedException(e, new ModelNode().set(NamingLogger.ROOT_LOGGER.failedToReadContextEntries("java:global"))); context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { AuthorizationResult authorizationResult = context.authorize(operation); if (authorizationResult.getDecision() == AuthorizationResult.Decision.DENY) { throw ControllerMessages.MESSAGES.unauthorized(operation.get(OP).asString(), PathAddress.pathAddress(operation.get(OP_ADDR)), authorizationResult.getExplanation()); } try { String name = persister.snapshot(); context.getResult().set(name); } catch (ConfigurationPersistenceException e) { throw new OperationFailedException(e); } context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER); }
public void execute(final JndiViewExtensionContext context) throws OperationFailedException { final ModelNode applicationsNode = context.getResult().get("applications"); final ServiceRegistry serviceRegistry = context.getOperationContext().getServiceRegistry(false); final Set<Resource.ResourceEntry> deploymentResource = context.getOperationContext().readResourceFromRoot(PathAddress.EMPTY_ADDRESS, false).getChildren(DEPLOYMENT); for (final Resource.ResourceEntry entry : deploymentResource) { final ServiceController<?> deploymentUnitServiceController = serviceRegistry.getService(ServiceName.JBOSS.append("deployment", "unit", entry.getName())); if (deploymentUnitServiceController != null) { final ModelNode deploymentNode = applicationsNode.get(entry.getName()); final DeploymentUnit deploymentUnit = DeploymentUnit.class.cast(deploymentUnitServiceController.getValue()); final NamingStore appStore = NamingStore.class.cast(appContextController.getValue()); try { context.addEntries(deploymentNode.get("java:app"), new NamingContext(appStore, null)); } catch (NamingException e) { throw new OperationFailedException(e, new ModelNode().set(EeLogger.ROOT_LOGGER.failedToRead("java:app", appName)));
@Override public ModelNode execute(ExpressionResolver expressionResolver, ModelNode operation, ModClusterServiceMBean service) throws OperationFailedException { String virtualHost = VIRTUAL_HOST.resolveModelAttribute(expressionResolver, operation).asString(); String webContext = CONTEXT.resolveModelAttribute(expressionResolver, operation).asString(); try { boolean disabled = service.disableContext(virtualHost, webContext); return new ModelNode().get(ModelDescriptionConstants.RESULT).set(disabled); } catch (IllegalArgumentException e) { throw new OperationFailedException(ModClusterLogger.ROOT_LOGGER.contextOrHostNotFound(virtualHost, webContext)); } } },
static void installCapability(OperationContext context, ModelNode operation) throws OperationFailedException { PathAddress pathAddress = PathAddress.pathAddress(operation.get(OP_ADDR)); String factoryName = pathAddress.getLastElement().getValue(); ServiceName serviceName = context.getCapabilityServiceName(HTTP_SERVER_AUTHENTICATION_CAPABILITY, factoryName, HttpServerAuthenticationMechanismFactory.class); boolean publicClient = SecureServerDefinition.PUBLIC_CLIENT.resolveModelAttribute(context, operation).asBoolean(false); if (!publicClient) { throw new OperationFailedException("Only public clients are allowed to have their configuration exposed through the management interface"); } KeycloakHttpAuthenticationFactoryService service = new KeycloakHttpAuthenticationFactoryService(factoryName); ServiceTarget serviceTarget = context.getServiceTarget(); InjectedValue<ExtensibleHttpManagement> injectedValue = new InjectedValue<>(); serviceTarget.addService(serviceName.append("http-management-context"), createHttpManagementConfigContextService(factoryName, injectedValue)) .addDependency(context.getCapabilityServiceName(HTTP_MANAGEMENT_HTTP_EXTENSIBLE_CAPABILITY, ExtensibleHttpManagement.class), ExtensibleHttpManagement.class, injectedValue).setInitialMode(Mode.ACTIVE).install(); serviceTarget.addService(serviceName, service).setInitialMode(Mode.ACTIVE).install(); } }