use of org.glassfish.deployment.common.DeploymentContextImpl in project Payara by payara.
the class BatchRuntimeHelper method event.
@Override
public void event(Event event) {
try {
if (event.is(EventTypes.SERVER_READY)) {
for (String appName : applicationRegistry.getAllApplicationNames()) {
ApplicationInfo applicationInfo = applicationRegistry.get(appName);
registerIfBatchJobsDirExists(applicationInfo);
}
} else if (event.is(Deployment.APPLICATION_LOADED)) {
if (event.hook() != null && event.hook() instanceof ApplicationInfo) {
ApplicationInfo applicationInfo = (ApplicationInfo) event.hook();
registerIfBatchJobsDirExists(applicationInfo);
}
}
if (event.is(Deployment.UNDEPLOYMENT_SUCCESS)) {
if (event.hook() != null && event.hook() instanceof DeploymentContextImpl) {
DeploymentContextImpl deploymentContext = (DeploymentContextImpl) event.hook();
Properties props = deploymentContext.getAppProps();
String appName = props.getProperty("defaultAppName");
if (!Boolean.parseBoolean(props.getProperty("retain-batch-jobs"))) {
String tagName = config.getName() + ":" + appName;
ClassLoader prevCL = Thread.currentThread().getContextClassLoader();
try {
// set TCCL to ensure loading of the Joboperator
Thread.currentThread().setContextClassLoader(BatchSPIManager.class.getClassLoader());
BatchSPIManager batchSPIManager = BatchSPIManager.getInstance();
if (batchSPIManager != null && batchSPIManager.getBatchJobUtil() != null) {
batchSPIManager.getBatchJobUtil().purgeOwnedRepositoryData(tagName);
tagNamesRequiringCleanup.remove(tagName);
} else if (tagNamesRequiringCleanup.contains(tagName)) {
// Force initialization of BatchRuntime
JobOperator jobOperator = BatchRuntime.getJobOperator();
if (batchSPIManager.getBatchJobUtil() != null) {
batchSPIManager.getBatchJobUtil().purgeOwnedRepositoryData(tagName);
tagNamesRequiringCleanup.remove(tagName);
}
}
} catch (Exception ex) {
logger.log(Level.FINE, "Error while purging jobs", ex);
} finally {
Thread.currentThread().setContextClassLoader(prevCL);
}
}
}
}
} catch (Exception ex) {
logger.log(Level.FINE, "Exception while handling event: " + event, ex);
}
}
use of org.glassfish.deployment.common.DeploymentContextImpl in project Payara by payara.
the class DescriptorFactory method createApplicationDescriptor.
/**
* Returns the parsed DOL object from archive
*
* @param archiveFile original archive file
* @param destRootDir root destination directory where the application
* should be expanded under in case of archive deployment
* @param parentCl parent classloader
*
* @return the parsed DOL object
*/
public ResultHolder createApplicationDescriptor(File archiveFile, File destRootDir, ClassLoader parentCl) throws IOException {
ReadableArchive archive = null;
Application application = null;
try {
Descriptor.setBoundsChecking(false);
archive = archiveFactory.openArchive(archiveFile);
ArchiveHandler archiveHandler = deployment.getArchiveHandler(archive);
ActionReport dummyReport = new HTMLActionReporter();
String appName = DeploymentUtils.getDefaultEEName(archiveFile.getName());
DeployCommandParameters params = new DeployCommandParameters();
params.name = appName;
ExtendedDeploymentContext context = new DeploymentContextImpl(dummyReport, archive, params, env);
context.setArchiveHandler(archiveHandler);
if (!archiveFile.isDirectory()) {
// expand archive
File destDir = new File(destRootDir, appName);
if (destDir.exists()) {
FileUtils.whack(destDir);
}
destDir.mkdirs();
archiveHandler.expand(archive, archiveFactory.createArchive(destDir), context);
archive.close();
archive = archiveFactory.openArchive(destDir);
context.setSource(archive);
}
// issue 14564
context.addTransientAppMetaData(ExtendedDeploymentContext.IS_TEMP_CLASSLOADER, Boolean.TRUE);
String archiveType = context.getArchiveHandler().getArchiveType();
ClassLoader cl = archiveHandler.getClassLoader(parentCl, context);
Archivist archivist = archivistFactory.getArchivist(archiveType, cl);
if (archivist == null) {
throw new IOException("Cannot determine the Java EE module type for " + archive.getURI());
}
archivist.setAnnotationProcessingRequested(true);
String xmlValidationLevel = dasConfig.getDeployXmlValidation();
archivist.setXMLValidationLevel(xmlValidationLevel);
if (xmlValidationLevel.equals("none")) {
archivist.setXMLValidation(false);
}
archivist.setRuntimeXMLValidation(false);
try {
application = applicationFactory.openArchive(appName, archivist, archive, true);
} catch (SAXParseException e) {
throw new IOException(e);
}
if (application != null) {
application.setClassLoader(cl);
application.visit((ApplicationVisitor) new ApplicationValidator());
}
} finally {
if (archive != null) {
archive.close();
}
// We need to reset it after descriptor building
Descriptor.setBoundsChecking(true);
}
ResultHolder result = new ResultHolder();
result.application = application;
result.archive = archive;
return result;
}
use of org.glassfish.deployment.common.DeploymentContextImpl in project Payara by payara.
the class CreateLifecycleModuleCommand method execute.
public void execute(AdminCommandContext context) {
ActionReport report = context.getActionReport();
try {
validateTarget(target, name);
} catch (IllegalArgumentException ie) {
report.setMessage(ie.getMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
DeployCommandParameters commandParams = new DeployCommandParameters();
commandParams.name = name;
commandParams.enabled = enabled;
commandParams.description = description;
commandParams.target = target;
// create a dummy context to hold params and props
ExtendedDeploymentContext deploymentContext = new DeploymentContextImpl(report, null, commandParams, null);
Properties appProps = deploymentContext.getAppProps();
if (property != null) {
appProps.putAll(property);
}
// set to default "user", deployers can override it
appProps.setProperty(ServerTags.OBJECT_TYPE, "user");
appProps.setProperty(ServerTags.CLASS_NAME, classname);
if (classpath != null) {
appProps.setProperty(ServerTags.CLASSPATH, classpath);
}
if (loadorder != null) {
appProps.setProperty(ServerTags.LOAD_ORDER, loadorder);
}
appProps.setProperty(ServerTags.IS_FAILURE_FATAL, failurefatal.toString());
appProps.setProperty(ServerTags.IS_LIFECYCLE, "true");
try {
Transaction t = deployment.prepareAppConfigChanges(deploymentContext);
deployment.registerAppInDomainXML(null, deploymentContext, t);
} catch (Exception e) {
report.setMessage("Failed to create lifecycle module: " + e);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of org.glassfish.deployment.common.DeploymentContextImpl in project Payara by payara.
the class InstanceLifecycleModuleCommand method execute.
@Override
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
final Logger logger = context.getLogger();
try {
Application application = applications.getApplication(name);
Transaction t = new Transaction();
// create a dummy context to hold params and props
DeployCommandParameters commandParams = new DeployCommandParameters();
commandParams.name = name;
commandParams.target = target;
commandParams.enabled = enabled;
commandParams.virtualservers = virtualservers;
ExtendedDeploymentContext lifecycleContext = new DeploymentContextImpl(report, null, commandParams, null);
lifecycleContext.getAppProps().putAll(appprops);
if (application != null) {
// application element already been synchronized over
// just write application-ref
deployment.registerAppInDomainXML(null, lifecycleContext, t, true);
} else {
// write both
t = deployment.prepareAppConfigChanges(lifecycleContext);
deployment.registerAppInDomainXML(null, lifecycleContext, t);
}
} catch (Exception e) {
report.failure(logger, e.getMessage());
}
}
Aggregations