public void readElement(final XMLExtendedStreamReader reader, final List<ModelNode> operationList) throws XMLStreamException { final ModelNode address = new ModelNode().setEmptyList(); if (Element.forName(reader.getLocalName()) != Element.SERVER) { throw unexpectedElement(reader); } Namespace readerNS = Namespace.forUri(reader.getNamespaceURI()); switch (readerNS) { case DOMAIN_1_0: readServerElement_1_0(reader, address, operationList); break; default: // Instead of having to list the remaining versions we just check it is actually a valid // version. for (Namespace current : Namespace.domainValues()) { if (readerNS.equals(current)) { readServerElement_1_1(readerNS, reader, address, operationList); return; } } throw unexpectedElement(reader); } }
protected void readDomainElementAttributes_1_0( XMLExtendedStreamReader reader, ModelNode address, List<ModelNode> list) throws XMLStreamException { final int count = reader.getAttributeCount(); for (int i = 0; i < count; i++) { switch (Namespace.forUri(reader.getAttributeNamespace(i))) { case XML_SCHEMA_INSTANCE: { switch (Attribute.forName(reader.getAttributeLocalName(i))) { case SCHEMA_LOCATION: { parseSchemaLocations(reader, address, list, i); break; } case NO_NAMESPACE_SCHEMA_LOCATION: { // todo, jeez break; } default: { throw unexpectedAttribute(reader, i); } } break; } default: throw unexpectedAttribute(reader, i); } } }
@Override public void readElement(final XMLExtendedStreamReader reader, final List<ModelNode> nodes) throws XMLStreamException { if (Element.forName(reader.getLocalName()) != Element.DOMAIN) { throw unexpectedElement(reader); } Namespace readerNS = Namespace.forUri(reader.getNamespaceURI()); switch (readerNS) { case DOMAIN_1_0: { readDomainElement1_0(reader, new ModelNode(), readerNS, nodes); break; } case DOMAIN_1_1: case DOMAIN_1_2: readDomainElement1_1(reader, new ModelNode(), readerNS, nodes); break; case DOMAIN_1_3: { readDomainElement1_3(reader, new ModelNode(), readerNS, nodes); break; } default: { throw unexpectedElement(reader); } } }
@Override public void readElement(XMLExtendedStreamReader reader, List<ModelNode> operations) throws XMLStreamException { ParseUtils.requireNoAttributes(reader); final Map<String, List<ModelNode>> profileOps = new LinkedHashMap<String, List<ModelNode>>(); while (reader.hasNext() && reader.nextTag() != END_ELEMENT) { if (Namespace.forUri(reader.getNamespaceURI()) != Namespace.UNKNOWN) { throw unexpectedElement(reader); } if (Element.forName(reader.getLocalName()) != Element.SUBSYSTEM) { throw unexpectedElement(reader); } String namespace = reader.getNamespaceURI(); if (profileOps.containsKey(namespace)) { throw ControllerMessages.MESSAGES.duplicateDeclaration("subsystem", reader.getLocation()); } // parse subsystem final List<ModelNode> subsystems = new ArrayList<ModelNode>(); reader.handleAny(subsystems); profileOps.put(namespace, subsystems); } // Let extensions modify the profile Set<ProfileParsingCompletionHandler> completionHandlers = extensionRegistry.getProfileParsingCompletionHandlers(); for (ProfileParsingCompletionHandler completionHandler : completionHandlers) { completionHandler.handleProfileParsingCompletion(profileOps, operations); } for (List<ModelNode> subsystems : profileOps.values()) { operations.addAll(subsystems); } }
private ModelNode loadDomainModel(File file) throws Exception { final QName rootElement = new QName(Namespace.CURRENT.getUriString(), "domain"); final DomainXml parser = new DomainXml(Module.getBootModuleLoader(), null); final XmlConfigurationPersister persister = new XmlConfigurationPersister(file, rootElement, parser, parser); for (Namespace namespace : Namespace.values()) { if (namespace != Namespace.CURRENT) { persister.registerAdditionalRootElement( new QName(namespace.getUriString(), "domain"), parser); } } final List<ModelNode> ops = persister.load(); final ModelNode model = new ModelNode(); final ModelController controller = createController( model, new Setup() { public void setup( Resource resource, ManagementResourceRegistration rootRegistration) { DomainModelUtil.updateCoreModel(resource.getModel()); DomainModelUtil.initializeMasterDomainRegistry( rootRegistration, persister, null, new MockFileRepository(), new MockDomainController(), null); } }); final ModelNode caputreModelOp = new ModelNode(); caputreModelOp.get(OP_ADDR).set(PathAddress.EMPTY_ADDRESS.toModelNode()); caputreModelOp.get(OP).set("capture-model"); final List<ModelNode> toRun = new ArrayList<ModelNode>(ops); toRun.add(caputreModelOp); executeOperations(controller, toRun); // persister.store(model, null).commit(); return model; }
@Override public void readElement(XMLExtendedStreamReader reader, List<ModelNode> operations) throws XMLStreamException { ParseUtils.requireNoAttributes(reader); while (reader.hasNext() && reader.nextTag() != END_ELEMENT) { if (Namespace.forUri(reader.getNamespaceURI()) != Namespace.UNKNOWN) { throw unexpectedElement(reader); } if (Element.forName(reader.getLocalName()) != Element.SUBSYSTEM) { throw unexpectedElement(reader); } reader.handleAny(operations); } }
protected void readDomainElementAttributes_1_3( XMLExtendedStreamReader reader, Namespace expectedNs, ModelNode address, List<ModelNode> list) throws XMLStreamException { final int count = reader.getAttributeCount(); for (int i = 0; i < count; i++) { Namespace ns = Namespace.forUri(reader.getAttributeNamespace(i)); switch (ns) { case XML_SCHEMA_INSTANCE: { switch (Attribute.forName(reader.getAttributeLocalName(i))) { case SCHEMA_LOCATION: { parseSchemaLocations(reader, address, list, i); break; } case NO_NAMESPACE_SCHEMA_LOCATION: { // todo, jeez break; } default: { throw unexpectedAttribute(reader, i); } } break; } default: switch (Attribute.forName(reader.getAttributeLocalName(i))) { case NAME: ModelNode op = new ModelNode(); op.get(OP).set(WRITE_ATTRIBUTE_OPERATION); op.get(NAME).set(NAME); op.get(VALUE).set(ParseUtils.parsePossibleExpression(reader.getAttributeValue(i))); list.add(op); break; default: throw unexpectedAttribute(reader, i); } } } }
private ModelNode loadHostModel(final File file) throws Exception { final QName rootElement = new QName(Namespace.CURRENT.getUriString(), "host"); final HostXml parser = new HostXml(Module.getBootModuleLoader(), null); final XmlConfigurationPersister persister = new XmlConfigurationPersister(file, rootElement, parser, parser); for (Namespace namespace : Namespace.values()) { if (namespace != Namespace.CURRENT) { persister.registerAdditionalRootElement( new QName(namespace.getUriString(), "host"), parser); } } final List<ModelNode> ops = persister.load(); // System.out.println(ops); final ModelNode model = new ModelNode(); final ModelController controller = createController( model, new Setup() { public void setup(Resource resource, ManagementResourceRegistration root) { final Resource host = Resource.Factory.create(); resource.registerChild(PathElement.pathElement(HOST, "master"), host); // TODO maybe make creating of empty nodes part of the MNR description host.registerChild( PathElement.pathElement( ModelDescriptionConstants.CORE_SERVICE, ModelDescriptionConstants.MANAGEMENT), Resource.Factory.create()); host.registerChild( PathElement.pathElement( ModelDescriptionConstants.CORE_SERVICE, ModelDescriptionConstants.SERVICE_CONTAINER), Resource.Factory.create()); final LocalHostControllerInfoImpl hostControllerInfo = new LocalHostControllerInfoImpl(new ControlledProcessState(false)); // Add of the host itself ManagementResourceRegistration hostRegistration = root.registerSubModel( PathElement.pathElement(HOST), HostDescriptionProviders.HOST_ROOT_PROVIDER); // Other root resource operations XmlMarshallingHandler xmh = new XmlMarshallingHandler(persister); hostRegistration.registerOperationHandler( XmlMarshallingHandler.OPERATION_NAME, xmh, xmh, false, OperationEntry.EntryType.PUBLIC); hostRegistration.registerOperationHandler( NamespaceAddHandler.OPERATION_NAME, NamespaceAddHandler.INSTANCE, NamespaceAddHandler.INSTANCE, false); hostRegistration.registerOperationHandler( SchemaLocationAddHandler.OPERATION_NAME, SchemaLocationAddHandler.INSTANCE, SchemaLocationAddHandler.INSTANCE, false); hostRegistration.registerReadWriteAttribute( NAME, null, new WriteAttributeHandlers.StringLengthValidatingHandler(1), AttributeAccess.Storage.CONFIGURATION); hostRegistration.registerReadOnlyAttribute( MASTER, IsMasterHandler.INSTANCE, AttributeAccess.Storage.RUNTIME); // System Properties ManagementResourceRegistration sysProps = hostRegistration.registerSubModel( PathElement.pathElement(SYSTEM_PROPERTY), HostDescriptionProviders.SYSTEM_PROPERTIES_PROVIDER); sysProps.registerOperationHandler( SystemPropertyAddHandler.OPERATION_NAME, SystemPropertyAddHandler.INSTANCE_WITH_BOOTTIME, SystemPropertyAddHandler.INSTANCE_WITH_BOOTTIME, false); // vault ManagementResourceRegistration vault = hostRegistration.registerSubModel( PathElement.pathElement(CORE_SERVICE, VAULT), CommonProviders.VAULT_PROVIDER); VaultAddHandler vah = new VaultAddHandler(new MockVaultReader()); vault.registerOperationHandler(VaultAddHandler.OPERATION_NAME, vah, vah, false); // Central Management ManagementResourceRegistration management = hostRegistration.registerSubModel( PathElement.pathElement(CORE_SERVICE, MANAGEMENT), CommonProviders.MANAGEMENT_WITH_INTERFACES_PROVIDER); ManagementResourceRegistration securityRealm = management.registerSubModel( PathElement.pathElement(SECURITY_REALM), CommonProviders.MANAGEMENT_SECURITY_REALM_PROVIDER); securityRealm.registerOperationHandler( SecurityRealmAddHandler.OPERATION_NAME, SecurityRealmAddHandler.INSTANCE, SecurityRealmAddHandler.INSTANCE, false); ManagementResourceRegistration connection = management.registerSubModel( PathElement.pathElement(OUTBOUND_CONNECTION), CommonProviders.MANAGEMENT_OUTBOUND_CONNECTION_PROVIDER); connection.registerOperationHandler( ConnectionAddHandler.OPERATION_NAME, ConnectionAddHandler.INSTANCE, ConnectionAddHandler.INSTANCE, false); // Management API protocols management.registerSubModel( new NativeManagementResourceDefinition(hostControllerInfo)); management.registerSubModel( new HttpManagementResourceDefinition(hostControllerInfo, null)); // Domain controller LocalDomainControllerAddHandler localDcAddHandler = new MockLocalDomainControllerAddHandler(); hostRegistration.registerOperationHandler( LocalDomainControllerAddHandler.OPERATION_NAME, localDcAddHandler, localDcAddHandler, false); RemoteDomainControllerAddHandler remoteDcAddHandler = new MockRemoteDomainControllerAddHandler(); hostRegistration.registerOperationHandler( RemoteDomainControllerAddHandler.OPERATION_NAME, remoteDcAddHandler, remoteDcAddHandler, false); // Jvms final ManagementResourceRegistration jvms = hostRegistration.registerSubModel( PathElement.pathElement(JVM), CommonProviders.JVM_PROVIDER); JVMHandlers.register(jvms); // Paths ManagementResourceRegistration paths = hostRegistration.registerSubModel( PathElement.pathElement(PATH), CommonProviders.SPECIFIED_PATH_PROVIDER); paths.registerOperationHandler( PathAddHandler.OPERATION_NAME, PathAddHandler.SPECIFIED_INSTANCE, PathAddHandler.SPECIFIED_INSTANCE, false); // interface ManagementResourceRegistration interfaces = hostRegistration.registerSubModel( PathElement.pathElement(INTERFACE), CommonProviders.SPECIFIED_INTERFACE_PROVIDER); HostSpecifiedInterfaceAddHandler hsiah = new HostSpecifiedInterfaceAddHandler(hostControllerInfo); interfaces.registerOperationHandler( InterfaceAddHandler.OPERATION_NAME, hsiah, hsiah, false); InterfaceCriteriaWriteHandler.register(interfaces); // server ManagementResourceRegistration servers = hostRegistration.registerSubModel( PathElement.pathElement(SERVER_CONFIG), HostDescriptionProviders.SERVER_PROVIDER); servers.registerOperationHandler( ServerAddHandler.OPERATION_NAME, ServerAddHandler.INSTANCE, ServerAddHandler.INSTANCE, false); servers.registerReadWriteAttribute( AUTO_START, null, new WriteAttributeHandlers.ModelTypeValidatingHandler(ModelType.BOOLEAN), AttributeAccess.Storage.CONFIGURATION); servers.registerReadWriteAttribute( SOCKET_BINDING_GROUP, null, WriteAttributeHandlers.WriteAttributeOperationHandler.INSTANCE, AttributeAccess.Storage.CONFIGURATION); servers.registerReadWriteAttribute( SOCKET_BINDING_PORT_OFFSET, null, new WriteAttributeHandlers.IntRangeValidatingHandler(0), AttributeAccess.Storage.CONFIGURATION); servers.registerReadWriteAttribute( PRIORITY, null, new WriteAttributeHandlers.IntRangeValidatingHandler(0), AttributeAccess.Storage.CONFIGURATION); servers.registerReadWriteAttribute( CPU_AFFINITY, null, new WriteAttributeHandlers.StringLengthValidatingHandler(1), AttributeAccess.Storage.CONFIGURATION); // server paths ManagementResourceRegistration serverPaths = servers.registerSubModel( PathElement.pathElement(PATH), CommonProviders.SPECIFIED_INTERFACE_PROVIDER); serverPaths.registerOperationHandler( PathAddHandler.OPERATION_NAME, PathAddHandler.SPECIFIED_INSTANCE, PathAddHandler.SPECIFIED_INSTANCE, false); // server interfaces ManagementResourceRegistration serverInterfaces = servers.registerSubModel( PathElement.pathElement(INTERFACE), CommonProviders.SPECIFIED_INTERFACE_PROVIDER); serverInterfaces.registerOperationHandler( InterfaceAddHandler.OPERATION_NAME, SpecifiedInterfaceAddHandler.INSTANCE, SpecifiedInterfaceAddHandler.INSTANCE, false); InterfaceCriteriaWriteHandler.register(serverInterfaces); // Server system Properties ManagementResourceRegistration serverSysProps = servers.registerSubModel( PathElement.pathElement(SYSTEM_PROPERTY), HostDescriptionProviders.SERVER_SYSTEM_PROPERTIES_PROVIDER); serverSysProps.registerOperationHandler( SystemPropertyAddHandler.OPERATION_NAME, SystemPropertyAddHandler.INSTANCE_WITH_BOOTTIME, SystemPropertyAddHandler.INSTANCE_WITH_BOOTTIME, false); serverSysProps.registerReadWriteAttribute( VALUE, null, SystemPropertyValueWriteAttributeHandler.INSTANCE, AttributeAccess.Storage.CONFIGURATION); serverSysProps.registerReadWriteAttribute( BOOT_TIME, null, new WriteAttributeHandlers.ModelTypeValidatingHandler(ModelType.BOOLEAN), AttributeAccess.Storage.CONFIGURATION); // Server jvm final ManagementResourceRegistration serverVMs = servers.registerSubModel( PathElement.pathElement(JVM), JVMHandlers.SERVER_MODEL_PROVIDER); JVMHandlers.register(serverVMs, true); } }); final ModelNode caputreModelOp = new ModelNode(); caputreModelOp.get(OP_ADDR).set(PathAddress.EMPTY_ADDRESS.toModelNode()); caputreModelOp.get(OP).set("capture-model"); final List<ModelNode> toRun = new ArrayList<ModelNode>(ops); toRun.add(caputreModelOp); executeOperations(controller, toRun); model.get(HOST, "master", NAME).set("master"); persister.store(model.get(HOST, "master"), null).commit(); // System.out.println(model.toString()); return model; }
void parseProfiles( final XMLExtendedStreamReader reader, final ModelNode address, final Namespace expectedNs, final List<ModelNode> list) throws XMLStreamException { requireNoAttributes(reader); final Set<String> names = new HashSet<String>(); while (reader.nextTag() != END_ELEMENT) { requireNamespace(reader, expectedNs); Element element = Element.forName(reader.getLocalName()); if (Element.PROFILE != element) { throw unexpectedElement(reader); } // Attributes requireSingleAttribute(reader, Attribute.NAME.getLocalName()); final String name = reader.getAttributeValue(0); if (!names.add(name)) { throw MESSAGES.duplicateDeclaration("profile", name, reader.getLocation()); } // final Set<String> includes = new HashSet<String>(); // See commented out section below. // final ModelNode profileIncludes = new ModelNode(); // Content // Sequence final Map<String, List<ModelNode>> profileOps = new LinkedHashMap<String, List<ModelNode>>(); while (reader.nextTag() != END_ELEMENT) { Namespace ns = Namespace.forUri(reader.getNamespaceURI()); switch (ns) { case UNKNOWN: { if (Element.forName(reader.getLocalName()) != Element.SUBSYSTEM) { throw unexpectedElement(reader); } String namespace = reader.getNamespaceURI(); if (profileOps.containsKey(namespace)) { throw MESSAGES.duplicateDeclaration("subsystem", name, reader.getLocation()); } // parse content final List<ModelNode> subsystems = new ArrayList<ModelNode>(); reader.handleAny(subsystems); profileOps.put(namespace, subsystems); break; } case DOMAIN_1_0: case DOMAIN_1_1: case DOMAIN_1_2: case DOMAIN_1_3: { requireNamespace(reader, expectedNs); // include should come first if (profileOps.size() > 0) { throw unexpectedElement(reader); } if (Element.forName(reader.getLocalName()) != Element.INCLUDE) { throw unexpectedElement(reader); } // Remove support for profile includes until 7.2.0 if (ns == Namespace.DOMAIN_1_0) { HOST_CONTROLLER_LOGGER.warnIgnoringProfileInclude(reader.getLocation()); } throw unexpectedElement(reader); /* This will be reintroduced for 7.2.0, leave commented out final String includedName = readStringAttributeElement(reader, Attribute.PROFILE.getLocalName()); if (! names.contains(includedName)) { throw MESSAGES.profileNotFound(reader.getLocation()); } if (! includes.add(includedName)) { throw MESSAGES.duplicateProfile(reader.getLocation()); } profileIncludes.add(includedName); break; */ } default: { throw unexpectedElement(reader); } } } // Let extensions modify the profile Set<ProfileParsingCompletionHandler> completionHandlers = extensionRegistry.getProfileParsingCompletionHandlers(); for (ProfileParsingCompletionHandler completionHandler : completionHandlers) { completionHandler.handleProfileParsingCompletion(profileOps, list); } final ModelNode profile = new ModelNode(); profile.get(OP).set(ADD); profile.get(OP_ADDR).set(address).add(ModelDescriptionConstants.PROFILE, name); /* This will be reintroduced for 7.2.0, leave commented out profile.get(INCLUDES).set(profileIncludes); */ list.add(profile); // Process subsystems for (List<ModelNode> subsystems : profileOps.values()) { for (final ModelNode update : subsystems) { // Process relative subsystem path address final ModelNode subsystemAddress = address.clone().set(address).add(ModelDescriptionConstants.PROFILE, name); for (final Property path : update.get(OP_ADDR).asPropertyList()) { subsystemAddress.add(path.getName(), path.getValue().asString()); } update.get(OP_ADDR).set(subsystemAddress); list.add(update); } } if (profileOps.size() == 0) { throw MESSAGES.profileHasNoSubsystems(reader.getLocation()); } } }
/** * Read the <server/> element based on version 1.1 of the schema. * * @param reader the xml stream reader * @param address address of the parent resource of any resources this method will add * @param list the list of boot operations to which any new operations should be added * @throws XMLStreamException if a parsing error occurs */ private void readServerElement_1_1( final Namespace namespace, final XMLExtendedStreamReader reader, final ModelNode address, final List<ModelNode> list) throws XMLStreamException { parseNamespaces(reader, address, list); String serverName = null; // attributes final int count = reader.getAttributeCount(); for (int i = 0; i < count; i++) { switch (Namespace.forUri(reader.getAttributeNamespace(i))) { case NONE: { final String value = reader.getAttributeValue(i); final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case NAME: { serverName = value; break; } default: throw unexpectedAttribute(reader, i); } break; } case XML_SCHEMA_INSTANCE: { switch (Attribute.forName(reader.getAttributeLocalName(i))) { case SCHEMA_LOCATION: { parseSchemaLocations(reader, address, list, i); break; } case NO_NAMESPACE_SCHEMA_LOCATION: { // todo, jeez break; } default: { throw unexpectedAttribute(reader, i); } } break; } default: throw unexpectedAttribute(reader, i); } } setServerName(address, list, serverName); // elements - sequence Element element = nextElement(reader, namespace); if (element == Element.EXTENSIONS) { extensionXml.parseExtensions(reader, address, namespace, list); element = nextElement(reader, namespace); } // System properties if (element == Element.SYSTEM_PROPERTIES) { parseSystemProperties(reader, address, namespace, list, true); element = nextElement(reader, namespace); } if (element == Element.PATHS) { parsePaths(reader, address, namespace, list, true); element = nextElement(reader, namespace); } if (element == Element.VAULT) { switch (namespace) { // Less than 1.1 does not end up in this method case DOMAIN_1_1: case DOMAIN_1_2: case DOMAIN_1_3: case DOMAIN_1_4: case DOMAIN_1_5: case DOMAIN_2_0: case DOMAIN_2_1: { parseVault_1_1(reader, address, namespace, list); break; } default: { parseVault_3_0(reader, address, namespace, list); } } element = nextElement(reader, namespace); } // Single profile if (element == Element.PROFILE) { parseServerProfile(reader, address, list); element = nextElement(reader, namespace); } // Interfaces final Set<String> interfaceNames = new HashSet<String>(); if (element == Element.INTERFACES) { parseInterfaces(reader, interfaceNames, address, namespace, list, true); element = nextElement(reader, namespace); } // Single socket binding group if (element == Element.SOCKET_BINDING_GROUP) { parseSocketBindingGroup(reader, interfaceNames, address, namespace, list); element = nextElement(reader, namespace); } if (element != null) { throw unexpectedElement(reader); } }