From 745ed3a7e4307a4d8253d9aa81e2f7483a3096da Mon Sep 17 00:00:00 2001 From: Cousjava Date: Mon, 24 Aug 2020 15:47:56 +0100 Subject: [PATCH] FISH-477 Deployment group properties are now resolved --- .../deployment/util/ResourceValidator.java | 9 ++-- .../enterprise/v3/server/SystemTasksImpl.java | 46 ++++++++++++------- 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/appserver/deployment/dol/src/main/java/com/sun/enterprise/deployment/util/ResourceValidator.java b/appserver/deployment/dol/src/main/java/com/sun/enterprise/deployment/util/ResourceValidator.java index f21ee5e86a7..f5a9d667b24 100644 --- a/appserver/deployment/dol/src/main/java/com/sun/enterprise/deployment/util/ResourceValidator.java +++ b/appserver/deployment/dol/src/main/java/com/sun/enterprise/deployment/util/ResourceValidator.java @@ -65,6 +65,7 @@ import java.util.*; import java.util.logging.Level; import java.util.logging.Logger; +import org.glassfish.config.support.TranslatedConfigView; import org.glassfish.hk2.runlevel.RunLevel; import org.glassfish.internal.api.JavaEEContextUtil; import org.glassfish.internal.api.JavaEEContextUtil.Context; @@ -840,7 +841,7 @@ private void validateJNDIRefs(DeploymentContext deploymentContext, Application a "JNDI lookup failed for the resource: Name: {0}, Lookup: {1}, Type: {2}", resource.getName(), null, resource.getType())); } - String jndiName = resource.getJndiName(); + String jndiName = TranslatedConfigView.expandConfigValue(resource.getJndiName()); if (jndiName == null) { // there's no mapping in this resource, but it exists in JNDI namespace, so it's validated by other ref. return; @@ -895,12 +896,10 @@ private void validateJNDIRefs(DeploymentContext deploymentContext, Application a } catch (NamingException e) { deplLogger.log(Level.SEVERE, RESOURCE_REF_JNDI_LOOKUP_FAILED, new Object[]{resource.getName(), jndiName, resource.getType()}); - DeploymentException de = new DeploymentException(localStrings.getLocalString( + throw new DeploymentException(localStrings.getLocalString( "enterprise.deployment.util.resource.validation", "JNDI lookup failed for the resource: Name: {0}, Lookup: {1}, Type: {2}", - resource.getName(), jndiName, resource.getType())); - de.initCause(e); - throw de; + resource.getName(), jndiName, resource.getType()), e); } } diff --git a/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/server/SystemTasksImpl.java b/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/server/SystemTasksImpl.java index a8c69f06fd0..77e06332e55 100644 --- a/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/server/SystemTasksImpl.java +++ b/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/server/SystemTasksImpl.java @@ -37,6 +37,8 @@ * only if the new code is made subject to such option by the copyright * holder. */ +// Portions Copyright [2020] Payara Foundation and/or affiliates + package com.sun.enterprise.v3.server; import com.sun.enterprise.config.serverbeans.Cluster; @@ -59,6 +61,8 @@ import com.sun.enterprise.util.SystemPropertyConstants; import com.sun.appserv.server.util.Version; import com.sun.enterprise.universal.io.SmartFile; +import fish.payara.enterprise.config.serverbeans.DeploymentGroup; +import java.util.ArrayList; import org.jvnet.hk2.annotations.Optional; import org.glassfish.hk2.api.PostConstruct; @@ -74,6 +78,7 @@ import java.util.logging.Logger; import java.util.logging.Level; import org.glassfish.kernel.KernelLoggerInfo; +import org.jvnet.hk2.config.types.Property; /** * Init run level service to take care of vm related tasks. @@ -107,7 +112,7 @@ public void postConstruct() { setSystemPropertiesFromEnv(); setSystemPropertiesFromDomainXml(); resolveJavaConfig(); - _logger.fine("SystemTasks: loaded server named: " + server.getName()); + _logger.log(Level.FINE, "SystemTasks: loaded server named: {0}", server.getName()); } @Override @@ -120,14 +125,11 @@ public void writePidFile() { String pidString = getPidString(); FileUtils.writeStringToFile(pidString, pidFile); FileUtils.writeStringToFile(pidString, pidFileCopy); - } - catch (PidException pe) { + } catch (PidException pe) { _logger.warning(pe.getMessage()); - } - catch (Exception e) { + } catch (Exception e) { _logger.warning(strings.get("internal_error", e)); - } - finally { + } finally { if (pidFile != null) { FileUtils.deleteOnExit(pidFile); } @@ -157,8 +159,7 @@ private void setSystemPropertiesFromEnv() { hostname = NetUtils.getCanonicalHostName(); - } - catch (Exception ex) { + } catch (Exception ex) { if (_logger != null) { _logger.log(Level.SEVERE, KernelLoggerInfo.exceptionHostname, ex); } @@ -173,7 +174,8 @@ private void setSystemPropertiesFromDomainXml() { // 0. server // 1. cluster // 2. -config or -config - // 3. domain + // 3. deployment-group + // 4. domain // so we need to add System Properties in *reverse order* to get the // right precedence. @@ -181,7 +183,11 @@ private void setSystemPropertiesFromDomainXml() { List configSPList = getConfigSystemProperties(); Cluster cluster = server.getCluster(); List clusterSPList = null; - + List depGroups = server.getDeploymentGroup(); + List depGroupProperties = new ArrayList<>(); + for (DeploymentGroup group : depGroups) { + depGroupProperties.addAll(group.getProperty()); + } if (cluster != null) { clusterSPList = cluster.getSystemProperty(); @@ -190,10 +196,9 @@ private void setSystemPropertiesFromDomainXml() { } List serverSPList = server.getSystemProperty(); - setSystemProperties( - domainSPList); - setSystemProperties( - configSPList); + setSystemProperties(domainSPList); + setProperties(depGroupProperties); + setSystemProperties(configSPList); if (clusterSPList != null) { @@ -236,7 +241,7 @@ private void resolveJavaConfig() { setSystemProperty(m.group(1), value); if (_logger.isLoggable(Level.FINE)) { - _logger.fine("Setting " + m.group(1) + " = " + value); + _logger.log(Level.FINE, "Setting {0} = {1}", new Object[]{m.group(1), value}); } } } @@ -253,6 +258,15 @@ private void setSystemProperties(List spList) { } } } + + private void setProperties(List propList) { + for (Property prop: propList) { + String name = prop.getName(); + if (ok(name)) { + setSystemProperty(name, prop.getValue()); + } + } + } private String getPidString() { return "" + ProcessUtils.getPid();