Search in sources :

Example 6 with ArchiveHandler

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

the class EarDeployer method subContext.

private ExtendedDeploymentContext subContext(final Application application, final DeploymentContext context, final String moduleUri) {
    ExtendedDeploymentContext moduleContext = ((ExtendedDeploymentContext) context).getModuleDeploymentContexts().get(moduleUri);
    if (moduleContext != null) {
        return moduleContext;
    }
    final ReadableArchive subArchive;
    try {
        subArchive = context.getSource().getSubArchive(moduleUri);
        subArchive.setParentArchive(context.getSource());
    } catch (IOException ioe) {
        deplLogger.log(Level.WARNING, ERROR_OCCURRED, ioe);
        return null;
    }
    final Properties moduleProps = getModuleProps(context, moduleUri);
    ActionReport subReport = context.getActionReport().addSubActionsReport();
    moduleContext = new DeploymentContextImpl(subReport, context.getSource(), context.getCommandParameters(OpsParams.class), env) {

        @Override
        public ClassLoader getClassLoader() {
            try {
                if (context.getClassLoader() == null) {
                    return null;
                }
                EarClassLoader appCl = EarClassLoader.class.cast(context.getClassLoader());
                if (((ExtendedDeploymentContext) context).getPhase() == Phase.PREPARE) {
                    return appCl;
                } else {
                    return appCl.getModuleClassLoader(moduleUri);
                }
            } catch (ClassCastException e) {
                return context.getClassLoader();
            }
        }

        @Override
        public ClassLoader getFinalClassLoader() {
            try {
                EarClassLoader finalEarCL = (EarClassLoader) context.getFinalClassLoader();
                return finalEarCL.getModuleClassLoader(moduleUri);
            } catch (ClassCastException e) {
                return context.getClassLoader();
            }
        }

        @Override
        public ReadableArchive getSource() {
            return subArchive;
        }

        @Override
        public Properties getAppProps() {
            return context.getAppProps();
        }

        @Override
        public <U extends OpsParams> U getCommandParameters(Class<U> commandParametersType) {
            return context.getCommandParameters(commandParametersType);
        }

        @Override
        public void addTransientAppMetaData(String metaDataKey, Object metaData) {
            context.addTransientAppMetaData(metaDataKey, metaData);
        }

        @Override
        public <T> T getTransientAppMetaData(String metaDataKey, Class<T> metadataType) {
            return context.getTransientAppMetaData(metaDataKey, metadataType);
        }

        @Override
        public Properties getModuleProps() {
            return moduleProps;
        }

        @Override
        public ReadableArchive getOriginalSource() {
            try {
                File appRoot = context.getSourceDir();
                File origModuleFile = new File(appRoot, moduleUri);
                return archiveFactory.openArchive(origModuleFile);
            } catch (IOException ioe) {
                return null;
            }
        }

        @Override
        public File getScratchDir(String subDirName) {
            String modulePortion = Util.getURIName(getSource().getURI());
            return (new File(super.getScratchDir(subDirName), modulePortion));
        }

        @Override
        public <T> T getModuleMetaData(Class<T> metadataType) {
            try {
                return metadataType.cast(application.getModuleByUri(moduleUri));
            } catch (Exception e) {
                // let's first try the extensions mechanisms...
                if (RootDeploymentDescriptor.class.isAssignableFrom(metadataType)) {
                    for (RootDeploymentDescriptor extension : application.getModuleByUri(moduleUri).getExtensionsDescriptors((Class<RootDeploymentDescriptor>) metadataType)) {
                        // we assume there can only be one type of
                        if (extension != null) {
                            try {
                                return metadataType.cast(extension);
                            } catch (Exception e1) {
                            // next one...
                            }
                        }
                    }
                }
                return context.getModuleMetaData(metadataType);
            }
        }
    };
    ((ExtendedDeploymentContext) context).getModuleDeploymentContexts().put(moduleUri, moduleContext);
    moduleContext.setParentContext((ExtendedDeploymentContext) context);
    moduleContext.setModuleUri(moduleUri);
    ArchiveHandler subHandler = context.getModuleArchiveHandlers().get(moduleUri);
    moduleContext.setArchiveHandler(subHandler);
    return moduleContext;
}
Also used : ArchiveHandler(org.glassfish.api.deployment.archive.ArchiveHandler) IOException(java.io.IOException) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) ActionReport(org.glassfish.api.ActionReport) IOException(java.io.IOException) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) File(java.io.File)

Example 7 with ArchiveHandler

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

the class InstanceDeployCommand method execute.

@Override
public void execute(AdminCommandContext ctxt) {
    long operationStartTime = Calendar.getInstance().getTimeInMillis();
    final ActionReport report = ctxt.getActionReport();
    final Logger logger = ctxt.getLogger();
    ReadableArchive archive = null;
    this.origin = Origin.deploy_instance;
    this.command = Command._deploy;
    this.previousContextRoot = preservedcontextroot;
    if (previousVirtualServers != null) {
        String vs = previousVirtualServers.getProperty(target);
        if (vs != null) {
            this.virtualservers = vs;
        }
    }
    if (previousEnabledAttributes != null) {
        String enabledAttr = previousEnabledAttributes.getProperty(target);
        if (enabledAttr != null) {
            String enabledAttrForApp = previousEnabledAttributes.getProperty(DeploymentUtils.DOMAIN_TARGET_NAME);
            this.enabled = Boolean.valueOf(enabledAttr) && Boolean.valueOf(enabledAttrForApp);
        }
    }
    try {
        if (!path.exists()) {
            report.setMessage(localStrings.getLocalString("fnf", "File not found", path.getAbsolutePath()));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
        if (snifferManager.hasNoSniffers()) {
            String msg = localStrings.getLocalString("nocontainer", "No container services registered, done...");
            report.failure(logger, msg);
            return;
        }
        archive = archiveFactory.openArchive(path, this);
        ArchiveHandler archiveHandler = deployment.getArchiveHandler(archive, type);
        if (archiveHandler == null) {
            report.failure(logger, localStrings.getLocalString("deploy.unknownarchivetype", "Archive type of {0} was not recognized", path.getName()));
            return;
        }
        // wait until all applications are loaded as we may have dependency on these, or the previous app is still
        // starting
        startupProvider.get();
        // clean up any left over repository files
        if (!keepreposdir.booleanValue()) {
            FileUtils.whack(new File(env.getApplicationRepositoryPath(), VersioningUtils.getRepositoryName(name)));
        }
        ExtendedDeploymentContext deploymentContext = deployment.getBuilder(logger, this, report).source(archive).build();
        // clean up any remaining generated files
        deploymentContext.clean();
        deploymentContext.getAppProps().putAll(appprops);
        processGeneratedContent(generatedcontent, deploymentContext, logger);
        Transaction t = null;
        Application application = applications.getApplication(name);
        if (application != null) {
            // application element already been synchronized over
            t = new Transaction();
        } else {
            t = deployment.prepareAppConfigChanges(deploymentContext);
        }
        ApplicationInfo appInfo;
        appInfo = deployment.deploy(deploymentContext);
        if (report.getActionExitCode() == ActionReport.ExitCode.SUCCESS) {
            try {
                moveAltDDFilesToPermanentLocation(deploymentContext, logger);
                // register application information in domain.xml
                if (application != null) {
                    // application element already synchronized over
                    // just write application-ref
                    deployment.registerAppInDomainXML(appInfo, deploymentContext, t, true);
                } else {
                    // write both application and application-ref
                    deployment.registerAppInDomainXML(appInfo, deploymentContext, t);
                }
            } catch (Exception e) {
                // roll back the deployment and re-throw the exception
                deployment.undeploy(name, deploymentContext);
                deploymentContext.clean();
                throw e;
            }
        }
    } 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) {
            logger.log(Level.INFO, localStrings.getLocalString("errClosingArtifact", "Error while closing deployable artifact : ", path.getAbsolutePath()), e);
        }
        if (report.getActionExitCode().equals(ActionReport.ExitCode.SUCCESS)) {
            logger.info(localStrings.getLocalString("deploy.done", "Deployment of {0} done is {1} ms", name, (Calendar.getInstance().getTimeInMillis() - operationStartTime)));
        } else if (report.getActionExitCode().equals(ActionReport.ExitCode.FAILURE)) {
            String errorMessage = report.getMessage();
            Throwable cause = report.getFailureCause();
            if (cause != null) {
                String causeMessage = cause.getMessage();
                if (causeMessage != null && !causeMessage.equals(errorMessage)) {
                    errorMessage = errorMessage + " : " + cause.getMessage();
                }
                logger.log(Level.SEVERE, errorMessage, cause.getCause());
            }
            report.setMessage(localStrings.getLocalString("failToLoadOnInstance", "Failed to load the application on instance {0} : {1}", server.getName(), errorMessage));
            // reset the failure cause so command framework will not try
            // to print the same message again
            report.setFailureCause(null);
        }
    }
}
Also used : ArchiveHandler(org.glassfish.api.deployment.archive.ArchiveHandler) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) IOException(java.io.IOException) ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) IOException(java.io.IOException) Transaction(org.jvnet.hk2.config.Transaction) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) ZipFile(java.util.zip.ZipFile) File(java.io.File) Application(com.sun.enterprise.config.serverbeans.Application)

Example 8 with ArchiveHandler

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

the class SnifferManagerImpl method getSniffers.

/**
 * Returns a collection of sniffers that recognized some parts of the
 * passed archive as components their container handle.
 *
 * If no sniffer recognize the passed archive, an empty collection is
 * returned.
 *
 * @param context the deployment context
 * @return possibly empty collection of sniffers that handle the passed
 * archive.
 */
public Collection<Sniffer> getSniffers(DeploymentContext context) {
    ReadableArchive archive = context.getSource();
    ArchiveHandler handler = context.getArchiveHandler();
    List<URI> uris = handler.getClassPathURIs(archive);
    Types types = context.getTransientAppMetaData(Types.class.getName(), Types.class);
    return getSniffers(context, uris, types);
}
Also used : ArchiveHandler(org.glassfish.api.deployment.archive.ArchiveHandler) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) URI(java.net.URI)

Aggregations

ArchiveHandler (org.glassfish.api.deployment.archive.ArchiveHandler)8 File (java.io.File)6 IOException (java.io.IOException)6 ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)6 ExtendedDeploymentContext (org.glassfish.internal.deployment.ExtendedDeploymentContext)6 ActionReport (org.glassfish.api.ActionReport)5 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)5 DeploymentContextImpl (org.glassfish.deployment.common.DeploymentContextImpl)4 HTMLActionReporter (com.sun.enterprise.v3.common.HTMLActionReporter)3 Application (com.sun.enterprise.deployment.Application)2 URI (java.net.URI)2 Logger (java.util.logging.Logger)2 ServerEnvironment (org.glassfish.api.admin.ServerEnvironment)2 ApplicationInfo (org.glassfish.internal.data.ApplicationInfo)2 Transaction (org.jvnet.hk2.config.Transaction)2 SAXParseException (org.xml.sax.SAXParseException)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 FileArchive (com.sun.enterprise.deploy.shared.FileArchive)1