@Override
  public void execute(AdminCommandContext context) {
    final ActionReport actionReport = context.getActionReport();
    Properties extraProperties = actionReport.getExtraProperties();
    if (extraProperties == null) {
      extraProperties = new Properties();
      actionReport.setExtraProperties(extraProperties);
    }

    Config config = targetUtil.getConfig(target);
    final NotificationServiceConfiguration notificationServiceConfiguration =
        config.getExtensionByType(NotificationServiceConfiguration.class);

    if (notificationServiceConfiguration != null) {
      try {
        ConfigSupport.apply(
            new SingleConfigCode<NotificationServiceConfiguration>() {
              @Override
              public Object run(
                  final NotificationServiceConfiguration notificationServiceConfigurationProxy)
                  throws PropertyVetoException, TransactionFailure {
                if (enabled != null) {
                  notificationServiceConfigurationProxy.enabled(enabled.toString());
                }
                actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                return notificationServiceConfigurationProxy;
              }
            },
            notificationServiceConfiguration);
      } catch (TransactionFailure ex) {
        logger.log(Level.WARNING, "Exception during command ", ex);
        actionReport.setMessage(ex.getCause().getMessage());
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
      }
    }

    if (dynamic) {
      if (server.isDas()) {
        if (targetUtil.getConfig(target).isDas()) {
          service.getExecutionOptions().setEnabled(enabled);
        }
      } else {
        // apply as not the DAS so implicitly it is for us
        service.getExecutionOptions().setEnabled(enabled);
      }
    }
  }
  /**
   * Executes the command with the command parameters passed as Properties where the keys are the
   * parameter names and the values the parameter values
   *
   * @param context information
   */
  public void execute(AdminCommandContext context) {

    final ActionReport report = context.getActionReport();

    try {
      Collection<ManagedExecutorService> managedExecutorServices =
          domain.getResources().getResources(ManagedExecutorService.class);
      List<Map<String, String>> resourcesList = new ArrayList<Map<String, String>>();
      List<DefaultResourceProxy> drps = habitat.getAllServices(DefaultResourceProxy.class);

      for (ManagedExecutorService managedExecutorService : managedExecutorServices) {
        String jndiName = managedExecutorService.getJndiName();
        if (bindableResourcesHelper.resourceExists(jndiName, target)) {
          ActionReport.MessagePart part = report.getTopMessagePart().addChild();
          part.setMessage(jndiName);
          Map<String, String> resourceNameMap = new HashMap<String, String>();
          String logicalName = DefaultResourceProxy.Util.getLogicalName(drps, jndiName);
          if (logicalName != null) {
            resourceNameMap.put("logical-jndi-name", logicalName);
          }
          resourceNameMap.put("name", jndiName);
          resourcesList.add(resourceNameMap);
        }
      }

      Properties extraProperties = new Properties();
      extraProperties.put("managedExecutorServices", resourcesList);
      report.setExtraProperties(extraProperties);
    } catch (Exception e) {
      report.setMessage(
          localStrings.getLocalString(
              "list.managed.executor.service.failed", "List managed executor services failed"));
      report.setActionExitCode(ActionReport.ExitCode.FAILURE);
      report.setFailureCause(e);
      return;
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
  }
Example #3
0
  @Override
  public void execute(AdminCommandContext context) {
    ActionReport actionReport = context.getActionReport();
    Properties extraProperties = actionReport.getExtraProperties();
    if (extraProperties == null) {
      extraProperties = new Properties();
      actionReport.setExtraProperties(extraProperties);
    }

    try {
      calculateHeaders();
      helper.checkAndInitializeBatchRuntime();
      glassFishBatchSecurityHelper.markInvocationPrivilege(true);
      executeCommand(context, extraProperties);
      actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    } catch (Exception ex) {
      logger.log(Level.FINE, "Exception during command ", ex);
      actionReport.setMessage(ex.getMessage());
      actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
    } finally {
      glassFishBatchSecurityHelper.markInvocationPrivilege(false);
    }
  }
  @Override
  public void execute(AdminCommandContext context) {
    final AdminCommandContext theContext = context;
    final ActionReport actionReport = context.getActionReport();
    Properties extraProperties = actionReport.getExtraProperties();
    if (extraProperties == null) {
      extraProperties = new Properties();
      actionReport.setExtraProperties(extraProperties);
    }

    if (!validate(actionReport)) {
      return;
    }

    Config config = targetUtil.getConfig(target);
    final RequestTracingServiceConfiguration requestTracingServiceConfiguration =
        config.getExtensionByType(RequestTracingServiceConfiguration.class);

    if (requestTracingServiceConfiguration != null) {
      try {
        ConfigSupport.apply(
            new SingleConfigCode<RequestTracingServiceConfiguration>() {
              @Override
              public Object run(
                  final RequestTracingServiceConfiguration requestTracingServiceConfigurationProxy)
                  throws PropertyVetoException, TransactionFailure {
                if (enabled != null) {
                  requestTracingServiceConfigurationProxy.enabled(enabled.toString());
                }
                if (unit != null) {
                  requestTracingServiceConfigurationProxy.setThresholdUnit(unit);
                }
                if (value != null) {
                  requestTracingServiceConfigurationProxy.setThresholdValue(value);
                }
                actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                return requestTracingServiceConfigurationProxy;
              }
            },
            requestTracingServiceConfiguration);
      } catch (TransactionFailure ex) {
        logger.log(Level.WARNING, "Exception during command ", ex);
        actionReport.setMessage(ex.getCause().getMessage());
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
      }
    }

    if (dynamic) {
      if (server.isDas()) {
        if (targetUtil.getConfig(target).isDas()) {
          service.getExecutionOptions().setEnabled(enabled);
          if (value != null) {
            service.getExecutionOptions().setThresholdValue(Long.valueOf(value));
            actionReport.appendMessage(
                strings.getLocalString(
                        "requesttracing.configure.thresholdvalue.success",
                        "Request Tracing Service Threshold Value is set to {0}.",
                        value)
                    + "\n");
          }
          if (unit != null) {
            service.getExecutionOptions().setThresholdUnit(TimeUnit.valueOf(unit));
            actionReport.appendMessage(
                strings.getLocalString(
                        "requesttracing.configure.thresholdunit.success",
                        "Request Tracing Service Threshold Unit is set to {0}.",
                        unit)
                    + "\n");
          }
        }
      } else {
        service.getExecutionOptions().setEnabled(enabled);
        if (value != null) {
          service.getExecutionOptions().setThresholdValue(Long.valueOf(value));
          actionReport.appendMessage(
              strings.getLocalString(
                      "requesttracing.configure.thresholdvalue.success",
                      "Request Tracing Service Threshold Value is set to {0}.",
                      value)
                  + "\n");
        }
        if (unit != null) {
          service.getExecutionOptions().setThresholdUnit(TimeUnit.valueOf(unit));
          actionReport.appendMessage(
              strings.getLocalString(
                      "requesttracing.configure.thresholdunit.success",
                      "Request Tracing Service Threshold Unit is set to {0}.",
                      unit)
                  + "\n");
        }
      }
    }
  }