use of org.jboss.dmr.ModelNode in project wildfly by wildfly.
the class MigrateOperation method execute.
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
if (!describe && context.getRunningMode() != RunningMode.ADMIN_ONLY) {
throw ROOT_LOGGER.migrateOperationAllowedOnlyInAdminOnly();
}
boolean addLegacyEntries = ADD_LEGACY_ENTRIES.resolveModelAttribute(context, operation).asBoolean();
final List<String> warnings = new ArrayList<>();
// node containing the description (list of add operations) of the legacy subsystem
final ModelNode legacyModelAddOps = new ModelNode();
// preserve the order of insertion of the add operations for the new subsystem.
final Map<PathAddress, ModelNode> migrationOperations = new LinkedHashMap<PathAddress, ModelNode>();
// invoke an OSH to describe the legacy messaging subsystem
describeLegacyMessagingResources(context, legacyModelAddOps);
// invoke an OSH to add the messaging-activemq extension
// FIXME: this does not work it the extension :add is added to the migrationOperations directly (https://issues.jboss.org/browse/WFCORE-323)
addMessagingActiveMQExtension(context, migrationOperations, describe);
context.addStep(new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
// transform the legacy add operations and put them in migrationOperations
transformResources(context, legacyModelAddOps, migrationOperations, addLegacyEntries, warnings);
// put the /subsystem=messaging:remove operation
removeMessagingSubsystem(migrationOperations, context.getProcessType() == ProcessType.STANDALONE_SERVER);
PathAddress parentAddress = context.getCurrentAddress().getParent();
fixAddressesForDomainMode(parentAddress, migrationOperations);
if (describe) {
// :describe-migration operation
// for describe-migration operation, do nothing and return the list of operations that would
// be executed in the composite operation
final Collection<ModelNode> values = migrationOperations.values();
ModelNode result = new ModelNode();
fillWarnings(result, warnings);
result.get(MIGRATION_OPERATIONS).set(values);
context.getResult().set(result);
} else {
// :migrate operation
// invoke an OSH on a composite operation with all the migration operations
final Map<PathAddress, ModelNode> migrateOpResponses = migrateSubsystems(context, migrationOperations);
context.completeStep(new OperationContext.ResultHandler() {
@Override
public void handleResult(OperationContext.ResultAction resultAction, OperationContext context, ModelNode operation) {
final ModelNode result = new ModelNode();
fillWarnings(result, warnings);
if (resultAction == OperationContext.ResultAction.ROLLBACK) {
for (Map.Entry<PathAddress, ModelNode> entry : migrateOpResponses.entrySet()) {
if (entry.getValue().hasDefined(FAILURE_DESCRIPTION)) {
//we check for failure description, as every node has 'failed', but one
//the real error has a failure description
//we break when we find the first one, as there will only ever be one failure
//as the op stops after the first failure
ModelNode desc = new ModelNode();
desc.get(OP).set(migrationOperations.get(entry.getKey()));
desc.get(RESULT).set(entry.getValue());
result.get(MIGRATION_ERROR).set(desc);
break;
}
}
context.getFailureDescription().set(ROOT_LOGGER.migrationFailed());
}
context.getResult().set(result);
}
});
}
}
}, MODEL);
}
use of org.jboss.dmr.ModelNode in project wildfly by wildfly.
the class MigrateOperation method fixAddressesForDomainMode.
/**
* In domain mode, the subsystem are under /profile=XXX.
* This method fixes the address by prepending the addresses (that start with /subsystem) with the current
* operation parent so that is works both in standalone (parent = EMPTY_ADDRESS) and domain mode
* (parent = /profile=XXX)
*/
private void fixAddressesForDomainMode(PathAddress parentAddress, Map<PathAddress, ModelNode> migrationOperations) {
// in standalone mode, do nothing
if (parentAddress.size() == 0) {
return;
}
// use a linked hash map to preserve operations order
Map<PathAddress, ModelNode> fixedMigrationOperations = new LinkedHashMap<>(migrationOperations);
migrationOperations.clear();
for (Map.Entry<PathAddress, ModelNode> entry : fixedMigrationOperations.entrySet()) {
PathAddress fixedAddress = parentAddress.append(entry.getKey());
entry.getValue().get(ADDRESS).set(fixedAddress.toModelNode());
migrationOperations.put(fixedAddress, entry.getValue());
}
}
use of org.jboss.dmr.ModelNode in project wildfly by wildfly.
the class MigrateOperation method connectionFactoryIsUsingInVMConnectors.
private boolean connectionFactoryIsUsingInVMConnectors(OperationContext context, ModelNode connectionFactoryAddOp) {
ModelNode connector = connectionFactoryAddOp.get(CONNECTOR);
if (connector.isDefined()) {
PathAddress connectionFactoryAddress = pathAddress(connectionFactoryAddOp.get(OP_ADDR));
PathElement relativeLegacyServerAddress = connectionFactoryAddress.getParent().getLastElement();
// read the server resource related to the context current address (which is the messaging subsystem address).
Resource serverResource = context.readResource(pathAddress(relativeLegacyServerAddress), false);
Set<String> definedInVMConnectors = serverResource.getChildrenNames("in-vm-connector");
// legacy connector is a property list where the name is the connector and the value is undefined
List<Property> connectorProps = connector.asPropertyList();
for (Property connectorProp : connectorProps) {
String connectorName = connectorProp.getName();
if (definedInVMConnectors.contains(connectorName)) {
return true;
}
}
}
return false;
}
use of org.jboss.dmr.ModelNode in project wildfly by wildfly.
the class MigrateOperation method describeLegacyMessagingResources.
private void describeLegacyMessagingResources(OperationContext context, ModelNode legacyModelDescription) {
ModelNode describeLegacySubsystem = createOperation(GenericSubsystemDescribeHandler.DEFINITION, context.getCurrentAddress());
context.addStep(legacyModelDescription, describeLegacySubsystem, GenericSubsystemDescribeHandler.INSTANCE, MODEL, true);
}
use of org.jboss.dmr.ModelNode in project wildfly by wildfly.
the class MigrateOperation method addMessagingActiveMQExtension.
/**
* It's possible that the extension is already present. In that case, this method does nothing.
*/
private void addMessagingActiveMQExtension(OperationContext context, Map<PathAddress, ModelNode> migrationOperations, boolean describe) {
Resource root = context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS, false);
if (root.getChildrenNames(EXTENSION).contains(MESSAGING_ACTIVEMQ_EXTENSION)) {
// extension is already added, do nothing
return;
}
PathAddress extensionAddress = pathAddress(EXTENSION, MESSAGING_ACTIVEMQ_EXTENSION);
OperationEntry addEntry = context.getRootResourceRegistration().getOperationEntry(extensionAddress, ADD);
ModelNode addOperation = createAddOperation(extensionAddress);
addOperation.get(MODULE).set(MESSAGING_ACTIVEMQ_MODULE);
if (describe) {
migrationOperations.put(extensionAddress, addOperation);
} else {
context.addStep(context.getResult().get(extensionAddress.toString()), addOperation, addEntry.getOperationHandler(), MODEL);
}
}
Aggregations