Skip to content

Commit

Permalink
EjbDescriptor, Archivist, cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: David Matějček <david.matejcek@omnifish.ee>
  • Loading branch information
dmatej committed Sep 18, 2022
1 parent d3071b5 commit 89b1064
Show file tree
Hide file tree
Showing 15 changed files with 236 additions and 278 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -17,7 +18,6 @@
package org.glassfish.appclient.client.acc;

import com.sun.enterprise.module.ModulesRegistry;
import com.sun.enterprise.module.bootstrap.ContextDuplicatePostProcessor;
import com.sun.enterprise.module.bootstrap.StartupContext;
import com.sun.enterprise.module.single.StaticModulesRegistry;
import com.sun.enterprise.naming.impl.ClientNamingConfiguratorImpl;
Expand All @@ -32,13 +32,14 @@
import org.glassfish.api.naming.ClientNamingConfigurator;
import org.glassfish.hk2.api.DynamicConfiguration;
import org.glassfish.hk2.api.DynamicConfigurationService;
import org.glassfish.hk2.api.PopulatorPostProcessor;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.hk2.api.ServiceLocatorFactory;
import org.glassfish.hk2.bootstrap.HK2Populator;
import org.glassfish.hk2.bootstrap.PopulatorPostProcessor;
import org.glassfish.hk2.bootstrap.impl.ClasspathDescriptorFileFinder;
import org.glassfish.hk2.utilities.AbstractActiveDescriptor;
import org.glassfish.hk2.utilities.BuilderHelper;
import org.glassfish.hk2.utilities.ClasspathDescriptorFileFinder;
import org.glassfish.hk2.utilities.DuplicatePostProcessor;
import org.glassfish.internal.api.Globals;

/**
Expand All @@ -59,7 +60,7 @@
*/
public class ACCModulesManager /*implements ModuleStartup*/ {

private static ServiceLocator habitat = null;
private static ServiceLocator habitat;

public synchronized static void initialize(final ClassLoader loader) throws URISyntaxException {
/*
Expand Down Expand Up @@ -107,8 +108,8 @@ public synchronized static void initialize(final ClassLoader loader) throws URIS
ModulesRegistry modulesRegistry = new StaticModulesRegistry(ACCModulesManager.class.getClassLoader());
config.addActiveDescriptor(BuilderHelper.createConstantDescriptor(modulesRegistry));

config.addActiveDescriptor(BuilderHelper.createConstantDescriptor(
new ProcessEnvironment(ProcessEnvironment.ProcessType.ACC)));
config.addActiveDescriptor(
BuilderHelper.createConstantDescriptor(new ProcessEnvironment(ProcessEnvironment.ProcessType.ACC)));

/*
* Create the ClientNamingConfigurator used by naming.
Expand All @@ -134,24 +135,25 @@ public static <T> T getService(Class<T> c) {
return habitat.getService(c);
}


/**
* Sets up the HK2 habitat.
* <p>
* Must be invoked at least once before an AppClientContainerBuilder
* returns a new AppClientContainer to the caller.
*
* @param classLoader
* @param logger
* @throws com.sun.enterprise.module.bootstrap.BootException
* @throws java.net.URISyntaxException
*/
private static ServiceLocator prepareHabitat(
final ClassLoader loader) {
private static ServiceLocator prepareHabitat(final ClassLoader loader) {
ServiceLocator serviceLocator = ServiceLocatorFactory.getInstance().create("default");

habitat = serviceLocator;

ContextDuplicatePostProcessor duplicateProcessor = new ContextDuplicatePostProcessor();
List<PopulatorPostProcessor> postProcessors = new LinkedList<PopulatorPostProcessor>();
DuplicatePostProcessor duplicateProcessor = new DuplicatePostProcessor();
List<PopulatorPostProcessor> postProcessors = new LinkedList<>();
postProcessors.add(duplicateProcessor);

try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -16,57 +17,56 @@

package com.sun.enterprise.connectors.module;

import com.sun.appserv.connectors.internal.api.ConnectorConstants;
import com.sun.appserv.connectors.internal.api.ConnectorsUtil;
import com.sun.enterprise.config.serverbeans.Resource;
import com.sun.enterprise.config.serverbeans.Resources;
import com.sun.enterprise.connectors.ConnectorRuntime;
import com.sun.enterprise.connectors.util.ResourcesUtil;
import com.sun.enterprise.deployment.ConnectorDescriptor;
import com.sun.enterprise.util.i18n.StringManager;
import com.sun.logging.LogDomains;

import java.util.Collection;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.glassfish.api.ActionReport;
import org.glassfish.api.deployment.*;
import org.glassfish.api.deployment.ApplicationContainer;
import org.glassfish.api.deployment.ApplicationContext;
import org.glassfish.api.deployment.DeploymentContext;
import org.glassfish.api.deployment.OpsParams;
import org.glassfish.api.deployment.UndeployCommandParameters;
import org.glassfish.api.event.EventListener;
import org.glassfish.api.event.Events;
import org.glassfish.connectors.config.AdminObjectResource;
import org.glassfish.connectors.config.ConnectorConnectionPool;
import org.glassfish.internal.deployment.Deployment;
import org.glassfish.resourcebase.resources.api.ResourceConstants;
import org.glassfish.resourcebase.resources.listener.ResourceManager;
import org.glassfish.resources.listener.ApplicationScopedResourcesManager;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* Represents a connector application, one per resource-adapter.
* GlassFish kernel will call start/stop of connector application during start/stop of server and
* deploy/undeploy of the resource-adapter.
*
* @author Jagadish Ramu
*/
public class ConnectorApplication implements ApplicationContainer, EventListener {
private static Logger _logger = LogDomains.getLogger(ConnectorApplication.class, LogDomains.RSR_LOGGER);
public class ConnectorApplication implements ApplicationContainer<ConnectorDescriptor>, EventListener {
private static final Logger LOG = LogDomains.getLogger(ConnectorApplication.class, LogDomains.RSR_LOGGER);
private String moduleName = "";
//indicates the "application" (ear) name if its embedded rar
private String applicationName = null;
private org.glassfish.resourcebase.resources.listener.ResourceManager resourceManager;
private ApplicationScopedResourcesManager asrManager;
private ClassLoader loader;
private ConnectorRuntime runtime;
private Events event;
private ConnectorDescriptor descriptor;
private final String applicationName;
private final ResourceManager resourceManager;
private final ClassLoader loader;
private final ConnectorRuntime runtime;
private final Events event;
private final ConnectorDescriptor descriptor;
private static StringManager localStrings = StringManager.getManager(ConnectorRuntime.class);
private ResourcesUtil resourcesUtil;
private final ResourcesUtil resourcesUtil;

public ConnectorApplication(String moduleName, String appName, org.glassfish.resourcebase.resources.listener.ResourceManager resourceManager,
ApplicationScopedResourcesManager asrManager, ClassLoader loader,
ConnectorRuntime runtime, Events event, ConnectorDescriptor descriptor) {
public ConnectorApplication(String moduleName, String appName, ResourceManager resourceManager,
ApplicationScopedResourcesManager asrManager, ClassLoader loader, ConnectorRuntime runtime, Events event,
ConnectorDescriptor descriptor) {
this.setModuleName(moduleName);
this.resourceManager = resourceManager;
this.asrManager = asrManager;
this.loader = loader;
this.runtime = runtime;
this.applicationName = appName;
Expand All @@ -80,7 +80,8 @@ public ConnectorApplication(String moduleName, String appName, org.glassfish.res
*
* @return deployment descriptor if they exist or null if not
*/
public Object getDescriptor() {
@Override
public ConnectorDescriptor getDescriptor() {
return descriptor;
}

Expand All @@ -94,6 +95,7 @@ public Object getDescriptor() {
* @param startupContext the start up context
* @return true if the container startup was successful.
*/
@Override
public boolean start(ApplicationContext startupContext) {
boolean started = false;

Expand All @@ -104,7 +106,7 @@ public boolean start(ApplicationContext startupContext) {

event.register(this);

logFine("Resource Adapter [ " + getModuleName() + " ] started");
LOG.log(Level.INFO, "Resource Adapter [ {0} ] started", getModuleName());
return started;
}

Expand Down Expand Up @@ -150,22 +152,18 @@ public void undeployApplicationScopedResources() {
* undeploy all resources/pools pertaining to this resource adapter
*/
public boolean undeployGlobalResources(boolean failIfResourcesExist) {
boolean status;
//TODO ASR : should we undeploy app-scoped connector resources also ?
//TODO ASR : should we stop deployment by checking app-scoped connector resources also ?
Collection<Resource> resources =
resourcesUtil.filterConnectorResources(resourceManager.getAllResources(), moduleName, true);
if (failIfResourcesExist && resources.size() > 0) {
if (failIfResourcesExist && !resources.isEmpty()) {
String message = "one or more resources of resource-adapter [ " + moduleName + " ] exist, " +
"use '--cascade=true' to delete them during undeploy";
_logger.log(Level.WARNING, "resources.of.rar.exist", moduleName);
status = false;
LOG.log(Level.WARNING, "resources.of.rar.exist", moduleName);
throw new RuntimeException(message);
} else {
resourceManager.undeployResources(resources);
status = true;
}
return status;
resourceManager.undeployResources(resources);
return true;
}

/**
Expand All @@ -174,6 +172,7 @@ public boolean undeployGlobalResources(boolean failIfResourcesExist) {
* @param stopContext
* @return true if stopping was successful.
*/
@Override
public boolean stop(ApplicationContext stopContext) {
boolean stopped = false;

Expand All @@ -196,7 +195,7 @@ public boolean stop(ApplicationContext stopContext) {
} else {
runtime.unregisterConnectorApplication(getModuleName());
stopped = true;
logFine("Resource Adapter [ " + getModuleName() + " ] stopped");
LOG.log(Level.INFO, "Resource Adapter [ {0} ] stopped", getModuleName());
event.unregister(this);
}
return stopped;
Expand All @@ -207,6 +206,7 @@ public boolean stop(ApplicationContext stopContext) {
*
* @return true if suspending was successful, false otherwise.
*/
@Override
public boolean suspend() {
// Not (yet) supported
return false;
Expand All @@ -217,6 +217,7 @@ public boolean suspend() {
*
* @return true if resumption was successful, false otherwise.
*/
@Override
public boolean resume() {
// Not (yet) supported
return false;
Expand All @@ -227,15 +228,11 @@ public boolean resume() {
*
* @return ClassLoader for this app
*/
@Override
public ClassLoader getClassLoader() {
return loader;
}

public void logFine(String message) {
if(_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, message);
}
}

/**
* returns the module name
Expand Down Expand Up @@ -265,28 +262,26 @@ public String getApplicationName() {
* and --cascade is not set.
* @param event Event
*/
@Override
public void event(Event event) {
if (Deployment.UNDEPLOYMENT_VALIDATION.equals(event.type())) {
//this is an application undeploy event
// this is an application undeploy event
DeploymentContext dc = (DeploymentContext) event.hook();
UndeployCommandParameters dcp = dc.getCommandParameters(UndeployCommandParameters.class);
if (dcp.name.equals(moduleName) ||
//Consider the application with embedded RAR being undeployed
(dcp.name.equals(applicationName) &&
moduleName.contains(ConnectorConstants.EMBEDDEDRAR_NAME_DELIMITER) &&
moduleName.startsWith(dcp.name))) {
// Consider the application with embedded RAR being undeployed
if (dcp.name.equals(moduleName) || (dcp.name.equals(applicationName)
&& moduleName.contains(ResourceConstants.EMBEDDEDRAR_NAME_DELIMITER)
&& moduleName.startsWith(dcp.name))) {

if (dcp.origin != OpsParams.Origin.deploy) {
if (dcp.origin == OpsParams.Origin.undeploy) {
if (!(dcp._ignoreCascade || dcp.cascade)) {
if (resourcesUtil.filterConnectorResources(resourceManager.getAllResources(), moduleName, true).size() > 0) {
String message = localStrings.getString("con.deployer.resources.exist", moduleName);
_logger.log(Level.WARNING, "resources.of.rar.exist", moduleName);
if (dcp.origin != OpsParams.Origin.deploy && dcp.origin == OpsParams.Origin.undeploy) {
if (!dcp._ignoreCascade && !dcp.cascade) {
if (!resourcesUtil.filterConnectorResources(resourceManager.getAllResources(), moduleName, true).isEmpty()) {
String message = localStrings.getString("con.deployer.resources.exist", moduleName);
LOG.log(Level.WARNING, "resources.of.rar.exist", moduleName);

ActionReport report = dc.getActionReport();
report.setMessage(message);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
}
ActionReport report = dc.getActionReport();
report.setMessage(message);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation.
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022 Contributors to Eclipse Foundation. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -28,30 +28,27 @@
import java.util.logging.Level;
import java.util.logging.Logger;


public final class ConnectionPoolReconfigHelper {

private static final Logger _logger = LogDomains.getLogger(ConnectionPoolReconfigHelper.class, LogDomains.RSR_LOGGER);

private static final Logger _logger = LogDomains.getLogger(ConnectionPoolReconfigHelper.class,
LogDomains.RSR_LOGGER);

public enum ReconfigAction {
RECREATE_POOL, UPDATE_MCF_AND_ATTRIBUTES, NO_OP
RECREATE_POOL,
UPDATE_MCF_AND_ATTRIBUTES,
NO_OP
}

public static ReconfigAction compare(ConnectorConnectionPool oldPool,
ConnectorConnectionPool newPool, Set excludedProps)
throws ConnectorRuntimeException {

if (isEqualConnectorConnectionPool(oldPool, newPool, excludedProps)
== ReconfigAction.NO_OP) {

public static ReconfigAction compare(ConnectorConnectionPool oldPool, ConnectorConnectionPool newPool,
Set excludedProps) throws ConnectorRuntimeException {
if (isEqualConnectorConnectionPool(oldPool, newPool, excludedProps) == ReconfigAction.NO_OP) {
return ReconfigAction.UPDATE_MCF_AND_ATTRIBUTES;
}

return ReconfigAction.RECREATE_POOL;
}

/*

/**
* Compare the Original ConnectorConnectionPool with the passed one
* If MCF properties are changed, indicate that pool recreation is
* required
Expand All @@ -61,8 +58,9 @@ public static ReconfigAction compare(ConnectorConnectionPool oldPool,
* If the new pool and old pool have identical MCF properties returns
* true
*/
private static ReconfigAction isEqualConnectorConnectionPool(ConnectorConnectionPool
oldCcp, ConnectorConnectionPool newCcp, Set excludedProps) {
private static ReconfigAction isEqualConnectorConnectionPool(ConnectorConnectionPool oldCcp,
ConnectorConnectionPool newCcp, Set excludedProps) {

//for all the following properties, we need to recreate pool if they
//have changed
if(newCcp.isPoolingOn() != oldCcp.isPoolingOn()) {
Expand Down Expand Up @@ -148,11 +146,9 @@ private static ReconfigAction isEqualConnectorConnectionPool(ConnectorConnection
}

ConnectorSecurityMap[] newSecurityMaps = newCcp.getSecurityMaps();
RuntimeSecurityMap newRuntimeSecurityMap =
SecurityMapUtils.processSecurityMaps(newSecurityMaps);
RuntimeSecurityMap newRuntimeSecurityMap = SecurityMapUtils.processSecurityMaps(newSecurityMaps);
ConnectorSecurityMap[] oldSecurityMaps = oldCcp.getSecurityMaps();
RuntimeSecurityMap oldRuntimeSecurityMap =
SecurityMapUtils.processSecurityMaps(oldSecurityMaps);
RuntimeSecurityMap oldRuntimeSecurityMap = SecurityMapUtils.processSecurityMaps(oldSecurityMaps);
if (!(oldRuntimeSecurityMap.equals(newRuntimeSecurityMap))) {
logFine("isEqualConnectorConnectionPool: CCP.getSecurityMaps:: " +
"New set of Security Maps is not equal to the existing" +
Expand Down

0 comments on commit 89b1064

Please sign in to comment.