Skip to content

Commit

Permalink
FISH-9198 Move to appserver-modules
Browse files Browse the repository at this point in the history
  • Loading branch information
kalinchan committed Oct 7, 2024
1 parent f69b4eb commit 61cbe56
Show file tree
Hide file tree
Showing 15 changed files with 160 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ config.property.configuration.moduleNameHelp=The name of the module when the Con

config.secretsDirectory.configuration.directory=Directory
config.secretsDirectory.configuration.directoryHelp=Full path to the directory containing configuration files.
config.toml.configuration.enabledLabel=Enabled
config.toml.configuration.enabledHelpText=Enable the config source, which fetches data from the specified TOML file
config.toml.configuration.dynamicLabel=Dynamic
config.toml.configuration.dynamicHelpText=Configure the config source dynamically, which will not require a restart
config.toml.configuration.path=Path
config.toml.configuration.pathHelp=Full path to the TOML configuration file.
config.toml.configuration.depth=Depth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,20 @@
getRequestValue(key="configName" value="#{pageSession.configName}");
setPageSessionAttribute(key="MICROPROFILE_CONFIG_URL",
value="#{sessionScope.REST_URL}/configs/config/#{pageSession.configName}/microprofile-config");
gf.restRequest(endpoint="#{pageSession.MICROPROFILE_CONFIG_URL}/get-toml-configuration?target=#{pageSession.configName}"
gf.restRequest(endpoint="#{pageSession.MICROPROFILE_CONFIG_URL}/get-toml-config-source-configuration?target=#{pageSession.configName}"
method="GET" result="#{requestScope.resp}");

setPageSessionAttribute(key="valueMap",
value="#{requestScope.resp.data.extraProperties.toml}");
value="#{requestScope.resp.data.extraProperties.configSourceConfiguration}");
mapPut(map="#{pageSession.valueMap}" key="target" value="#{pageSession.configName}");
/>

setPageSessionAttribute(key="convertToFalseList", value={"enabled"});

if (#{pageSession.valueMap['enabled']}=true) {
setPageSessionAttribute(key="enabledSelected", value="true");
}
setPageSessionAttribute(key="dynamic", value="true");
/>
</event>


Expand All @@ -75,9 +82,11 @@
onClick="if (guiValidate('#{reqMsg}','#{reqInt}','#{reqPort}'))
submitAndDisable(this, '$resource{i18n.button.Processing}'); return false;" >
<!command
mapPut(map="#{pageSession.valueMap}" key="enabled" value="#{pageSession.enabledSelected}");
mapPut(map="#{pageSession.valueMap}" key="dynamic" value="#{pageSession.dynamic}");
prepareSuccessfulMsg();
gf.restRequest(endpoint="#{pageSession.MICROPROFILE_CONFIG_URL}/set-toml-configuration"
method="POST" attrs="#{pageSession.valueMap}");
gf.updateEntity(endpoint="#{pageSession.MICROPROFILE_CONFIG_URL}/set-toml-config-source-configuration"
attrs="#{pageSession.valueMap}" convertToFalse="#{pageSession.convertToFalseList}");
/>
</sun:button>
</sun:panelGroup>
Expand All @@ -86,17 +95,29 @@
<sun:propertySheet id="propertySheet">
#include "/common/shared/configNameSection.inc"
<sun:propertySheetSection id="tomlProps">
<sun:property id="enabledProp" labelAlign="left" noWrap="#{true}" overlapLabel="#{false}"
label="$resource{i18n_microprofile.config.toml.configuration.enabledLabel}"
helpText="$resource{i18n_microprofile.config.toml.configuration.enabledHelpText}">
<sun:checkbox id="enabledProp" selected="#{pageSession.enabledSelected}" selectedValue="true" />
</sun:property>
<sun:property id="dynamic" labelAlign="left" noWrap="#{true}" overlapLabel="#{false}"
label="$resource{i18n_microprofile.config.toml.configuration.dynamicLabel}"
helpText="$resource{i18n_microprofile.config.toml.configuration.dynamicHelpText}">
<sun:checkbox id="dynamic" selected="#{pageSession.dynamic}" selectedValue="true" />
</sun:property>
<sun:property id="tomlPath" labelAlign="left" noWrap="#{true}" overlapLabel="#{false}"
label="$resource{i18n_microprofile.config.toml.configuration.path}"
helpText="$resource{i18n_microprofile.config.toml.configuration.pathHelp}">
<sun:textField id="endPoint" columns="$int{40}" maxLength="250"
text="#{pageSession.valueMap['path']}"/>
<sun:textField id="tomlPathField" columns="$int{40}" maxLength="250"
text="#{pageSession.valueMap['path']}" styleClass="required"
required="#{true}"/>
</sun:property>
<sun:property id="tomlDepth" labelAlign="left" noWrap="#{true}" overlapLabel="#{false}"
label="$resource{i18n_microprofile.config.toml.configuration.depth}"
helpText="$resource{i18n_microprofile.config.toml.configuration.depthHelp}">
<sun:textField id="endPoint" columns="$int{40}" maxLength="250"
text="#{pageSession.valueMap['depth']}"/>
<sun:textField id="tomlDepthField" columns="$int{40}" maxLength="250"
text="#{pageSession.valueMap['depth']}" styleClass="required"
required="#{true}"/>
</sun:property>
</sun:propertySheetSection>
</sun:propertySheet>
Expand Down
2 changes: 1 addition & 1 deletion appserver/packager/appserver-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@
<dependency>
<groupId>fish.payara.server.internal.packager</groupId>
<artifactId>tomlj-repackaged</artifactId>
<version>6.2024.10-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
5 changes: 5 additions & 0 deletions appserver/packager/external/tomlj-repackaged/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
<description>tomlj repackaged as a module</description>
<packaging>jar</packaging>

<properties>
<tomlj.version>1.1.1</tomlj.version>
</properties>

<build>
<plugins>
<plugin>
Expand Down Expand Up @@ -105,6 +109,7 @@
<dependency>
<groupId>org.tomlj</groupId>
<artifactId>tomlj</artifactId>
<version>${tomlj.version}</version>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!--
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright (c) [2020-2022] Payara Foundation and/or its affiliates. All rights reserved.
Copyright (c) [2020-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
Expand Down Expand Up @@ -46,8 +46,7 @@
<artifactId>microprofile</artifactId>
<version>6.2024.11-SNAPSHOT</version>
</parent>

<groupId>fish.payara.server.internal.payara-appserver-modules</groupId>

<artifactId>microprofile-config-extensions</artifactId>
<packaging>glassfish-jar</packaging>
<name>Microprofile-Config-Extensions</name>
Expand Down Expand Up @@ -85,6 +84,11 @@
<artifactId>jersey-client</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>fish.payara.server.internal.packager</groupId>
<artifactId>tomlj-repackaged</artifactId>
<version>${project.version}</version>
</dependency>

<!-- Test dependencies -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
package fish.payara.nucleus.microprofile.config.source;
package fish.payara.microprofile.config.extensions.toml;

import fish.payara.nucleus.microprofile.config.source.extension.ConfiguredExtensionConfigSource;
import fish.payara.nucleus.microprofile.config.spi.MicroprofileConfigConfiguration;
import jakarta.inject.Inject;
import org.jvnet.hk2.annotations.Service;
import org.tomlj.Toml;
import org.tomlj.TomlArray;
import org.tomlj.TomlParseResult;
Expand All @@ -54,12 +58,15 @@
import java.util.logging.Level;
import java.util.logging.Logger;

public class TOMLConfigSource extends PayaraConfigSource {
@Service(name = "toml-config-source")
public class TOMLConfigSource extends ConfiguredExtensionConfigSource<TOMLConfigSourceConfiguration> {

private static final Logger LOGGER = Logger.getLogger(TOMLConfigSource.class.getName());
private final Map<String, String> properties = new ConcurrentHashMap<>();
private long lastModified;

@Inject
MicroprofileConfigConfiguration mpConfig;

@Override
public String getValue(String s) {
Expand All @@ -68,21 +75,17 @@ public String getValue(String s) {

@Override
public String getName() {
return "TOML";
return "toml";
}

@Override
public int getOrdinal() {
String storedOrdinal = getValue("config_ordinal");
if (storedOrdinal != null) {
return Integer.parseInt(storedOrdinal);
}
return Integer.parseInt(configService.getMPConfig().getTomlOrdinality());
return Integer.parseInt(mpConfig.getTomlOrdinality());
}

@Override
public Map<String, String> getProperties() {
Path tomlFilePath = getTomlFilePath();
Path tomlFilePath = getFilePath();
if (tomlFilePath == null) {
return properties;
}
Expand All @@ -99,7 +102,7 @@ public Map<String, String> getProperties() {
LOGGER.log(Level.WARNING, "Error parsing TOML file: {0}", tomlParseResult.errors().toString());
return properties;
}
flattenToml(tomlParseResult, "", properties, 0, Integer.parseInt(configService.getMPConfig().getTomlDepth()));
flattenToml(tomlParseResult, "", properties, 0, Integer.parseInt(configuration.getDepth()));

} catch (IOException e) {
throw new RuntimeException(e);
Expand All @@ -112,8 +115,23 @@ public Set<String> getPropertyNames() {
return getProperties().keySet();
}

private Path getTomlFilePath() {
String path = configService.getMPConfig().getTomlPath();
@Override
public boolean setValue(String name, String value) {
return false;
}

@Override
public boolean deleteValue(String name) {
return false;
}

@Override
public String getSource() {
return "toml";
}

private Path getFilePath() {
String path = configuration.getPath();
if (path == null || path.isEmpty()) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package fish.payara.microprofile.config.extensions.toml;

import fish.payara.nucleus.microprofile.config.spi.ConfigSourceConfiguration;
import org.jvnet.hk2.config.Attribute;
import org.jvnet.hk2.config.Configured;

@Configured(name = "toml-config-source-configuration")

public interface TOMLConfigSourceConfiguration extends ConfigSourceConfiguration {

@Attribute(required = true)
String getPath();
void setPath(String tomlPath);

@Attribute(required = true, dataType = Integer.class)
String getDepth();
void setDepth(String depth);
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,83 +37,50 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
package fish.payara.nucleus.microprofile.config.admin;
package fish.payara.microprofile.config.extensions.toml.admin;

import com.sun.enterprise.config.serverbeans.Config;
import com.sun.enterprise.util.ColumnFormatter;
import fish.payara.microprofile.config.extensions.toml.TOMLConfigSourceConfiguration;
import fish.payara.nucleus.microprofile.config.source.extension.BaseGetConfigSourceConfigurationCommand;
import fish.payara.nucleus.microprofile.config.spi.MicroprofileConfigConfiguration;
import jakarta.inject.Inject;
import org.glassfish.api.ActionReport;
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.internal.api.Target;
import org.jvnet.hk2.annotations.Service;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
* asAdmin command to the get the configuration for the TOML Config Source
*
* @since 6.2024.11
* @author Kalin Chan (Payara Foundation)
*/
@Service(name = "get-toml-configuration")
@Service(name = "get-toml-config-source-configuration")
@PerLookup
@ExecuteOn(RuntimeType.DAS)
@TargetType()
@CommandLock(CommandLock.LockType.NONE)
@ExecuteOn(value = {RuntimeType.DAS, RuntimeType.INSTANCE})
@TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG, CommandTarget.DEPLOYMENT_GROUP})
@RestEndpoints({
@RestEndpoint(configBean = MicroprofileConfigConfiguration.class,
opType = RestEndpoint.OpType.GET,
path = "get-toml-configuration",
description = "Gets the configuration for the TOML Config Source")
path = "get-toml-config-source-configuration",
description = "List TOML Config Source Configuration")
})
public class GetTOMLConfiguration implements AdminCommand {

@Param(optional = true, defaultValue = "server")
String target;

@Inject
Target targetUtil;

private final String[] OUTPUT_HEADERS = {"Path", "Depth"};
public class GetTOMLConfigurationCommand extends BaseGetConfigSourceConfigurationCommand<TOMLConfigSourceConfiguration> {

@Override
public void execute(AdminCommandContext context) {
final ActionReport actionReport = context.getActionReport();
protected Map<String, Object> getConfigSourceConfiguration(TOMLConfigSourceConfiguration configuration) {
Map<String, Object> config = super.getConfigSourceConfiguration(configuration);

final Config targetConfig = targetUtil.getConfig(target);
if (targetConfig == null) {
actionReport.setMessage("No such config named: " + target);
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
if (configuration != null) {
config.put("Path", configuration.getPath());
config.put("Depth", configuration.getDepth());
}

MicroprofileConfigConfiguration microprofileConfigConfiguration = targetConfig
.getExtensionByType(MicroprofileConfigConfiguration.class);

ColumnFormatter columnFormatter = new ColumnFormatter(OUTPUT_HEADERS);
Object[] outputValues = {
microprofileConfigConfiguration.getTomlPath(),
microprofileConfigConfiguration.getTomlDepth()
};
columnFormatter.addRow(outputValues);
actionReport.appendMessage(columnFormatter.toString());

Map<String, Object> extraPropertiesMap = new HashMap<>();
extraPropertiesMap.put("path", microprofileConfigConfiguration.getTomlPath());
extraPropertiesMap.put("depth", microprofileConfigConfiguration.getTomlDepth());

Properties extraProperties = new Properties();
extraProperties.put("toml", extraPropertiesMap);
actionReport.setExtraProperties(extraProperties);
return config;
}
}
Loading

0 comments on commit 61cbe56

Please sign in to comment.