use of org.jboss.as.controller.OperationFailedException in project wildfly by wildfly.
the class TransportResourceDefinition method buildTransformation.
static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder parent) {
ResourceTransformationDescriptionBuilder builder = parent.addChildResource(WILDCARD_PATH);
AbstractProtocolResourceDefinition.addTransformations(version, builder);
if (JGroupsModel.VERSION_3_0_0.requiresTransformation(version)) {
builder.getAttributeBuilder().setValueConverter(new DefaultValueAttributeConverter(Attribute.SHARED.getDefinition()), Attribute.SHARED.getDefinition());
builder.setCustomResourceTransformer(new ResourceTransformer() {
@Override
public void transformResource(ResourceTransformationContext context, PathAddress address, Resource resource) throws OperationFailedException {
new LegacyPropertyResourceTransformer().transformResource(context, LEGACY_ADDRESS_TRANSFORMER.transform(address), resource);
}
});
builder.addOperationTransformationOverride(ModelDescriptionConstants.ADD).setCustomOperationTransformer(new SimpleOperationTransformer(new org.jboss.as.clustering.controller.transform.OperationTransformer() {
@Override
public ModelNode transformOperation(final ModelNode operation) {
operation.get(ModelDescriptionConstants.OP_ADDR).set(LEGACY_ADDRESS_TRANSFORMER.transform(Operations.getPathAddress(operation)).toModelNode());
return new LegacyPropertyAddOperationTransformer().transformOperation(operation);
}
})).inheritResourceAttributeDefinitions();
builder.addOperationTransformationOverride(ModelDescriptionConstants.REMOVE).setCustomOperationTransformer(new SimpleRemoveOperationTransformer(LEGACY_ADDRESS_TRANSFORMER));
builder.addOperationTransformationOverride(ModelDescriptionConstants.READ_ATTRIBUTE_OPERATION).setCustomOperationTransformer(new SimpleReadAttributeOperationTransformer(LEGACY_ADDRESS_TRANSFORMER));
builder.addOperationTransformationOverride(ModelDescriptionConstants.DESCRIBE).setCustomOperationTransformer(new SimpleDescribeOperationTransformer(LEGACY_ADDRESS_TRANSFORMER));
List<OperationTransformer> getOpTransformerChain = new LinkedList<>();
getOpTransformerChain.add(new SimplePathOperationTransformer(LEGACY_ADDRESS_TRANSFORMER));
getOpTransformerChain.add(new SimpleOperationTransformer(new LegacyPropertyMapGetOperationTransformer()));
ChainedOperationTransformer getOpChainedTransformer = new ChainedOperationTransformer(getOpTransformerChain, false);
builder.addRawOperationTransformationOverride(MapOperations.MAP_GET_DEFINITION.getName(), getOpChainedTransformer);
List<OperationTransformer> writeOpTransformerChain = new LinkedList<>();
writeOpTransformerChain.add(new SimplePathOperationTransformer(LEGACY_ADDRESS_TRANSFORMER));
writeOpTransformerChain.add(new LegacyPropertyWriteOperationTransformer());
ChainedOperationTransformer writeOpChainedTransformer = new ChainedOperationTransformer(writeOpTransformerChain, false);
for (String opName : Operations.getAllWriteAttributeOperationNames()) {
builder.addOperationTransformationOverride(opName).inheritResourceAttributeDefinitions().setCustomOperationTransformer(writeOpChainedTransformer);
}
// Reject thread pool configuration, discard if undefined, support EAP 6.x slaves using deprecated attributes
builder.addChildResource(ThreadPoolResourceDefinition.WILDCARD_PATH, RequiredChildResourceDiscardPolicy.REJECT_AND_WARN);
} else {
EnumSet.allOf(ThreadPoolResourceDefinition.class).forEach(p -> p.buildTransformation(version, parent));
}
}
use of org.jboss.as.controller.OperationFailedException in project wildfly by wildfly.
the class StackOperationExecutor method execute.
@Override
public ModelNode execute(OperationContext context, Operation<ChannelFactory> operation) throws OperationFailedException {
String stackName = context.getCurrentAddressValue();
ServiceRegistry registry = context.getServiceRegistry(false);
ServiceName serviceName = JGroupsRequirement.CHANNEL_FACTORY.getServiceName(context, stackName);
try {
ServiceController<ChannelFactory> controller = ServiceContainerHelper.getService(registry, serviceName);
ServiceController.Mode mode = controller.getMode();
controller.setMode(ServiceController.Mode.ACTIVE);
try {
return operation.execute(controller.awaitValue());
} finally {
controller.setMode(mode);
}
} catch (InterruptedException e) {
throw new OperationFailedException(e.getLocalizedMessage(), e);
}
}
use of org.jboss.as.controller.OperationFailedException in project wildfly by wildfly.
the class ProtocolMetricsHandler method executeRuntimeStep.
@Override
protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
String name = Operations.getAttributeName(operation);
try {
Protocol protocol = this.locator.findProtocol(context);
if (protocol != null) {
Attribute attribute = getAttribute(protocol.getClass(), name);
if (attribute != null) {
FieldType type = FieldType.valueOf(attribute.getType());
try {
ModelNode result = new ModelNode();
Object value = attribute.read(protocol);
if (value != null) {
type.setValue(result, value);
}
context.getResult().set(result);
} catch (Exception e) {
context.getFailureDescription().set(JGroupsLogger.ROOT_LOGGER.privilegedAccessExceptionForAttribute(name));
}
} else {
context.getFailureDescription().set(JGroupsLogger.ROOT_LOGGER.unknownMetric(name));
}
}
} catch (ClassNotFoundException | ModuleLoadException e) {
context.getFailureDescription().set(e.getLocalizedMessage());
} finally {
context.completeStep(OperationContext.ResultHandler.NOOP_RESULT_HANDLER);
}
}
use of org.jboss.as.controller.OperationFailedException in project wildfly by wildfly.
the class EEJndiViewExtension method handleModule.
private void handleModule(final JndiViewExtensionContext context, final DeploymentUnit deploymentUnit, final ModelNode modulesNode, final ServiceRegistry serviceRegistry) throws OperationFailedException {
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
// If it isn't an EE module, just return
if (moduleDescription == null) {
return;
}
final String appName = moduleDescription.getApplicationName();
final String moduleName = moduleDescription.getModuleName();
final ModelNode moduleNode = modulesNode.get(moduleDescription.getModuleName());
final ServiceName moduleContextName = ContextNames.contextServiceNameOfModule(appName, moduleName);
final ServiceController<?> moduleContextController = serviceRegistry.getService(moduleContextName);
if (moduleContextController != null) {
final NamingStore moduleStore = NamingStore.class.cast(moduleContextController.getValue());
try {
context.addEntries(moduleNode.get("java:module"), new NamingContext(moduleStore, null));
} catch (NamingException e) {
throw new OperationFailedException(e, new ModelNode().set(EeLogger.ROOT_LOGGER.failedToRead("java:module", appName, moduleName)));
}
final Collection<ComponentDescription> componentDescriptions = moduleDescription.getComponentDescriptions();
for (ComponentDescription componentDescription : componentDescriptions) {
final String componentName = componentDescription.getComponentName();
final ServiceName compContextServiceName = ContextNames.contextServiceNameOfComponent(appName, moduleName, componentName);
final ServiceController<?> compContextController = serviceRegistry.getService(compContextServiceName);
if (compContextController != null) {
final ModelNode componentNode = moduleNode.get("components").get(componentName);
final NamingStore compStore = NamingStore.class.cast(compContextController.getValue());
try {
context.addEntries(componentNode.get("java:comp"), new NamingContext(compStore, null));
} catch (NamingException e) {
throw new OperationFailedException(e, new ModelNode().set(EeLogger.ROOT_LOGGER.failedToRead("java:comp", appName, moduleName, componentName)));
}
}
}
}
}
use of org.jboss.as.controller.OperationFailedException in project wildfly by wildfly.
the class ImportJournalOperation method executeRuntimeStep.
@Override
protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
if (context.getRunningMode() != NORMAL) {
throw MessagingLogger.ROOT_LOGGER.managementOperationAllowedOnlyInRunningMode("import-journal", NORMAL);
}
String file = FILE.resolveModelAttribute(context, operation).asString();
final XmlDataImporter importer = new XmlDataImporter();
TransportConfiguration transportConfiguration = createInVMTransportConfiguration(context);
try (InputStream is = new FileInputStream(new File(file));
ServerLocator serverLocator = ActiveMQClient.createServerLocator(false, transportConfiguration);
ClientSessionFactory sf = serverLocator.createSessionFactory()) {
ClientSession session = sf.createSession();
importer.process(is, session);
} catch (Exception e) {
throw new OperationFailedException(e);
}
}
Aggregations