Search in sources :

Example 61 with ReadableArchive

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

the class WebServiceUtils method isJaxwsRIDeployment.

/**
 * If WEB-INF/sun-jaxws.xml exists and is not processed in EJB context , then it returns true.
 * @param annInfo
 * @return
 */
static boolean isJaxwsRIDeployment(AnnotationInfo annInfo) {
    boolean riDeployment = false;
    AnnotatedElementHandler annCtx = annInfo.getProcessingContext().getHandler();
    try {
        ReadableArchive moduleArchive = annInfo.getProcessingContext().getArchive();
        if (moduleArchive != null && moduleArchive.exists("WEB-INF/sun-jaxws.xml") && !((Class) annInfo.getAnnotatedElement()).isInterface() && ((annCtx instanceof WebBundleContext) || (annCtx instanceof WebComponentContext))) {
            riDeployment = true;
        }
    } catch (Exception e) {
    // continue, processing
    }
    return riDeployment;
}
Also used : WebBundleContext(com.sun.enterprise.deployment.annotation.context.WebBundleContext) WebComponentContext(com.sun.enterprise.deployment.annotation.context.WebComponentContext) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) AnnotatedElementHandler(org.glassfish.apf.AnnotatedElementHandler)

Example 62 with ReadableArchive

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

the class UndeployCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    // for each matched version
    for (String appName : matchedVersions) {
        if (target == null) {
            target = deployment.getDefaultTarget(appName, origin, _classicstyle);
        }
        ApplicationInfo info = deployment.get(appName);
        Application application = apps.getModule(Application.class, appName);
        if (application == null) {
            report.setMessage(localStrings.getLocalString("application.notreg", "Application {0} not registered", appName));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
        deployment.validateUndeploymentTarget(target, appName);
        if (!DeploymentUtils.isDomainTarget(target)) {
            ApplicationRef ref = domain.getApplicationRefInTarget(appName, target);
            if (ref == null) {
                report.setMessage(localStrings.getLocalString("ref.not.referenced.target", "Application {0} is not referenced by target {1}", appName, target));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        }
        ReadableArchive source = null;
        if (info == null) {
            // disabled application or application failed to be
            // loaded for some reason
            URI uri = null;
            try {
                uri = new URI(application.getLocation());
            } catch (URISyntaxException e) {
                logger.severe("Cannot determine original location for application : " + e.getMessage());
            }
            if (uri != null) {
                File location = new File(uri);
                if (location.exists()) {
                    try {
                        source = archiveFactory.openArchive(location);
                    } catch (IOException e) {
                        logger.log(Level.INFO, e.getMessage(), e);
                    }
                } else {
                    logger.warning("Originally deployed application at " + location + " not found");
                }
            }
        } else {
            source = info.getSource();
        }
        if (source == null) {
            logger.fine("Cannot get source archive for undeployment");
            // server is in a consistent state after restart
            try {
                deployment.unregisterAppFromDomainXML(appName, target);
            } catch (TransactionFailure e) {
                logger.warning("Module " + appName + " not found in configuration");
            }
            // also remove application from runtime registry
            if (info != null) {
                appRegistry.remove(appName);
            }
            return;
        }
        File sourceFile = new File(source.getURI());
        if (!source.exists()) {
            logger.log(Level.WARNING, "Cannot find application bits at " + sourceFile.getPath() + ". Please restart server to ensure server is in a consistent state before redeploy the application.");
            // server is in a consistent state after restart
            try {
                deployment.unregisterAppFromDomainXML(appName, target);
            } catch (TransactionFailure e) {
                logger.warning("Module " + appName + " not found in configuration");
            }
            // also remove application from runtime registry
            if (info != null) {
                appRegistry.remove(appName);
            }
            return;
        }
        hotDeployService.removeApplicationState(sourceFile);
        // now start the normal undeploying
        this.name = appName;
        this._type = application.archiveType();
        ExtendedDeploymentContext deploymentContext = null;
        try {
            deploymentContext = deployment.getBuilder(logger, this, report).source(source).build();
        } catch (IOException e) {
            logger.log(Level.SEVERE, "Cannot create context for undeployment ", e);
            report.setMessage(localStrings.getLocalString("undeploy.contextcreation.failed", "Cannot create context for undeployment : {0} ", e.getMessage()));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
        final InterceptorNotifier notifier = new InterceptorNotifier(habitat, deploymentContext);
        final DeployCommandSupplementalInfo suppInfo = new DeployCommandSupplementalInfo();
        suppInfo.setDeploymentContext(deploymentContext);
        report.setResultType(DeployCommandSupplementalInfo.class, suppInfo);
        final Properties appProps = deploymentContext.getAppProps();
        appProps.putAll(application.getDeployProperties());
        if (properties != null) {
            appProps.putAll(properties);
        }
        deploymentContext.setModulePropsMap(application.getModulePropertiesMap());
        events.send(new Event<DeploymentContext>(Deployment.UNDEPLOYMENT_VALIDATION, deploymentContext), false);
        if (report.getActionExitCode() == ActionReport.ExitCode.FAILURE) {
            // status as failure, return
            return;
        }
        // pass despite the DAS potentially being a valid target
        if (env.isDas() && !DeploymentUtils.isDASTarget(target)) {
            ActionReport subReport = report.addSubActionsReport();
            // Disable the application first - note that even though the DAS may come under the target of "domain"
            // it won't be disabled by the disable command itself, but rather by an application config listener
            CommandRunner.CommandInvocation inv = commandRunner.getCommandInvocation("disable", subReport, context.getSubject());
            try {
                final ParameterMapExtractor extractor = new ParameterMapExtractor(this);
                final ParameterMap parameters = extractor.extract(Collections.EMPTY_LIST);
                parameters.set("DEFAULT", appName);
                parameters.add(DeploymentProperties.IS_UNDEPLOY, Boolean.TRUE.toString());
                inv.parameters(parameters).execute();
                if (subReport.getActionExitCode().equals(ActionReport.ExitCode.FAILURE)) {
                    // if disable application failed
                    // we should just return
                    report.setMessage(localStrings.getLocalString("disable.command.failed", "{0} disabled failed", appName));
                    return;
                }
                if (DeploymentUtils.isDomainTarget(target)) {
                    List<String> targets = domain.getAllReferencedTargetsForApplication(appName);
                    // replicate command to all referenced targets
                    parameters.remove("isUndeploy");
                    notifier.ensureBeforeReported(ExtendedDeploymentContext.Phase.REPLICATION);
                    ClusterOperationUtil.replicateCommand("undeploy", FailurePolicy.Error, FailurePolicy.Warn, FailurePolicy.Ignore, targets, context, parameters, habitat);
                }
            } catch (Exception e) {
                report.failure(logger, e.getMessage());
                return;
            }
        }
        /*
             * Extract the generated artifacts from the application's properties
             * and record them in the DC.  This will be useful, for example,
             * during Deployer.clean.
             */
        final Artifacts generatedArtifacts = DeploymentUtils.generatedArtifacts(application);
        generatedArtifacts.record(deploymentContext);
        if (info != null) {
            /**
             * Send the disable start event for the DAS. Even though the disable command itself doesn't get called
             * against the DAS when the target is specifically set to "server", the unload lifecycle method is still
             * executed (calling the ApplicationLifecycleListeners for the STOP event), so fire the alternative
             * event here.
             */
            if (env.isDas() && (DeploymentUtils.isDASTarget(target))) {
                events.send(new EventListener.Event<>(Deployment.DISABLE_START, info), true);
            }
            deployment.undeploy(appName, deploymentContext);
        }
        // check if it's directory deployment
        boolean isDirectoryDeployed = Boolean.valueOf(application.getDirectoryDeployed());
        // and warning case
        if (!report.getActionExitCode().equals(ActionReport.ExitCode.FAILURE)) {
            // so far I am doing this after the unload, maybe this should be moved before...
            try {
                // remove the "application" element
                deployment.unregisterAppFromDomainXML(appName, target);
            } catch (TransactionFailure e) {
                logger.warning("Module " + appName + " not found in configuration");
            }
            // remove context from generated
            deploymentContext.clean();
            // Ensure All cached JarFiles are closed after undeployment to
            // free file descriptors
            JarFileUtils.closeCachedJarFiles();
            // perform full GC after cleaning to ensure full clean up
            System.gc();
            // if directory deployment then do not remove the directory
            if ((!keepreposdir) && !isDirectoryDeployed && source.exists()) {
                /*
                     * Delete the repository directory as an archive so
                     * any special handling (such as stale file handling)
                     * known to the archive can run.
                     */
                source.delete();
            }
        }
    // else a message should have been provided.
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) URISyntaxException(java.net.URISyntaxException) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) DeploymentProperties(org.glassfish.deployment.common.DeploymentProperties) Properties(java.util.Properties) ActionReport(org.glassfish.api.ActionReport) URI(java.net.URI) ParameterMapExtractor(org.glassfish.common.util.admin.ParameterMapExtractor) EventListener(org.glassfish.api.event.EventListener) CommandRunner(org.glassfish.api.admin.CommandRunner) ParameterMap(org.glassfish.api.admin.ParameterMap) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) VersioningException(org.glassfish.deployment.versioning.VersioningException) IOException(java.io.IOException) DeploymentContext(org.glassfish.api.deployment.DeploymentContext) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) Artifacts(org.glassfish.deployment.common.Artifacts) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) File(java.io.File)

Example 63 with ReadableArchive

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

the class ValidateRemoteDirDeploymentCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    final Logger logger = context.getLogger();
    /*
         * This supplemental command should run only if the deployment
         * underway is a directory deployment, if the archive exists, and
         * only if the target includes a non-DAS target.
         */
    final ReadableArchive archive = archive(logger, report);
    if (archive == null) {
        /*
             * This is a little weird.  We cannot read the archive the user
             * specified.  Eventually, the deploy command will find this out
             * also.  But if we return a failure from here then the
             * command framework will report that a supplemental command has
             * failed and the deploy command will never have a chance to nicely
             * complain about the missing archive.  So, from this supplemental
             * command we'll report success so the deploy command will
             * be run.
             */
        reportSuccess(report);
        return;
    }
    final File source = new File(archive.getURI().getSchemeSpecificPart());
    try {
        archive.close();
    } catch (IOException ex) {
        report.failure(logger, ex.getLocalizedMessage(), ex);
    }
    if (!source.isDirectory()) {
        /*
             * This is not a directory deployment, so we're done.
             */
        reportSuccess(report);
        return;
    }
    if (target == null) {
        target = deployment.getDefaultTarget(name, origin, _classicstyle);
    }
    final TargetInfo targetInfo = new TargetInfo(target);
    if (!targetInfo.containsNonDAS()) {
        reportSuccess(report);
        return;
    }
    /*
         * There is at least one non-DAS target.  Compute the checksum as seen
         * here on the DAS.
         */
    final long checksum = DeploymentUtils.checksum(source);
    /*
         * Replicate the hidden validateRemoteDirDeployment command on the
         * targets, passing the URI for the directory and the checksum.
         */
    final ParameterMap paramMap = new ParameterMap();
    paramMap.add("checksum", Long.toString(checksum));
    paramMap.add("DEFAULT", path.toURI().getSchemeSpecificPart());
    ActionReport.ExitCode replicateResult = ClusterOperationUtil.replicateCommand("_instanceValidateRemoteDirDeployment", FailurePolicy.Error, FailurePolicy.Ignore, FailurePolicy.Ignore, targetInfo.targetNames(), context, paramMap, habitat);
    report.setActionExitCode(replicateResult);
}
Also used : ParameterMap(org.glassfish.api.admin.ParameterMap) IOException(java.io.IOException) ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) File(java.io.File)

Example 64 with ReadableArchive

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

the class MTProvisionCommand method expandCustomizationJar.

private void expandCustomizationJar(File tenantDir) throws IOException {
    if (!tenantDir.exists() && !tenantDir.mkdirs()) {
    // TODO Handle this situation properly -- issue reported by findbugs
    }
    if (customizations == null) {
        return;
    }
    ReadableArchive cusArchive = null;
    WritableArchive expandedArchive = null;
    try {
        expandedArchive = archiveFactory.createArchive(tenantDir);
        cusArchive = archiveFactory.openArchive(customizations);
        DeploymentUtils.expand(cusArchive, expandedArchive);
    } finally {
        try {
            if (cusArchive != null) {
                cusArchive.close();
            }
            if (expandedArchive != null) {
                expandedArchive.close();
            }
        } catch (IOException e) {
        // ignore
        }
    }
}
Also used : IOException(java.io.IOException) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) WritableArchive(org.glassfish.api.deployment.archive.WritableArchive)

Example 65 with ReadableArchive

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

the class MTUnprovisionCommand method execute.

public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    final Logger logger = context.getLogger();
    if (app == null) {
        report.setMessage("Application " + appname + " is not deployed");
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (appTenant == null) {
        report.setMessage("Application " + appname + " is not provisioned to tenant " + tenant);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    String internalAppName = DeploymentUtils.getInternalNameForTenant(appname, tenant);
    ApplicationInfo appInfo = deployment.get(internalAppName);
    ReadableArchive archive = null;
    try {
        if (appInfo != null) {
            archive = appInfo.getSource();
        } else {
            URI uri = new URI(app.getLocation());
            File location = new File(uri);
            if (location.exists()) {
                archive = archiveFactory.openArchive(location);
            } else {
                logger.log(Level.WARNING, localStrings.getLocalString("fnf", "File not found", location.getAbsolutePath()));
                deployment.unregisterTenantWithAppInDomainXML(appname, tenant);
                return;
            }
        }
        UndeployCommandParameters commandParams = new UndeployCommandParameters();
        commandParams.target = DeploymentUtils.DAS_TARGET_NAME;
        commandParams.name = internalAppName;
        commandParams.origin = DeployCommandParameters.Origin.mt_unprovision;
        ExtendedDeploymentContext deploymentContext = deployment.getBuilder(logger, commandParams, report).source(archive).build();
        deploymentContext.getAppProps().putAll(app.getDeployProperties());
        deploymentContext.getAppProps().putAll(appTenant.getDeployProperties());
        deploymentContext.setModulePropsMap(app.getModulePropertiesMap());
        deploymentContext.setTenant(tenant, app.getName());
        deployment.undeploy(internalAppName, deploymentContext);
        deployment.unregisterTenantWithAppInDomainXML(appname, tenant);
        // remove context from generated and tenant dir
        deploymentContext.clean();
    } catch (Throwable e) {
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(e.getMessage());
        report.setFailureCause(e);
    } finally {
        try {
            if (archive != null) {
                archive.close();
            }
        } catch (IOException e) {
        // ignore
        }
    }
}
Also used : UndeployCommandParameters(org.glassfish.api.deployment.UndeployCommandParameters) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) IOException(java.io.IOException) ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) URI(java.net.URI) File(java.io.File)

Aggregations

ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)97 IOException (java.io.IOException)46 File (java.io.File)28 URI (java.net.URI)18 ActionReport (org.glassfish.api.ActionReport)17 ExtendedDeploymentContext (org.glassfish.internal.deployment.ExtendedDeploymentContext)14 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)12 WritableArchive (org.glassfish.api.deployment.archive.WritableArchive)12 Application (com.sun.enterprise.deployment.Application)10 JarFile (java.util.jar.JarFile)10 ArchiveHandler (org.glassfish.api.deployment.archive.ArchiveHandler)10 ApplicationInfo (org.glassfish.internal.data.ApplicationInfo)10 ArrayList (java.util.ArrayList)9 ModuleDescriptor (org.glassfish.deployment.common.ModuleDescriptor)9 ConfigurationDeploymentDescriptorFile (com.sun.enterprise.deployment.io.ConfigurationDeploymentDescriptorFile)8 Logger (java.util.logging.Logger)8 DeploymentDescriptorFile (com.sun.enterprise.deployment.io.DeploymentDescriptorFile)7 Manifest (java.util.jar.Manifest)7 HashSet (java.util.HashSet)6 HashMap (java.util.HashMap)5