@org.junit.Ignore("AS7-2480")
  @Test
  public void testMessageMovement() throws Exception {

    MessageProducer producer = session.createProducer(queue);
    Message msgA = session.createTextMessage("A");
    producer.send(msgA);
    producer.send(session.createTextMessage("B"));
    producer.send(session.createTextMessage("C"));

    ModelNode op = getQueueOperation("move-message");
    op.get("message-id").set(msgA.getJMSMessageID());
    op.get("other-queue-name").set(getOtherQueueName());

    ModelNode result = execute(op, true);
    Assert.assertTrue(result.isDefined());
    Assert.assertTrue(result.asBoolean());

    result = execute(getQueueOperation("count-messages"), true);
    Assert.assertTrue(result.isDefined());
    Assert.assertEquals(2, result.asInt());

    op = getQueueOperation("move-messages");
    op.get("other-queue-name").set(getOtherQueueName());

    result = execute(op, true);
    Assert.assertTrue(result.isDefined());
    Assert.assertEquals(2, result.asInt());

    result = execute(getQueueOperation("count-messages"), true);
    Assert.assertTrue(result.isDefined());
    Assert.assertEquals(0, result.asInt());
  }
  @Test
  public void testChangeMessagePriority() throws Exception {

    MessageProducer producer = session.createProducer(queue);
    Message msgA = session.createTextMessage("A");
    producer.send(msgA);
    producer.send(session.createTextMessage("B"));
    producer.send(session.createTextMessage("C"));

    Set<Integer> priorities = new HashSet<Integer>();
    ModelNode result = execute(getQueueOperation("list-messages"), true);
    Assert.assertEquals(3, result.asInt());
    for (ModelNode node : result.asList()) {
      priorities.add(node.get("JMSPriority").asInt());
    }
    int newPriority = -1;
    for (int i = 0; i < 10; i++) {
      if (!priorities.contains(i)) {
        newPriority = i;
        break;
      }
    }

    ModelNode op = getQueueOperation("change-message-priority");
    op.get("message-id").set(msgA.getJMSMessageID());
    op.get("new-priority").set(newPriority);

    result = execute(op, true);
    Assert.assertTrue(result.isDefined());
    Assert.assertTrue(result.asBoolean());

    result = execute(getQueueOperation("list-messages"), true);
    boolean found = false;
    for (ModelNode node : result.asList()) {
      if (msgA.getJMSMessageID().equals(node.get("JMSMessageID").asString())) {
        Assert.assertEquals(newPriority, node.get("JMSPriority").asInt());
        found = true;
        break;
      }
    }
    Assert.assertTrue(found);

    op = getQueueOperation("change-messages-priority");
    op.get("new-priority").set(newPriority);

    result = execute(op, true);
    Assert.assertTrue(result.isDefined());
    Assert.assertTrue(result.asInt() > 1 && result.asInt() < 4);

    result = execute(getQueueOperation("list-messages"), true);
    for (ModelNode node : result.asList()) {
      Assert.assertEquals(newPriority, node.get("JMSPriority").asInt());
    }
  }
  @Override
  public void marshallAsElement(ModelNode resourceModel, XMLStreamWriter writer)
      throws XMLStreamException {
    if (resourceModel.hasDefined(getName()) && resourceModel.asInt() > 0) {
      final ModelNode modules = resourceModel.get(getName());
      for (ModelNode module : modules.asList()) {
        writer.writeStartElement(getXmlName());
        writer.writeAttribute(Attribute.CODE.getLocalName(), module.get(CODE).asString());
        if (module.hasDefined(Constants.LOGIN_MODULE_STACK_REF)) {
          writer.writeAttribute(
              Attribute.LOGIN_MODULE_STACK_REF.getLocalName(),
              module.get(Constants.LOGIN_MODULE_STACK_REF).asString());
        }

        if (module.hasDefined(Constants.MODULE_OPTIONS)) {
          for (ModelNode option : module.get(Constants.MODULE_OPTIONS).asList()) {
            writer.writeEmptyElement(Element.MODULE_OPTION.getLocalName());
            writer.writeAttribute(Attribute.NAME.getLocalName(), option.asProperty().getName());
            writer.writeAttribute(
                Attribute.VALUE.getLocalName(), option.asProperty().getValue().asString());
          }
        }
        writer.writeEndElement();
      }
    }
  }
示例#4
0
 private Integer intAttribute(
     OperationContext context, ModelNode model, AttributeDefinition defn, Integer defaultValue)
     throws OperationFailedException {
   ModelNode value = defn.resolveModelAttribute(context, model);
   if (value == null || !value.isDefined()) return defaultValue;
   return value.asInt();
 }
示例#5
0
  @Test
  public void test() throws Exception {
    final ModelController controller = getController();

    final ModelNode address = new ModelNode();
    address.add("host", "*");
    address.add("server", "[one,two]");
    address.add("subsystem", "web");
    address.add("connector", "*");

    final ModelNode read = new ModelNode();
    read.get(OP).set("read-resource");
    read.get(OP_ADDR).set(address);

    ModelNode result = controller.execute(read, null, null, null);
    System.out.println(result);
    result = result.get("result");

    Assert.assertEquals(4, result.asInt()); // A,B one,two

    final ModelNode describe = new ModelNode();
    describe.get(OP).set("describe");
    describe.get(OP_ADDR).set(address);

    result = controller.execute(describe, null, null, null).get("result");
  }
示例#6
0
 public final List<Integer> intListValue() {
   List<ModelNode> listValue = listValue();
   List<Integer> result = new ArrayList<Integer>(listValue.size());
   for (ModelNode value : listValue) {
     result.add(value.asInt());
   }
   return Collections.unmodifiableList(result);
 }
  private IdentityStoreConfigurationBuilder<?, ?> configureFileIdentityStore(
      OperationContext context,
      ServiceBuilder<PartitionManager> serviceBuilder,
      ServiceVerificationHandler verificationHandler,
      List<ServiceController<?>> newControllers,
      PartitionManagerService partitionManagerService,
      ModelNode resource,
      String configurationName,
      final NamedIdentityConfigurationBuilder builder)
      throws OperationFailedException {
    FileStoreConfigurationBuilder fileStoreBuilder = builder.stores().file();
    String workingDir =
        FileStoreResourceDefinition.WORKING_DIR.resolveModelAttribute(context, resource).asString();
    String relativeTo =
        FileStoreResourceDefinition.RELATIVE_TO.resolveModelAttribute(context, resource).asString();
    ModelNode alwaysCreateFiles =
        FileStoreResourceDefinition.ALWAYS_CREATE_FILE.resolveModelAttribute(context, resource);
    ModelNode asyncWrite =
        FileStoreResourceDefinition.ASYNC_WRITE.resolveModelAttribute(context, resource);
    ModelNode asyncWriteThreadPool =
        FileStoreResourceDefinition.ASYNC_WRITE_THREAD_POOL.resolveModelAttribute(
            context, resource);

    fileStoreBuilder.preserveState(!alwaysCreateFiles.asBoolean());
    fileStoreBuilder.asyncWrite(asyncWrite.asBoolean());
    fileStoreBuilder.asyncWriteThreadPool(asyncWriteThreadPool.asInt());

    if (serviceBuilder != null) {
      FileIdentityStoreService storeService =
          new FileIdentityStoreService(fileStoreBuilder, workingDir, relativeTo);
      ServiceName storeServiceName =
          PartitionManagerService.createIdentityStoreServiceName(
              partitionManagerService.getName(),
              configurationName,
              ModelElement.FILE_STORE.getName());
      ServiceBuilder<FileIdentityStoreService> storeServiceBuilder =
          context.getServiceTarget().addService(storeServiceName, storeService);

      storeServiceBuilder.addDependency(
          PathManagerService.SERVICE_NAME, PathManager.class, storeService.getPathManager());

      serviceBuilder.addDependency(storeServiceName);

      if (verificationHandler != null) {
        storeServiceBuilder.addListener(verificationHandler);
      }

      ServiceController<FileIdentityStoreService> controller =
          storeServiceBuilder.setInitialMode(Mode.PASSIVE).install();

      if (newControllers != null) {
        newControllers.add(controller);
      }
    }

    return fileStoreBuilder;
  }
示例#8
0
 void updateModel(final OperationContext context, ModelNode model, ModelNode listAttribute)
     throws OperationFailedException {
   ModelNode value = VALUE.resolveModelAttribute(context, model);
   ModelNode index = INDEX.resolveModelAttribute(context, model);
   List<ModelNode> res = new ArrayList<>(listAttribute.asList());
   if (index.isDefined()) {
     res.remove(index.asInt());
   } else {
     res.remove(value);
   }
   listAttribute.set(res);
 }
  /**
   * Creates and returns a {@link org.jboss.dmr.ModelNode} using the given {@code value} after first
   * validating the node against {@link #getValidator() this object's validator}.
   *
   * <p>If {@code value} is {@code null} and a {@link #getDefaultValue() default value} is
   * available, the value of that default value will be used.
   *
   * @param value the value. Will be {@link String#trim() trimmed} before use if not {@code null}.
   * @param location current location of the parser's {@link javax.xml.stream.XMLStreamReader}. Used
   *     for any exception message
   * @return {@code ModelNode} representing the parsed value
   * @throws javax.xml.stream.XMLStreamException if {@code value} is not valid
   */
  public ModelNode parse(final String value, final Location location) throws XMLStreamException {

    final String trimmed = value == null ? null : value.trim();
    ModelNode node;
    if (trimmed != null) {
      if (isAllowExpression()) {
        node = ParseUtils.parsePossibleExpression(trimmed);
      } else {
        node = new ModelNode().set(trimmed);
      }
      if (node.getType() != ModelType.EXPRESSION) {
        // Convert the string to the expected type
        switch (getType()) {
          case BIG_DECIMAL:
            node.set(node.asBigDecimal());
            break;
          case BIG_INTEGER:
            node.set(node.asBigInteger());
            break;
          case BOOLEAN:
            node.set(node.asBoolean());
            break;
          case BYTES:
            node.set(node.asBytes());
            break;
          case DOUBLE:
            node.set(node.asDouble());
            break;
          case INT:
            node.set(node.asInt());
            break;
          case LONG:
            node.set(node.asLong());
            break;
        }
      }
    } else if (getDefaultValue().isDefined()) {
      node = new ModelNode().set(getDefaultValue());
    } else {
      node = new ModelNode();
    }

    try {
      getValidator().validateParameter(getXmlName(), node);
    } catch (OperationFailedException e) {
      throw new XMLStreamException(e.getFailureDescription().toString(), location);
    }

    return node;
  }
  @Test
  public void testListAndCountMessages() throws Exception {

    MessageProducer producer = session.createProducer(queue);
    producer.send(session.createTextMessage("A"));
    producer.send(session.createTextMessage("B"));

    ModelNode result = execute(getQueueOperation("list-messages"), true);
    Assert.assertTrue(result.isDefined());
    Assert.assertEquals(2, result.asList().size());

    result = execute(getQueueOperation("count-messages"), true);
    Assert.assertTrue(result.isDefined());
    Assert.assertEquals(2, result.asInt());
  }
示例#11
0
    void updateModel(final OperationContext context, ModelNode model, ModelNode listAttribute)
        throws OperationFailedException {
      String value = VALUE.resolveModelAttribute(context, model).asString();
      ModelNode indexNode = INDEX.resolveModelAttribute(context, model);

      LinkedList<ModelNode> res =
          new LinkedList<>(
              listAttribute.isDefined()
                  ? listAttribute.asList()
                  : Collections.<ModelNode>emptyList());
      if (indexNode.isDefined()) {
        res.add(indexNode.asInt(), new ModelNode(value));
      } else {
        res.add(new ModelNode(value));
      }
      listAttribute.set(res);
    }
示例#12
0
 public static ModelNode parseAttributeValue(
     final String value, final boolean isExpressionAllowed, final ModelType attributeType) {
   final String trimmed = value == null ? null : value.trim();
   ModelNode node;
   if (trimmed != null) {
     if (isExpressionAllowed && isExpression(trimmed)) {
       node = new ModelNode(new ValueExpression(trimmed));
     } else {
       if (attributeType == STRING || attributeType == PROPERTY) {
         node = new ModelNode().set(value);
       } else {
         node = new ModelNode().set(trimmed);
       }
     }
     if (node.getType() != ModelType.EXPRESSION) {
       // Convert the string to the expected type
       switch (attributeType) {
         case BIG_DECIMAL:
           node.set(node.asBigDecimal());
           break;
         case BIG_INTEGER:
           node.set(node.asBigInteger());
           break;
         case BOOLEAN:
           node.set(node.asBoolean());
           break;
         case BYTES:
           node.set(node.asBytes());
           break;
         case DOUBLE:
           node.set(node.asDouble());
           break;
         case INT:
           node.set(node.asInt());
           break;
         case LONG:
           node.set(node.asLong());
           break;
       }
     }
   } else {
     node = new ModelNode();
   }
   return node;
 }
示例#13
0
 protected static OptionMap getOptions(ModelNode properties) {
   final OptionMap optionMap;
   if (properties.isDefined() && properties.asInt() > 0) {
     OptionMap.Builder builder = OptionMap.builder();
     final ClassLoader loader = SecurityActions.getClassLoader(ConnectorResource.class);
     for (Property property : properties.asPropertyList()) {
       String name = property.getName();
       if (!name.contains(".")) {
         name = "org.xnio.Options." + name;
       }
       final Option option = Option.fromString(name, loader);
       builder.set(
           option,
           option.parseValue(property.getValue().get(CommonAttributes.VALUE).asString(), loader));
     }
     optionMap = builder.getMap();
   } else {
     optionMap = OptionMap.EMPTY;
   }
   return optionMap;
 }
示例#14
0
 public static Integer asInt(
     final SimpleAttributeDefinition attr, final ModelNode node, final OperationContext context)
     throws OperationFailedException {
   ModelNode resolvedNode = attr.resolveModelAttribute(context, node);
   return resolvedNode.isDefined() ? resolvedNode.asInt() : null;
 }
 @Override
 public int size() {
   return model.asInt();
 }
  static void installHttpManagementConnector(
      final OperationContext context,
      final ModelNode model,
      final ServiceTarget serviceTarget,
      final ServiceVerificationHandler verificationHandler,
      final List<ServiceController<?>> newControllers)
      throws OperationFailedException {

    ServiceName socketBindingServiceName = null;
    ServiceName secureSocketBindingServiceName = null;
    ServiceName interfaceSvcName = null;
    int port = -1;
    int securePort = -1;

    final ModelNode interfaceModelNode = validateResolvedModel(INTERFACE, context, model);
    if (interfaceModelNode.isDefined()) {
      // Legacy config
      String interfaceName = interfaceModelNode.asString();
      interfaceSvcName = NetworkInterfaceService.JBOSS_NETWORK_INTERFACE.append(interfaceName);
      final ModelNode portNode = HTTP_PORT.resolveModelAttribute(context, model);
      port = portNode.isDefined() ? portNode.asInt() : -1;
      final ModelNode securePortNode = HTTPS_PORT.resolveModelAttribute(context, model);
      securePort = securePortNode.isDefined() ? securePortNode.asInt() : -1;

      // Log the config
      if (securePort > -1) {
        if (port > -1) {
          ServerLogger.ROOT_LOGGER.creatingHttpManagementServiceOnPortAndSecurePort(
              interfaceName, port, securePort);
        } else {
          ServerLogger.ROOT_LOGGER.creatingHttpManagementServiceOnSecurePort(
              interfaceName, securePort);
        }
      } else if (port > -1) {
        ServerLogger.ROOT_LOGGER.creatingHttpManagementServiceOnPort(interfaceName, port);
      }
    } else {
      // Socket-binding reference based config
      final ModelNode socketBindingNode = SOCKET_BINDING.resolveModelAttribute(context, model);
      if (socketBindingNode.isDefined()) {
        final String bindingName = socketBindingNode.asString();
        socketBindingServiceName = SocketBinding.JBOSS_BINDING_NAME.append(bindingName);
      }
      final ModelNode secureSocketBindingNode =
          SECURE_SOCKET_BINDING.resolveModelAttribute(context, model);
      if (secureSocketBindingNode.isDefined()) {
        final String bindingName = secureSocketBindingNode.asString();
        secureSocketBindingServiceName = SocketBinding.JBOSS_BINDING_NAME.append(bindingName);
      }

      // Log the config
      if (socketBindingServiceName != null) {
        if (secureSocketBindingServiceName != null) {
          ServerLogger.ROOT_LOGGER.creatingHttpManagementServiceOnSocketAndSecureSocket(
              socketBindingServiceName.getSimpleName(),
              secureSocketBindingServiceName.getSimpleName());
        } else {
          ServerLogger.ROOT_LOGGER.creatingHttpManagementServiceOnSocket(
              socketBindingServiceName.getSimpleName());
        }
      } else if (secureSocketBindingServiceName != null) {
        ServerLogger.ROOT_LOGGER.creatingHttpManagementServiceOnSecureSocket(
            secureSocketBindingServiceName.getSimpleName());
      }
    }

    ServiceName realmSvcName = null;
    final ModelNode realmNode = SECURITY_REALM.resolveModelAttribute(context, model);
    if (realmNode.isDefined()) {
      realmSvcName = SecurityRealmService.BASE_SERVICE_NAME.append(realmNode.asString());
    } else {
      ServerLogger.ROOT_LOGGER.httpManagementInterfaceIsUnsecured();
    }
    boolean consoleEnabled = model.get(ModelDescriptionConstants.CONSOLE_ENABLED).asBoolean(true);
    ConsoleMode consoleMode;
    if (consoleEnabled) {
      consoleMode =
          context.getRunningMode() == RunningMode.ADMIN_ONLY
              ? ConsoleMode.ADMIN_ONLY
              : ConsoleMode.CONSOLE;
    } else {
      consoleMode = ConsoleMode.NO_CONSOLE;
    }

    ServerEnvironment environment =
        (ServerEnvironment)
            context
                .getServiceRegistry(false)
                .getRequiredService(ServerEnvironmentService.SERVICE_NAME)
                .getValue();
    final HttpManagementService service =
        new HttpManagementService(consoleMode, environment.getProductConfig().getConsoleSlot());
    ServiceBuilder<HttpManagement> builder =
        serviceTarget
            .addService(HttpManagementService.SERVICE_NAME, service)
            .addDependency(
                Services.JBOSS_SERVER_CONTROLLER,
                ModelController.class,
                service.getModelControllerInjector())
            .addDependency(
                SocketBindingManagerImpl.SOCKET_BINDING_MANAGER,
                SocketBindingManager.class,
                service.getSocketBindingManagerInjector())
            .addDependency(
                ControlledProcessStateService.SERVICE_NAME,
                ControlledProcessStateService.class,
                service.getControlledProcessStateServiceInjector())
            .addInjection(
                service.getExecutorServiceInjector(),
                Executors.newCachedThreadPool(
                    new JBossThreadFactory(
                        new ThreadGroup("HttpManagementService-threads"),
                        Boolean.FALSE,
                        null,
                        "%G - %t",
                        null,
                        null,
                        AccessController.getContext())));

    if (interfaceSvcName != null) {
      builder
          .addDependency(
              interfaceSvcName, NetworkInterfaceBinding.class, service.getInterfaceInjector())
          .addInjection(service.getPortInjector(), port)
          .addInjection(service.getSecurePortInjector(), securePort);
    } else {
      if (socketBindingServiceName != null) {
        builder.addDependency(
            socketBindingServiceName, SocketBinding.class, service.getSocketBindingInjector());
      }
      if (secureSocketBindingServiceName != null) {
        builder.addDependency(
            secureSocketBindingServiceName,
            SocketBinding.class,
            service.getSecureSocketBindingInjector());
      }
    }

    if (realmSvcName != null) {
      builder.addDependency(
          realmSvcName, SecurityRealmService.class, service.getSecurityRealmInjector());
    }

    if (verificationHandler != null) {
      builder.addListener(verificationHandler);
    }
    ServiceController<?> controller = builder.install();
    if (newControllers != null) {
      newControllers.add(controller);
    }
  }