protected void describe(
     final Resource resource,
     final ModelNode address,
     ModelNode result,
     final ImmutableManagementResourceRegistration registration) {
   if (registration.isRemote()
       || registration.isRuntimeOnly()
       || resource.isProxy()
       || resource.isRuntime()) {
     return;
   }
   final Set<PathElement> children = registration.getChildAddresses(PathAddress.EMPTY_ADDRESS);
   result.add(createAddOperation(address, resource.getModel(), children));
   for (final PathElement element : children) {
     if (element.isMultiTarget()) {
       final String childType = element.getKey();
       for (final Resource.ResourceEntry entry : resource.getChildren(childType)) {
         final ImmutableManagementResourceRegistration childRegistration =
             registration.getSubModel(
                 PathAddress.pathAddress(PathElement.pathElement(childType, entry.getName())));
         final ModelNode childAddress = address.clone();
         childAddress.add(childType, entry.getName());
         describe(entry, childAddress, result, childRegistration);
       }
     } else {
       final Resource child = resource.getChild(element);
       final ImmutableManagementResourceRegistration childRegistration =
           registration.getSubModel(PathAddress.pathAddress(element));
       final ModelNode childAddress = address.clone();
       childAddress.add(element.getKey(), element.getValue());
       describe(child, childAddress, result, childRegistration);
     }
   }
 }
  /** {@inheritDoc} */
  @Override
  public OperationResult execute(
      OperationContext context, ModelNode operation, ResultHandler resultHandler)
      throws OperationFailedException {

    validator.validate(operation);

    String name = operation.require(NAME).asString();
    String toReplace = operation.require(TO_REPLACE).asString();

    if (name.equals(toReplace)) {
      throw operationFailed(
          String.format(
              "Cannot use %s with the same value for parameters %s and %s. "
                  + "Use %s to redeploy the same content or %s to replace content with a new version with the same name.",
              OPERATION_NAME,
              NAME,
              TO_REPLACE,
              ServerGroupDeploymentRedeployHandler.OPERATION_NAME,
              DeploymentFullReplaceHandler.OPERATION_NAME));
    }

    ModelNode deployment;
    try {
      deployment =
          context.getSubModel(PathAddress.pathAddress(PathElement.pathElement(DEPLOYMENT, name)));
    } catch (IllegalArgumentException iae) {
      throw operationFailed(String.format("No deployment with name %s found", name));
    }

    byte[] hash = deployment.require(HASH).asBytes();
    // Ensure the local repo has the files
    fileRepository.getDeploymentFiles(hash);

    ModelNode deployments = context.getSubModel().get(DEPLOYMENT);
    ModelNode deployNode = deployments.hasDefined(name) ? deployments.get(name) : null;
    ModelNode replaceNode = deployments.hasDefined(toReplace) ? deployments.get(toReplace) : null;
    if (deployNode == null) {
      deployNode = deployment.clone();
      deployments.get(name).set(deployNode);
    } else if (deployNode.get(START).asBoolean()) {
      throw operationFailed(String.format("Deployment %s is already started", toReplace));
    } else if (replaceNode == null) {
      throw operationFailed(String.format("No deployment with name %s found", toReplace));
    }

    // Update model
    deployNode.get(START).set(true);
    replaceNode.get(START).set(false);

    ModelNode compensatingOp = operation.clone();
    compensatingOp.get(NAME).set(toReplace);
    compensatingOp.get(TO_REPLACE).set(name);

    resultHandler.handleResultComplete();

    return new BasicOperationResult();
  }
Example #3
0
  private ModelNode removeServerGroups(final DomainClient client) throws Exception {
    final ModelNode op =
        Util.createEmptyOperation(
            READ_RESOURCE_OPERATION,
            PathAddress.pathAddress(PathElement.pathElement(SERVER_GROUP)));
    final ModelNode results = executeForResult(op, client);
    ModelNode group = null;
    for (ModelNode result : results.asList()) {
      String groupName = PathAddress.pathAddress(result.get(ADDRESS)).getLastElement().getValue();
      if (groupName.equals(OTHER_SERVER_GROUP)) {
        group = result.get(RESULT);
      } else {
        ModelNode remove = Util.createRemoveOperation(PathAddress.pathAddress(result.get(ADDRESS)));
        executeForResult(remove, client);
      }
    }
    Assert.assertNotNull(group);

    // Add main-server-group as a copy of other-server-group (cuts down on the amount of profiles
    // needed)
    final ModelNode addMain = group.clone();
    final PathAddress mainServerGroupAddress =
        PathAddress.pathAddress(SERVER_GROUP, MAIN_SERVER_GROUP);
    addMain.get(OP).set(ADD);
    addMain.get(OP_ADDR).set(mainServerGroupAddress.toModelNode());
    executeForResult(addMain, client);

    return group;
  }
Example #4
0
  /**
   * [AS7-5850] Core queues created with ActiveMQ API does not create WildFly resources
   *
   * <p>For backwards compatibility if an operation is invoked on a queue that has no corresponding
   * resources, we forward the operation to the corresponding runtime-queue resource (which *does*
   * exist).
   *
   * @return true if the operation is forwarded to the corresponding runtime-queue resource, false
   *     else.
   */
  static boolean forwardToRuntimeQueue(
      OperationContext context, ModelNode operation, OperationStepHandler handler) {
    PathAddress address =
        PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR));

    // do not forward if the current operation is for a runtime-queue already:
    if (RUNTIME_QUEUE.equals(address.getLastElement().getKey())) {
      return false;
    }

    String queueName = address.getLastElement().getValue();

    PathAddress activeMQPathAddress = MessagingServices.getActiveMQServerPathAddress(address);
    Resource serverResource = context.readResourceFromRoot(activeMQPathAddress);
    boolean hasChild = serverResource.hasChild(address.getLastElement());
    if (hasChild) {
      return false;
    } else {
      // there is no registered queue resource, forward to the runtime-queue address instead
      ModelNode forwardOperation = operation.clone();
      forwardOperation
          .get(ModelDescriptionConstants.OP_ADDR)
          .set(activeMQPathAddress.append(RUNTIME_QUEUE, queueName).toModelNode());
      context.addStep(forwardOperation, handler, OperationContext.Stage.RUNTIME, true);
      return true;
    }
  }
Example #5
0
  private void parseServerProfile(
      final XMLExtendedStreamReader reader, final ModelNode address, final List<ModelNode> list)
      throws XMLStreamException {
    // Attributes
    requireNoAttributes(reader);

    // Content
    final Set<String> configuredSubsystemTypes = new HashSet<String>();
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
      if (Element.forName(reader.getLocalName()) != Element.SUBSYSTEM) {
        throw unexpectedElement(reader);
      }
      if (!configuredSubsystemTypes.add(reader.getNamespaceURI())) {
        throw AppClientLogger.ROOT_LOGGER.duplicateSubsystemDeclaration(reader.getLocation());
      }
      // parse subsystem
      final List<ModelNode> subsystems = new ArrayList<ModelNode>();
      reader.handleAny(subsystems);

      // Process subsystems
      for (final ModelNode update : subsystems) {
        // Process relative subsystem path address
        final ModelNode subsystemAddress = address.clone();
        for (final Property path : update.get(OP_ADDR).asPropertyList()) {
          subsystemAddress.add(path.getName(), path.getValue().asString());
        }
        update.get(OP_ADDR).set(subsystemAddress);
        list.add(update);
      }
    }
  }
 // For any request params that are of type BYTES, replace the file path with the bytes from the
 // file
 private boolean replaceFilePathsWithBytes(ModelNode request)
     throws CommandFormatException, IOException {
   boolean didReplacement = false;
   ModelNode opDesc = request.clone();
   String opName = opDesc.get("operation").asString();
   opDesc.get("operation").set("read-operation-description");
   opDesc.get("name").set(opName);
   ModelNode response = execute(opDesc, false).getResponseNode();
   ModelNode requestProps = response.get("result", "request-properties");
   for (Property prop : requestProps.asPropertyList()) {
     ModelNode typeDesc = prop.getValue().get("type");
     if (typeDesc.getType() == ModelType.TYPE
         && typeDesc.asType() == ModelType.BYTES
         && request.hasDefined(prop.getName())) {
       String filePath = request.get(prop.getName()).asString();
       File localFile = new File(filePath);
       if (!localFile.exists()) continue;
       try {
         request.get(prop.getName()).set(Util.readBytes(localFile));
         didReplacement = true;
       } catch (OperationFormatException e) {
         throw new CommandFormatException(e);
       }
     }
   }
   return didReplacement;
 }
  public CacheBuilder<PrincipalToGroupBuilder> cache() {
    assertNotBuilt();
    if (cacheBuilder == null) {
      cacheBuilder = new CacheBuilder<PrincipalToGroupBuilder>(this, address.clone());
    }

    return cacheBuilder;
  }
 private ModelNode trimNonSubsystem(ModelNode definition) {
   ModelNode def = definition.clone();
   for (String key : def.get(CHILDREN).keys()) {
     if (!key.equals(SUBSYSTEM)) {
       def.remove(key);
     }
   }
   return def;
 }
  private void parseTransport(
      XMLExtendedStreamReader reader, ModelNode containerAddress, List<ModelNode> operations)
      throws XMLStreamException {

    // ModelNode for the transport add operation
    ModelNode transport = Util.getEmptyOperation(ModelDescriptionConstants.ADD, null);

    for (int i = 0; i < reader.getAttributeCount(); i++) {
      String value = reader.getAttributeValue(i);
      Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
      switch (attribute) {
        case STACK:
          {
            transport.get(ModelKeys.STACK).set(value);
            break;
          }
        case EXECUTOR:
          {
            transport.get(ModelKeys.EXECUTOR).set(value);
            break;
          }
        case LOCK_TIMEOUT:
          {
            transport.get(ModelKeys.LOCK_TIMEOUT).set(Long.parseLong(value));
            break;
          }
        case SITE:
          {
            transport.get(ModelKeys.SITE).set(value);
            break;
          }
        case RACK:
          {
            transport.get(ModelKeys.RACK).set(value);
            break;
          }
        case MACHINE:
          {
            transport.get(ModelKeys.MACHINE).set(value);
            break;
          }
        default:
          {
            throw ParseUtils.unexpectedAttribute(reader, i);
          }
      }
    }
    ParseUtils.requireNoContent(reader);

    // setup the transport address
    ModelNode transportAddress = containerAddress.clone();
    transportAddress.add(ModelKeys.SINGLETON, ModelKeys.TRANSPORT);
    transportAddress.protect();
    transport.get(ModelDescriptionConstants.OP_ADDR).set(transportAddress);

    operations.add(transport);
  }
 /** Resolve expressions in the given model (if there are any) */
 private ModelNode resolveExpressions(final ModelNode unresolved) {
   if (unresolved == null) {
     return null;
   }
   try {
     return expressionResolver.resolveExpressions(unresolved.clone());
   } catch (OperationFailedException e) {
     // Fail
     throw new IllegalStateException(e.getMessage(), e);
   }
 }
  /**
   * Reads a element from the stream considering the parameters.
   *
   * @param reader XMLExtendedStreamReader instance from which the elements are read.
   * @param xmlElement Name of the Model Element to be parsed.
   * @param key Name of the attribute to be used to as the key for the model.
   * @param addOperations List of operations.
   * @param lastNode Parent ModelNode instance.
   * @param attributes AttributeDefinition instances to be used to extract the attributes and
   *     populate the resulting model.
   * @return A ModelNode instance populated.
   * @throws javax.xml.stream.XMLStreamException
   */
  protected ModelNode parseConfig(
      XMLExtendedStreamReader reader,
      ModelElement xmlElement,
      String key,
      ModelNode lastNode,
      List<SimpleAttributeDefinition> attributes,
      List<ModelNode> addOperations)
      throws XMLStreamException {
    if (!reader.getLocalName().equals(xmlElement.getName())) {
      return null;
    }

    ModelNode modelNode = Util.getEmptyOperation(ADD, null);

    int attributeCount = reader.getAttributeCount();

    for (int i = 0; i < attributeCount; i++) {
      String attributeLocalName = reader.getAttributeLocalName(i);

      if (ModelElement.forName(attributeLocalName) == null) {
        throw unexpectedAttribute(reader, i);
      }
    }

    for (SimpleAttributeDefinition simpleAttributeDefinition : attributes) {
      simpleAttributeDefinition.parseAndSetParameter(
          reader.getAttributeValue("", simpleAttributeDefinition.getXmlName()), modelNode, reader);
    }

    String name = xmlElement.getName();

    if (key != null) {
      name = key;

      if (modelNode.hasDefined(key)) {
        name = modelNode.get(key).asString();
      } else {
        String attributeValue = reader.getAttributeValue("", key);

        if (attributeValue != null) {
          name = attributeValue;
        }
      }
    }

    modelNode
        .get(ModelDescriptionConstants.OP_ADDR)
        .set(lastNode.clone().get(OP_ADDR).add(xmlElement.getName(), name));

    addOperations.add(modelNode);

    return modelNode;
  }
  private void addCacheNameToAddress(
      ModelNode cache, ModelNode containerAddress, String cacheType) {

    String name = cache.get(ModelKeys.NAME).asString();
    // setup the cache address
    ModelNode cacheAddress = containerAddress.clone();
    cacheAddress.add(cacheType, name);
    cacheAddress.protect();
    cache.get(ModelDescriptionConstants.OP_ADDR).set(cacheAddress);

    // get rid of NAME now that we are finished with it
    cache.remove(ModelKeys.NAME);
  }
 protected ModelNode createAddOperation(
     final ModelNode address, final ModelNode subModel, final Set<PathElement> children) {
   final ModelNode operation = subModel.clone();
   operation.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.ADD);
   operation.get(ModelDescriptionConstants.OP_ADDR).set(address);
   if (children != null && !children.isEmpty()) {
     for (final PathElement path : children) {
       if (subModel.hasDefined(path.getKey())) {
         subModel.remove(path.getKey());
       }
     }
   }
   return operation;
 }
 private ModelNode unmaskUsersPasswords(OperationContext context, ModelNode users)
     throws OperationFailedException {
   users = users.clone();
   for (Property property : users.get(USER).asPropertyList()) {
     // Don't use the value from property as it is a clone and does not update the returned users
     // ModelNode.
     ModelNode user = users.get(USER, property.getName());
     if (user.hasDefined(PASSWORD)) {
       // TODO This will be cleaned up once it uses attribute definitions
       user.set(PASSWORD, context.resolveExpressions(user.get(PASSWORD)).asString());
     }
   }
   return users;
 }
  private void addManagementComponentComponent(
      ModelNode realm, ModelNode parentAddress, String key, List<ModelNode> updates) {
    for (String currentComponent : realm.get(key).keys()) {
      ModelNode addComponent = new ModelNode();
      // First take the properties to pass over.
      addComponent.set(realm.get(key, currentComponent));

      // Now convert it to an operation by adding a name and address.
      ModelNode identityAddress = parentAddress.clone().add(key, currentComponent);
      addComponent.get(OP).set(ADD);
      addComponent.get(OP_ADDR).set(identityAddress);

      updates.add(addComponent);
    }
  }
 private ModelNode getEnhancedSyntaxResolvedOperation(
     ModelNode originalOperation,
     ModelNode currentModel,
     String attributeName,
     String attributeExpression)
     throws OperationFailedException {
   ModelNode writeOp = originalOperation.clone();
   ModelNode diffValue = originalOperation.get(ModelDescriptionConstants.VALUE);
   ModelNode old = new ModelNode();
   old.get(attributeName).set(currentModel);
   ModelNode fullValue =
       EnhancedSyntaxSupport.updateWithEnhancedSyntax(attributeExpression, old, diffValue);
   writeOp.get(ModelDescriptionConstants.NAME).set(attributeName);
   writeOp.get(ModelDescriptionConstants.VALUE).set(fullValue.get(attributeName));
   return writeOp;
 }
Example #17
0
  private void parseRolloutPlans(
      XMLExtendedStreamReader reader, ModelNode address, List<ModelNode> list)
      throws XMLStreamException {

    String hash = readStringAttributeElement(reader, Attribute.SHA1.getLocalName());

    ModelNode addAddress = address.clone().add(MANAGEMENT_CLIENT_CONTENT, ROLLOUT_PLANS);
    ModelNode addOp = Util.getEmptyOperation(ADD, addAddress);
    try {
      addOp.get(HASH).set(HashUtil.hexStringToByteArray(hash));
    } catch (final Exception e) {
      throw MESSAGES.invalidSha1Value(e, hash, Attribute.SHA1.getLocalName(), reader.getLocation());
    }

    list.add(addOp);
  }
  private void parseTransport(
      XMLExtendedStreamReader reader, ModelNode containerAddress, List<ModelNode> operations)
      throws XMLStreamException {

    // ModelNode for the transport add operation
    ModelNode transport = Util.getEmptyOperation(ModelDescriptionConstants.ADD, null);

    for (int i = 0; i < reader.getAttributeCount(); i++) {
      String value = reader.getAttributeValue(i);
      Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
      switch (attribute) {
        case STACK:
          {
            TransportResource.STACK.parseAndSetParameter(value, transport, reader);
            break;
          }
        case CLUSTER:
          {
            TransportResource.CLUSTER.parseAndSetParameter(value, transport, reader);
            break;
          }
        case EXECUTOR:
          {
            TransportResource.EXECUTOR.parseAndSetParameter(value, transport, reader);
            break;
          }
        case LOCK_TIMEOUT:
          {
            TransportResource.LOCK_TIMEOUT.parseAndSetParameter(value, transport, reader);
            break;
          }
        default:
          {
            throw ParseUtils.unexpectedAttribute(reader, i);
          }
      }
    }
    ParseUtils.requireNoContent(reader);

    // setup the transport address
    ModelNode transportAddress = containerAddress.clone();
    transportAddress.add(ModelKeys.TRANSPORT, ModelKeys.TRANSPORT_NAME);
    transportAddress.protect();
    transport.get(ModelDescriptionConstants.OP_ADDR).set(transportAddress);

    operations.add(transport);
  }
  @Test
  public void testPropertyValueTypeExpressionConverter() throws Exception {
    ModelNode description = createDescription(ModelType.PROPERTY, ModelType.INT);
    TypeConverter converter = getConverter(description);

    ModelNode node = new ModelNode();
    node.set("name", "${this.should.not.exist.!!!!!:1}");
    node.protect();

    ModelNode expected = node.clone().resolve();

    Assert.assertEquals(SimpleType.STRING, converter.getOpenType());
    String dmr = assertCast(String.class, converter.fromModelNode(node));
    Assert.assertEquals(expected, ModelNode.fromString(dmr));
    Assert.assertEquals(dmr, assertCast(String.class, converter.fromModelNode(expected)));
    assertToArray(converter, dmr);
  }
  private void parseInvalidationCache(
      XMLExtendedStreamReader reader, ModelNode containerAddress, List<ModelNode> operations)
      throws XMLStreamException {

    // ModelNode for the cache add operation
    ModelNode cache = Util.getEmptyOperation(ModelDescriptionConstants.ADD, null);

    for (int i = 0; i < reader.getAttributeCount(); i++) {
      String value = reader.getAttributeValue(i);
      Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
      this.parseClusteredCacheAttribute(reader, i, attribute, value, cache);
    }

    if (!cache.hasDefined(ModelKeys.NAME)) {
      throw ParseUtils.missingRequired(reader, EnumSet.of(Attribute.NAME));
    }
    if (!cache.hasDefined(ModelKeys.MODE)) {
      throw ParseUtils.missingRequired(reader, EnumSet.of(Attribute.MODE));
    }

    while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
      Element element = Element.forName(reader.getLocalName());
      switch (element) {
        case STATE_TRANSFER:
          {
            this.parseStateTransfer(reader, cache.get(ModelKeys.STATE_TRANSFER).setEmptyObject());
            break;
          }
        default:
          {
            this.parseCacheElement(reader, element, cache);
          }
      }
    }
    String name = cache.get(ModelKeys.NAME).asString();
    // setup the cache address
    ModelNode cacheAddress = containerAddress.clone();
    cacheAddress.add(ModelKeys.INVALIDATION_CACHE, name);
    cacheAddress.protect();
    cache.get(ModelDescriptionConstants.OP_ADDR).set(cacheAddress);

    // get rid of NAME now that we are finished with it
    cache.remove(ModelKeys.NAME);

    operations.add(cache);
  }
    /** @return the description of the operation augmented of the operation's entry flags. */
    ModelNode getDescription() {
      final ModelNode result = description.clone();
      boolean readOnly = flags.contains(OperationEntry.Flag.READ_ONLY);
      result.get(READ_ONLY).set(readOnly);
      if (!readOnly) {
        if (flags.contains(OperationEntry.Flag.RESTART_ALL_SERVICES)) {
          result.get(RESTART_REQUIRED).set(ALL_SERVICES);
        } else if (flags.contains(OperationEntry.Flag.RESTART_RESOURCE_SERVICES)) {
          result.get(RESTART_REQUIRED).set(RESOURCE_SERVICES);
        } else if (flags.contains(OperationEntry.Flag.RESTART_JVM)) {
          result.get(RESTART_REQUIRED).set(JVM);
        }
      }

      boolean runtimeOnly = flags.contains(OperationEntry.Flag.RUNTIME_ONLY);
      result.get(RUNTIME_ONLY).set(runtimeOnly);
      return result;
    }
  private void addManagementConnections(List<ModelNode> updates) {
    if (hostModel.get(CORE_SERVICE, MANAGEMENT, LDAP_CONNECTION).isDefined()) {
      ModelNode baseAddress = new ModelNode();
      baseAddress.add(CORE_SERVICE, MANAGEMENT);

      ModelNode connections = hostModel.get(CORE_SERVICE, MANAGEMENT, LDAP_CONNECTION);
      for (String connectionName : connections.keys()) {
        ModelNode addConnection = new ModelNode();
        // First take the properties to pass over.
        addConnection.set(connections.get(connectionName));

        // Now convert it to an operation by adding a name and address.
        ModelNode identityAddress = baseAddress.clone().add(LDAP_CONNECTION, connectionName);
        addConnection.get(OP).set(ADD);
        addConnection.get(OP_ADDR).set(identityAddress);

        updates.add(addConnection);
      }
    }
  }
Example #23
0
  @Override
  public void execute(OperationContext context, ModelNode operation)
      throws OperationFailedException {
    final Resource resource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS);
    final ModelNode model = resource.getModel();

    final String name = NAME.validateOperation(operation).asString();
    ModelNode variables = model.get(JvmAttributes.JVM_ENV_VARIABLES);
    if (variables.isDefined()) {
      final ModelNode values = variables.clone();
      model.get(JvmAttributes.JVM_ENV_VARIABLES).setEmptyList();

      for (Property value : values.asPropertyList()) {
        if (!value.getName().equals(name)) {
          model.get(JvmAttributes.JVM_ENV_VARIABLES).add(value.getName(), value.getValue());
        }
      }
    }

    context.stepCompleted();
  }
    /**
     * Creates data source and return its node address
     *
     * @param xa - should be data source XA?
     * @param jndiName of data source
     * @return ModelNode - address of data source node
     * @throws Exception
     */
    private ModelNode createDataSource(boolean xa, String jndiName) throws Exception {
      ModelNode address = new ModelNode();
      address.add(SUBSYSTEM, "datasources");
      address.add((xa ? "xa-" : "") + "data-source", jndiName);
      address.protect();

      ModelNode operation = new ModelNode();
      operation.get(OP).set(ADD);
      operation.get(OP_ADDR).set(address);
      operation.get("jndi-name").set(jndiName);
      operation.get("driver-name").set("h2");
      if (!xa) operation.get("connection-url").set("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1");
      operation.get("prepared-statements-cache-size").set(3);
      operation.get("user-name").set("sa");
      operation.get("password").set("sa");

      executeOperation(operation);

      if (xa) {
        final ModelNode xaDatasourcePropertiesAddress = address.clone();
        xaDatasourcePropertiesAddress.add("xa-datasource-properties", "URL");
        xaDatasourcePropertiesAddress.protect();
        final ModelNode xaDatasourcePropertyOperation = new ModelNode();
        xaDatasourcePropertyOperation.get(OP).set("add");
        xaDatasourcePropertyOperation.get(OP_ADDR).set(xaDatasourcePropertiesAddress);
        xaDatasourcePropertyOperation.get("value").set("jdbc:h2:mem:test");

        executeOperation(xaDatasourcePropertyOperation);
      }

      operation = new ModelNode();
      operation.get(OP).set("enable");
      operation.get(OP_ADDR).set(address);

      executeOperation(operation);

      return address;
    }
  private void parseLocalCache(
      XMLExtendedStreamReader reader, ModelNode containerAddress, List<ModelNode> operations)
      throws XMLStreamException {

    // ModelNode for the cache add operation
    ModelNode cache = Util.getEmptyOperation(ModelDescriptionConstants.ADD, null);

    // set the cache mode to local
    // cache.get(ModelKeys.MODE).set(Configuration.CacheMode.LOCAL.name());

    for (int i = 0; i < reader.getAttributeCount(); i++) {
      String value = reader.getAttributeValue(i);
      Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
      this.parseCacheAttribute(reader, i, attribute, value, cache);
    }

    if (!cache.hasDefined(ModelKeys.NAME)) {
      throw ParseUtils.missingRequired(reader, EnumSet.of(Attribute.NAME));
    }

    while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
      Element element = Element.forName(reader.getLocalName());
      this.parseCacheElement(reader, element, cache);
    }

    String name = cache.get(ModelKeys.NAME).asString();
    // setup the cache address
    ModelNode cacheAddress = containerAddress.clone();
    cacheAddress.add(ModelKeys.LOCAL_CACHE, name);
    cacheAddress.protect();
    cache.get(ModelDescriptionConstants.OP_ADDR).set(cacheAddress);

    // get rid of NAME now that we are finished with it
    cache.remove(ModelKeys.NAME);

    operations.add(cache);
  }
 private ModelNode trimSubsystem(ModelNode definition) {
   ModelNode def = definition.clone();
   def.get(CHILDREN).remove(SUBSYSTEM);
   return def;
 }
  private void parseRepository(
      final XMLExtendedStreamReader reader,
      final ModelNode address,
      final List<ModelNode> repositories)
      throws XMLStreamException {

    final ModelNode repositoryAddress = address.clone();
    final ModelNode repository =
        Util.getEmptyOperation(ModelDescriptionConstants.ADD, repositoryAddress);

    String repositoryName = null;
    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) {
          case NAME:
            repositoryName = attrValue;
            repositoryAddress.add("repository", attrValue); // $NON-NLS-1$
            repositoryAddress.protect();
            repository.get(OP).set(ADD);
            repository.get(OP_ADDR).set(repositoryAddress);
            repositories.add(repository);
            break;
          case CACHE_NAME:
            ModelAttributes.CACHE_NAME.parseAndSetParameter(attrValue, repository, reader);
            break;
          case CACHE_CONTAINER:
            ModelAttributes.CACHE_CONTAINER.parseAndSetParameter(attrValue, repository, reader);
            break;
          case JNDI_NAME:
            ModelAttributes.JNDI_NAME.parseAndSetParameter(attrValue, repository, reader);
            break;
          case ENABLE_MONITORING:
            ModelAttributes.ENABLE_MONITORING.parseAndSetParameter(attrValue, repository, reader);
            break;
          case SECURITY_DOMAIN:
            ModelAttributes.SECURITY_DOMAIN.parseAndSetParameter(attrValue, repository, reader);
            break;
          case ANONYMOUS_ROLES:
            for (String role : reader.getListAttributeValue(i)) {
              repository.get(ModelKeys.ANONYMOUS_ROLES).add(role);
            }
            break;
          case ANONYMOUS_USERNAME:
            ModelAttributes.ANONYMOUS_USERNAME.parseAndSetParameter(attrValue, repository, reader);
            break;
          case USE_ANONYMOUS_IF_AUTH_FAILED:
            ModelAttributes.USE_ANONYMOUS_IF_AUTH_FAILED.parseAndSetParameter(
                attrValue, repository, reader);
            break;
          case CLUSTER_STACK:
            ModelAttributes.CLUSTER_STACK.parseAndSetParameter(attrValue, repository, reader);
            break;
          case CLUSTER_NAME:
            ModelAttributes.CLUSTER_NAME.parseAndSetParameter(attrValue, repository, reader);
            break;
          default:
            throw ParseUtils.unexpectedAttribute(reader, i);
        }
      }
    }

    ModelNode indexStorage = null;
    ModelNode binaryStorage = null;
    List<ModelNode> sequencers = new ArrayList<ModelNode>();
    List<ModelNode> textExtractors = new ArrayList<ModelNode>();
    while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
      Element element = Element.forName(reader.getLocalName());
      switch (element) {
        case WORKSPACES:
          parseWorkspaces(reader, address, repository);
          break;
        case INDEXING:
          parseIndexing(reader, address, repository);
          break;

          // Index storage ...
        case RAM_INDEX_STORAGE:
          addIndexStorageConfiguration(repositories, repositoryName);
          indexStorage = parseRamIndexStorage(reader, repositoryName);
          break;
        case LOCAL_FILE_INDEX_STORAGE:
          addIndexStorageConfiguration(repositories, repositoryName);
          indexStorage =
              parseFileIndexStorage(reader, repositoryName, ModelKeys.LOCAL_FILE_INDEX_STORAGE);
          break;
        case MASTER_FILE_INDEX_STORAGE:
          addIndexStorageConfiguration(repositories, repositoryName);
          indexStorage =
              parseFileIndexStorage(reader, repositoryName, ModelKeys.MASTER_FILE_INDEX_STORAGE);
          break;
        case SLAVE_FILE_INDEX_STORAGE:
          addIndexStorageConfiguration(repositories, repositoryName);
          indexStorage =
              parseFileIndexStorage(reader, repositoryName, ModelKeys.SLAVE_FILE_INDEX_STORAGE);
          break;
        case CACHE_INDEX_STORAGE:
          addIndexStorageConfiguration(repositories, repositoryName);
          indexStorage = parseCacheIndexStorage(reader, repositoryName);
          break;
        case CUSTOM_INDEX_STORAGE:
          addIndexStorageConfiguration(repositories, repositoryName);
          indexStorage = parseCustomIndexStorage(reader, repositoryName);
          break;

          // Binary storage ...
        case FILE_BINARY_STORAGE:
          addBinaryStorageConfiguration(repositories, repositoryName);
          binaryStorage = parseFileBinaryStorage(reader, repositoryName);
          break;
        case DB_BINARY_STORAGE:
          addBinaryStorageConfiguration(repositories, repositoryName);
          binaryStorage = parseDatabaseBinaryStorage(reader, repositoryName);
          break;
        case CACHE_BINARY_STORAGE:
          addBinaryStorageConfiguration(repositories, repositoryName);
          binaryStorage = parseCacheBinaryStorage(reader, repositoryName);
          break;
        case CUSTOM_BINARY_STORAGE:
          addBinaryStorageConfiguration(repositories, repositoryName);
          binaryStorage = parseCustomBinaryStorage(reader, repositoryName);
          break;

          // Sequencing ...
        case AUTHENTICATORS:
          parseAuthenticators(reader, address, repository);
          break;

          // Sequencing ...
        case SEQUENCERS:
          sequencers = parseSequencers(reader, address, repositoryName);
          break;

          // Text extracting ...
        case TEXT_EXTRACTORS:
          textExtractors = parseTextExtracting(reader, repositoryName);
          break;

        default:
          throw ParseUtils.unexpectedElement(reader);
      }
    }

    if (indexStorage != null) repositories.add(indexStorage);
    if (binaryStorage != null) repositories.add(binaryStorage);
    repositories.addAll(sequencers);
    repositories.addAll(textExtractors);
  }
Example #28
0
    void parseQueuelessThreadPool(
        final XMLExtendedStreamReader reader,
        final ModelNode parentAddress,
        final List<ModelNode> list)
        throws XMLStreamException {
      final ModelNode op = new ModelNode();
      list.add(op);
      op.get(OP).set(ADD);

      String name = null;
      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 NAME:
            {
              name = value;
              break;
            }
          case BLOCKING:
            {
              op.get(BLOCKING).set(Boolean.valueOf(value));
              break;
            }
          default:
            throw unexpectedAttribute(reader, i);
        }
      }

      if (name == null) {
        throw missingRequired(reader, Collections.singleton(Attribute.NAME));
      }

      // FIXME Make relative and use this scheme to add the addresses
      // address.add("profile", "test).add("subsystem", "threads")
      final ModelNode address = parentAddress.clone();
      address.add(QUEUELESS_THREAD_POOL, name);
      address.protect();
      op.get(OP_ADDR).set(address);

      boolean foundMaxThreads = false;
      while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        switch (Element.forName(reader.getLocalName())) {
          case HANDOFF_EXECUTOR:
            {
              op.get(HANDOFF_EXECUTOR).set(parseRef(reader));
              break;
            }
          case MAX_THREADS:
            {
              op.get(MAX_THREADS).set(parseScaledCount(reader));
              foundMaxThreads = true;
              break;
            }
          case KEEPALIVE_TIME:
            {
              op.get(KEEPALIVE_TIME).set(parseTimeSpec(reader));
              break;
            }
          case THREAD_FACTORY:
            {
              op.get(CommonAttributes.THREAD_FACTORY).set(parseRef(reader));
              break;
            }
          case PROPERTIES:
            {
              ModelNode props = parseProperties(reader);
              if (props.isDefined()) {
                op.get(PROPERTIES).set(props);
              }
              break;
            }
          default:
            {
              throw unexpectedElement(reader);
            }
        }
      }
      if (!foundMaxThreads) {
        throw missingRequiredElement(reader, Collections.singleton(Element.MAX_THREADS));
      }
    }
Example #29
0
    void parseBoundedQueueThreadPool(
        final XMLExtendedStreamReader reader,
        final ModelNode parentAddress,
        final List<ModelNode> list)
        throws XMLStreamException {
      final ModelNode op = new ModelNode();
      list.add(op);
      op.get(OP).set(ADD);

      String name = null;
      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 NAME:
            {
              name = value;
              break;
            }
          case BLOCKING:
            {
              op.get(BLOCKING).set(Boolean.valueOf(value));
              break;
            }
          case ALLOW_CORE_TIMEOUT:
            {
              op.get(ALLOW_CORE_TIMEOUT).set(Boolean.valueOf(value));
              break;
            }
          default:
            throw unexpectedAttribute(reader, i);
        }
      }

      if (name == null) {
        throw missingRequired(reader, Collections.singleton(Attribute.NAME));
      }

      final ModelNode address = parentAddress.clone();
      address.add(BOUNDED_QUEUE_THREAD_POOL, name);
      address.protect();
      op.get(OP_ADDR).set(address);

      boolean foundQueueLength = false;
      boolean foundMaxThreads = false;
      while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        switch (Element.forName(reader.getLocalName())) {
          case CORE_THREADS:
            {
              op.get(CORE_THREADS).set(parseScaledCount(reader));
              break;
            }
          case HANDOFF_EXECUTOR:
            {
              op.get(HANDOFF_EXECUTOR).set(parseRef(reader));
              break;
            }
          case MAX_THREADS:
            {
              op.get(MAX_THREADS).set(parseScaledCount(reader));
              foundMaxThreads = true;
              break;
            }
          case KEEPALIVE_TIME:
            {
              op.get(KEEPALIVE_TIME).set(parseTimeSpec(reader));
              break;
            }
          case THREAD_FACTORY:
            {
              op.get(CommonAttributes.THREAD_FACTORY).set(parseRef(reader));
              break;
            }
          case PROPERTIES:
            {
              ModelNode props = parseProperties(reader);
              if (props.isDefined()) {
                op.get(PROPERTIES).set(props);
              }
              break;
            }
          case QUEUE_LENGTH:
            {
              op.get(QUEUE_LENGTH).set(parseScaledCount(reader));
              foundQueueLength = true;
              break;
            }
          default:
            {
              throw unexpectedElement(reader);
            }
        }
      }
      if (!foundMaxThreads || !foundQueueLength) {
        Set<Element> missing = new HashSet<Element>();
        if (!foundMaxThreads) {
          missing.add(Element.MAX_THREADS);
        }
        if (!foundQueueLength) {
          missing.add(Element.QUEUE_LENGTH);
        }
        throw missingRequiredElement(reader, missing);
      }
    }
Example #30
0
    private void parseThreadFactory(
        final XMLExtendedStreamReader reader,
        final ModelNode parentAddress,
        final List<ModelNode> list)
        throws XMLStreamException {
      final ModelNode op = new ModelNode();
      list.add(op);

      op.get(OP).set(ADD);

      String name = null;
      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 NAME:
            {
              name = value;
              break;
            }
          case GROUP_NAME:
            {
              op.get(GROUP_NAME).set(value);
              break;
            }
          case THREAD_NAME_PATTERN:
            {
              op.get(THREAD_NAME_PATTERN).set(value);
              break;
            }
          case PRIORITY:
            {
              try {
                int priority = Integer.valueOf(value);
                op.get(PRIORITY).set(priority);
              } catch (NumberFormatException e) {
                invalidAttributeValue(reader, i);
              }
            }
            break;
          default:
            throw unexpectedAttribute(reader, i);
        }
      }

      if (name == null) {
        throw missingRequired(reader, Collections.singleton(Attribute.NAME));
      }

      final ModelNode address = parentAddress.clone();
      address.add(THREAD_FACTORY, name);
      address.protect();
      op.get(OP_ADDR).set(address);

      while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        switch (Element.forName(reader.getLocalName())) {
          case PROPERTIES:
            {
              ModelNode props = parseProperties(reader);
              if (props.isDefined()) {
                op.get(PROPERTIES).set(props);
              }
              break;
            }
          default:
            {
              throw unexpectedElement(reader);
            }
        }
        break;
      }
    }