@Test
  public void testServerReadResource() throws IOException {
    DomainClient domainClient = domainMasterLifecycleUtil.getDomainClient();
    final ModelNode serverOp = new ModelNode();
    serverOp.get(OP).set(READ_RESOURCE_OPERATION);
    ModelNode address = serverOp.get(OP_ADDR);
    address.add(HOST, "master");
    address.add(SERVER, "main-one");
    serverOp.get(RECURSIVE).set(true);
    serverOp.get(INCLUDE_RUNTIME).set(true);
    serverOp.get(PROXIES).set(false);

    ModelNode response = domainClient.execute(serverOp);
    validateResponse(response);
    // TODO make some more assertions about result content
    ModelNode result = response.get(RESULT);
    Assert.assertTrue(result.isDefined());
    Assert.assertTrue(result.hasDefined(PROFILE_NAME));

    address.setEmptyList();
    address.add(HOST, "slave");
    address.add(SERVER, "main-three");
    response = domainClient.execute(serverOp);
    validateResponse(response);
    // TODO make some more assertions about result content
    result = response.get(RESULT);
    Assert.assertTrue(result.isDefined());
    Assert.assertTrue(result.hasDefined(PROFILE_NAME));
  }
 protected boolean isAddressValid(CommandContext ctx) {
   final ModelNode request = new ModelNode();
   final ModelNode address = request.get(Util.ADDRESS);
   address.setEmptyList();
   request.get(Util.OPERATION).set(Util.VALIDATE_ADDRESS);
   final ModelNode addressValue = request.get(Util.VALUE);
   for (OperationRequestAddress.Node node : requiredAddress) {
     addressValue.add(node.getType(), node.getName());
   }
   final ModelNode response;
   try {
     response = ctx.getModelControllerClient().execute(request);
   } catch (IOException e) {
     return false;
   }
   final ModelNode result = response.get(Util.RESULT);
   if (!result.isDefined()) {
     return false;
   }
   final ModelNode valid = result.get(Util.VALID);
   if (!valid.isDefined()) {
     return false;
   }
   return valid.asBoolean();
 }
  @Override
  protected void executeReadAttribute(OperationContext context, ModelNode operation)
      throws OperationFailedException {

    final String gcName =
        PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR))
            .getLastElement()
            .getValue();
    final String name = operation.require(ModelDescriptionConstants.NAME).asString();

    GarbageCollectorMXBean gcMBean = null;

    for (GarbageCollectorMXBean mbean : ManagementFactory.getGarbageCollectorMXBeans()) {
      if (gcName.equals(escapeMBeanName(mbean.getName()))) {
        gcMBean = mbean;
      }
    }

    if (gcMBean == null) {
      throw PlatformMBeanLogger.ROOT_LOGGER.unknownGarbageCollector(gcName);
    }

    if (PlatformMBeanConstants.OBJECT_NAME.getName().equals(name)) {
      final String objName =
          PlatformMBeanUtil.getObjectNameStringWithNameKey(
              ManagementFactory.GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE, gcName);
      context.getResult().set(objName);
    } else if (ModelDescriptionConstants.NAME.equals(name)) {
      context.getResult().set(escapeMBeanName(gcMBean.getName()));
    } else if (PlatformMBeanConstants.VALID.getName().equals(name)) {
      context.getResult().set(gcMBean.isValid());
    } else if (PlatformMBeanConstants.MEMORY_POOL_NAMES.equals(name)) {
      final ModelNode result = context.getResult();
      result.setEmptyList();
      for (String pool : gcMBean.getMemoryPoolNames()) {
        result.add(escapeMBeanName(pool));
      }
    } else if (PlatformMBeanConstants.COLLECTION_COUNT.equals(name)) {
      context.getResult().set(gcMBean.getCollectionCount());
    } else if (PlatformMBeanConstants.COLLECTION_TIME.equals(name)) {
      context.getResult().set(gcMBean.getCollectionTime());
    } else if (GarbageCollectorResourceDefinition.GARBAGE_COLLECTOR_READ_ATTRIBUTES.contains(name)
        || GarbageCollectorResourceDefinition.GARBAGE_COLLECTOR_METRICS.contains(name)) {
      // Bug
      throw PlatformMBeanLogger.ROOT_LOGGER.badReadAttributeImpl(name);
    } else {
      // Shouldn't happen; the global handler should reject
      throw unknownAttribute(operation);
    }
  }
  @Override
  protected void executeReadAttribute(OperationContext context, ModelNode operation)
      throws OperationFailedException {

    final String mmName =
        PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR))
            .getLastElement()
            .getValue();
    final String name = operation.require(ModelDescriptionConstants.NAME).asString();

    MemoryManagerMXBean memoryManagerMXBean = null;

    for (MemoryManagerMXBean mbean : ManagementFactory.getMemoryManagerMXBeans()) {
      if (mmName.equals(escapeMBeanName(mbean.getName()))) {
        memoryManagerMXBean = mbean;
      }
    }

    if (memoryManagerMXBean == null) {
      throw PlatformMBeanMessages.MESSAGES.unknownMemoryManager(mmName);
    }

    if (PlatformMBeanUtil.JVM_MAJOR_VERSION > 6
        && PlatformMBeanConstants.OBJECT_NAME.equals(name)) {
      final String objName =
          PlatformMBeanUtil.getObjectNameStringWithNameKey(
              ManagementFactory.MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE, mmName);
      context.getResult().set(objName);
    } else if (ModelDescriptionConstants.NAME.equals(name)) {
      context.getResult().set(escapeMBeanName(memoryManagerMXBean.getName()));
    } else if (PlatformMBeanConstants.VALID.equals(name)) {
      context.getResult().set(memoryManagerMXBean.isValid());
    } else if (PlatformMBeanConstants.MEMORY_POOL_NAMES.equals(name)) {
      final ModelNode result = context.getResult();
      result.setEmptyList();
      for (String pool : memoryManagerMXBean.getMemoryPoolNames()) {
        result.add(escapeMBeanName(pool));
      }
    } else if (PlatformMBeanConstants.MEMORY_MANAGER_READ_ATTRIBUTES.contains(name)) {
      // Bug
      throw PlatformMBeanMessages.MESSAGES.badReadAttributeImpl5(name);
    } else {
      // Shouldn't happen; the global handler should reject
      throw unknownAttribute(operation);
    }
  }
  @Override
  public void execute(OperationContext context, ModelNode operation)
      throws OperationFailedException {

    try {
      long[] ids = ManagementFactory.getThreadMXBean().findDeadlockedThreads();
      final ModelNode result = context.getResult();
      if (ids != null) {
        result.setEmptyList();
        for (long id : ids) {
          result.add(id);
        }
      }
    } catch (SecurityException e) {
      throw new OperationFailedException(new ModelNode().set(e.toString()));
    }

    context.stepCompleted();
  }
  @Test
  public void testServerReadConfigAsXml() throws IOException {

    DomainClient domainClient = domainMasterLifecycleUtil.getDomainClient();
    ModelNode request = new ModelNode();
    request.get(OP).set("read-config-as-xml");
    ModelNode address = request.get(OP_ADDR);
    address.add(HOST, "master");
    address.add(SERVER, "main-one");

    ModelNode response = domainClient.execute(request);
    validateResponse(response);
    // TODO make some more assertions about result content

    address.setEmptyList();
    address.add(HOST, "slave");
    address.add(SERVER, "main-three");
    response = domainClient.execute(request);
    validateResponse(response);
    // TODO make some more assertions about result content
  }
  @Test
  public void testServerReadResourceDescription() throws IOException {

    DomainClient domainClient = domainMasterLifecycleUtil.getDomainClient();
    ModelNode request = new ModelNode();
    request.get(OP).set("read-resource-description");
    ModelNode address = request.get(OP_ADDR);
    address.add(HOST, "master");
    address.add(SERVER, "main-one");
    request.get(RECURSIVE).set(true);
    request.get(OPERATIONS).set(true);

    ModelNode response = domainClient.execute(request);
    validateResponse(response);
    // TODO make getDeploymentManager();some more assertions about result content

    address.setEmptyList();
    address.add(HOST, "slave");
    address.add(SERVER, "main-three");
    response = domainClient.execute(request);
    validateResponse(response);
    // TODO make some more assertions about result content
  }
Beispiel #8
0
  private void addJaspiTestSecurityDomain(final DomainClient client) throws Exception {
    // Before when this test was configured via xml, there was an extra security domain for testing
    // jaspi.
    final PathAddress domain =
        PathAddress.pathAddress(PROFILE, FULL_HA)
            .append(SUBSYSTEM, SecurityExtension.SUBSYSTEM_NAME)
            .append("security-domain", "jaspi-test");
    DomainTestUtils.executeForResult(Util.createAddOperation(domain), client);

    final PathAddress auth = domain.append(AUTHENTICATION, "jaspi");
    DomainTestUtils.executeForResult(Util.createAddOperation(auth), client);

    final PathAddress stack = auth.append("login-module-stack", "lm-stack");
    DomainTestUtils.executeForResult(Util.createAddOperation(stack), client);

    final ModelNode addLoginModule = Util.createAddOperation(stack.append("login-module", "lm"));
    addLoginModule.get("code").set("UsersRoles");
    addLoginModule.get("flag").set("required");
    addLoginModule.get("module").set("test-jaspi");
    final ModelNode options = addLoginModule.get("module-options");
    options.setEmptyList();
    options.add(
        new ModelNode()
            .set("usersProperties", "${jboss.server.config.dir:}/application-users.properties"));
    options.add(
        new ModelNode()
            .set("rolesProperties", "${jboss.server.config.dir:}/application-roles.properties"));
    DomainTestUtils.executeForResult(addLoginModule, client);

    final ModelNode addAuthModule =
        Util.createAddOperation(auth.append("auth-module", getJaspiTestAuthModuleName()));
    addAuthModule.get("code").set(getJaspiTestAuthModuleName());
    addAuthModule.get("login-module-stack-ref").set("lm-stack");
    addAuthModule.get("flag").set("${test.prop:optional}");
    DomainTestUtils.executeForResult(addAuthModule, client);
  }
Beispiel #9
0
  void parseSocketBindingGroup_1_1(
      final XMLExtendedStreamReader reader,
      final Set<String> interfaces,
      final ModelNode address,
      final Namespace expectedNs,
      final List<ModelNode> updates)
      throws XMLStreamException {
    final Set<String> includedGroups = new HashSet<String>();
    // both outbound-socket-bindings and socket-binding names
    final Set<String> uniqueBindingNames = new HashSet<String>();

    // Handle attributes
    final String[] attrValues =
        requireAttributes(
            reader, Attribute.NAME.getLocalName(), Attribute.DEFAULT_INTERFACE.getLocalName());
    final String socketBindingGroupName = attrValues[0];
    final String defaultInterface = attrValues[1];

    final ModelNode groupAddress = new ModelNode().set(address);
    groupAddress.add(SOCKET_BINDING_GROUP, socketBindingGroupName);

    final ModelNode bindingGroupUpdate = new ModelNode();
    bindingGroupUpdate.get(OP_ADDR).set(groupAddress);
    bindingGroupUpdate.get(OP).set(ADD);

    SocketBindingGroupResourceDefinition.DEFAULT_INTERFACE.parseAndSetParameter(
        defaultInterface, bindingGroupUpdate, reader);
    if (bindingGroupUpdate
                .get(SocketBindingGroupResourceDefinition.DEFAULT_INTERFACE.getName())
                .getType()
            != ModelType.EXPRESSION
        && !interfaces.contains(defaultInterface)) {
      throw MESSAGES.unknownInterface(
          defaultInterface,
          Attribute.DEFAULT_INTERFACE.getLocalName(),
          Element.INTERFACES.getLocalName(),
          reader.getLocation());
    }

    final ModelNode includes = bindingGroupUpdate.get(INCLUDES);
    includes.setEmptyList();
    updates.add(bindingGroupUpdate);

    // Handle elements
    while (reader.nextTag() != END_ELEMENT) {
      requireNamespace(reader, expectedNs);
      final Element element = Element.forName(reader.getLocalName());
      switch (element) {
          /* This will be reintroduced for 7.2.0, leave commented out
          case INCLUDE: {
              final String includedGroup = readStringAttributeElement(reader, Attribute.SOCKET_BINDING_GROUP.getLocalName());
              if (!includedGroups.add(includedGroup)) {
                  throw MESSAGES.alreadyDeclared(Attribute.SOCKET_BINDING_GROUP.getLocalName(), includedGroup, reader.getLocation());
              }
              SocketBindingGroupResourceDefinition.INCLUDES.parseAndAddParameterElement(includedGroup, bindingGroupUpdate, reader.getLocation());
              break;
          }
          */
        case SOCKET_BINDING:
          {
            final String bindingName =
                parseSocketBinding(reader, interfaces, groupAddress, updates);
            if (!uniqueBindingNames.add(bindingName)) {
              throw MESSAGES.alreadyDeclared(
                  Element.SOCKET_BINDING.getLocalName(),
                  Element.OUTBOUND_SOCKET_BINDING.getLocalName(),
                  bindingName,
                  Element.SOCKET_BINDING_GROUP.getLocalName(),
                  socketBindingGroupName,
                  reader.getLocation());
            }
            break;
          }
        case OUTBOUND_SOCKET_BINDING:
          {
            final String bindingName =
                parseOutboundSocketBinding(reader, interfaces, groupAddress, updates);
            if (!uniqueBindingNames.add(bindingName)) {
              throw MESSAGES.alreadyDeclared(
                  Element.SOCKET_BINDING.getLocalName(),
                  Element.OUTBOUND_SOCKET_BINDING.getLocalName(),
                  bindingName,
                  Element.SOCKET_BINDING_GROUP.getLocalName(),
                  socketBindingGroupName,
                  reader.getLocation());
            }
            break;
          }
        default:
          throw unexpectedElement(reader);
      }
    }
  }
 static {
   EMPTY.setEmptyList();
   EMPTY.protect();
 }
  @Override
  public void execute(final OperationContext context, final ModelNode operation)
      throws OperationFailedException {

    // read /subsystem=jgroups/stack=* for update
    final Resource resource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS);
    final ModelNode subModel = resource.getModel();

    // validate the protocol type to be added
    ModelNode type = ProtocolResource.TYPE.validateOperation(operation);
    PathElement protocolRelativePath = PathElement.pathElement(ModelKeys.PROTOCOL, type.asString());

    // if child resource already exists, throw OFE
    if (resource.hasChild(protocolRelativePath)) {
      throw JGroupsMessages.MESSAGES.protocolAlreadyDefined(protocolRelativePath.toString());
    }

    // now get the created model
    Resource childResource = context.createResource(PathAddress.pathAddress(protocolRelativePath));
    final ModelNode protocol = childResource.getModel();

    // Process attributes
    for (final AttributeDefinition attribute : attributes) {
      // we use PROPERTIES only to allow the user to pass in a list of properties on store add
      // commands
      // don't copy these into the model
      if (attribute.getName().equals(ModelKeys.PROPERTIES)) continue;

      attribute.validateAndSet(operation, protocol);
    }

    // get the current list of protocol names and add the new protocol
    // this list is used to maintain order
    ModelNode protocols = subModel.get(ModelKeys.PROTOCOLS);
    if (!protocols.isDefined()) {
      protocols.setEmptyList();
    }
    protocols.add(type);

    // Process type specific properties if required
    process(subModel, operation);

    // The protocol parameters  <property name=>value</property>
    if (operation.hasDefined(ModelKeys.PROPERTIES)) {
      for (Property property : operation.get(ModelKeys.PROPERTIES).asPropertyList()) {
        // create a new property=name resource
        final Resource param =
            context.createResource(
                PathAddress.pathAddress(
                    protocolRelativePath,
                    PathElement.pathElement(ModelKeys.PROPERTY, property.getName())));
        final ModelNode value = property.getValue();
        if (!value.isDefined()) {
          throw JGroupsMessages.MESSAGES.propertyNotDefined(
              property.getName(), protocolRelativePath.toString());
        }
        // set the value of the property
        param.getModel().get(ModelDescriptionConstants.VALUE).set(value);
      }
    }
    // This needs a reload
    reloadRequiredStep(context);
    context.completeStep();
  }
 void updateModel(final OperationContext context, ModelNode model, ModelNode listAttribute)
     throws OperationFailedException {
   listAttribute.setEmptyList();
 }