Search in sources :

Example 51 with OperationFailedException

use of org.jboss.as.controller.OperationFailedException in project wildfly by wildfly.

the class AbstractPicketLinkMetricsOperationHandler method execute.

@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    context.addStep(new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
            final String name = address.getLastElement().getValue();
            final String attributeName = operation.require(NAME).asString();
            final ServiceController<?> controller = context.getServiceRegistry(false).getRequiredService(createServiceName(name));
            try {
                PicketLinkFederationService<?> service = (PicketLinkFederationService<?>) controller.getValue();
                doPopulateResult(service.getMetrics(), context.getResult(), attributeName);
            } catch (Exception e) {
                throw PicketLinkLogger.ROOT_LOGGER.failedToGetMetrics(e.getMessage());
            }
            context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
        }
    }, OperationContext.Stage.RUNTIME);
    context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) PicketLinkFederationService(org.wildfly.extension.picketlink.federation.service.PicketLinkFederationService) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) PathAddress(org.jboss.as.controller.PathAddress) OperationFailedException(org.jboss.as.controller.OperationFailedException) ServiceController(org.jboss.msc.service.ServiceController) ModelNode(org.jboss.dmr.ModelNode) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Example 52 with OperationFailedException

use of org.jboss.as.controller.OperationFailedException in project wildfly by wildfly.

the class IDMConfigWriteAttributeHandler method execute.

@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    context.addStep(new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            final PathAddress address = getParentAddress(PathAddress.pathAddress(operation.require(OP_ADDR)));
            Resource resource = context.readResourceFromRoot(address);
            final ModelNode parentModel = Resource.Tools.readModel(resource);
            PartitionManagerAddHandler.INSTANCE.validateModel(context, address.getLastElement().getValue(), parentModel);
            context.stepCompleted();
        }
    }, OperationContext.Stage.MODEL);
    super.execute(context, operation);
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) PathAddress(org.jboss.as.controller.PathAddress) OperationFailedException(org.jboss.as.controller.OperationFailedException) Resource(org.jboss.as.controller.registry.Resource) ModelNode(org.jboss.dmr.ModelNode)

Example 53 with OperationFailedException

use of org.jboss.as.controller.OperationFailedException in project wildfly by wildfly.

the class IdentityConfigurationRemoveStepHandler method updateModel.

@Override
protected void updateModel(OperationContext context, ModelNode operation) throws OperationFailedException {
    PathAddress partitionManagerAddress = getParentAddress(context.getCurrentAddress());
    Resource partitionManagerResource = context.readResourceFromRoot(partitionManagerAddress);
    checkIfLastConfiguration(partitionManagerResource);
    ModelNode originalParentModel = Resource.Tools.readModel(partitionManagerResource);
    super.updateModel(context, operation);
    context.addStep(new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            PartitionManagerRemoveHandler.INSTANCE.removeIdentityStoreServices(context, originalParentModel, partitionManagerAddress.getLastElement().getValue(), context.getCurrentAddressValue());
            context.completeStep(OperationContext.ResultHandler.NOOP_RESULT_HANDLER);
        }
    }, OperationContext.Stage.RUNTIME);
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource) OperationFailedException(org.jboss.as.controller.OperationFailedException) ModelNode(org.jboss.dmr.ModelNode)

Example 54 with OperationFailedException

use of org.jboss.as.controller.OperationFailedException in project wildfly by wildfly.

the class WSServerConfigAttributeHandler method updateServerConfig.

/**
     * Returns true if the update operation succeeds in modifying the runtime, false otherwise.
     *
     * @param context
     * @param attributeName
     * @param value
     * @return
     * @throws OperationFailedException
     * @throws DisabledOperationException
     */
private boolean updateServerConfig(OperationContext context, String attributeName, String value, boolean isRevert) throws OperationFailedException, DisabledOperationException {
    ServerConfigImpl config = (ServerConfigImpl) context.getServiceRegistry(false).getRequiredService(WSServices.CONFIG_SERVICE).getValue();
    try {
        if (MODIFY_WSDL_ADDRESS.equals(attributeName)) {
            final boolean modifyWSDLAddress = value != null && Boolean.parseBoolean(value);
            config.setModifySOAPAddress(modifyWSDLAddress, isRevert);
        } else if (WSDL_HOST.equals(attributeName)) {
            final String host = value != null ? value : null;
            try {
                config.setWebServiceHost(host, isRevert);
            } catch (final UnknownHostException e) {
                throw new OperationFailedException(e.getMessage(), e);
            }
        } else if (WSDL_PORT.equals(attributeName)) {
            final int port = value != null ? Integer.parseInt(value) : -1;
            config.setWebServicePort(port, isRevert);
        } else if (WSDL_SECURE_PORT.equals(attributeName)) {
            final int securePort = value != null ? Integer.parseInt(value) : -1;
            config.setWebServiceSecurePort(securePort, isRevert);
        } else if (WSDL_PATH_REWRITE_RULE.equals(attributeName)) {
            final String path = value != null ? value : null;
            config.setWebServicePathRewriteRule(path, isRevert);
        } else if (WSDL_URI_SCHEME.equals(attributeName)) {
            if (value == null || value.equals("http") || value.equals("https")) {
                config.setWebServiceUriScheme(value, isRevert);
            } else {
                throw new IllegalArgumentException(attributeName + " = " + value);
            }
        } else if (STATISTICS_ENABLED.equals(attributeName)) {
            final boolean enabled = value != null ? Boolean.parseBoolean(value) : false;
            config.setStatisticsEnabled(enabled);
        } else {
            throw new IllegalArgumentException(attributeName);
        }
    } catch (DisabledOperationException doe) {
        // the WS stack rejected the runtime update
        if (!isRevert) {
            return false;
        } else {
            throw doe;
        }
    }
    return true;
}
Also used : UnknownHostException(java.net.UnknownHostException) OperationFailedException(org.jboss.as.controller.OperationFailedException) ServerConfigImpl(org.jboss.as.webservices.config.ServerConfigImpl) DisabledOperationException(org.jboss.as.webservices.config.DisabledOperationException)

Example 55 with OperationFailedException

use of org.jboss.as.controller.OperationFailedException in project wildfly by wildfly.

the class RemotingProfileAdd method installServices.

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);
        List<StaticEJBDiscoveryDefinition.StaticEjbDiscovery> discoveryList = StaticEJBDiscoveryDefinition.createStaticEjbList(context, staticEjbDiscoery);
        final List<ServiceURL> urls = new ArrayList<>();
        for (StaticEJBDiscoveryDefinition.StaticEjbDiscovery resource : discoveryList) {
            ServiceURL.Builder builder = new ServiceURL.Builder();
            builder.setAbstractType("ejb").setAbstractTypeAuthority("jboss").setUri(new URI(resource.getUrl()));
            String distinctName = resource.getDistinct() == null ? "" : resource.getDistinct();
            String appName = resource.getApp() == null ? "" : resource.getApp();
            String moduleName = resource.getModule();
            if (distinctName.isEmpty()) {
                if (appName.isEmpty()) {
                    builder.addAttribute(EJBClientContext.FILTER_ATTR_EJB_MODULE, AttributeValue.fromString(moduleName));
                } else {
                    builder.addAttribute(EJBClientContext.FILTER_ATTR_EJB_MODULE, AttributeValue.fromString(appName + "/" + moduleName));
                }
            } else {
                if (appName.isEmpty()) {
                    builder.addAttribute(EJBClientContext.FILTER_ATTR_EJB_MODULE_DISTINCT, AttributeValue.fromString(moduleName + "/" + distinctName));
                } else {
                    builder.addAttribute(EJBClientContext.FILTER_ATTR_EJB_MODULE_DISTINCT, AttributeValue.fromString(appName + "/" + moduleName + "/" + distinctName));
                }
            }
            urls.add(builder.create());
        }
        final Map<String, RemotingProfileService.ConnectionSpec> map = new HashMap<>();
        final RemotingProfileService profileService = new RemotingProfileService(urls, map);
        // populating the map after the fact is cheating, but it works thanks to the MSC start service "fence"
        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();
                final ServiceName connectionDependencyService = AbstractOutboundConnectionService.OUTBOUND_CONNECTION_BASE_SERVICE_NAME.append(connectionRef);
                final InjectedValue<AbstractOutboundConnectionService> connectionInjector = new InjectedValue<AbstractOutboundConnectionService>();
                builder.addDependency(connectionDependencyService, AbstractOutboundConnectionService.class, connectionInjector);
                final ModelNode channelCreationOptionsNode = receiverNode.get(EJB3SubsystemModel.CHANNEL_CREATION_OPTIONS);
                OptionMap channelCreationOptions = createChannelOptionMap(context, channelCreationOptionsNode);
                map.put(connectionRef, new RemotingProfileService.ConnectionSpec(connectionRef, connectionInjector, channelCreationOptions, timeout));
            }
        }
        final boolean isLocalReceiverExcluded = RemotingProfileResourceDefinition.EXCLUDE_LOCAL_RECEIVER.resolveModelAttribute(context, profileNode).asBoolean();
        // service
        if (!isLocalReceiverExcluded) {
            final ModelNode passByValueNode = RemotingProfileResourceDefinition.LOCAL_RECEIVER_PASS_BY_VALUE.resolveModelAttribute(context, profileNode);
            if (passByValueNode.isDefined()) {
                final ServiceName localTransportProviderServiceName = passByValueNode.asBoolean() == true ? LocalTransportProvider.BY_VALUE_SERVICE_NAME : LocalTransportProvider.BY_REFERENCE_SERVICE_NAME;
                builder.addDependency(localTransportProviderServiceName, EJBTransportProvider.class, profileService.getLocalTransportProviderInjector());
            } else {
                // setup a dependency on the default local ejb receiver service configured at the subsystem level
                builder.addDependency(LocalTransportProvider.DEFAULT_LOCAL_TRANSPORT_PROVIDER_SERVICE_NAME, EJBTransportProvider.class, profileService.getLocalTransportProviderInjector());
            }
        }
        builder.setInitialMode(ServiceController.Mode.ACTIVE).install();
    } catch (IllegalArgumentException | URISyntaxException e) {
        throw new OperationFailedException(e.getLocalizedMessage());
    }
}
Also used : AbstractOutboundConnectionService(org.jboss.as.remoting.AbstractOutboundConnectionService) InjectedValue(org.jboss.msc.value.InjectedValue) HashMap(java.util.HashMap) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) ServiceURL(org.wildfly.discovery.ServiceURL) RemotingProfileService(org.jboss.as.ejb3.remote.RemotingProfileService) Property(org.jboss.dmr.Property) OperationFailedException(org.jboss.as.controller.OperationFailedException) ServiceName(org.jboss.msc.service.ServiceName) OptionMap(org.xnio.OptionMap) ModelNode(org.jboss.dmr.ModelNode)

Aggregations

OperationFailedException (org.jboss.as.controller.OperationFailedException)113 ModelNode (org.jboss.dmr.ModelNode)86 PathAddress (org.jboss.as.controller.PathAddress)51 OperationContext (org.jboss.as.controller.OperationContext)49 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)34 ServiceName (org.jboss.msc.service.ServiceName)33 Resource (org.jboss.as.controller.registry.Resource)26 ServiceController (org.jboss.msc.service.ServiceController)19 ServiceTarget (org.jboss.msc.service.ServiceTarget)15 PathElement (org.jboss.as.controller.PathElement)13 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)12 IOException (java.io.IOException)11 Map (java.util.Map)11 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)11 ArrayList (java.util.ArrayList)9 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)9 ContextNames (org.jboss.as.naming.deployment.ContextNames)7 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)7 List (java.util.List)6 ResourceServiceHandler (org.jboss.as.clustering.controller.ResourceServiceHandler)6