@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);
      }
    }
  }
 @Override
 public void execute(AdminCommandContext context) {
   Target targetUtil = habitat.getComponent(Target.class);
   Config newConfig = targetUtil.getConfig(target);
   if (newConfig != null) {
     config = newConfig;
   }
   report = context.getActionReport();
   try {
     final Protocols protocols = config.getNetworkConfig().getProtocols();
     final Protocol protocol = protocols.findProtocol(protocolName);
     validate(
         protocol,
         "create.http.fail.protocolnotfound",
         "The specified protocol {0} is not yet configured",
         protocolName);
     final Class<?> filterClass =
         Thread.currentThread().getContextClassLoader().loadClass(classname);
     if (!com.sun.grizzly.ProtocolFilter.class.isAssignableFrom(filterClass)) {
       report.setMessage(
           localStrings.getLocalString(
               "create.portunif.fail.notfilter",
               "{0} create failed.  Given class is not a ProtocolFilter: {1}",
               name,
               classname));
       report.setActionExitCode(ActionReport.ExitCode.FAILURE);
       return;
     }
     ProtocolChainInstanceHandler handler = getHandler(protocol);
     ProtocolChain chain = getChain(handler);
     ConfigSupport.apply(
         new SingleConfigCode<ProtocolChain>() {
           @Override
           public Object run(ProtocolChain param)
               throws PropertyVetoException, TransactionFailure {
             final List<ProtocolFilter> list = param.getProtocolFilter();
             for (ProtocolFilter filter : list) {
               if (name.equals(filter.getName())) {
                 throw new TransactionFailure(
                     String.format("A protocol filter named %s already exists.", name));
               }
             }
             final ProtocolFilter filter = param.createChild(ProtocolFilter.class);
             filter.setName(name);
             filter.setClassname(classname);
             list.add(filter);
             return null;
           }
         },
         chain);
   } catch (ValidationFailureException e) {
     return;
   } catch (Exception e) {
     e.printStackTrace();
     report.setMessage(
         localStrings.getLocalString(
             "create.portunif.fail",
             "{0} create failed: {1}",
             name,
             e.getMessage() == null ? "No reason given" : e.getMessage()));
     report.setActionExitCode(ActionReport.ExitCode.FAILURE);
     report.setFailureCause(e);
     return;
   }
 }
Example #3
0
  protected void configureContextXmlAttribute(
      WebappClassLoader cloader, File base, DeploymentContext dc)
      throws XMLStreamException, IOException {

    boolean consistent = true;
    Boolean value = null;

    File warContextXml = new File(base.getAbsolutePath(), WAR_CONTEXT_XML);
    if (warContextXml.exists()) {
      ContextXmlParser parser = new ContextXmlParser(warContextXml);
      value = parser.getClearReferencesStatic();
    }

    if (value == null) {
      Boolean domainCRS = null;
      File defaultContextXml = new File(serverEnvironment.getInstanceRoot(), DEFAULT_CONTEXT_XML);
      if (defaultContextXml.exists()) {
        ContextXmlParser parser = new ContextXmlParser(defaultContextXml);
        domainCRS = parser.getClearReferencesStatic();
      }

      List<Boolean> csrs = new ArrayList<Boolean>();
      HttpService httpService = serverConfig.getHttpService();
      DeployCommandParameters params = dc.getCommandParameters(DeployCommandParameters.class);
      String vsIDs = params.virtualservers;
      List<String> vsList = StringUtils.parseStringList(vsIDs, " ,");
      if (httpService != null && vsList != null && !vsList.isEmpty()) {
        for (VirtualServer vsBean : httpService.getVirtualServer()) {
          if (vsList.contains(vsBean.getId())) {
            Boolean csr = null;
            Property prop = vsBean.getProperty("contextXmlDefault");
            if (prop != null) {
              File contextXml = new File(serverEnvironment.getInstanceRoot(), prop.getValue());
              if (contextXml.exists()) { // vs context.xml
                ContextXmlParser parser = new ContextXmlParser(contextXml);
                csr = parser.getClearReferencesStatic();
              }
            }

            if (csr == null) {
              csr = domainCRS;
            }
            csrs.add(csr);
          }
        }

        // check that it is consistent
        for (Boolean b : csrs) {
          if (b != null) {
            if (value != null && !b.equals(value)) {
              consistent = false;
              break;
            }
            value = b;
          }
        }
      }
    }

    if (consistent) {
      if (value != null) {
        cloader.setClearReferencesStatic(value);
      }
    } else if (logger.isLoggable(Level.WARNING)) {
      logger.log(Level.WARNING, INCONSISTENT_CLEAR_REFERENCE_STATIC);
    }
  }
  @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");
        }
      }
    }
  }