@Test public void testProductInfo() throws Exception { final ModelNode setOrganizationOp = Util.getWriteAttributeOperation(PathAddress.EMPTY_ADDRESS, ORGANIZATION, "wildfly-core"); executeOperation(setOrganizationOp, true); final ModelNode operation = new ModelNode(); operation.get(OP_ADDR).set(PathAddress.EMPTY_ADDRESS.toModelNode()); operation.get(OP).set(OPERATION_NAME); final List<Property> result = executeOperation(operation, true).asPropertyList(); assertThat(result.size(), is(1)); assertThat(result.get(0).getName(), is(SUMMARY)); final ModelNode report = result.get(0).getValue(); assertThat(report.isDefined(), is(true)); assertThat(report.hasDefined(NODE_NAME), is(false)); assertThat(report.hasDefined(HOSTNAME), is(true)); assertThat(report.hasDefined(HOSTNAME), is(true)); assertThat(report.hasDefined(ORGANIZATION), is(true)); assertThat(report.get(ORGANIZATION).asString(), is("wildfly-core")); assertThat(report.hasDefined(PRODUCT_COMMUNITY_IDENTIFIER), is(true)); assertThat(report.get(PRODUCT_COMMUNITY_IDENTIFIER).asString(), is(PROJECT_TYPE)); assertThat(report.hasDefined(STANDALONE_DOMAIN_IDENTIFIER), is(true)); assertThat( report.get(STANDALONE_DOMAIN_IDENTIFIER).asString(), is(ProcessType.STANDALONE_SERVER.name())); assertThat(report.hasDefined(OS), is(true)); assertThat(report.hasDefined(CPU), is(true)); assertThat(report.get(CPU).hasDefined(ARCH), is(true)); assertThat(report.get(CPU).hasDefined(AVAILABLE_PROCESSORS), is(true)); assertThat(report.hasDefined(JVM), is(true)); assertThat(report.get(JVM).hasDefined(NAME), is(true)); assertThat(report.get(JVM).hasDefined(JVM_VENDOR), is(true)); assertThat(report.get(JVM).hasDefined(JVM_VERSION), is(true)); assertThat(report.get(JVM).hasDefined(JVM_HOME), is(true)); }
private ModelNode loadDomainModel(File file) throws Exception { final QName rootElement = new QName(Namespace.CURRENT.getUriString(), "domain"); final DomainXml parser = new DomainXml(Module.getBootModuleLoader()); final XmlConfigurationPersister persister = new XmlConfigurationPersister(file, rootElement, parser, 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(), null, 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; }
/** Test of authorizeAddress method, of class AuthorizedAddress. */ @Test public void testAccessUnauthorizedAddress() { ModelNode address = PathAddress.pathAddress( PathElement.pathElement(DEPLOYMENT, "test.war"), PathElement.pathElement(SUBSYSTEM, "Undertow")) .toModelNode(); ModelNode authorizedAddress = PathAddress.EMPTY_ADDRESS.toModelNode(); OperationContext context = new AuthorizationOperationContext(authorizedAddress.asString()); ModelNode operation = new ModelNode(); operation.get(OP).set(READ_RESOURCE_OPERATION); operation.get(OP_ADDR).set(address); AuthorizedAddress expResult = new AuthorizedAddress( PathAddress.pathAddress(PathElement.pathElement(DEPLOYMENT, "<hidden>")).toModelNode(), true); AuthorizedAddress result = AuthorizedAddress.authorizeAddress(context, operation); assertEquals(expResult, result); }
private ModelNode loadServerModel(final File file) throws Exception { final QName rootElement = new QName(Namespace.CURRENT.getUriString(), "server"); final StandaloneXml parser = new StandaloneXml(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(), "server"), 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) { ServerControllerModelUtil.updateCoreModel(model); ServerControllerModelUtil.initOperations( rootRegistration, null, persister, null, null, null, false); } }); 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; }
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; }