/**
   * Test the deployment operation. This will add and remove a given set of deployment using a
   * composite operation and attaching the streams necessary to the http post message.
   *
   * @param quantity the amount of deployments
   * @param encoded whether to send the operation in the dmr encoded format or not
   * @throws IOException
   */
  private void testDeploymentOperations(final int quantity, final boolean encoded)
      throws IOException {

    // Create the deployment
    final File temp = createTempDeploymentZip();
    try {
      final ModelNode deployment = createCompositeDeploymentOperation(quantity);
      final ContentBody operation = getOperationBody(deployment, encoded);
      final List<ContentBody> streams = new ArrayList<ContentBody>();
      for (int i = 0; i < quantity; i++) {
        streams.add(new FileBody(temp));
      }

      final ModelNode response = executePost(operation, encoded, streams);
      Assert.assertEquals(response.toString(), SUCCESS, response.get(OUTCOME).asString());

    } finally {
      temp.delete();
    }

    // And remove the deployments again
    final ModelNode remove = removeDeploymentsOperation(quantity);
    final ContentBody operation = getOperationBody(remove, encoded);
    final ModelNode response = executePost(operation, encoded);
    Assert.assertEquals(response.toString(), SUCCESS, response.get(OUTCOME).asString());
  }
  @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();
      }
    }
  }
  private void compareValueType(
      CompareContext context, String id, ModelNode current, ModelNode legacy) {
    ModelNode currentValueType = current.get(VALUE_TYPE);
    ModelNode legacyValueType = legacy.get(VALUE_TYPE);
    if (!currentValueType.isDefined() && !legacyValueType.isDefined()) {
      return;
    }
    if (isType(legacyValueType) || isType(currentValueType)) {
      if (!currentValueType.equals(legacyValueType)) {
        context.println(
            "Different 'value-type' for "
                + id
                + ". Current: "
                + current.get(VALUE_TYPE)
                + "; legacy: "
                + legacy.get(VALUE_TYPE));
      }
    } else {
      Map<String, ModelNode> legacyValueTypes = createMapIndexedByKey(legacyValueType);
      Map<String, ModelNode> currentValueTypes = createMapIndexedByKey(currentValueType);

      compareKeySetsAndRemoveMissing(
          context, "value-type for " + id, currentValueTypes, legacyValueTypes);
      for (Map.Entry<String, ModelNode> entry : currentValueTypes.entrySet()) {
        ModelNode currentEntry = entry.getValue();
        ModelNode legacyEntry = legacyValueTypes.get(entry.getKey());
        compareAttributeOrOperationParameter(
            context,
            "value-type key '" + entry.getKey() + "' for " + id,
            currentEntry,
            legacyEntry);
      }
    }
  }
 static ModelNode parseModClusterConfig(XMLExtendedStreamReader reader) throws XMLStreamException {
   final ModelNode config = new ModelNode();
   // Parse the attributes.
   parsePropConf(reader, config);
   // Parse the elements
   while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
     final Element element = Element.forName(reader.getLocalName());
     switch (element) {
       case SIMPLE_LOAD_PROVIDER:
         final ModelNode load = parseSimpleLoadProvider(reader);
         config.get(SIMPLE_LOAD_PROVIDER).set(load);
         break;
       case DYNAMIC_LOAD_PROVIDER:
         final ModelNode dynload = parseDynamicLoadProvider(reader);
         config.get(DYNAMIC_LOAD_PROVIDER).set(dynload);
         break;
       case SSL:
         final ModelNode ssl = parseSSL(reader);
         config.get(SSL).set(ssl);
         break;
       default:
         unexpectedElement(reader);
     }
   }
   return config;
 }
Exemplo n.º 5
0
 static ModelNode getConnectorRemove(final Locale locale) {
   final ResourceBundle bundle = getResourceBundle(locale);
   final ModelNode node = new ModelNode();
   node.get(OPERATION_NAME).set(REMOVE);
   node.get(DESCRIPTION).set(bundle.getString("web.connector.remove"));
   return node;
 }
  private ModelNode parseDatabaseBinaryStorage(
      final XMLExtendedStreamReader reader, final String repositoryName) throws XMLStreamException {
    final ModelNode storageType = new ModelNode();
    storageType.get(OP).set(ADD);
    storageType
        .get(OP_ADDR)
        .add(SUBSYSTEM, ModeShapeExtension.SUBSYSTEM_NAME)
        .add(ModelKeys.REPOSITORY, repositoryName)
        .add(ModelKeys.CONFIGURATION, ModelKeys.BINARY_STORAGE)
        .add(ModelKeys.STORAGE_TYPE, ModelKeys.DB_BINARY_STORAGE);

    if (reader.getAttributeCount() > 0) {
      for (int i = 0; i < reader.getAttributeCount(); i++) {
        String attrName = reader.getAttributeLocalName(i);
        String attrValue = reader.getAttributeValue(i);
        Attribute attribute = Attribute.forName(attrName);
        switch (attribute) {
            // The rest go on the ModelNode for the type ...
          case DATA_SOURCE_JNDI_NAME:
            ModelAttributes.DATA_SOURCE_JNDI_NAME.parseAndSetParameter(
                attrValue, storageType, reader);
            break;
          case MIN_VALUE_SIZE:
            ModelAttributes.MINIMUM_BINARY_SIZE.parseAndSetParameter(
                attrValue, storageType, reader);
            break;
          default:
            throw ParseUtils.unexpectedAttribute(reader, i);
        }
      }
    }
    requireNoElements(reader);

    return storageType;
  }
Exemplo n.º 7
0
  private Map<ServerIdentity, ControlledProcessState.State> getServerStatuses() {

    Map<ServerIdentity, ControlledProcessState.State> result =
        new HashMap<ServerIdentity, ControlledProcessState.State>();
    ModelNode op = new ModelNode();
    op.get("operation").set("read-children-names");
    op.get("child-type").set("server-config");
    op.get("address").add("host", configuration.getHostName());
    ModelNode opResult = executeForResult(new OperationBuilder(op).build());
    Set<String> servers = new HashSet<String>();
    for (ModelNode server : opResult.asList()) {
      servers.add(server.asString());
    }
    for (String server : servers) {
      ModelNode address = new ModelNode();
      address.add("host", configuration.getHostName());
      address.add("server-config", server);
      String group = readAttribute("group", address).asString();
      if (!readAttribute("auto-start", address).asBoolean()) continue;

      address = new ModelNode();
      address.add("host", configuration.getHostName());
      address.add("server", server);

      ControlledProcessState.State status =
          Enum.valueOf(
              ControlledProcessState.State.class,
              readAttribute("server-state", address).asString().toUpperCase(Locale.ENGLISH));
      ServerIdentity id = new ServerIdentity(configuration.getHostName(), group, server);
      result.put(id, status);
    }

    return result;
  }
Exemplo n.º 8
0
    private void writeBoundedQueueThreadPool(
        final XMLExtendedStreamWriter writer, final ModelNode node) throws XMLStreamException {
      writer.writeStartElement(Element.BOUNDED_QUEUE_THREAD_POOL.getLocalName());

      if (node.hasDefined(NAME)) {
        writeAttribute(writer, Attribute.NAME, node.get(NAME));
      }
      if (node.hasDefined(BLOCKING)) {
        writeAttribute(writer, Attribute.BLOCKING, node.get(BLOCKING));
      }
      if (node.hasDefined(ALLOW_CORE_TIMEOUT)) {
        writeAttribute(writer, Attribute.ALLOW_CORE_TIMEOUT, node.get(ALLOW_CORE_TIMEOUT));
      }
      writeRef(writer, node, Element.HANDOFF_EXECUTOR, HANDOFF_EXECUTOR);
      writeRef(writer, node, Element.THREAD_FACTORY, THREAD_FACTORY);
      writeThreads(writer, node, Element.CORE_THREADS);
      writeThreads(writer, node, Element.QUEUE_LENGTH);
      writeThreads(writer, node, Element.MAX_THREADS);
      writeTime(writer, node, Element.KEEPALIVE_TIME);

      if (node.hasDefined(PROPERTIES)) {
        writeProperties(writer, node.get(PROPERTIES));
      }

      writer.writeEndElement();
    }
 private void parseStateTransfer(XMLExtendedStreamReader reader, ModelNode stateTransfer)
     throws XMLStreamException {
   for (int i = 0; i < reader.getAttributeCount(); i++) {
     String value = reader.getAttributeValue(i);
     Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
     switch (attribute) {
       case ENABLED:
         {
           stateTransfer.get(ModelKeys.ENABLED).set(Boolean.parseBoolean(value));
           break;
         }
       case TIMEOUT:
         {
           stateTransfer.get(ModelKeys.TIMEOUT).set(Long.parseLong(value));
           break;
         }
       case FLUSH_TIMEOUT:
         {
           stateTransfer.get(ModelKeys.FLUSH_TIMEOUT).set(Long.parseLong(value));
           break;
         }
       default:
         {
           throw ParseUtils.unexpectedAttribute(reader, i);
         }
     }
   }
   ParseUtils.requireNoContent(reader);
 }
 private void parseClusteredCacheAttribute(
     XMLExtendedStreamReader reader, int index, Attribute attribute, String value, ModelNode cache)
     throws XMLStreamException {
   switch (attribute) {
     case MODE:
       {
         cache.get(ModelKeys.MODE).set(value);
         break;
       }
     case QUEUE_SIZE:
       {
         cache.get(ModelKeys.QUEUE_SIZE).set(Integer.parseInt(value));
         break;
       }
     case QUEUE_FLUSH_INTERVAL:
       {
         cache.get(ModelKeys.QUEUE_FLUSH_INTERVAL).set(Long.parseLong(value));
         break;
       }
     case REMOTE_TIMEOUT:
       {
         cache.get(ModelKeys.REMOTE_TIMEOUT).set(Long.parseLong(value));
         break;
       }
     default:
       {
         this.parseCacheAttribute(reader, index, attribute, value, cache);
       }
   }
 }
  @Test
  public void testJson() throws Exception {
    ModelNode node = new ModelNode();
    node.get("realm").set("demo");
    node.get("resource").set("customer-portal");
    node.get("realm-public-key")
        .set(
            "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB");
    node.get("auth-url")
        .set("http://localhost:8080/auth-server/rest/realms/demo/protocol/openid-connect/login");
    node.get("code-url")
        .set(
            "http://localhost:8080/auth-server/rest/realms/demo/protocol/openid-connect/access/codes");
    node.get("ssl-required").set("external");
    node.get("expose-token").set(true);

    ModelNode jwtCredential = new ModelNode();
    jwtCredential.get("client-keystore-file").set("/tmp/keystore.jks");
    jwtCredential.get("client-keystore-password").set("changeit");
    ModelNode credential = new ModelNode();
    credential.get("jwt").set(jwtCredential);
    node.get("credentials").set(credential);

    System.out.println("json=" + node.toJSONString(false));
  }
  private void addManagementSecurityRealms(List<ModelNode> updates) {
    if (hostModel.get(CORE_SERVICE, MANAGEMENT, SECURITY_REALM).isDefined()) {
      ModelNode securityRealms = hostModel.get(CORE_SERVICE, MANAGEMENT, SECURITY_REALM);
      Set<String> keys = securityRealms.keys();
      for (String current : keys) {
        ModelNode addOp = new ModelNode();
        ModelNode realmAddress = new ModelNode();
        realmAddress.add(CORE_SERVICE, MANAGEMENT).add(SECURITY_REALM, current);
        addOp.get(OP).set(ADD);
        addOp.get(OP_ADDR).set(realmAddress);
        updates.add(addOp);

        ModelNode currentRealm = securityRealms.get(current);
        if (currentRealm.hasDefined(SERVER_IDENTITY)) {
          addManagementComponentComponent(currentRealm, realmAddress, SERVER_IDENTITY, updates);
        }
        if (currentRealm.hasDefined(AUTHENTICATION)) {
          addManagementComponentComponent(currentRealm, realmAddress, AUTHENTICATION, updates);
        }
        if (currentRealm.hasDefined(AUTHORIZATION)) {
          addManagementComponentComponent(currentRealm, realmAddress, AUTHORIZATION, updates);
        }
      }
    }
  }
Exemplo n.º 13
0
  @Override
  public void writeContent(XMLExtendedStreamWriter writer, SubsystemMarshallingContext context)
      throws XMLStreamException {
    context.startSubsystemElement(CURRENT.getUriString(), false);
    final ModelNode node = context.getModelNode();

    if (node.hasDefined(HORNETQ_SERVER)) {
      final ModelNode servers = node.get(HORNETQ_SERVER);
      boolean first = true;
      for (Property prop : servers.asPropertyList()) {
        writeHornetQServer(writer, prop.getName(), prop.getValue());
        if (!first) {
          writeNewLine(writer);
        } else {
          first = false;
        }
      }
    }

    if (node.hasDefined(JMS_BRIDGE)) {
      final ModelNode jmsBridges = node.get(JMS_BRIDGE);
      boolean first = true;
      for (Property prop : jmsBridges.asPropertyList()) {
        writeJmsBridge(writer, prop.getName(), prop.getValue());
        if (!first) {
          writeNewLine(writer);
        } else {
          first = false;
        }
      }
    }
    writer.writeEndElement();
  }
Exemplo n.º 14
0
 private static void writeAcceptors(final XMLExtendedStreamWriter writer, final ModelNode node)
     throws XMLStreamException {
   if (node.hasDefined(ACCEPTOR)
       || node.hasDefined(REMOTE_ACCEPTOR)
       || node.hasDefined(IN_VM_ACCEPTOR)) {
     writer.writeStartElement(Element.ACCEPTORS.getLocalName());
     if (node.hasDefined(REMOTE_ACCEPTOR)) {
       for (final Property property : node.get(REMOTE_ACCEPTOR).asPropertyList()) {
         writer.writeStartElement(Element.NETTY_ACCEPTOR.getLocalName());
         writeAcceptorContent(writer, property);
         writer.writeEndElement();
       }
     }
     if (node.hasDefined(IN_VM_ACCEPTOR)) {
       for (final Property property : node.get(IN_VM_ACCEPTOR).asPropertyList()) {
         writer.writeStartElement(Element.IN_VM_ACCEPTOR.getLocalName());
         writeAcceptorContent(writer, property);
         writer.writeEndElement();
       }
     }
     if (node.hasDefined(ACCEPTOR)) {
       for (final Property property : node.get(ACCEPTOR).asPropertyList()) {
         writer.writeStartElement(Element.ACCEPTOR.getLocalName());
         writeAcceptorContent(writer, property);
         writer.writeEndElement();
       }
     }
     writer.writeEndElement();
     writeNewLine(writer);
   }
 }
Exemplo n.º 15
0
  @Test
  public void testParseSubsystem_1_0() throws Exception {
    String subsystemXml =
        "<subsystem xmlns=\"urn:jboss:domain:jacorb:1.0\">"
            + "    <orb name=\"JBoss\" print-version=\"off\">"
            + "        <connection retries=\"5\" retry-interval=\"500\" client-timeout=\"0\" server-timeout=\"0\"/>"
            + "        <naming root-context=\"JBoss/Naming/root\" export-corbaloc=\"on\"/>"
            + "    </orb>"
            + "    <poa monitoring=\"off\" queue-wait=\"on\" queue-min=\"10\" queue-max=\"100\">"
            + "        <request-processors pool-size=\"10\" max-threads=\"32\"/>"
            + "    </poa>"
            + "    <interop sun=\"on\" comet=\"off\" chunk-custom-rmi-valuetypes=\"on\"/>"
            + "    <security support-ssl=\"off\" use-domain-socket-factory=\"off\" use-domain-server-socket-factory=\"off\"/>"
            + "    <property key=\"a\" value=\"va\"/>"
            + "    <property key=\"b\" value=\"vb\"/>"
            + "    <initializers>security,transactions</initializers>"
            + "</subsystem>";

    List<ModelNode> operations = super.parse(subsystemXml);

    // check that we have the expected number of operations.
    Assert.assertEquals(1, operations.size());
    // check that each operation has the correct content.
    ModelNode addSubsystem = operations.get(0);
    Assert.assertEquals(ADD, addSubsystem.get(OP).asString());
    PathAddress addr = PathAddress.pathAddress(addSubsystem.get(OP_ADDR));
    Assert.assertEquals(1, addr.size());
    PathElement element = addr.getElement(0);
    Assert.assertEquals(SUBSYSTEM, element.getKey());
    Assert.assertEquals(JacORBExtension.SUBSYSTEM_NAME, element.getValue());
  }
Exemplo n.º 16
0
    private void addUnboundedQueueThreadPools(final ModelNode result, final ModelNode model) {
      if (model.hasDefined(UNBOUNDED_QUEUE_THREAD_POOL)) {
        ModelNode pools = model.get(UNBOUNDED_QUEUE_THREAD_POOL);
        for (Property poolProp : pools.asPropertyList()) {
          final ModelNode operation =
              Util.getEmptyOperation(
                  ADD,
                  pathAddress(
                      PathElement.pathElement(SUBSYSTEM, SUBSYSTEM_NAME),
                      PathElement.pathElement(UNBOUNDED_QUEUE_THREAD_POOL, poolProp.getName())));
          final ModelNode pool = poolProp.getValue();

          operation.get(NAME).set(pool.require(NAME));
          if (pool.hasDefined(THREAD_FACTORY)) {
            operation.get(THREAD_FACTORY).set(pool.get(THREAD_FACTORY));
          }
          if (pool.hasDefined(PROPERTIES)) {
            operation.get(PROPERTIES).set(pool.get(PROPERTIES));
          }
          if (pool.hasDefined(MAX_THREADS)) {
            operation.get(MAX_THREADS).set(pool.get(MAX_THREADS));
          }
          if (pool.hasDefined(KEEPALIVE_TIME)) {
            operation.get(KEEPALIVE_TIME).set(pool.get(KEEPALIVE_TIME));
          }
          result.add(operation);
        }
      }
    }
Exemplo n.º 17
0
    @Override
    public void readElement(final XMLExtendedStreamReader reader, final List<ModelNode> list)
        throws XMLStreamException {

      final ModelNode address = new ModelNode();
      address.add(SUBSYSTEM, SUBSYSTEM_NAME);
      address.protect();

      final ModelNode subsystem = new ModelNode();
      subsystem.get(OP).set(ADD);
      subsystem.get(OP_ADDR).set(address);
      list.add(subsystem);

      // Handle elements
      while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        switch (Namespace.forUri(reader.getNamespaceURI())) {
          case THREADS_1_0:
            {
              final Element element = Element.forName(reader.getLocalName());
              switch (element) {
                case BOUNDED_QUEUE_THREAD_POOL:
                  {
                    parseBoundedQueueThreadPool(reader, address, list);
                    break;
                  }
                case THREAD_FACTORY:
                  {
                    // Add connector updates
                    parseThreadFactory(reader, address, list);
                    break;
                  }
                case QUEUELESS_THREAD_POOL:
                  {
                    parseQueuelessThreadPool(reader, address, list);
                    break;
                  }
                case SCHEDULED_THREAD_POOL:
                  {
                    parseScheduledThreadPool(reader, address, list);
                    break;
                  }
                case UNBOUNDED_QUEUE_THREAD_POOL:
                  {
                    parseUnboundedQueueThreadPool(reader, address, list);
                    break;
                  }
                default:
                  {
                    throw unexpectedElement(reader);
                  }
              }
              break;
            }
          default:
            {
              throw unexpectedElement(reader);
            }
        }
      }
    }
 private void parseEviction(XMLExtendedStreamReader reader, ModelNode eviction)
     throws XMLStreamException {
   for (int i = 0; i < reader.getAttributeCount(); i++) {
     String value = reader.getAttributeValue(i);
     Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
     switch (attribute) {
       case STRATEGY:
         {
           try {
             EvictionStrategy strategy = EvictionStrategy.valueOf(value);
             eviction.get(ModelKeys.STRATEGY).set(strategy.name());
           } catch (IllegalArgumentException e) {
             throw ParseUtils.invalidAttributeValue(reader, i);
           }
           break;
         }
       case MAX_ENTRIES:
         {
           eviction.get(ModelKeys.MAX_ENTRIES).set(Integer.parseInt(value));
           break;
         }
       case INTERVAL:
         {
           ROOT_LOGGER.deprecatedAttribute(
               attribute.getLocalName(), Element.EVICTION.getLocalName(), "ISPN-1268");
           break;
         }
       default:
         {
           throw ParseUtils.unexpectedAttribute(reader, i);
         }
     }
   }
   ParseUtils.requireNoContent(reader);
 }
Exemplo n.º 19
0
  @Override
  public ModelNode buildRequest(CommandContext ctx) throws OperationFormatException {

    ModelNode composite = new ModelNode();
    composite.get("operation").set("composite");
    composite.get("address").setEmptyList();
    ModelNode steps = composite.get("steps");

    final String name = this.name.getValue(ctx.getParsedArguments());
    if (name == null) {
      throw new OperationFormatException("Required argument name are missing.");
    }

    DefaultOperationRequestBuilder builder;

    // undeploy
    builder = new DefaultOperationRequestBuilder();
    builder.setOperationName("undeploy");
    builder.addNode("deployment", name);
    steps.add(builder.buildRequest());

    builder = new DefaultOperationRequestBuilder();
    builder.setOperationName("remove");
    builder.addNode("deployment", name);
    steps.add(builder.buildRequest());
    return composite;
  }
 private void parseExpiration(XMLExtendedStreamReader reader, ModelNode expiration)
     throws XMLStreamException {
   for (int i = 0; i < reader.getAttributeCount(); i++) {
     String value = reader.getAttributeValue(i);
     Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
     switch (attribute) {
       case MAX_IDLE:
         {
           expiration.get(ModelKeys.MAX_IDLE).set(Long.parseLong(value));
           break;
         }
       case LIFESPAN:
         {
           expiration.get(ModelKeys.LIFESPAN).set(Long.parseLong(value));
           break;
         }
       case INTERVAL:
         {
           expiration.get(ModelKeys.INTERVAL).set(Long.parseLong(value));
           break;
         }
       default:
         {
           throw ParseUtils.unexpectedAttribute(reader, i);
         }
     }
   }
   ParseUtils.requireNoContent(reader);
 }
Exemplo n.º 21
0
 private ModelNode readAttribute(String name, ModelNode address) {
   ModelNode op = new ModelNode();
   op.get("operation").set("read-attribute");
   op.get("address").set(address);
   op.get("name").set(name);
   return executeForResult(new OperationBuilder(op).build());
 }
  private void parseFileStore(XMLExtendedStreamReader reader, ModelNode store)
      throws XMLStreamException {
    for (int i = 0; i < reader.getAttributeCount(); i++) {
      String value = reader.getAttributeValue(i);
      Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
      switch (attribute) {
        case RELATIVE_TO:
          {
            store.get(ModelKeys.RELATIVE_TO).set(value);
            break;
          }
        case PATH:
          {
            store.get(ModelKeys.PATH).set(value);
            break;
          }
        default:
          {
            this.parseStoreAttribute(reader, i, attribute, value, store);
          }
      }
    }

    this.parseStoreProperties(reader, store);
  }
 private void parseAuthenticator(final XMLExtendedStreamReader reader, final ModelNode repository)
     throws XMLStreamException {
   if (reader.getAttributeCount() > 0) {
     ModelNode authenticator = new ModelNode();
     for (int i = 0; i < reader.getAttributeCount(); i++) {
       String attrName = reader.getAttributeLocalName(i);
       String attrValue = reader.getAttributeValue(i);
       Attribute attribute = Attribute.forName(attrName);
       switch (attribute) {
           // Set these as properties on the repository ModelNode ...
         case NAME:
           ModelAttributes.NAME.parseAndSetParameter(attrValue, authenticator, reader);
           break;
         case CLASSNAME:
           ModelAttributes.CLASSNAME.parseAndSetParameter(attrValue, authenticator, reader);
           if (!authenticator.has(ModelKeys.NAME)) {
             ModelAttributes.NAME.parseAndSetParameter(attrValue, authenticator, reader);
           }
           break;
         case MODULE:
           ModelAttributes.MODULE.parseAndSetParameter(attrValue, authenticator, reader);
           break;
         default:
           authenticator.get(attrName).set(attrValue);
           break;
       }
     }
     if (authenticator.has(ModelKeys.NAME))
       repository.get(ModelKeys.AUTHENTICATORS).add(authenticator);
   }
   requireNoElements(reader);
 }
  private Object getAttribute(
      final ResourceAndRegistration reg,
      final PathAddress address,
      final ObjectName name,
      final String attribute,
      final ResourceAccessControl accessControl)
      throws ReflectionException, AttributeNotFoundException, InstanceNotFoundException {
    final ImmutableManagementResourceRegistration registration = getMBeanRegistration(address, reg);
    final DescriptionProvider provider =
        registration.getModelDescription(PathAddress.EMPTY_ADDRESS);
    if (provider == null) {
      throw MESSAGES.descriptionProviderNotFound(address);
    }
    final ModelNode description = provider.getModelDescription(null);
    final String attributeName = findAttributeName(description.get(ATTRIBUTES), attribute);

    if (!accessControl.isReadableAttribute(attributeName)) {
      throw MESSAGES.notAuthorizedToReadAttribute(attributeName);
    }

    ModelNode op = new ModelNode();
    op.get(OP).set(READ_ATTRIBUTE_OPERATION);
    op.get(OP_ADDR).set(address.toModelNode());
    op.get(NAME).set(attributeName);
    ModelNode result = execute(op);
    String error = getFailureDescription(result);
    if (error != null) {
      throw new AttributeNotFoundException(error);
    }

    return converters.fromModelNode(
        description.require(ATTRIBUTES).require(attributeName), result.get(RESULT));
  }
  @org.junit.Ignore("This fails for some mysterious reason - but this isn't a critical test")
  @Test
  @BMRule(
      name = "Test remove rollback operation",
      targetClass = "org.jboss.as.clustering.jgroups.subsystem.StackRemoveHandler",
      targetMethod = "performRuntime",
      targetLocation = "AT EXIT",
      action = "traceln(\"Injecting rollback fault via Byteman\");$1.setRollbackOnly()")
  public void testProtocolStackRemoveRollback() throws Exception {

    KernelServices services = buildKernelServices();

    ModelNode operation =
        Operations.createCompositeOperation(addStackOp, addTransportOp, addProtocolOp);

    // add a protocol stack
    ModelNode result = services.executeOperation(operation);
    Assert.assertEquals(SUCCESS, result.get(OUTCOME).asString());

    // remove the protocol stack
    // the remove has OperationContext.setRollbackOnly() injected
    // and so is expected to fail
    result = services.executeOperation(removeStackOp);
    Assert.assertEquals(FAILED, result.get(OUTCOME).asString());

    // need to check that all services are correctly re-installed
    ServiceName channelFactoryServiceName =
        ProtocolStackServiceName.CHANNEL_FACTORY.getServiceName("maximal2");
    Assert.assertNotNull(
        "channel factory service not installed",
        services.getContainer().getService(channelFactoryServiceName));
  }
Exemplo n.º 26
0
 protected StringBuilder formatResponse(
     CommandContext ctx, ModelNode opResponse, boolean composite, StringBuilder buf) {
   if (!opResponse.hasDefined(Util.RESULT)) {
     return null;
   }
   final ModelNode result = opResponse.get(Util.RESULT);
   if (composite) {
     final Set<String> keys;
     try {
       keys = result.keys();
     } catch (Exception e) {
       ctx.printLine(
           "Failed to get step results from a composite operation response " + opResponse);
       e.printStackTrace();
       return null;
     }
     for (String key : keys) {
       final ModelNode stepResponse = result.get(key);
       buf =
           formatResponse(
               ctx, stepResponse, false, buf); // TODO nested composite ops aren't expected for now
     }
   } else {
     final ModelNodeFormatter formatter = ModelNodeFormatter.Factory.forType(result.getType());
     if (buf == null) {
       buf = new StringBuilder();
     }
     formatter.format(buf, 0, result);
   }
   return buf;
 }
 static ModelNode parseCustomLoadMetric(XMLExtendedStreamReader reader) throws XMLStreamException {
   final ModelNode load = new ModelNode();
   final int count = reader.getAttributeCount();
   for (int i = 0; i < count; i++) {
     requireNoNamespaceAttribute(reader, i);
     final String value = reader.getAttributeValue(i);
     final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
     switch (attribute) {
       case CAPACITY:
         load.get(CAPACITY).set(value);
         break;
       case WEIGHT:
         load.get(WEIGHT).set(value);
         break;
       case CLASS:
         load.get(CLASS).set(value);
         break;
       default:
         unexpectedAttribute(reader, i);
     }
   }
   while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
     final Element element = Element.forName(reader.getLocalName());
     switch (element) {
       case PROPERTY:
         final Property property = parseProperty(reader);
         load.get("property").add(property.getName(), property.getValue());
         break;
       default:
         unexpectedElement(reader);
     }
   }
   return load;
 }
 @Override
 public void persist(XMLExtendedStreamWriter writer, ModelNode model) throws XMLStreamException {
   boolean wildcard = getPathElement().isWildcard();
   model =
       wildcard
           ? model.get(getPathElement().getKey())
           : model.get(getPathElement().getKeyValuePair());
   if (!model.isDefined()) {
     return;
   }
   boolean writeWrapper = getXmlWrapperElement() != null;
   if (writeWrapper) {
     writer.writeStartElement(getXmlWrapperElement());
   }
   writer.writeStartElement(getXmlElementName());
   if (wildcard) {
     for (Property p : model.asPropertyList()) {
       writer.writeAttribute(NAME, p.getName());
       for (AttributeDefinition def : getAttributes()) {
         def.getAttributeMarshaller().marshallAsAttribute(def, p.getValue(), false, writer);
       }
       persistChildren(writer, p.getValue());
     }
   } else {
     for (AttributeDefinition def : getAttributes()) {
       def.getAttributeMarshaller().marshallAsAttribute(def, model, false, writer);
     }
     persistChildren(writer, model);
   }
   writer.writeEndElement();
   if (writeWrapper) {
     writer.writeEndElement();
   }
 }
Exemplo n.º 29
0
    private void addThreadFactories(final ModelNode result, final ModelNode model) {
      if (model.hasDefined(THREAD_FACTORY)) {
        ModelNode pools = model.get(THREAD_FACTORY);
        for (Property poolProp : pools.asPropertyList()) {
          final ModelNode operation =
              Util.getEmptyOperation(
                  ADD,
                  pathAddress(
                      PathElement.pathElement(SUBSYSTEM, SUBSYSTEM_NAME),
                      PathElement.pathElement(THREAD_FACTORY, poolProp.getName())));
          final ModelNode pool = poolProp.getValue();

          operation.get(NAME).set(pool.require(NAME));
          if (pool.hasDefined(GROUP_NAME)) {
            operation.get(GROUP_NAME).set(pool.get(GROUP_NAME));
          }
          if (pool.hasDefined(THREAD_NAME_PATTERN)) {
            operation.get(THREAD_NAME_PATTERN).set(pool.get(THREAD_NAME_PATTERN));
          }
          if (pool.hasDefined(PRIORITY)) {
            operation.get(PRIORITY).set(pool.get(PRIORITY));
          }
          if (pool.hasDefined(PROPERTIES)) {
            operation.get(PROPERTIES).set(pool.get(PROPERTIES));
          }
          result.add(operation);
        }
      }
    }
Exemplo n.º 30
0
  protected ModelNode buildWritePropertyRequest(CommandContext ctx) throws CommandFormatException {

    final String name = this.name.getValue(ctx.getParsedCommandLine(), true);

    ModelNode composite = new ModelNode();
    composite.get(Util.OPERATION).set(Util.COMPOSITE);
    composite.get(Util.ADDRESS).setEmptyList();
    ModelNode steps = composite.get(Util.STEPS);

    final ParsedCommandLine args = ctx.getParsedCommandLine();

    final String profile;
    if (isDependsOnProfile() && ctx.isDomainMode()) {
      profile = this.profile.getValue(args);
      if (profile == null) {
        throw new OperationFormatException("--profile argument value is missing.");
      }
    } else {
      profile = null;
    }

    final Map<String, CommandArgument> nodeProps = loadArguments(ctx, null);
    for (String argName : args.getPropertyNames()) {
      if (isDependsOnProfile() && argName.equals("--profile")
          || this.name.getFullName().equals(argName)) {
        continue;
      }

      final ArgumentWithValue arg = (ArgumentWithValue) nodeProps.get(argName);
      if (arg == null) {
        throw new CommandFormatException("Unrecognized argument name '" + argName + "'");
      }

      DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder();
      if (profile != null) {
        builder.addNode(Util.PROFILE, profile);
      }

      for (OperationRequestAddress.Node node : getRequiredAddress()) {
        builder.addNode(node.getType(), node.getName());
      }
      builder.addNode(getRequiredType(), name);
      builder.setOperationName(Util.WRITE_ATTRIBUTE);
      final String propName;
      if (argName.charAt(1) == '-') {
        propName = argName.substring(2);
      } else {
        propName = argName.substring(1);
      }
      builder.addProperty(Util.NAME, propName);

      final String valueString = args.getPropertyValue(argName);
      ModelNode nodeValue = arg.getValueConverter().fromString(valueString);
      builder.getModelNode().get(Util.VALUE).set(nodeValue);

      steps.add(builder.buildRequest());
    }

    return composite;
  }