Search in sources :

Example 6 with ExtendedDeploymentContext

use of org.glassfish.internal.deployment.ExtendedDeploymentContext in project Payara by payara.

the class JPADeployer method event.

@Override
public void event(Event event) {
    if (logger.isLoggable(Level.FINEST)) {
        logger.finest("JpaDeployer.event():" + event.name());
    }
    if (event.is(Deployment.APPLICATION_PREPARED)) {
        ExtendedDeploymentContext context = (ExtendedDeploymentContext) event.hook();
        DeployCommandParameters deployCommandParameters = context.getCommandParameters(DeployCommandParameters.class);
        if (logger.isLoggable(Level.FINE)) {
            logger.fine("JpaDeployer.event(): Handling APPLICATION_PREPARED origin is:" + deployCommandParameters.origin);
        }
        // an application-ref is being created on DAS. Process the app
        if (!deployCommandParameters.origin.isCreateAppRef() || isTargetDas(deployCommandParameters)) {
            Map<String, ExtendedDeploymentContext> deploymentContexts = context.getModuleDeploymentContexts();
            for (DeploymentContext deploymentContext : deploymentContexts.values()) {
                // bundle level pus
                iterateInitializedPUsAtApplicationPrepare(deploymentContext);
            }
            // app level pus
            iterateInitializedPUsAtApplicationPrepare(context);
        }
    } else if (event.is(Deployment.APPLICATION_DISABLED)) {
        logger.fine("JpaDeployer.event(): APPLICATION_DISABLED");
        // APPLICATION_DISABLED will be generated when an app is disabled/undeployed/appserver goes down.
        // close all the emfs created for this app
        ApplicationInfo appInfo = (ApplicationInfo) event.hook();
        closeEMFs(appInfo);
    }
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) DeploymentContext(org.glassfish.api.deployment.DeploymentContext) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext)

Example 7 with ExtendedDeploymentContext

use of org.glassfish.internal.deployment.ExtendedDeploymentContext in project Payara by payara.

the class MEJBNamingObjectProxy method deployMEJB.

private void deployMEJB() throws IOException {
    _logger.info("Loading MEJB app on JNDI look up");
    ServerContext serverContext = habitat.getService(ServerContext.class);
    File mejbArchive = new File(serverContext.getInstallRoot(), "lib/install/applications/mejb.jar");
    DeployCommandParameters deployParams = new DeployCommandParameters(mejbArchive);
    String targetName = habitat.<Server>getService(Server.class, ServerEnvironment.DEFAULT_INSTANCE_NAME).getName();
    deployParams.target = targetName;
    deployParams.name = "mejb";
    ActionReport report = habitat.getService(ActionReport.class, "plain");
    Deployment deployment = habitat.getService(Deployment.class);
    ExtendedDeploymentContext dc = deployment.getBuilder(_logger, deployParams, report).source(mejbArchive).build();
    deployment.deploy(dc);
    if (report.getActionExitCode() != ActionReport.ExitCode.SUCCESS) {
        throw new RuntimeException("Failed to deploy MEJB app: " + report.getFailureCause());
    }
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) ServerContext(org.glassfish.internal.api.ServerContext) Server(com.sun.enterprise.config.serverbeans.Server) Deployment(org.glassfish.internal.deployment.Deployment) ActionReport(org.glassfish.api.ActionReport) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) File(java.io.File)

Example 8 with ExtendedDeploymentContext

use of org.glassfish.internal.deployment.ExtendedDeploymentContext in project Payara by payara.

the class DOLUtils method getCurrentBundleForContext.

/**
 * Gets the associated descriptor with the context
 * @param context
 * @return null if there is no associated application
 */
public static BundleDescriptor getCurrentBundleForContext(DeploymentContext context) {
    ExtendedDeploymentContext ctx = (ExtendedDeploymentContext) context;
    Application application = context.getModuleMetaData(Application.class);
    // this can happen for non-JavaEE type deployment. e.g., issue 15869
    if (application == null)
        return null;
    if (ctx.getParentContext() == null) {
        if (application.isVirtual()) {
            // standalone module
            return application.getStandaloneBundleDescriptor();
        } else {
            // top level
            return application;
        }
    } else {
        // a sub module of ear
        return application.getModuleByUri(ctx.getModuleUri());
    }
}
Also used : ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) Application(com.sun.enterprise.deployment.Application)

Example 9 with ExtendedDeploymentContext

use of org.glassfish.internal.deployment.ExtendedDeploymentContext 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<Sniffer>();
    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;
}
Also used : ArchiveHandler(org.glassfish.api.deployment.archive.ArchiveHandler) Types(org.glassfish.hk2.classmodel.reflect.Types) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) SnifferManager(org.glassfish.internal.deployment.SnifferManager) Sniffer(org.glassfish.api.container.Sniffer) DeploymentProperties(org.glassfish.deployment.common.DeploymentProperties) Properties(java.util.Properties) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) URI(java.net.URI) DeploymentContextImpl(org.glassfish.deployment.common.DeploymentContextImpl) DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) ServerEnvironment(org.glassfish.api.admin.ServerEnvironment) Collection(java.util.Collection)

Example 10 with ExtendedDeploymentContext

use of org.glassfish.internal.deployment.ExtendedDeploymentContext in project Payara by payara.

the class Verifier method verify.

public void verify(DeploymentContext context) {
    com.sun.enterprise.tools.verifier.VerifierFrameworkContext verifierFrameworkContext = new com.sun.enterprise.tools.verifier.VerifierFrameworkContext();
    verifierFrameworkContext.setArchive(context.getSource());
    verifierFrameworkContext.setApplication(context.getModuleMetaData(com.sun.enterprise.deployment.Application.class));
    verifierFrameworkContext.setJarFileName(context.getSourceDir().getAbsolutePath());
    verifierFrameworkContext.setJspOutDir(context.getScratchDir("jsp"));
    verifierFrameworkContext.setIsBackend(true);
    verifierFrameworkContext.setOutputDirName(env.getDomainRoot().getAbsolutePath() + "/logs/verifier-results");
    com.sun.enterprise.tools.verifier.ResultManager rm = verifierFrameworkContext.getResultManager();
    try {
        init(verifierFrameworkContext);
        verify();
    } catch (Exception e) {
        LogRecord logRecord = new LogRecord(Level.SEVERE, "Could not verify successfully.");
        logRecord.setThrown(e);
        verifierFrameworkContext.getResultManager().log(logRecord);
    }
    try {
        generateReports();
    } catch (IOException ioe) {
        context.getLogger().log(Level.WARNING, "Can not generate verifier report: {0}", ioe.getMessage());
    }
    int failedCount = rm.getFailedCount() + rm.getErrorCount();
    if (failedCount != 0) {
        ((ExtendedDeploymentContext) context).clean();
        throw new DeploymentException(smh.getLocalString("deploy.failverifier", "Some verifier tests failed. Aborting deployment"));
    }
}
Also used : IOException(java.io.IOException) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) IOException(java.io.IOException) DeploymentException(org.glassfish.deployment.common.DeploymentException) LogRecord(java.util.logging.LogRecord) DeploymentException(org.glassfish.deployment.common.DeploymentException) Application(com.sun.enterprise.deployment.Application)

Aggregations

ExtendedDeploymentContext (org.glassfish.internal.deployment.ExtendedDeploymentContext)39 ActionReport (org.glassfish.api.ActionReport)23 IOException (java.io.IOException)17 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)17 File (java.io.File)16 Logger (java.util.logging.Logger)11 ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)11 ApplicationInfo (org.glassfish.internal.data.ApplicationInfo)10 Properties (java.util.Properties)9 URI (java.net.URI)7 Deployment (org.glassfish.internal.deployment.Deployment)7 DeploymentContext (org.glassfish.api.deployment.DeploymentContext)6 UndeployCommandParameters (org.glassfish.api.deployment.UndeployCommandParameters)6 ArchiveHandler (org.glassfish.api.deployment.archive.ArchiveHandler)6 DeploymentContextImpl (org.glassfish.deployment.common.DeploymentContextImpl)6 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)6 Application (com.sun.enterprise.deployment.Application)5 ArrayList (java.util.ArrayList)5 DeploymentProperties (org.glassfish.deployment.common.DeploymentProperties)5 VersioningException (org.glassfish.deployment.versioning.VersioningException)5