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);
}
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);
}
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);
}
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;
}
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());
}
}
Aggregations