Package org.glassfish.deployment.common
Class DeploymentContextImpl
- java.lang.Object
-
- org.glassfish.deployment.common.DeploymentContextImpl
-
- All Implemented Interfaces:
ApplicationContext
,DeploymentContext
,ExecutionContext
,org.glassfish.hk2.api.PreDestroy
,ExtendedDeploymentContext
public class DeploymentContextImpl extends Object implements ExtendedDeploymentContext, org.glassfish.hk2.api.PreDestroy
- Author:
- dochez
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.glassfish.internal.deployment.ExtendedDeploymentContext
ExtendedDeploymentContext.Phase
-
-
Field Summary
Fields Modifier and Type Field Description static Logger
deplLogger
-
Fields inherited from interface org.glassfish.internal.deployment.ExtendedDeploymentContext
IS_TEMP_CLASSLOADER, TRACKER
-
-
Constructor Summary
Constructors Constructor Description DeploymentContextImpl(ActionReport actionReport, Logger logger, ReadableArchive source, OpsParams params, ServerEnvironment env)
DeploymentContextImpl(ActionReport actionReport, ReadableArchive source, OpsParams params, ServerEnvironment env)
DeploymentContextImpl(Deployment.DeploymentContextBuilder builder, ServerEnvironment env)
Creates a new instance of DeploymentContext
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addModuleMetaData(Object metaData)
Stores a descriptor for the module in the context so other deployer's can have access to it.void
addTransformer(ClassFileTransformer transformer)
Add a new ClassFileTransformer to the contextvoid
addTransientAppMetaData(String metaDataKey, Object metaData)
Stores application level metadata in the context so other deployer's can have access to it.void
clean()
void
createApplicationClassLoader(ClassLoaderHierarchy clh, ArchiveHandler handler)
Create the final class loader.It will be used to load and start application.void
createDeploymentClassLoader(ClassLoaderHierarchy clh, ArchiveHandler handler)
Create the deployment class loader.It will be used for sniffer retrieval, metadata parsing and deployer prepare.ActionReport
getActionReport()
Gets the action report for this contextFile
getAppAltDDDir()
Returns the alternate deployment descriptor directory for the application (used for holding the external alternate deployment descriptors).File
getAppInternalDir()
Returns the internal directory for the application (used for holding the uploaded archive, for example).List<URI>
getAppLibs()
gets the app-libs specified for this archive
This list includes --libraries as well EXTENSION_LIST specified in the manifest entriesProperties
getAppProps()
Returns the application level properties that will be persisted as a key value pair at then end of deployment.ArchiveHandler
getArchiveHandler()
Returns the archive handler that's associated with this contextClassLoader
getClassLoader()
Returns the class loader associated to this deployment request.ClassLoader
getClassLoader(boolean sharable)
<U extends OpsParams>
UgetCommandParameters(Class<U> commandParametersType)
Returns the DeployCommand parametersClassLoader
getFinalClassLoader()
Returns the class loader associated to this deployment request.Logger
getLogger()
Returns the logger services implementation should use to log useful information about their execution.Map<String,ArchiveHandler>
getModuleArchiveHandlers()
Gets the archive handlers for modulesMap<String,ExtendedDeploymentContext>
getModuleDeploymentContexts()
Gets the deployment context for modulesCollection<Object>
getModuleMetadata()
Returns all the metadata associated with this deployment<T> T
getModuleMetaData(Class<T> metadataType)
Returns the meta data associated with a module type.Properties
getModuleProps()
Returns the module level properties that will be persisted as a key value pair at then end of deployment.Map<String,Properties>
getModulePropsMap()
Gets the module properties for modulesString
getModuleUri()
Gets the module uri for this module contextReadableArchive
getOriginalSource()
Gets the original source archive In case of archive deployment, this will return the archive before expanding.ExtendedDeploymentContext
getParentContext()
Gets the parent context of the moduleExtendedDeploymentContext.Phase
getPhase()
File
getScratchDir(String subDirName)
Returns a scratch directory that can be used to store things in.ReadableArchive
getSource()
Application bits, at the raw level.File
getSourceDir()
Returns the directory where the original applications bits should be stored.String
getTenant()
Returns the tenant, if one is valid for this DeploymentContext.File
getTenantDir()
Returns the directory containing the expanded tenant customization archive, if this DC is for a tenant and if a customization archive was specified when the tenant was provisioned.List<ClassFileTransformer>
getTransformers()
Returns the list of transformers registered to this context.Map<String,Object>
getTransientAppMetadata()
Returns all the transient app metadata associated with this deployment<T> T
getTransientAppMetaData(String key, Class<T> metadataType)
Returns the meta data for the given keyvoid
postDeployClean(boolean isFinalClean)
Performs any clean-up of the deployment context after deployment has finished.void
preDestroy()
void
prepareScratchDirs()
Prepare the scratch directories, creating the directories if they do not existvoid
removeTransientAppMetaData(String metaDataKey)
Removes application level metadata of input key from the context.void
resetModuleMetaData()
Reset the meta data associated with a module type.void
setArchiveHandler(ArchiveHandler archiveHandler)
Sets the archive handler that's associated with this contextvoid
setClassLoader(ClassLoader cloader)
Sets the application classloadervoid
setModulePropsMap(Map<String,Properties> modulePropsMap)
Sets the module properties for modulesvoid
setModuleUri(String moduleUri)
Sets the module uri for this module contextvoid
setParentContext(ExtendedDeploymentContext parentContext)
Sets the parent context for the modulevoid
setPhase(ExtendedDeploymentContext.Phase newPhase)
Sets the phase of the deployment activity.void
setSource(ReadableArchive source)
Sets the source archivevoid
setTenant(String tenant, String appName)
Sets the tenant to which this deployment context applies.
-
-
-
Field Detail
-
deplLogger
public static final Logger deplLogger
-
-
Constructor Detail
-
DeploymentContextImpl
public DeploymentContextImpl(Deployment.DeploymentContextBuilder builder, ServerEnvironment env)
Creates a new instance of DeploymentContext- Parameters:
builder
-env
-
-
DeploymentContextImpl
public DeploymentContextImpl(ActionReport actionReport, Logger logger, ReadableArchive source, OpsParams params, ServerEnvironment env)
-
DeploymentContextImpl
public DeploymentContextImpl(ActionReport actionReport, ReadableArchive source, OpsParams params, ServerEnvironment env)
-
-
Method Detail
-
getPhase
public ExtendedDeploymentContext.Phase getPhase()
- Specified by:
getPhase
in interfaceExtendedDeploymentContext
-
setPhase
public void setPhase(ExtendedDeploymentContext.Phase newPhase)
Description copied from interface:ExtendedDeploymentContext
Sets the phase of the deployment activity.- Specified by:
setPhase
in interfaceExtendedDeploymentContext
-
getSource
public ReadableArchive getSource()
Description copied from interface:DeploymentContext
Application bits, at the raw level. Deployer's should avoid using such low level access as it binds the deployer to a particular directory layout. Instead Deployers should use the class loader obtained via the getClassLoader() API- Specified by:
getSource
in interfaceDeploymentContext
- Returns:
- Abstraction to the application's source archive.
-
setSource
public void setSource(ReadableArchive source)
Description copied from interface:ExtendedDeploymentContext
Sets the source archive- Specified by:
setSource
in interfaceExtendedDeploymentContext
-
getCommandParameters
public <U extends OpsParams> U getCommandParameters(Class<U> commandParametersType)
Description copied from interface:DeploymentContext
Returns the DeployCommand parameters- Specified by:
getCommandParameters
in interfaceDeploymentContext
- Parameters:
commandParametersType
- expected deployment operation parameters type.- Returns:
- the command parameters
-
getLogger
public Logger getLogger()
Description copied from interface:ExecutionContext
Returns the logger services implementation should use to log useful information about their execution.- Specified by:
getLogger
in interfaceExecutionContext
- Returns:
- the services logger
-
preDestroy
public void preDestroy()
- Specified by:
preDestroy
in interfaceorg.glassfish.hk2.api.PreDestroy
-
getFinalClassLoader
public ClassLoader getFinalClassLoader()
Returns the class loader associated to this deployment request. ClassLoader instances are usually obtained by the getClassLoader API on the associated ArchiveHandler for the archive type being deployed. This can return null and the container should allocate a ClassLoader while loading the application.- Specified by:
getFinalClassLoader
in interfaceDeploymentContext
- Returns:
- a class loader capable of loading classes and resources from the source
-
getClassLoader
public ClassLoader getClassLoader()
Returns the class loader associated to this deployment request. ClassLoader instances are usually obtained by the getClassLoader API on the associated ArchiveHandler for the archive type being deployed. This can return null and the container should allocate a ClassLoader while loading the application.- Specified by:
getClassLoader
in interfaceApplicationContext
- Returns:
- a class loader capable of loading classes and resources from the source
-
setClassLoader
public void setClassLoader(ClassLoader cloader)
Description copied from interface:ExtendedDeploymentContext
Sets the application classloader- Specified by:
setClassLoader
in interfaceExtendedDeploymentContext
-
createDeploymentClassLoader
public void createDeploymentClassLoader(ClassLoaderHierarchy clh, ArchiveHandler handler) throws URISyntaxException, MalformedURLException
Description copied from interface:ExtendedDeploymentContext
Create the deployment class loader.It will be used for sniffer retrieval, metadata parsing and deployer prepare.- Specified by:
createDeploymentClassLoader
in interfaceExtendedDeploymentContext
- Parameters:
clh
- the hierarchy of class loader for the parenthandler
- the archive handler for the source archive- Throws:
URISyntaxException
MalformedURLException
-
createApplicationClassLoader
public void createApplicationClassLoader(ClassLoaderHierarchy clh, ArchiveHandler handler) throws URISyntaxException, MalformedURLException
Description copied from interface:ExtendedDeploymentContext
Create the final class loader.It will be used to load and start application.- Specified by:
createApplicationClassLoader
in interfaceExtendedDeploymentContext
- Parameters:
clh
- the hierarchy of class loader for the parenthandler
- the archive handler for the source archive- Throws:
URISyntaxException
MalformedURLException
-
getClassLoader
public ClassLoader getClassLoader(boolean sharable)
-
getScratchDir
public File getScratchDir(String subDirName)
Returns a scratch directory that can be used to store things in. The scratch directory will be persisted across server restart but not across redeployment of the same application- Specified by:
getScratchDir
in interfaceDeploymentContext
- Parameters:
subDirName
- the sub directory name of the scratch dir- Returns:
- the scratch directory for this application based on passed in subDirName. Returns the root scratch dir if the passed in value is null.
-
getSourceDir
public File getSourceDir()
Returns the directory where the original applications bits should be stored. This is useful when users deploy an archive file that need to be unzipped somewhere for the container to work with.- Specified by:
getSourceDir
in interfaceDeploymentContext
- Returns:
- the source directory for this application
-
addModuleMetaData
public void addModuleMetaData(Object metaData)
Description copied from interface:DeploymentContext
Stores a descriptor for the module in the context so other deployer's can have access to it. Module meta-data is usual not persistent which mean that any modification to it will not be available at the next server restart and will need to be reset.- Specified by:
addModuleMetaData
in interfaceDeploymentContext
- Parameters:
metaData
- the meta data itself
-
resetModuleMetaData
public void resetModuleMetaData()
Description copied from interface:DeploymentContext
Reset the meta data associated with a module type.- Specified by:
resetModuleMetaData
in interfaceDeploymentContext
-
getModuleMetaData
public <T> T getModuleMetaData(Class<T> metadataType)
Description copied from interface:DeploymentContext
Returns the meta data associated with a module type.- Specified by:
getModuleMetaData
in interfaceDeploymentContext
- Parameters:
metadataType
- type of the meta date.- Returns:
- instance of T or null
-
getModuleMetadata
public Collection<Object> getModuleMetadata()
Description copied from interface:DeploymentContext
Returns all the metadata associated with this deployment- Specified by:
getModuleMetadata
in interfaceDeploymentContext
- Returns:
- collection of metadata added to the context
-
getTransientAppMetadata
public Map<String,Object> getTransientAppMetadata()
Description copied from interface:DeploymentContext
Returns all the transient app metadata associated with this deployment- Specified by:
getTransientAppMetadata
in interfaceDeploymentContext
- Returns:
- collection of metadata added to the context
-
addTransientAppMetaData
public void addTransientAppMetaData(String metaDataKey, Object metaData)
Description copied from interface:DeploymentContext
Stores application level metadata in the context so other deployer's can have access to it. The transient meta-data is not persistent which mean that any modification to it will not be available at the next server restart and will need to be reset.- Specified by:
addTransientAppMetaData
in interfaceDeploymentContext
- Parameters:
metaDataKey
- key of the meta date.metaData
- the meta data itself
-
removeTransientAppMetaData
public void removeTransientAppMetaData(String metaDataKey)
Description copied from interface:DeploymentContext
Removes application level metadata of input key from the context.- Specified by:
removeTransientAppMetaData
in interfaceDeploymentContext
- Parameters:
metaDataKey
- key of the meta date.
-
getTransientAppMetaData
public <T> T getTransientAppMetaData(String key, Class<T> metadataType)
Description copied from interface:DeploymentContext
Returns the meta data for the given key- Specified by:
getTransientAppMetaData
in interfaceDeploymentContext
- Parameters:
key
- key of the meta date.metadataType
- type of the meta date.- Returns:
- instance of T or null
-
getAppProps
public Properties getAppProps()
Returns the application level properties that will be persisted as a key value pair at then end of deployment. That allows individual Deployers implementation to store some information at the application level that should be available upon server restart. Application level properties are shared by all the modules.- Specified by:
getAppProps
in interfaceApplicationContext
- Returns:
- the application's properties.
-
getModuleProps
public Properties getModuleProps()
Returns the module level properties that will be persisted as a key value pair at then end of deployment. That allows individual Deployers implementation to store some information at the module level that should be available upon server restart. Module level properties are only visible to the current module.- Specified by:
getModuleProps
in interfaceApplicationContext
- Returns:
- the module's properties.
-
addTransformer
public void addTransformer(ClassFileTransformer transformer)
Add a new ClassFileTransformer to the context- Specified by:
addTransformer
in interfaceDeploymentContext
- Parameters:
transformer
- the new class file transformer to register to the new application class loader- Throws:
UnsupportedOperationException
- if the class loader we use does not support the registration of a ClassFileTransformer. In such case, the deployer should either fail deployment or revert to a mode without the bytecode enhancement feature.
-
getTransformers
public List<ClassFileTransformer> getTransformers()
Returns the list of transformers registered to this context.- Specified by:
getTransformers
in interfaceExtendedDeploymentContext
- Returns:
- the transformers list
-
getAppLibs
public List<URI> getAppLibs() throws URISyntaxException
Description copied from interface:DeploymentContext
gets the app-libs specified for this archive
This list includes --libraries as well EXTENSION_LIST specified in the manifest entries- Specified by:
getAppLibs
in interfaceDeploymentContext
- Returns:
- list of library URIs
- Throws:
URISyntaxException
- when unable to get the library URIs
-
clean
public void clean()
- Specified by:
clean
in interfaceExtendedDeploymentContext
-
getArchiveHandler
public ArchiveHandler getArchiveHandler()
Description copied from interface:DeploymentContext
Returns the archive handler that's associated with this context- Specified by:
getArchiveHandler
in interfaceDeploymentContext
- Returns:
- archive handler
-
setArchiveHandler
public void setArchiveHandler(ArchiveHandler archiveHandler)
Description copied from interface:ExtendedDeploymentContext
Sets the archive handler that's associated with this context- Specified by:
setArchiveHandler
in interfaceExtendedDeploymentContext
-
getOriginalSource
public ReadableArchive getOriginalSource()
Description copied from interface:DeploymentContext
Gets the original source archive In case of archive deployment, this will return the archive before expanding. In case of directory deployment, this will return the same thing as getSource()- Specified by:
getOriginalSource
in interfaceDeploymentContext
- Returns:
- the original source archive
-
getModulePropsMap
public Map<String,Properties> getModulePropsMap()
Gets the module properties for modules- Specified by:
getModulePropsMap
in interfaceDeploymentContext
- Returns:
- a map containing module properties
-
setModulePropsMap
public void setModulePropsMap(Map<String,Properties> modulePropsMap)
Sets the module properties for modules- Specified by:
setModulePropsMap
in interfaceExtendedDeploymentContext
- Parameters:
modulePropsMap
-
-
setParentContext
public void setParentContext(ExtendedDeploymentContext parentContext)
Sets the parent context for the module- Specified by:
setParentContext
in interfaceExtendedDeploymentContext
- Parameters:
parentContext
-
-
getParentContext
public ExtendedDeploymentContext getParentContext()
Gets the parent context of the module- Specified by:
getParentContext
in interfaceExtendedDeploymentContext
- Returns:
- the parent context
-
getModuleUri
public String getModuleUri()
Gets the module uri for this module context- Specified by:
getModuleUri
in interfaceExtendedDeploymentContext
- Returns:
- the module uri
-
setModuleUri
public void setModuleUri(String moduleUri)
Sets the module uri for this module context- Specified by:
setModuleUri
in interfaceExtendedDeploymentContext
- Parameters:
moduleUri
-
-
getModuleArchiveHandlers
public Map<String,ArchiveHandler> getModuleArchiveHandlers()
Gets the archive handlers for modules- Specified by:
getModuleArchiveHandlers
in interfaceDeploymentContext
- Returns:
- a map containing module archive handlers
-
getModuleDeploymentContexts
public Map<String,ExtendedDeploymentContext> getModuleDeploymentContexts()
Gets the deployment context for modules- Specified by:
getModuleDeploymentContexts
in interfaceExtendedDeploymentContext
- Returns:
- a map containing module deployment contexts
-
getActionReport
public ActionReport getActionReport()
Gets the action report for this context- Specified by:
getActionReport
in interfaceDeploymentContext
- Returns:
- an action report
-
getAppInternalDir
public File getAppInternalDir()
Description copied from interface:ExtendedDeploymentContext
Returns the internal directory for the application (used for holding the uploaded archive, for example).- Specified by:
getAppInternalDir
in interfaceExtendedDeploymentContext
- Returns:
- location of the internal directory for the application
-
getAppAltDDDir
public File getAppAltDDDir()
Description copied from interface:ExtendedDeploymentContext
Returns the alternate deployment descriptor directory for the application (used for holding the external alternate deployment descriptors).- Specified by:
getAppAltDDDir
in interfaceExtendedDeploymentContext
- Returns:
- location of the alternate deployment descriptor directory for the application
-
setTenant
public void setTenant(String tenant, String appName)
Description copied from interface:ExtendedDeploymentContext
Sets the tenant to which this deployment context applies. Also initializes the tenant directory.- Specified by:
setTenant
in interfaceExtendedDeploymentContext
- Parameters:
tenant
- the name of the tenantappName
- the name of the application
-
getTenant
public String getTenant()
Description copied from interface:ExtendedDeploymentContext
Returns the tenant, if one is valid for this DeploymentContext.- Specified by:
getTenant
in interfaceExtendedDeploymentContext
- Returns:
- tenant name if applicable, null if no tenant is set for this DC
-
getTenantDir
public File getTenantDir()
Description copied from interface:ExtendedDeploymentContext
Returns the directory containing the expanded tenant customization archive, if this DC is for a tenant and if a customization archive was specified when the tenant was provisioned.- Specified by:
getTenantDir
in interfaceExtendedDeploymentContext
- Returns:
- directory containing the expanded customization archive; null if none
-
postDeployClean
public void postDeployClean(boolean isFinalClean)
Description copied from interface:ExtendedDeploymentContext
Performs any clean-up of the deployment context after deployment has finished.This method can be invoked either with "true", meaning that this is the final clean-up for the DC, or with "false," meaning that the DC implementation should be selective. (Some data is used, for instance, in the DeployCommand logic after ApplicationLifeCycle.deploy has completed.)
- Specified by:
postDeployClean
in interfaceExtendedDeploymentContext
- Parameters:
isFinalClean
- whether this clean is the final clean or a selective one.
-
prepareScratchDirs
public void prepareScratchDirs() throws IOException
Prepare the scratch directories, creating the directories if they do not exist- Specified by:
prepareScratchDirs
in interfaceExtendedDeploymentContext
- Throws:
IOException
-
-