Search in sources :

Example 6 with DeploymentContextImpl

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);
    }
}
Also used : ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) JobOperator(javax.batch.operations.JobOperator) NamingException(javax.naming.NamingException) DeploymentContextImpl(org.glassfish.deployment.common.DeploymentContextImpl)

Example 7 with DeploymentContextImpl

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;
}
Also used : ArchiveHandler(org.glassfish.api.deployment.archive.ArchiveHandler) Archivist(com.sun.enterprise.deployment.archivist.Archivist) IOException(java.io.IOException) ActionReport(org.glassfish.api.ActionReport) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) DeploymentContextImpl(org.glassfish.deployment.common.DeploymentContextImpl) DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) ApplicationValidator(com.sun.enterprise.deployment.util.ApplicationValidator) SAXParseException(org.xml.sax.SAXParseException) HTMLActionReporter(com.sun.enterprise.v3.common.HTMLActionReporter) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) Application(com.sun.enterprise.deployment.Application) File(java.io.File)

Example 8 with DeploymentContextImpl

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);
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) Transaction(org.jvnet.hk2.config.Transaction) ActionReport(org.glassfish.api.ActionReport) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) Properties(java.util.Properties) DeploymentContextImpl(org.glassfish.deployment.common.DeploymentContextImpl)

Example 9 with DeploymentContextImpl

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());
    }
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) Transaction(org.jvnet.hk2.config.Transaction) ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) Application(com.sun.enterprise.config.serverbeans.Application) DeploymentContextImpl(org.glassfish.deployment.common.DeploymentContextImpl)

Aggregations

DeploymentContextImpl (org.glassfish.deployment.common.DeploymentContextImpl)9 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)7 ExtendedDeploymentContext (org.glassfish.internal.deployment.ExtendedDeploymentContext)6 ActionReport (org.glassfish.api.ActionReport)5 IOException (java.io.IOException)4 ArchiveHandler (org.glassfish.api.deployment.archive.ArchiveHandler)4 File (java.io.File)3 Properties (java.util.Properties)3 ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)3 Application (com.sun.enterprise.deployment.Application)2 HTMLActionReporter (com.sun.enterprise.v3.common.HTMLActionReporter)2 ArrayList (java.util.ArrayList)2 Logger (java.util.logging.Logger)2 ServerEnvironment (org.glassfish.api.admin.ServerEnvironment)2 DeploymentProperties (org.glassfish.deployment.common.DeploymentProperties)2 ApplicationInfo (org.glassfish.internal.data.ApplicationInfo)2 Transaction (org.jvnet.hk2.config.Transaction)2 Application (com.sun.enterprise.config.serverbeans.Application)1 ApplicationRef (com.sun.enterprise.config.serverbeans.ApplicationRef)1 Applications (com.sun.enterprise.config.serverbeans.Applications)1