diff --git a/appserver/concurrent/concurrent-impl/src/main/java/org/glassfish/concurrent/admin/ManagedExecutorServiceBaseManager.java b/appserver/concurrent/concurrent-impl/src/main/java/org/glassfish/concurrent/admin/ManagedExecutorServiceBaseManager.java index 317e1220381..6d2ec360cf7 100644 --- a/appserver/concurrent/concurrent-impl/src/main/java/org/glassfish/concurrent/admin/ManagedExecutorServiceBaseManager.java +++ b/appserver/concurrent/concurrent-impl/src/main/java/org/glassfish/concurrent/admin/ManagedExecutorServiceBaseManager.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright [2016-2018] [Payara Foundation] +// Portions Copyright [2016-2022] [Payara Foundation] package org.glassfish.concurrent.admin; import com.sun.appserv.connectors.internal.api.ConnectorsUtil; @@ -153,7 +153,13 @@ protected ResourceStatus isValid(Resources resources, boolean validateResourceRe clazz = ManagedScheduledExecutorService.class; } status = resourcesHelper.validateBindableResourceForDuplicates(resources, jndiName, validateResourceRef, target, clazz); - + + try { + Integer.parseInt(corePoolSize); + } catch (NumberFormatException nfe) { + return new ResourceStatus(ResourceStatus.FAILURE, localStrings.getLocalString("coresize.must.be.number", "Option corepoolsize must be a number.")); + } + return status; } diff --git a/appserver/concurrent/concurrent-impl/src/main/java/org/glassfish/concurrent/admin/ManagedExecutorServiceManager.java b/appserver/concurrent/concurrent-impl/src/main/java/org/glassfish/concurrent/admin/ManagedExecutorServiceManager.java index cf5feed9534..dedc9c71c09 100644 --- a/appserver/concurrent/concurrent-impl/src/main/java/org/glassfish/concurrent/admin/ManagedExecutorServiceManager.java +++ b/appserver/concurrent/concurrent-impl/src/main/java/org/glassfish/concurrent/admin/ManagedExecutorServiceManager.java @@ -37,6 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ +// Portions Copyright [2022] [Payara Foundation and/or its affiliates] package org.glassfish.concurrent.admin; @@ -78,19 +79,26 @@ protected void setAttributes(HashMap attributes, String target) { @Override protected ResourceStatus isValid(Resources resources, boolean validateResourceRef, String target){ - if (Integer.parseInt(corePoolSize) == 0 && - Integer.parseInt(maximumPoolSize) == 0) { + ResourceStatus superStatus = super.isValid(resources, validateResourceRef, target); + + try { + Integer.parseInt(maximumPoolSize); + } catch (NumberFormatException nfe) { + return new ResourceStatus(ResourceStatus.FAILURE, localStrings.getLocalString("maxsize.must.be.number", "Option maximumpoolsize must be a number.")); + } + + if (Integer.parseInt(corePoolSize) == 0 + && Integer.parseInt(maximumPoolSize) == 0) { String msg = localStrings.getLocalString("coresize.maxsize.both.zero", "Options corepoolsize and maximumpoolsize cannot both have value 0."); return new ResourceStatus(ResourceStatus.FAILURE, msg); } - if (Integer.parseInt(corePoolSize) > - Integer.parseInt(maximumPoolSize)) { + if (Integer.parseInt(corePoolSize) > Integer.parseInt(maximumPoolSize)) { String msg = localStrings.getLocalString("coresize.biggerthan.maxsize", "Option corepoolsize cannot have a bigger value than option maximumpoolsize."); return new ResourceStatus(ResourceStatus.FAILURE, msg); } - return super.isValid(resources, validateResourceRef, target); + return superStatus; } protected ManagedExecutorServiceBase createConfigBean(Resources param, Properties properties) throws PropertyVetoException, TransactionFailure { diff --git a/appserver/concurrent/concurrent-impl/src/main/resources/org/glassfish/concurrent/admin/LocalStrings.properties b/appserver/concurrent/concurrent-impl/src/main/resources/org/glassfish/concurrent/admin/LocalStrings.properties index 2ccb30fc100..bf206ffee55 100644 --- a/appserver/concurrent/concurrent-impl/src/main/resources/org/glassfish/concurrent/admin/LocalStrings.properties +++ b/appserver/concurrent/concurrent-impl/src/main/resources/org/glassfish/concurrent/admin/LocalStrings.properties @@ -37,6 +37,7 @@ # only if the new code is made subject to such option by the copyright # holder. # +# Portions Copyright [2022] [Payara Foundation and/or its affiliates] #context-service element create.context.service.failed=Context service {0} creation failed. @@ -86,6 +87,8 @@ delete.managed.scheduled.executor.service.no.resource-ref=This managed scheduled delete.managed.scheduled.executor.service.multiple.resource-refs=This managed scheduled executor service [ {0} ] is referenced in multiple instance/cluster targets, Use delete-resource-ref on appropriate target. list.managed.scheduled.executor.service.failed=List managed scheduled executor services failed. +coresize.must.be.number=Option corepoolsize must be a number. +maxsize.must.be.number=Option maximumpoolsize must be a number. coresize.maxsize.both.zero=Options corepoolsize and maximumpoolsize cannot both have value 0. coresize.biggerthan.maxsize=Option corepoolsize cannot have a bigger value than option maximumpoolsize. delete.concurrent.resource.notAllowed=The {0} resource cannot be deleted as it is required to be configured in the system. diff --git a/appserver/connectors/descriptors/src/main/resources/glassfish/lib/dtds/payara-resources_1_7.dtd b/appserver/connectors/descriptors/src/main/resources/glassfish/lib/dtds/payara-resources_1_7.dtd new file mode 100644 index 00000000000..08ddaa22923 --- /dev/null +++ b/appserver/connectors/descriptors/src/main/resources/glassfish/lib/dtds/payara-resources_1_7.dtd @@ -0,0 +1,1095 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/appserver/resources/resources-connector/src/main/java/org/glassfish/resources/admin/cli/ResourceConstants.java b/appserver/resources/resources-connector/src/main/java/org/glassfish/resources/admin/cli/ResourceConstants.java index c1298c739cf..8e59b929d9b 100644 --- a/appserver/resources/resources-connector/src/main/java/org/glassfish/resources/admin/cli/ResourceConstants.java +++ b/appserver/resources/resources-connector/src/main/java/org/glassfish/resources/admin/cli/ResourceConstants.java @@ -36,9 +36,8 @@ * 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. - * - * Portions Copyright [2017-2020] Payara Foundation and/or affiliates */ +// Portions Copyright [2017-2022] [Payara Foundation and/or its affiliates] package org.glassfish.resources.admin.cli; @@ -258,6 +257,7 @@ public final class ResourceConstants { public static final String KEEP_ALIVE_SECONDS = "keep-alive-seconds"; public static final String THREAD_LIFETIME_SECONDS = "thread-lifetime-seconds"; public static final String TASK_QUEUE_CAPACITY = "task-queue-capacity"; + public static final String MAX_ASYNC = "max-async"; public static final String SYSTEM_ALL_REQ = "system-all-req"; diff --git a/appserver/resources/resources-connector/src/main/java/org/glassfish/resources/admin/cli/ResourcesXMLParser.java b/appserver/resources/resources-connector/src/main/java/org/glassfish/resources/admin/cli/ResourcesXMLParser.java index 43c5af8abd7..325a1a7e63f 100644 --- a/appserver/resources/resources-connector/src/main/java/org/glassfish/resources/admin/cli/ResourcesXMLParser.java +++ b/appserver/resources/resources-connector/src/main/java/org/glassfish/resources/admin/cli/ResourcesXMLParser.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright [2017-2020] [Payara Foundation and/or its affiliates] +// Portions Copyright [2017-2022] [Payara Foundation and/or its affiliates] package org.glassfish.resources.admin.cli; @@ -45,19 +45,45 @@ import com.sun.enterprise.util.i18n.StringManager; import org.glassfish.api.I18n; import org.glassfish.resources.api.Resource; -import org.w3c.dom.*; -import org.xml.sax.*; +import org.w3c.dom.DOMException; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.EntityResolver; +import org.xml.sax.ErrorHandler; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; import org.xml.sax.ext.LexicalHandler; -import javax.xml.parsers.*; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; -import java.io.*; +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; import java.net.URL; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.StringTokenizer; import java.util.logging.Level; import java.util.logging.Logger; @@ -120,6 +146,7 @@ public class ResourcesXMLParser implements EntityResolver private static final String publicID_ges31 = "GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions"; private static final String publicId_py4 = "Payara.fish//DTD Payara Server 4 Resource Definitions"; + private static final String DTD_1_7 = "payara-resources_1_7.dtd"; private static final String DTD_1_6 = "payara-resources_1_6.dtd"; private static final String DTD_1_5 = "glassfish-resources_1_5.dtd"; private static final String DTD_1_4 = "sun-resources_1_4.dtd"; @@ -130,6 +157,7 @@ public class ResourcesXMLParser implements EntityResolver private static final List systemIDs = Collections.unmodifiableList( Arrays.asList( + DTD_1_7, DTD_1_6, DTD_1_5, DTD_1_4, @@ -367,6 +395,12 @@ else if (nodeName.equalsIgnoreCase(org.glassfish.resources.api.Resource.RESOURCE else if (nodeName.equalsIgnoreCase(org.glassfish.resources.api.Resource.CONNECTOR_WORK_SECURITY_MAP)) { generateWorkSecurityMap(nextKid, scope); + } else if (nodeName.equalsIgnoreCase(org.glassfish.resources.api.Resource.MANAGED_EXECUTOR_SERVICE)) { + generateManagedExecutorService(nextKid, scope); + } else if (nodeName.equalsIgnoreCase(org.glassfish.resources.api.Resource.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) { + generateManagedScheduledExecutorService(nextKid, scope); + } else if (nodeName.equalsIgnoreCase(org.glassfish.resources.api.Resource.MANAGED_THREAD_FACTORY)) { + generateManagedThreadFactory(nextKid, scope); } } } @@ -699,6 +733,236 @@ private void generateJDBCResource(Node nextKid, String scope) throws Exception { printResourceElements(jdbcResource); } + /** + * Generate the ManagedExecutorService resource + */ + private void generateManagedExecutorService(Node nextKid, String scope) throws Exception { + NamedNodeMap attributes = nextKid.getAttributes(); + if (attributes == null) { + return; + } + + Resource managedExecutorServiceResource = new org.glassfish.resources.api.Resource(org.glassfish.resources.api.Resource.MANAGED_EXECUTOR_SERVICE); + + Node jndiNameNode = attributes.getNamedItem(JNDI_NAME); + String jndiName = getScopedName(jndiNameNode.getNodeValue(), scope); + managedExecutorServiceResource.setAttribute(JNDI_NAME, jndiName); + Node corePoolSizeNode = attributes.getNamedItem(CORE_POOL_SIZE); + if (corePoolSizeNode != null) { + String corePoolSizeValue = corePoolSizeNode.getNodeValue(); + managedExecutorServiceResource.setAttribute(CORE_POOL_SIZE, corePoolSizeValue); + } + Node maxPoolSizeNode = attributes.getNamedItem(MAXIMUM_POOL_SIZE); + if (maxPoolSizeNode != null) { + String maxPoolSizeValue = maxPoolSizeNode.getNodeValue(); + managedExecutorServiceResource.setAttribute(MAXIMUM_POOL_SIZE, maxPoolSizeValue); + } + Node contextInfoNode = attributes.getNamedItem(CONTEXT_INFO); + if (contextInfoNode != null) { + String contextInfoValue = contextInfoNode.getNodeValue(); + managedExecutorServiceResource.setAttribute(CONTEXT_INFO, contextInfoValue); + } + Node contextInfoEnabledNode = attributes.getNamedItem(CONTEXT_INFO_ENABLED); + if (contextInfoEnabledNode != null) { + String contextInfoEnabledValue = contextInfoEnabledNode.getNodeValue(); + managedExecutorServiceResource.setAttribute(CONTEXT_INFO_ENABLED, contextInfoEnabledValue); + } + Node enabledNode = attributes.getNamedItem(ENABLED); + if (enabledNode != null) { + String enabledValue = enabledNode.getNodeValue(); + managedExecutorServiceResource.setAttribute(ENABLED, enabledValue); + } + Node threadpriorityNode = attributes.getNamedItem(THREAD_PRIORITY); + if (threadpriorityNode != null) { + String threadpriorityValue = threadpriorityNode.getNodeValue(); + managedExecutorServiceResource.setAttribute(THREAD_PRIORITY, threadpriorityValue); + } + Node longrunningstasksNode = attributes.getNamedItem(LONG_RUNNING_TASKS); + if (longrunningstasksNode != null) { + String longrunningstasksValue = longrunningstasksNode.getNodeValue(); + managedExecutorServiceResource.setAttribute(LONG_RUNNING_TASKS, longrunningstasksValue); + } + Node hungaftersecondsNode = attributes.getNamedItem(HUNG_AFTER_SECONDS); + if (hungaftersecondsNode != null) { + String hungaftersecondsValue = hungaftersecondsNode.getNodeValue(); + managedExecutorServiceResource.setAttribute(HUNG_AFTER_SECONDS, hungaftersecondsValue); + } + Node keepalivesecondsNode = attributes.getNamedItem(KEEP_ALIVE_SECONDS); + if (keepalivesecondsNode != null) { + String keepalivesecondsValue = keepalivesecondsNode.getNodeValue(); + managedExecutorServiceResource.setAttribute(KEEP_ALIVE_SECONDS, keepalivesecondsValue); + } + Node threadlifetimesecondsNode = attributes.getNamedItem(THREAD_LIFETIME_SECONDS); + if (threadlifetimesecondsNode != null) { + String threadlifetimesecondsValue = threadlifetimesecondsNode.getNodeValue(); + managedExecutorServiceResource.setAttribute(THREAD_LIFETIME_SECONDS, threadlifetimesecondsValue); + } + Node taskqueuecapacityNode = attributes.getNamedItem(TASK_QUEUE_CAPACITY); + if (taskqueuecapacityNode != null) { + String taskqueuecapacityValue = taskqueuecapacityNode.getNodeValue(); + managedExecutorServiceResource.setAttribute(TASK_QUEUE_CAPACITY, taskqueuecapacityValue); + } + + NodeList children = nextKid.getChildNodes(); + //get description + if (children != null) { + for (int ii = 0; ii < children.getLength(); ii++) { + if (children.item(ii).getNodeName().equals("description")) { + if (children.item(ii).getFirstChild() != null) { + managedExecutorServiceResource.setDescription( + children.item(ii).getFirstChild().getNodeValue()); + } + } + } + } + + vResources.add(managedExecutorServiceResource); + resourceMap.put(managedExecutorServiceResource, nextKid); + + //debug strings + printResourceElements(managedExecutorServiceResource); + } + + /** + * Generate the ManagedScheduledExecutorService resource + */ + private void generateManagedScheduledExecutorService(Node nextKid, String scope) throws Exception { + NamedNodeMap attributes = nextKid.getAttributes(); + if (attributes == null) { + return; + } + + Resource managedScheduledExecutorServiceResource = new org.glassfish.resources.api.Resource(org.glassfish.resources.api.Resource.MANAGED_SCHEDULED_EXECUTOR_SERVICE); + + Node jndiNameNode = attributes.getNamedItem(JNDI_NAME); + String jndiName = getScopedName(jndiNameNode.getNodeValue(), scope); + managedScheduledExecutorServiceResource.setAttribute(JNDI_NAME, jndiName); + Node corePoolSizeNode = attributes.getNamedItem(CORE_POOL_SIZE); + if (corePoolSizeNode != null) { + String corePoolSizeValue = corePoolSizeNode.getNodeValue(); + managedScheduledExecutorServiceResource.setAttribute(CORE_POOL_SIZE, corePoolSizeValue); + } + Node contextInfoNode = attributes.getNamedItem(CONTEXT_INFO); + if (contextInfoNode != null) { + String contextInfoValue = contextInfoNode.getNodeValue(); + managedScheduledExecutorServiceResource.setAttribute(CONTEXT_INFO, contextInfoValue); + } + Node contextInfoEnabledNode = attributes.getNamedItem(CONTEXT_INFO_ENABLED); + if (contextInfoEnabledNode != null) { + String contextInfoEnabledValue = contextInfoEnabledNode.getNodeValue(); + managedScheduledExecutorServiceResource.setAttribute(CONTEXT_INFO_ENABLED, contextInfoEnabledValue); + } + Node enabledNode = attributes.getNamedItem(ENABLED); + if (enabledNode != null) { + String enabledValue = enabledNode.getNodeValue(); + managedScheduledExecutorServiceResource.setAttribute(ENABLED, enabledValue); + } + Node threadpriorityNode = attributes.getNamedItem(THREAD_PRIORITY); + if (threadpriorityNode != null) { + String threadpriorityValue = threadpriorityNode.getNodeValue(); + managedScheduledExecutorServiceResource.setAttribute(THREAD_PRIORITY, threadpriorityValue); + } + Node longrunningstasksNode = attributes.getNamedItem(LONG_RUNNING_TASKS); + if (longrunningstasksNode != null) { + String longrunningstasksValue = longrunningstasksNode.getNodeValue(); + managedScheduledExecutorServiceResource.setAttribute(LONG_RUNNING_TASKS, longrunningstasksValue); + } + Node hungaftersecondsNode = attributes.getNamedItem(HUNG_AFTER_SECONDS); + if (hungaftersecondsNode != null) { + String hungaftersecondsValue = hungaftersecondsNode.getNodeValue(); + managedScheduledExecutorServiceResource.setAttribute(HUNG_AFTER_SECONDS, hungaftersecondsValue); + } + Node keepalivesecondsNode = attributes.getNamedItem(KEEP_ALIVE_SECONDS); + if (keepalivesecondsNode != null) { + String keepalivesecondsValue = keepalivesecondsNode.getNodeValue(); + managedScheduledExecutorServiceResource.setAttribute(KEEP_ALIVE_SECONDS, keepalivesecondsValue); + } + Node threadlifetimesecondsNode = attributes.getNamedItem(THREAD_LIFETIME_SECONDS); + if (threadlifetimesecondsNode != null) { + String threadlifetimesecondsValue = threadlifetimesecondsNode.getNodeValue(); + managedScheduledExecutorServiceResource.setAttribute(THREAD_LIFETIME_SECONDS, threadlifetimesecondsValue); + } + + NodeList children = nextKid.getChildNodes(); + //get description + if (children != null) { + for (int ii = 0; ii < children.getLength(); ii++) { + if (children.item(ii).getNodeName().equals("description")) { + if (children.item(ii).getFirstChild() != null) { + managedScheduledExecutorServiceResource.setDescription( + children.item(ii).getFirstChild().getNodeValue()); + } + } + } + } + + vResources.add(managedScheduledExecutorServiceResource); + resourceMap.put(managedScheduledExecutorServiceResource, nextKid); + + //debug strings + printResourceElements(managedScheduledExecutorServiceResource); + } + + /** + * Generate the ManagedThreadFactory resource + */ + private void generateManagedThreadFactory(Node nextKid, String scope) throws Exception { + NamedNodeMap attributes = nextKid.getAttributes(); + if (attributes == null) { + return; + } + + Resource managedThreadFactoryResource = new org.glassfish.resources.api.Resource(org.glassfish.resources.api.Resource.MANAGED_THREAD_FACTORY); + + Node jndiNameNode = attributes.getNamedItem(JNDI_NAME); + String jndiName = getScopedName(jndiNameNode.getNodeValue(), scope); + managedThreadFactoryResource.setAttribute(JNDI_NAME, jndiName); + Node corePoolSizeNode = attributes.getNamedItem(CORE_POOL_SIZE); + if (corePoolSizeNode != null) { + String corePoolSizeValue = corePoolSizeNode.getNodeValue(); + managedThreadFactoryResource.setAttribute(CORE_POOL_SIZE, corePoolSizeValue); + } + Node contextInfoNode = attributes.getNamedItem(CONTEXT_INFO); + if (contextInfoNode != null) { + String contextInfoValue = contextInfoNode.getNodeValue(); + managedThreadFactoryResource.setAttribute(CONTEXT_INFO, contextInfoValue); + } + Node contextInfoEnabledNode = attributes.getNamedItem(CONTEXT_INFO_ENABLED); + if (contextInfoEnabledNode != null) { + String contextInfoEnabledValue = contextInfoEnabledNode.getNodeValue(); + managedThreadFactoryResource.setAttribute(CONTEXT_INFO_ENABLED, contextInfoEnabledValue); + } + Node enabledNode = attributes.getNamedItem(ENABLED); + if (enabledNode != null) { + String enabledValue = enabledNode.getNodeValue(); + managedThreadFactoryResource.setAttribute(ENABLED, enabledValue); + } + Node threadpriorityNode = attributes.getNamedItem(THREAD_PRIORITY); + if (threadpriorityNode != null) { + String threadpriorityValue = threadpriorityNode.getNodeValue(); + managedThreadFactoryResource.setAttribute(THREAD_PRIORITY, threadpriorityValue); + } + + NodeList children = nextKid.getChildNodes(); + //get description + if (children != null) { + for (int ii = 0; ii < children.getLength(); ii++) { + if (children.item(ii).getNodeName().equals("description")) { + if (children.item(ii).getFirstChild() != null) { + managedThreadFactoryResource.setDescription( + children.item(ii).getFirstChild().getNodeValue()); + } + } + } + } + + vResources.add(managedThreadFactoryResource); + resourceMap.put(managedThreadFactoryResource, nextKid); + + //debug strings + printResourceElements(managedThreadFactoryResource); + } + /** * Generate the JDBC Connection pool Resource */ @@ -1606,7 +1870,7 @@ public InputSource resolveEntity(String publicId, String systemId) }else if(publicId.contains(publicID_ges31)){ dtdFileName = DTD_1_5; } else if (publicId.contains(publicId_py4)) { - dtdFileName = DTD_1_6; + dtdFileName = DTD_1_7; } } diff --git a/appserver/resources/resources-connector/src/main/java/org/glassfish/resources/api/Resource.java b/appserver/resources/resources-connector/src/main/java/org/glassfish/resources/api/Resource.java index 71393b76469..a82328603da 100644 --- a/appserver/resources/resources-connector/src/main/java/org/glassfish/resources/api/Resource.java +++ b/appserver/resources/resources-connector/src/main/java/org/glassfish/resources/api/Resource.java @@ -37,10 +37,15 @@ * only if the new code is made subject to such option by the copyright * holder. */ +// Portions Copyright [2022] [Payara Foundation and/or its affiliates] package org.glassfish.resources.api; -import java.util.*; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Properties; import static org.glassfish.resources.admin.cli.ResourceConstants.*; @@ -58,26 +63,31 @@ public class Resource { public static final String JDBC_CONNECTION_POOL = "jdbc-connection-pool"; public static final String CONNECTOR_CONNECTION_POOL = "connector-connection-pool"; - public static final String RESOURCE_ADAPTER_CONFIG = "resource-adapter-config"; + public static final String MANAGED_EXECUTOR_SERVICE = "managed-executor-service"; + public static final String MANAGED_SCHEDULED_EXECUTOR_SERVICE = "managed-scheduled-executor-service"; + public static final String MANAGED_THREAD_FACTORY = "managed-thread-factory"; + + public static final String RESOURCE_ADAPTER_CONFIG = "resource-adapter-config"; public static final String PERSISTENCE_MANAGER_FACTORY_RESOURCE = "persistence-manager-factory-resource"; public static final String CONNECTOR_SECURITY_MAP = "security-map"; public static final String CONNECTOR_WORK_SECURITY_MAP = "work-security-map"; public static final List BINDABLE_RESOURCES = Collections.unmodifiableList( Arrays.asList( - CUSTOM_RESOURCE, - CONNECTOR_RESOURCE, - ADMIN_OBJECT_RESOURCE, - JDBC_RESOURCE, - MAIL_RESOURCE, - EXTERNAL_JNDI_RESOURCE + CUSTOM_RESOURCE, + CONNECTOR_RESOURCE, + ADMIN_OBJECT_RESOURCE, + JDBC_RESOURCE, + MAIL_RESOURCE, + EXTERNAL_JNDI_RESOURCE, + MANAGED_EXECUTOR_SERVICE )); public static final List RESOURCE_POOL = Collections.unmodifiableList( Arrays.asList( JDBC_CONNECTION_POOL, - CONNECTOR_CONNECTION_POOL - )); + CONNECTOR_CONNECTION_POOL + )); private String resType; private HashMap attrList = new HashMap(); @@ -241,9 +251,10 @@ public String toString(){ String rType = getType(); String identity = ""; - if (rType.equals(CUSTOM_RESOURCE)|| rType.equals(EXTERNAL_JNDI_RESOURCE) - || rType.equals(JDBC_RESOURCE)|| rType.equals(PERSISTENCE_MANAGER_FACTORY_RESOURCE) - || rType.equals(CONNECTOR_RESOURCE)|| rType.equals(ADMIN_OBJECT_RESOURCE) || rType.equals(MAIL_RESOURCE)) { + if (rType.equals(CUSTOM_RESOURCE) || rType.equals(EXTERNAL_JNDI_RESOURCE) + || rType.equals(JDBC_RESOURCE) || rType.equals(PERSISTENCE_MANAGER_FACTORY_RESOURCE) + || rType.equals(CONNECTOR_RESOURCE) || rType.equals(ADMIN_OBJECT_RESOURCE) + || rType.equals(MAIL_RESOURCE) || rType.equals(MANAGED_EXECUTOR_SERVICE)) { identity = getAttribute(this, JNDI_NAME); }else if (rType.equals(JDBC_CONNECTION_POOL) || rType.equals(CONNECTOR_CONNECTION_POOL)) { identity = getAttribute(this, CONNECTION_POOL_NAME); diff --git a/appserver/resources/resources-runtime/src/main/java/org/glassfish/resources/module/ResourcesDeployer.java b/appserver/resources/resources-runtime/src/main/java/org/glassfish/resources/module/ResourcesDeployer.java index a8bfb767711..3ba1c3d0eca 100644 --- a/appserver/resources/resources-runtime/src/main/java/org/glassfish/resources/module/ResourcesDeployer.java +++ b/appserver/resources/resources-runtime/src/main/java/org/glassfish/resources/module/ResourcesDeployer.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright [2016-2018] [Payara Foundation and/or its affiliates] +// Portions Copyright [2016-2022] [Payara Foundation and/or its affiliates] package org.glassfish.resources.module; @@ -197,6 +197,7 @@ public void getResources(ReadableArchive archive, String appName, List connectorResources, List nonConnectorResources, Map resourceXmlParsers) { + String processedFilename = "glassfish-resources.xml"; try { if (ResourceUtil.hasGlassfishResourcesXML(archive, locator) || ResourceUtil.hasPayaraResourcesXML(archive, locator)) { Map> appScopedResources = new HashMap>(); @@ -209,6 +210,7 @@ public void getResources(ReadableArchive archive, String appName, String moduleName = entry.getKey(); String fileName = entry.getValue(); debug("GlassFish Resources XML : " + fileName); + processedFilename = fileName; moduleName = org.glassfish.resourcebase.resources.util.ResourceUtil.getActualModuleNameWithExtension(moduleName); String scope; @@ -245,12 +247,13 @@ public void getResources(ReadableArchive archive, String appName, } catch (Exception e) { // only DeploymentExceptions are propagated and result in deployment failure // in the event notification infrastructure - throw new DeploymentException("Failue while processing glassfish-resources.xml(s) in the archive ", e); + throw new DeploymentException("Failure while processing " + processedFilename + " in the archive ", e); } } private void processArchive(DeploymentContext dc) { + String processedFilename = "glassfish-resources.xml"; try { ReadableArchive archive = dc.getSource(); @@ -270,6 +273,7 @@ private void processArchive(DeploymentContext dc) { String moduleName = entry.getKey(); String fileName = entry.getValue(); debug("Sun Resources XML : " + fileName); + processedFilename = fileName; moduleName = org.glassfish.resourcebase.resources.util.ResourceUtil.getActualModuleNameWithExtension(moduleName); String scope ; @@ -329,7 +333,7 @@ private void processArchive(DeploymentContext dc) { } catch (Exception e) { // only DeploymentExceptions are propagated and result in deployment failure // in the event notification infrastructure - throw new DeploymentException("Failue while processing glassfish-resources.xml(s) in the archive ", e); + throw new DeploymentException("Failure while processing " + processedFilename + " in the archive ", e); } } diff --git a/appserver/tests/payara-samples/samples/pom.xml b/appserver/tests/payara-samples/samples/pom.xml index a9165c64aee..edc49e70a5f 100644 --- a/appserver/tests/payara-samples/samples/pom.xml +++ b/appserver/tests/payara-samples/samples/pom.xml @@ -86,6 +86,7 @@ microprofile-rest-client grpc-ejb + resources diff --git a/appserver/tests/payara-samples/samples/resources/mes-in-payara-resources-example/pom.xml b/appserver/tests/payara-samples/samples/resources/mes-in-payara-resources-example/pom.xml new file mode 100644 index 00000000000..00d25ae8581 --- /dev/null +++ b/appserver/tests/payara-samples/samples/resources/mes-in-payara-resources-example/pom.xml @@ -0,0 +1,156 @@ + + + + 4.0.0 + + mes-in-payara-resources-example + war + Payara Server example that demonstrates managed executor service defined in payara-resources.xml + Payara Samples - ManagedExecutorService in payara-resources.xml + + fish.payara.samples + payara-samples-resources-tests + 5.40.0-SNAPSHOT + + + + 1.8 + 1.8 + UTF-8 + false + 5.8.2 + + + + ${project.artifactId} + + + org.apache.maven.plugins + maven-compiler-plugin + 3.10.1 + + 1.8 + 1.8 + UTF-8 + + + + + + + + jakarta.enterprise + jakarta.enterprise.cdi-api + provided + + + jakarta.ws.rs + jakarta.ws.rs-api + provided + + + jakarta.enterprise.concurrent + jakarta.enterprise.concurrent-api + provided + + + + org.hibernate + hibernate-entitymanager + 5.6.9.Final + + + com.h2database + h2 + + + + + org.glassfish.jersey.ext.microprofile + jersey-mp-rest-client + test + + + org.jboss.arquillian.junit5 + arquillian-junit5-container + test + + + org.jboss.arquillian.protocol + arquillian-protocol-servlet-jakarta + test + + + org.junit.jupiter + junit-jupiter + ${junit-jupiter.version} + test + + + org.jboss.shrinkwrap.resolver + shrinkwrap-resolver-impl-maven + test + + + org.jboss.shrinkwrap.resolver + shrinkwrap-resolver-api-maven + test + + + + + + payara-server-remote + + + fish.payara.arquillian + payara-client-ee8 + test + + + fish.payara.arquillian + arquillian-payara-server-remote + test + + + + + diff --git a/appserver/tests/payara-samples/samples/resources/mes-in-payara-resources-example/src/main/java/fish/payara/examples/ApplicationConfig.java b/appserver/tests/payara-samples/samples/resources/mes-in-payara-resources-example/src/main/java/fish/payara/examples/ApplicationConfig.java new file mode 100644 index 00000000000..27234cb05cf --- /dev/null +++ b/appserver/tests/payara-samples/samples/resources/mes-in-payara-resources-example/src/main/java/fish/payara/examples/ApplicationConfig.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2022 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.examples; + +import javax.ws.rs.core.Application; +import java.util.Set; + +@javax.ws.rs.ApplicationPath("resources") +public class ApplicationConfig extends Application { + + @Override + public Set> getClasses() { + Set> resources = new java.util.HashSet<>(); + addRestResourceClasses(resources); + return resources; + } + + private void addRestResourceClasses(Set> resources) { + resources.add(fish.payara.examples.MSESResource.class); + resources.add(fish.payara.examples.PersonResource.class); + } +} \ No newline at end of file diff --git a/appserver/tests/payara-samples/samples/resources/mes-in-payara-resources-example/src/main/java/fish/payara/examples/MSESResource.java b/appserver/tests/payara-samples/samples/resources/mes-in-payara-resources-example/src/main/java/fish/payara/examples/MSESResource.java new file mode 100644 index 00000000000..0f995556287 --- /dev/null +++ b/appserver/tests/payara-samples/samples/resources/mes-in-payara-resources-example/src/main/java/fish/payara/examples/MSESResource.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2022 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.examples; + +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import javax.annotation.Resource; +import javax.enterprise.concurrent.ManagedScheduledExecutorService; +import javax.enterprise.concurrent.ManagedThreadFactory; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +/** + * Simple test for ManagedScheduledExecutorService and ManagedThreadFactory defined in payara-resources.xml. + * + * @author Petr Aubrecht + */ +@Path("concurrent") +public class MSESResource { + @Resource(lookup = "java:app/concurrent/MSESPayara") + private ManagedScheduledExecutorService mses; + + @Resource(lookup = "java:app/concurrent/MTFPayara") + private ManagedThreadFactory mtf; + + @GET + @Produces(MediaType.TEXT_PLAIN) + @Path("mses") + public String findMSES() { + return "MSES " + (mses == null ? "MISSING" : "PRESENT"); + } + + @GET + @Produces(MediaType.TEXT_PLAIN) + @Path("mtf") + public String findMTF() throws InterruptedException, ExecutionException, TimeoutException { + CompletableFuture info = new CompletableFuture<>(); + mtf.newThread(() -> { + info.complete(Thread.currentThread().getPriority()); + }).start(); + return "MTF, priority " + info.get(1, TimeUnit.SECONDS); + } + +} diff --git a/appserver/tests/payara-samples/samples/resources/mes-in-payara-resources-example/src/main/java/fish/payara/examples/Person.java b/appserver/tests/payara-samples/samples/resources/mes-in-payara-resources-example/src/main/java/fish/payara/examples/Person.java new file mode 100644 index 00000000000..a2f951639d8 --- /dev/null +++ b/appserver/tests/payara-samples/samples/resources/mes-in-payara-resources-example/src/main/java/fish/payara/examples/Person.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2022 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.examples; + +import javax.persistence.*; + +/** + * @author mertcaliskan + */ +@Entity +@NamedQueries({ + @NamedQuery(name = "Person.findOne", query = "select p from Person p where p.id = :id"), + @NamedQuery(name = "Person.getAll", query = "select p from Person p") + } +) +public class Person { + + @Id + @GeneratedValue + private long id; + private String name; + private String lastName; + + public Person() { + } + + public Person(String name, String lastName) { + this.name = name; + this.lastName = lastName; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } +} diff --git a/appserver/tests/payara-samples/samples/resources/mes-in-payara-resources-example/src/main/java/fish/payara/examples/PersonDao.java b/appserver/tests/payara-samples/samples/resources/mes-in-payara-resources-example/src/main/java/fish/payara/examples/PersonDao.java new file mode 100644 index 00000000000..5a6870fb018 --- /dev/null +++ b/appserver/tests/payara-samples/samples/resources/mes-in-payara-resources-example/src/main/java/fish/payara/examples/PersonDao.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2022 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.examples; + +import javax.ejb.Stateless; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import java.util.List; + +/** + * @author mertcaliskan + */ +@Stateless +public class PersonDao { + + @PersistenceContext + private EntityManager entityManager; + + public List getAll() { + return entityManager.createNamedQuery("Person.getAll", Person.class).getResultList(); + } + + public Person find(Long id) { + return entityManager.createNamedQuery("Person.findOne", Person.class).setParameter("id", id).getSingleResult(); + } + + public void save(Person person) { + entityManager.persist(person); + } + + public void update(Person person) { + entityManager.merge(person); + } + + public void delete(Person person) { + entityManager.remove(person); + } +} \ No newline at end of file diff --git a/appserver/tests/payara-samples/samples/resources/mes-in-payara-resources-example/src/main/java/fish/payara/examples/PersonResource.java b/appserver/tests/payara-samples/samples/resources/mes-in-payara-resources-example/src/main/java/fish/payara/examples/PersonResource.java new file mode 100644 index 00000000000..1fb3080d462 --- /dev/null +++ b/appserver/tests/payara-samples/samples/resources/mes-in-payara-resources-example/src/main/java/fish/payara/examples/PersonResource.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2022 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.examples; + +import javax.ejb.Stateless; +import javax.inject.Inject; +import javax.ws.rs.*; +import java.util.List; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import javax.annotation.Resource; +import javax.enterprise.concurrent.ManagedExecutorService; + +/** + * Resource for people, using ManagedExecutorService. + * + * @author mertcaliskan, Petr Aubrecht + */ +@Stateless +@Path("person") +public class PersonResource { + + @Resource(lookup = "java:app/concurrent/MESPayara") + private ManagedExecutorService mes; + + @Inject + private PersonDao personDao; + + @GET + @Produces("application/json") + public List all() { + return personDao.getAll(); + } + + @POST + @Consumes("application/json") + public void save(Person person) { + personDao.save(person); + } + + @POST + @Path("create-demo") + @Consumes("application/json") + public void createDemo(Person person) throws InterruptedException, ExecutionException { + Future future1 = mes.submit(() -> { + Person p1 = new Person("John", "Doe"); + personDao.save(p1); + }); + Future future2 = mes.submit(() -> { + Person p2 = new Person("Jane", "Doe"); + personDao.save(p2); + }); + future1.get(); + future2.get(); + } + + @PUT + @Consumes("application/json") + public void update(Person person) { + personDao.update(person); + } + + @DELETE + @Path("/{id}") + @Consumes("application/json") + public void delete(@PathParam("id") Long id) { + Person person = personDao.find(id); + personDao.delete(person); + } +} diff --git a/appserver/tests/payara-samples/samples/resources/mes-in-payara-resources-example/src/main/resources/META-INF/persistence.xml b/appserver/tests/payara-samples/samples/resources/mes-in-payara-resources-example/src/main/resources/META-INF/persistence.xml new file mode 100644 index 00000000000..a2df6e184c9 --- /dev/null +++ b/appserver/tests/payara-samples/samples/resources/mes-in-payara-resources-example/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,54 @@ + + + + + org.hibernate.jpa.HibernatePersistenceProvider + java:app/jdbc/hibernate + + + + + + + + \ No newline at end of file diff --git a/appserver/tests/payara-samples/samples/resources/mes-in-payara-resources-example/src/main/webapp/WEB-INF/payara-resources.xml b/appserver/tests/payara-samples/samples/resources/mes-in-payara-resources-example/src/main/webapp/WEB-INF/payara-resources.xml new file mode 100644 index 00000000000..b2e6bb9bc3d --- /dev/null +++ b/appserver/tests/payara-samples/samples/resources/mes-in-payara-resources-example/src/main/webapp/WEB-INF/payara-resources.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/appserver/tests/payara-samples/samples/resources/mes-in-payara-resources-example/src/main/webapp/WEB-INF/web.xml b/appserver/tests/payara-samples/samples/resources/mes-in-payara-resources-example/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 00000000000..d9cbe71421a --- /dev/null +++ b/appserver/tests/payara-samples/samples/resources/mes-in-payara-resources-example/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,43 @@ + + + + + index.xhtml + + diff --git a/appserver/tests/payara-samples/samples/resources/mes-in-payara-resources-example/src/main/webapp/index.xhtml b/appserver/tests/payara-samples/samples/resources/mes-in-payara-resources-example/src/main/webapp/index.xhtml new file mode 100644 index 00000000000..140fa0528ad --- /dev/null +++ b/appserver/tests/payara-samples/samples/resources/mes-in-payara-resources-example/src/main/webapp/index.xhtml @@ -0,0 +1,48 @@ + + + + + + ManagedExecutorService in payara-resources.xml + + + +
ManagedExecutorService in payara-resources.xml demo
+ + diff --git a/appserver/tests/payara-samples/samples/resources/mes-in-payara-resources-example/src/test/java/fish/payara/examples/ConcurrencyResourcesIT.java b/appserver/tests/payara-samples/samples/resources/mes-in-payara-resources-example/src/test/java/fish/payara/examples/ConcurrencyResourcesIT.java new file mode 100644 index 00000000000..ac198631bf4 --- /dev/null +++ b/appserver/tests/payara-samples/samples/resources/mes-in-payara-resources-example/src/test/java/fish/payara/examples/ConcurrencyResourcesIT.java @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2022 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.examples; + +import fish.payara.samples.Libraries; +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.List; +import java.util.logging.Logger; +import java.util.logging.Level; +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.container.test.api.RunAsClient; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.AfterEach; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +/** + * Test REST using ManamgedExecutorService configured in payara-resources xml. + * + * @author Petr Aubrecht + */ +@ExtendWith(ArquillianExtension.class) +public class ConcurrencyResourcesIT { + + private final static Logger logger = Logger.getLogger(ConcurrencyResourcesIT.class.getName()); + + @ArquillianResource + private URL base; + + private Client client; + + @Deployment + public static WebArchive createDeployment() { + WebArchive war = ShrinkWrap.create(WebArchive.class, "mes-in-payara-resources-example.war") + .addPackage(PersonResource.class.getPackage()) + .addAsWebResource(new File("src/main/webapp/index.xhtml")) + .addAsResource(new File("src/main/resources/META-INF/persistence.xml"), "META-INF/persistence.xml") + .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") + .addAsWebInfResource(new File("src/main/webapp", "WEB-INF/payara-resources.xml")) + .addAsWebInfResource(new File("src/main/webapp", "WEB-INF/web.xml")) + .addAsLibraries(Libraries.resolveMavenCoordinatesToFiles("org.hibernate:hibernate-entitymanager")) + .addAsLibraries(Libraries.resolveMavenCoordinatesToFiles("org.hibernate:hibernate-core:5.6.9.Final")) + .addAsLibraries(Libraries.resolveMavenCoordinatesToFiles("org.hibernate.common:hibernate-commons-annotations:5.1.2.Final")) + .addAsLibraries(Libraries.resolveMavenCoordinatesToFiles("com.h2database:h2")) + .addAsLibraries(Libraries.resolveMavenCoordinatesToFiles("net.bytebuddy:byte-buddy:1.12.9")) + .addAsLibraries(Libraries.resolveMavenCoordinatesToFiles("org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:1.1.1.Final")) + .addAsLibraries(Libraries.resolveMavenCoordinatesToFiles("org.jboss:jandex:2.4.2.Final")) + .addAsLibraries(Libraries.resolveMavenCoordinatesToFiles("org.jboss.logging:jboss-logging:3.4.2.Final")) + .addAsLibraries(Libraries.resolveMavenCoordinatesToFiles("antlr:antlr:2.7.7")) + .addAsLibraries(Libraries.resolveMavenCoordinatesToFiles("com.fasterxml:classmate:1.5.1")) + .addAsLibraries(Libraries.resolveMavenCoordinatesToFiles("javax.activation:javax.activation-api:1.2.0")) + .addAsLibraries(Libraries.resolveMavenCoordinatesToFiles("org.glassfish.jaxb:jaxb-runtime:2.3.1")) + .addAsLibraries(Libraries.resolveMavenCoordinatesToFiles("org.glassfish.jaxb:txw2:2.3.1")) + .addAsLibraries(Libraries.resolveMavenCoordinatesToFiles("com.sun.xml.fastinfoset:FastInfoset:1.2.15")); + System.out.println(war.toString(true)); + return war; + } + + @BeforeEach + public void setup() throws MalformedURLException { + logger.info("setting client"); + this.client = ClientBuilder.newClient(); + List createdPeople = client + .target(new URL(this.base, "resources/person/create-demo").toExternalForm()) + .request().accept(MediaType.APPLICATION_JSON_TYPE).post(null, List.class); + System.out.println(createdPeople); + } + + @AfterEach + public void clean() throws MalformedURLException { + logger.info("close client"); + if (this.client != null) { + this.client.close(); + } + } + + @Test + @DisplayName("Test ManagedExecutorService loaded from payara-resources.xml") + @RunAsClient + public void testManagedExecutorServiceResource() throws MalformedURLException { + logger.log(Level.INFO, "Consuming service to submit rest {0}", new Object[]{client}); + WebTarget target = this.client.target(new URL(this.base, "resources/person").toExternalForm()); + logger.info(target.getUri().toASCIIString()); + String message = target.request().accept(MediaType.APPLICATION_JSON_TYPE).get(String.class); + logger.log(Level.INFO, "Returned message {0}", new Object[]{message}); + assertTrue(message.contains("\"lastName\":\"Doe\"")); + assertTrue(message.contains("\"name\":\"Jane\"}")); + assertTrue(message.contains("\"name\":\"John\"")); + } + + @Test + @DisplayName("Test ManagedScheduledExecutorService loaded from payara-resources.xml") + @RunAsClient + public void testManagedScheduledExecutorServiceResource() throws MalformedURLException { + logger.log(Level.INFO, "Consuming service to submit rest {0}", new Object[]{client}); + WebTarget target = this.client.target(new URL(this.base, "resources/concurrent/mses").toExternalForm()); + logger.info(target.getUri().toASCIIString()); + String message = target.request().accept(MediaType.TEXT_PLAIN_TYPE).get(String.class); + logger.log(Level.INFO, "Returned message {0}", new Object[]{message}); + assertEquals("MSES PRESENT", message); + } + + @Test + @DisplayName("Test ManagedThreadFactory loaded from payara-resources.xml") + @RunAsClient + public void testManagedThreadFactoryResource() throws MalformedURLException { + logger.log(Level.INFO, "Consuming service to submit rest {0}", new Object[]{client}); + WebTarget target = this.client.target(new URL(this.base, "resources/concurrent/mtf").toExternalForm()); + logger.info(target.getUri().toASCIIString()); + String message = target.request().accept(MediaType.TEXT_PLAIN_TYPE).get(String.class); + logger.log(Level.INFO, "Returned message {0}", new Object[]{message}); + assertEquals("MTF, priority 3", message); + } + +} diff --git a/appserver/tests/payara-samples/samples/resources/pom.xml b/appserver/tests/payara-samples/samples/resources/pom.xml new file mode 100644 index 00000000000..6d76e2c397d --- /dev/null +++ b/appserver/tests/payara-samples/samples/resources/pom.xml @@ -0,0 +1,59 @@ + + + + 4.0.0 + + + fish.payara.samples + payara-samples-profiled-tests + 5.40.0-SNAPSHOT + + + payara-samples-resources-tests + pom + + Payara Samples - Resources + + + mes-in-payara-resources-example + +