From 782fca76b46e46922038afdddcb709001c858c1b Mon Sep 17 00:00:00 2001 From: Steve Millidge Date: Sat, 13 Aug 2016 13:17:28 +0100 Subject: [PATCH] PAYARA-848 Notification target fix (#1026) * Fixed "notification-configure" command * Fixed "notification-configure-notifier" command * Fixed Typo * PAYARA-848 Notification target Fix for asadmin commands --- ...=> EnableNotificationConfigurerOnDas.java} | 61 +------ ...nableNotificationConfigurerOnInstance.java | 83 +++++++++ ...eNotificationNotifierConfigurerOnDas.java} | 56 ++---- ...ificationNotifierConfigurerOnInstance.java | 170 ++++++++++++++++++ .../admin/NotificationConfigurer.java | 30 +++- .../admin/NotificationNotifierConfigurer.java | 61 ++++--- .../admin/SetNotificationConfiguration.java | 12 +- 7 files changed, 335 insertions(+), 138 deletions(-) rename nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/{NotificationConfigurerDas.java => EnableNotificationConfigurerOnDas.java} (52%) create 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/{NotificationNotifierConfigurerDas.java => EnableNotificationNotifierConfigurerOnDas.java} (76%) create mode 100644 nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/EnableNotificationNotifierConfigurerOnInstance.java diff --git a/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/NotificationConfigurerDas.java b/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/EnableNotificationConfigurerOnDas.java similarity index 52% rename from nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/NotificationConfigurerDas.java rename to nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/EnableNotificationConfigurerOnDas.java index b16021015de..6111986cc66 100644 --- a/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/NotificationConfigurerDas.java +++ b/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/EnableNotificationConfigurerOnDas.java @@ -17,12 +17,10 @@ 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; @@ -32,38 +30,25 @@ 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 mertcaliskan + * @author Susan Rai */ -@Service(name = "notification-configure-das") +@Service(name = "__enable-notification-configure-das") @PerLookup @CommandLock(CommandLock.LockType.NONE) -@I18n("notification.configure.das") +@I18n("__enable-notification-configure-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.POST, - path = "notification-configure-das", - description = "Enables/Disables Notification Service") -}) -public class NotificationConfigurerDas implements AdminCommand { +public class EnableNotificationConfigurerOnDas implements AdminCommand { - final private static LocalStringManagerImpl strings = new LocalStringManagerImpl(NotificationConfigurerDas.class); + final private static LocalStringManagerImpl strings = new LocalStringManagerImpl(EnableNotificationConfigurerOnDas.class); @Inject NotificationService service; @@ -73,10 +58,7 @@ public class NotificationConfigurerDas 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; @@ -92,37 +74,6 @@ 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/EnableNotificationConfigurerOnInstance.java b/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/EnableNotificationConfigurerOnInstance.java new file mode 100644 index 00000000000..65d2ad49870 --- /dev/null +++ b/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/EnableNotificationConfigurerOnInstance.java @@ -0,0 +1,83 @@ +/* + + 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/NotificationNotifierConfigurerDas.java b/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/EnableNotificationNotifierConfigurerOnDas.java similarity index 76% rename from nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/NotificationNotifierConfigurerDas.java rename to nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/EnableNotificationNotifierConfigurerOnDas.java index 3255eebf15b..3242a1a7348 100644 --- a/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/NotificationNotifierConfigurerDas.java +++ b/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/EnableNotificationNotifierConfigurerOnDas.java @@ -49,27 +49,19 @@ 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 + * @author Susan Rai */ @ExecuteOn({RuntimeType.DAS}) @TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG}) -@Service(name = "notification-configure-notifier-das") +@Service(name = "__enable-notification-configure-notifier-das") @CommandLock(CommandLock.LockType.NONE) @PerLookup -@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 { +@I18n("__enable-notification-configure-notifier-das") +public class EnableNotificationNotifierConfigurerOnDas implements AdminCommand { - final private static LocalStringManagerImpl strings = new LocalStringManagerImpl(NotificationNotifierConfigurerDas.class); + final private static LocalStringManagerImpl strings = new LocalStringManagerImpl(EnableNotificationNotifierConfigurerOnDas.class); @Inject NotificationService service; @@ -89,9 +81,6 @@ public class NotificationNotifierConfigurerDas 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; @@ -131,25 +120,18 @@ 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]); - if (dynamic) { - service.getExecutionOptions().addNotifierConfigurationExecutionOption(executionOptions); - eventBus.register(notifierService); - } + service.getExecutionOptions().addNotifierConfigurationExecutionOption(executionOptions); + eventBus.register(notifierService); } else { notifierConfigList.remove(createdNotifier[0]); - if (dynamic) { - service.getExecutionOptions().removeNotifierConfigurationExecutionOption(executionOptions); - eventBus.unregister(notifierService); - } + service.getExecutionOptions().removeNotifierConfigurationExecutionOption(executionOptions); + eventBus.unregister(notifierService); } actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS); @@ -161,19 +143,13 @@ public Object run(final NotificationServiceConfiguration notificationServiceConf @Override public Object run(final NotifierConfiguration notifierProxy) throws PropertyVetoException, TransactionFailure { - 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); - } + 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/EnableNotificationNotifierConfigurerOnInstance.java b/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/EnableNotificationNotifierConfigurerOnInstance.java new file mode 100644 index 00000000000..29d47881679 --- /dev/null +++ b/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/EnableNotificationNotifierConfigurerOnInstance.java @@ -0,0 +1,170 @@ +/* + + 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.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.service.BaseNotifierService; +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.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-notification-configure-notifier-instance") +@CommandLock(CommandLock.LockType.NONE) +@PerLookup +@I18n("__enable-notification-configure-notifier-instance") +public class EnableNotificationNotifierConfigurerOnInstance implements AdminCommand { + + final private static LocalStringManagerImpl strings = new LocalStringManagerImpl(EnableNotificationNotifierConfigurerOnInstance.class); + + @Inject + NotificationService service; + + @Inject + ServiceLocator habitat; + + @Inject + protected Logger logger; + + @Inject + protected Target targetUtil; + + @Inject + private NotifierConfigurationExecutionOptionsFactory factory; + + @Inject + private NotificationEventBus eventBus; + + @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); + } + + Config config = targetUtil.getConfig(target); + + final BaseNotifierService notifierService = habitat.getService(BaseNotifierService.class, notifierName); + if (notifierService == 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()); + + try { + if (notifier == null) { + final NotifierConfiguration[] createdNotifier = {null}; + ConfigSupport.apply(new SingleConfigCode() { + @Override + public Object run(final NotificationServiceConfiguration notificationServiceConfigurationProxy) throws + PropertyVetoException, TransactionFailure { + NotifierConfiguration notifierProxy = (NotifierConfiguration) notificationServiceConfigurationProxy.createChild(notifierService.getNotifierConfigType()); + 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); + } else { + notifierConfigList.remove(createdNotifier[0]); + service.getExecutionOptions().removeNotifierConfigurationExecutionOption(executionOptions); + eventBus.unregister(notifierService); + } + + actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS); + return notificationServiceConfigurationProxy; + } + }, notificationServiceConfiguration); + } else { + ConfigSupport.apply(new SingleConfigCode() { + @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); + } + + actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS); + return notifierProxy; + } + }, notifier); + + } + + actionReport.appendMessage(strings.getLocalString("notification.configure.notifier.added.configured", + "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()); + actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE); + } + } +} 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 1e4fdb170f8..c712782502b 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,6 +41,7 @@ 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; /** @@ -53,7 +54,7 @@ and Distribution License("CDDL") (collectively, the "License"). You @PerLookup @CommandLock(CommandLock.LockType.NONE) @I18n("notification.configure") -@ExecuteOn({RuntimeType.INSTANCE}) +@ExecuteOn({RuntimeType.DAS}) @TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG}) @RestEndpoints({ @RestEndpoint(configBean = Domain.class, @@ -83,6 +84,11 @@ 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(); @@ -123,10 +129,24 @@ public Object run(final NotificationServiceConfiguration notificationServiceConf } private void enableOnTarget(ActionReport actionReport, AdminCommandContext context, Boolean enabled) { - if (enabled != null) { - service.getExecutionOptions().setEnabled(enabled); - actionReport.appendMessage(strings.getLocalString("notification.configure.status.success", - "Notification service status is set to {0}.", enabled) + "\n"); + + 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(""); } } } 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 6016c96a967..3784ce70b9e 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,13 +49,12 @@ 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.INSTANCE}) +@ExecuteOn({RuntimeType.DAS}) @TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG}) @Service(name = "notification-configure-notifier") @CommandLock(CommandLock.LockType.NONE) @@ -101,9 +100,13 @@ 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(); @@ -134,24 +137,10 @@ 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); - } - } + if (dynamic) { + enableOnTarget(actionReport, theContext, notifierEnabled); + } actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS); return notificationServiceConfigurationProxy; } @@ -166,16 +155,8 @@ public Object run(final NotifierConfiguration notifierProxy) throws } if (dynamic) { - NotifierConfigurationExecutionOptions executionOptions = factory.build(notifierProxy); - if (notifierEnabled) { - service.getExecutionOptions().addNotifierConfigurationExecutionOption(executionOptions); - eventBus.register(notifierService); - } else { - service.getExecutionOptions().removeNotifierConfigurationExecutionOption(executionOptions); - eventBus.unregister(notifierService); - } + enableOnTarget(actionReport, theContext, notifierEnabled); } - actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS); return notifierProxy; } @@ -191,4 +172,28 @@ 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/SetNotificationConfiguration.java b/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/admin/SetNotificationConfiguration.java index 61d86b32a33..e9d27787fe7 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/SetNotificationConfiguration.java @@ -105,11 +105,7 @@ private void enableNotificationConfigureOnTarget(ActionReport actionReport, Admi CommandRunner runner = serviceLocator.getService(CommandRunner.class); ActionReport subReport = context.getActionReport().addSubActionsReport(); - if (target.equals("server-config")) { - inv = runner.getCommandInvocation("notification-configure-das", subReport, context.getSubject()); - } else { - inv = runner.getCommandInvocation("notification-configure", subReport, context.getSubject()); - } + inv = runner.getCommandInvocation("notification-configure", subReport, context.getSubject()); ParameterMap params = new ParameterMap(); params.add("enabled", enabled.toString()); @@ -127,11 +123,7 @@ private void enableNotificationNotifierConfigurerOnTarget(ActionReport actionRep CommandRunner runner = serviceLocator.getService(CommandRunner.class); ActionReport subReport = context.getActionReport().addSubActionsReport(); - 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()); - } + inv = runner.getCommandInvocation("notification-configure-notifier", subReport, context.getSubject()); ParameterMap params = new ParameterMap(); params.add("dynamic", notifierDynamic.toString());