private boolean checkHostServersStarted(DomainClient masterClient, String host) { try { ModelNode op = Util.createEmptyOperation( READ_CHILDREN_NAMES_OPERATION, PathAddress.pathAddress(HOST, host)); op.get(CHILD_TYPE).set(SERVER); ModelNode ret = DomainTestUtils.executeForResult(op, masterClient); List<ModelNode> list = ret.asList(); for (ModelNode entry : list) { String server = entry.asString(); op = Util.createEmptyOperation( READ_ATTRIBUTE_OPERATION, PathAddress.pathAddress(HOST, host).append(SERVER, server)); op.get(NAME).set("server-state"); ModelNode state = DomainTestUtils.executeForResult(op, masterClient); if (SUCCESS.equals(state.get(OUTCOME).asString())) { return "running".equals(state.get(RESULT).asString()); } } return false; } catch (Exception e) { return false; } }
@Override protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR)); final String name = address.getLastElement().getValue(); final ServiceTarget serviceTarget = context.getServiceTarget(); final ServiceName serviceName = MessagingServices.getActiveMQServiceName( PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR))); final ModelNode selectorNode = SELECTOR.resolveModelAttribute(context, model); final boolean durable = DURABLE.resolveModelAttribute(context, model).asBoolean(); final String selector = selectorNode.isDefined() ? selectorNode.asString() : null; // Do not pass the JNDI bindings to ActiveMQ but install them directly instead so that the // dependencies from the BinderServices to the JMSQueueService are not broken Service<Queue> queueService = JMSQueueService.installService( name, serviceTarget, serviceName, selector, durable, new String[0]); final ModelNode entries = CommonAttributes.DESTINATION_ENTRIES.resolveModelAttribute(context, model); final ServiceName jmsQueueServiceName = JMSServices.getJmsQueueBaseServiceName(serviceName).append(name); final String[] jndiBindings = JMSServices.getJndiBindings(entries); for (String jndiBinding : jndiBindings) { // install a binder service which depends on the JMS queue service BinderServiceUtil.installBinderService( serviceTarget, jndiBinding, queueService, jmsQueueServiceName); } }
@After public void after() throws IOException, MgmtOperationException { shutdownHttpClient(); try { ModelNode op = Util.createEmptyOperation( REMOVE, PathAddress.pathAddress(SYSTEM_PROPERTY, LogStreamExtension.LOG_MESSAGE_PROP)); executeOperation(op); } finally { try { ModelNode op = Util.createEmptyOperation( REMOVE, PathAddress.pathAddress(SUBSYSTEM, LogStreamExtension.SUBSYSTEM_NAME)); executeOperation(op); } finally { ModelNode op = Util.createEmptyOperation( REMOVE, PathAddress.pathAddress(EXTENSION, LogStreamExtension.MODULE_NAME)); executeOperation(op); } } }
@Override public OperationResult execute( OperationContext context, ModelNode operation, ResultHandler resultHandler) { final ModelNode model = context.getSubModel(); PathAddress rootAddress = PathAddress.pathAddress( PathAddress.pathAddress(operation.require(OP_ADDR)).getLastElement()); final ModelNode result = new ModelNode(); final ModelNode subsystem = new ModelNode(); subsystem.get(OP).set(ADD); subsystem.get(OP_ADDR).set(rootAddress.toModelNode()); if (model.has(ACTIVATION)) { subsystem.get(ACTIVATION).set(model.get(ACTIVATION)); } if (model.has(CONFIGURATION)) { subsystem.get(CONFIGURATION).set(model.get(CONFIGURATION)); } if (model.has(PROPERTIES)) { subsystem.get(PROPERTIES).set(model.get(PROPERTIES)); } if (model.has(MODULES)) { subsystem.get(MODULES).set(model.get(MODULES)); } result.add(subsystem); resultHandler.handleResultFragment(Util.NO_LOCATION, result); resultHandler.handleResultComplete(); return new BasicOperationResult(); }
protected void performRuntime( OperationContext context, ModelNode operation, ModelNode model, ServiceVerificationHandler verificationHandler, List<ServiceController<?>> newControllers) throws OperationFailedException { final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR)); final String name = address.getLastElement().getValue(); final ServiceTarget serviceTarget = context.getServiceTarget(); final ServiceName hqServiceName = MessagingServices.getHornetQServiceName( PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR))); final ModelNode selectorNode = SELECTOR.resolveModelAttribute(context, model); final boolean durable = DURABLE.resolveModelAttribute(context, model).asBoolean(); final String selector = selectorNode.isDefined() ? selectorNode.asString() : null; final ModelNode entries = CommonAttributes.DESTINATION_ENTRIES.resolveModelAttribute(context, model); final String[] jndiBindings = JMSServices.getJndiBindings(entries); installServices( verificationHandler, newControllers, name, serviceTarget, hqServiceName, selector, durable, jndiBindings); }
@Override protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { ServiceRegistry registry = context.getServiceRegistry(false); final ServiceName serviceName = MessagingServices.getActiveMQServiceName( PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR))); ServiceController<?> service = registry.getService(serviceName); if (service != null) { context.reloadRequired(); } else { final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR)); final String name = address.getLastElement().getValue(); final ServiceTarget target = context.getServiceTarget(); if (model.hasDefined(JGROUPS_CHANNEL.getName())) { // nothing to do, in that case, the clustering.jgroups subsystem will have setup the stack } else if (model.hasDefined(RemoteTransportDefinition.SOCKET_BINDING.getName())) { final GroupBindingService bindingService = new GroupBindingService(); target .addService( GroupBindingService.getBroadcastBaseServiceName(serviceName).append(name), bindingService) .addDependency( SocketBinding.JBOSS_BINDING_NAME.append(model.get(SOCKET_BINDING).asString()), SocketBinding.class, bindingService.getBindingRef()) .install(); } } }
public static void excludeBadOps_7_1_x(LegacyKernelServicesInitializer initializer) { // deployment overlays don't exist in 7.1.x initializer.addOperationValidationExclude( ADD, PathAddress.pathAddress(PathElement.pathElement(DEPLOYMENT_OVERLAY))); initializer.addOperationValidationExclude( ADD, PathAddress.pathAddress( PathElement.pathElement(DEPLOYMENT_OVERLAY), PathElement.pathElement(CONTENT))); initializer.addOperationValidationExclude( ADD, PathAddress.pathAddress( PathElement.pathElement(SERVER_GROUP), PathElement.pathElement(DEPLOYMENT_OVERLAY))); // Socket binding group/socket-binding has problems if there are expressions in the // multicast-port initializer.addOperationValidationResolve( ADD, PathAddress.pathAddress( PathElement.pathElement(SOCKET_BINDING_GROUP), PathElement.pathElement(SOCKET_BINDING))); // Deployment operation validator thinks that content is required initializer.addOperationValidationExclude( ADD, PathAddress.pathAddress( PathElement.pathElement(SERVER_GROUP), PathElement.pathElement(DEPLOYMENT))); }
private ModelNode removeServerGroups(final DomainClient client) throws Exception { final ModelNode op = Util.createEmptyOperation( READ_RESOURCE_OPERATION, PathAddress.pathAddress(PathElement.pathElement(SERVER_GROUP))); final ModelNode results = executeForResult(op, client); ModelNode group = null; for (ModelNode result : results.asList()) { String groupName = PathAddress.pathAddress(result.get(ADDRESS)).getLastElement().getValue(); if (groupName.equals(OTHER_SERVER_GROUP)) { group = result.get(RESULT); } else { ModelNode remove = Util.createRemoveOperation(PathAddress.pathAddress(result.get(ADDRESS))); executeForResult(remove, client); } } Assert.assertNotNull(group); // Add main-server-group as a copy of other-server-group (cuts down on the amount of profiles // needed) final ModelNode addMain = group.clone(); final PathAddress mainServerGroupAddress = PathAddress.pathAddress(SERVER_GROUP, MAIN_SERVER_GROUP); addMain.get(OP).set(ADD); addMain.get(OP_ADDR).set(mainServerGroupAddress.toModelNode()); executeForResult(addMain, client); return group; }
protected void describe( final Resource resource, final ModelNode address, ModelNode result, final ImmutableManagementResourceRegistration registration) { if (registration.isRemote() || registration.isRuntimeOnly() || resource.isProxy() || resource.isRuntime()) { return; } final Set<PathElement> children = registration.getChildAddresses(PathAddress.EMPTY_ADDRESS); result.add(createAddOperation(address, resource.getModel(), children)); for (final PathElement element : children) { if (element.isMultiTarget()) { final String childType = element.getKey(); for (final Resource.ResourceEntry entry : resource.getChildren(childType)) { final ImmutableManagementResourceRegistration childRegistration = registration.getSubModel( PathAddress.pathAddress(PathElement.pathElement(childType, entry.getName()))); final ModelNode childAddress = address.clone(); childAddress.add(childType, entry.getName()); describe(entry, childAddress, result, childRegistration); } } else { final Resource child = resource.getChild(element); final ImmutableManagementResourceRegistration childRegistration = registration.getSubModel(PathAddress.pathAddress(element)); final ModelNode childAddress = address.clone(); childAddress.add(element.getKey(), element.getValue()); describe(child, childAddress, result, childRegistration); } } }
public void addDeploymentOverlays(final List<ModelNode> updates) { if (domainModel.hasDefined(DEPLOYMENT_OVERLAY)) { HostFileRepository remoteRepository = null; if (!domainController.getLocalHostInfo().isMasterDomainController()) { remoteRepository = domainController.getRemoteFileRepository(); } for (Property deploymentOverlay : domainModel.get(DEPLOYMENT_OVERLAY).asPropertyList()) { String name = deploymentOverlay.getName(); ModelNode details = deploymentOverlay.getValue(); PathAddress addr = PathAddress.pathAddress(PathElement.pathElement(DEPLOYMENT_OVERLAY, name)); ModelNode addOp = Util.getEmptyOperation(ADD, addr.toModelNode()); updates.add(addOp); if (details.hasDefined(CONTENT)) { for (Property content : details.get(CONTENT).asPropertyList()) { final String contentName = content.getName(); final ModelNode contentDetails = content.getValue(); byte[] hash = contentDetails.require(CONTENT).asBytes(); File[] files = domainController.getLocalFileRepository().getDeploymentFiles(hash); if (files == null || files.length == 0) { if (remoteRepository != null) { remoteRepository.getDeploymentFiles(hash); } } addr = PathAddress.pathAddress( PathElement.pathElement(DEPLOYMENT_OVERLAY, name), PathElement.pathElement(CONTENT, contentName)); addOp = Util.getEmptyOperation(ADD, addr.toModelNode()); addOp.get(CONTENT).get(HASH).set(contentDetails.get(CONTENT)); updates.add(addOp); } } if (serverGroup.hasDefined(DEPLOYMENT_OVERLAY)) { final ModelNode groupOverlay = serverGroup.get(DEPLOYMENT_OVERLAY).asObject(); if (groupOverlay.has(name)) { ModelNode deploymentsNode = groupOverlay.get(name); if (deploymentsNode.has(DEPLOYMENT)) { for (Property content : deploymentsNode.get(DEPLOYMENT).asPropertyList()) { final String deploymentName = content.getName(); final ModelNode deploymentDetails = content.getValue(); addr = PathAddress.pathAddress( PathElement.pathElement(DEPLOYMENT_OVERLAY, name), PathElement.pathElement(DEPLOYMENT, deploymentName)); addOp = Util.getEmptyOperation(ADD, addr.toModelNode()); updates.add(addOp); } } } } } } }
private void setupNestingProperties() throws IOException, MgmtOperationException { ModelNode opA = Util.createAddOperation(PathAddress.pathAddress("system-property", "A")); opA.get("value").set("a"); executeOperation(opA); ModelNode opB = Util.createAddOperation(PathAddress.pathAddress("system-property", "B")); opA.get("value").set("b"); executeOperation(opB); ModelNode opab = Util.createAddOperation(PathAddress.pathAddress("system-property", "ab")); opA.get("value").set("asd"); executeOperation(opab); }
@Override public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException { final ModelNode address = PathAddress.pathAddress( PathAddress.pathAddress(operation.require(OP_ADDR)).getLastElement()) .toModelNode(); final Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS); final ModelNode result = context.getResult(); describe(resource, address, result, context.getResourceRegistration()); context.completeStep(); }
private AddressControl getAddressControl( final OperationContext context, final ModelNode operation) { final String addressName = PathAddress.pathAddress(operation.require(OP_ADDR)).getLastElement().getValue(); final ServiceName hqServiceName = MessagingServices.getHornetQServiceName( PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR))); ServiceController<?> hqService = context.getServiceRegistry(false).getService(hqServiceName); HornetQServer hqServer = HornetQServer.class.cast(hqService.getValue()); return AddressControl.class.cast( hqServer.getManagementService().getResource(ResourceNames.CORE_ADDRESS + addressName)); }
private void removeUnusedSocketBindingGroups(final DomainClient client, final String keepGroup) throws Exception { final List<String> allGroups = getAllChildrenOfType(client, PathAddress.EMPTY_ADDRESS, SOCKET_BINDING_GROUP); for (String groupName : allGroups) { if (!keepGroup.equals(groupName)) { ModelNode remove = Util.createRemoveOperation( PathAddress.pathAddress(PathAddress.pathAddress(SOCKET_BINDING_GROUP, groupName))); executeForResult(remove, client); } } }
@Test public void testNativeInterface() throws Exception { ModelNode opNode = Util.getReadAttributeOperation( PathAddress.pathAddress(SUBSYSTEM, LogStreamExtension.SUBSYSTEM_NAME), "log-file"); readLogFile(opNode); opNode = Util.createEmptyOperation( LogStreamExtension.STREAM_LOG_FILE, PathAddress.pathAddress(SUBSYSTEM, LogStreamExtension.SUBSYSTEM_NAME)); readLogFile(opNode); }
@Test public void testExcludeLegacy() throws Exception { ModelControllerClient client = getModelControllerClient(); final ModelNode add = Util.createAddOperation( PathAddress.pathAddress( PathAddress.pathAddress() .append(PathElement.pathElement(CORE_SERVICE, MANAGEMENT)) .append(LegacyConfigurationChangeResourceDefinition.PATH))); add.get("max-history").set(MAX_HISTORY_SIZE); ModelNode response = client.execute(add); Assert.assertFalse(Operations.isSuccessfulOutcome(response)); assertThat( Operations.getFailureDescription(response).asString(), containsString("WFLYCTL0158")); }
@Override protected void addBootOperations(List<ModelNode> bootOperations) { if (enableRbac) { for (StandardRole standardRole : EnumSet.allOf(StandardRole.class)) { ModelNode addRoleMappingOp = Util.createAddOperation( PathAddress.pathAddress( CoreManagementResourceDefinition.PATH_ELEMENT, AccessAuthorizationResourceDefinition.PATH_ELEMENT, PathElement.pathElement( RoleMappingResourceDefinition.PATH_KEY, standardRole.getFormalName()))); bootOperations.add(addRoleMappingOp); ModelNode addIncludeUserOp = Util.createAddOperation( PathAddress.pathAddress( CoreManagementResourceDefinition.PATH_ELEMENT, AccessAuthorizationResourceDefinition.PATH_ELEMENT, PathElement.pathElement( RoleMappingResourceDefinition.PATH_KEY, standardRole.getFormalName()), PathElement.pathElement( ModelDescriptionConstants.INCLUDE, "user-" + roleToUserName(standardRole)))); addIncludeUserOp .get(PrincipalResourceDefinition.NAME.getName()) .set(roleToUserName(standardRole)); addIncludeUserOp .get(PrincipalResourceDefinition.TYPE.getName()) .set(PrincipalResourceDefinition.Type.USER.toString()); bootOperations.add(addIncludeUserOp); } ModelNode enableRbacOp = Util.getWriteAttributeOperation( PathAddress.pathAddress( CoreManagementResourceDefinition.PATH_ELEMENT, AccessAuthorizationResourceDefinition.PATH_ELEMENT), AccessAuthorizationResourceDefinition.PROVIDER.getName(), new ModelNode(AccessAuthorizationResourceDefinition.Provider.RBAC.toString())); bootOperations.add(enableRbacOp); } ModelNode addOp = Util.createAddOperation( PathAddress.pathAddress( ModelDescriptionConstants.SUBSYSTEM, JMXExtension.SUBSYSTEM_NAME)); bootOperations.add(addOp); }
String getServerGroupName(final ModelNode operation) { final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR)); if (address.size() == 0) { return null; } return address.getLastElement().getValue(); }
/** {@inheritDoc} */ @Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR)); final PathElement element = address.getLastElement(); context.addStep( new OperationStepHandler() { @Override public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException { final ModelNode result = context.getResult(); final ServiceController<?> controller = context .getServiceRegistry(false) .getRequiredService(SOCKET_BINDING.append(element.getValue())); if (controller != null && controller.getState() == ServiceController.State.UP) { final SocketBinding binding = SocketBinding.class.cast(controller.getValue()); AbstractBindingMetricsHandler.this.execute(operation, binding, result); } else { result.set(getNoMetrics()); } context.stepCompleted(); } }, OperationContext.Stage.RUNTIME); context.stepCompleted(); }
/** * [AS7-5850] Core queues created with ActiveMQ API does not create WildFly resources * * <p>For backwards compatibility if an operation is invoked on a queue that has no corresponding * resources, we forward the operation to the corresponding runtime-queue resource (which *does* * exist). * * @return true if the operation is forwarded to the corresponding runtime-queue resource, false * else. */ static boolean forwardToRuntimeQueue( OperationContext context, ModelNode operation, OperationStepHandler handler) { PathAddress address = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)); // do not forward if the current operation is for a runtime-queue already: if (RUNTIME_QUEUE.equals(address.getLastElement().getKey())) { return false; } String queueName = address.getLastElement().getValue(); PathAddress activeMQPathAddress = MessagingServices.getActiveMQServerPathAddress(address); Resource serverResource = context.readResourceFromRoot(activeMQPathAddress); boolean hasChild = serverResource.hasChild(address.getLastElement()); if (hasChild) { return false; } else { // there is no registered queue resource, forward to the runtime-queue address instead ModelNode forwardOperation = operation.clone(); forwardOperation .get(ModelDescriptionConstants.OP_ADDR) .set(activeMQPathAddress.append(RUNTIME_QUEUE, queueName).toModelNode()); context.addStep(forwardOperation, handler, OperationContext.Stage.RUNTIME, true); return true; } }
@Override protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR)); final String name = address.getLastElement().getValue(); ModClusterService.install(name, context.getServiceTarget(), model, context); }
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR)); final PathElement element = address.getLastElement(); final String serverName = element.getValue(); final ModelNode subModel = context.readModel(PathAddress.EMPTY_ADDRESS); final boolean isStart; if (subModel.hasDefined(AUTO_START)) { isStart = subModel.get(AUTO_START).asBoolean(); } else { isStart = true; } ServerStatus status = serverInventory.determineServerStatus(serverName); if (status == ServerStatus.STOPPED) { status = isStart ? status : ServerStatus.DISABLED; } if (status != null) { context.getResult().set(status.toString()); context.completeStep(); } else { throw new OperationFailedException(new ModelNode().set("Failed to get server status")); } }
@Test public void testParseSubsystem_1_0() throws Exception { String subsystemXml = "<subsystem xmlns=\"urn:jboss:domain:jacorb:1.0\">" + " <orb name=\"JBoss\" print-version=\"off\">" + " <connection retries=\"5\" retry-interval=\"500\" client-timeout=\"0\" server-timeout=\"0\"/>" + " <naming root-context=\"JBoss/Naming/root\" export-corbaloc=\"on\"/>" + " </orb>" + " <poa monitoring=\"off\" queue-wait=\"on\" queue-min=\"10\" queue-max=\"100\">" + " <request-processors pool-size=\"10\" max-threads=\"32\"/>" + " </poa>" + " <interop sun=\"on\" comet=\"off\" chunk-custom-rmi-valuetypes=\"on\"/>" + " <security support-ssl=\"off\" use-domain-socket-factory=\"off\" use-domain-server-socket-factory=\"off\"/>" + " <property key=\"a\" value=\"va\"/>" + " <property key=\"b\" value=\"vb\"/>" + " <initializers>security,transactions</initializers>" + "</subsystem>"; List<ModelNode> operations = super.parse(subsystemXml); // check that we have the expected number of operations. Assert.assertEquals(1, operations.size()); // check that each operation has the correct content. ModelNode addSubsystem = operations.get(0); Assert.assertEquals(ADD, addSubsystem.get(OP).asString()); PathAddress addr = PathAddress.pathAddress(addSubsystem.get(OP_ADDR)); Assert.assertEquals(1, addr.size()); PathElement element = addr.getElement(0); Assert.assertEquals(SUBSYSTEM, element.getKey()); Assert.assertEquals(JacORBExtension.SUBSYSTEM_NAME, element.getValue()); }
private void parseFileStore( XMLExtendedStreamReader reader, ModelNode cache, List<ModelNode> operations) throws XMLStreamException { PathAddress storeAddress = PathAddress.pathAddress(cache.get(OP_ADDR)) .append(ModelKeys.FILE_STORE, ModelKeys.FILE_STORE_NAME); ModelNode store = Util.createAddOperation(storeAddress); for (int i = 0; i < reader.getAttributeCount(); i++) { String value = reader.getAttributeValue(i); Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case RELATIVE_TO: { FileStoreResource.RELATIVE_TO.parseAndSetParameter(value, store, reader); break; } case PATH: { FileStoreResource.PATH.parseAndSetParameter(value, store, reader); break; } default: { this.parseStoreAttribute(reader, i, attribute, value, store); } } } List<ModelNode> additionalConfigurationOperations = new ArrayList<ModelNode>(); this.parseStoreElements(reader, store, additionalConfigurationOperations); operations.add(store); operations.addAll(additionalConfigurationOperations); }
private void parseCustomStore( XMLExtendedStreamReader reader, ModelNode cache, List<ModelNode> operations) throws XMLStreamException { PathAddress storeAddress = PathAddress.pathAddress(cache.get(OP_ADDR)).append(ModelKeys.STORE, ModelKeys.STORE_NAME); ModelNode store = Util.createAddOperation(storeAddress); for (int i = 0; i < reader.getAttributeCount(); i++) { String value = reader.getAttributeValue(i); Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case CLASS: { StoreResource.CLASS.parseAndSetParameter(value, store, reader); break; } default: { this.parseStoreAttribute(reader, i, attribute, value, store); } } } if (!store.hasDefined(ModelKeys.CLASS)) { throw ParseUtils.missingRequired(reader, EnumSet.of(Attribute.CLASS)); } List<ModelNode> additionalConfigurationOperations = new ArrayList<ModelNode>(); this.parseStoreElements(reader, store, additionalConfigurationOperations); operations.add(store); operations.addAll(additionalConfigurationOperations); }
private void parseEviction( XMLExtendedStreamReader reader, ModelNode cache, List<ModelNode> operations) throws XMLStreamException { PathAddress evictionAddress = PathAddress.pathAddress(cache.get(OP_ADDR)) .append(ModelKeys.EVICTION, ModelKeys.EVICTION_NAME); ModelNode eviction = Util.createAddOperation(evictionAddress); for (int i = 0; i < reader.getAttributeCount(); i++) { String value = reader.getAttributeValue(i); Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case STRATEGY: { EvictionResource.EVICTION_STRATEGY.parseAndSetParameter(value, eviction, reader); break; } case MAX_ENTRIES: { EvictionResource.MAX_ENTRIES.parseAndSetParameter(value, eviction, reader); break; } default: { throw ParseUtils.unexpectedAttribute(reader, i); } } } ParseUtils.requireNoContent(reader); operations.add(eviction); }
/** * {@inheritDoc} * * @see * org.jboss.staxmapper.XMLElementReader#readElement(org.jboss.staxmapper.XMLExtendedStreamReader, * Object) */ @Override public void readElement(XMLExtendedStreamReader reader, List<ModelNode> operations) throws XMLStreamException { PathAddress subsystemAddress = PathAddress.pathAddress(InfinispanExtension.SUBSYSTEM_PATH); ModelNode subsystem = Util.createAddOperation(subsystemAddress); // command to add the subsystem operations.add(subsystem); while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) { Element element = Element.forName(reader.getLocalName()); switch (element) { case CACHE_CONTAINER: { parseContainer(reader, subsystemAddress, operations); break; } default: { throw ParseUtils.unexpectedElement(reader); } } } }
/** Tests that the xml is parsed into the correct operations */ @Test public void testParseSubsystem() throws Exception { // Parse the subsystem xml into operations List<ModelNode> operations = super.parse(getSubsystemXml()); /* // print the operations System.out.println("List of operations"); for (ModelNode op : operations) { System.out.println("operation = " + op.toString()); } */ // Check that we have the expected number of operations // one for each resource instance Assert.assertEquals(this.operations, operations.size()); // Check that each operation has the correct content ModelNode addSubsystem = operations.get(0); Assert.assertEquals(ADD, addSubsystem.get(OP).asString()); PathAddress addr = PathAddress.pathAddress(addSubsystem.get(OP_ADDR)); Assert.assertEquals(1, addr.size()); PathElement element = addr.getElement(0); Assert.assertEquals(SUBSYSTEM, element.getKey()); Assert.assertEquals(getMainSubsystemName(), element.getValue()); }
private void compareSubsystemModels() { System.out.println("====== Comparing subsystem models ======"); ResourceDefinition rootCurrentDefinition = new ResourceDefinition(trimNonSubsystem(currentResourceDefinitions), currentModelVersions); ResourceDefinition rootLegacyDefinition = new ResourceDefinition(trimNonSubsystem(legacyResourceDefinitions), legacyModelVersions); Map<String, ModelNode> currentSubsystems = rootCurrentDefinition.getChildren(SUBSYSTEM); Map<String, ModelNode> legacySubsystems = rootLegacyDefinition.getChildren(SUBSYSTEM); CompareContext context = new CompareContext( PathAddress.EMPTY_ADDRESS, PathAddress.EMPTY_ADDRESS, true, rootCurrentDefinition, rootLegacyDefinition); compareKeySetsAndRemoveMissing(context, "subsystems", currentSubsystems, legacySubsystems); for (Map.Entry<String, ModelNode> legacyEntry : legacySubsystems.entrySet()) { PathAddress subsystemAddress = PathAddress.pathAddress(PathElement.pathElement(SUBSYSTEM, legacyEntry.getKey())); ResourceDefinition currentDefinition = new ResourceDefinition(currentSubsystems.get(legacyEntry.getKey()), currentModelVersions); ResourceDefinition legacyDefinition = new ResourceDefinition(legacyEntry.getValue(), legacyModelVersions); context = new CompareContext( subsystemAddress, subsystemAddress, false, currentDefinition, legacyDefinition); if (!context.continuteWithCheck()) { continue; } compareModel(context); } }
private void parseStoreProperty( XMLExtendedStreamReader reader, ModelNode node, final List<ModelNode> operations) throws XMLStreamException { int attributes = reader.getAttributeCount(); String propertyName = null; for (int i = 0; i < attributes; i++) { String value = reader.getAttributeValue(i); Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case NAME: { propertyName = value; break; } default: { throw ParseUtils.unexpectedAttribute(reader, i); } } } if (propertyName == null) { throw ParseUtils.missingRequired(reader, Collections.singleton(Attribute.NAME)); } String propertyValue = reader.getElementText(); PathAddress propertyAddress = PathAddress.pathAddress(node.get(OP_ADDR)).append(ModelKeys.PROPERTY, propertyName); ModelNode property = Util.createAddOperation(propertyAddress); // represent the value as a ModelNode to cater for expressions StorePropertyResource.VALUE.parseAndSetParameter(propertyValue, property, reader); operations.add(property); }