Search in sources :

Example 11 with DeployCommandParameters

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

the class CreateApplicationRefCommand method handleLifecycleModule.

private void handleLifecycleModule(AdminCommandContext context, Transaction t) {
    final ActionReport report = context.getActionReport();
    final Logger logger = context.getLogger();
    Application app = applications.getApplication(name);
    // create a dummy context to hold params and props
    DeployCommandParameters commandParams = new DeployCommandParameters();
    commandParams.name = name;
    commandParams.target = target;
    commandParams.virtualservers = virtualservers;
    commandParams.enabled = enabled;
    ExtendedDeploymentContext lifecycleContext = new DeploymentContextImpl(report, null, commandParams, null);
    try {
        deployment.registerAppInDomainXML(null, lifecycleContext, t, true);
    } catch (Exception e) {
        report.failure(logger, e.getMessage());
    }
    if (!DeploymentUtils.isDASTarget(target)) {
        final ParameterMap paramMap = new ParameterMap();
        paramMap.add("DEFAULT", name);
        paramMap.add(DeploymentProperties.TARGET, target);
        paramMap.add(DeploymentProperties.ENABLED, enabled.toString());
        if (virtualservers != null) {
            paramMap.add(DeploymentProperties.VIRTUAL_SERVERS, virtualservers);
        }
        // pass the applicationInfo props so we have the information to persist in the
        // domain.xml
        Properties appProps = app.getDeployProperties();
        paramMap.set(DeploymentProperties.APP_PROPS, DeploymentUtils.propertiesValue(appProps, ':'));
        final List<String> targets = new ArrayList<String>();
        targets.add(target);
        ClusterOperationUtil.replicateCommand("_lifecycle", FailurePolicy.Error, FailurePolicy.Warn, FailurePolicy.Ignore, targets, context, paramMap, habitat);
    }
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) ArrayList(java.util.ArrayList) ParameterMap(org.glassfish.api.admin.ParameterMap) ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) DeploymentProperties(org.glassfish.deployment.common.DeploymentProperties) Properties(java.util.Properties) VersioningException(org.glassfish.deployment.versioning.VersioningException) VersioningWildcardException(org.glassfish.deployment.versioning.VersioningWildcardException) VersioningSyntaxException(org.glassfish.deployment.versioning.VersioningSyntaxException) IOException(java.io.IOException) DeploymentContextImpl(org.glassfish.deployment.common.DeploymentContextImpl)

Example 12 with DeployCommandParameters

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

the class WebServicesApplication method start.

@Override
public boolean start(ApplicationContext startupContext) throws Exception {
    cl = startupContext.getClassLoader();
    app = deploymentCtx.getModuleMetaData(Application.class);
    DeployCommandParameters commandParams = ((DeploymentContext) startupContext).getCommandParameters(DeployCommandParameters.class);
    virtualServers = commandParams.virtualservers;
    createEndpoints();
    grizzlyRestartListener.addListener(this);
    return true;
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) DeploymentContext(org.glassfish.api.deployment.DeploymentContext) Application(com.sun.enterprise.deployment.Application)

Example 13 with DeployCommandParameters

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

the class MetroContainer method deployWsTxServices.

public void deployWsTxServices(String target) {
    synchronized (lock) {
        if (wstxServicesDeployed.get() || !wstxServicesDeploying.compareAndSet(false, true)) {
            return;
        }
        Deployment deployment = serviceLocator.getService(Deployment.class);
        boolean isRegistered = deployment.isRegistered(WSTX_SERVICES_APP_NAME);
        if (isRegistered) {
            logger.log(WARNING, WSTX_SERVICE_DEPLOYED_EXPLICITLY);
        } else {
            logger.log(INFO, WSTX_SERVICE_LOADING);
            File root = serverContext.getInstallRoot();
            File app = null;
            try {
                app = FileUtils.getManagedFile(WSTX_SERVICES_APP_NAME + ".war", new File(root, METRO_APPS_INSTALL_ROOT));
            } catch (Exception e) {
                logger.log(WARNING, WSTX_SERVICE_UNEXPECTED_EXCEPTION, e);
            }
            if (app == null || !app.exists()) {
                // TODO
                logger.log(WARNING, format(WSTX_SERVICE_CANNOT_DEPLOY, "Required WAR file (" + WSTX_SERVICES_APP_NAME + ".war) is not installed"));
            } else {
                ActionReport report = serviceLocator.getService(ActionReport.class, "plain");
                DeployCommandParameters params = new DeployCommandParameters(app);
                String appName = WSTX_SERVICES_APP_NAME;
                params.name = appName;
                try {
                    File rootScratchDir = env.getApplicationStubPath();
                    File appScratchDir = new File(rootScratchDir, appName);
                    if (isDas() && appScratchDir.createNewFile()) {
                        params.origin = OpsParams.Origin.deploy;
                        if (target != null) {
                            params.target = target;
                        }
                    } else {
                        params.origin = OpsParams.Origin.load;
                        params.target = env.getInstanceName();
                    }
                    ExtendedDeploymentContext dc = deployment.getBuilder(logger, params, report).source(app).build();
                    Properties appProps = dc.getAppProps();
                    appProps.setProperty(OBJECT_TYPE, SYSTEM_ALL);
                    deployment.deploy(dc);
                    if (report.getActionExitCode() != ActionReport.ExitCode.SUCCESS) {
                        logger.log(WARNING, format(WSTX_SERVICE_CANNOT_DEPLOY, report.getMessage()), report.getFailureCause());
                    }
                    logger.log(INFO, WSTX_SERVICE_STARTED);
                } catch (Exception ex) {
                    logger.log(WARNING, format(WSTX_SERVICE_CANNOT_DEPLOY, ex.getLocalizedMessage()), ex);
                }
            }
        }
        wstxServicesDeployed.set(true);
        wstxServicesDeploying.set(false);
    }
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) Deployment(org.glassfish.internal.deployment.Deployment) ActionReport(org.glassfish.api.ActionReport) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) Properties(java.util.Properties) File(java.io.File)

Example 14 with DeployCommandParameters

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

the class ApplicationLifecycle method prepareInstanceDeployParamMap.

@Override
public ParameterMap prepareInstanceDeployParamMap(DeploymentContext dc) throws Exception {
    final DeployCommandParameters params = dc.getCommandParameters(DeployCommandParameters.class);
    final Collection<String> excludedParams = new ArrayList<>();
    excludedParams.add(DeploymentProperties.PATH);
    excludedParams.add(DeploymentProperties.DEPLOYMENT_PLAN);
    excludedParams.add(DeploymentProperties.ALT_DD);
    excludedParams.add(DeploymentProperties.RUNTIME_ALT_DD);
    // We'll force it to true ourselves.
    excludedParams.add(DeploymentProperties.UPLOAD);
    final ParameterMap paramMap;
    final ParameterMapExtractor extractor = new ParameterMapExtractor(params);
    paramMap = extractor.extract(excludedParams);
    prepareGeneratedContent(dc, paramMap);
    // set the path and plan params
    // get the location properties from the application so the token
    // will be resolved
    Application application = applications.getApplication(params.name);
    Properties appProperties = application.getDeployProperties();
    String archiveLocation = appProperties.getProperty(Application.APP_LOCATION_PROP_NAME);
    final File archiveFile = new File(new URI(archiveLocation));
    paramMap.set("DEFAULT", archiveFile.getAbsolutePath());
    String planLocation = appProperties.getProperty(Application.DEPLOYMENT_PLAN_LOCATION_PROP_NAME);
    if (planLocation != null) {
        final File actualPlan = new File(new URI(planLocation));
        paramMap.set(DeployCommandParameters.ParameterNames.DEPLOYMENT_PLAN, actualPlan.getAbsolutePath());
    }
    String altDDLocation = appProperties.getProperty(Application.ALT_DD_LOCATION_PROP_NAME);
    if (altDDLocation != null) {
        final File altDD = new File(new URI(altDDLocation));
        paramMap.set(DeployCommandParameters.ParameterNames.ALT_DD, altDD.getAbsolutePath());
    }
    String runtimeAltDDLocation = appProperties.getProperty(Application.RUNTIME_ALT_DD_LOCATION_PROP_NAME);
    if (runtimeAltDDLocation != null) {
        final File runtimeAltDD = new File(new URI(runtimeAltDDLocation));
        paramMap.set(DeployCommandParameters.ParameterNames.RUNTIME_ALT_DD, runtimeAltDD.getAbsolutePath());
    }
    // always upload the archives to the instance side
    // but not directories.  Note that we prepare a zip file containing
    // the generated directories and pass that as a single parameter so it
    // will be uploaded even though a deployment directory is not.
    paramMap.set(DeploymentProperties.UPLOAD, "true");
    // redeployment
    if (params.previousContextRoot != null) {
        paramMap.set(DeploymentProperties.PRESERVED_CONTEXT_ROOT, params.previousContextRoot);
    }
    // pass the app props so we have the information to persist in the
    // domain.xml
    Properties appProps = dc.getAppProps();
    appProps.remove(DeploymentProperties.APP_CONFIG);
    paramMap.set(DeploymentProperties.APP_PROPS, extractor.propertiesValue(appProps, ':'));
    Properties previousVirtualServers = dc.getTransientAppMetaData(DeploymentProperties.PREVIOUS_VIRTUAL_SERVERS, Properties.class);
    if (previousVirtualServers != null) {
        paramMap.set(DeploymentProperties.PREVIOUS_VIRTUAL_SERVERS, extractor.propertiesValue(previousVirtualServers, ':'));
    }
    Properties previousEnabledAttributes = dc.getTransientAppMetaData(DeploymentProperties.PREVIOUS_ENABLED_ATTRIBUTES, Properties.class);
    if (previousEnabledAttributes != null) {
        paramMap.set(DeploymentProperties.PREVIOUS_ENABLED_ATTRIBUTES, extractor.propertiesValue(previousEnabledAttributes, ':'));
    }
    return paramMap;
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) ParameterMapExtractor(org.glassfish.common.util.admin.ParameterMapExtractor) ParameterMap(org.glassfish.api.admin.ParameterMap) DeploymentProperties(org.glassfish.deployment.common.DeploymentProperties) File(java.io.File) URI(java.net.URI)

Example 15 with DeployCommandParameters

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

the class ApplicationLifecycle method prepareAppConfigChanges.

// prepare application config change for later registering
// in the domain.xml
@Override
public Transaction prepareAppConfigChanges(final DeploymentContext context) throws TransactionFailure {
    final Properties appProps = context.getAppProps();
    final DeployCommandParameters deployParams = context.getCommandParameters(DeployCommandParameters.class);
    Transaction tx = null;
    Application app_w = null;
    if (deployParams.hotDeploy) {
        app_w = applications.getApplication(deployParams.name);
    }
    if (app_w == null) {
        try {
            tx = new Transaction();
            // prepare the application element
            ConfigBean newBean = ((ConfigBean) Dom.unwrap(applications)).allocate(Application.class);
            Application app = newBean.createProxy();
            app_w = tx.enroll(app);
            setInitialAppAttributes(app_w, deployParams, appProps, context);
        } catch (TransactionFailure e) {
            tx.rollback();
            throw e;
        } catch (Exception e) {
            tx.rollback();
            throw new TransactionFailure(e.getMessage(), e);
        }
    }
    context.addTransientAppMetaData(ServerTags.APPLICATION, app_w);
    return tx;
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Transaction(org.jvnet.hk2.config.Transaction) ConfigBean(org.jvnet.hk2.config.ConfigBean) DeploymentProperties(org.glassfish.deployment.common.DeploymentProperties) MultiException(org.glassfish.hk2.api.MultiException) DeploymentException(org.glassfish.deployment.common.DeploymentException) IOException(java.io.IOException) PropertyVetoException(java.beans.PropertyVetoException) RetryableException(org.jvnet.hk2.config.RetryableException) VersioningSyntaxException(org.glassfish.deployment.versioning.VersioningSyntaxException)

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