Search in sources :

Example 31 with DeployCommandParameters

use of org.glassfish.api.deployment.DeployCommandParameters in project Payara by payara.

the class EjbApplication method start.

@Override
public boolean start(ApplicationContext startupContext) throws Exception {
    started = true;
    if (!initializeInOrder) {
        Boolean alreadyMarked = dc.getTransientAppMetaData(EJB_APP_MARKED_AS_STARTED_STATUS, Boolean.class);
        if (!alreadyMarked) {
            List<EjbApplication> ejbAppList = dc.getTransientAppMetaData(CONTAINER_LIST_KEY, List.class);
            for (EjbApplication app : ejbAppList) {
                app.markAllContainersAsStarted();
            }
            dc.addTransientAppMetaData(EJB_APP_MARKED_AS_STARTED_STATUS, Boolean.TRUE);
        }
    }
    try {
        DeployCommandParameters params = ((DeploymentContext) startupContext).getCommandParameters(DeployCommandParameters.class);
        for (Container container : containers) {
            container.startApplication(params.origin.isDeploy());
        }
        singletonLCM.doStartup(this);
    } catch (Exception e) {
        abortInitializationAfterException();
        throw e;
    }
    return true;
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) DeploymentContext(org.glassfish.api.deployment.DeploymentContext) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) Container(com.sun.ejb.Container) AbstractSingletonContainer(com.sun.ejb.containers.AbstractSingletonContainer) ApplicationContainer(org.glassfish.api.deployment.ApplicationContainer)

Example 32 with DeployCommandParameters

use of org.glassfish.api.deployment.DeployCommandParameters in project Payara by payara.

the class EjbApplication method resolveKeepStateOptions.

/**
 * Returns a consolidated keepstate value.  keepstate only takes effect for
 * redeploy operations where the app is already registered.  If the app is
 * not already registered, keepstate always resolves to false even if
 * keepstate is true in CLI or descriptors.  For redeploy operations, CLI
 * --keepstate option has precedence over descriptor keep-state element.
 * @param deployContext
 * @param isDeploy
 * @param bundleDesc
 * @return true if keepstate is true after consolidating --keepstate CLI option
 * and keep-state element in descriptors; false otherwise.
 */
private boolean resolveKeepStateOptions(DeploymentContext deployContext, boolean isDeploy, EjbBundleDescriptorImpl bundleDesc) {
    Boolean isredeploy = Boolean.FALSE;
    Boolean keepState = null;
    if (isDeploy) {
        DeployCommandParameters dcp = deployContext.getCommandParameters(DeployCommandParameters.class);
        if (dcp != null) {
            isredeploy = dcp.isredeploy;
            keepState = dcp.keepstate;
        }
    } else {
        UndeployCommandParameters ucp = deployContext.getCommandParameters(UndeployCommandParameters.class);
        if (ucp != null) {
            isredeploy = ucp.isredeploy;
            keepState = ucp.keepstate;
        }
    }
    if (!isredeploy) {
        return false;
    }
    if (keepState == null) {
        Application app = bundleDesc.getApplication();
        keepState = app.getKeepState();
    }
    return keepState;
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) UndeployCommandParameters(org.glassfish.api.deployment.UndeployCommandParameters) Application(com.sun.enterprise.deployment.Application)

Example 33 with DeployCommandParameters

use of org.glassfish.api.deployment.DeployCommandParameters in project Payara by payara.

the class EjbDeployer method event.

@Override
public void event(Event event) {
    if (event.is(Deployment.APPLICATION_PREPARED) && isDas()) {
        ExtendedDeploymentContext context = (ExtendedDeploymentContext) event.hook();
        OpsParams opsparams = context.getCommandParameters(OpsParams.class);
        DeployCommandParameters dcp = context.getCommandParameters(DeployCommandParameters.class);
        ApplicationInfo appInfo = appRegistry.get(opsparams.name());
        Application app = appInfo.getMetaData(Application.class);
        if (app == null) {
            // Not a Java EE application
            return;
        }
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "EjbDeployer in APPLICATION_PREPARED for origin: " + opsparams.origin + ", target: " + dcp.target + ", name: " + opsparams.name());
        }
        boolean createTimers = true;
        // target could be null for internal apps such as wstx-services or admin console
        boolean isDeploymentGroup = dcp.target == null ? false : domain.getDeploymentGroupNamed(dcp.target) != null;
        boolean isDeployment = opsparams.origin.isDeploy() || opsparams.origin.isCreateAppRef();
        boolean isDirectTarget = env.getInstanceName().equals(dcp.target);
        // Create timers on DAS only if this condition is not met
        if (!isDeployment || isDirectTarget) {
            // Otherwise, timers will be created by the BaseContainer if it's a single instance deploy
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "EjbDeployer ... will only set the timeout application flag if any");
            }
            // But is-timed-app needs to be set in AppInfo in any case
            createTimers = false;
        }
        if (isDeploymentGroup) {
            _logger.log(Level.WARNING, "Deployment targets deployment group {0}, it is assumed that timer " + "service configuration is consistent accross all members of the group", dcp.target);
        }
        String target = dcp.target;
        if (createTimers && dcp.isredeploy != null && dcp.isredeploy && DeploymentUtils.isDomainTarget(target)) {
            List<String> targets = (List<String>) context.getTransientAppMetaData(DeploymentProperties.PREVIOUS_TARGETS, List.class);
            for (String ref : targets) {
                target = ref;
                if (domain.getClusterNamed(target) != null || domain.getDeploymentGroupNamed(target) != null) {
                    // prefer cluster target
                    break;
                }
            }
        }
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "EjbDeployer using target for event as " + target);
        }
        boolean isTimedApp = false;
        for (EjbBundleDescriptorImpl ejbBundle : app.getBundleDescriptors(EjbBundleDescriptorImpl.class)) {
            if (checkEjbBundleForTimers(ejbBundle, createTimers, target)) {
                isTimedApp = true;
            }
        }
        if (isTimedApp && (opsparams.origin.isDeploy() || opsparams.origin.isLoad())) {
            // Mark application as a timeout application, so that the clean() call removes the timers.
            appInfo.addTransientAppMetaData(IS_TIMEOUT_APP_PROP, Boolean.TRUE);
        }
    }
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) OpsParams(org.glassfish.api.deployment.OpsParams) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) List(java.util.List) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) Application(com.sun.enterprise.deployment.Application) EjbBundleDescriptorImpl(org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)

Example 34 with DeployCommandParameters

use of org.glassfish.api.deployment.DeployCommandParameters in project Payara by payara.

the class PersistentEJBTimerService method deployEJBTimerService.

private static boolean deployEJBTimerService(File root, File appScratchFile, String resourceName, boolean is_upgrade) {
    boolean deployed = false;
    logger.log(Level.INFO, "Loading EJBTimerService. Please wait.");
    File app = null;
    try {
        app = FileUtils.getManagedFile(TIMER_SERVICE_APP_NAME + ".war", new File(root, "lib/install/applications/"));
    } catch (Exception e) {
        logger.log(Level.WARNING, "Caught unexpected exception", e);
    }
    if (app == null || !app.exists()) {
        logger.log(Level.WARNING, "Cannot deploy or load persistent EJBTimerService: " + "required WAR file (" + TIMER_SERVICE_APP_NAME + ".war) is not installed");
    } else {
        DeployCommandParameters params = new DeployCommandParameters(app);
        params.name = TIMER_SERVICE_APP_NAME;
        try {
            EjbContainerUtil _ejbContainerUtil = EjbContainerUtilImpl.getInstance();
            // first access of the Timer Service application
            if (_ejbContainerUtil.isDas() && appScratchFile.createNewFile() && !is_upgrade) {
                params.origin = OpsParams.Origin.deploy;
            } else {
                params.origin = OpsParams.Origin.load;
            }
            params.target = _ejbContainerUtil.getServerEnvironment().getInstanceName();
            ActionReport report = _ejbContainerUtil.getServices().getService(ActionReport.class, "plain");
            Deployment deployment = _ejbContainerUtil.getDeployment();
            ExtendedDeploymentContext dc = deployment.getBuilder(logger, params, report).source(app).build();
            dc.addTransientAppMetaData(DatabaseConstants.JTA_DATASOURCE_JNDI_NAME_OVERRIDE, resourceName);
            Properties appProps = dc.getAppProps();
            appProps.setProperty(ServerTags.OBJECT_TYPE, DeploymentProperties.SYSTEM_ALL);
            deployment.deploy(dc);
            if (report.getActionExitCode() != ActionReport.ExitCode.SUCCESS) {
                logger.log(Level.WARNING, "Cannot deploy or load EJBTimerService: ", report.getFailureCause());
            } else {
                deployed = true;
            }
        } catch (Exception e) {
            logger.log(Level.WARNING, "Cannot deploy or load EJBTimerService: ", e);
        } finally {
            if (!deployed && params.origin.isDeploy() && appScratchFile.exists()) {
                // Remove marker file if deploy failed
                if (!appScratchFile.delete()) {
                    logger.log(Level.WARNING, "Failed to remove the marker file " + appScratchFile);
                }
            }
        }
    }
    return deployed;
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) EjbContainerUtil(com.sun.ejb.containers.EjbContainerUtil) Deployment(org.glassfish.internal.deployment.Deployment) ActionReport(org.glassfish.api.ActionReport) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) DeploymentProperties(org.glassfish.deployment.common.DeploymentProperties) Properties(java.util.Properties) File(java.io.File) PropertyVetoException(java.beans.PropertyVetoException) EJBException(javax.ejb.EJBException) FinderException(javax.ejb.FinderException) CreateException(javax.ejb.CreateException)

Example 35 with DeployCommandParameters

use of org.glassfish.api.deployment.DeployCommandParameters in project Payara by payara.

the class Java2DBProcessorHelper method init.

/**
 * Initializes the rest of the settings
 */
public void init() {
    if (deploy) {
        // DeployCommandParameters are available only on deploy or deploy
        // part of redeploy
        DeployCommandParameters cliOverrides = ctx.getCommandParameters(DeployCommandParameters.class);
        if (logger.isLoggable(Level.FINE)) {
            logger.fine("---> cliOverrides " + cliOverrides);
        }
        cliCreateTables = cliOverrides.createtables;
        cliDropAndCreateTables = cliOverrides.dropandcreatetables;
        Application application = ctx.getModuleMetaData(Application.class);
        appRegisteredName = application.getRegistrationName();
        deploymentContextProps.setProperty(APPLICATION_NAME, appRegisteredName);
    } else {
        // UndeployCommandParameters are available only on undeploy or undeploy
        // part of redeploy. In the latter case, cliOverrides.droptables
        // is set from cliOverrides.dropandcreatetables passed to redeploy.
        UndeployCommandParameters cliOverrides = ctx.getCommandParameters(UndeployCommandParameters.class);
        if (logger.isLoggable(Level.FINE)) {
            logger.fine("---> cliOverrides " + cliOverrides);
        }
        cliDropTables = cliOverrides.droptables;
        appRegisteredName = deploymentContextProps.getProperty(APPLICATION_NAME);
    }
    try {
        appGeneratedLocation = ctx.getScratchDir("ejb").getCanonicalPath() + File.separator;
    } catch (Exception e) {
        throw new RuntimeException(I18NHelper.getMessage(messages, // NOI18N
        "Java2DBProcessorHelper.generatedlocation", appRegisteredName), e);
    }
    appDeployedLocation = ctx.getSource().getURI().getSchemeSpecificPart() + File.separator;
    ActionReport report = ctx.getActionReport();
    subReport = report.addSubActionsReport();
    subReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) UndeployCommandParameters(org.glassfish.api.deployment.UndeployCommandParameters) ActionReport(org.glassfish.api.ActionReport) Application(com.sun.enterprise.deployment.Application) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Aggregations

DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)69 IOException (java.io.IOException)25 File (java.io.File)24 ExtendedDeploymentContext (org.glassfish.internal.deployment.ExtendedDeploymentContext)24 ActionReport (org.glassfish.api.ActionReport)23 DeploymentContext (org.glassfish.api.deployment.DeploymentContext)16 Application (com.sun.enterprise.deployment.Application)14 ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)13 DeploymentProperties (org.glassfish.deployment.common.DeploymentProperties)13 Logger (java.util.logging.Logger)12 Properties (java.util.Properties)10 DeploymentContextImpl (org.glassfish.deployment.common.DeploymentContextImpl)10 DeploymentException (org.glassfish.deployment.common.DeploymentException)10 ApplicationInfo (org.glassfish.internal.data.ApplicationInfo)10 ArchiveHandler (org.glassfish.api.deployment.archive.ArchiveHandler)9 VersioningSyntaxException (org.glassfish.deployment.versioning.VersioningSyntaxException)9 Deployment (org.glassfish.internal.deployment.Deployment)9 PropertyVetoException (java.beans.PropertyVetoException)8 URI (java.net.URI)8 UndeployCommandParameters (org.glassfish.api.deployment.UndeployCommandParameters)8