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
  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));
  }
예제 #3
0
  ManagedServer(
      final String hostControllerName,
      final String serverName,
      final String authKey,
      final ProcessControllerClient processControllerClient,
      final URI managementURI,
      final TransformationTarget transformationTarget) {

    assert hostControllerName != null : "hostControllerName is null";
    assert serverName != null : "serverName is null";
    assert processControllerClient != null : "processControllerSlave is null";
    assert managementURI != null : "managementURI is null";

    this.hostControllerName = hostControllerName;
    this.serverName = serverName;
    this.serverProcessName = getServerProcessName(serverName);
    this.processControllerClient = processControllerClient;
    this.managementURI = managementURI;

    this.authKey = authKey;

    // Setup the proxy controller
    final PathElement serverPath = PathElement.pathElement(RUNNING_SERVER, serverName);
    final PathAddress address =
        PathAddress.EMPTY_ADDRESS.append(
            PathElement.pathElement(HOST, hostControllerName), serverPath);
    this.protocolClient = new ManagedServerProxy(this);
    this.proxyController =
        TransformingProxyController.Factory.create(
            protocolClient,
            Transformers.Factory.create(transformationTarget),
            address,
            ProxyOperationAddressTranslator.SERVER);
  }
 /** 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);
 }
 @Override
 public void registerRunningServer(final ProxyController serverControllerClient) {
   PathAddress pa = serverControllerClient.getProxyNodeAddress();
   PathElement pe = pa.getElement(1);
   if (modelNodeRegistration.getProxyController(pa) != null) {
     throw MESSAGES.serverNameAlreadyRegistered(pe.getValue());
   }
   ROOT_LOGGER.registeringServer(pe.getValue());
   // Register the proxy
   final ManagementResourceRegistration hostRegistration =
       modelNodeRegistration.getSubModel(
           PathAddress.pathAddress(
               PathElement.pathElement(HOST, hostControllerInfo.getLocalHostName())));
   hostRegistration.registerProxyController(pe, serverControllerClient);
   // Register local operation overrides
   final ManagementResourceRegistration serverRegistration =
       hostRegistration.getSubModel(PathAddress.EMPTY_ADDRESS.append(pe));
   ServerConfigResourceDefinition.registerServerLifecycleOperations(
       serverRegistration, serverInventory);
   serverProxies.put(pe.getValue(), serverControllerClient);
 }
  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;
  }
예제 #8
0
  @Override
  public void execute(OperationContext context, ModelNode operation)
      throws OperationFailedException {

    final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR));
    final String childType = CHILD_TYPE.resolveModelAttribute(context, operation).asString();

    // Build up the op we're going to repeatedly execute
    final ModelNode readOp = new ModelNode();
    readOp.get(OP).set(READ_RESOURCE_OPERATION);
    INCLUDE_RUNTIME.validateAndSet(operation, readOp);
    RECURSIVE.validateAndSet(operation, readOp);
    RECURSIVE_DEPTH.validateAndSet(operation, readOp);
    PROXIES.validateAndSet(operation, readOp);
    INCLUDE_DEFAULTS.validateAndSet(operation, readOp);

    final Map<PathElement, ModelNode> resources = new HashMap<PathElement, ModelNode>();

    final Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS, false);
    final ImmutableManagementResourceRegistration registry = context.getResourceRegistration();
    Map<String, Set<String>> childAddresses =
        GlobalOperationHandlers.getChildAddresses(context, address, registry, resource, childType);
    Set<String> childNames = childAddresses.get(childType);
    if (childNames == null) {
      throw new OperationFailedException(
          new ModelNode().set(ControllerLogger.ROOT_LOGGER.unknownChildType(childType)));
    }

    // Track any excluded items
    FilteredData filteredData = new FilteredData(address);

    // We're going to add a bunch of steps that should immediately follow this one. We are going to
    // add them
    // in reverse order of how they should execute, building up a stack.

    // Last to execute is the handler that assembles the overall response from the pieces created by
    // all the other steps
    final ReadChildrenResourcesAssemblyHandler assemblyHandler =
        new ReadChildrenResourcesAssemblyHandler(resources, filteredData, address, childType);
    context.addStep(assemblyHandler, OperationContext.Stage.MODEL, true);

    for (final String key : childNames) {
      final PathElement childPath = PathElement.pathElement(childType, key);
      final PathAddress childAddress =
          PathAddress.EMPTY_ADDRESS.append(PathElement.pathElement(childType, key));

      final ModelNode readResOp = readOp.clone();
      readResOp.get(OP_ADDR).set(PathAddress.pathAddress(address, childPath).toModelNode());

      // See if there was an override registered for the standard :read-resource handling
      // (unlikely!!!)
      OperationStepHandler overrideHandler =
          context
              .getResourceRegistration()
              .getOperationHandler(childAddress, READ_RESOURCE_OPERATION);
      if (overrideHandler == null) {
        throw new OperationFailedException(
            new ModelNode().set(ControllerLogger.ROOT_LOGGER.noOperationHandler()));
      } else if (overrideHandler.getClass() == ReadResourceHandler.class) {
        // not an override
        overrideHandler = null;
      }
      OperationStepHandler rrHandler =
          new ReadResourceHandler(filteredData, overrideHandler, false);
      final ModelNode rrRsp = new ModelNode();
      resources.put(childPath, rrRsp);
      context.addStep(rrRsp, readResOp, rrHandler, OperationContext.Stage.MODEL, true);
    }

    context.stepCompleted();
  }