Exemplo n.º 1
0
  static BroadcastGroupConfiguration createBroadcastGroupConfiguration(
      final OperationContext context,
      final Set<String> connectors,
      final String name,
      final ModelNode model)
      throws OperationFailedException {

    final long broadcastPeriod =
        BroadcastGroupDefinition.BROADCAST_PERIOD.resolveModelAttribute(context, model).asLong();
    final List<String> connectorRefs = new ArrayList<String>();
    if (model.hasDefined(CommonAttributes.CONNECTORS)) {
      for (ModelNode ref : model.get(CommonAttributes.CONNECTORS).asList()) {
        final String refName = ref.asString();
        if (!connectors.contains(refName)) {
          throw MessagingLogger.ROOT_LOGGER.wrongConnectorRefInBroadCastGroup(
              name, refName, connectors);
        }
        connectorRefs.add(refName);
      }
    }

    return new BroadcastGroupConfiguration()
        .setName(name)
        .setBroadcastPeriod(broadcastPeriod)
        .setConnectorInfos(connectorRefs);
  }
 private static void checkFactoryClass(final String factoryClass) throws OperationFailedException {
   try {
     ClassloadingUtil.newInstanceFromClassLoader(factoryClass);
   } catch (Throwable t) {
     throw MessagingLogger.ROOT_LOGGER.unableToLoadConnectorServiceFactoryClass(factoryClass);
   }
 }
  @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());
    }
  }
  @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);
    }
  }