From f47b86ac804dbf3347c348912c9a2876aaedba6e Mon Sep 17 00:00:00 2001 From: merorai Date: Thu, 7 Nov 2019 12:19:46 +0000 Subject: [PATCH 1/2] Improved the monitoring service --- .../common/handlers/MonitoringHandlers.java | 51 ++++++++------ .../main/resources/monitor/monitoringPage.jsf | 68 +++++++++++++++---- .../common/admingui/Strings.properties | 8 ++- .../payara/admin/monitor/cli/Constants.java | 18 ++++- .../GetMonitoringServiceConfiguration.java | 12 ++-- .../admin/monitor/cli/SetMonitoringLevel.java | 16 +++-- .../SetMonitoringServiceConfiguration.java | 32 ++++++--- .../fish/payara/admin/amx/AMXBootService.java | 24 +++---- .../payara/admin/amx/cli/SetAmxEnabled.java | 28 ++++---- 9 files changed, 170 insertions(+), 87 deletions(-) diff --git a/appserver/admingui/common/src/main/java/org/glassfish/admingui/common/handlers/MonitoringHandlers.java b/appserver/admingui/common/src/main/java/org/glassfish/admingui/common/handlers/MonitoringHandlers.java index 2797e302809..42746163674 100644 --- a/appserver/admingui/common/src/main/java/org/glassfish/admingui/common/handlers/MonitoringHandlers.java +++ b/appserver/admingui/common/src/main/java/org/glassfish/admingui/common/handlers/MonitoringHandlers.java @@ -37,33 +37,29 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright [2018] Payara Foundation and/or affiliates +// Portions Copyright [2018-2019] Payara Foundation and/or affiliates package org.glassfish.admingui.common.handlers; -import java.io.UnsupportedEncodingException; -import org.glassfish.admingui.common.util.GuiUtil; - import com.sun.jsftemplating.annotation.Handler; import com.sun.jsftemplating.annotation.HandlerInput; import com.sun.jsftemplating.annotation.HandlerOutput; import com.sun.jsftemplating.layout.descriptors.handler.HandlerContext; +import java.io.UnsupportedEncodingException; import java.math.BigDecimal; import java.net.URLEncoder; - -import java.util.List; -import java.util.HashMap; -import java.util.Map; -import java.util.ArrayList; import java.text.DateFormat; -import java.text.NumberFormat; +import java.util.ArrayList; import java.util.Arrays; -import java.util.Locale; import java.util.Date; +import java.util.HashMap; +import java.util.List; import java.util.ListIterator; +import java.util.Locale; +import java.util.Map; +import java.util.StringJoiner; import java.util.logging.Level; - -import org.glassfish.admingui.common.util.RestResponse; +import org.glassfish.admingui.common.util.GuiUtil; import org.glassfish.admingui.common.util.RestUtil; /** @@ -406,18 +402,33 @@ public static void getStats(HandlerContext handlerCtx) { @Handler(id = "updateMonitorLevels", input = { @HandlerInput(name = "allRows", type = List.class, required = true), - @HandlerInput(name = "endpoint", type = String.class)}) + @HandlerInput(name = "config", type = String.class, required = true)}) public static void updateMonitorLevels(HandlerContext handlerCtx) { - String endpoint = (String) handlerCtx.getInputValue("endpoint"); + String config = (String) handlerCtx.getInputValue("config"); List allRows = (List) handlerCtx.getInputValue("allRows"); Map payload = new HashMap(); + + StringJoiner moduelNames = new StringJoiner(":"); + StringJoiner moduellevels = new StringJoiner(":"); + for (Map oneRow : allRows) { - payload.put(oneRow.get("attrName"), oneRow.get("level")); + String moduleName = oneRow.get("attrName"); + String level = oneRow.get("level"); + + if (moduleName.length() > 0 && level.length() > 0) { + moduelNames.add(moduleName); + moduellevels.add(level); + } } - try{ - RestUtil.restRequest( endpoint , payload, "post" , null, false); - }catch (Exception ex){ - GuiUtil.getLogger().severe(GuiUtil.getCommonMessage("msg.error.save.monitor.modules" , new Object[]{endpoint, payload})); + + String endpoint = (String) GuiUtil.getSessionValue("REST_URL") + "/set-monitoring-level.json"; + payload.put("module", moduelNames.toString()); + payload.put("level", moduellevels.toString()); + payload.put("target", config); + try { + RestUtil.restRequest(endpoint, payload, "POST", null, false, true); + } catch (Exception ex) { + GuiUtil.getLogger().severe(GuiUtil.getCommonMessage("msg.error.save.monitor.modules", new Object[]{endpoint, payload})); GuiUtil.handleError(handlerCtx, GuiUtil.getMessage("msg.error.checkLog")); return; } diff --git a/appserver/admingui/common/src/main/resources/monitor/monitoringPage.jsf b/appserver/admingui/common/src/main/resources/monitor/monitoringPage.jsf index ddd8e4d6c96..d2197b131a4 100644 --- a/appserver/admingui/common/src/main/resources/monitor/monitoringPage.jsf +++ b/appserver/admingui/common/src/main/resources/monitor/monitoringPage.jsf @@ -39,7 +39,7 @@ holder. --> - + $page{configName} default="server-config"); urlencode(value="#{pageSession.configName}" encoding="UTF-8" result="#{pageSession.encodedConfigName}"); setPageSessionAttribute(key="childType" value="monitoring-service"); setPageSessionAttribute(key="parentUrl", value="#{sessionScope.REST_URL}/configs/config/#{pageSession.encodedConfigName}"); setPageSessionAttribute(key="selfUrl", value="#{pageSession.parentUrl}/#{pageSession.childType}"); - setPageSessionAttribute(key="amxUrl", value="#{pageSession.parentUrl}/amx-configuration"); setPageSessionAttribute(key="rest-api" value="true"); - gf.getEntityAttrs(endpoint="#{pageSession.selfUrl}", valueMap="#{pageSession.valueMap}"); + + gf.restRequest(endpoint="#{sessionScope.REST_URL}/get-monitoring-service-configuration?target=#{pageSession.encodedConfigName}" + method="GET" result="#{requestScope.resp}"); + + setPageSessionAttribute(key="valueMap", value="#{requestScope.resp.data.extraProperties.getMonitoringServiceConfiguration}"); + mapPut(map="#{pageSession.valueMap}" key="target" value="#{pageSession.encodedConfigName}"); + + setPageSessionAttribute(key="convertToFalseList" value={"dtraceEnabled", "monitoringEnabled", "mbeanEnabled", "enabled", "dynamic"}); + if (#{pageSession.valueMap['monitoringEnabled']}=true) { + setPageSessionAttribute(key="monitoringEnabledSelected", value="true"); + } + + if (#{pageSession.valueMap['mbeanEnabled']}=true) { + setPageSessionAttribute(key="mbeanEnabledSelected", value="true"); + } + + if (#{pageSession.valueMap['dtraceEnabled']}=true) { + setPageSessionAttribute(key="dtraceEnabledSelected", value="true"); + } + + mapRemove(map="#{pageSession.valueMap}" key="amxEnabled"); + + setPageSessionAttribute(key="amxUrl", value="#{pageSession.parentUrl}/amx-configuration"); gf.getEntityAttrs(endpoint="#{pageSession.amxUrl}", valueMap="#{pageSession.amxMap}"); - setPageSessionAttribute(key="convertToFalseList" value={"dtraceEnabled", "monitoringEnabled", "mbeanEnabled", "enabled"}); - setPageSessionAttribute(key="skipAttrsList" value={"amxSelected"}); + mapPut(map="#{pageSession.amxMap}" key="target" value="#{pageSession.encodedConfigName}"); + setPageSessionAttribute(key="enabledSelected", value="false"); + if (#{pageSession.amxMap['enabled']}=true) { + setPageSessionAttribute(key="enabledSelected", value="true"); + } + setPageSessionAttribute(key="dynamic", value="true"); + setPageSessionAttribute(key="skipAttrsList" value={"amxEnabled"}); gf.getMonitorLevels(endpoint="#{pageSession.parentUrl}" monitorCompList="#{requestScope.tableList}") /> @@ -75,16 +101,26 @@ + onClick="if (guiValidate('#{reqMsg}','#{reqInt}','#{reqPort}')) {submitAndDisable(this, '$resource{i18n.button.Processing}');}; return false;" > $attribute{tableRowGroup}); getAllSingleMapRows(TableRowGroup="${tableRowGroup}" Rows=>$attribute{allRows}); - updateMonitorLevels(endpoint="#{pageSession.selfUrl}/module-monitoring-levels", allRows="#{requestScope.allRows}") - gf.updateEntity(endpoint="#{pageSession.selfUrl}" attrs="#{pageSession.valueMap}" + updateMonitorLevels(allRows="#{requestScope.allRows}" config="#{pageSession.configName}"); + + gf.updateEntity(endpoint="#{sessionScope.REST_URL}/set-monitoring-service-configuration" skipAttrs="#{pageSession.skipAttrsList}" + attrs="#{pageSession.valueMap}" convertToFalse="#{pageSession.convertToFalseList}" onlyUseAttrs="#{pageSession.onlyUseAttrs}" ); - gf.updateEntity(endpoint="#{pageSession.amxUrl}" attrs="#{pageSession.amxMap}" + + gf.updateEntity(endpoint="#{sessionScope.REST_URL}/set-amx-enabled" + attrs="#{pageSession.amxMap}" convertToFalse="#{pageSession.convertToFalseList}" ); prepareSuccessfulMsg(); @@ -102,13 +138,19 @@ /> - + - + + + + - + + + + "
@@ -173,4 +215,4 @@ "
#include "/common/shared/changeButtonsJS.inc" - + \ No newline at end of file diff --git a/appserver/admingui/common/src/main/resources/org/glassfish/common/admingui/Strings.properties b/appserver/admingui/common/src/main/resources/org/glassfish/common/admingui/Strings.properties index c51977da03c..0be9da8c03f 100644 --- a/appserver/admingui/common/src/main/resources/org/glassfish/common/admingui/Strings.properties +++ b/appserver/admingui/common/src/main/resources/org/glassfish/common/admingui/Strings.properties @@ -658,9 +658,13 @@ monitoring.monService=Monitoring Service: monitoring.monServiceHelp=Enable monitoring for Payara Server monitoring.monMbeans=Monitoring MBeans: monitoring.monMbeansHelp=Deploy all MBeans needed for monitoring +monitoring.monDtrace=DTrace Monitoring: +monitoring.monDtraceHelp=Enable or disable DTrace Monitoring monitoringInfo.pageHelp=View and manage the monitoring information for Payara Server instances. -monitoring.AMXEnabled=AMX Enabled -monitoring.AMXEnabledHelp=Whether or not AMX beans are enabled on startup +monitoring.AMXEnabled=AMX: +monitoring.AMXEnabledHelp=Enable or disable AMX. If enabled AMX will boot on server startup +monitoring.AMXDynamic=AMX Dynamic: +monitoring.AMXDynamicHelp=Amx can be enabled dynamically but disabling will require the server to be restarted. #monitoring Service page, Module name monitoring.module.Jvm=Jvm diff --git a/nucleus/admin/monitor/src/main/java/fish/payara/admin/monitor/cli/Constants.java b/nucleus/admin/monitor/src/main/java/fish/payara/admin/monitor/cli/Constants.java index 23ace515135..6e86be9ff8f 100644 --- a/nucleus/admin/monitor/src/main/java/fish/payara/admin/monitor/cli/Constants.java +++ b/nucleus/admin/monitor/src/main/java/fish/payara/admin/monitor/cli/Constants.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) 2018 Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) 2018-2019 Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -67,6 +67,20 @@ public final class Constants { "thread-pool", "transaction-service", "web-container", - "web-services-container" + "web-services-container", + "cloudElasticity", + "cloudOrchestrator", + "cloudTenantManager", + "cloudVirtAssemblyService", + "connectorConnectionPool", + "connectorService", + "ejbContainer", + "jdbcConnectionPool", + "jmsService", + "threadPool", + "transactionService", + "webContainer", + "webServicesContainer", + "httpService" }; } diff --git a/nucleus/admin/monitor/src/main/java/fish/payara/admin/monitor/cli/GetMonitoringServiceConfiguration.java b/nucleus/admin/monitor/src/main/java/fish/payara/admin/monitor/cli/GetMonitoringServiceConfiguration.java index b0e4e1c28e8..5aed3a7d751 100644 --- a/nucleus/admin/monitor/src/main/java/fish/payara/admin/monitor/cli/GetMonitoringServiceConfiguration.java +++ b/nucleus/admin/monitor/src/main/java/fish/payara/admin/monitor/cli/GetMonitoringServiceConfiguration.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) 2018 Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) 2018-2019 Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -103,16 +103,18 @@ public void execute(AdminCommandContext context) { AMXConfiguration amxConfiguration = config.getExtensionByType(AMXConfiguration.class); final ActionReport actionReport = context.getActionReport(); - final String[] headers= {"Enabled", "AMX Enabled", "MBeans Enabled"}; + final String[] headers= {"Monitoring Enabled", "AMX Enabled", "MBeans Enabled", "DTrace Enabled"}; ColumnFormatter columnFormatter = new ColumnFormatter(headers); - columnFormatter.addRow(new Object[]{monitoringService.getMonitoringEnabled(), amxConfiguration.getEnabled(), monitoringService.getMbeanEnabled()}); + columnFormatter.addRow(new Object[]{monitoringService.getMonitoringEnabled(), amxConfiguration.getEnabled(), + monitoringService.getMbeanEnabled(), monitoringService.getDtraceEnabled()}); actionReport.appendMessage(columnFormatter.toString()); Map extraPropertiesMap = new HashMap<>(); - extraPropertiesMap.put("enabled", monitoringService.getMonitoringEnabled()); + extraPropertiesMap.put("monitoringEnabled", monitoringService.getMonitoringEnabled()); extraPropertiesMap.put("amxEnabled", amxConfiguration.getEnabled()); - extraPropertiesMap.put("mbeansEnabled", monitoringService.getMbeanEnabled()); + extraPropertiesMap.put("mbeanEnabled", monitoringService.getMbeanEnabled()); + extraPropertiesMap.put("dtraceEnabled", monitoringService.getDtraceEnabled()); Properties extraProperties = new Properties(); extraProperties.put("getMonitoringServiceConfiguration", extraPropertiesMap); diff --git a/nucleus/admin/monitor/src/main/java/fish/payara/admin/monitor/cli/SetMonitoringLevel.java b/nucleus/admin/monitor/src/main/java/fish/payara/admin/monitor/cli/SetMonitoringLevel.java index 3aced527809..796722fdb75 100644 --- a/nucleus/admin/monitor/src/main/java/fish/payara/admin/monitor/cli/SetMonitoringLevel.java +++ b/nucleus/admin/monitor/src/main/java/fish/payara/admin/monitor/cli/SetMonitoringLevel.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) 2018 Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) 2018-2019 Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -96,7 +96,7 @@ public class SetMonitoringLevel implements AdminCommand { private String moduleNames; @Param(name = "level", optional = false) - private String moduleMonitoringLevel; + private String moduleMonitoringLevels; @Inject private Target targetUtil; @@ -118,9 +118,11 @@ public void execute(AdminCommandContext context) { actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE); } - if (moduleNames != null && moduleMonitoringLevel != null) { - List moduleNameList = Arrays.asList(moduleNames.split(",")); - List moduleLevelList = Arrays.asList(moduleMonitoringLevel.split(",")); + if (moduleNames != null && moduleMonitoringLevels != null) { + String modifiedModuleNames = moduleNames.replace(":", ","); + String modifiedModuleMonitoringLevels = moduleMonitoringLevels.replace(":", ","); + List moduleNameList = Arrays.asList(modifiedModuleNames.split(",")); + List moduleLevelList = Arrays.asList(modifiedModuleMonitoringLevels.split(",")); if (moduleNameList.size() == moduleLevelList.size()) { for (int i = 0; i < moduleLevelList.size(); i++) { @@ -128,7 +130,7 @@ public void execute(AdminCommandContext context) { List validModuleList = new ArrayList<>(Arrays.asList(Constants.validModuleNames)); String moduleName = moduleNameList.get(i).trim().toLowerCase(); for (String module : validModuleList) { - if (module.trim().equals(moduleName)) { + if (module.trim().equalsIgnoreCase(moduleName)) { String moduleLevel = moduleLevelList.get(i).trim().toUpperCase(); try { ConfigSupport.apply(new SingleConfigCode() { @@ -165,4 +167,4 @@ public Object run(final MonitoringService monitoringServiceProxy) } actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS); } -} +} \ No newline at end of file diff --git a/nucleus/admin/monitor/src/main/java/fish/payara/admin/monitor/cli/SetMonitoringServiceConfiguration.java b/nucleus/admin/monitor/src/main/java/fish/payara/admin/monitor/cli/SetMonitoringServiceConfiguration.java index 4e0336a680e..f4dd5e876f5 100644 --- a/nucleus/admin/monitor/src/main/java/fish/payara/admin/monitor/cli/SetMonitoringServiceConfiguration.java +++ b/nucleus/admin/monitor/src/main/java/fish/payara/admin/monitor/cli/SetMonitoringServiceConfiguration.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) 2018 Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) 2018-2019 Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -87,18 +87,26 @@ }) public class SetMonitoringServiceConfiguration implements AdminCommand { - @Param(name = "enabled", optional = true) - private Boolean enabled; + @Param(name = "enabled", optional = true, alias = "monitoringEnabled") + private Boolean monitoringEnabled; @Param(name = "target", optional = true, defaultValue = SystemPropertyConstants.DAS_SERVER_NAME) String target; - @Param(name = "mbeansenabled", optional = true, alias = "mbeansEnabled") - private Boolean mbeansEnabled; + @Param(name = "mbeansenabled", optional = true, alias = "mbeanEnabled") + private Boolean mbeanEnabled; + /** + * + * @deprecated Since 5.194. Use set-amx-enabled command instead. + */ + @Deprecated @Param(name = "amxenabled", optional = true, alias = "amxEnabled") private Boolean amxEnabled; + @Param(name = "dtraceenabled", optional = true, alias = "dtraceEnabled") + private Boolean dtraceEnabled; + @Inject protected Target targetUtil; @@ -128,12 +136,16 @@ public void execute(AdminCommandContext context) { ConfigSupport.apply(new SingleConfigCode() { @Override public Object run(final MonitoringService monitoringServiceProxy) throws PropertyVetoException, TransactionFailure { - if (enabled != null) { - monitoringServiceProxy.setMonitoringEnabled(String.valueOf(enabled)); + if (monitoringEnabled != null) { + monitoringServiceProxy.setMonitoringEnabled(String.valueOf(monitoringEnabled)); } - if (mbeansEnabled != null) { - monitoringServiceProxy.setMbeanEnabled(String.valueOf(mbeansEnabled)); + if (mbeanEnabled != null) { + monitoringServiceProxy.setMbeanEnabled(String.valueOf(mbeanEnabled)); + } + + if (dtraceEnabled != null) { + monitoringServiceProxy.setDtraceEnabled(String.valueOf(dtraceEnabled)); } if (amxEnabled != null) { @@ -157,4 +169,4 @@ public Object run(final AMXConfiguration amxConfigurationProxy) throws PropertyV actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE); } } -} +} \ No newline at end of file diff --git a/nucleus/common/amx-core/src/main/java/fish/payara/admin/amx/AMXBootService.java b/nucleus/common/amx-core/src/main/java/fish/payara/admin/amx/AMXBootService.java index 178fac07277..6badf4aaf84 100644 --- a/nucleus/common/amx-core/src/main/java/fish/payara/admin/amx/AMXBootService.java +++ b/nucleus/common/amx-core/src/main/java/fish/payara/admin/amx/AMXBootService.java @@ -72,6 +72,7 @@ public class AMXBootService implements ConfigListener { ServiceLocator habitat; private boolean enabled; + private boolean dynamic; @PostConstruct public void postConstruct(){ @@ -87,32 +88,27 @@ private void startup(){ bootAMX.bootAMX(); } - public void setEnabled(boolean enabled){ + public void setEnabled(boolean enabled, boolean dynamic) { this.enabled = enabled; - if (enabled){ + this.dynamic = dynamic; + if (enabled && dynamic) { startup(); - } + } } @Override public UnprocessedChangeEvents changed(PropertyChangeEvent[] events) { UnprocessedChangeEvents unchanged = null; - for (PropertyChangeEvent event: events){ - if (event.getPropertyName().contains("enabled")){ + + for (PropertyChangeEvent event : events) { + if (event.getPropertyName().contains("enabled")) { String change = (String) event.getNewValue(); - if (change.equalsIgnoreCase("false")){ - unchanged = new UnprocessedChangeEvents(new UnprocessedChangeEvent(event, "Unable to stop AMX dynamically")); - } else if (change.equalsIgnoreCase("true")){ - setEnabled(true); - } else { - throw new IllegalArgumentException("Not boolean change" + event.toString()); + if (change.equalsIgnoreCase("false") && dynamic) { + unchanged = new UnprocessedChangeEvents(new UnprocessedChangeEvent(event, "AMX can't be disabled dynamically.")); } } } return unchanged; } - - - } diff --git a/nucleus/common/amx-core/src/main/java/fish/payara/admin/amx/cli/SetAmxEnabled.java b/nucleus/common/amx-core/src/main/java/fish/payara/admin/amx/cli/SetAmxEnabled.java index 421e8f32b54..c9f39efba32 100644 --- a/nucleus/common/amx-core/src/main/java/fish/payara/admin/amx/cli/SetAmxEnabled.java +++ b/nucleus/common/amx-core/src/main/java/fish/payara/admin/amx/cli/SetAmxEnabled.java @@ -43,6 +43,7 @@ package fish.payara.admin.amx.cli; import com.sun.enterprise.config.serverbeans.Config; +import com.sun.enterprise.config.serverbeans.Domain; import fish.payara.admin.amx.AMXBootService; import fish.payara.admin.amx.config.AMXConfiguration; import java.beans.PropertyVetoException; @@ -58,12 +59,6 @@ import org.glassfish.api.admin.RestEndpoint; import org.glassfish.api.admin.RestEndpoints; import org.glassfish.api.admin.RuntimeType; -import static org.glassfish.config.support.CommandTarget.CLUSTER; -import static org.glassfish.config.support.CommandTarget.CLUSTERED_INSTANCE; -import static org.glassfish.config.support.CommandTarget.CONFIG; -import static org.glassfish.config.support.CommandTarget.DAS; -import static org.glassfish.config.support.CommandTarget.DEPLOYMENT_GROUP; -import static org.glassfish.config.support.CommandTarget.STANDALONE_INSTANCE; import org.glassfish.config.support.TargetType; import org.glassfish.hk2.api.PerLookup; import org.glassfish.hk2.api.ServiceLocator; @@ -73,6 +68,13 @@ import org.jvnet.hk2.config.SingleConfigCode; import org.jvnet.hk2.config.TransactionFailure; +import static org.glassfish.config.support.CommandTarget.CLUSTER; +import static org.glassfish.config.support.CommandTarget.CLUSTERED_INSTANCE; +import static org.glassfish.config.support.CommandTarget.CONFIG; +import static org.glassfish.config.support.CommandTarget.DAS; +import static org.glassfish.config.support.CommandTarget.DEPLOYMENT_GROUP; +import static org.glassfish.config.support.CommandTarget.STANDALONE_INSTANCE; + /** * Comment to enable AMX, as separate from JMX. *

@@ -82,10 +84,10 @@ */ @Service(name = "set-amx-enabled") @PerLookup -@ExecuteOn({RuntimeType.ALL}) +@ExecuteOn({RuntimeType.DAS}) @TargetType({DAS, DEPLOYMENT_GROUP, STANDALONE_INSTANCE, CLUSTER, CLUSTERED_INSTANCE, CONFIG}) @RestEndpoints({ - @RestEndpoint(configBean = AMXConfiguration.class, + @RestEndpoint(configBean = Domain.class, opType = RestEndpoint.OpType.POST, path = "set-amx-enabled", description = "Sets whether AMX in enabled") @@ -94,10 +96,10 @@ public class SetAmxEnabled implements AdminCommand { private static final Logger LOGGER = AMXLoggerInfo.getLogger(); - @Param(name = "enabled", optional = false, primary = true, defaultValue = "true") + @Param(name = "enabled", optional = true, defaultValue = "true") Boolean enabled; - @Param(name = "dynamic", optional = false, defaultValue = "true") + @Param(name = "dynamic", optional = true, defaultValue = "true") private Boolean dynamic; @Param(name="target", optional = true, defaultValue = "server-config") @@ -126,10 +128,8 @@ public Object run(final AMXConfiguration configProxy) throws PropertyVetoExcepti } }, metricsConfiguration); - if (dynamic) { - AMXBootService bootService = habitat.getService(AMXBootService.class); - bootService.setEnabled(enabled); - } + AMXBootService bootService = habitat.getService(AMXBootService.class); + bootService.setEnabled(enabled, dynamic); } catch (TransactionFailure ex) { LOGGER.log(Level.WARNING, "Exception during command set-amx-enabled: {0}", ex.getCause().getMessage()); From 81f87239ac175e26affc4fc2fbe0c5338a618696 Mon Sep 17 00:00:00 2001 From: merorai Date: Thu, 7 Nov 2019 13:05:30 +0000 Subject: [PATCH 2/2] Command is now replicated among instances in a Deployment Group --- .../enterprise/config/serverbeans/Domain.java | 21 +++++++-------- .../config/support/CommandTarget.java | 4 +-- .../cluster/CreateLocalInstanceCommand.java | 27 +++++++++++-------- .../payara/admin/amx/cli/SetAmxEnabled.java | 2 +- 4 files changed, 28 insertions(+), 26 deletions(-) diff --git a/nucleus/admin/config-api/src/main/java/com/sun/enterprise/config/serverbeans/Domain.java b/nucleus/admin/config-api/src/main/java/com/sun/enterprise/config/serverbeans/Domain.java index 1146558c329..c8482280b89 100644 --- a/nucleus/admin/config-api/src/main/java/com/sun/enterprise/config/serverbeans/Domain.java +++ b/nucleus/admin/config-api/src/main/java/com/sun/enterprise/config/serverbeans/Domain.java @@ -47,6 +47,15 @@ import fish.payara.enterprise.config.serverbeans.DGServerRef; import fish.payara.enterprise.config.serverbeans.DeploymentGroup; import fish.payara.enterprise.config.serverbeans.DeploymentGroups; +import java.beans.PropertyVetoException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.validation.constraints.NotNull; import org.glassfish.api.admin.config.ApplicationName; import org.glassfish.api.admin.config.PropertiesDesc; import org.glassfish.api.admin.config.PropertyDesc; @@ -61,16 +70,6 @@ import org.jvnet.hk2.config.types.Property; import org.jvnet.hk2.config.types.PropertyBag; -import javax.validation.constraints.NotNull; -import java.beans.PropertyVetoException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; - /** * Top level Domain Element that includes applications, resources, configs, @@ -917,7 +916,7 @@ public static List getAllTargets(Domain d) { // only add non-clustered servers as the cluster // targets will be separately added for (Server server : d.getServers().getServer()) { - if (server.getCluster() == null && server.getDeploymentGroup().isEmpty()) { + if (server.getCluster() == null) { targets.add(server.getName()); } } diff --git a/nucleus/admin/config-api/src/main/java/org/glassfish/config/support/CommandTarget.java b/nucleus/admin/config-api/src/main/java/org/glassfish/config/support/CommandTarget.java index bbeb0ff0e4a..185726a3c3f 100644 --- a/nucleus/admin/config-api/src/main/java/org/glassfish/config/support/CommandTarget.java +++ b/nucleus/admin/config-api/src/main/java/org/glassfish/config/support/CommandTarget.java @@ -41,8 +41,6 @@ package org.glassfish.config.support; import com.sun.enterprise.config.serverbeans.*; - - import org.glassfish.hk2.api.ServiceLocator; /** @@ -140,7 +138,7 @@ public String getDescription() { } }, /** - * a cluster configuration change + * a Deployment Group configuration change */ DEPLOYMENT_GROUP { @Override diff --git a/nucleus/cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/CreateLocalInstanceCommand.java b/nucleus/cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/CreateLocalInstanceCommand.java index 7a50fec8097..78a242b25c2 100644 --- a/nucleus/cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/CreateLocalInstanceCommand.java +++ b/nucleus/cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/CreateLocalInstanceCommand.java @@ -43,14 +43,6 @@ package com.sun.enterprise.admin.cli.cluster; -import static com.sun.enterprise.admin.servermgmt.domain.DomainConstants.MASTERPASSWORD_FILE; - -import java.io.File; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.ArrayList; -import java.util.logging.Level; - import com.sun.enterprise.admin.cli.CLIConstants; import com.sun.enterprise.admin.cli.remote.RemoteCLICommand; import com.sun.enterprise.admin.servermgmt.KeystoreManager; @@ -60,7 +52,13 @@ import com.sun.enterprise.util.OS; import com.sun.enterprise.util.SystemPropertyConstants; import com.sun.enterprise.util.io.FileUtils; - +import fish.payara.admin.cli.cluster.NamingHelper; +import fish.payara.util.cluster.PayaraServerNameGenerator; +import java.io.File; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.logging.Level; import org.glassfish.api.ActionReport; import org.glassfish.api.I18n; import org.glassfish.api.Param; @@ -70,8 +68,7 @@ import org.glassfish.security.common.FileProtectionUtility; import org.jvnet.hk2.annotations.Service; -import fish.payara.admin.cli.cluster.NamingHelper; -import fish.payara.util.cluster.PayaraServerNameGenerator; +import static com.sun.enterprise.admin.servermgmt.domain.DomainConstants.MASTERPASSWORD_FILE; /** @@ -86,12 +83,16 @@ public final class CreateLocalInstanceCommand extends CreateLocalInstanceFilesystemCommand { private static final String CONFIG = "config"; private static final String CLUSTER = "cluster"; + private static final String DEPLOYMENT_GROUP = "deploymentGroup"; @Param(name = CONFIG, optional = true) private String configName; @Param(name = CLUSTER, optional = true) private String clusterName; + + @Param(name = DEPLOYMENT_GROUP, optional = true) + private String deploymentGroup; @Param(name="lbenabled", optional = true) private Boolean lbEnabled; @@ -351,6 +352,10 @@ private int registerToDAS() throws CommandException { argsList.add("--cluster"); argsList.add(clusterName); } + if (deploymentGroup != null) { + argsList.add("--deploymentgroup"); + argsList.add(deploymentGroup); + } if (lbEnabled != null) { argsList.add("--lbenabled"); argsList.add(lbEnabled.toString()); diff --git a/nucleus/common/amx-core/src/main/java/fish/payara/admin/amx/cli/SetAmxEnabled.java b/nucleus/common/amx-core/src/main/java/fish/payara/admin/amx/cli/SetAmxEnabled.java index c9f39efba32..d0b2fdd00d1 100644 --- a/nucleus/common/amx-core/src/main/java/fish/payara/admin/amx/cli/SetAmxEnabled.java +++ b/nucleus/common/amx-core/src/main/java/fish/payara/admin/amx/cli/SetAmxEnabled.java @@ -84,7 +84,7 @@ */ @Service(name = "set-amx-enabled") @PerLookup -@ExecuteOn({RuntimeType.DAS}) +@ExecuteOn({RuntimeType.DAS, RuntimeType.INSTANCE}) @TargetType({DAS, DEPLOYMENT_GROUP, STANDALONE_INSTANCE, CLUSTER, CLUSTERED_INSTANCE, CONFIG}) @RestEndpoints({ @RestEndpoint(configBean = Domain.class,