Beispiel #1
0
  @Override
  public void execute(OperationContext context, ModelNode operation)
      throws OperationFailedException {
    if (context.isNormalServer()
        && context.getServiceRegistry(false).getService(ModClusterService.NAME) != null) {
      context.addStep(
          new OperationStepHandler() {
            @Override
            public void execute(OperationContext context, ModelNode operation)
                throws OperationFailedException {
              ServiceController<?> controller =
                  context.getServiceRegistry(false).getService(ModClusterService.NAME);
              ModCluster modcluster = (ModCluster) controller.getValue();
              ROOT_LOGGER.debugf("add-proxy: %s", operation);

              Proxy proxy = new Proxy(operation);
              modcluster.addProxy(proxy.host, proxy.port);

              // TODO AS7-5695 handle rollback
              context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
            }
          },
          OperationContext.Stage.RUNTIME);
    }

    context.stepCompleted();
  }
    @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(final OperationContext context, final ModelNode operation)
        throws OperationFailedException {
      context.readResource(PathAddress.EMPTY_ADDRESS, false);
      final String group = getServerGroupName(operation);
      context.addStep(
          new OperationStepHandler() {
            @Override
            public void execute(OperationContext context, ModelNode operation)
                throws OperationFailedException {
              if (group != null) {
                final ModelNode model =
                    Resource.Tools.readModel(
                        context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS, true));
                for (String server : getServersForGroup(model, group)) {
                  serverInventory.stopServer(server, TIMEOUT);
                }
              } else {
                serverInventory.stopServers(TIMEOUT);
              }
              context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
            }
          },
          Stage.RUNTIME);

      context.stepCompleted();
    }
  @Override
  public void execute(OperationContext context, ModelNode operation)
      throws OperationFailedException {
    ModelNode newValue = operation.require(CacheContainerResource.PROTO_URL.getName());
    String urlString = newValue.asString();

    final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
    final String cacheContainerName = address.getElement(address.size() - 1).getValue();
    final ServiceController<?> controller =
        context
            .getServiceRegistry(false)
            .getService(EmbeddedCacheManagerService.getServiceName(cacheContainerName));

    EmbeddedCacheManager cacheManager = (EmbeddedCacheManager) controller.getValue();
    ProtobufMetadataManager protoManager =
        cacheManager.getGlobalComponentRegistry().getComponent(ProtobufMetadataManager.class);
    if (protoManager != null) {
      try {
        URL url = new URL(urlString);
        protoManager.registerProtofile(url.openStream());
      } catch (Exception e) {
        throw new OperationFailedException(
            new ModelNode().set(MESSAGES.failedToInvokeOperation(e.getLocalizedMessage())));
      }
    }
    context.stepCompleted();
  }
 @Override
 public void execute(OperationContext context, ModelNode operation)
     throws OperationFailedException {
   context.readResource(PathAddress.EMPTY_ADDRESS, false);
   final ModelNode model =
       Resource.Tools.readModel(context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS, true));
   final String group = getServerGroupName(operation);
   context.addStep(
       new OperationStepHandler() {
         @Override
         public void execute(OperationContext context, ModelNode operation)
             throws OperationFailedException {
           Map<String, ProcessInfo> processes = serverInventory.determineRunningProcesses(true);
           final Set<String> serversInGroup = getServersForGroup(model, group);
           for (String serverName : processes.keySet()) {
             final String serverModelName = serverInventory.getProcessServerName(serverName);
             if (group == null || serversInGroup.contains(serverModelName)) {
               serverInventory.restartServer(serverModelName, TIMEOUT, model);
             }
           }
           context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
         }
       },
       Stage.RUNTIME);
   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;
      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.stepCompleted();
  }
  @Override
  public void execute(OperationContext context, ModelNode operation)
      throws OperationFailedException {
    if (context.isNormalServer()
        && context.getServiceRegistry(false).getService(ModClusterService.NAME) != null) {
      context.addStep(
          new OperationStepHandler() {
            @Override
            public void execute(OperationContext context, ModelNode operation)
                throws OperationFailedException {
              ServiceController<?> controller =
                  context.getServiceRegistry(false).getService(ModClusterService.NAME);
              ModCluster modcluster = (ModCluster) controller.getValue();
              Map<InetSocketAddress, String> map = modcluster.getProxyInfo();
              ROOT_LOGGER.debugf("Mod_cluster ProxyInfo %s", map);
              if (!map.isEmpty()) {
                final ModelNode result = new ModelNode();
                Object[] addr = map.keySet().toArray();
                for (int i = 0; i < addr.length; i++) {
                  InetSocketAddress address = (InetSocketAddress) addr[i];
                  result.add(address.getHostName() + ":" + address.getPort());
                  result.add(map.get(addr[i]));
                }
                context.getResult().set(result);
              }

              context.stepCompleted();
            }
          },
          OperationContext.Stage.RUNTIME);
    }

    context.stepCompleted();
  }
    /** {@inheritDoc} */
    @Override
    public void execute(OperationContext context, ModelNode operation)
        throws OperationFailedException {
      final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR));
      final PathElement element = address.getLastElement();

      context.addStep(
          new OperationStepHandler() {
            @Override
            public void execute(final OperationContext context, final ModelNode operation)
                throws OperationFailedException {
              final ModelNode result = context.getResult();
              final ServiceController<?> controller =
                  context
                      .getServiceRegistry(false)
                      .getRequiredService(SOCKET_BINDING.append(element.getValue()));
              if (controller != null && controller.getState() == ServiceController.State.UP) {
                final SocketBinding binding = SocketBinding.class.cast(controller.getValue());
                AbstractBindingMetricsHandler.this.execute(operation, binding, result);
              } else {
                result.set(getNoMetrics());
              }

              context.stepCompleted();
            }
          },
          OperationContext.Stage.RUNTIME);

      context.stepCompleted();
    }
Beispiel #9
0
 @Override
 public void execute(OperationContext context, ModelNode operation)
     throws OperationFailedException {
   context.removeResource(PathAddress.EMPTY_ADDRESS);
   reloadRequiredStep(context);
   context.stepCompleted();
 }
  @Override
  public void execute(OperationContext context, ModelNode operation)
      throws OperationFailedException {
    if (context.isNormalServer()
        && context.getServiceRegistry(false).getService(ModClusterService.NAME) != null) {
      context.addStep(
          new OperationStepHandler() {
            @Override
            public void execute(OperationContext context, ModelNode operation)
                throws OperationFailedException {
              ServiceController<?> controller =
                  context.getServiceRegistry(false).getService(ModClusterService.NAME);
              final ModCluster modcluster = (ModCluster) controller.getValue();
              ROOT_LOGGER.debugf("remove-proxy: %s", operation);

              final Proxy proxy = new Proxy(operation);
              modcluster.removeProxy(proxy.host, proxy.port);

              context.completeStep(
                  new OperationContext.RollbackHandler() {
                    @Override
                    public void handleRollback(OperationContext context, ModelNode operation) {
                      // TODO What if mod_cluster was never aware of this proxy?
                      modcluster.addProxy(proxy.host, proxy.port);
                    }
                  });
            }
          },
          OperationContext.Stage.RUNTIME);
    }

    context.stepCompleted();
  }
 @Override
 public void execute(OperationContext context, ModelNode operation)
     throws OperationFailedException {
   ModelNode aliased = getAliasedOperation(operation);
   context.addStep(
       aliased, getHandlerForOperation(context, operation), OperationContext.Stage.MODEL, true);
   context.stepCompleted();
 }
 private void handleGetRolesAsJson(final OperationContext context, final ModelNode operation) {
   final AddressControl addressControl = getAddressControl(context, operation);
   try {
     String json = addressControl.getRolesAsJSON();
     reportRolesAsJSON(context, json);
     context.stepCompleted();
   } catch (RuntimeException e) {
     throw e;
   } catch (Exception e) {
     context.getFailureDescription().set(e.getLocalizedMessage());
   }
 }
Beispiel #13
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();
    }
Beispiel #14
0
        @Override
        public void execute(final OperationContext context, final ModelNode operation)
            throws OperationFailedException {
          final Resource resource = context.createResource(PathAddress.EMPTY_ADDRESS);
          final ModelNode model = resource.getModel();
          final String path =
              PathAddress.pathAddress(operation.require(OP_ADDR)).getLastElement().getValue();

          for (AttributeDefinition attribute : getAttributes(path)) {
            attribute.validateAndSet(operation, model);
          }
          reloadRequiredStep(context);
          context.stepCompleted();
        }
  public void execute(OperationContext context, ModelNode operation)
      throws OperationFailedException {
    ModelNode model = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS).getModel();
    final String deploymentUnitName = RUNTIME_NAME.resolveModelAttribute(context, model).asString();
    model.get(ENABLED.getName()).set(false);

    final ModelNode opAddr = operation.get(OP_ADDR);
    PathAddress address = PathAddress.pathAddress(opAddr);
    final String managementName = address.getLastElement().getValue();

    DeploymentHandlerUtil.undeploy(context, managementName, deploymentUnitName, vaultReader);

    context.stepCompleted();
  }
  @Override
  public void execute(OperationContext context, ModelNode operation)
      throws OperationFailedException {
    if (context.isNormalServer()
        && context.getServiceRegistry(false).getService(ContainerEventHandlerService.SERVICE_NAME)
            != null) {
      context.addStep(
          new OperationStepHandler() {
            @Override
            public void execute(OperationContext context, ModelNode operation)
                throws OperationFailedException {
              ServiceController<?> controller =
                  context
                      .getServiceRegistry(false)
                      .getService(ContainerEventHandlerService.SERVICE_NAME);
              final ModClusterServiceMBean service = (ModClusterServiceMBean) controller.getValue();
              ROOT_LOGGER.debugf("stop-context: %s", operation);
              final ContextHost contexthost = new ContextHost(operation);

              try {
                service.stopContext(
                    contexthost.webhost,
                    contexthost.webcontext,
                    contexthost.waittime,
                    TimeUnit.SECONDS);
              } catch (IllegalArgumentException e) {
                throw new OperationFailedException(
                    new ModelNode()
                        .set(
                            ModClusterLogger.ROOT_LOGGER.ContextOrHostNotFound(
                                contexthost.webhost, contexthost.webcontext)));
              }

              context.completeStep(
                  new OperationContext.RollbackHandler() {
                    @Override
                    public void handleRollback(OperationContext context, ModelNode operation) {
                      // TODO We're assuming that the context was previously enabled, but it could
                      // have been disabled
                      service.enableContext(contexthost.webhost, contexthost.webcontext);
                    }
                  });
            }
          },
          OperationContext.Stage.RUNTIME);
    }

    context.stepCompleted();
  }
 @Override
 public void execute(OperationContext context, ModelNode operation)
     throws OperationFailedException {
   final Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS);
   Set<String> children = resource.getChildrenNames(ModelDescriptionConstants.AUTHORIZATION);
   if (children.size() > 1) {
     String realmName =
         PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR))
             .getLastElement()
             .getValue();
     Set<String> invalid = new HashSet<String>(children);
     throw DomainManagementMessages.MESSAGES.multipleAuthorizationConfigurationsDefined(
         realmName, invalid);
   }
   context.stepCompleted();
 }
Beispiel #18
0
    @Override
    public void execute(OperationContext context, ModelNode operation)
        throws OperationFailedException {

      context.addStep(
          new OperationStepHandler() {
            @Override
            public void execute(OperationContext context, ModelNode operation)
                throws OperationFailedException {
              Map<String, ModelNode> sortedChildren = new TreeMap<String, ModelNode>();
              boolean failed = false;
              for (Map.Entry<PathElement, ModelNode> entry : resources.entrySet()) {
                PathElement path = entry.getKey();
                ModelNode value = entry.getValue();
                if (!value.has(FAILURE_DESCRIPTION)) {
                  sortedChildren.put(path.getValue(), value.get(RESULT));
                } else if (!failed && value.hasDefined(FAILURE_DESCRIPTION)) {
                  context.getFailureDescription().set(value.get(FAILURE_DESCRIPTION));
                  failed = true;
                }
              }

              if (!failed) {
                boolean hasFilteredData = filteredData.hasFilteredData();
                final ModelNode result = context.getResult();
                result.setEmptyObject();

                for (Map.Entry<String, ModelNode> entry : sortedChildren.entrySet()) {
                  if (!hasFilteredData
                      || !filteredData.isAddressFiltered(
                          address, PathElement.pathElement(childType, entry.getKey()))) {
                    result.get(entry.getKey()).set(entry.getValue());
                  }
                }

                if (hasFilteredData) {
                  context.getResponseHeaders().get(ACCESS_CONTROL).set(filteredData.toModelNode());
                }
              }

              context.stepCompleted();
            }
          },
          OperationContext.Stage.VERIFY);

      context.stepCompleted();
    }
  @Override
  protected void modelChanged(
      OperationContext context,
      ModelNode operation,
      String attributeName,
      ModelNode newValue,
      ModelNode currentValue)
      throws OperationFailedException {
    if (newValue.equals(currentValue)) {
      // Set an attachment to avoid propagation to the servers, we don't want them to go into
      // restart-required if nothing changed
      ServerOperationResolver.addToDontPropagateToServersAttachment(context, operation);
    }
    validateReferencedNewValueExisits(context, newValue);

    context.stepCompleted();
  }
  @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();
  }
  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();
  }
Beispiel #22
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();
  }
 @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 execute(final OperationContext context, final ModelNode operation)
        throws OperationFailedException {
      context.readResource(PathAddress.EMPTY_ADDRESS, false);
      final ModelNode model =
          Resource.Tools.readModel(context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS, true));
      final String group = getServerGroupName(operation);
      context.addStep(
          new OperationStepHandler() {
            @Override
            public void execute(OperationContext context, ModelNode operation)
                throws OperationFailedException {
              final String hostName = model.get(HOST).keys().iterator().next();
              final ModelNode serverConfig = model.get(HOST, hostName).get(SERVER_CONFIG);
              final Set<String> serversInGroup = getServersForGroup(model, group);
              if (serverConfig.isDefined()) {
                for (Property config : serverConfig.asPropertyList()) {
                  final ServerStatus status =
                      serverInventory.determineServerStatus(config.getName());
                  if (status != ServerStatus.STARTING && status != ServerStatus.STARTED) {
                    if (group == null || serversInGroup.contains(config.getName())) {
                      if (status != ServerStatus.STOPPED) {
                        serverInventory.stopServer(config.getName(), TIMEOUT);
                      }
                      serverInventory.startServer(config.getName(), model);
                    }
                  }
                }
              }
              context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
            }
          },
          Stage.RUNTIME);

      context.stepCompleted();
    }
 @Override
 public void execute(OperationContext context, ModelNode operation)
     throws OperationFailedException {
   final String attribute = operation.require(NAME).asString();
   final ModelNode value = operation.require(VALUE);
   final SensitivityClassificationResource resource =
       (SensitivityClassificationResource)
           context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS);
   final AbstractSensitivity classification = resource.classification;
   if (attribute.equals(CONFIGURED_REQUIRES_ADDRESSABLE.getName())) {
     classification.setConfiguredRequiresAccessPermission(
         readValue(context, value, CONFIGURED_REQUIRES_ADDRESSABLE));
   } else if (attribute.equals(CONFIGURED_REQUIRES_READ.getName())) {
     classification.setConfiguredRequiresReadPermission(
         readValue(context, value, CONFIGURED_REQUIRES_READ));
   } else if (attribute.equals(CONFIGURED_REQUIRES_WRITE.getName())) {
     classification.setConfiguredRequiresWritePermission(
         readValue(context, value, CONFIGURED_REQUIRES_WRITE));
   } else {
     // TODO i18n
     throw new IllegalStateException();
   }
   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 {

      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();
    }
Beispiel #28
0
  @Override
  public void execute(OperationContext context, ModelNode operation)
      throws OperationFailedException {

    final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR));
    final String childType = CHILD_TYPE.resolveModelAttribute(context, operation).asString();

    // Build up the op we're going to repeatedly execute
    final ModelNode readOp = new ModelNode();
    readOp.get(OP).set(READ_RESOURCE_OPERATION);
    INCLUDE_RUNTIME.validateAndSet(operation, readOp);
    RECURSIVE.validateAndSet(operation, readOp);
    RECURSIVE_DEPTH.validateAndSet(operation, readOp);
    PROXIES.validateAndSet(operation, readOp);
    INCLUDE_DEFAULTS.validateAndSet(operation, readOp);

    final Map<PathElement, ModelNode> resources = new HashMap<PathElement, ModelNode>();

    final Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS, false);
    final ImmutableManagementResourceRegistration registry = context.getResourceRegistration();
    Map<String, Set<String>> childAddresses =
        GlobalOperationHandlers.getChildAddresses(context, address, registry, resource, childType);
    Set<String> childNames = childAddresses.get(childType);
    if (childNames == null) {
      throw new OperationFailedException(
          new ModelNode().set(ControllerLogger.ROOT_LOGGER.unknownChildType(childType)));
    }

    // Track any excluded items
    FilteredData filteredData = new FilteredData(address);

    // We're going to add a bunch of steps that should immediately follow this one. We are going to
    // add them
    // in reverse order of how they should execute, building up a stack.

    // Last to execute is the handler that assembles the overall response from the pieces created by
    // all the other steps
    final ReadChildrenResourcesAssemblyHandler assemblyHandler =
        new ReadChildrenResourcesAssemblyHandler(resources, filteredData, address, childType);
    context.addStep(assemblyHandler, OperationContext.Stage.MODEL, true);

    for (final String key : childNames) {
      final PathElement childPath = PathElement.pathElement(childType, key);
      final PathAddress childAddress =
          PathAddress.EMPTY_ADDRESS.append(PathElement.pathElement(childType, key));

      final ModelNode readResOp = readOp.clone();
      readResOp.get(OP_ADDR).set(PathAddress.pathAddress(address, childPath).toModelNode());

      // See if there was an override registered for the standard :read-resource handling
      // (unlikely!!!)
      OperationStepHandler overrideHandler =
          context
              .getResourceRegistration()
              .getOperationHandler(childAddress, READ_RESOURCE_OPERATION);
      if (overrideHandler == null) {
        throw new OperationFailedException(
            new ModelNode().set(ControllerLogger.ROOT_LOGGER.noOperationHandler()));
      } else if (overrideHandler.getClass() == ReadResourceHandler.class) {
        // not an override
        overrideHandler = null;
      }
      OperationStepHandler rrHandler =
          new ReadResourceHandler(filteredData, overrideHandler, false);
      final ModelNode rrRsp = new ModelNode();
      resources.put(childPath, rrRsp);
      context.addStep(rrRsp, readResOp, rrHandler, OperationContext.Stage.MODEL, true);
    }

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

    // read /subsystem=jgroups/stack=* for update
    final Resource resource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS);
    final ModelNode subModel = resource.getModel();

    // validate the protocol type to be added
    ModelNode type = ProtocolResourceDefinition.TYPE.validateOperation(operation);
    PathElement protocolRelativePath = PathElement.pathElement(ModelKeys.PROTOCOL, type.asString());

    // if child resource already exists, throw OFE
    if (resource.hasChild(protocolRelativePath)) {
      throw JGroupsMessages.MESSAGES.protocolAlreadyDefined(protocolRelativePath.toString());
    }

    // now get the created model
    Resource childResource = context.createResource(PathAddress.pathAddress(protocolRelativePath));
    final ModelNode protocol = childResource.getModel();

    // Process attributes
    for (final AttributeDefinition attribute : attributes) {
      // we use PROPERTIES only to allow the user to pass in a list of properties on store add
      // commands
      // don't copy these into the model
      if (attribute.getName().equals(ModelKeys.PROPERTIES)) {
        continue;
      }

      attribute.validateAndSet(operation, protocol);
    }

    // get the current list of protocol names and add the new protocol
    // this list is used to maintain order
    ModelNode protocols = subModel.get(ModelKeys.PROTOCOLS);
    if (!protocols.isDefined()) {
      protocols.setEmptyList();
    }
    protocols.add(type);

    // Process type specific properties if required

    // The protocol parameters  <property name=>value</property>
    if (operation.hasDefined(ModelKeys.PROPERTIES)) {
      for (Property property : operation.get(ModelKeys.PROPERTIES).asPropertyList()) {
        // create a new property=name resource
        final Resource param =
            context.createResource(
                PathAddress.pathAddress(
                    protocolRelativePath,
                    PathElement.pathElement(ModelKeys.PROPERTY, property.getName())));
        final ModelNode value = property.getValue();
        if (!value.isDefined()) {
          throw JGroupsMessages.MESSAGES.propertyNotDefined(
              property.getName(), protocolRelativePath.toString());
        }
        // set the value of the property
        PropertyResourceDefinition.VALUE.validateAndSet(value, param.getModel());
      }
    }
    // This needs a reload
    reloadRequiredStep(context);
    context.stepCompleted();
  }