use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.
the class AddressSettingsWriteHandler method applyUpdateToRuntime.
@Override
protected boolean applyUpdateToRuntime(final OperationContext context, final ModelNode operation, final String attributeName, final ModelNode resolvedValue, final ModelNode currentValue, final HandbackHolder<RevertHandback> handbackHolder) throws OperationFailedException {
final Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS);
final ActiveMQServer server = getActiveMQServer(context, operation);
if (server != null) {
final ModelNode model = resource.getModel();
final PathAddress address = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR));
final AddressSettings settings = AddressSettingAdd.createSettings(context, model);
final HierarchicalRepository<AddressSettings> repository = server.getAddressSettingsRepository();
final String match = address.getLastElement().getValue();
final AddressSettings existingSettings = repository.getMatch(match);
repository.addMatch(match, settings);
if (existingSettings != null) {
handbackHolder.setHandback(new RevertHandback() {
@Override
public void doRevertUpdateToRuntime() {
// Restore the old settings
repository.addMatch(address.getLastElement().getValue(), existingSettings);
}
});
}
}
return false;
}
use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.
the class ImportJournalOperation method createInVMTransportConfiguration.
/**
* The XmlDataImporter requires a connector to connect to the artemis broker.
*
* We require to use a in-vm one so that importing a journal is not subject to any network connection problem.
*/
private TransportConfiguration createInVMTransportConfiguration(OperationContext context) throws OperationFailedException {
final Resource serverResource = context.readResource(EMPTY_ADDRESS, false);
Set<Resource.ResourceEntry> invmConnectors = serverResource.getChildren(CommonAttributes.IN_VM_CONNECTOR);
if (invmConnectors.isEmpty()) {
throw MessagingLogger.ROOT_LOGGER.noInVMConnector();
}
Resource.ResourceEntry connectorEntry = invmConnectors.iterator().next();
Resource connectorResource = context.readResource(PathAddress.pathAddress(connectorEntry.getPathElement()), false);
ModelNode model = connectorResource.getModel();
Map<String, Object> params = new HashMap<>(CommonAttributes.PARAMS.unwrap(context, model));
params.put(InVMTransportDefinition.SERVER_ID.getName(), InVMTransportDefinition.SERVER_ID.resolveModelAttribute(context, model).asInt());
TransportConfiguration transportConfiguration = new TransportConfiguration(InVMConnectorFactory.class.getName(), params);
return transportConfiguration;
}
use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.
the class SecurityDomainAdd method performRuntime.
@Override
protected void performRuntime(OperationContext context, ModelNode operation, final ModelNode model) {
PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR));
final String securityDomain = address.getLastElement().getValue();
// This needs to run after all child resources so that they can detect a fresh state
context.addStep(new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
final Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS);
launchServices(context, securityDomain, Resource.Tools.readModel(resource));
// Rollback handled by the parent step
context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
}
}, OperationContext.Stage.RUNTIME);
}
use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.
the class WebMigrateOperation method createIoSubsystem.
/**
* We need to create the IO subsystem, if it does not already exist
*/
private void createIoSubsystem(OperationContext context, Map<PathAddress, ModelNode> migrationOperations, PathAddress baseAddress) {
Resource root = context.readResourceFromRoot(baseAddress, false);
if (root.getChildrenNames(SUBSYSTEM).contains(IOExtension.SUBSYSTEM_NAME)) {
// subsystem is already added, do nothing
return;
}
//these addresses will be fixed later, no need to use the base address
PathAddress address = pathAddress(pathElement(SUBSYSTEM, IOExtension.SUBSYSTEM_NAME));
migrationOperations.put(address, createAddOperation(address));
address = pathAddress(pathElement(SUBSYSTEM, IOExtension.SUBSYSTEM_NAME), pathElement("worker", "default"));
migrationOperations.put(address, createAddOperation(address));
address = pathAddress(pathElement(SUBSYSTEM, IOExtension.SUBSYSTEM_NAME), pathElement("buffer-pool", "default"));
migrationOperations.put(address, createAddOperation(address));
}
use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.
the class WebMigrateOperation method createSecurityRealm.
/**
* Creates the security realm
*
* @param context
* @param migrationOperations
* @return
*/
private SSLInformation createSecurityRealm(OperationContext context, Map<PathAddress, ModelNode> migrationOperations, ModelNode legacyModelAddOps, String connector, List<String> warnings, boolean domainMode) {
ModelNode legacyAddOp = findResource(pathAddress(WebExtension.SUBSYSTEM_PATH, pathElement(WebExtension.CONNECTOR_PATH.getKey(), connector), pathElement("configuration", "ssl")), legacyModelAddOps);
if (legacyAddOp == null) {
return null;
}
//we have SSL
//read all the info from the SSL definition
ModelNode keyAlias = legacyAddOp.get(WebSSLDefinition.KEY_ALIAS.getName());
ModelNode password = legacyAddOp.get(WebSSLDefinition.PASSWORD.getName());
ModelNode certificateKeyFile = legacyAddOp.get(WebSSLDefinition.CERTIFICATE_KEY_FILE.getName());
ModelNode cipherSuite = legacyAddOp.get(WebSSLDefinition.CIPHER_SUITE.getName());
ModelNode protocol = legacyAddOp.get(WebSSLDefinition.PROTOCOL.getName());
ModelNode verifyClient = legacyAddOp.get(WebSSLDefinition.VERIFY_CLIENT.getName());
ModelNode verifyDepth = legacyAddOp.get(WebSSLDefinition.VERIFY_DEPTH.getName());
ModelNode certificateFile = legacyAddOp.get(WebSSLDefinition.CERTIFICATE_FILE.getName());
ModelNode caCertificateFile = legacyAddOp.get(WebSSLDefinition.CA_CERTIFICATE_FILE.getName());
ModelNode caCertificatePassword = legacyAddOp.get(WebSSLDefinition.CA_CERTIFICATE_PASSWORD.getName());
ModelNode csRevocationURL = legacyAddOp.get(WebSSLDefinition.CA_REVOCATION_URL.getName());
ModelNode trustStoreType = legacyAddOp.get(WebSSLDefinition.TRUSTSTORE_TYPE.getName());
ModelNode keystoreType = legacyAddOp.get(WebSSLDefinition.KEYSTORE_TYPE.getName());
ModelNode sessionCacheSize = legacyAddOp.get(WebSSLDefinition.SESSION_CACHE_SIZE.getName());
ModelNode sessionTimeout = legacyAddOp.get(WebSSLDefinition.SESSION_TIMEOUT.getName());
ModelNode sslProvider = legacyAddOp.get(WebSSLDefinition.SSL_PROTOCOL.getName());
if (verifyDepth.isDefined()) {
warnings.add(WebLogger.ROOT_LOGGER.couldNotMigrateResource(WebSSLDefinition.VERIFY_DEPTH.getName(), pathAddress(legacyAddOp.get(ADDRESS))));
}
if (certificateFile.isDefined()) {
warnings.add(WebLogger.ROOT_LOGGER.couldNotMigrateResource(WebSSLDefinition.CERTIFICATE_FILE.getName(), pathAddress(legacyAddOp.get(ADDRESS))));
}
if (sslProvider.isDefined()) {
warnings.add(WebLogger.ROOT_LOGGER.couldNotMigrateResource(WebSSLDefinition.SSL_PROTOCOL.getName(), pathAddress(legacyAddOp.get(ADDRESS))));
}
if (csRevocationURL.isDefined()) {
warnings.add(WebLogger.ROOT_LOGGER.couldNotMigrateResource(WebSSLDefinition.CA_REVOCATION_URL.getName(), pathAddress(legacyAddOp.get(ADDRESS))));
}
String realmName;
PathAddress managementCoreService;
if (domainMode) {
Set<String> hosts = new HashSet<>();
Resource hostResource = context.readResourceFromRoot(pathAddress(), false);
hosts.addAll(hostResource.getChildrenNames(HOST));
//now we need to find a unique name
//in domain mode different profiles could have different SSL configurations
//but the realms are not scoped to a profile
//if we hard coded a name migration would fail when migrating domains with multiple profiles
int counter = 1;
realmName = REALM_NAME + counter;
while (true) {
boolean hostOk = true;
for (String host : hosts) {
Resource root = context.readResourceFromRoot(pathAddress(pathElement(HOST, host), pathElement(CORE_SERVICE, MANAGEMENT)), false);
if (root.getChildrenNames(SECURITY_REALM).contains(realmName)) {
counter++;
realmName = REALM_NAME + counter;
hostOk = false;
break;
}
}
if (hostOk) {
break;
}
}
for (String host : hosts) {
createHostSSLConfig(realmName, migrationOperations, keyAlias, password, certificateKeyFile, protocol, caCertificateFile, caCertificatePassword, trustStoreType, keystoreType, pathAddress(pathElement(HOST, host), pathElement(CORE_SERVICE, MANAGEMENT)));
}
} else {
managementCoreService = pathAddress(CORE_SERVICE, MANAGEMENT);
//now we need to find a unique name
//in domain mode different profiles could have different SSL configurations
//but the realms are not scoped to a profile
//if we hard coded a name migration would fail when migrating domains with multiple profiles
int counter = 1;
realmName = REALM_NAME + counter;
boolean ok = false;
do {
Resource root = context.readResourceFromRoot(managementCoreService, false);
if (root.getChildrenNames(SECURITY_REALM).contains(realmName)) {
counter++;
realmName = REALM_NAME + counter;
} else {
ok = true;
}
} while (!ok);
//we have a unique realm name
createHostSSLConfig(realmName, migrationOperations, keyAlias, password, certificateKeyFile, protocol, caCertificateFile, caCertificatePassword, trustStoreType, keystoreType, managementCoreService);
}
return new SSLInformation(realmName, verifyClient, sessionCacheSize, sessionTimeout, protocol, cipherSuite);
}
Aggregations