Ejemplo n.º 1
0
  void parseSocketBindingGroup_1_0(
      final XMLExtendedStreamReader reader,
      final Set<String> interfaces,
      final ModelNode address,
      final Namespace expectedNs,
      final List<ModelNode> updates)
      throws XMLStreamException {
    final Set<String> includedGroups = new HashSet<String>();
    // unique socket-binding names
    final Set<String> uniqueBindingNames = new HashSet<String>();

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

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

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

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

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

    // Handle elements
    while (reader.nextTag() != END_ELEMENT) {
      requireNamespace(reader, expectedNs);
      final Element element = Element.forName(reader.getLocalName());
      switch (element) {
        case INCLUDE:
          {
            HOST_CONTROLLER_LOGGER.warnIgnoringSocketBindingGroupInclude(reader.getLocation());

            /* This will be reintroduced for 7.2.0, leave commented out
            final String includedGroup = readStringAttributeElement(reader, Attribute.SOCKET_BINDING_GROUP.getLocalName());
            if (!includedGroups.add(includedGroup)) {
                throw MESSAGES.alreadyDeclared(Attribute.SOCKET_BINDING_GROUP.getLocalName(), includedGroup, reader.getLocation());
            }
            SocketBindingGroupResourceDefinition.INCLUDES.parseAndAddParameterElement(includedGroup, bindingGroupUpdate, reader.getLocation());
            */
            break;
          }
        case SOCKET_BINDING:
          {
            final String bindingName =
                parseSocketBinding(reader, interfaces, groupAddress, updates);
            if (!uniqueBindingNames.add(bindingName)) {
              throw MESSAGES.alreadyDeclared(
                  Element.SOCKET_BINDING.getLocalName(),
                  bindingName,
                  Element.SOCKET_BINDING_GROUP.getLocalName(),
                  socketBindingGroupName,
                  reader.getLocation());
            }
            break;
          }
        default:
          throw unexpectedElement(reader);
      }
    }
  }
Ejemplo n.º 2
0
  void parseProfiles(
      final XMLExtendedStreamReader reader,
      final ModelNode address,
      final Namespace expectedNs,
      final List<ModelNode> list)
      throws XMLStreamException {
    requireNoAttributes(reader);

    final Set<String> names = new HashSet<String>();

    while (reader.nextTag() != END_ELEMENT) {
      requireNamespace(reader, expectedNs);
      Element element = Element.forName(reader.getLocalName());
      if (Element.PROFILE != element) {
        throw unexpectedElement(reader);
      }

      // Attributes
      requireSingleAttribute(reader, Attribute.NAME.getLocalName());
      final String name = reader.getAttributeValue(0);
      if (!names.add(name)) {
        throw MESSAGES.duplicateDeclaration("profile", name, reader.getLocation());
      }

      // final Set<String> includes = new HashSet<String>();  // See commented out section below.
      // final ModelNode profileIncludes = new ModelNode();

      // Content
      // Sequence
      final Map<String, List<ModelNode>> profileOps = new LinkedHashMap<String, List<ModelNode>>();
      while (reader.nextTag() != END_ELEMENT) {
        Namespace ns = Namespace.forUri(reader.getNamespaceURI());
        switch (ns) {
          case UNKNOWN:
            {
              if (Element.forName(reader.getLocalName()) != Element.SUBSYSTEM) {
                throw unexpectedElement(reader);
              }
              String namespace = reader.getNamespaceURI();
              if (profileOps.containsKey(namespace)) {
                throw MESSAGES.duplicateDeclaration("subsystem", name, reader.getLocation());
              }
              // parse content
              final List<ModelNode> subsystems = new ArrayList<ModelNode>();
              reader.handleAny(subsystems);

              profileOps.put(namespace, subsystems);

              break;
            }
          case DOMAIN_1_0:
          case DOMAIN_1_1:
          case DOMAIN_1_2:
          case DOMAIN_1_3:
            {
              requireNamespace(reader, expectedNs);
              // include should come first
              if (profileOps.size() > 0) {
                throw unexpectedElement(reader);
              }
              if (Element.forName(reader.getLocalName()) != Element.INCLUDE) {
                throw unexpectedElement(reader);
              }
              // Remove support for profile includes until 7.2.0
              if (ns == Namespace.DOMAIN_1_0) {
                HOST_CONTROLLER_LOGGER.warnIgnoringProfileInclude(reader.getLocation());
              }
              throw unexpectedElement(reader);
              /* This will be reintroduced for 7.2.0, leave commented out
              final String includedName = readStringAttributeElement(reader, Attribute.PROFILE.getLocalName());
              if (! names.contains(includedName)) {
                  throw MESSAGES.profileNotFound(reader.getLocation());
              }
              if (! includes.add(includedName)) {
                  throw MESSAGES.duplicateProfile(reader.getLocation());
              }
              profileIncludes.add(includedName);
              break;
              */
            }
          default:
            {
              throw unexpectedElement(reader);
            }
        }
      }

      // Let extensions modify the profile
      Set<ProfileParsingCompletionHandler> completionHandlers =
          extensionRegistry.getProfileParsingCompletionHandlers();
      for (ProfileParsingCompletionHandler completionHandler : completionHandlers) {
        completionHandler.handleProfileParsingCompletion(profileOps, list);
      }

      final ModelNode profile = new ModelNode();
      profile.get(OP).set(ADD);
      profile.get(OP_ADDR).set(address).add(ModelDescriptionConstants.PROFILE, name);
      /* This will be reintroduced for 7.2.0, leave commented out
      profile.get(INCLUDES).set(profileIncludes);
      */
      list.add(profile);

      // Process subsystems
      for (List<ModelNode> subsystems : profileOps.values()) {
        for (final ModelNode update : subsystems) {
          // Process relative subsystem path address
          final ModelNode subsystemAddress =
              address.clone().set(address).add(ModelDescriptionConstants.PROFILE, name);
          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);
        }
      }

      if (profileOps.size() == 0) {
        throw MESSAGES.profileHasNoSubsystems(reader.getLocation());
      }
    }
  }
Ejemplo n.º 3
0
  @Override
  public void execute(final OperationContext context, final ModelNode operation)
      throws OperationFailedException {

    if (context.hasFailureDescription()) {
      // abort
      context.setRollbackOnly();
      context.completeStep();
      return;
    }

    final Set<String> outstanding = new HashSet<String>(hostProxies.keySet());
    final List<
            TransactionalProtocolClient.PreparedOperation<HostControllerUpdateTask.ProxyOperation>>
        results =
            new ArrayList<
                TransactionalProtocolClient.PreparedOperation<
                    HostControllerUpdateTask.ProxyOperation>>();
    final Map<String, HostControllerUpdateTask.ExecutedHostRequest> finalResults =
        new HashMap<String, HostControllerUpdateTask.ExecutedHostRequest>();
    final HostControllerUpdateTask.ProxyOperationListener listener =
        new HostControllerUpdateTask.ProxyOperationListener();
    for (Map.Entry<String, ProxyController> entry : hostProxies.entrySet()) {
      // Create the proxy task
      final String host = entry.getKey();
      final TransformingProxyController proxyController =
          (TransformingProxyController) entry.getValue();
      List<DomainOperationTransformer> transformers =
          context.getAttachment(OperationAttachments.SLAVE_SERVER_OPERATION_TRANSFORMERS);
      ModelNode op = operation;
      if (transformers != null) {
        for (final DomainOperationTransformer transformer : transformers) {
          op = transformer.transform(context, op);
        }
      }
      final HostControllerUpdateTask task =
          new HostControllerUpdateTask(host, op.clone(), context, proxyController);
      // Execute the operation on the remote host
      final HostControllerUpdateTask.ExecutedHostRequest finalResult = task.execute(listener);
      finalResults.put(host, finalResult);
    }

    // Wait for all hosts to reach the prepared state
    boolean interrupted = false;
    try {
      try {
        while (outstanding.size() > 0) {
          final TransactionalProtocolClient.PreparedOperation<
                  HostControllerUpdateTask.ProxyOperation>
              prepared = listener.retrievePreparedOperation();
          final String hostName = prepared.getOperation().getName();
          if (!outstanding.remove(hostName)) {
            continue;
          }
          final ModelNode preparedResult = prepared.getPreparedResult();
          if (HOST_CONTROLLER_LOGGER.isTraceEnabled()) {
            HOST_CONTROLLER_LOGGER.tracef(
                "Preliminary result for remote host %s is %s", hostName, preparedResult);
          }
          domainOperationContext.addHostControllerResult(hostName, preparedResult);
          results.add(prepared);
        }
      } catch (InterruptedException ie) {
        interrupted = true;
        // Set rollback only
        domainOperationContext.setFailureReported(true);
        // Rollback all HCs
        for (final HostControllerUpdateTask.ExecutedHostRequest finalResult :
            finalResults.values()) {
          finalResult.asyncCancel();
        }
        // Wait that all hosts are rolled back!?
        for (final Map.Entry<String, HostControllerUpdateTask.ExecutedHostRequest> entry :
            finalResults.entrySet()) {
          final String hostName = entry.getKey();
          try {
            final HostControllerUpdateTask.ExecutedHostRequest request = entry.getValue();
            final ModelNode result = request.getFinalResult().get();
            final ModelNode transformedResult = request.transformResult(result);
            domainOperationContext.addHostControllerResult(hostName, transformedResult);
          } catch (Exception e) {
            final ModelNode result = new ModelNode();
            result.get(OUTCOME).set(FAILED);
            if (e instanceof InterruptedException) {
              result
                  .get(FAILURE_DESCRIPTION)
                  .set(MESSAGES.interruptedAwaitingResultFromHost(entry.getKey()));
              interrupted = true;
            } else {
              result
                  .get(FAILURE_DESCRIPTION)
                  .set(MESSAGES.exceptionAwaitingResultFromHost(entry.getKey(), e.getMessage()));
            }
            domainOperationContext.addHostControllerResult(hostName, result);
          }
        }
      }

      context.completeStep();

    } finally {
      try {
        // Inform the remote hosts whether to commit or roll back their updates
        // Do this in parallel
        boolean rollback = domainOperationContext.isCompleteRollback();
        for (final TransactionalProtocolClient.PreparedOperation<
                HostControllerUpdateTask.ProxyOperation>
            prepared : results) {
          if (prepared.isDone()) {
            continue;
          }
          if (!rollback) {
            prepared.commit();
          } else {
            prepared.rollback();
          }
        }
        // Now get the final results from the hosts
        for (final TransactionalProtocolClient.PreparedOperation<
                HostControllerUpdateTask.ProxyOperation>
            prepared : results) {
          final String hostName = prepared.getOperation().getName();
          try {
            final ModelNode finalResult = prepared.getFinalResult().get();
            domainOperationContext.addHostControllerResult(hostName, finalResult);

            if (HOST_CONTROLLER_LOGGER.isTraceEnabled()) {
              HOST_CONTROLLER_LOGGER.tracef(
                  "Final result for remote host %s is %s", hostName, finalResult);
            }
          } catch (InterruptedException e) {
            interrupted = true;
            CONTROLLER_LOGGER.interruptedAwaitingFinalResponse(hostName);
          } catch (ExecutionException e) {
            CONTROLLER_LOGGER.caughtExceptionAwaitingFinalResponse(e.getCause(), hostName);
          }
        }
      } finally {
        if (interrupted) {
          Thread.currentThread().interrupt();
        }
      }
    }
  }