Skip to content

Commit

Permalink
Merge pull request #2212 from Pandrex247/Master-Merge-2017-12-14
Browse files Browse the repository at this point in the history
Master merge 2017-12-14
  • Loading branch information
Pandrex247 authored Dec 14, 2017
2 parents dbd8a83 + 8c89fe7 commit e964d94
Show file tree
Hide file tree
Showing 23 changed files with 1,006 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ nb-configuration.xml
/appserver/tests/quicklook/*.output
/appserver/tests/quicklook/*.log
/appserver/tests/quicklook/**/*.war

/nucleus/payara-modules/nucleus-microprofile/config-service/nbproject/
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ Portions Copyright [2016-2017] [Payara Foundation and/or its affiliates]
<thread-pool name="http-thread-pool" min-thread-pool-size="10" max-thread-pool-size="200" max-queue-size="4096"></thread-pool>
<thread-pool name="thread-pool-1" min-thread-pool-size="2" max-thread-pool-size="200"/>
</thread-pools>
<microprofile-config/>
</config>
</configs>
<property name="administrative.domain.name" value="domain1"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public enum RUNTIME_OPTION {
addjars(true, new SeparatedFilesValidator(true, true, false, true, true)),
rootdir(true, new DirectoryValidator(true, true, true)),
deploymentdir(true, new DirectoryValidator(true, true, false)),
secretsdir(true,new DirectoryValidator(true, true, false)),
domainconfig(true, new FileValidator(true, true, true)),
minhttpthreads(true, new IntegerValidator(1, Integer.MAX_VALUE)),
maxhttpthreads(true, new IntegerValidator(2, Integer.MAX_VALUE)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ public class PayaraMicroImpl implements PayaraMicroBoot {
private RuntimeDirectory runtimeDir = null;
private String clustermode;
private String interfaces;

private String secretsDir;

/**
* Runs a Payara Micro server used via java -jar payara-micro.jar
*
Expand Down Expand Up @@ -986,6 +987,7 @@ public PayaraMicroRuntime bootStrap() throws BootstrapException {
configurePhoneHome();
configureNotificationService();
configureHealthCheck();
configureSecrets();

// Add additional libraries
addLibraries();
Expand Down Expand Up @@ -1318,6 +1320,9 @@ else if (requestTracing[0].matches("\\D+")) {
break;
case interfaces:
interfaces = value;
break;
case secretsdir:
secretsDir = value;
break;
default:
break;
Expand Down Expand Up @@ -2028,6 +2033,7 @@ private void setArgumentsFromSystemProperties() {
requestTracingThresholdValue = getLongProperty("payaramicro.requestTracingThresholdValue", 30L);
clustermode = getProperty("payaramicro.clusterMode");
interfaces = getProperty("payaramicro.interfaces");
secretsDir = getProperty("payaramicro.secretsDir");

// Set the rootDir file
String rootDirFileStr = getProperty("payaramicro.rootDir");
Expand Down Expand Up @@ -2160,6 +2166,10 @@ private void packageUberJar() {
props.setProperty("payaramicro.interfaces", interfaces);
}

if (secretsDir != null) {
props.setProperty("payaramicro.secretsDir", secretsDir);
}

props.setProperty("payaramicro.autoBindHttp", Boolean.toString(autoBindHttp));
props.setProperty("payaramicro.autoBindSsl", Boolean.toString(autoBindSsl));
props.setProperty("payaramicro.autoBindRange", Integer.toString(autoBindRange));
Expand Down Expand Up @@ -2475,4 +2485,10 @@ public void addLibrary(File lib) {
}
}

private void configureSecrets() {
if (secretsDir != null) {
preBootCommands.add(new BootCommand("set", "configs.config.server-config.microprofile-config.secret-dir=" + secretsDir));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,4 @@ nested=Do not unpack the Nested Jars when booting the server. This is generally
unpackdir=Unpack the Nested Jar runtime jars to the specified directory. Default behaviour is to unpack to java.io.tmpdir
clustermode=Modifies the cluster discovery mode of Payara Micro when finding members of the cluster. Options are multicast:group:port, tcpip:host:port, domain:dashost:port
interfaces=Specifies the Interfaces that the data grid discovery mode should use to listen can be comma separated e.g. 127.0.0.1,192,168,0,*
secretsdir=Directory to read secrets files using the Microprofile config api.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ holder.
<description>Implementation of Microprofile Configuration Service</description>
<packaging>glassfish-jar</packaging>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.15</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.glassfish.hk2</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@

/**
* asAdmin command to the get the ordinal for one of the built in Config Sources
*
* @since 4.1.2.173
* @author Steve Millidge (Payara Foundation)
*/
Expand All @@ -65,15 +66,15 @@
@ExecuteOn(RuntimeType.DAS)
@TargetType()
@RestEndpoints({ // creates a REST endpoint needed for integration with the admin interface

@RestEndpoint(configBean = MicroprofileConfigConfiguration.class,
opType = RestEndpoint.OpType.POST, // must be POST as it is doing an update
path = "get-config-ordinal",
description = "Gets the Ordinal of a builtin Config Source")
})
public class GetConfigOrdinal implements AdminCommand {

@Param(optional = true, acceptableValues = "domain,config,server,application,module,cluster,jndi", defaultValue = "domain")
@Param(optional = true, acceptableValues = "domain,config,server,application,module,cluster,jndi,secrets", defaultValue = "domain")
String source;

@Param(optional = true, defaultValue = "server") // if no target is specified it will be the DAS
Expand Down Expand Up @@ -112,10 +113,16 @@ public void execute(AdminCommandContext context) {
case "cluster": {
result = serviceConfig.getClusterOrdinality();
break;
}case "jndi": {
}
case "jndi": {
result = serviceConfig.getJNDIOrdinality();
break;
}
case "secrets": {
result = serviceConfig.getSecretDirOrdinality();
break;
}

}
context.getActionReport().setMessage(result.toString());
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2017 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/master/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.nucleus.microprofile.config.admin;

import com.sun.enterprise.config.serverbeans.Config;
import fish.payara.nucleus.microprofile.config.spi.MicroprofileConfigConfiguration;
import javax.inject.Inject;
import org.glassfish.api.Param;
import org.glassfish.api.admin.AdminCommand;
import org.glassfish.api.admin.AdminCommandContext;
import org.glassfish.api.admin.ExecuteOn;
import org.glassfish.api.admin.RestEndpoint;
import org.glassfish.api.admin.RestEndpoints;
import org.glassfish.config.support.TargetType;
import org.glassfish.hk2.api.PerLookup;
import org.glassfish.internal.api.Target;
import org.jvnet.hk2.annotations.Service;

/**
* asAdmin command to the set the directory for the Secrets Dir Config Source
*
* @since 4.1.2.181
* @author Steve Millidge (Payara Foundation)
*/
@Service(name = "get-config-secrets-dir") // the name of the service is the asadmin command name
@PerLookup // this means one instance is created every time the command is run
@ExecuteOn()
@TargetType()
@RestEndpoints({ // creates a REST endpoint needed for integration with the admin interface

@RestEndpoint(configBean = MicroprofileConfigConfiguration.class,
opType = RestEndpoint.OpType.POST, // must be POST as it is doing an update
path = "get-config-secrets-dir",
description = "Gets the Secrets Directory for the Secrets Config Source")
})
public class GetConfigSecretsDirectory implements AdminCommand {

@Param(optional = true, defaultValue = "server") // if no target is specified it will be the DAS
String target;

@Inject
Target targetUtil;

@Override
public void execute(AdminCommandContext context) {
String result = "Not Found";
Config configVal = targetUtil.getConfig(target);
MicroprofileConfigConfiguration serviceConfig = configVal.getExtensionByType(MicroprofileConfigConfiguration.class);
if (serviceConfig != null) {
result = serviceConfig.getSecretDir();
}
context.getActionReport().setMessage(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,33 +59,34 @@

/**
* asAdmin command to the set the ordinal for one of the built in Config Sources
*
* @since 4.1.2.173
* @author Steve Millidge (Payara Foundation)
*/
@Service(name = "set-config-ordinal") // the name of the service is the asadmin command name
@PerLookup // this means one instance is created every time the command is run
@ExecuteOn()
@ExecuteOn()
@TargetType()
@RestEndpoints({ // creates a REST endpoint needed for integration with the admin interface
@RestEndpoints({ // creates a REST endpoint needed for integration with the admin interface

@RestEndpoint(configBean = MicroprofileConfigConfiguration.class,
opType = RestEndpoint.OpType.POST, // must be POST as it is doing an update
path = "set-config-ordinal",
description = "Sets the Ordinal of a builtin Config Source")
})
public class SetConfigOrdinal implements AdminCommand {

@Param()
int ordinal;
@Param(optional = true, acceptableValues = "domain,config,server,application,module,cluster,jndi", defaultValue = "domain")

@Param(optional = true, acceptableValues = "domain,config,server,application,module,cluster,jndi,secrets", defaultValue = "domain")
String source;
@Param (optional = true, defaultValue = "server") // if no target is specified it will be the DAS

@Param(optional = true, defaultValue = "server") // if no target is specified it will be the DAS
String target;

@Inject
Target targetUtil;


@Override
public void execute(AdminCommandContext context) {
Expand All @@ -95,11 +96,11 @@ public void execute(AdminCommandContext context) {
try {
// to perform a transaction on the domain.xml you need to use this construct
// see https://github.com/hk2-project/hk2/blob/master/hk2-configuration/persistence/hk2-xml-dom/hk2-config/src/main/java/org/jvnet/hk2/config/ConfigSupport.java
ConfigSupport.apply(new SingleConfigCode<MicroprofileConfigConfiguration>(){
ConfigSupport.apply(new SingleConfigCode<MicroprofileConfigConfiguration>() {
@Override
public Object run(MicroprofileConfigConfiguration config) {
switch(source) {

switch (source) {
case "domain": {
config.setDomainOrdinality(ordinal);
break;
Expand All @@ -111,23 +112,27 @@ public Object run(MicroprofileConfigConfiguration config) {
case "server": {
config.setServerOrdinality(ordinal);
break;
}
}
case "application": {
config.setApplicationOrdinality(ordinal);
break;
}
case "module": {
config.setModuleOrdinality(ordinal);
break;
}
}
case "cluster": {
config.setClusterOrdinality(ordinal);
break;
}
}
case "jndi": {
config.setJNDIOrdinality(ordinal);
break;
}
}
case "secrets": {
config.setSecretDirOrdinality(ordinal);
break;
}
}
return null;
}
Expand All @@ -139,7 +144,7 @@ public Object run(MicroprofileConfigConfiguration config) {
} else {
context.getActionReport().failure(Logger.getLogger(SetConfigOrdinal.class.getName()), "No configuration with name " + target);
}

}

}
Loading

0 comments on commit e964d94

Please sign in to comment.