From 77eb91adf0aaf790a8649e5b63e26ae46b7351fd Mon Sep 17 00:00:00 2001 From: Steve Millidge Date: Sat, 13 Aug 2016 20:01:05 +0100 Subject: [PATCH] Revert "Payara blue merge prior to release 163" (#1030) --- .../resources/notification/notification.jsf | 2 +- .../requestTracing/requestTracing.jsf | 2 +- .../admin/EnableMonitoringServiceOnDas.java | 76 -------- .../EnableMonitoringServiceOnInstance.java | 77 -------- .../admin/GetMonitoringConfiguration.java | 5 +- .../admin/SetMonitoringConfiguration.java | 33 +--- .../apache/catalina/fileupload/PartItem.java | 20 +- .../healthcheck/HealthCheckService.java | 8 - ...hCheckServiceThresholdConfigurerOnDas.java | 121 ------------ ...kServiceThresholdConfigurerOnInstance.java | 123 ------------ .../EnableHealthCheckConfigurerOnDas.java | 80 -------- ...EnableHealthCheckConfigurerOnInstance.java | 77 -------- ...ableHealthCheckServiceConfigurerOnDas.java | 117 ------------ ...ealthCheckServiceConfigurerOnInstance.java | 115 ----------- .../admin/GetHealthCheckConfiguration.java | 7 +- .../admin/HealthCheckConfigurer.java | 49 ++--- .../admin/HealthCheckServiceConfigurer.java | 70 +++---- .../admin/HealthCheckServiceLister.java | 5 +- ...HealthCheckServiceThresholdConfigurer.java | 64 +++---- .../preliminary/BaseHealthCheck.java | 17 +- ...nableNotificationConfigurerOnInstance.java | 83 -------- .../admin/NotificationConfigurer.java | 30 +-- ...as.java => NotificationConfigurerDas.java} | 61 +++++- .../admin/NotificationNotifierConfigurer.java | 65 ++++--- ...=> NotificationNotifierConfigurerDas.java} | 56 ++++-- ...onfiguration.java => SetNotification.java} | 21 +- .../EnableRequestTracingConfigurerOnDas.java | 104 ---------- ...bleRequestTracingConfigurerOnInstance.java | 105 ---------- ...RequestTracingNotifierConfigurerOnDas.java | 104 ---------- ...stTracingNotifierConfigurerOnInstance.java | 107 ----------- .../admin/RequestTracingConfigurer.java | 56 ++---- .../admin/RequestTracingConfigurerDas.java | 180 ++++++++++++++++++ .../RequestTracingNotifierConfigurer.java | 58 +++--- .../RequestTracingNotifierConfigurerDas.java} | 110 ++++++----- ...figuration.java => SetRequestTracing.java} | 62 +++--- .../execoptions/NotifierExecutionOptions.java | 2 +- .../requesttracing/RequestTraceTest.java | 3 +- 37 files changed, 553 insertions(+), 1722 deletions(-) delete mode 100644 appserver/payara-appserver-modules/jmx-monitoring-service/src/main/java/fish/payara/jmx/monitoring/admin/EnableMonitoringServiceOnDas.java delete mode 100644 appserver/payara-appserver-modules/jmx-monitoring-service/src/main/java/fish/payara/jmx/monitoring/admin/EnableMonitoringServiceOnInstance.java delete mode 100644 nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/EditHealthCheckServiceThresholdConfigurerOnDas.java delete mode 100644 nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/EditHealthCheckServiceThresholdConfigurerOnInstance.java delete mode 100644 nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/EnableHealthCheckConfigurerOnDas.java delete mode 100644 nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/EnableHealthCheckConfigurerOnInstance.java delete mode 100644 nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/EnableHealthCheckServiceConfigurerOnDas.java delete mode 100644 nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/EnableHealthCheckServiceConfigurerOnInstance.java delete mode 100644 nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/EnableNotificationConfigurerOnInstance.java rename nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/{EnableNotificationConfigurerOnDas.java => NotificationConfigurerDas.java} (52%) rename nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/{EnableNotificationNotifierConfigurerOnDas.java => NotificationNotifierConfigurerDas.java} (76%) rename nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/{SetNotificationConfiguration.java => SetNotification.java} (86%) delete mode 100644 nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/admin/EnableRequestTracingConfigurerOnDas.java delete mode 100644 nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/admin/EnableRequestTracingConfigurerOnInstance.java delete mode 100644 nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/admin/EnableRequestTracingNotifierConfigurerOnDas.java delete mode 100644 nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/admin/EnableRequestTracingNotifierConfigurerOnInstance.java create mode 100644 nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/admin/RequestTracingConfigurerDas.java rename nucleus/payara-modules/{notification-core/src/main/java/fish/payara/nucleus/notification/admin/EnableNotificationNotifierConfigurerOnInstance.java => requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/admin/RequestTracingNotifierConfigurerDas.java} (53%) rename nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/admin/{SetRequestTracingConfiguration.java => SetRequestTracing.java} (79%) diff --git a/appserver/admingui/payara-console-extras/src/main/resources/notification/notification.jsf b/appserver/admingui/payara-console-extras/src/main/resources/notification/notification.jsf index 34ba8f8d0ab..f47a59ec9c2 100644 --- a/appserver/admingui/payara-console-extras/src/main/resources/notification/notification.jsf +++ b/appserver/admingui/payara-console-extras/src/main/resources/notification/notification.jsf @@ -58,7 +58,7 @@ mapPut(map="#{pageSession.valueMap}" key="dynamic" value="#{pageSession.dynamic}"); mapPut(map="#{pageSession.valueMap}" key="notifierDynamic" value="#{pageSession.notifierDynamic}"); prepareSuccessfulMsg(); - gf.updateEntity(endpoint="#{sessionScope.REST_URL}/set-notification-configuration" attrs="#{pageSession.valueMap}" convertToFalse="#{pageSession.convertToFalseList}"); + gf.updateEntity(endpoint="#{sessionScope.REST_URL}/set-notification" attrs="#{pageSession.valueMap}" convertToFalse="#{pageSession.convertToFalseList}"); /> diff --git a/appserver/admingui/payara-console-extras/src/main/resources/requestTracing/requestTracing.jsf b/appserver/admingui/payara-console-extras/src/main/resources/requestTracing/requestTracing.jsf index d5d5122d635..54ac3f99683 100644 --- a/appserver/admingui/payara-console-extras/src/main/resources/requestTracing/requestTracing.jsf +++ b/appserver/admingui/payara-console-extras/src/main/resources/requestTracing/requestTracing.jsf @@ -58,7 +58,7 @@ mapPut(map="#{pageSession.valueMap}" key="dynamic" value="#{pageSession.dynamic}"); mapPut(map="#{pageSession.valueMap}" key="notifierDynamic" value="#{pageSession.notifierDynamic}"); prepareSuccessfulMsg(); - gf.updateEntity(endpoint="#{sessionScope.REST_URL}/set-requesttracing-configuration" attrs="#{pageSession.valueMap}" convertToFalse="#{pageSession.convertToFalseList}"); + gf.updateEntity(endpoint="#{sessionScope.REST_URL}/set-requesttracing" attrs="#{pageSession.valueMap}" convertToFalse="#{pageSession.convertToFalseList}"); /> diff --git a/appserver/payara-appserver-modules/jmx-monitoring-service/src/main/java/fish/payara/jmx/monitoring/admin/EnableMonitoringServiceOnDas.java b/appserver/payara-appserver-modules/jmx-monitoring-service/src/main/java/fish/payara/jmx/monitoring/admin/EnableMonitoringServiceOnDas.java deleted file mode 100644 index 9aeffdb4ada..00000000000 --- a/appserver/payara-appserver-modules/jmx-monitoring-service/src/main/java/fish/payara/jmx/monitoring/admin/EnableMonitoringServiceOnDas.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - Copyright (c) 2016 C2B2 Consulting Limited. All rights reserved. - The contents of this file are subject to the terms of the Common Development - and Distribution License("CDDL") (collectively, the "License"). You - may not use this file except in compliance with the License. You can - obtain a copy of the License at - https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html - or packager/legal/LICENSE.txt. See the License for the specific - language governing permissions and limitations under the License. - When distributing the software, include this License Header Notice in each - file and include the License file at packager/legal/LICENSE.txt. - */ -package fish.payara.jmx.monitoring.admin; - -import com.sun.enterprise.config.serverbeans.Domain; -import fish.payara.jmx.monitoring.MonitoringService; -import java.util.Properties; -import javax.inject.Inject; -import org.glassfish.api.ActionReport; -import org.glassfish.api.I18n; -import org.glassfish.api.Param; -import org.glassfish.api.admin.AdminCommand; -import org.glassfish.api.admin.AdminCommandContext; -import org.glassfish.api.admin.CommandLock; -import org.glassfish.api.admin.ExecuteOn; -import org.glassfish.api.admin.RestEndpoint; -import org.glassfish.api.admin.RestEndpoints; -import org.glassfish.api.admin.RuntimeType; -import org.glassfish.config.support.CommandTarget; -import org.glassfish.config.support.TargetType; -import org.glassfish.hk2.api.PerLookup; -import org.jvnet.hk2.annotations.Service; - -/** - * - * @author savage - */ -@Service(name = "__enable-monitoring-service-on-das") -@PerLookup -@CommandLock(CommandLock.LockType.NONE) -@I18n("__enable-monitoring-service-on-das") -@ExecuteOn(RuntimeType.DAS) -@TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG}) -@RestEndpoints({ - @RestEndpoint(configBean = Domain.class, - opType = RestEndpoint.OpType.GET, - path = "__enable-monitoring-service-on-das", - description = "Enables the JMX Monitoring Service on the DAS") -}) -public class EnableMonitoringServiceOnDas implements AdminCommand { - - @Inject - MonitoringService monitoringService; - - @Param(name = "enabled", optional = false) - private Boolean enabled; - - @Param(name = "target", optional = true, defaultValue = "server") - protected String target; - - @Override - public void execute(AdminCommandContext context) { - - final ActionReport actionReport = context.getActionReport(); - Properties extraProperties = actionReport.getExtraProperties(); - if (extraProperties == null) { - extraProperties = new Properties(); - actionReport.setExtraProperties(extraProperties); - } - - monitoringService.setEnabled(enabled); - actionReport.appendMessage("The JMX Monitoring Service status set to " + enabled + " on " + target); - } - -} diff --git a/appserver/payara-appserver-modules/jmx-monitoring-service/src/main/java/fish/payara/jmx/monitoring/admin/EnableMonitoringServiceOnInstance.java b/appserver/payara-appserver-modules/jmx-monitoring-service/src/main/java/fish/payara/jmx/monitoring/admin/EnableMonitoringServiceOnInstance.java deleted file mode 100644 index c8020912121..00000000000 --- a/appserver/payara-appserver-modules/jmx-monitoring-service/src/main/java/fish/payara/jmx/monitoring/admin/EnableMonitoringServiceOnInstance.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - Copyright (c) 2016 C2B2 Consulting Limited. All rights reserved. - The contents of this file are subject to the terms of the Common Development - and Distribution License("CDDL") (collectively, the "License"). You - may not use this file except in compliance with the License. You can - obtain a copy of the License at - https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html - or packager/legal/LICENSE.txt. See the License for the specific - language governing permissions and limitations under the License. - When distributing the software, include this License Header Notice in each - file and include the License file at packager/legal/LICENSE.txt. - */ -package fish.payara.jmx.monitoring.admin; - -import com.sun.enterprise.config.serverbeans.Domain; -import fish.payara.jmx.monitoring.MonitoringService; -import java.util.Properties; -import javax.inject.Inject; -import org.glassfish.api.ActionReport; -import org.glassfish.api.I18n; -import org.glassfish.api.Param; -import org.glassfish.api.admin.AdminCommand; -import org.glassfish.api.admin.AdminCommandContext; -import org.glassfish.api.admin.CommandLock; -import org.glassfish.api.admin.ExecuteOn; -import org.glassfish.api.admin.RestEndpoint; -import org.glassfish.api.admin.RestEndpoints; -import org.glassfish.api.admin.RuntimeType; -import org.glassfish.config.support.CommandTarget; -import org.glassfish.config.support.TargetType; -import org.glassfish.hk2.api.PerLookup; -import org.jboss.logging.Logger; -import org.jvnet.hk2.annotations.Service; - -/** - * - * @author savage - */ -@Service(name = "__enable-monitoring-service-on-instance") -@PerLookup -@CommandLock(CommandLock.LockType.NONE) -@I18n("__enable-monitoring-service-on-instance") -@ExecuteOn(RuntimeType.INSTANCE) -@TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG}) -@RestEndpoints({ - @RestEndpoint(configBean = Domain.class, - opType = RestEndpoint.OpType.GET, - path = "__enable-monitoring-service-on-instance", - description = "Enables the JMX Monitoring Service on Instance") -}) -public class EnableMonitoringServiceOnInstance implements AdminCommand { - - @Inject - MonitoringService monitoringService; - - @Param(name = "enabled", optional = false) - private Boolean enabled; - - @Param(name = "target", optional = true, defaultValue = "server") - protected String target; - - @Override - public void execute(AdminCommandContext context) { - - final ActionReport actionReport = context.getActionReport(); - Properties extraProperties = actionReport.getExtraProperties(); - if (extraProperties == null) { - extraProperties = new Properties(); - actionReport.setExtraProperties(extraProperties); - } - - monitoringService.setEnabled(enabled); - actionReport.appendMessage("The JMX Monitoring Service status set to " + enabled + " on " + target); - } - -} diff --git a/appserver/payara-appserver-modules/jmx-monitoring-service/src/main/java/fish/payara/jmx/monitoring/admin/GetMonitoringConfiguration.java b/appserver/payara-appserver-modules/jmx-monitoring-service/src/main/java/fish/payara/jmx/monitoring/admin/GetMonitoringConfiguration.java index 0434f9e9fe2..5f07fe894f5 100644 --- a/appserver/payara-appserver-modules/jmx-monitoring-service/src/main/java/fish/payara/jmx/monitoring/admin/GetMonitoringConfiguration.java +++ b/appserver/payara-appserver-modules/jmx-monitoring-service/src/main/java/fish/payara/jmx/monitoring/admin/GetMonitoringConfiguration.java @@ -17,7 +17,6 @@ and Distribution License("CDDL") (collectively, the "License"). You import com.sun.enterprise.config.serverbeans.Domain; import com.sun.enterprise.util.ColumnFormatter; import com.sun.enterprise.util.StringUtils; -import com.sun.enterprise.util.SystemPropertyConstants; import fish.payara.jmx.monitoring.configuration.MonitoringServiceConfiguration; import javax.inject.Inject; import org.glassfish.api.ActionReport; @@ -47,7 +46,7 @@ and Distribution License("CDDL") (collectively, the "License"). You @CommandLock(CommandLock.LockType.NONE) @I18n("get.monitoring.configuration") @ExecuteOn(value = {RuntimeType.DAS}) -@TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG}) +@TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER}) @RestEndpoints({ @RestEndpoint(configBean = Domain.class, opType = RestEndpoint.OpType.GET, @@ -64,7 +63,7 @@ public class GetMonitoringConfiguration implements AdminCommand { @Param(name = "pretty", defaultValue = "false", optional = true) private Boolean pretty; - @Param(name = "target", defaultValue = SystemPropertyConstants.DAS_SERVER_NAME, optional = true) + @Param(name = "target", defaultValue = "server", optional = true) private String target; /** diff --git a/appserver/payara-appserver-modules/jmx-monitoring-service/src/main/java/fish/payara/jmx/monitoring/admin/SetMonitoringConfiguration.java b/appserver/payara-appserver-modules/jmx-monitoring-service/src/main/java/fish/payara/jmx/monitoring/admin/SetMonitoringConfiguration.java index 36bced6663b..17504cb57dd 100644 --- a/appserver/payara-appserver-modules/jmx-monitoring-service/src/main/java/fish/payara/jmx/monitoring/admin/SetMonitoringConfiguration.java +++ b/appserver/payara-appserver-modules/jmx-monitoring-service/src/main/java/fish/payara/jmx/monitoring/admin/SetMonitoringConfiguration.java @@ -28,9 +28,7 @@ and Distribution License("CDDL") (collectively, the "License"). You import org.glassfish.api.admin.AdminCommand; import org.glassfish.api.admin.AdminCommandContext; import org.glassfish.api.admin.CommandLock; -import org.glassfish.api.admin.CommandRunner; import org.glassfish.api.admin.ExecuteOn; -import org.glassfish.api.admin.ParameterMap; import org.glassfish.api.admin.RestEndpoint; import org.glassfish.api.admin.RestEndpoints; import org.glassfish.api.admin.RuntimeType; @@ -54,8 +52,8 @@ and Distribution License("CDDL") (collectively, the "License"). You @PerLookup @CommandLock(CommandLock.LockType.NONE) @I18n("set.monitoring.configuration") -@ExecuteOn(RuntimeType.DAS) -@TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG}) +@ExecuteOn(RuntimeType.INSTANCE) +@TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER}) @RestEndpoints({ @RestEndpoint(configBean = Domain.class, opType = RestEndpoint.OpType.GET, @@ -65,7 +63,7 @@ and Distribution License("CDDL") (collectively, the "License"). You public class SetMonitoringConfiguration implements AdminCommand { @Inject - ServiceLocator serviceLocator; + ServiceLocator habitat; @Inject protected Target targetUtil; @@ -102,7 +100,7 @@ public void execute(AdminCommandContext context) { final ActionReport actionReport = context.getActionReport(); Config config = targetUtil.getConfig(target); - final MonitoringService service = serviceLocator.getService(MonitoringService.class); + final MonitoringService service = habitat.getService(MonitoringService.class); if (service == null) { actionReport.appendMessage("Could not find a monitoring service."); actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE); @@ -120,9 +118,9 @@ public Object run(final MonitoringServiceConfiguration monitoringConfigProxy) th return monitoringConfigProxy; } }, monitoringConfig); - + if (dynamic) { - enableOnTarget(actionReport, context, enabled); + monitoringService.setEnabled(enabled); } } catch (TransactionFailure ex) { @@ -155,25 +153,6 @@ private void updateConfiguration(MonitoringServiceConfiguration monitoringConfig } } - private void enableOnTarget(ActionReport actionReport, AdminCommandContext context, Boolean enabled) { - CommandRunner runner = serviceLocator.getService(CommandRunner.class); - ActionReport subReport = context.getActionReport().addSubActionsReport(); - CommandRunner.CommandInvocation invocation; - - if (target.equals("server-config")) { - invocation = runner.getCommandInvocation("__enable-monitoring-service-on-das", subReport, context.getSubject()); - } else { - invocation = runner.getCommandInvocation("__enable-monitoring-service-on-instance", subReport, context.getSubject()); - } - - // Build the parameters - ParameterMap params = new ParameterMap(); - params.add("enabled", enabled.toString()); - params.add("target", target); - invocation.parameters(params); - invocation.execute(); - } - /** * Updates monitoring attributes through adding a new property and/or deleting an existing one. * diff --git a/appserver/web/web-core/src/main/java/org/apache/catalina/fileupload/PartItem.java b/appserver/web/web-core/src/main/java/org/apache/catalina/fileupload/PartItem.java index 11397236cb8..fe5752ee316 100644 --- a/appserver/web/web-core/src/main/java/org/apache/catalina/fileupload/PartItem.java +++ b/appserver/web/web-core/src/main/java/org/apache/catalina/fileupload/PartItem.java @@ -56,7 +56,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -// Portions Copyright [2016] [C2B2 Consulting Limited and/or its affiliates] + package org.apache.catalina.fileupload; import org.apache.catalina.Globals; @@ -739,24 +739,6 @@ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { // read values in.defaultReadObject(); - - // PAYARA-953 protect against null byte attacks - if (repository != null) { - if (repository.getPath().contains("\0")) { - throw new IOException("Repository path cannot contain a null byte"); - } - - if (!repository.isDirectory()) { - throw new IOException("Repository path " + repository.getPath() + " is not a directory "); - } - } - - if (dfosFile != null) { - if (dfosFile.getPath().contains("\0")) { - throw new IOException("File path cannot contain a null byte"); - } - } - // END PAYARA-953 OutputStream output = getOutputStream(); if (cachedContent != null) { diff --git a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/HealthCheckService.java b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/HealthCheckService.java index c5d3eca3b55..39490ea63b0 100644 --- a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/HealthCheckService.java +++ b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/HealthCheckService.java @@ -132,12 +132,4 @@ public void shutdownHealthCheck() { Logger.getLogger(HealthCheckService.class.getName()).log(Level.INFO, "Payara Health Check Service is shutdown."); } } - - public BaseHealthCheck getCheck(String serviceName) { - return registeredTasks.get(serviceName).getCheck(); - } - - public HealthCheckServiceConfiguration getConfiguration() { - return configuration; - } } \ No newline at end of file diff --git a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/EditHealthCheckServiceThresholdConfigurerOnDas.java b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/EditHealthCheckServiceThresholdConfigurerOnDas.java deleted file mode 100644 index cdc24aa1791..00000000000 --- a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/EditHealthCheckServiceThresholdConfigurerOnDas.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - - - Copyright (c) 2016 C2B2 Consulting Limited. All rights reserved. - - - The contents of this file are subject to the terms of the Common Development - and Distribution License("CDDL") (collectively, the "License"). You - may not use this file except in compliance with the License. You can - obtain a copy of the License at - https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html - or packager/legal/LICENSE.txt. See the License for the specific - language governing permissions and limitations under the License. - - When distributing the software, include this License Header Notice in each - file and include the License file at packager/legal/LICENSE.txt. - */ -package fish.payara.nucleus.healthcheck.admin; - -import com.sun.enterprise.config.serverbeans.Domain; -import com.sun.enterprise.util.LocalStringManagerImpl; -import fish.payara.nucleus.healthcheck.HealthCheckService; -import fish.payara.nucleus.healthcheck.preliminary.BaseThresholdHealthCheck; -import java.util.Properties; -import javax.inject.Inject; -import org.glassfish.api.ActionReport; -import org.glassfish.api.I18n; -import org.glassfish.api.Param; -import org.glassfish.api.admin.AdminCommand; -import org.glassfish.api.admin.AdminCommandContext; -import org.glassfish.api.admin.CommandLock; -import org.glassfish.api.admin.ExecuteOn; -import org.glassfish.api.admin.RestEndpoint; -import org.glassfish.api.admin.RestEndpoints; -import org.glassfish.api.admin.RuntimeType; -import org.glassfish.config.support.CommandTarget; -import org.glassfish.config.support.TargetType; -import org.glassfish.hk2.api.PerLookup; -import org.glassfish.hk2.api.ServiceLocator; -import org.jvnet.hk2.annotations.Service; - -/** - * - * @author Susan Rai - */ -@Service(name = "__edit-healthcheck-configure-service-threshold-on-das") -@PerLookup -@CommandLock(CommandLock.LockType.NONE) -@I18n("__edit-healthcheck-configure-service-threshold-on-das") -@ExecuteOn(RuntimeType.DAS) -@TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG}) -public class EditHealthCheckServiceThresholdConfigurerOnDas implements AdminCommand { - - final private static LocalStringManagerImpl strings = new LocalStringManagerImpl(HealthCheckServiceThresholdConfigurer.class); - - @Inject - ServiceLocator habitat; - - @Inject - HealthCheckService healthCheckService; - - @Param(name = "serviceName", optional = false) - private String serviceName; - - @Param(name = "thresholdCritical", optional = true) - private String thresholdCritical; - - @Param(name = "thresholdWarning", optional = true) - private String thresholdWarning; - - @Param(name = "thresholdGood", optional = true) - private String thresholdGood; - - @Param(name = "target", optional = true, defaultValue = "server") - protected String target; - - @Override - public void execute(AdminCommandContext context) { - final ActionReport actionReport = context.getActionReport(); - Properties extraProperties = actionReport.getExtraProperties(); - if (extraProperties == null) { - extraProperties = new Properties(); - actionReport.setExtraProperties(extraProperties); - } - - BaseThresholdHealthCheck service = habitat.getService(BaseThresholdHealthCheck.class, serviceName); - if (service == null) { - actionReport.appendMessage("No service found with name " + serviceName); - return; - } - - if (service.getOptions() == null) { - actionReport.appendMessage("Setting the service thresholds for " + serviceName + " will require a server restart"); - return; - } - - if (thresholdCritical != null) { - service.getOptions().setThresholdCritical(Integer.valueOf(thresholdCritical)); - actionReport.appendMessage(strings.getLocalString( - "healthcheck.service.configure.threshold.critical.success", - "Critical threshold for {0} service is set with value {1}.", serviceName, thresholdCritical)); - actionReport.appendMessage("\n"); - } - if (thresholdWarning != null) { - service.getOptions().setThresholdWarning(Integer.valueOf(thresholdWarning)); - actionReport.appendMessage(strings.getLocalString("healthcheck.service.configure.threshold.warning.success", - "Warning threshold for {0} service is set with value {1}.", serviceName, thresholdWarning)); - actionReport.appendMessage("\n"); - } - if (thresholdGood != null) { - service.getOptions().setThresholdGood(Integer.valueOf(thresholdGood)); - actionReport.appendMessage(strings.getLocalString("healthcheck.service.configure.threshold.good.success", - "Good threshold for {0} service is set with value {1}.", serviceName, thresholdGood)); - actionReport.appendMessage("\n"); - } - - healthCheckService.shutdownHealthCheck(); - healthCheckService.bootstrapHealthCheck(); - } -} diff --git a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/EditHealthCheckServiceThresholdConfigurerOnInstance.java b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/EditHealthCheckServiceThresholdConfigurerOnInstance.java deleted file mode 100644 index bc62e462749..00000000000 --- a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/EditHealthCheckServiceThresholdConfigurerOnInstance.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - - - Copyright (c) 2016 C2B2 Consulting Limited. All rights reserved. - - - The contents of this file are subject to the terms of the Common Development - and Distribution License("CDDL") (collectively, the "License"). You - may not use this file except in compliance with the License. You can - obtain a copy of the License at - https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html - or packager/legal/LICENSE.txt. See the License for the specific - language governing permissions and limitations under the License. - - When distributing the software, include this License Header Notice in each - file and include the License file at packager/legal/LICENSE.txt. - */ -package fish.payara.nucleus.healthcheck.admin; - -import com.sun.enterprise.config.serverbeans.Domain; -import com.sun.enterprise.util.LocalStringManagerImpl; -import fish.payara.nucleus.healthcheck.HealthCheckService; -import fish.payara.nucleus.healthcheck.preliminary.BaseHealthCheck; -import fish.payara.nucleus.healthcheck.preliminary.BaseThresholdHealthCheck; -import java.util.Properties; -import javax.inject.Inject; -import org.glassfish.api.ActionReport; -import org.glassfish.api.I18n; -import org.glassfish.api.Param; -import org.glassfish.api.admin.AdminCommand; -import org.glassfish.api.admin.AdminCommandContext; -import org.glassfish.api.admin.CommandLock; -import org.glassfish.api.admin.ExecuteOn; -import org.glassfish.api.admin.RestEndpoint; -import org.glassfish.api.admin.RestEndpoints; -import org.glassfish.api.admin.RuntimeType; -import org.glassfish.config.support.CommandTarget; -import org.glassfish.config.support.TargetType; -import org.glassfish.hk2.api.PerLookup; -import org.glassfish.hk2.api.ServiceLocator; -import org.jvnet.hk2.annotations.Service; - -/** - * - * @author Susan Rai - */ -@Service(name = "__edit-healthcheck-configure-service-threshold-on-instance") -@PerLookup -@CommandLock(CommandLock.LockType.NONE) -@I18n("__edit-healthcheck-configure-service-threshold-on-instance") -@ExecuteOn(RuntimeType.INSTANCE) -@TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG}) -public class EditHealthCheckServiceThresholdConfigurerOnInstance implements AdminCommand { - - final private static LocalStringManagerImpl strings = new LocalStringManagerImpl(HealthCheckServiceThresholdConfigurer.class); - - - @Inject - HealthCheckService healthCheckService; - - @Inject - ServiceLocator habitat; - - @Param(name = "serviceName", optional = false) - private String serviceName; - - @Param(name = "thresholdCritical", optional = true) - private String thresholdCritical; - - @Param(name = "thresholdWarning", optional = true) - private String thresholdWarning; - - @Param(name = "thresholdGood", optional = true) - private String thresholdGood; - - @Param(name = "target", optional = true, defaultValue = "server") - protected String target; - - @Override - public void execute(AdminCommandContext context) { - final ActionReport actionReport = context.getActionReport(); - Properties extraProperties = actionReport.getExtraProperties(); - if (extraProperties == null) { - extraProperties = new Properties(); - actionReport.setExtraProperties(extraProperties); - } - - BaseThresholdHealthCheck service = habitat.getService(BaseThresholdHealthCheck.class, serviceName); - if (service == null) { - actionReport.appendMessage("No service found with name " + serviceName); - return; - } - - if (service.getOptions() == null) { - actionReport.appendMessage("Setting the service thresholds for " + serviceName + " will require a server restart"); - return; - } - - if (thresholdCritical != null) { - service.getOptions().setThresholdCritical(Integer.valueOf(thresholdCritical)); - actionReport.appendMessage(strings.getLocalString( - "healthcheck.service.configure.threshold.critical.success", - "Critical threshold for {0} service is set with value {1}.", serviceName, thresholdCritical)); - actionReport.appendMessage("\n"); - } - if (thresholdWarning != null) { - service.getOptions().setThresholdWarning(Integer.valueOf(thresholdWarning)); - actionReport.appendMessage(strings.getLocalString("healthcheck.service.configure.threshold.warning.success", - "Warning threshold for {0} service is set with value {1}.", serviceName, thresholdWarning)); - actionReport.appendMessage("\n"); - } - if (thresholdGood != null) { - service.getOptions().setThresholdGood(Integer.valueOf(thresholdGood)); - actionReport.appendMessage(strings.getLocalString("healthcheck.service.configure.threshold.good.success", - "Good threshold for {0} service is set with value {1}.", serviceName, thresholdGood)); - actionReport.appendMessage("\n"); - } - - healthCheckService.shutdownHealthCheck(); - healthCheckService.bootstrapHealthCheck(); - } -} diff --git a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/EnableHealthCheckConfigurerOnDas.java b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/EnableHealthCheckConfigurerOnDas.java deleted file mode 100644 index 42f691b7553..00000000000 --- a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/EnableHealthCheckConfigurerOnDas.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - - - Copyright (c) 2016 C2B2 Consulting Limited. All rights reserved. - - - The contents of this file are subject to the terms of the Common Development - and Distribution License("CDDL") (collectively, the "License"). You - may not use this file except in compliance with the License. You can - obtain a copy of the License at - https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html - or packager/legal/LICENSE.txt. See the License for the specific - language governing permissions and limitations under the License. - - When distributing the software, include this License Header Notice in each - file and include the License file at packager/legal/LICENSE.txt. - */ -package fish.payara.nucleus.healthcheck.admin; - -import com.sun.enterprise.config.serverbeans.Domain; -import com.sun.enterprise.util.LocalStringManagerImpl; -import fish.payara.nucleus.healthcheck.HealthCheckService; -import java.util.Properties; -import javax.inject.Inject; -import org.glassfish.api.ActionReport; -import org.glassfish.api.I18n; -import org.glassfish.api.Param; -import org.glassfish.api.admin.AdminCommand; -import org.glassfish.api.admin.AdminCommandContext; -import org.glassfish.api.admin.CommandLock; -import org.glassfish.api.admin.ExecuteOn; -import org.glassfish.api.admin.RestEndpoint; -import org.glassfish.api.admin.RestEndpoints; -import org.glassfish.api.admin.RuntimeType; -import org.glassfish.config.support.CommandTarget; -import org.glassfish.config.support.TargetType; -import org.glassfish.hk2.api.PerLookup; -import org.jvnet.hk2.annotations.Service; - -/** - * - * @author Susan Rai - */ -@Service(name = "__enable-healthcheck-configurer-on-das") -@PerLookup -@CommandLock(CommandLock.LockType.NONE) -@I18n("__enable-healthcheck-configurer-on-das") -@ExecuteOn(RuntimeType.DAS) -@TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG}) -public class EnableHealthCheckConfigurerOnDas implements AdminCommand { - - final private static LocalStringManagerImpl strings = new LocalStringManagerImpl(HealthCheckConfigurer.class); - - @Inject - HealthCheckService service; - - @Param(name = "target", optional = true, defaultValue = "server") - protected String target; - - @Param(name = "enabled", optional = false) - private Boolean enabled; - - @Override - public void execute(AdminCommandContext context) { - final ActionReport actionReport = context.getActionReport(); - Properties extraProperties = actionReport.getExtraProperties(); - if (extraProperties == null) { - extraProperties = new Properties(); - actionReport.setExtraProperties(extraProperties); - } - - service.setEnabled(enabled); - actionReport.appendMessage("Health Check Service staus set to " + enabled + " on " + target ); - - service.shutdownHealthCheck(); - service.bootstrapHealthCheck(); - } - -} diff --git a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/EnableHealthCheckConfigurerOnInstance.java b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/EnableHealthCheckConfigurerOnInstance.java deleted file mode 100644 index aaa2079878a..00000000000 --- a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/EnableHealthCheckConfigurerOnInstance.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - - - Copyright (c) 2016 C2B2 Consulting Limited. All rights reserved. - - - The contents of this file are subject to the terms of the Common Development - and Distribution License("CDDL") (collectively, the "License"). You - may not use this file except in compliance with the License. You can - obtain a copy of the License at - https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html - or packager/legal/LICENSE.txt. See the License for the specific - language governing permissions and limitations under the License. - - When distributing the software, include this License Header Notice in each - file and include the License file at packager/legal/LICENSE.txt. - */ -package fish.payara.nucleus.healthcheck.admin; - -import com.sun.enterprise.config.serverbeans.Domain; -import com.sun.enterprise.util.LocalStringManagerImpl; -import fish.payara.nucleus.healthcheck.HealthCheckService; -import java.util.Properties; -import javax.inject.Inject; -import org.glassfish.api.ActionReport; -import org.glassfish.api.I18n; -import org.glassfish.api.Param; -import org.glassfish.api.admin.AdminCommand; -import org.glassfish.api.admin.AdminCommandContext; -import org.glassfish.api.admin.CommandLock; -import org.glassfish.api.admin.ExecuteOn; -import org.glassfish.api.admin.RestEndpoint; -import org.glassfish.api.admin.RestEndpoints; -import org.glassfish.api.admin.RuntimeType; -import org.glassfish.config.support.CommandTarget; -import org.glassfish.config.support.TargetType; -import org.glassfish.hk2.api.PerLookup; -import org.jvnet.hk2.annotations.Service; - -/** - * - * @author Susan Rai - */ -@Service(name = "__enable-healthcheck-configurer-on-instance") -@PerLookup -@CommandLock(CommandLock.LockType.NONE) -@I18n("__enable-healthcheck-configurer-on-instance") -@ExecuteOn(RuntimeType.INSTANCE) -@TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG}) -public class EnableHealthCheckConfigurerOnInstance implements AdminCommand { - - @Inject - HealthCheckService service; - - @Param(name = "target", optional = true, defaultValue = "server") - protected String target; - - @Param(name = "enabled", optional = false) - private Boolean enabled; - - @Override - public void execute(AdminCommandContext context) { - final ActionReport actionReport = context.getActionReport(); - Properties extraProperties = actionReport.getExtraProperties(); - if (extraProperties == null) { - extraProperties = new Properties(); - actionReport.setExtraProperties(extraProperties); - } - - service.setEnabled(enabled); - actionReport.appendMessage("Health Check Service staus set to " + enabled + " on " + target ); - service.shutdownHealthCheck(); - service.bootstrapHealthCheck(); - } - -} diff --git a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/EnableHealthCheckServiceConfigurerOnDas.java b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/EnableHealthCheckServiceConfigurerOnDas.java deleted file mode 100644 index 72ad1e04a11..00000000000 --- a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/EnableHealthCheckServiceConfigurerOnDas.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - - - Copyright (c) 2016 C2B2 Consulting Limited. All rights reserved. - - - The contents of this file are subject to the terms of the Common Development - and Distribution License("CDDL") (collectively, the "License"). You - may not use this file except in compliance with the License. You can - obtain a copy of the License at - https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html - or packager/legal/LICENSE.txt. See the License for the specific - language governing permissions and limitations under the License. - - When distributing the software, include this License Header Notice in each - file and include the License file at packager/legal/LICENSE.txt. - */ -package fish.payara.nucleus.healthcheck.admin; - -import com.sun.enterprise.config.serverbeans.Domain; -import com.sun.enterprise.util.LocalStringManagerImpl; -import fish.payara.nucleus.healthcheck.HealthCheckService; -import fish.payara.nucleus.healthcheck.configuration.Checker; -import fish.payara.nucleus.healthcheck.preliminary.BaseHealthCheck; -import java.util.Properties; -import java.util.concurrent.TimeUnit; -import javax.inject.Inject; -import org.glassfish.api.ActionReport; -import org.glassfish.api.I18n; -import org.glassfish.api.Param; -import org.glassfish.api.admin.AdminCommand; -import org.glassfish.api.admin.AdminCommandContext; -import org.glassfish.api.admin.CommandLock; -import org.glassfish.api.admin.ExecuteOn; -import org.glassfish.api.admin.RestEndpoint; -import org.glassfish.api.admin.RestEndpoints; -import org.glassfish.api.admin.RuntimeType; -import org.glassfish.config.support.CommandTarget; -import org.glassfish.config.support.TargetType; -import org.glassfish.hk2.api.PerLookup; -import org.glassfish.hk2.api.ServiceLocator; -import org.jvnet.hk2.annotations.Service; - -/** - * - * @author Susan Rai - */ -@Service(name = "__enable-healthcheck-configure-service-on-das") -@PerLookup -@CommandLock(CommandLock.LockType.NONE) -@I18n("__enable-healthcheck-configure-service-on-das") -@ExecuteOn(RuntimeType.DAS) -@TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG}) -public class EnableHealthCheckServiceConfigurerOnDas implements AdminCommand { - - final private static LocalStringManagerImpl strings = new LocalStringManagerImpl(HealthCheckServiceConfigurer.class); - - @Inject - ServiceLocator habitat; - - @Inject - HealthCheckService healthCheckService; - - @Param(name = "target", optional = true, defaultValue = "server") - protected String target; - - @Param(name = "enabled", optional = false) - private Boolean enabled; - - @Param(name = "time", optional = true) - private String time; - - @Param(name = "unit", optional = true) - private String unit; - - @Param(name = "serviceName", optional = false) - private String serviceName; - - @Override - public void execute(AdminCommandContext context) { - final ActionReport actionReport = context.getActionReport(); - Properties extraProperties = actionReport.getExtraProperties(); - if (extraProperties == null) { - extraProperties = new Properties(); - actionReport.setExtraProperties(extraProperties); - } - - BaseHealthCheck service = habitat.getService(BaseHealthCheck.class, serviceName); - Checker checkerByType = healthCheckService.getConfiguration().getCheckerByType(service.getCheckerType()); - if (service.getOptions() == null) { - if (checkerByType == null) { - actionReport.appendMessage("Enabling a new Healthcheck requires a server restart.."); - return; - } else { - service.setOptions(service.constructOptions(checkerByType)); - } - } - - if (enabled != null) { - service.getOptions().setEnabled(enabled); - } - if (time != null) { - service.getOptions().setTime(Long.valueOf(time)); - } - if (unit != null) { - service.getOptions().setUnit(TimeUnit.valueOf(unit)); - } - - actionReport.appendMessage(strings.getLocalString("healthcheck.service.configure.status.success", - "Service status for {0} is set to {1}.", serviceName, enabled)); - healthCheckService.registerCheck(checkerByType.getName(), service); - healthCheckService.shutdownHealthCheck(); - healthCheckService.bootstrapHealthCheck(); - - } -} diff --git a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/EnableHealthCheckServiceConfigurerOnInstance.java b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/EnableHealthCheckServiceConfigurerOnInstance.java deleted file mode 100644 index cafde5cc9ad..00000000000 --- a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/EnableHealthCheckServiceConfigurerOnInstance.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - - - Copyright (c) 2016 C2B2 Consulting Limited. All rights reserved. - - - The contents of this file are subject to the terms of the Common Development - and Distribution License("CDDL") (collectively, the "License"). You - may not use this file except in compliance with the License. You can - obtain a copy of the License at - https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html - or packager/legal/LICENSE.txt. See the License for the specific - language governing permissions and limitations under the License. - - When distributing the software, include this License Header Notice in each - file and include the License file at packager/legal/LICENSE.txt. - */ -package fish.payara.nucleus.healthcheck.admin; - -import com.sun.enterprise.util.LocalStringManagerImpl; -import fish.payara.nucleus.healthcheck.HealthCheckExecutionOptions; -import fish.payara.nucleus.healthcheck.HealthCheckService; -import fish.payara.nucleus.healthcheck.configuration.Checker; -import fish.payara.nucleus.healthcheck.preliminary.BaseHealthCheck; -import java.util.Properties; -import java.util.concurrent.TimeUnit; -import javax.inject.Inject; -import org.glassfish.api.ActionReport; -import org.glassfish.api.I18n; -import org.glassfish.api.Param; -import org.glassfish.api.admin.AdminCommand; -import org.glassfish.api.admin.AdminCommandContext; -import org.glassfish.api.admin.CommandLock; -import org.glassfish.api.admin.ExecuteOn; -import org.glassfish.api.admin.RuntimeType; -import org.glassfish.config.support.CommandTarget; -import org.glassfish.config.support.TargetType; -import org.glassfish.hk2.api.PerLookup; -import org.glassfish.hk2.api.ServiceLocator; -import org.jvnet.hk2.annotations.Service; - -/** - * - * @author Susan Rai - */ -@Service(name = "__enable-healthcheck-configure-service-on-instance") -@PerLookup -@CommandLock(CommandLock.LockType.NONE) -@I18n("__enable-healthcheck-configure-service-on-instance") -@ExecuteOn(RuntimeType.INSTANCE) -@TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG}) -public class EnableHealthCheckServiceConfigurerOnInstance implements AdminCommand { - - final private static LocalStringManagerImpl strings = new LocalStringManagerImpl(HealthCheckServiceConfigurer.class); - - @Inject - HealthCheckService healthCheckService; - - @Inject - ServiceLocator habitat; - - @Param(name = "target", optional = true, defaultValue = "server") - protected String target; - - @Param(name = "enabled", optional = false) - private Boolean enabled; - - @Param(name = "time", optional = true) - private String time; - - @Param(name = "unit", optional = true) - private String unit; - - @Param(name = "serviceName", optional = false) - private String serviceName; - - @Override - public void execute(AdminCommandContext context) { - final ActionReport actionReport = context.getActionReport(); - Properties extraProperties = actionReport.getExtraProperties(); - if (extraProperties == null) { - extraProperties = new Properties(); - actionReport.setExtraProperties(extraProperties); - } - - BaseHealthCheck service = habitat.getService(BaseHealthCheck.class, serviceName); - Checker checkerByType = healthCheckService.getConfiguration().getCheckerByType(service.getCheckerType()); - if (service.getOptions() == null) { - if (checkerByType == null) { - actionReport.appendMessage("Enabling a new Healthcheck requires a server restart.."); - return; - } else { - service.setOptions(service.constructOptions(checkerByType)); - } - } - - if (enabled != null) { - service.getOptions().setEnabled(enabled); - } - if (time != null) { - service.getOptions().setTime(Long.valueOf(time)); - } - if (unit != null) { - service.getOptions().setUnit(TimeUnit.valueOf(unit)); - } - - actionReport.appendMessage(strings.getLocalString("healthcheck.service.configure.status.success", - "Service status for {0} is set to {1}.", serviceName, enabled)); - healthCheckService.registerCheck(checkerByType.getName(), service); - healthCheckService.shutdownHealthCheck(); - healthCheckService.bootstrapHealthCheck(); - - } -} diff --git a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/GetHealthCheckConfiguration.java b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/GetHealthCheckConfiguration.java index 5f0d7e34f11..fafdebe2c06 100644 --- a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/GetHealthCheckConfiguration.java +++ b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/GetHealthCheckConfiguration.java @@ -1,9 +1,8 @@ /* - DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - - Copyright (c) 2016 C2B2 Consulting Limited. All rights reserved. + DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + Copyright (c) 2014 C2B2 Consulting Limited. All rights reserved. The contents of this file are subject to the terms of the Common Development and Distribution License("CDDL") (collectively, the "License"). You @@ -52,7 +51,7 @@ and Distribution License("CDDL") (collectively, the "License"). You @CommandLock(CommandLock.LockType.NONE) @I18n("get.healthcheck.configuration") @ExecuteOn(value = {RuntimeType.DAS}) -@TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CONFIG}) +@TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER}) @RestEndpoints({ @RestEndpoint(configBean = Domain.class, opType = RestEndpoint.OpType.GET, diff --git a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/HealthCheckConfigurer.java b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/HealthCheckConfigurer.java index abb515a187a..0f3c1b25d59 100644 --- a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/HealthCheckConfigurer.java +++ b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/HealthCheckConfigurer.java @@ -1,9 +1,8 @@ /* - DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - - Copyright (c) 2016 C2B2 Consulting Limited. All rights reserved. + DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + Copyright (c) 2014 C2B2 Consulting Limited. All rights reserved. The contents of this file are subject to the terms of the Common Development and Distribution License("CDDL") (collectively, the "License"). You @@ -21,9 +20,9 @@ and Distribution License("CDDL") (collectively, the "License"). You import com.sun.enterprise.config.serverbeans.Config; import com.sun.enterprise.config.serverbeans.Domain; import com.sun.enterprise.util.LocalStringManagerImpl; +import com.sun.enterprise.util.SystemPropertyConstants; import fish.payara.nucleus.healthcheck.HealthCheckService; import fish.payara.nucleus.healthcheck.configuration.HealthCheckServiceConfiguration; -import fish.payara.nucleus.notification.configuration.Notifier; import org.glassfish.api.ActionReport; import org.glassfish.api.I18n; import org.glassfish.api.Param; @@ -40,14 +39,12 @@ and Distribution License("CDDL") (collectively, the "License"). You import javax.inject.Inject; import java.beans.PropertyVetoException; -import java.util.List; -import java.util.Properties; import java.util.logging.Level; import java.util.logging.Logger; + /** - * Admin command to enable/disable all health check services defined in - * domain.xml. + * Admin command to enable/disable all health check services defined in domain.xml. * * @author mertcaliskan */ @@ -55,7 +52,7 @@ and Distribution License("CDDL") (collectively, the "License"). You @PerLookup @CommandLock(CommandLock.LockType.NONE) @I18n("healthcheck.configure") -@ExecuteOn(RuntimeType.DAS) +@ExecuteOn(RuntimeType.INSTANCE) @TargetType({CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG}) @RestEndpoints({ @RestEndpoint(configBean = Domain.class, @@ -92,12 +89,6 @@ public class HealthCheckConfigurer implements AdminCommand { 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 HealthCheckServiceConfiguration healthCheckServiceConfiguration = config.getExtensionByType(HealthCheckServiceConfiguration.class); if (healthCheckServiceConfiguration != null) { @@ -108,13 +99,14 @@ public Object run(final HealthCheckServiceConfiguration healthCheckServiceConfig PropertyVetoException, TransactionFailure { if (enabled != null) { healthCheckServiceConfigurationProxy.enabled(enabled.toString()); - } + } actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS); return healthCheckServiceConfigurationProxy; } }, healthCheckServiceConfiguration); - } catch (TransactionFailure ex) { + } + catch(TransactionFailure ex){ logger.log(Level.WARNING, "Exception during command ", ex); actionReport.setMessage(ex.getCause().getMessage()); actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE); @@ -128,25 +120,8 @@ public Object run(final HealthCheckServiceConfiguration healthCheckServiceConfig } private void enableOnTarget(ActionReport actionReport, AdminCommandContext context, Boolean enabled) { - CommandRunner runner = serviceLocator.getService(CommandRunner.class); - ActionReport subReport = context.getActionReport().addSubActionsReport(); - CommandRunner.CommandInvocation inv; - - if (target.equals("server-config")) { - inv = runner.getCommandInvocation("__enable-healthcheck-configurer-on-das", subReport, context.getSubject()); - } else { - inv = runner.getCommandInvocation("__enable-healthcheck-configurer-on-instance", subReport, context.getSubject()); - } - - ParameterMap params = new ParameterMap(); - params.add("enabled", enabled.toString()); - params.add("target", target); - inv.parameters(params); - inv.execute(); - // swallow the offline warning as it is not a problem - if (subReport.hasWarnings()) { - subReport.setMessage(""); - } - + service.setEnabled(enabled); + actionReport.appendMessage(strings.getLocalString("healthcheck.configure.status.success", + "Health Check Service status is set to {0}.", enabled)); } } diff --git a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/HealthCheckServiceConfigurer.java b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/HealthCheckServiceConfigurer.java index 9e5cfd16a92..c5a6a5b99a2 100644 --- a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/HealthCheckServiceConfigurer.java +++ b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/HealthCheckServiceConfigurer.java @@ -1,9 +1,8 @@ /* - DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - - Copyright (c) 2016 C2B2 Consulting Limited. All rights reserved. + DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + Copyright (c) 2014 C2B2 Consulting Limited. All rights reserved. The contents of this file are subject to the terms of the Common Development and Distribution License("CDDL") (collectively, the "License"). You @@ -21,6 +20,7 @@ and Distribution License("CDDL") (collectively, the "License"). You import com.sun.enterprise.config.serverbeans.Config; import com.sun.enterprise.config.serverbeans.Domain; import com.sun.enterprise.util.LocalStringManagerImpl; +import com.sun.enterprise.util.SystemPropertyConstants; import fish.payara.nucleus.healthcheck.HealthCheckService; import fish.payara.nucleus.healthcheck.configuration.Checker; import fish.payara.nucleus.healthcheck.configuration.HealthCheckServiceConfiguration; @@ -39,14 +39,12 @@ and Distribution License("CDDL") (collectively, the "License"). You import javax.inject.Inject; import java.beans.PropertyVetoException; -import java.util.Properties; import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; /** - * Admin command to enable/disable specific health check service given with its - * name + * Admin command to enable/disable specific health check service given with its name * * @author mertcaliskan */ @@ -54,17 +52,18 @@ and Distribution License("CDDL") (collectively, the "License"). You @PerLookup @CommandLock(CommandLock.LockType.NONE) @I18n("healthcheck.configure.service") -@ExecuteOn(RuntimeType.DAS) +@ExecuteOn(RuntimeType.INSTANCE) @TargetType({CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG}) @RestEndpoints({ - @RestEndpoint(configBean = Domain.class, - opType = RestEndpoint.OpType.GET, - path = "healthcheck-configure-service", - description = "Enables/Disables Health Check Service Specified With Name") + @RestEndpoint(configBean = Domain.class, + opType = RestEndpoint.OpType.GET, + path = "healthcheck-configure-service", + description = "Enables/Disables Health Check Service Specified With Name") }) public class HealthCheckServiceConfigurer implements AdminCommand { - final private static LocalStringManagerImpl strings = new LocalStringManagerImpl(HealthCheckServiceConfigurer.class); + final private static LocalStringManagerImpl strings = new LocalStringManagerImpl(HealthCheckServiceConfigurer + .class); @Inject ServiceLocator habitat; @@ -102,13 +101,6 @@ public class HealthCheckServiceConfigurer implements AdminCommand { @Override public void execute(AdminCommandContext context) { final ActionReport actionReport = context.getActionReport(); - final AdminCommandContext theContext = context; - Properties extraProperties = actionReport.getExtraProperties(); - if (extraProperties == null) { - extraProperties = new Properties(); - actionReport.setExtraProperties(extraProperties); - } - Config config = targetUtil.getConfig(target); final BaseHealthCheck service = habitat.getService(BaseHealthCheck.class, serviceName); @@ -152,7 +144,7 @@ public Object run(final Checker checkerProxy) throws } if (dynamic) { - enableOnTarget(actionReport, theContext, service, createdChecker[0], enabled, time, unit); + enableOnTarget(actionReport, service, createdChecker[0], enabled, time, unit); } } catch (TransactionFailure ex) { @@ -177,28 +169,26 @@ private void applyValues(Checker checkerProxy) throws PropertyVetoException { } } - private void enableOnTarget(ActionReport actionReport, AdminCommandContext context, BaseHealthCheck service, Checker checker, Boolean enabled, String time, String unit) { - CommandRunner runner = habitat.getService(CommandRunner.class); - ActionReport subReport = context.getActionReport().addSubActionsReport(); - CommandRunner.CommandInvocation inv; - - if (target.equals("server-config")) { - inv = runner.getCommandInvocation("__enable-healthcheck-configure-service-on-das", subReport, context.getSubject()); - } else { - inv = runner.getCommandInvocation("__enable-healthcheck-configure-service-on-instance", subReport, context.getSubject()); + private void enableOnTarget(ActionReport actionReport, BaseHealthCheck service, Checker checker, Boolean enabled, String time, String unit) { + if (service.getOptions() == null) { + service.setOptions(service.constructOptions(checker)); + healthCheckService.registerCheck(checker.getName(), service); } - ParameterMap params = new ParameterMap(); - params.add("enabled", enabled.toString()); - params.add("target", target); - params.add("time", time); - params.add("unit", unit); - params.add("serviceName", serviceName); - inv.parameters(params); - inv.execute(); - // swallow the offline warning as it is not a problem - if (subReport.hasWarnings()) { - subReport.setMessage(""); + if (enabled != null) { + service.getOptions().setEnabled(enabled); } + if (time != null) { + service.getOptions().setTime(Long.valueOf(time)); + } + if (unit != null) { + service.getOptions().setUnit(TimeUnit.valueOf(unit)); + } + + actionReport.appendMessage(strings.getLocalString("healthcheck.service.configure.status.success", + "Service status for {0} is set to {1}.", serviceName, enabled)); + + healthCheckService.shutdownHealthCheck(); + healthCheckService.bootstrapHealthCheck(); } } diff --git a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/HealthCheckServiceLister.java b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/HealthCheckServiceLister.java index 9d21f688bde..29bd5a4319e 100644 --- a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/HealthCheckServiceLister.java +++ b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/HealthCheckServiceLister.java @@ -1,9 +1,8 @@ /* - DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - - Copyright (c) 2016 C2B2 Consulting Limited. All rights reserved. + DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + Copyright (c) 2014 C2B2 Consulting Limited. All rights reserved. The contents of this file are subject to the terms of the Common Development and Distribution License("CDDL") (collectively, the "License"). You diff --git a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/HealthCheckServiceThresholdConfigurer.java b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/HealthCheckServiceThresholdConfigurer.java index fef7dc00a5f..79dc13118b5 100644 --- a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/HealthCheckServiceThresholdConfigurer.java +++ b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/HealthCheckServiceThresholdConfigurer.java @@ -1,9 +1,8 @@ /* - DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - - Copyright (c) 2016 C2B2 Consulting Limited. All rights reserved. + DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + Copyright (c) 2014 C2B2 Consulting Limited. All rights reserved. The contents of this file are subject to the terms of the Common Development and Distribution License("CDDL") (collectively, the "License"). You @@ -45,7 +44,6 @@ and Distribution License("CDDL") (collectively, the "License"). You import javax.inject.Inject; import java.beans.PropertyVetoException; -import java.util.Properties; import java.util.logging.Level; import java.util.logging.Logger; @@ -58,7 +56,7 @@ and Distribution License("CDDL") (collectively, the "License"). You @PerLookup @CommandLock(CommandLock.LockType.NONE) @I18n("healthcheck.configure.service.threshold") -@ExecuteOn(RuntimeType.DAS) +@ExecuteOn(RuntimeType.INSTANCE) @TargetType({CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG}) @RestEndpoints({ @RestEndpoint(configBean = Domain.class, @@ -100,20 +98,10 @@ public class HealthCheckServiceThresholdConfigurer implements AdminCommand { @Param(name = "target", optional = true, defaultValue = "server") protected String target; - - @Inject - ServiceLocator serviceLocator; @Override public void execute(AdminCommandContext context) { final ActionReport actionReport = context.getActionReport(); - final AdminCommandContext theContext = context; - Properties extraProperties = actionReport.getExtraProperties(); - if (extraProperties == null) { - extraProperties = new Properties(); - actionReport.setExtraProperties(extraProperties); - } - final BaseThresholdHealthCheck service = habitat.getService(BaseThresholdHealthCheck.class, serviceName); Config config = targetUtil.getConfig(target); @@ -149,7 +137,7 @@ public void execute(AdminCommandContext context) { } if (dynamic) { - enableOnTarget(actionReport, theContext, service, thresholdCritical, thresholdWarning, thresholdGood); + enableOnTarget(actionReport, service, thresholdCritical, thresholdWarning, thresholdGood); } } @@ -188,30 +176,30 @@ private void applyThreshold(Property propertyProxy, String name, String value) t } } - private void enableOnTarget(ActionReport actionReport, AdminCommandContext context, BaseThresholdHealthCheck service, String + private void enableOnTarget(ActionReport actionReport, BaseThresholdHealthCheck service, String thresholdCritical, String thresholdWarning, String thresholdGood) { - - CommandRunner runner = serviceLocator.getService(CommandRunner.class); - ActionReport subReport = context.getActionReport().addSubActionsReport(); - CommandRunner.CommandInvocation inv; - - if (target.equals("server-config")) { - inv = runner.getCommandInvocation("__edit-healthcheck-configure-service-threshold-on-das", subReport, context.getSubject()); - } else { - inv = runner.getCommandInvocation("__edit-healthcheck-configure-service-threshold-on-instance", subReport, context.getSubject()); - } - ParameterMap params = new ParameterMap(); - params.add("target", target); - params.add("serviceName", serviceName); - params.add("thresholdCritical", thresholdCritical); - params.add("thresholdWarning", thresholdWarning); - params.add("thresholdGood", thresholdGood); - inv.parameters(params); - inv.execute(); - // swallow the offline warning as it is not a problem - if (subReport.hasWarnings()) { - subReport.setMessage(""); + if (thresholdCritical != null) { + service.getOptions().setThresholdCritical(Integer.valueOf(thresholdCritical)); + actionReport.appendMessage(strings.getLocalString( + "healthcheck.service.configure.threshold.critical.success", + "Critical threshold for {0} service is set with value {1}.", serviceName, thresholdCritical)); + actionReport.appendMessage("\n"); + } + if (thresholdWarning != null) { + service.getOptions().setThresholdWarning(Integer.valueOf(thresholdWarning)); + actionReport.appendMessage(strings.getLocalString("healthcheck.service.configure.threshold.warning.success", + "Warning threshold for {0} service is set with value {1}.", serviceName, thresholdWarning)); + actionReport.appendMessage("\n"); } + if (thresholdGood != null) { + service.getOptions().setThresholdGood(Integer.valueOf(thresholdGood)); + actionReport.appendMessage(strings.getLocalString("healthcheck.service.configure.threshold.good.success", + "Good threshold for {0} service is set with value {1}.", serviceName, thresholdGood)); + actionReport.appendMessage("\n"); + } + + healthCheckService.shutdownHealthCheck(); + healthCheckService.bootstrapHealthCheck(); } } diff --git a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/preliminary/BaseHealthCheck.java b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/preliminary/BaseHealthCheck.java index f69a9336021..95b8060ca84 100644 --- a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/preliminary/BaseHealthCheck.java +++ b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/preliminary/BaseHealthCheck.java @@ -134,11 +134,16 @@ public Class getCheckerType() { } public void sendNotification(Level level, String message, Object[] parameters) { - - LogNotificationEvent notificationEvent = new LogNotificationEvent(); - notificationEvent.setLevel(level); - notificationEvent.setMessage(message); - notificationEvent.setParameters(parameters); - notificationService.notify(notificationEvent); + List notifierList = configuration.getNotifierList(); + for (Notifier notifier : notifierList) { + if (notifier instanceof LogNotifier) { + LogNotificationEvent notificationEvent = new LogNotificationEvent(); + notificationEvent.setLevel(level); + notificationEvent.setMessage(message); + notificationEvent.setParameters(parameters); + + notificationService.notify(notificationEvent); + } + } } } diff --git a/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/EnableNotificationConfigurerOnInstance.java b/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/EnableNotificationConfigurerOnInstance.java deleted file mode 100644 index 65d2ad49870..00000000000 --- a/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/EnableNotificationConfigurerOnInstance.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - - DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - - Copyright (c) 2016 C2B2 Consulting Limited. All rights reserved. - - The contents of this file are subject to the terms of the Common Development - and Distribution License("CDDL") (collectively, the "License"). You - may not use this file except in compliance with the License. You can - obtain a copy of the License at - https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html - or packager/legal/LICENSE.txt. See the License for the specific - language governing permissions and limitations under the License. - - When distributing the software, include this License Header Notice in each - file and include the License file at packager/legal/LICENSE.txt. - */ -package fish.payara.nucleus.notification.admin; - -import com.sun.enterprise.config.serverbeans.Domain; -import com.sun.enterprise.util.LocalStringManagerImpl; -import com.sun.enterprise.util.SystemPropertyConstants; -import fish.payara.nucleus.notification.NotificationService; -import org.glassfish.api.ActionReport; -import org.glassfish.api.I18n; -import org.glassfish.api.Param; -import org.glassfish.api.admin.*; -import org.glassfish.config.support.CommandTarget; -import org.glassfish.config.support.TargetType; -import org.glassfish.hk2.api.PerLookup; -import org.glassfish.internal.api.Target; -import org.jvnet.hk2.annotations.Service; - -import javax.inject.Inject; -import java.util.Properties; -import java.util.logging.Logger; - - -/** - * - * @author Susan Rai - */ -@Service(name = "__enable-notification-configure-instance") -@PerLookup -@CommandLock(CommandLock.LockType.NONE) -@I18n("__enable-notification-configure-instance") -@ExecuteOn({RuntimeType.INSTANCE}) -@TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG}) -public class EnableNotificationConfigurerOnInstance implements AdminCommand { - - final private static LocalStringManagerImpl strings = new LocalStringManagerImpl(EnableNotificationConfigurerOnInstance.class); - - @Inject - NotificationService service; - - @Inject - protected Logger logger; - - @Inject - protected Target targetUtil; - - @Param(name = "target", optional = true, defaultValue = SystemPropertyConstants.DAS_SERVER_NAME) - String target; - - @Param(name = "enabled", optional = false) - private Boolean enabled; - - @Override - public void execute(AdminCommandContext context) { - final ActionReport actionReport = context.getActionReport(); - Properties extraProperties = actionReport.getExtraProperties(); - if (extraProperties == null) { - extraProperties = new Properties(); - actionReport.setExtraProperties(extraProperties); - } - - if (enabled != null) { - service.getExecutionOptions().setEnabled(enabled); - actionReport.appendMessage(strings.getLocalString("notification.configure.status.success", - "Notification service status is set to {0}.", enabled) + "\n"); - } - } -} diff --git a/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/NotificationConfigurer.java b/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/NotificationConfigurer.java index c712782502b..1e4fdb170f8 100644 --- a/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/NotificationConfigurer.java +++ b/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/NotificationConfigurer.java @@ -41,7 +41,6 @@ and Distribution License("CDDL") (collectively, the "License"). You import java.util.Properties; import java.util.logging.Level; import java.util.logging.Logger; -import org.glassfish.hk2.api.ServiceLocator; /** @@ -54,7 +53,7 @@ and Distribution License("CDDL") (collectively, the "License"). You @PerLookup @CommandLock(CommandLock.LockType.NONE) @I18n("notification.configure") -@ExecuteOn({RuntimeType.DAS}) +@ExecuteOn({RuntimeType.INSTANCE}) @TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG}) @RestEndpoints({ @RestEndpoint(configBean = Domain.class, @@ -84,11 +83,6 @@ public class NotificationConfigurer implements AdminCommand { @Param(name = "enabled", optional = false) private Boolean enabled; - @Inject - ServiceLocator serviceLocator; - - CommandRunner.CommandInvocation inv; - @Override public void execute(AdminCommandContext context) { final ActionReport actionReport = context.getActionReport(); @@ -129,24 +123,10 @@ public Object run(final NotificationServiceConfiguration notificationServiceConf } private void enableOnTarget(ActionReport actionReport, AdminCommandContext context, Boolean enabled) { - - CommandRunner runner = serviceLocator.getService(CommandRunner.class); - ActionReport subReport = context.getActionReport().addSubActionsReport(); - - if (target.equals("server-config")) { - inv = runner.getCommandInvocation("__enable-notification-configure-das", subReport, context.getSubject()); - } else { - inv = runner.getCommandInvocation("__enable-notification-configure-instance", subReport, context.getSubject()); - } - - ParameterMap params = new ParameterMap(); - params.add("enabled", enabled.toString()); - params.add("target", target); - inv.parameters(params); - inv.execute(); - // swallow the offline warning as it is not a problem - if (subReport.hasWarnings()) { - subReport.setMessage(""); + if (enabled != null) { + service.getExecutionOptions().setEnabled(enabled); + actionReport.appendMessage(strings.getLocalString("notification.configure.status.success", + "Notification service status is set to {0}.", enabled) + "\n"); } } } diff --git a/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/EnableNotificationConfigurerOnDas.java b/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/NotificationConfigurerDas.java similarity index 52% rename from nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/EnableNotificationConfigurerOnDas.java rename to nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/NotificationConfigurerDas.java index 6111986cc66..b16021015de 100644 --- a/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/EnableNotificationConfigurerOnDas.java +++ b/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/NotificationConfigurerDas.java @@ -17,10 +17,12 @@ and Distribution License("CDDL") (collectively, the "License"). You */ package fish.payara.nucleus.notification.admin; +import com.sun.enterprise.config.serverbeans.Config; import com.sun.enterprise.config.serverbeans.Domain; import com.sun.enterprise.util.LocalStringManagerImpl; import com.sun.enterprise.util.SystemPropertyConstants; import fish.payara.nucleus.notification.NotificationService; +import fish.payara.nucleus.notification.configuration.NotificationServiceConfiguration; import org.glassfish.api.ActionReport; import org.glassfish.api.I18n; import org.glassfish.api.Param; @@ -30,25 +32,38 @@ and Distribution License("CDDL") (collectively, the "License"). You import org.glassfish.hk2.api.PerLookup; import org.glassfish.internal.api.Target; import org.jvnet.hk2.annotations.Service; +import org.jvnet.hk2.config.ConfigSupport; +import org.jvnet.hk2.config.SingleConfigCode; +import org.jvnet.hk2.config.TransactionFailure; import javax.inject.Inject; +import java.beans.PropertyVetoException; import java.util.Properties; +import java.util.logging.Level; import java.util.logging.Logger; /** + * Admin command to enable/disable all notification services defined in + * domain.xml. * - * @author Susan Rai + * @author mertcaliskan */ -@Service(name = "__enable-notification-configure-das") +@Service(name = "notification-configure-das") @PerLookup @CommandLock(CommandLock.LockType.NONE) -@I18n("__enable-notification-configure-das") +@I18n("notification.configure.das") @ExecuteOn({RuntimeType.DAS}) @TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG}) -public class EnableNotificationConfigurerOnDas implements AdminCommand { +@RestEndpoints({ + @RestEndpoint(configBean = Domain.class, + opType = RestEndpoint.OpType.POST, + path = "notification-configure-das", + description = "Enables/Disables Notification Service") +}) +public class NotificationConfigurerDas implements AdminCommand { - final private static LocalStringManagerImpl strings = new LocalStringManagerImpl(EnableNotificationConfigurerOnDas.class); + final private static LocalStringManagerImpl strings = new LocalStringManagerImpl(NotificationConfigurerDas.class); @Inject NotificationService service; @@ -58,7 +73,10 @@ public class EnableNotificationConfigurerOnDas implements AdminCommand { @Inject protected Target targetUtil; - + + @Param(name = "dynamic", optional = true, defaultValue = "false") + protected Boolean dynamic; + @Param(name = "target", optional = true, defaultValue = SystemPropertyConstants.DAS_SERVER_NAME) String target; @@ -74,6 +92,37 @@ public void execute(AdminCommandContext context) { actionReport.setExtraProperties(extraProperties); } + Config config = targetUtil.getConfig(target); + final NotificationServiceConfiguration notificationServiceConfiguration = config.getExtensionByType(NotificationServiceConfiguration.class); + + if (notificationServiceConfiguration != null) { + try { + ConfigSupport.apply(new SingleConfigCode() { + @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) { + enableOnTarget(actionReport, context, enabled); + } + } + + private void enableOnTarget(ActionReport actionReport, AdminCommandContext context, Boolean enabled) { if (enabled != null) { service.getExecutionOptions().setEnabled(enabled); actionReport.appendMessage(strings.getLocalString("notification.configure.status.success", diff --git a/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/NotificationNotifierConfigurer.java b/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/NotificationNotifierConfigurer.java index 6e514468ea1..6016c96a967 100644 --- a/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/NotificationNotifierConfigurer.java +++ b/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/NotificationNotifierConfigurer.java @@ -49,12 +49,13 @@ and Distribution License("CDDL") (collectively, the "License"). You import java.util.logging.Level; import java.util.logging.Logger; + /** * Admin command to enable/disable specific notifier given with its name * * @author mertcaliskan */ -@ExecuteOn({RuntimeType.DAS}) +@ExecuteOn({RuntimeType.INSTANCE}) @TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG}) @Service(name = "notification-configure-notifier") @CommandLock(CommandLock.LockType.NONE) @@ -100,13 +101,9 @@ public class NotificationNotifierConfigurer implements AdminCommand { @Param(name = "notifierEnabled", optional = false) private Boolean notifierEnabled; - @Inject - ServiceLocator serviceLocator; - @Override public void execute(AdminCommandContext context) { final ActionReport actionReport = context.getActionReport(); - final AdminCommandContext theContext = context; Properties extraProperties = actionReport.getExtraProperties(); if (extraProperties == null) { extraProperties = new Properties(); @@ -137,6 +134,24 @@ public Object run(final NotificationServiceConfiguration notificationServiceConf if (notifierEnabled != null) { notifierProxy.enabled(notifierEnabled); } + createdNotifier[0] = notifierProxy; + + List notifierConfigList = notificationServiceConfigurationProxy.getNotifierConfigurationList(); + NotifierConfigurationExecutionOptions executionOptions = factory.build(createdNotifier[0]); + if (notifierEnabled) { + notifierConfigList.add(createdNotifier[0]); + if (dynamic) { + service.getExecutionOptions().addNotifierConfigurationExecutionOption(executionOptions); + eventBus.register(notifierService); + } + } else { + notifierConfigList.remove(createdNotifier[0]); + if (dynamic) { + service.getExecutionOptions().removeNotifierConfigurationExecutionOption(executionOptions); + eventBus.unregister(notifierService); + } + } + actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS); return notificationServiceConfigurationProxy; } @@ -149,16 +164,24 @@ public Object run(final NotifierConfiguration notifierProxy) throws if (notifierEnabled != null) { notifierProxy.enabled(notifierEnabled); } + + if (dynamic) { + NotifierConfigurationExecutionOptions executionOptions = factory.build(notifierProxy); + if (notifierEnabled) { + service.getExecutionOptions().addNotifierConfigurationExecutionOption(executionOptions); + eventBus.register(notifierService); + } else { + service.getExecutionOptions().removeNotifierConfigurationExecutionOption(executionOptions); + eventBus.unregister(notifierService); + } + } + actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS); return notifierProxy; } }, notifier); } - - if (dynamic) { - enableOnTarget(actionReport, theContext, notifierEnabled); - } actionReport.appendMessage(strings.getLocalString("notification.configure.notifier.added.configured", "Notifier with name {0} is registered and set enabled to {1}.", notifierName, notifierEnabled) + "\n"); @@ -168,28 +191,4 @@ public Object run(final NotifierConfiguration notifierProxy) throws actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE); } } - - private void enableOnTarget(ActionReport actionReport, AdminCommandContext context, Boolean enabled) { - CommandRunner runner = serviceLocator.getService(CommandRunner.class); - ActionReport subReport = context.getActionReport().addSubActionsReport(); - CommandRunner.CommandInvocation inv; - - if (target.equals("server-config")) { - inv = runner.getCommandInvocation("__enable-notification-configure-notifier-das", subReport, context.getSubject()); - } else { - inv = runner.getCommandInvocation("__enable-notification-configure-notifier-instance", subReport, context.getSubject()); - } - - ParameterMap params = new ParameterMap(); - params.add("notifierEnabled", enabled.toString()); - params.add("target", target); - params.add("notifierName", notifierName); - inv.parameters(params); - inv.execute(); - // swallow the offline warning as it is not a problem - if (subReport.hasWarnings()) { - subReport.setMessage(""); - } - - } } diff --git a/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/EnableNotificationNotifierConfigurerOnDas.java b/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/NotificationNotifierConfigurerDas.java similarity index 76% rename from nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/EnableNotificationNotifierConfigurerOnDas.java rename to nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/NotificationNotifierConfigurerDas.java index 3242a1a7348..3255eebf15b 100644 --- a/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/EnableNotificationNotifierConfigurerOnDas.java +++ b/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/NotificationNotifierConfigurerDas.java @@ -49,19 +49,27 @@ and Distribution License("CDDL") (collectively, the "License"). You import java.util.logging.Level; import java.util.logging.Logger; + /** + * Admin command to enable/disable specific notifier given with its name * - * @author Susan Rai + * @author mertcaliskan */ @ExecuteOn({RuntimeType.DAS}) @TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG}) -@Service(name = "__enable-notification-configure-notifier-das") +@Service(name = "notification-configure-notifier-das") @CommandLock(CommandLock.LockType.NONE) @PerLookup -@I18n("__enable-notification-configure-notifier-das") -public class EnableNotificationNotifierConfigurerOnDas implements AdminCommand { +@I18n("notification.configure.notifier.das") +@RestEndpoints({ + @RestEndpoint(configBean = Domain.class, + opType = RestEndpoint.OpType.POST, + path = "notification-configure-notifier-das", + description = "Enables/Disables Notifier Specified With Name") +}) +public class NotificationNotifierConfigurerDas implements AdminCommand { - final private static LocalStringManagerImpl strings = new LocalStringManagerImpl(EnableNotificationNotifierConfigurerOnDas.class); + final private static LocalStringManagerImpl strings = new LocalStringManagerImpl(NotificationNotifierConfigurerDas.class); @Inject NotificationService service; @@ -81,6 +89,9 @@ public class EnableNotificationNotifierConfigurerOnDas implements AdminCommand { @Inject private NotificationEventBus eventBus; + @Param(name = "dynamic", optional = true, defaultValue = "false") + protected Boolean dynamic; + @Param(name = "target", optional = true, defaultValue = SystemPropertyConstants.DAS_SERVER_NAME) String target; @@ -120,18 +131,25 @@ public void execute(AdminCommandContext context) { public Object run(final NotificationServiceConfiguration notificationServiceConfigurationProxy) throws PropertyVetoException, TransactionFailure { NotifierConfiguration notifierProxy = (NotifierConfiguration) notificationServiceConfigurationProxy.createChild(notifierService.getNotifierConfigType()); + if (notifierEnabled != null) { + notifierProxy.enabled(notifierEnabled); + } createdNotifier[0] = notifierProxy; List notifierConfigList = notificationServiceConfigurationProxy.getNotifierConfigurationList(); NotifierConfigurationExecutionOptions executionOptions = factory.build(createdNotifier[0]); if (notifierEnabled) { notifierConfigList.add(createdNotifier[0]); - service.getExecutionOptions().addNotifierConfigurationExecutionOption(executionOptions); - eventBus.register(notifierService); + if (dynamic) { + service.getExecutionOptions().addNotifierConfigurationExecutionOption(executionOptions); + eventBus.register(notifierService); + } } else { notifierConfigList.remove(createdNotifier[0]); - service.getExecutionOptions().removeNotifierConfigurationExecutionOption(executionOptions); - eventBus.unregister(notifierService); + if (dynamic) { + service.getExecutionOptions().removeNotifierConfigurationExecutionOption(executionOptions); + eventBus.unregister(notifierService); + } } actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS); @@ -143,13 +161,19 @@ public Object run(final NotificationServiceConfiguration notificationServiceConf @Override public Object run(final NotifierConfiguration notifierProxy) throws PropertyVetoException, TransactionFailure { - NotifierConfigurationExecutionOptions executionOptions = factory.build(notifierProxy); - if (notifierEnabled) { - service.getExecutionOptions().addNotifierConfigurationExecutionOption(executionOptions); - eventBus.register(notifierService); - } else { - service.getExecutionOptions().removeNotifierConfigurationExecutionOption(executionOptions); - eventBus.unregister(notifierService); + if (notifierEnabled != null) { + notifierProxy.enabled(notifierEnabled); + } + + if (dynamic) { + NotifierConfigurationExecutionOptions executionOptions = factory.build(notifierProxy); + if (notifierEnabled) { + service.getExecutionOptions().addNotifierConfigurationExecutionOption(executionOptions); + eventBus.register(notifierService); + } else { + service.getExecutionOptions().removeNotifierConfigurationExecutionOption(executionOptions); + eventBus.unregister(notifierService); + } } actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS); diff --git a/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/SetNotificationConfiguration.java b/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/SetNotification.java similarity index 86% rename from nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/SetNotificationConfiguration.java rename to nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/SetNotification.java index e9d27787fe7..d54fe2ce386 100644 --- a/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/SetNotificationConfiguration.java +++ b/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/SetNotification.java @@ -28,7 +28,6 @@ import org.glassfish.hk2.api.PerLookup; import org.glassfish.hk2.api.ServiceLocator; import org.jvnet.hk2.annotations.Service; -import static javax.management.Query.value; /** * Admin command to set notification services configuration @@ -37,17 +36,17 @@ */ @ExecuteOn(value = {RuntimeType.DAS}) @TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG}) -@Service(name = "set-notification-configuration") +@Service(name = "set-notification") @CommandLock(CommandLock.LockType.NONE) @PerLookup -@I18n("set.notification.configuration") +@I18n("set.notification") @RestEndpoints({ @RestEndpoint(configBean = Domain.class, opType = RestEndpoint.OpType.POST, - path = "set-notification-configuration", + path = "set-notification", description = "Set notification Services Configuration") }) -public class SetNotificationConfiguration implements AdminCommand { +public class SetNotification implements AdminCommand { @Param(name = "target", optional = true, defaultValue = SystemPropertyConstants.DAS_SERVER_NAME) String target; @@ -105,7 +104,11 @@ private void enableNotificationConfigureOnTarget(ActionReport actionReport, Admi CommandRunner runner = serviceLocator.getService(CommandRunner.class); ActionReport subReport = context.getActionReport().addSubActionsReport(); - inv = runner.getCommandInvocation("notification-configure", subReport, context.getSubject()); + if (target.equals("server-config")) { + inv = runner.getCommandInvocation("notification-configure-das", subReport, context.getSubject()); + } else { + inv = runner.getCommandInvocation("notification-configure", subReport, context.getSubject()); + } ParameterMap params = new ParameterMap(); params.add("enabled", enabled.toString()); @@ -123,7 +126,11 @@ private void enableNotificationNotifierConfigurerOnTarget(ActionReport actionRep CommandRunner runner = serviceLocator.getService(CommandRunner.class); ActionReport subReport = context.getActionReport().addSubActionsReport(); - inv = runner.getCommandInvocation("notification-configure-notifier", subReport, context.getSubject()); + if (target.equals("server-config")) { + inv = runner.getCommandInvocation("notification-configure-notifier-das", subReport, context.getSubject()); + } else { + inv = runner.getCommandInvocation("notification-configure-notifier", subReport, context.getSubject()); + } ParameterMap params = new ParameterMap(); params.add("dynamic", notifierDynamic.toString()); diff --git a/nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/admin/EnableRequestTracingConfigurerOnDas.java b/nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/admin/EnableRequestTracingConfigurerOnDas.java deleted file mode 100644 index 7dd33a0c7eb..00000000000 --- a/nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/admin/EnableRequestTracingConfigurerOnDas.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - - DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - - Copyright (c) 2016 C2B2 Consulting Limited. All rights reserved. - - The contents of this file are subject to the terms of the Common Development - and Distribution License("CDDL") (collectively, the "License"). You - may not use this file except in compliance with the License. You can - obtain a copy of the License at - https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html - or packager/legal/LICENSE.txt. See the License for the specific - language governing permissions and limitations under the License. - - When distributing the software, include this License Header Notice in each - file and include the License file at packager/legal/LICENSE.txt. - */ -package fish.payara.nucleus.requesttracing.admin; - -import com.sun.enterprise.config.serverbeans.Domain; -import com.sun.enterprise.util.LocalStringManagerImpl; -import com.sun.enterprise.util.SystemPropertyConstants; -import fish.payara.nucleus.notification.configuration.NotifierType; -import fish.payara.nucleus.requesttracing.RequestTracingService; -import fish.payara.nucleus.requesttracing.domain.execoptions.NotifierExecutionOptions; -import java.util.Map; -import org.glassfish.api.ActionReport; -import org.glassfish.api.I18n; -import org.glassfish.api.Param; -import org.glassfish.api.admin.*; -import org.glassfish.config.support.CommandTarget; -import org.glassfish.config.support.TargetType; -import org.glassfish.hk2.api.PerLookup; -import org.jvnet.hk2.annotations.Service; - -import javax.inject.Inject; -import java.util.Properties; -import java.util.concurrent.TimeUnit; - -/** - * - * @author Susan Rai - */ -@ExecuteOn({RuntimeType.DAS}) -@TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG}) -@Service(name = "__enable-requesttracing-configure-das") -@CommandLock(CommandLock.LockType.NONE) -@PerLookup -@I18n("__enable-requesttracing-configure-das") -public class EnableRequestTracingConfigurerOnDas implements AdminCommand { - - final private static LocalStringManagerImpl strings = new LocalStringManagerImpl(EnableRequestTracingConfigurerOnDas.class); - - @Inject - RequestTracingService service; - - @Param(name = "target", optional = true, defaultValue = SystemPropertyConstants.DAS_SERVER_NAME) - String target; - - @Param(name = "enabled", optional = false) - private Boolean enabled; - - @Param(name = "thresholdUnit", optional = true, defaultValue = "SECONDS") - private String unit; - - @Param(name = "thresholdValue", optional = true, defaultValue = "30") - private String value; - - @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 (enabled != null) { - service.getExecutionOptions().setEnabled(enabled); - // also set all notifiers - Map notifierExecutionOptionsList = service.getExecutionOptions().getNotifierExecutionOptionsList(); - if (notifierExecutionOptionsList != null) { - for (Map.Entry entry : notifierExecutionOptionsList.entrySet()) { - NotifierExecutionOptions value1 = entry.getValue(); - value1.setEnabled(enabled); - } - } - actionReport.appendMessage(strings.getLocalString("requesttracing.configure.status.success", - "request tracing service status is set to {0}.", enabled) + "\n"); - } - 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"); - } - } -} - diff --git a/nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/admin/EnableRequestTracingConfigurerOnInstance.java b/nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/admin/EnableRequestTracingConfigurerOnInstance.java deleted file mode 100644 index 8860cf4d860..00000000000 --- a/nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/admin/EnableRequestTracingConfigurerOnInstance.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - - DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - - Copyright (c) 2016 C2B2 Consulting Limited. All rights reserved. - - The contents of this file are subject to the terms of the Common Development - and Distribution License("CDDL") (collectively, the "License"). You - may not use this file except in compliance with the License. You can - obtain a copy of the License at - https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html - or packager/legal/LICENSE.txt. See the License for the specific - language governing permissions and limitations under the License. - - When distributing the software, include this License Header Notice in each - file and include the License file at packager/legal/LICENSE.txt. - */ -package fish.payara.nucleus.requesttracing.admin; - -import com.sun.enterprise.config.serverbeans.Domain; -import com.sun.enterprise.util.LocalStringManagerImpl; -import com.sun.enterprise.util.SystemPropertyConstants; -import fish.payara.nucleus.notification.configuration.NotifierType; -import fish.payara.nucleus.requesttracing.RequestTracingService; -import fish.payara.nucleus.requesttracing.domain.execoptions.NotifierExecutionOptions; -import java.util.Map; -import org.glassfish.api.ActionReport; -import org.glassfish.api.I18n; -import org.glassfish.api.Param; -import org.glassfish.api.admin.*; -import org.glassfish.config.support.CommandTarget; -import org.glassfish.config.support.TargetType; -import org.glassfish.hk2.api.PerLookup; -import org.jvnet.hk2.annotations.Service; - -import javax.inject.Inject; -import java.util.Properties; -import java.util.concurrent.TimeUnit; - -/** - * - * - * @author Susan Rai - */ -@ExecuteOn({RuntimeType.INSTANCE}) -@TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG}) -@Service(name = "__enable-requesttracing-configure-instance") -@CommandLock(CommandLock.LockType.NONE) -@PerLookup -@I18n("__enable-requesttracing-configure-instance") -public class EnableRequestTracingConfigurerOnInstance implements AdminCommand { - - final private static LocalStringManagerImpl strings = new LocalStringManagerImpl(EnableRequestTracingConfigurerOnInstance.class); - - @Inject - RequestTracingService service; - - @Param(name = "target", optional = true, defaultValue = SystemPropertyConstants.DAS_SERVER_NAME) - String target; - - @Param(name = "enabled", optional = false) - private Boolean enabled; - - @Param(name = "thresholdUnit", optional = true, defaultValue = "SECONDS") - private String unit; - - @Param(name = "thresholdValue", optional = true, defaultValue = "30") - private String value; - - @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 (enabled != null) { - service.getExecutionOptions().setEnabled(enabled); - // also set all notifiers - Map notifierExecutionOptionsList = service.getExecutionOptions().getNotifierExecutionOptionsList(); - if (notifierExecutionOptionsList != null) { - for (Map.Entry entry : notifierExecutionOptionsList.entrySet()) { - NotifierExecutionOptions value1 = entry.getValue(); - value1.setEnabled(enabled); - } - } - actionReport.appendMessage(strings.getLocalString("requesttracing.configure.status.success", - "request tracing service status is set to {0}.", enabled) + "\n"); - } - 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"); - } - } -} - diff --git a/nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/admin/EnableRequestTracingNotifierConfigurerOnDas.java b/nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/admin/EnableRequestTracingNotifierConfigurerOnDas.java deleted file mode 100644 index 58914f46680..00000000000 --- a/nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/admin/EnableRequestTracingNotifierConfigurerOnDas.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - - DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - - Copyright (c) 2016 C2B2 Consulting Limited. All rights reserved. - - The contents of this file are subject to the terms of the Common Development - and Distribution License("CDDL") (collectively, the "License"). You - may not use this file except in compliance with the License. You can - obtain a copy of the License at - https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html - or packager/legal/LICENSE.txt. See the License for the specific - language governing permissions and limitations under the License. - - When distributing the software, include this License Header Notice in each - file and include the License file at packager/legal/LICENSE.txt. - */ -package fish.payara.nucleus.requesttracing.admin; - -import com.sun.enterprise.config.serverbeans.Config; -import com.sun.enterprise.config.serverbeans.Domain; -import com.sun.enterprise.util.LocalStringManagerImpl; -import com.sun.enterprise.util.SystemPropertyConstants; -import fish.payara.nucleus.notification.configuration.Notifier; -import fish.payara.nucleus.notification.configuration.NotifierType; -import fish.payara.nucleus.notification.service.BaseNotifierService; -import fish.payara.nucleus.requesttracing.RequestTracingService; -import fish.payara.nucleus.requesttracing.configuration.RequestTracingServiceConfiguration; -import fish.payara.nucleus.requesttracing.domain.execoptions.NotifierExecutionOptions; -import fish.payara.nucleus.requesttracing.domain.execoptions.NotifierExecutionOptionsFactory; -import org.glassfish.api.ActionReport; -import org.glassfish.api.I18n; -import org.glassfish.api.Param; -import org.glassfish.api.admin.*; -import org.glassfish.config.support.CommandTarget; -import org.glassfish.config.support.TargetType; -import org.glassfish.hk2.api.PerLookup; -import org.glassfish.hk2.api.ServiceLocator; -import org.glassfish.internal.api.Target; -import org.jvnet.hk2.annotations.Service; -import org.jvnet.hk2.config.ConfigSupport; -import org.jvnet.hk2.config.SingleConfigCode; -import org.jvnet.hk2.config.TransactionFailure; - -import javax.inject.Inject; -import java.beans.PropertyVetoException; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.logging.Level; -import java.util.logging.Logger; - - -/** - * - * @author Susan Rai - */ -@ExecuteOn({RuntimeType.DAS}) -@TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG}) -@Service(name = "__enable-requesttracing-configure-notifier-das") -@CommandLock(CommandLock.LockType.NONE) -@PerLookup -@I18n("__enable-requesttracing-configure-notifier-das") -public class EnableRequestTracingNotifierConfigurerOnDas implements AdminCommand { - - final private static LocalStringManagerImpl strings = new LocalStringManagerImpl(RequestTracingNotifierConfigurer.class); - - @Inject - RequestTracingService service; - - @Inject - ServiceLocator habitat; - - @Inject - protected Logger logger; - - @Inject - protected Target targetUtil; - - @Param(name = "target", optional = true, defaultValue = SystemPropertyConstants.DAS_SERVER_NAME) - String target; - - @Param(name = "notifierName", optional = true, defaultValue = "service-log") - private String notifierName; - - @Param(name = "notifierEnabled", optional = false) - private Boolean notifierEnabled; - - @Override - public void execute(AdminCommandContext context) { - final ActionReport actionReport = context.getActionReport(); - Properties extraProperties = actionReport.getExtraProperties(); - if (extraProperties == null) { - extraProperties = new Properties(); - actionReport.setExtraProperties(extraProperties); - } - - Map notifierExecutionOptionsList = service.getExecutionOptions().getNotifierExecutionOptionsList(); - for (Map.Entry entry : notifierExecutionOptionsList.entrySet()) { - NotifierExecutionOptions value = entry.getValue(); - value.setEnabled(notifierEnabled); - } - } -} diff --git a/nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/admin/EnableRequestTracingNotifierConfigurerOnInstance.java b/nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/admin/EnableRequestTracingNotifierConfigurerOnInstance.java deleted file mode 100644 index 948473682ba..00000000000 --- a/nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/admin/EnableRequestTracingNotifierConfigurerOnInstance.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - - DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - - Copyright (c) 2016 C2B2 Consulting Limited. All rights reserved. - - The contents of this file are subject to the terms of the Common Development - and Distribution License("CDDL") (collectively, the "License"). You - may not use this file except in compliance with the License. You can - obtain a copy of the License at - https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html - or packager/legal/LICENSE.txt. See the License for the specific - language governing permissions and limitations under the License. - - When distributing the software, include this License Header Notice in each - file and include the License file at packager/legal/LICENSE.txt. - */ -package fish.payara.nucleus.requesttracing.admin; - -import com.sun.enterprise.config.serverbeans.Config; -import com.sun.enterprise.config.serverbeans.Domain; -import com.sun.enterprise.util.LocalStringManagerImpl; -import com.sun.enterprise.util.SystemPropertyConstants; -import fish.payara.nucleus.notification.configuration.Notifier; -import fish.payara.nucleus.notification.configuration.NotifierType; -import fish.payara.nucleus.notification.service.BaseNotifierService; -import fish.payara.nucleus.requesttracing.RequestTracingService; -import fish.payara.nucleus.requesttracing.configuration.RequestTracingServiceConfiguration; -import fish.payara.nucleus.requesttracing.domain.execoptions.NotifierExecutionOptions; -import fish.payara.nucleus.requesttracing.domain.execoptions.NotifierExecutionOptionsFactory; -import org.glassfish.api.ActionReport; -import org.glassfish.api.I18n; -import org.glassfish.api.Param; -import org.glassfish.api.admin.*; -import org.glassfish.config.support.CommandTarget; -import org.glassfish.config.support.TargetType; -import org.glassfish.hk2.api.PerLookup; -import org.glassfish.hk2.api.ServiceLocator; -import org.glassfish.internal.api.Target; -import org.jvnet.hk2.annotations.Service; -import org.jvnet.hk2.config.ConfigSupport; -import org.jvnet.hk2.config.SingleConfigCode; -import org.jvnet.hk2.config.TransactionFailure; - -import javax.inject.Inject; -import java.beans.PropertyVetoException; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.logging.Level; -import java.util.logging.Logger; - - -/** - * - * @author Susan Rai - */ -@ExecuteOn({RuntimeType.INSTANCE}) -@TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG}) -@Service(name = "__enable-requesttracing-configure-notifier-instance") -@CommandLock(CommandLock.LockType.NONE) -@PerLookup -@I18n("__enable-requesttracing-configure-notifier-instance") -public class EnableRequestTracingNotifierConfigurerOnInstance implements AdminCommand { - - final private static LocalStringManagerImpl strings = new LocalStringManagerImpl(RequestTracingNotifierConfigurer.class); - - @Inject - RequestTracingService service; - - @Inject - NotifierExecutionOptionsFactory factory; - - @Inject - ServiceLocator habitat; - - @Inject - protected Logger logger; - - @Inject - protected Target targetUtil; - - @Param(name = "target", optional = true, defaultValue = SystemPropertyConstants.DAS_SERVER_NAME) - String target; - - @Param(name = "notifierName", optional = true, defaultValue = "service-log") - private String notifierName; - - @Param(name = "notifierEnabled", optional = false) - private Boolean notifierEnabled; - - @Override - public void execute(AdminCommandContext context) { - final ActionReport actionReport = context.getActionReport(); - Properties extraProperties = actionReport.getExtraProperties(); - if (extraProperties == null) { - extraProperties = new Properties(); - actionReport.setExtraProperties(extraProperties); - } - Map notifierExecutionOptionsList = service.getExecutionOptions().getNotifierExecutionOptionsList(); - for (Map.Entry entry : notifierExecutionOptionsList.entrySet()) { - NotifierExecutionOptions value = entry.getValue(); - value.setEnabled(notifierEnabled); - } - - } -} diff --git a/nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/admin/RequestTracingConfigurer.java b/nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/admin/RequestTracingConfigurer.java index 6ecbb695b47..3d3699f9a81 100644 --- a/nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/admin/RequestTracingConfigurer.java +++ b/nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/admin/RequestTracingConfigurer.java @@ -45,12 +45,11 @@ and Distribution License("CDDL") (collectively, the "License"). You import org.glassfish.hk2.api.ServiceLocator; /** - * Admin command to enable/disable all request tracing services defined in - * domain.xml. + * Admin command to enable/disable all request tracing services defined in domain.xml. * * @author mertcaliskan */ -@ExecuteOn({RuntimeType.DAS}) +@ExecuteOn({RuntimeType.INSTANCE}) @TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG}) @Service(name = "requesttracing-configure") @CommandLock(CommandLock.LockType.NONE) @@ -92,8 +91,6 @@ public class RequestTracingConfigurer implements AdminCommand { @Inject ServiceLocator serviceLocator; - - CommandRunner.CommandInvocation inv; @Override public void execute(AdminCommandContext context) { @@ -145,25 +142,20 @@ public Object run(final RequestTracingServiceConfiguration requestTracingService } private void enableOnTarget(ActionReport actionReport, AdminCommandContext context, Boolean enabled) { - CommandRunner runner = serviceLocator.getService(CommandRunner.class); - ActionReport subReport = context.getActionReport().addSubActionsReport(); - - if (target.equals("server-config")) { - inv = runner.getCommandInvocation("__enable-requesttracing-configure-das", subReport, context.getSubject()); - } else { - inv = runner.getCommandInvocation("__enable-requesttracing-configure-instance", subReport, context.getSubject()); + if (enabled != null) { + service.getExecutionOptions().setEnabled(enabled); + actionReport.appendMessage(strings.getLocalString("requesttracing.configure.status.success", + "request tracing service status is set to {0}.", enabled) + "\n"); } - - ParameterMap params = new ParameterMap(); - params.add("enabled", enabled.toString()); - params.add("target", target); - params.add("thresholdUnit", unit); - params.add("thresholdValue", value); - inv.parameters(params); - inv.execute(); - // swallow the offline warning as it is not a problem - if (subReport.hasWarnings()) { - subReport.setMessage(""); + 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"); } } @@ -183,24 +175,6 @@ private boolean validate(ActionReport actionReport) { } - if (unit != null) { - try { - if (!unit.equals("NANOSECONDS") - && !unit.equals("MICROSECONDS") - && !unit.equals("MILLISECONDS") - && !unit.equals("SECONDS") - && !unit.equals("MINUTES") - && !unit.equals("HOURS") - && !unit.equals("DAYS")) { - actionReport.failure(logger, unit + " is an invalid time unit"); - return result; - } - } catch (IllegalArgumentException iaf) { - actionReport.failure(logger, unit + " is an invalid time unit", iaf); - return result; - } - } - return true; } } diff --git a/nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/admin/RequestTracingConfigurerDas.java b/nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/admin/RequestTracingConfigurerDas.java new file mode 100644 index 00000000000..32ca2ce61df --- /dev/null +++ b/nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/admin/RequestTracingConfigurerDas.java @@ -0,0 +1,180 @@ +/* + + DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + + Copyright (c) 2016 C2B2 Consulting Limited. All rights reserved. + + The contents of this file are subject to the terms of the Common Development + and Distribution License("CDDL") (collectively, the "License"). You + may not use this file except in compliance with the License. You can + obtain a copy of the License at + https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html + or packager/legal/LICENSE.txt. See the License for the specific + language governing permissions and limitations under the License. + + When distributing the software, include this License Header Notice in each + file and include the License file at packager/legal/LICENSE.txt. + */ +package fish.payara.nucleus.requesttracing.admin; + +import com.sun.enterprise.config.serverbeans.Config; +import com.sun.enterprise.config.serverbeans.Domain; +import com.sun.enterprise.util.LocalStringManagerImpl; +import com.sun.enterprise.util.SystemPropertyConstants; +import fish.payara.nucleus.requesttracing.RequestTracingService; +import fish.payara.nucleus.requesttracing.configuration.RequestTracingServiceConfiguration; +import org.glassfish.api.ActionReport; +import org.glassfish.api.I18n; +import org.glassfish.api.Param; +import org.glassfish.api.admin.*; +import org.glassfish.config.support.CommandTarget; +import org.glassfish.config.support.TargetType; +import org.glassfish.hk2.api.PerLookup; +import org.glassfish.internal.api.Target; +import org.jvnet.hk2.annotations.Service; +import org.jvnet.hk2.config.ConfigSupport; +import org.jvnet.hk2.config.SingleConfigCode; +import org.jvnet.hk2.config.TransactionFailure; + +import javax.inject.Inject; +import java.beans.PropertyVetoException; +import java.util.Properties; +import java.util.concurrent.TimeUnit; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.glassfish.hk2.api.ServiceLocator; + +/** + * Admin command to enable/disable all request tracing services defined in domain.xml. + * + * @author mertcaliskan + */ +@ExecuteOn({RuntimeType.DAS}) +@TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG}) +@Service(name = "requesttracing-configure-das") +@CommandLock(CommandLock.LockType.NONE) +@PerLookup +@I18n("requesttracing.configure.das") +@RestEndpoints({ + @RestEndpoint(configBean = Domain.class, + opType = RestEndpoint.OpType.POST, + path = "requesttracing-configure-das", + description = "Enables/Disables Request Tracing Service") +}) +public class RequestTracingConfigurerDas implements AdminCommand { + + final private static LocalStringManagerImpl strings = new LocalStringManagerImpl(RequestTracingConfigurerDas.class); + + @Inject + RequestTracingService service; + + @Inject + protected Logger logger; + + @Inject + protected Target targetUtil; + + @Param(name = "target", optional = true, defaultValue = SystemPropertyConstants.DAS_SERVER_NAME) + String target; + + @Param(name = "enabled", optional = false) + private Boolean enabled; + + @Param(name = "dynamic", optional = true, defaultValue = "false") + private Boolean dynamic; + + @Param(name = "thresholdUnit", optional = true, defaultValue = "SECONDS") + private String unit; + + @Param(name = "thresholdValue", optional = true, defaultValue = "10") + private String value; + + @Inject + ServiceLocator serviceLocator; + + @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() { + @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) { + enableOnTarget(actionReport, theContext, enabled); + } + } + + private void enableOnTarget(ActionReport actionReport, AdminCommandContext context, Boolean enabled) { + if (enabled != null) { + service.getExecutionOptions().setEnabled(enabled); + actionReport.appendMessage(strings.getLocalString("requesttracing.configure.status.success", + "request tracing service status is set to {0}.", enabled) + "\n"); + } + 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"); + } + } + + private boolean validate(ActionReport actionReport) { + boolean result = false; + if (value != null) { + try { + int thresholdValue = Integer.parseInt(value); + if (thresholdValue <= 0 || thresholdValue > Short.MAX_VALUE * 2) { + actionReport.failure(logger, "Threshold Value must be greater than zero or less than " + Short.MAX_VALUE * 2 + 1); + return result; + } + } catch (NumberFormatException nfe) { + actionReport.failure(logger, "Threshold Value is not a valid integer", nfe); + return result; + } + + } + + return true; + } +} diff --git a/nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/admin/RequestTracingNotifierConfigurer.java b/nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/admin/RequestTracingNotifierConfigurer.java index dd93a61068b..3cdfeeef952 100644 --- a/nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/admin/RequestTracingNotifierConfigurer.java +++ b/nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/admin/RequestTracingNotifierConfigurer.java @@ -48,12 +48,13 @@ and Distribution License("CDDL") (collectively, the "License"). You import java.util.logging.Level; import java.util.logging.Logger; + /** * Admin command to enable/disable specific notifier given with its name * * @author mertcaliskan */ -@ExecuteOn({RuntimeType.DAS}) +@ExecuteOn({RuntimeType.INSTANCE}) @TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG}) @Service(name = "requesttracing-configure-notifier") @CommandLock(CommandLock.LockType.NONE) @@ -96,13 +97,9 @@ public class RequestTracingNotifierConfigurer implements AdminCommand { @Param(name = "notifierEnabled", optional = false) private Boolean notifierEnabled; - @Inject - ServiceLocator serviceLocator; - @Override public void execute(AdminCommandContext context) { final ActionReport actionReport = context.getActionReport(); - final AdminCommandContext theContext = context; Properties extraProperties = actionReport.getExtraProperties(); if (extraProperties == null) { extraProperties = new Properties(); @@ -133,10 +130,22 @@ public Object run(final RequestTracingServiceConfiguration requestTracingService if (notifierEnabled != null) { notifierProxy.enabled(notifierEnabled); } - - if (dynamic) { - enableOnTarget(actionReport, theContext, notifierEnabled); + createdNotifier[0] = notifierProxy; + + List notifierList = requestTracingServiceConfigurationProxy.getNotifierList(); + NotifierExecutionOptions executionOptions = factory.build(createdNotifier[0]); + if (notifierEnabled) { + notifierList.add(createdNotifier[0]); + if (dynamic) { + service.getExecutionOptions().addNotifierExecutionOption(executionOptions); + } + } else { + notifierList.remove(createdNotifier[0]); + if (dynamic) { + service.getExecutionOptions().removeNotifierExecutionOption(executionOptions); + } } + actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS); return requestTracingServiceConfigurationProxy; } @@ -149,9 +158,16 @@ public Object run(final Notifier notifierProxy) throws if (notifierEnabled != null) { notifierProxy.enabled(notifierEnabled); } + if (dynamic) { - enableOnTarget(actionReport, theContext, notifierEnabled); + NotifierExecutionOptions executionOptions = factory.build(notifierProxy); + if (notifierEnabled) { + service.getExecutionOptions().addNotifierExecutionOption(executionOptions); + } else { + service.getExecutionOptions().removeNotifierExecutionOption(executionOptions); + } } + actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS); return notifierProxy; } @@ -167,28 +183,4 @@ public Object run(final Notifier notifierProxy) throws actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE); } } - - private void enableOnTarget(ActionReport actionReport, AdminCommandContext context, Boolean enabled) { - CommandRunner runner = serviceLocator.getService(CommandRunner.class); - ActionReport subReport = context.getActionReport().addSubActionsReport(); - CommandRunner.CommandInvocation inv; - - if (target.equals("server-config")) { - inv = runner.getCommandInvocation("__enable-requesttracing-configure-notifier-das", subReport, context.getSubject()); - } else { - inv = runner.getCommandInvocation("__enable-requesttracing-configure-notifier-instance", subReport, context.getSubject()); - } - - ParameterMap params = new ParameterMap(); - params.add("notifierEnabled", enabled.toString()); - params.add("target", target); - params.add("notifierName", notifierName); - inv.parameters(params); - inv.execute(); - // swallow the offline warning as it is not a problem - if (subReport.hasWarnings()) { - subReport.setMessage(""); - } - - } } diff --git a/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/EnableNotificationNotifierConfigurerOnInstance.java b/nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/admin/RequestTracingNotifierConfigurerDas.java similarity index 53% rename from nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/EnableNotificationNotifierConfigurerOnInstance.java rename to nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/admin/RequestTracingNotifierConfigurerDas.java index 29d47881679..01fda2112e4 100644 --- a/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/EnableNotificationNotifierConfigurerOnInstance.java +++ b/nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/admin/RequestTracingNotifierConfigurerDas.java @@ -15,19 +15,18 @@ and Distribution License("CDDL") (collectively, the "License"). You When distributing the software, include this License Header Notice in each file and include the License file at packager/legal/LICENSE.txt. */ -package fish.payara.nucleus.notification.admin; +package fish.payara.nucleus.requesttracing.admin; import com.sun.enterprise.config.serverbeans.Config; import com.sun.enterprise.config.serverbeans.Domain; import com.sun.enterprise.util.LocalStringManagerImpl; import com.sun.enterprise.util.SystemPropertyConstants; -import fish.payara.nucleus.notification.NotificationEventBus; -import fish.payara.nucleus.notification.NotificationService; -import fish.payara.nucleus.notification.configuration.NotificationServiceConfiguration; -import fish.payara.nucleus.notification.configuration.NotifierConfiguration; -import fish.payara.nucleus.notification.domain.execoptions.NotifierConfigurationExecutionOptions; -import fish.payara.nucleus.notification.domain.execoptions.NotifierConfigurationExecutionOptionsFactory; +import fish.payara.nucleus.notification.configuration.Notifier; import fish.payara.nucleus.notification.service.BaseNotifierService; +import fish.payara.nucleus.requesttracing.RequestTracingService; +import fish.payara.nucleus.requesttracing.configuration.RequestTracingServiceConfiguration; +import fish.payara.nucleus.requesttracing.domain.execoptions.NotifierExecutionOptions; +import fish.payara.nucleus.requesttracing.domain.execoptions.NotifierExecutionOptionsFactory; import org.glassfish.api.ActionReport; import org.glassfish.api.I18n; import org.glassfish.api.Param; @@ -49,22 +48,33 @@ and Distribution License("CDDL") (collectively, the "License"). You import java.util.logging.Level; import java.util.logging.Logger; + /** + * Admin command to enable/disable specific notifier given with its name * - * @author Susan Rai + * @author mertcaliskan */ -@ExecuteOn({RuntimeType.INSTANCE}) +@ExecuteOn({RuntimeType.DAS}) @TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG}) -@Service(name = "__enable-notification-configure-notifier-instance") +@Service(name = "requesttracing-configure-notifier-das") @CommandLock(CommandLock.LockType.NONE) @PerLookup -@I18n("__enable-notification-configure-notifier-instance") -public class EnableNotificationNotifierConfigurerOnInstance implements AdminCommand { +@I18n("requesttracing.configure.notifier.das") +@RestEndpoints({ + @RestEndpoint(configBean = Domain.class, + opType = RestEndpoint.OpType.POST, + path = "requesttracing-configure-notifier-das", + description = "Enables/Disables Notifier Specified With Name") +}) +public class RequestTracingNotifierConfigurerDas implements AdminCommand { + + final private static LocalStringManagerImpl strings = new LocalStringManagerImpl(RequestTracingNotifierConfigurerDas.class); - final private static LocalStringManagerImpl strings = new LocalStringManagerImpl(EnableNotificationNotifierConfigurerOnInstance.class); + @Inject + RequestTracingService service; @Inject - NotificationService service; + NotifierExecutionOptionsFactory factory; @Inject ServiceLocator habitat; @@ -75,11 +85,8 @@ public class EnableNotificationNotifierConfigurerOnInstance implements AdminComm @Inject protected Target targetUtil; - @Inject - private NotifierConfigurationExecutionOptionsFactory factory; - - @Inject - private NotificationEventBus eventBus; + @Param(name = "dynamic", optional = true, defaultValue = "false") + private Boolean dynamic; @Param(name = "target", optional = true, defaultValue = SystemPropertyConstants.DAS_SERVER_NAME) String target; @@ -102,54 +109,63 @@ public void execute(AdminCommandContext context) { Config config = targetUtil.getConfig(target); final BaseNotifierService notifierService = habitat.getService(BaseNotifierService.class, notifierName); - if (notifierService == null) { + if (service == null) { actionReport.appendMessage(strings.getLocalString("requesttracing.notifier.configure.status.error", "Notifier with name {0} could not be found.", notifierName)); actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE); return; } - final NotificationServiceConfiguration notificationServiceConfiguration = config.getExtensionByType(NotificationServiceConfiguration.class); - final NotifierConfiguration notifier = notificationServiceConfiguration.getNotifierConfigurationByType(notifierService.getNotifierConfigType()); + final RequestTracingServiceConfiguration requestTracingServiceConfiguration = config.getExtensionByType(RequestTracingServiceConfiguration.class); + final Notifier notifier = requestTracingServiceConfiguration.getNotifierByType(notifierService.getNotifierType()); try { if (notifier == null) { - final NotifierConfiguration[] createdNotifier = {null}; - ConfigSupport.apply(new SingleConfigCode() { + final Notifier[] createdNotifier = {null}; + ConfigSupport.apply(new SingleConfigCode() { @Override - public Object run(final NotificationServiceConfiguration notificationServiceConfigurationProxy) throws + public Object run(final RequestTracingServiceConfiguration requestTracingServiceConfigurationProxy) throws PropertyVetoException, TransactionFailure { - NotifierConfiguration notifierProxy = (NotifierConfiguration) notificationServiceConfigurationProxy.createChild(notifierService.getNotifierConfigType()); + Notifier notifierProxy = (Notifier) requestTracingServiceConfigurationProxy.createChild(notifierService.getNotifierType()); + if (notifierEnabled != null) { + notifierProxy.enabled(notifierEnabled); + } createdNotifier[0] = notifierProxy; - List notifierConfigList = notificationServiceConfigurationProxy.getNotifierConfigurationList(); - NotifierConfigurationExecutionOptions executionOptions = factory.build(createdNotifier[0]); + List notifierList = requestTracingServiceConfigurationProxy.getNotifierList(); + NotifierExecutionOptions executionOptions = factory.build(createdNotifier[0]); if (notifierEnabled) { - notifierConfigList.add(createdNotifier[0]); - service.getExecutionOptions().addNotifierConfigurationExecutionOption(executionOptions); - eventBus.register(notifierService); + notifierList.add(createdNotifier[0]); + if (dynamic) { + service.getExecutionOptions().addNotifierExecutionOption(executionOptions); + } } else { - notifierConfigList.remove(createdNotifier[0]); - service.getExecutionOptions().removeNotifierConfigurationExecutionOption(executionOptions); - eventBus.unregister(notifierService); + notifierList.remove(createdNotifier[0]); + if (dynamic) { + service.getExecutionOptions().removeNotifierExecutionOption(executionOptions); + } } actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS); - return notificationServiceConfigurationProxy; + return requestTracingServiceConfigurationProxy; } - }, notificationServiceConfiguration); + }, requestTracingServiceConfiguration); } else { - ConfigSupport.apply(new SingleConfigCode() { + ConfigSupport.apply(new SingleConfigCode() { @Override - public Object run(final NotifierConfiguration notifierProxy) throws + public Object run(final Notifier notifierProxy) throws PropertyVetoException, TransactionFailure { - NotifierConfigurationExecutionOptions executionOptions = factory.build(notifierProxy); - if (notifierEnabled) { - service.getExecutionOptions().addNotifierConfigurationExecutionOption(executionOptions); - eventBus.register(notifierService); - } else { - service.getExecutionOptions().removeNotifierConfigurationExecutionOption(executionOptions); - eventBus.unregister(notifierService); + if (notifierEnabled != null) { + notifierProxy.enabled(notifierEnabled); + } + + if (dynamic) { + NotifierExecutionOptions executionOptions = factory.build(notifierProxy); + if (notifierEnabled) { + service.getExecutionOptions().addNotifierExecutionOption(executionOptions); + } else { + service.getExecutionOptions().removeNotifierExecutionOption(executionOptions); + } } actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS); @@ -159,8 +175,8 @@ public Object run(final NotifierConfiguration notifierProxy) throws } - actionReport.appendMessage(strings.getLocalString("notification.configure.notifier.added.configured", - "Notifier with name {0} is registered and set enabled to {1}.", notifierName, notifierEnabled) + "\n"); + actionReport.appendMessage(strings.getLocalString("requesttracing.configure.notifier.added.configured", + "Request Tracing Notifier with name {0} is registered and set enabled to {1}.", notifierName, notifierEnabled) + "\n"); } catch (TransactionFailure ex) { logger.log(Level.WARNING, "Exception during command ", ex); actionReport.setMessage(ex.getCause().getMessage()); diff --git a/nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/admin/SetRequestTracingConfiguration.java b/nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/admin/SetRequestTracing.java similarity index 79% rename from nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/admin/SetRequestTracingConfiguration.java rename to nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/admin/SetRequestTracing.java index 685b0d4f554..256a2d1db3b 100644 --- a/nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/admin/SetRequestTracingConfiguration.java +++ b/nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/admin/SetRequestTracing.java @@ -47,17 +47,17 @@ and Distribution License("CDDL") (collectively, the "License"). You */ @ExecuteOn({RuntimeType.DAS}) @TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG}) -@Service(name = "set-requesttracing-configuration") +@Service(name = "set-requesttracing") @CommandLock(CommandLock.LockType.NONE) @PerLookup -@I18n("set.requesttracing.configuration") +@I18n("set.requesttracing") @RestEndpoints({ @RestEndpoint(configBean = Domain.class, opType = RestEndpoint.OpType.POST, - path = "set-requesttracing-configuration", + path = "set-requesttracing", description = "Set Request Tracing Services Configuration") }) -public class SetRequestTracingConfiguration implements AdminCommand { +public class SetRequestTracing implements AdminCommand { @Inject protected Logger logger; @@ -128,7 +128,11 @@ private void enableRequestTracingConfigureOnTarget(ActionReport actionReport, Ad CommandRunner runner = serviceLocator.getService(CommandRunner.class); ActionReport subReport = context.getActionReport().addSubActionsReport(); - inv = runner.getCommandInvocation("requesttracing-configure", subReport, context.getSubject()); + if (target.equals("server-config")) { + inv = runner.getCommandInvocation("requesttracing-configure-das", subReport, context.getSubject()); + } else { + inv = runner.getCommandInvocation("requesttracing-configure", subReport, context.getSubject()); + } ParameterMap params = new ParameterMap(); params.add("enabled", enabled.toString()); @@ -148,20 +152,26 @@ private void enableRequestTracingNotifierConfigurerOnTarget(ActionReport actionR CommandRunner runner = serviceLocator.getService(CommandRunner.class); ActionReport subReport = context.getActionReport().addSubActionsReport(); - inv = runner.getCommandInvocation("requesttracing-configure-notifier", subReport, context.getSubject()); + if (target.equals("server-config")) { + inv = runner.getCommandInvocation("requesttracing-configure-notifier-das", subReport, context.getSubject()); + } else { + inv = runner.getCommandInvocation("requesttracing-configure-notifier", subReport, context.getSubject()); + } - ParameterMap params = new ParameterMap(); - params.add("dynamic", notifierDynamic.toString()); - params.add("target", target); - params.add("notifierName", notifierName); - params.add("notifierEnabled", enabled.toString()); - inv.parameters(params); - inv.execute(); - // swallow the offline warning as it is not a problem - if (subReport.hasWarnings()) { - subReport.setMessage(""); + ParameterMap params = new ParameterMap(); + params.add("dynamic", notifierDynamic.toString()); + params.add("target", target); + params.add("notifierName", notifierName); + params.add("notifierEnabled", enabled.toString()); + inv.parameters(params); + inv.execute(); + // swallow the offline warning as it is not a problem + if (subReport.hasWarnings()) { + subReport.setMessage(""); + } } - } + + private boolean validate(ActionReport actionReport) { boolean result = false; @@ -179,24 +189,6 @@ private boolean validate(ActionReport actionReport) { } - if (unit != null) { - try { - if (!unit.equals("NANOSECONDS") - && !unit.equals("MICROSECONDS") - && !unit.equals("MILLISECONDS") - && !unit.equals("SECONDS") - && !unit.equals("MINUTES") - && !unit.equals("HOURS") - && !unit.equals("DAYS")) { - actionReport.failure(logger, unit + " is an invalid time unit"); - return result; - } - } catch (IllegalArgumentException iaf) { - actionReport.failure(logger, unit + " is an invalid time unit", iaf); - return result; - } - } - return true; } } diff --git a/nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/domain/execoptions/NotifierExecutionOptions.java b/nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/domain/execoptions/NotifierExecutionOptions.java index 3e457f11179..349900d4b68 100644 --- a/nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/domain/execoptions/NotifierExecutionOptions.java +++ b/nucleus/payara-modules/requesttracing-core/src/main/java/fish/payara/nucleus/requesttracing/domain/execoptions/NotifierExecutionOptions.java @@ -41,7 +41,7 @@ public boolean isEnabled() { return enabled; } - public void setEnabled(boolean enabled) { + void setEnabled(boolean enabled) { this.enabled = enabled; } diff --git a/nucleus/payara-modules/requesttracing-core/src/test/java/fish/payara/nucleus/requesttracing/RequestTraceTest.java b/nucleus/payara-modules/requesttracing-core/src/test/java/fish/payara/nucleus/requesttracing/RequestTraceTest.java index 1e7fc4afdf5..50ad671059f 100644 --- a/nucleus/payara-modules/requesttracing-core/src/test/java/fish/payara/nucleus/requesttracing/RequestTraceTest.java +++ b/nucleus/payara-modules/requesttracing-core/src/test/java/fish/payara/nucleus/requesttracing/RequestTraceTest.java @@ -103,14 +103,13 @@ public void testElapsedTime() throws InterruptedException { } @Test - public void testFullStream() throws InterruptedException { + public void testFullStream() { RequestEvent re = new RequestEvent(EventType.TRACE_START,"Start"); trace.addEvent(re); for (int i = 0; i < 10000; i++) { re = new RequestEvent("Event"+i); trace.addEvent(re); } - Thread.currentThread().sleep(1000); re = new RequestEvent(EventType.TRACE_END,"TraceEnd"); trace.addEvent(re); assertTrue(trace.isStarted());