コード例 #1
0
ファイル: QueueDefinition.java プロジェクト: Chaohua/wildfly
  /**
   * [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;
    }
  }
コード例 #2
0
  @Override
  protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model)
      throws OperationFailedException {

    ServiceRegistry registry = context.getServiceRegistry(false);
    final ServiceName serviceName =
        MessagingServices.getActiveMQServiceName(
            PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
    ServiceController<?> service = registry.getService(serviceName);
    if (service != null) {
      context.reloadRequired();
    } else {
      final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
      final String name = address.getLastElement().getValue();

      final ServiceTarget target = context.getServiceTarget();
      if (model.hasDefined(JGROUPS_CHANNEL.getName())) {
        // nothing to do, in that case, the clustering.jgroups subsystem will have setup the stack
      } else if (model.hasDefined(RemoteTransportDefinition.SOCKET_BINDING.getName())) {
        final GroupBindingService bindingService = new GroupBindingService();
        target
            .addService(
                GroupBindingService.getBroadcastBaseServiceName(serviceName).append(name),
                bindingService)
            .addDependency(
                SocketBinding.JBOSS_BINDING_NAME.append(model.get(SOCKET_BINDING).asString()),
                SocketBinding.class,
                bindingService.getBindingRef())
            .install();
      }
    }
  }
コード例 #3
0
 private AddressControl getAddressControl(
     final OperationContext context, final ModelNode operation) {
   final String addressName =
       PathAddress.pathAddress(operation.require(OP_ADDR)).getLastElement().getValue();
   final ServiceName hqServiceName =
       MessagingServices.getHornetQServiceName(
           PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
   ServiceController<?> hqService = context.getServiceRegistry(false).getService(hqServiceName);
   HornetQServer hqServer = HornetQServer.class.cast(hqService.getValue());
   return AddressControl.class.cast(
       hqServer.getManagementService().getResource(ResourceNames.CORE_ADDRESS + addressName));
 }
コード例 #4
0
  @Override
  protected void performRuntime(
      OperationContext context,
      ModelNode operation,
      ModelNode model,
      ServiceVerificationHandler verificationHandler,
      List<ServiceController<?>> newControllers)
      throws OperationFailedException {

    ServiceRegistry registry = context.getServiceRegistry(false);
    final ServiceName hqServiceName =
        MessagingServices.getHornetQServiceName(
            PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
    ServiceController<?> hqService = registry.getService(hqServiceName);
    if (hqService != null) {
      context.reloadRequired();
    }
    // else MessagingSubsystemAdd will add a handler that calls addConnectorServiceConfigs
  }
コード例 #5
0
  @Override
  public void executeRuntimeStep(OperationContext context, ModelNode operation)
      throws OperationFailedException {
    final String attributeName = operation.require(ModelDescriptionConstants.NAME).asString();

    PathAddress pathAddress =
        PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR));
    String addressName = pathAddress.getElement(pathAddress.size() - 2).getValue();
    String roleName = pathAddress.getLastElement().getValue();

    final ServiceName serviceName =
        MessagingServices.getActiveMQServiceName(
            PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
    ServiceController<?> service = context.getServiceRegistry(false).getService(serviceName);
    ActiveMQServer server = ActiveMQServer.class.cast(service.getValue());
    AddressControl control =
        AddressControl.class.cast(
            server.getManagementService().getResource(ResourceNames.CORE_ADDRESS + addressName));

    if (control == null) {
      PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
      throw ControllerLogger.ROOT_LOGGER.managementResourceNotFound(address);
    }

    try {
      String rolesAsJSON = control.getRolesAsJSON();
      ModelNode res = ModelNode.fromJSONString(rolesAsJSON);
      ModelNode roles = ManagementUtil.convertSecurityRole(res);
      ModelNode matchedRole = findRole(roleName, roles);
      if (matchedRole == null || !matchedRole.hasDefined(attributeName)) {
        throw MessagingLogger.ROOT_LOGGER.unsupportedAttribute(attributeName);
      }
      boolean value = matchedRole.get(attributeName).asBoolean();
      context.getResult().set(value);
    } catch (Exception e) {
      context.getFailureDescription().set(e.getLocalizedMessage());
    }
  }
コード例 #6
0
  @Override
  public void executeRuntimeStep(OperationContext context, ModelNode operation)
      throws OperationFailedException {
    if (ignoreOperationIfServerNotActive(context, operation)) {
      return;
    }

    validator.validate(operation);
    final String attributeName = operation.require(ModelDescriptionConstants.NAME).asString();

    PathAddress address =
        PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR));
    String queueName = address.getLastElement().getValue();

    if (forwardToRuntimeQueue(context, operation, RUNTIME_INSTANCE)) {
      return;
    }

    final ServiceName serviceName = MessagingServices.getActiveMQServiceName(address);
    ServiceController<?> service = context.getServiceRegistry(false).getService(serviceName);
    ActiveMQServer server = ActiveMQServer.class.cast(service.getValue());
    QueueControl control =
        QueueControl.class.cast(
            server.getManagementService().getResource(ResourceNames.CORE_QUEUE + queueName));

    if (control == null) {
      throw ControllerLogger.ROOT_LOGGER.managementResourceNotFound(address);
    }

    if (MESSAGE_COUNT.getName().equals(attributeName)) {
      context.getResult().set(control.getMessageCount());
    } else if (SCHEDULED_COUNT.getName().equals(attributeName)) {
      context.getResult().set(control.getScheduledCount());
    } else if (CONSUMER_COUNT.getName().equals(attributeName)) {
      context.getResult().set(control.getConsumerCount());
    } else if (DELIVERING_COUNT.getName().equals(attributeName)) {
      context.getResult().set(control.getDeliveringCount());
    } else if (MESSAGES_ADDED.getName().equals(attributeName)) {
      context.getResult().set(control.getMessagesAdded());
    } else if (ID.getName().equals(attributeName)) {
      context.getResult().set(control.getID());
    } else if (PAUSED.getName().equals(attributeName)) {
      try {
        context.getResult().set(control.isPaused());
      } catch (RuntimeException e) {
        throw e;
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    } else if (TEMPORARY.getName().equals(attributeName)) {
      context.getResult().set(control.isTemporary());
    } else if (EXPIRY_ADDRESS.getName().equals(attributeName)) {
      if (control.getExpiryAddress() != null) {
        context.getResult().set(control.getExpiryAddress());
      }
    } else if (DEAD_LETTER_ADDRESS.getName().equals(attributeName)) {
      if (control.getDeadLetterAddress() != null) {
        context.getResult().set(control.getDeadLetterAddress());
      }
    } else if (readStorageAttributes && getStorageAttributeNames().contains(attributeName)) {
      if (ADDRESS.getName().equals(attributeName)) {
        context.getResult().set(control.getAddress());
      } else if (DURABLE.getName().equals(attributeName)) {
        context.getResult().set(control.isDurable());
      } else if (FILTER.getName().equals(attributeName)) {
        ModelNode result = context.getResult();
        String filter = control.getFilter();
        if (filter != null) {
          result.set(filter);
        }
      }
    } else {
      throw MessagingLogger.ROOT_LOGGER.unsupportedAttribute(attributeName);
    }
  }