@Override
    public void execute(OperationContext context, ModelNode operation)
        throws OperationFailedException {
      final String attribute = operation.require(NAME).asString();
      final SensitivityClassificationResource resource =
          (SensitivityClassificationResource) context.readResource(PathAddress.EMPTY_ADDRESS);
      final AbstractSensitivity classification = resource.classification;
      Boolean result = null;
      if (attribute.equals(DEFAULT_REQUIRES_ADDRESSABLE.getName())) {
        result = classification.isDefaultRequiresAccessPermission();
      } else if (attribute.equals(DEFAULT_REQUIRES_READ.getName())) {
        result = classification.isDefaultRequiresReadPermission();
      } else if (attribute.equals(DEFAULT_REQUIRES_WRITE.getName())) {
        result = classification.isDefaultRequiresWritePermission();
      } else if (attribute.equals(CONFIGURED_REQUIRES_ADDRESSABLE.getName())) {
        result = classification.getConfiguredRequiresAccessPermission();
      } else if (attribute.equals(CONFIGURED_REQUIRES_READ.getName())) {
        result = classification.getConfiguredRequiresReadPermission();
      } else if (attribute.equals(CONFIGURED_REQUIRES_WRITE.getName())) {
        result = classification.getConfiguredRequiresWritePermission();
      } else {
        // TODO i18n
        throw new IllegalStateException();
      }

      context.getResult();
      if (result != null) {
        context.getResult().set(result);
      }
      context.stepCompleted();
    }
  @Override
  public void execute(OperationContext context, ModelNode operation)
      throws OperationFailedException {

    validator.validate(operation);
    ThreadMXBean mbean = ManagementFactory.getThreadMXBean();
    try {
      long id = operation.require(PlatformMBeanConstants.ID).asLong();
      ThreadInfo info = null;
      if (operation.hasDefined(PlatformMBeanConstants.MAX_DEPTH)) {
        info = mbean.getThreadInfo(id, operation.require(PlatformMBeanConstants.MAX_DEPTH).asInt());
      } else {
        info = mbean.getThreadInfo(id);
      }

      final ModelNode result = context.getResult();
      if (info != null) {
        result.set(PlatformMBeanUtil.getDetypedThreadInfo(info, mbean.isThreadCpuTimeSupported()));
      }
    } catch (SecurityException e) {
      throw new OperationFailedException(new ModelNode().set(e.toString()));
    }

    context.completeStep();
  }
  @Override
  public void execute(OperationContext context, ModelNode operation)
      throws OperationFailedException {

    String operationName = NAME.resolveModelAttribute(context, operation).asString();
    boolean accessControl = ACCESS_CONTROL.resolveModelAttribute(context, operation).asBoolean();

    final DescribedOp describedOp =
        getDescribedOp(context, operationName, operation, !accessControl);
    if (describedOp == null
        || (context.getProcessType() == ProcessType.DOMAIN_SERVER
            && !describedOp.flags.contains(OperationEntry.Flag.RUNTIME_ONLY))) {
      throw new OperationFailedException(
          ControllerLogger.ROOT_LOGGER.operationNotRegistered(
              operationName, context.getCurrentAddress()));
    } else {
      ModelNode result = describedOp.getDescription();

      if (accessControl) {
        final PathAddress address = context.getCurrentAddress();
        ModelNode operationToCheck = Util.createOperation(operationName, address);
        operationToCheck.get(OPERATION_HEADERS).set(operation.get(OPERATION_HEADERS));
        AuthorizationResult authorizationResult = context.authorizeOperation(operationToCheck);
        result
            .get(ACCESS_CONTROL.getName(), EXECUTE)
            .set(authorizationResult.getDecision() == Decision.PERMIT);
      }

      context.getResult().set(result);
    }
  }
  @Override
  public void execute(OperationContext context, ModelNode operation)
      throws OperationFailedException {

    final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
    final PathElement element = address.getLastElement();
    final String serverName = element.getValue();

    final ModelNode subModel = context.readModel(PathAddress.EMPTY_ADDRESS);
    final boolean isStart;
    if (subModel.hasDefined(AUTO_START)) {
      isStart = subModel.get(AUTO_START).asBoolean();
    } else {
      isStart = true;
    }

    ServerStatus status = serverInventory.determineServerStatus(serverName);

    if (status == ServerStatus.STOPPED) {
      status = isStart ? status : ServerStatus.DISABLED;
    }

    if (status != null) {
      context.getResult().set(status.toString());
      context.completeStep();
    } else {
      throw new OperationFailedException(new ModelNode().set("Failed to get server status"));
    }
  }
  @Override
  protected void executeRuntimeStep(OperationContext context, ModelNode operation)
      throws OperationFailedException {
    // Address is of the form:
    // /subsystem=infinispan/cache-container=*/*-cache=*/transaction=TRANSACTION
    PathAddress address = context.getCurrentAddress();
    String containerName = address.getElement(address.size() - 3).getValue();
    String cacheName = address.getElement(address.size() - 2).getValue();
    String name = operation.require(ModelDescriptionConstants.NAME).asString();

    TransactionMetric metric = TransactionMetric.forName(name);

    if (metric == null) {
      context.getFailureDescription().set(InfinispanLogger.ROOT_LOGGER.unknownMetric(name));
    } else {
      Cache<?, ?> cache =
          ServiceContainerHelper.findValue(
              context.getServiceRegistry(false),
              CacheServiceName.CACHE.getServiceName(containerName, cacheName));
      if (cache != null) {
        TxInterceptor interceptor = CacheMetric.findInterceptor(cache, TxInterceptor.class);
        context
            .getResult()
            .set((interceptor != null) ? metric.getValue(interceptor) : new ModelNode(0));
      }
    }
    context.completeStep(OperationContext.ResultHandler.NOOP_RESULT_HANDLER);
  }
 void updateModel(final OperationContext context, ModelNode model, ModelNode listAttribute)
     throws OperationFailedException {
   int index = INDEX.resolveModelAttribute(context, model).asInt();
   if (listAttribute.hasDefined(index)) {
     context.getResult().set(listAttribute.get(index));
   }
 }
  @Override
  protected void executeReadAttribute(OperationContext context, ModelNode operation)
      throws OperationFailedException {

    final String mmName =
        PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR))
            .getLastElement()
            .getValue();
    final String name = operation.require(ModelDescriptionConstants.NAME).asString();

    MemoryManagerMXBean memoryManagerMXBean = null;

    for (MemoryManagerMXBean mbean : ManagementFactory.getMemoryManagerMXBeans()) {
      if (mmName.equals(escapeMBeanName(mbean.getName()))) {
        memoryManagerMXBean = mbean;
      }
    }

    if (memoryManagerMXBean == null) {
      throw PlatformMBeanMessages.MESSAGES.unknownMemoryManager(mmName);
    }

    if (PlatformMBeanUtil.JVM_MAJOR_VERSION > 6
        && PlatformMBeanConstants.OBJECT_NAME.equals(name)) {
      final String objName =
          PlatformMBeanUtil.getObjectNameStringWithNameKey(
              ManagementFactory.MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE, mmName);
      context.getResult().set(objName);
    } else if (ModelDescriptionConstants.NAME.equals(name)) {
      context.getResult().set(escapeMBeanName(memoryManagerMXBean.getName()));
    } else if (PlatformMBeanConstants.VALID.equals(name)) {
      context.getResult().set(memoryManagerMXBean.isValid());
    } else if (PlatformMBeanConstants.MEMORY_POOL_NAMES.equals(name)) {
      final ModelNode result = context.getResult();
      result.setEmptyList();
      for (String pool : memoryManagerMXBean.getMemoryPoolNames()) {
        result.add(escapeMBeanName(pool));
      }
    } else if (PlatformMBeanConstants.MEMORY_MANAGER_READ_ATTRIBUTES.contains(name)) {
      // Bug
      throw PlatformMBeanMessages.MESSAGES.badReadAttributeImpl5(name);
    } else {
      // Shouldn't happen; the global handler should reject
      throw unknownAttribute(operation);
    }
  }
Exemple #8
0
 public void execute(OperationContext context, ModelNode operation)
     throws OperationFailedException {
   ModelNode model = context.readModel(PathAddress.EMPTY_ADDRESS);
   context
       .getResult()
       .add(createAddOperation(model.require(CommonAttributes.DEFAULT_DATASOURCE).asString()));
   context.completeStep();
 }
 void updateModel(
     final OperationContext context,
     ModelNode model,
     AttributeDefinition attributeDefinition,
     ModelNode attribute)
     throws OperationFailedException {
   String key = KEY.resolveModelAttribute(context, model).asString();
   context.getResult().set(attribute.get(key));
 }
  private void handleReadAttribute(OperationContext context, ModelNode operation) {

    if (ignoreOperationIfServerNotActive(context, operation)) {
      return;
    }

    final AddressControl addressControl = getAddressControl(context, operation);
    if (addressControl == null) {
      PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
      throw ControllerLogger.ROOT_LOGGER.managementResourceNotFound(address);
    }

    final String name = operation.require(ModelDescriptionConstants.NAME).asString();

    try {
      if (ROLES_ATTR_NAME.equals(name)) {
        String json = addressControl.getRolesAsJSON();
        reportRoles(context, json);
      } else if (QUEUE_NAMES.equals(name)) {
        String[] queues = addressControl.getQueueNames();
        reportListOfStrings(context, queues);
      } else if (NUMBER_OF_BYTES_PER_PAGE.equals(name)) {
        long l = addressControl.getNumberOfBytesPerPage();
        context.getResult().set(l);
      } else if (NUMBER_OF_PAGES.equals(name)) {
        int i = addressControl.getNumberOfPages();
        context.getResult().set(i);
      } else if (BINDING_NAMES.equals(name)) {
        String[] bindings = addressControl.getBindingNames();
        reportListOfStrings(context, bindings);
      } else {
        // Bug
        throw MessagingLogger.ROOT_LOGGER.unsupportedAttribute(name);
      }
    } catch (RuntimeException e) {
      throw e;
    } catch (Exception e) {
      context.getFailureDescription().set(e.getLocalizedMessage());
    }

    context.stepCompleted();
  }
 @Override
 public void execute(final OperationContext context, final ModelNode operation)
     throws OperationFailedException {
   final ModelNode address =
       PathAddress.pathAddress(
               PathAddress.pathAddress(operation.require(OP_ADDR)).getLastElement())
           .toModelNode();
   final Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS);
   final ModelNode result = context.getResult();
   describe(resource, address, result, context.getResourceRegistration());
   context.completeStep();
 }
    public void execute(OperationContext context, ModelNode operation)
        throws OperationFailedException {
      ModelNode result = context.getResult();

      result.add(
          Util.getEmptyOperation(
              ADD, pathAddress(PathElement.pathElement(SUBSYSTEM, SUBSYSTEM_NAME))));

      // TODO if child resources are developed, add operations to create those

      context.completeStep();
    }
  @Override
  public void execute(OperationContext context, ModelNode operation)
      throws OperationFailedException {

    final ModelNode subModel = context.readModel(PathAddress.EMPTY_ADDRESS);
    boolean master =
        subModel
            .get(ModelDescriptionConstants.DOMAIN_CONTROLLER)
            .hasDefined(ModelDescriptionConstants.LOCAL);
    context.getResult().set(master);
    context.completeStep();
  }
Exemple #14
0
    /** {@inheritDoc} */
    public void execute(OperationContext context, ModelNode operation) {

      final ImmutableManagementResourceRegistration registry = context.getResourceRegistration();
      final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
      final DescriptionProvider descriptionProvider = registry.getModelDescription(address);
      if (descriptionProvider == null) {
        context.getFailureDescription().set(new ModelNode());
      } else {
        context.getResult().set(descriptionProvider.getModelDescription(null));
      }

      context.stepCompleted();
    }
Exemple #15
0
    public void execute(OperationContext context, ModelNode operation)
        throws OperationFailedException {
      final ModelNode add = createEmptyAddOperation();
      final ModelNode model = context.readModel(PathAddress.EMPTY_ADDRESS);

      if (model.hasDefined(BEAN_VALIDATION_ENABLED)) {
        add.get(BEAN_VALIDATION_ENABLED).set(model.get(BEAN_VALIDATION_ENABLED));
      }
      if (model.hasDefined(ARCHIVE_VALIDATION_ENABLED)) {
        add.get(ARCHIVE_VALIDATION_ENABLED).set(model.get(ARCHIVE_VALIDATION_ENABLED));
      }
      if (model.hasDefined(ARCHIVE_VALIDATION_FAIL_ON_ERROR)) {
        add.get(ARCHIVE_VALIDATION_FAIL_ON_ERROR).set(model.get(ARCHIVE_VALIDATION_FAIL_ON_ERROR));
      }
      if (model.hasDefined(ARCHIVE_VALIDATION_FAIL_ON_WARN)) {
        add.get(ARCHIVE_VALIDATION_FAIL_ON_WARN).set(model.get(ARCHIVE_VALIDATION_FAIL_ON_WARN));
      }
      if (model.hasDefined(CACHED_CONNECTION_MANAGER_DEBUG)) {
        add.get(CACHED_CONNECTION_MANAGER_DEBUG).set(model.get(CACHED_CONNECTION_MANAGER_DEBUG));
      }
      if (model.hasDefined(CACHED_CONNECTION_MANAGER_ERROR)) {
        add.get(CACHED_CONNECTION_MANAGER_ERROR).set(model.get(CACHED_CONNECTION_MANAGER_ERROR));
      }

      final ModelNode result = context.getResult();
      result.add(add);

      if (model.hasDefined(THREAD_POOL)) {
        ModelNode pools = model.get(THREAD_POOL);
        for (Property poolProp : pools.asPropertyList()) {
          if (poolProp.getName().equals(LONG_RUNNING_THREADS)) {
            addBoundedQueueThreadPool(
                result,
                poolProp.getValue(),
                PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, SUBSYSTEM_NAME),
                PathElement.pathElement(THREAD_POOL, LONG_RUNNING_THREADS));
          } else if (poolProp.getName().equals(SHORT_RUNNING_THREADS)) {
            addBoundedQueueThreadPool(
                result,
                poolProp.getValue(),
                PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, SUBSYSTEM_NAME),
                PathElement.pathElement(THREAD_POOL, SHORT_RUNNING_THREADS));
          }
        }
      }

      context.completeStep();
    }
  @Override
  public void execute(OperationContext context, ModelNode operation)
      throws OperationFailedException {

    try {
      long[] ids = ManagementFactory.getThreadMXBean().findDeadlockedThreads();
      final ModelNode result = context.getResult();
      if (ids != null) {
        result.setEmptyList();
        for (long id : ids) {
          result.add(id);
        }
      }
    } catch (SecurityException e) {
      throw new OperationFailedException(new ModelNode().set(e.toString()));
    }

    context.stepCompleted();
  }
  @Override
  protected void executeReadAttribute(OperationContext context, ModelNode operation)
      throws OperationFailedException {

    final String gcName =
        PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR))
            .getLastElement()
            .getValue();
    final String name = operation.require(ModelDescriptionConstants.NAME).asString();

    GarbageCollectorMXBean gcMBean = null;

    for (GarbageCollectorMXBean mbean : ManagementFactory.getGarbageCollectorMXBeans()) {
      if (gcName.equals(escapeMBeanName(mbean.getName()))) {
        gcMBean = mbean;
      }
    }

    if (gcMBean == null) {
      throw PlatformMBeanLogger.ROOT_LOGGER.unknownGarbageCollector(gcName);
    }

    if (PlatformMBeanConstants.OBJECT_NAME.getName().equals(name)) {
      final String objName =
          PlatformMBeanUtil.getObjectNameStringWithNameKey(
              ManagementFactory.GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE, gcName);
      context.getResult().set(objName);
    } else if (ModelDescriptionConstants.NAME.equals(name)) {
      context.getResult().set(escapeMBeanName(gcMBean.getName()));
    } else if (PlatformMBeanConstants.VALID.getName().equals(name)) {
      context.getResult().set(gcMBean.isValid());
    } else if (PlatformMBeanConstants.MEMORY_POOL_NAMES.equals(name)) {
      final ModelNode result = context.getResult();
      result.setEmptyList();
      for (String pool : gcMBean.getMemoryPoolNames()) {
        result.add(escapeMBeanName(pool));
      }
    } else if (PlatformMBeanConstants.COLLECTION_COUNT.equals(name)) {
      context.getResult().set(gcMBean.getCollectionCount());
    } else if (PlatformMBeanConstants.COLLECTION_TIME.equals(name)) {
      context.getResult().set(gcMBean.getCollectionTime());
    } else if (GarbageCollectorResourceDefinition.GARBAGE_COLLECTOR_READ_ATTRIBUTES.contains(name)
        || GarbageCollectorResourceDefinition.GARBAGE_COLLECTOR_METRICS.contains(name)) {
      // Bug
      throw PlatformMBeanLogger.ROOT_LOGGER.badReadAttributeImpl(name);
    } else {
      // Shouldn't happen; the global handler should reject
      throw unknownAttribute(operation);
    }
  }
  /** {@inheritDoc} */
  @Override
  public void execute(OperationContext context, ModelNode operation)
      throws OperationFailedException {

    if (contentRepository != null) {
      try {
        InputStream is = getContentInputStream(context, operation);
        try {
          byte[] hash = contentRepository.addContent(is);
          context.getResult().set(hash);
        } finally {
          safeClose(is);
        }
      } catch (IOException e) {
        throw new OperationFailedException(new ModelNode().set(e.toString()));
      }
    }
    // else this is a slave domain controller and we should ignore this operation

    context.completeStep();
  }
 @Override
 public void execute(OperationContext context, ModelNode operation)
     throws OperationFailedException {
   if (context.getProcessType() == ProcessType.SELF_CONTAINED) {
     throw DomainControllerLogger.ROOT_LOGGER.cannotReadContentFromSelfContainedServer();
   }
   final Resource deploymentResource = context.readResource(PathAddress.EMPTY_ADDRESS);
   ModelNode contentItemNode = getContentItem(deploymentResource);
   // Validate this op is available
   if (!isManaged(contentItemNode)) {
     throw DomainControllerLogger.ROOT_LOGGER.cannotReadContentFromUnmanagedDeployment();
   }
   final byte[] deploymentHash =
       CONTENT_HASH.resolveModelAttribute(context, contentItemNode).asBytes();
   final ModelNode pathNode = DEPLOYMENT_CONTENT_PATH.resolveModelAttribute(context, operation);
   final String path;
   if (pathNode.isDefined()) {
     path = pathNode.asString();
   } else {
     path = "";
   }
   int depth = DEPTH.resolveModelAttribute(context, operation).asInt();
   boolean explodable = ARCHIVE.resolveModelAttribute(context, operation).asBoolean();
   try {
     for (ContentRepositoryElement content :
         contentRepository.listContent(
             deploymentHash, path, ContentFilter.Factory.createContentFilter(depth, explodable))) {
       ModelNode contentNode = new ModelNode();
       contentNode.get(PATH).set(content.getPath());
       contentNode.get(DIRECTORY).set(content.isFolder());
       if (!content.isFolder()) {
         contentNode.get(FILE_SIZE).set(content.getSize());
       }
       context.getResult().add(contentNode);
     }
   } catch (ExplodedContentException ex) {
     throw new OperationFailedException(ex.getMessage());
   }
 }
 @Override
 public void executeRuntimeStep(OperationContext context, ModelNode operation)
     throws OperationFailedException {
   final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
   final String cacheContainerName = address.getElement(address.size() - 2).getValue();
   final String cacheName = address.getElement(address.size() - 1).getValue();
   final ServiceController<?> controller =
       context
           .getServiceRegistry(false)
           .getService(CacheServiceName.CACHE.getServiceName(cacheContainerName, cacheName));
   if (controller != null) {
     Cache<?, ?> cache = (Cache<?, ?>) controller.getValue();
     if (cache != null) {
       ComponentRegistry registry = SecurityActions.getComponentRegistry(cache.getAdvancedCache());
       LocalTopologyManagerImpl localTopologyManager =
           (LocalTopologyManagerImpl)
               registry.getGlobalComponentRegistry().getComponent(LocalTopologyManager.class);
       if (localTopologyManager != null) {
         try {
           if (operation.hasDefined(VALUE)) {
             ModelNode newValue = operation.get(VALUE);
             localTopologyManager.setCacheAvailability(
                 cacheName, AvailabilityMode.valueOf(newValue.asString()));
           } else {
             context
                 .getResult()
                 .set(
                     new ModelNode()
                         .set(localTopologyManager.getCacheAvailability(cacheName).toString()));
           }
         } catch (Exception e) {
           throw new OperationFailedException(
               new ModelNode().set(MESSAGES.failedToInvokeOperation(e.getLocalizedMessage())));
         }
       }
     }
   }
   context.stepCompleted();
 }
  @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
  protected void executeRuntimeStep(OperationContext context, ModelNode operation) {
    // Address is of the form: /subsystem=infinispan/cache-container=*/*-cache=*
    PathAddress address = context.getCurrentAddress();
    String containerName = address.getElement(address.size() - 2).getValue();
    String cacheName = address.getElement(address.size() - 1).getValue();
    String name = Operations.getAttributeName(operation);

    CacheMetric metric = CacheMetric.forName(name);

    if (metric == null) {
      context.getFailureDescription().set(InfinispanLogger.ROOT_LOGGER.unknownMetric(name));
    } else {
      Cache<?, ?> cache =
          ServiceContainerHelper.findValue(
              context.getServiceRegistry(false),
              CacheServiceName.CACHE.getServiceName(containerName, cacheName));
      if (cache != null) {
        context.getResult().set(metric.getValue(cache));
      }
    }
    context.completeStep(OperationContext.ResultHandler.NOOP_RESULT_HANDLER);
  }
  @Override
  public void execute(OperationContext context, ModelNode operation)
      throws OperationFailedException {
    AuthorizationResult authorizationResult = context.authorize(operation);
    if (authorizationResult.getDecision() == AuthorizationResult.Decision.DENY) {
      throw ControllerLogger.ROOT_LOGGER.unauthorized(
          operation.get(OP).asString(),
          context.getCurrentAddress(),
          authorizationResult.getExplanation());
    }

    try {
      SnapshotInfo info = persister.listSnapshots();
      ModelNode result = context.getResult();
      result.get(ModelDescriptionConstants.DIRECTORY).set(info.getSnapshotDirectory());
      result.get(ModelDescriptionConstants.NAMES).setEmptyList();
      for (String name : info.names()) {
        result.get(ModelDescriptionConstants.NAMES).add(name);
      }
    } catch (Exception e) {
      throw new OperationFailedException(e);
    }
    context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
  }
 public void execute(OperationContext context, ModelNode operation)
     throws OperationFailedException {
   context.getResult().add(createAddSubsystemOperation());
   context.stepCompleted();
 }
  @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);
    }
  }
    @Override
    protected void executeRuntimeStep(OperationContext context, ModelNode operation)
        throws OperationFailedException {

      final PathAddress address =
          PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR));

      final Resource web =
          context.readResourceFromRoot(address.subAddress(0, address.size()), false);
      final ModelNode subModel = web.getModel();

      final String host = VIRTUAL_HOST.resolveModelAttribute(context, subModel).asString();
      final String path = CONTEXT_ROOT.resolveModelAttribute(context, subModel).asString();
      final String server = SERVER.resolveModelAttribute(context, subModel).asString();

      final ServiceController<?> controller =
          context
              .getServiceRegistry(false)
              .getService(UndertowService.deploymentServiceName(server, host, path));

      SessionStat stat =
          SessionStat.getStat(operation.require(ModelDescriptionConstants.NAME).asString());

      if (stat == null) {
        context
            .getFailureDescription()
            .set(
                UndertowMessages.MESSAGES.unknownMetric(
                    operation.require(ModelDescriptionConstants.NAME).asString()));
      } else {
        context.getResult().set("<not implemented>");
        /*final Context webContext = Context.class.cast(controller.getValue());
        ManagerBase sm = (ManagerBase) webContext.getManager();
        ModelNode result = new ModelNode();
        switch (stat) {
            case ACTIVE_SESSIONS:
                result.set(sm.getActiveSessions());
                break;
            case EXPIRED_SESSIONS:
                result.set(sm.getExpiredSessions());
                break;
            case MAX_ACTIVE_SESSIONS:
                result.set(sm.getMaxActive());
                break;
            case SESSIONS_CREATED:
                result.set(sm.getSessionCounter());
                break;
            case DUPLICATED_SESSION_IDS:
                result.set(sm.getDuplicates());
                break;
            case SESSION_AVG_ALIVE_TIME:
                result.set(sm.getSessionAverageAliveTime());
                break;
            case SESSION_MAX_ALIVE_TIME:
                result.set(sm.getSessionMaxAliveTime());
                break;
            case REJECTED_SESSIONS:
                result.set(sm.getRejectedSessions());
                break;
            default:
                throw new IllegalStateException(WebMessages.MESSAGES.unknownMetric(stat));
        }
        context.getResult().set(result);*/
      }

      context.stepCompleted();
    }
    @Override
    public void execute(OperationContext context, ModelNode operation)
        throws OperationFailedException {

      Map<String, ModelNode> sortedAttributes = new TreeMap<String, ModelNode>();
      Map<String, ModelNode> sortedChildren = new TreeMap<String, ModelNode>();
      boolean failed = false;
      for (Map.Entry<String, ModelNode> entry : otherAttributes.entrySet()) {
        ModelNode value = entry.getValue();
        if (!value.has(FAILURE_DESCRIPTION)) {
          sortedAttributes.put(entry.getKey(), value.get(RESULT));
        } else if (!failed && value.hasDefined(FAILURE_DESCRIPTION)) {
          context.getFailureDescription().set(value.get(FAILURE_DESCRIPTION));
          failed = true;
          break;
        }
      }
      if (!failed) {
        for (Map.Entry<PathElement, ModelNode> entry : childResources.entrySet()) {
          PathElement path = entry.getKey();
          ModelNode value = entry.getValue();
          if (!value.has(FAILURE_DESCRIPTION)) {
            ModelNode childTypeNode = sortedChildren.get(path.getKey());
            if (childTypeNode == null) {
              childTypeNode = new ModelNode();
              sortedChildren.put(path.getKey(), childTypeNode);
            }
            childTypeNode.get(path.getValue()).set(value.get(RESULT));
          } else if (!failed && value.hasDefined(FAILURE_DESCRIPTION)) {
            context.getFailureDescription().set(value.get(FAILURE_DESCRIPTION));
            failed = true;
          }
        }
      }
      if (!failed) {
        for (Map.Entry<String, ModelNode> simpleAttribute : directAttributes.entrySet()) {
          sortedAttributes.put(simpleAttribute.getKey(), simpleAttribute.getValue());
        }
        for (Map.Entry<String, ModelNode> directChild : directChildren.entrySet()) {
          sortedChildren.put(directChild.getKey(), directChild.getValue());
        }
        for (Map.Entry<String, ModelNode> metric : metrics.entrySet()) {
          ModelNode value = metric.getValue();
          if (!value.has(FAILURE_DESCRIPTION)) {
            sortedAttributes.put(metric.getKey(), value.get(RESULT));
          }
          // we ignore metric failures
          // TODO how to prevent the metric failure screwing up the overall context?
        }

        final ModelNode result = context.getResult();
        result.setEmptyObject();
        for (Map.Entry<String, ModelNode> entry : sortedAttributes.entrySet()) {
          result.get(entry.getKey()).set(entry.getValue());
        }

        for (Map.Entry<String, ModelNode> entry : sortedChildren.entrySet()) {
          result.get(entry.getKey()).set(entry.getValue());
        }
      }

      context.stepCompleted();
    }
  @Override
  protected void executeRuntimeStep(OperationContext context, ModelNode operation)
      throws OperationFailedException {

    // get the channel name and channel attribute
    PathAddress pathAddress = PathAddress.pathAddress(operation.require(OP_ADDR));
    String channelName = pathAddress.getElement(pathAddress.size() - 1).getValue();
    String attrName = operation.require(NAME).asString();
    ChannelMetrics metric = ChannelMetrics.getStat(attrName);

    // lookup the channel
    ServiceName channelServiceName = ChannelInstanceResource.CHANNEL_PARENT.append(channelName);
    ServiceController<?> controller =
        context.getServiceRegistry(false).getService(channelServiceName);

    // check that the service has been installed and started
    boolean started = controller != null && controller.getValue() != null;
    ModelNode result = new ModelNode();

    if (metric == null) {
      context.getFailureDescription().set(JGroupsMessages.MESSAGES.unknownMetric(attrName));
    } else if (!started) {
      // when the cache service is not available, return a null result
    } else {
      JChannel channel = (JChannel) controller.getValue();
      switch (metric) {
        case ADDRESS:
          result.set(channel.getAddressAsString());
          break;
        case ADDRESS_AS_UUID:
          result.set(channel.getAddressAsUUID());
          break;
        case DISCARD_OWN_MESSAGES:
          result.set(channel.getDiscardOwnMessages());
          break;
        case NUM_TASKS_IN_TIMER:
          result.set(channel.getNumberOfTasksInTimer());
          break;
        case NUM_TIMER_THREADS:
          result.set(channel.getTimerThreads());
          break;
        case RECEIVED_BYTES:
          result.set(channel.getReceivedBytes());
          break;
        case RECEIVED_MESSAGES:
          result.set(channel.getReceivedMessages());
          break;
        case SENT_BYTES:
          result.set(channel.getSentBytes());
          break;
        case SENT_MESSAGES:
          result.set(channel.getSentMessages());
          break;
        case STATE:
          result.set(channel.getState());
          break;
        case STATS_ENABLED:
          result.set(channel.statsEnabled());
          break;
        case VERSION:
          result.set(JChannel.getVersion());
          break;
        case VIEW:
          result.set(channel.getViewAsString());
          break;
      }
      context.getResult().set(result);
    }
    context.completeStep(OperationContext.ResultHandler.NOOP_RESULT_HANDLER);
  }