use of org.glassfish.deployment.common.DeploymentContextImpl in project Payara by payara.
the class DeploymentImpl method createModuleBda.
private void createModuleBda(ReadableArchive archive, Collection<EjbDescriptor> ejbs, DeploymentContext context, String moduleName) {
RootBeanDeploymentArchive rootBda = new RootBeanDeploymentArchive(archive, ejbs, context, moduleName);
BeanDeploymentArchive moduleBda = rootBda.getModuleBda();
BeansXml moduleBeansXml = moduleBda.getBeansXml();
if (moduleBeansXml == null || !moduleBeansXml.getBeanDiscoveryMode().equals(BeanDiscoveryMode.NONE)) {
addBdaToDeploymentBdas(rootBda);
addBdaToDeploymentBdas(moduleBda);
addBeanDeploymentArchives(rootBda);
}
// first check if the parent is an ear and if so see if there are app libs defined there.
if (!earContextAppLibBdasProcessed && context instanceof DeploymentContextImpl) {
DeploymentContextImpl deploymentContext = (DeploymentContextImpl) context;
DeploymentContext parentContext = deploymentContext.getParentContext();
if (parentContext != null) {
processBdasForAppLibs(parentContext.getSource(), parentContext);
parentContext.getSource();
earContextAppLibBdasProcessed = true;
}
}
// then check the module
processBdasForAppLibs(archive, context);
}
use of org.glassfish.deployment.common.DeploymentContextImpl in project Payara by payara.
the class ApplicationLoaderService method postConstruct.
/**
* Starts the application loader service.
*
* Look at the list of applications installed in our local repository
* Get a Deployer capable for each application found
* Invoke the deployer load() method for each application.
*/
public void postConstruct() {
assert env != null;
try {
logger.fine("Satisfying Optional Packages dependencies...");
InstalledLibrariesResolver.initializeInstalledLibRegistry(env.getLibPath().getAbsolutePath());
} catch (Exception e) {
logger.log(Level.WARNING, KernelLoggerInfo.exceptionOptionalDepend, e);
}
DeploymentLifecycleStatsProvider dlsp = new DeploymentLifecycleStatsProvider();
StatsProviderManager.register("deployment", PluginPoint.SERVER, "deployment/lifecycle", dlsp);
deploymentTracingEnabled = System.getProperty("org.glassfish.deployment.trace");
domain = habitat.getService(Domain.class);
/*
* Build a map that associates an application with its
* order in domain.xml. If the deployment-order attribute
* is not used for any application, then the applications
* are loaded in the order they occur in domain.xml. Also, for
* applications with the same deployment-order attribute,
* the applications are loaded in the order they occur in domain.xml.
* Otherwise, applications are loaded according to the
* deploynment-order attribute.
*/
systemApplications = domain.getSystemApplications();
for (Application systemApp : systemApplications.getApplications()) {
appOrderInfoMap.put(systemApp.getName(), Integer.valueOf(appOrder++));
}
List<Application> standaloneAdapters = applications.getApplicationsWithSnifferType(ServerTags.CONNECTOR, true);
for (Application standaloneAdapter : standaloneAdapters) {
appOrderInfoMap.put(standaloneAdapter.getName(), Integer.valueOf(appOrder++));
}
List<Application> allApplications = applications.getApplications();
for (Application app : allApplications) {
appOrderInfoMap.put(app.getName(), Integer.valueOf(appOrder++));
}
for (Application systemApp : systemApplications.getApplications()) {
// check to see if we need to load up this system application
if (Boolean.valueOf(systemApp.getDeployProperties().getProperty(ServerTags.LOAD_SYSTEM_APP_ON_STARTUP))) {
if (deployment.isAppEnabled(systemApp) || loadAppOnDAS(systemApp.getName())) {
Integer order = appOrderInfoMap.get(systemApp.getName());
ApplicationOrderInfo info = new ApplicationOrderInfo(systemApp, order);
DeploymentOrder.addApplicationDeployment(info);
}
}
}
// load standalone resource adapters first
for (Application standaloneAdapter : standaloneAdapters) {
// information is available on DAS
if (deployment.isAppEnabled(standaloneAdapter) || loadAppOnDAS(standaloneAdapter.getName())) {
DeploymentOrder.addApplicationDeployment(new ApplicationOrderInfo(standaloneAdapter, appOrderInfoMap.get(standaloneAdapter.getName()).intValue()));
}
}
// then the rest of the applications
for (Application app : allApplications) {
if (app.isStandaloneModule() && app.containsSnifferType(ServerTags.CONNECTOR)) {
continue;
}
// information is available on DAS
if (Boolean.valueOf(app.getEnabled()) || loadAppOnDAS(app.getName())) {
DeploymentOrder.addApplicationDeployment(new ApplicationOrderInfo(app, appOrderInfoMap.get(app.getName()).intValue()));
}
}
List<Deployment.ApplicationDeployment> appDeployments = new ArrayList<>();
// process the deployed applications
Iterator iter = DeploymentOrder.getApplicationDeployments();
while (iter.hasNext()) {
Application app = (Application) iter.next();
ApplicationRef appRef = server.getApplicationRef(app.getName());
if (appRef != null) {
// Does the application need to be run on this instance?
appDeployments.addAll(processApplication(app, appRef));
}
}
// does the user want us to run a particular application
String defaultParam = env.getStartupContext().getArguments().getProperty("default");
if (defaultParam != null) {
initializeRuntimeDependencies();
File sourceFile;
if (defaultParam.equals(".")) {
sourceFile = new File(System.getProperty("user.dir"));
} else {
sourceFile = new File(defaultParam);
}
if (sourceFile.exists()) {
sourceFile = sourceFile.getAbsoluteFile();
ReadableArchive sourceArchive = null;
try {
sourceArchive = archiveFactoryProvider.get().openArchive(sourceFile);
DeployCommandParameters parameters = new DeployCommandParameters(sourceFile);
parameters.name = sourceFile.getName();
parameters.enabled = Boolean.TRUE;
parameters.origin = DeployCommandParameters.Origin.deploy;
ActionReport report = new HTMLActionReporter();
if (!sourceFile.isDirectory()) {
// ok we need to explode the directory somwhere and remember to delete it on shutdown
final File tmpFile = File.createTempFile(sourceFile.getName(), "");
final String path = tmpFile.getAbsolutePath();
if (!tmpFile.delete()) {
logger.log(Level.WARNING, KernelLoggerInfo.cantDeleteTempFile, path);
}
File tmpDir = new File(path);
FileUtils.deleteOnExit(tmpDir);
events.register(new org.glassfish.api.event.EventListener() {
public void event(Event event) {
if (event.is(EventTypes.SERVER_SHUTDOWN)) {
if (tmpFile.exists()) {
FileUtils.whack(tmpFile);
}
}
}
});
if (tmpDir.mkdirs()) {
ArchiveHandler handler = deployment.getArchiveHandler(sourceArchive);
final String appName = handler.getDefaultApplicationName(sourceArchive);
DeploymentContextImpl dummyContext = new DeploymentContextImpl(report, logger, sourceArchive, parameters, env);
handler.expand(sourceArchive, archiveFactoryProvider.get().createArchive(tmpDir), dummyContext);
sourceArchive = archiveFactoryProvider.get().openArchive(tmpDir);
logger.log(Level.INFO, KernelLoggerInfo.sourceNotDirectory, tmpDir.getAbsolutePath());
parameters.name = appName;
}
}
ExtendedDeploymentContext depContext = deployment.getBuilder(logger, parameters, report).source(sourceArchive).build();
Deployment.ApplicationDeployment appDeployment = deployment.prepare(null, depContext);
if (appDeployment == null) {
logger.log(Level.SEVERE, KernelLoggerInfo.cantFindApplicationInfo, sourceFile.getAbsolutePath());
} else {
appDeployments.add(appDeployment);
}
} catch (RuntimeException | IOException e) {
logger.log(Level.SEVERE, KernelLoggerInfo.deployException, e);
} finally {
if (sourceArchive != null) {
try {
sourceArchive.close();
} catch (IOException ioe) {
// ignore
}
}
}
}
}
events.send(new Event<>(Deployment.ALL_APPLICATIONS_LOADED, null), false);
for (Deployment.ApplicationDeployment depl : appDeployments) {
deployment.initialize(depl.appInfo, depl.appInfo.getSniffers(), depl.context);
}
events.send(new Event<>(Deployment.ALL_APPLICATIONS_PROCESSED, null));
}
use of org.glassfish.deployment.common.DeploymentContextImpl in project Payara by payara.
the class CreateApplicationRefCommand method handleLifecycleModule.
private void handleLifecycleModule(AdminCommandContext context, Transaction t) {
final ActionReport report = context.getActionReport();
final Logger logger = context.getLogger();
Application app = applications.getApplication(name);
// create a dummy context to hold params and props
DeployCommandParameters commandParams = new DeployCommandParameters();
commandParams.name = name;
commandParams.target = target;
commandParams.virtualservers = virtualservers;
commandParams.enabled = enabled;
ExtendedDeploymentContext lifecycleContext = new DeploymentContextImpl(report, null, commandParams, null);
try {
deployment.registerAppInDomainXML(null, lifecycleContext, t, true);
} catch (Exception e) {
report.failure(logger, e.getMessage());
}
if (!DeploymentUtils.isDASTarget(target)) {
final ParameterMap paramMap = new ParameterMap();
paramMap.add("DEFAULT", name);
paramMap.add(DeploymentProperties.TARGET, target);
paramMap.add(DeploymentProperties.ENABLED, enabled.toString());
if (virtualservers != null) {
paramMap.add(DeploymentProperties.VIRTUAL_SERVERS, virtualservers);
}
// pass the applicationInfo props so we have the information to persist in the
// domain.xml
Properties appProps = app.getDeployProperties();
paramMap.set(DeploymentProperties.APP_PROPS, DeploymentUtils.propertiesValue(appProps, ':'));
final List<String> targets = new ArrayList<String>();
targets.add(target);
ClusterOperationUtil.replicateCommand("_lifecycle", FailurePolicy.Error, FailurePolicy.Warn, FailurePolicy.Ignore, targets, context, paramMap, habitat);
}
}
use of org.glassfish.deployment.common.DeploymentContextImpl in project Payara by payara.
the class DOLUtils method getSniffersForModule.
/**
* get sniffer list for sub modules of an ear application
*/
private static Collection<Sniffer> getSniffersForModule(ServiceLocator habitat, ReadableArchive archive, ModuleDescriptor md, Application app) throws Exception {
ArchiveHandler handler = habitat.getService(ArchiveHandler.class, md.getModuleType().toString());
SnifferManager snifferManager = habitat.getService(SnifferManager.class);
List<URI> classPathURIs = handler.getClassPathURIs(archive);
classPathURIs.addAll(getLibraryJarURIs(app, archive));
Types types = archive.getParentArchive().getExtraData(Types.class);
DeployCommandParameters parameters = archive.getParentArchive().getArchiveMetaData(DeploymentProperties.COMMAND_PARAMS, DeployCommandParameters.class);
Properties appProps = archive.getParentArchive().getArchiveMetaData(DeploymentProperties.APP_PROPS, Properties.class);
ExtendedDeploymentContext context = new DeploymentContextImpl(null, archive, parameters, habitat.<ServerEnvironment>getService(ServerEnvironment.class));
if (appProps != null) {
context.getAppProps().putAll(appProps);
}
context.setArchiveHandler(handler);
context.addTransientAppMetaData(Types.class.getName(), types);
Collection<Sniffer> sniffers = snifferManager.getSniffers(context, classPathURIs, types);
context.postDeployClean(true);
String type = getTypeFromModuleType(md.getModuleType());
Sniffer mainSniffer = null;
for (Sniffer sniffer : sniffers) {
if (sniffer.getModuleType().equals(type)) {
mainSniffer = sniffer;
}
}
// to add the appropriate sniffer
if (mainSniffer == null) {
mainSniffer = snifferManager.getSniffer(type);
sniffers.add(mainSniffer);
}
String[] incompatibleTypes = mainSniffer.getIncompatibleSnifferTypes();
List<String> allIncompatTypes = addAdditionalIncompatTypes(mainSniffer, incompatibleTypes);
List<Sniffer> sniffersToRemove = new ArrayList<>();
for (Sniffer sniffer : sniffers) {
for (String incompatType : allIncompatTypes) {
if (sniffer.getModuleType().equals(incompatType)) {
deplLogger.log(Level.WARNING, INCOMPATIBLE_TYPE, new Object[] { type, md.getArchiveUri(), incompatType });
sniffersToRemove.add(sniffer);
}
}
}
sniffers.removeAll(sniffersToRemove);
// store the module sniffer information so we don't need to
// recalculate them later
Hashtable sniffersTable = archive.getParentArchive().getExtraData(Hashtable.class);
if (sniffersTable == null) {
sniffersTable = new Hashtable<String, Collection<Sniffer>>();
archive.getParentArchive().setExtraData(Hashtable.class, sniffersTable);
}
sniffersTable.put(md.getArchiveUri(), sniffers);
return sniffers;
}
use of org.glassfish.deployment.common.DeploymentContextImpl in project Payara by payara.
the class EarHandler method getClassLoader.
public ClassLoader getClassLoader(final ClassLoader parent, DeploymentContext context) {
final ReadableArchive archive = context.getSource();
final ApplicationHolder holder = getApplicationHolder(archive, context, true);
// the ear classloader hierachy will be
// ear lib classloader <- embedded rar classloader <-
// ear classloader <- various module classloaders
final DelegatingClassLoader embeddedConnCl;
final EarClassLoader cl;
// Add the libraries packaged in the application library directory
try {
String compatProp = context.getAppProps().getProperty(COMPATIBILITY);
// let's see if it's defined in glassfish-application.xml
if (compatProp == null) {
GFApplicationXmlParser gfApplicationXmlParser = new GFApplicationXmlParser(context.getSource());
compatProp = gfApplicationXmlParser.getCompatibilityValue();
if (compatProp != null) {
context.getAppProps().put(COMPATIBILITY, compatProp);
}
}
// let's see if it's defined in sun-application.xml
if (compatProp == null) {
SunApplicationXmlParser sunApplicationXmlParser = new SunApplicationXmlParser(context.getSourceDir());
compatProp = sunApplicationXmlParser.getCompatibilityValue();
if (compatProp != null) {
context.getAppProps().put(COMPATIBILITY, compatProp);
}
}
if (getSecurityManager() != null) {
// Process declared permissions
earDeclaredPC = getDeclaredPermissions(CommponentType.ear, context);
// Process EE permissions
processEEPermissions(context);
}
final URL[] earLibURLs = ASClassLoaderUtil.getAppLibDirLibraries(context.getSourceDir(), holder.app.getLibraryDirectory(), compatProp);
final EarLibClassLoader earLibCl = AccessController.doPrivileged(new PrivilegedAction<EarLibClassLoader>() {
@Override
public EarLibClassLoader run() {
return new EarLibClassLoader(earLibURLs, parent);
}
});
String clDelegate = holder.app.getClassLoadingDelegate();
// Default to true if null
if (Boolean.parseBoolean(clDelegate == null ? "true" : clDelegate) == false) {
earLibCl.enableCurrentBeforeParentUnconditional();
} else if (clDelegate != null) {
// otherwise clDelegate == true
earLibCl.disableCurrentBeforeParent();
}
if (System.getSecurityManager() != null) {
addEEOrDeclaredPermissions(earLibCl, earDeclaredPC, false);
if (_logger.isLoggable(FINE)) {
_logger.fine("added declaredPermissions to earlib: " + earDeclaredPC);
}
addEEOrDeclaredPermissions(earLibCl, eeGarntsMap.get(CommponentType.ear), true);
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("added all ee permissions to earlib: " + eeGarntsMap.get(CommponentType.ear));
}
}
embeddedConnCl = AccessController.doPrivileged(new PrivilegedAction<DelegatingClassLoader>() {
@Override
public DelegatingClassLoader run() {
return new DelegatingClassLoader(earLibCl);
}
});
cl = AccessController.doPrivileged(new PrivilegedAction<EarClassLoader>() {
@Override
public EarClassLoader run() {
return new EarClassLoader(embeddedConnCl, holder.app);
}
});
// add ear lib to module classloader list so we can
// clean it up later
cl.addModuleClassLoader(EAR_LIB, earLibCl);
if (System.getSecurityManager() != null) {
// push declared permissions to ear classloader
addEEOrDeclaredPermissions(cl, earDeclaredPC, false);
if (_logger.isLoggable(Level.FINE))
_logger.fine("declaredPermissions added: " + earDeclaredPC);
// push ejb permissions to ear classloader
addEEOrDeclaredPermissions(cl, eeGarntsMap.get(CommponentType.ejb), true);
if (_logger.isLoggable(Level.FINE))
_logger.fine("ee permissions added: " + eeGarntsMap.get(CommponentType.ejb));
}
} catch (Exception e) {
_logger.log(Level.SEVERE, strings.get("errAddLibs"), e);
throw new RuntimeException(e);
}
for (ModuleDescriptor md : holder.app.getModules()) {
ReadableArchive sub = null;
String moduleUri = md.getArchiveUri();
try {
sub = archive.getSubArchive(moduleUri);
if (sub instanceof InputJarArchive) {
throw new IllegalArgumentException(strings.get("wrongArchType", moduleUri));
}
} catch (IOException e) {
_logger.log(Level.FINE, "Sub archive " + moduleUri + " seems unreadable", e);
}
if (sub != null) {
try {
ArchiveHandler handler = context.getModuleArchiveHandlers().get(moduleUri);
if (handler == null) {
handler = getArchiveHandlerFromModuleType(md.getModuleType());
if (handler == null) {
handler = deployment.getArchiveHandler(sub);
}
context.getModuleArchiveHandlers().put(moduleUri, handler);
}
if (handler != null) {
ActionReport subReport = context.getActionReport().addSubActionsReport();
// todo : this is a hack, once again,
// the handler is assuming a file:// url
ExtendedDeploymentContext subContext = new DeploymentContextImpl(subReport, sub, context.getCommandParameters(DeployCommandParameters.class), env) {
@Override
public File getScratchDir(String subDirName) {
String modulePortion = Util.getURIName(getSource().getURI());
return (new File(super.getScratchDir(subDirName), modulePortion));
}
};
// sub context will store the root archive handler also
// so we can figure out the enclosing archive type
subContext.setArchiveHandler(context.getArchiveHandler());
subContext.setParentContext((ExtendedDeploymentContext) context);
sub.setParentArchive(context.getSource());
ClassLoader subCl = handler.getClassLoader(cl, subContext);
if ((System.getSecurityManager() != null) && (subCl instanceof DDPermissionsLoader)) {
addEEOrDeclaredPermissions(subCl, earDeclaredPC, false);
if (_logger.isLoggable(Level.FINE))
_logger.fine("added declared permissions to sub module of " + subCl);
}
if (md.getModuleType().equals(DOLUtils.ejbType())) {
// for ejb module, we just add the ejb urls
// to EarClassLoader and use that to load
// ejb module
URL[] moduleURLs = ((URLClassLoader) subCl).getURLs();
for (URL moduleURL : moduleURLs) {
cl.addURL(moduleURL);
}
cl.addModuleClassLoader(moduleUri, cl);
PreDestroy.class.cast(subCl).preDestroy();
} else if (md.getModuleType().equals(DOLUtils.rarType())) {
embeddedConnCl.addDelegate((DelegatingClassLoader.ClassFinder) subCl);
cl.addModuleClassLoader(moduleUri, subCl);
} else {
Boolean isTempClassLoader = context.getTransientAppMetaData(ExtendedDeploymentContext.IS_TEMP_CLASSLOADER, Boolean.class);
if (subCl instanceof URLClassLoader && (isTempClassLoader != null) && isTempClassLoader) {
// for temp classloader, we add all the module
// urls to the top level EarClassLoader
URL[] moduleURLs = ((URLClassLoader) subCl).getURLs();
for (URL moduleURL : moduleURLs) {
cl.addURL(moduleURL);
}
}
cl.addModuleClassLoader(moduleUri, subCl);
}
}
} catch (IOException e) {
_logger.log(Level.SEVERE, strings.get("noClassLoader", moduleUri), e);
}
}
}
return cl;
}
Aggregations