From 4e971744d5ca5eeaa665b8195134c7d8d0a668cb Mon Sep 17 00:00:00 2001 From: Rhys Williams <170514543+Viii3@users.noreply.github.com> Date: Tue, 17 Dec 2024 10:30:11 +0000 Subject: [PATCH 1/3] FISH-10318: Add singular version of create-system-properties. --- .../com/sun/enterprise/v3/admin/CLIUtil.java | 3 +- .../admin/CreateSystemProperty.java | 147 ++++++++++++++++++ .../enterprise/admin/LocalStrings.properties | 46 ++++++ .../v3/admin/create-system-properties.1 | 4 +- .../v3/admin/delete-system-property.1 | 4 +- .../v3/admin/list-system-properties.1 | 4 +- .../enterprise/admin/create-system-property.1 | 92 +++++++++++ 7 files changed, 293 insertions(+), 7 deletions(-) create mode 100644 nucleus/core/kernel/src/main/java/fish/payara/enterprise/admin/CreateSystemProperty.java create mode 100644 nucleus/core/kernel/src/main/java/fish/payara/enterprise/admin/LocalStrings.properties create mode 100644 nucleus/core/kernel/src/main/manpages/fish/payara/enterprise/admin/create-system-property.1 diff --git a/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/admin/CLIUtil.java b/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/admin/CLIUtil.java index 7d3daf7f03d..f5d9a9afc90 100644 --- a/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/admin/CLIUtil.java +++ b/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/admin/CLIUtil.java @@ -37,6 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ +// Portions Copyright 2024 Payara Foundation and/or affiliates package com.sun.enterprise.v3.admin; import com.sun.enterprise.config.serverbeans.Config; @@ -61,7 +62,7 @@ static Config chooseConfig(final Target targetService, return config; } - static SystemPropertyBag chooseTarget(final Domain domain, final String target) { + public static SystemPropertyBag chooseTarget (final Domain domain, final String target) { SystemPropertyBag spb = null; Property domainProp = domain.getProperty("administrative.domain.name"); String domainName = domainProp.getValue(); diff --git a/nucleus/core/kernel/src/main/java/fish/payara/enterprise/admin/CreateSystemProperty.java b/nucleus/core/kernel/src/main/java/fish/payara/enterprise/admin/CreateSystemProperty.java new file mode 100644 index 00000000000..032e040a92a --- /dev/null +++ b/nucleus/core/kernel/src/main/java/fish/payara/enterprise/admin/CreateSystemProperty.java @@ -0,0 +1,147 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2024 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 + * 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://github.com/payara/Payara/blob/main/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 glassfish/legal/LICENSE.txt. + * + * GPL Classpath Exception: + * The Payara Foundation designates this particular file as subject to the "Classpath" + * exception as provided by the Payara Foundation in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package fish.payara.enterprise.admin; + +import com.sun.enterprise.config.serverbeans.Domain; +import com.sun.enterprise.config.serverbeans.SystemProperty; +import com.sun.enterprise.config.serverbeans.SystemPropertyBag; +import com.sun.enterprise.util.LocalStringManagerImpl; +import com.sun.enterprise.util.SystemPropertyConstants; +import com.sun.enterprise.v3.admin.CLIUtil; +import com.sun.enterprise.v3.admin.CreateSystemProperties; +import jakarta.inject.Inject; +import org.glassfish.api.ActionReport; +import org.glassfish.api.I18n; +import org.glassfish.api.Param; +import org.glassfish.api.admin.AccessRequired; +import org.glassfish.api.admin.AdminCommand; +import org.glassfish.api.admin.AdminCommandContext; +import org.glassfish.api.admin.AdminCommandSecurity; +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.jvnet.hk2.annotations.Service; +import org.jvnet.hk2.config.ConfigSupport; +import org.jvnet.hk2.config.Transaction; + +import java.util.ArrayList; +import java.util.Collection; + +@Service(name="create-system-property") +@PerLookup +@ExecuteOn({RuntimeType.DAS, RuntimeType.INSTANCE}) +@TargetType(value={CommandTarget.CLUSTER, + CommandTarget.CONFIG, CommandTarget.DAS, CommandTarget.DOMAIN, CommandTarget.STANDALONE_INSTANCE,CommandTarget.CLUSTERED_INSTANCE}) +@I18n("create.system.property") +public class CreateSystemProperty implements AdminCommand, AdminCommandSecurity.Preauthorization, AdminCommandSecurity.AccessCheckProvider { + final private static LocalStringManagerImpl localStrings = new LocalStringManagerImpl(CreateSystemProperties.class); + + @Param(optional=true, defaultValue=SystemPropertyConstants.DAS_SERVER_NAME) + String target; + + @Param(name="name") + String propertyName; + + @Param(name="value") + String propertyValue; + + @Inject + Domain domain; + + private SystemPropertyBag spb; + + @Override + public void execute (AdminCommandContext context) { + final ActionReport report = context.getActionReport(); + + try { + ConfigSupport.apply(propertyBag -> { + // update existing system property + for (SystemProperty property : propertyBag.getSystemProperty()) { + if (property.getName().equals(propertyName)) { + Transaction transaction = Transaction.getTransaction(propertyBag); + property = transaction.enroll(property); + property.setValue(propertyValue); + return property; + } + } + + // create system-property + SystemProperty newSysProp = propertyBag.createChild(SystemProperty.class); + newSysProp.setName(propertyName); + newSysProp.setValue(propertyValue); + propertyBag.getSystemProperty().add(newSysProp); + return newSysProp; + }, spb); + report.setActionExitCode(ActionReport.ExitCode.SUCCESS); + } catch(Exception e) { + report.setMessage(localStrings.getLocalString("create.system.property.failed", + "System property {0} creation failed", propertyName)); + report.setActionExitCode(ActionReport.ExitCode.FAILURE); + report.setFailureCause(e); + } + } + + @Override + public Collection> getAccessChecks () { + final Collection> result = new ArrayList<>(); + result.add(new AccessRequired.AccessCheck<>(AccessRequired.Util.resourceNameFromConfigBeanProxy(spb), "update")); + return result; + } + + @Override + public boolean preAuthorization (AdminCommandContext context) { + this.spb = CLIUtil.chooseTarget(domain, target); + if (this.spb == null) { + final ActionReport report = context.getActionReport(); + report.setActionExitCode(ActionReport.ExitCode.FAILURE); + String msg = localStrings.getLocalString( + "invalid.target.sys.props", + "Invalid target:{0}. Valid targets types are domain, config, cluster, default server, clustered instance, stand alone instance", target + ); + report.setMessage(msg); + return false; + } + return true; + } +} diff --git a/nucleus/core/kernel/src/main/java/fish/payara/enterprise/admin/LocalStrings.properties b/nucleus/core/kernel/src/main/java/fish/payara/enterprise/admin/LocalStrings.properties new file mode 100644 index 00000000000..ecfb97220ff --- /dev/null +++ b/nucleus/core/kernel/src/main/java/fish/payara/enterprise/admin/LocalStrings.properties @@ -0,0 +1,46 @@ +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright (c) 2024 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 +# 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://github.com/payara/Payara/blob/main/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 glassfish/legal/LICENSE.txt. +# +# GPL Classpath Exception: +# The Payara Foundation designates this particular file as subject to the "Classpath" +# exception as provided by the Payara Foundation in the GPL Version 2 section of the License +# file that accompanied this code. +# +# Modifications: +# If applicable, add the following below the License Header, with the fields +# enclosed by brackets [] replaced by your own identifying information: +# "Portions Copyright [year] [name of copyright owner]" +# +# Contributor(s): +# If you wish your version of this file to be governed by only the CDDL or +# only the GPL Version 2, indicate your decision by adding "[Contributor] +# elects to include this software in this distribution under the [CDDL or GPL +# Version 2] license." If you don't indicate a single choice of license, a +# recipient has the option to distribute your version of this file under +# either the CDDL, the GPL Version 2 or to extend the choice of license to +# its licensees as provided above. However, if you add GPL Version 2 code +# and therefore, elected the GPL Version 2 license, then the option applies +# only if the new code is made subject to such option by the copyright +# holder. +# + +create.system.property=adds or updates a single system property of the domain, configuration, cluster, or server instance +create.system.property.name=The name of the property to add or update. +create.system.property.value=The value to assign to the named property. +create.system.property.existsAlready=System property {0} already exists. +create.system.property.failed=System property {0} creation failed. +create.system.property.success=System property {0} created successfully. \ No newline at end of file diff --git a/nucleus/core/kernel/src/main/manpages/com/sun/enterprise/v3/admin/create-system-properties.1 b/nucleus/core/kernel/src/main/manpages/com/sun/enterprise/v3/admin/create-system-properties.1 index f35077b8673..e6b785a52a1 100644 --- a/nucleus/core/kernel/src/main/manpages/com/sun/enterprise/v3/admin/create-system-properties.1 +++ b/nucleus/core/kernel/src/main/manpages/com/sun/enterprise/v3/admin/create-system-properties.1 @@ -81,8 +81,8 @@ EXIT STATUS error in executing the subcommand SEE ALSO - delete-system-property(1), list-system-properties(1) + create-system-property(1), delete-system-property(1), list-system-properties(1) asadmin(1M) -Java EE 8 09 Aug 2017 create-system-properties(1) +Java EE 8 17 Dec 2024 create-system-properties(1) diff --git a/nucleus/core/kernel/src/main/manpages/com/sun/enterprise/v3/admin/delete-system-property.1 b/nucleus/core/kernel/src/main/manpages/com/sun/enterprise/v3/admin/delete-system-property.1 index 17fce6455f6..c8a7918ced0 100644 --- a/nucleus/core/kernel/src/main/manpages/com/sun/enterprise/v3/admin/delete-system-property.1 +++ b/nucleus/core/kernel/src/main/manpages/com/sun/enterprise/v3/admin/delete-system-property.1 @@ -45,8 +45,8 @@ EXIT STATUS error in executing the subcommand SEE ALSO - create-system-properties(1), list-system-properties(1) + create-system-property(1), create-system-properties(1), list-system-properties(1) asadmin(1M) -Java EE 8 09 Aug 2017 delete-system-property(1) +Java EE 8 17 Dec 2024 delete-system-property(1) diff --git a/nucleus/core/kernel/src/main/manpages/com/sun/enterprise/v3/admin/list-system-properties.1 b/nucleus/core/kernel/src/main/manpages/com/sun/enterprise/v3/admin/list-system-properties.1 index 3dff5dd82e4..2c8234ad378 100644 --- a/nucleus/core/kernel/src/main/manpages/com/sun/enterprise/v3/admin/list-system-properties.1 +++ b/nucleus/core/kernel/src/main/manpages/com/sun/enterprise/v3/admin/list-system-properties.1 @@ -56,8 +56,8 @@ EXIT STATUS error in executing the subcommand SEE ALSO - create-system-properties(1), delete-system-property(1) + create-system-property(1), create-system-properties(1), delete-system-property(1) asadmin(1M) -Java EE 8 09 Aug 2017 list-system-properties(1) +Java EE 8 17 Dec 2024 list-system-properties(1) diff --git a/nucleus/core/kernel/src/main/manpages/fish/payara/enterprise/admin/create-system-property.1 b/nucleus/core/kernel/src/main/manpages/fish/payara/enterprise/admin/create-system-property.1 new file mode 100644 index 00000000000..6c4c2080a63 --- /dev/null +++ b/nucleus/core/kernel/src/main/manpages/fish/payara/enterprise/admin/create-system-property.1 @@ -0,0 +1,92 @@ +create-system-property(1) asadmin Utility Subcommands create-system-property(1) + +NAME + create-system-property - adds or updates a single system property + of the domain, configuration, cluster, or server instance + +SYNOPSIS + create-system-property [--help] + [--target target] + [--name name] [--value value] + +DESCRIPTION + The create-system-property subcommand adds or updates a single system + property that can be referenced elsewhere on the server. + + Payara Server provides hooks where tokens (system properties) can be + specified. Because Payara Server does not have multiple server + elements, you can specify a particular token at any level. When a + domain supports multiple servers, the override potential can be + exploited. When a domain is started or restarted, all + elements are resolved and available to the Java Virtual Machine by + using the System.setProperty() call on each of them (with its name and + value derived from the corresponding attributes of the element). This + is analogous to sending the elements as -D parameters on the Java + command line. + + This subcommand is supported in remote mode only. + +OPTIONS + --help, -? + Displays the help text for the subcommand. + + --target + The target on which you are creating the system property. + + --name + The name of the property to add or update. + + --value + The value to assign to the named property. + +OPERANDS + target + The valid targets for this subcommand are instance, cluster, + configuration, domain, and server. Server is the default option. + Valid values are: + + server + Creates the property on the default server instance. This is + the default value. + + domain + Creates the property for all server instances in the default + domain. + + configuration_name + Creates the property in the specified configuration. + + cluster_name + Creates the property on all server instances in the specified + cluster. + + instance_name + Creates the property on a specified server instance. + + name + The name of the property to add or update. + + value + The value to assign to the named property. + +EXAMPLES + Example 1, Creating System Property + This example creates a system property associated with an HTTP + listener on a server instance named myserver. + + asadmin> create-system-property --target myserver --name http-listener-port --value 1088 + Command create-system-property executed successfully. + +EXIT STATUS + 0 + subcommand executed successfully + + 1 + error in executing the subcommand + +SEE ALSO + create-system-properties(1), delete-system-property(1), list-system-properties(1) + + asadmin(1M) + +Java EE 8 17 Dec 2024 create-system-property(1) From 8edc42801678cd7e3bc2baafefb737489f1d3f24 Mon Sep 17 00:00:00 2001 From: Rhys Williams <170514543+Viii3@users.noreply.github.com> Date: Wed, 18 Dec 2024 10:30:39 +0000 Subject: [PATCH 2/3] FISH-10319: Implement feedback. --- .../enterprise/admin/CreateSystemProperty.java | 14 ++++++++------ .../enterprise/admin/LocalStrings.properties | 3 +-- .../enterprise/admin/create-system-property.1 | 15 +++------------ 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/nucleus/core/kernel/src/main/java/fish/payara/enterprise/admin/CreateSystemProperty.java b/nucleus/core/kernel/src/main/java/fish/payara/enterprise/admin/CreateSystemProperty.java index 032e040a92a..291c5aa555a 100644 --- a/nucleus/core/kernel/src/main/java/fish/payara/enterprise/admin/CreateSystemProperty.java +++ b/nucleus/core/kernel/src/main/java/fish/payara/enterprise/admin/CreateSystemProperty.java @@ -79,11 +79,8 @@ public class CreateSystemProperty implements AdminCommand, AdminCommandSecurity. @Param(optional=true, defaultValue=SystemPropertyConstants.DAS_SERVER_NAME) String target; - @Param(name="name") - String propertyName; - - @Param(name="value") - String propertyValue; + @Param(name="name_value", primary=true) + String propertyAssignment; @Inject Domain domain; @@ -93,8 +90,13 @@ public class CreateSystemProperty implements AdminCommand, AdminCommandSecurity. @Override public void execute (AdminCommandContext context) { final ActionReport report = context.getActionReport(); + String[] assignment = propertyAssignment.split("="); + String propertyName; + String propertyValue; try { + propertyName = assignment[0]; + propertyValue = assignment[1]; ConfigSupport.apply(propertyBag -> { // update existing system property for (SystemProperty property : propertyBag.getSystemProperty()) { @@ -116,7 +118,7 @@ public void execute (AdminCommandContext context) { report.setActionExitCode(ActionReport.ExitCode.SUCCESS); } catch(Exception e) { report.setMessage(localStrings.getLocalString("create.system.property.failed", - "System property {0} creation failed", propertyName)); + "System property {0} creation failed", propertyAssignment)); report.setActionExitCode(ActionReport.ExitCode.FAILURE); report.setFailureCause(e); } diff --git a/nucleus/core/kernel/src/main/java/fish/payara/enterprise/admin/LocalStrings.properties b/nucleus/core/kernel/src/main/java/fish/payara/enterprise/admin/LocalStrings.properties index ecfb97220ff..782c7e5718d 100644 --- a/nucleus/core/kernel/src/main/java/fish/payara/enterprise/admin/LocalStrings.properties +++ b/nucleus/core/kernel/src/main/java/fish/payara/enterprise/admin/LocalStrings.properties @@ -39,8 +39,7 @@ # create.system.property=adds or updates a single system property of the domain, configuration, cluster, or server instance -create.system.property.name=The name of the property to add or update. -create.system.property.value=The value to assign to the named property. +create.system.property.name_value=The system property assignment to create. create.system.property.existsAlready=System property {0} already exists. create.system.property.failed=System property {0} creation failed. create.system.property.success=System property {0} created successfully. \ No newline at end of file diff --git a/nucleus/core/kernel/src/main/manpages/fish/payara/enterprise/admin/create-system-property.1 b/nucleus/core/kernel/src/main/manpages/fish/payara/enterprise/admin/create-system-property.1 index 6c4c2080a63..9e0c689d6da 100644 --- a/nucleus/core/kernel/src/main/manpages/fish/payara/enterprise/admin/create-system-property.1 +++ b/nucleus/core/kernel/src/main/manpages/fish/payara/enterprise/admin/create-system-property.1 @@ -33,12 +33,6 @@ OPTIONS --target The target on which you are creating the system property. - --name - The name of the property to add or update. - - --value - The value to assign to the named property. - OPERANDS target The valid targets for this subcommand are instance, cluster, @@ -63,18 +57,15 @@ OPERANDS instance_name Creates the property on a specified server instance. - name - The name of the property to add or update. - - value - The value to assign to the named property. + name_value + The system property to assign. In the form of "PropertyName=PropertyValue" EXAMPLES Example 1, Creating System Property This example creates a system property associated with an HTTP listener on a server instance named myserver. - asadmin> create-system-property --target myserver --name http-listener-port --value 1088 + asadmin> create-system-property --target myserver http-listener-port=1088 Command create-system-property executed successfully. EXIT STATUS From ede2ea0ae7f7d4c475ff87bd0d86de8961e9291a Mon Sep 17 00:00:00 2001 From: Andrew Pielage Date: Wed, 18 Dec 2024 15:29:22 +0000 Subject: [PATCH 3/3] Adjust help doc --- .../fish/payara/enterprise/admin/create-system-property.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nucleus/core/kernel/src/main/manpages/fish/payara/enterprise/admin/create-system-property.1 b/nucleus/core/kernel/src/main/manpages/fish/payara/enterprise/admin/create-system-property.1 index 9e0c689d6da..a93aae6f35a 100644 --- a/nucleus/core/kernel/src/main/manpages/fish/payara/enterprise/admin/create-system-property.1 +++ b/nucleus/core/kernel/src/main/manpages/fish/payara/enterprise/admin/create-system-property.1 @@ -7,7 +7,7 @@ NAME SYNOPSIS create-system-property [--help] [--target target] - [--name name] [--value value] + [name=value] DESCRIPTION The create-system-property subcommand adds or updates a single system