Search in sources :

Example 66 with ReadableArchive

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

the class GetDeploymentConfigurationsCommand method execute.

/**
 * Entry point from the framework into the command execution
 * @param context context for the command.
 */
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    ActionReport.MessagePart part = report.getTopMessagePart();
    final ApplicationInfo appInfo = appRegistry.get(appname);
    if (appInfo == null) {
        return;
    }
    try {
        if (appInfo.getEngineRefs().size() > 0) {
            // composite archive case, i.e. ear
            for (EngineRef ref : appInfo.getEngineRefs()) {
                Sniffer appSniffer = ref.getContainerInfo().getSniffer();
                addToResultDDList("", appSniffer.getDeploymentConfigurations(appInfo.getSource()), part);
            }
            for (ModuleInfo moduleInfo : appInfo.getModuleInfos()) {
                for (Sniffer moduleSniffer : moduleInfo.getSniffers()) {
                    ReadableArchive moduleArchive = appInfo.getSource().getSubArchive(moduleInfo.getName());
                    addToResultDDList(moduleInfo.getName(), moduleSniffer.getDeploymentConfigurations(moduleArchive), part);
                }
            }
        } else {
            // standalone module
            for (Sniffer sniffer : appInfo.getSniffers()) {
                addToResultDDList(appname, sniffer.getDeploymentConfigurations(appInfo.getSource()), part);
            }
        }
    } catch (final IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : ModuleInfo(org.glassfish.internal.data.ModuleInfo) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) Sniffer(org.glassfish.api.container.Sniffer) IOException(java.io.IOException) ActionReport(org.glassfish.api.ActionReport) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) EngineRef(org.glassfish.internal.data.EngineRef)

Example 67 with ReadableArchive

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

the class FileArchive method getSubArchive.

/**
 * create or obtain an embedded archive within this abstraction.
 *
 * @param name name of the embedded archive.
 */
@Override
public ReadableArchive getSubArchive(String name) throws IOException {
    String subEntryName = getFileSubArchivePath(name);
    File subEntry = new File(subEntryName);
    if (subEntry.exists() && isEntryValid(subEntry)) {
        deplLogger.log(DEBUG_LEVEL, "FileArchive.getSubArchive for {0} found that it is valid", subEntry.getAbsolutePath());
        ReadableArchive result = archiveFactory.openArchive(subEntry);
        if (result instanceof AbstractReadableArchive) {
            result.setParentArchive(this);
        }
        return result;
    } else if (subEntry.exists()) {
        deplLogger.log(DEBUG_LEVEL, "FileArchive.getSubArchive for {0} found that it is not a valid entry; it is stale", subEntry.getAbsolutePath());
    }
    return null;
}
Also used : ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) JarFile(java.util.jar.JarFile)

Example 68 with ReadableArchive

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

the class MemoryMappedArchive method getSubArchive.

/**
 * create or obtain an embedded archive within this abstraction.
 *
 * @param name the name of the embedded archive.
 */
public ReadableArchive getSubArchive(String name) throws IOException {
    InputStream is = getEntry(name);
    if (is != null) {
        ReadableArchive archive = new MemoryMappedArchive(is);
        is.close();
        return archive;
    }
    return null;
}
Also used : JarInputStream(java.util.jar.JarInputStream) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive)

Example 69 with ReadableArchive

use of org.glassfish.api.deployment.archive.ReadableArchive 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 70 with ReadableArchive

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

the class DeleteApplicationRefCommand method execute.

/**
 * Entry point from the framework into the command execution
 * @param context context for the command.
 */
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    final Logger logger = context.getLogger();
    UndeployCommandParameters commandParams = new UndeployCommandParameters();
    if (server.isDas()) {
        commandParams.origin = Origin.unload;
    } else {
        // delete application ref on instance
        // is essentially an undeploy
        commandParams.origin = Origin.undeploy;
    }
    commandParams.command = Command.delete_application_ref;
    // for each matched version
    Iterator it = matchedVersions.iterator();
    while (it.hasNext()) {
        String appName = (String) it.next();
        Application application = applications.getApplication(appName);
        if (application == null) {
            if (env.isDas()) {
                // let's only do this check for DAS to be more
                // tolerable of the partial deployment case
                report.setMessage(localStrings.getLocalString("application.notreg", "Application {0} not registered", appName));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            }
            return;
        }
        ApplicationRef applicationRef = domain.getApplicationRefInTarget(appName, target);
        if (applicationRef == null) {
            if (env.isDas()) {
                // let's only do this check for DAS to be more
                // tolerable of the partial deployment case
                report.setMessage(localStrings.getLocalString("appref.not.exists", "Target {1} does not have a reference to application {0}.", appName, target));
                report.setActionExitCode(ActionReport.ExitCode.WARNING);
            }
            return;
        }
        if (application.isLifecycleModule()) {
            try {
                deployment.unregisterAppFromDomainXML(appName, target, true);
            } catch (Exception e) {
                report.failure(logger, e.getMessage());
            }
            return;
        }
        try {
            ReadableArchive source = null;
            ApplicationInfo appInfo = deployment.get(appName);
            if (appInfo != null) {
                source = appInfo.getSource();
            } else {
                File location = new File(new URI(application.getLocation()));
                source = archiveFactory.openArchive(location);
            }
            commandParams.name = appName;
            commandParams.cascade = cascade;
            final ExtendedDeploymentContext deploymentContext = deployment.getBuilder(logger, commandParams, report).source(source).build();
            deploymentContext.getAppProps().putAll(application.getDeployProperties());
            deploymentContext.setModulePropsMap(application.getModulePropertiesMap());
            if (domain.isCurrentInstanceMatchingTarget(target, appName, server.getName(), null) && appInfo != null) {
                // stop and unload application if it's the target and the
                // the application is in enabled state
                deployment.unload(appInfo, deploymentContext);
            }
            if (report.getActionExitCode().equals(ActionReport.ExitCode.SUCCESS)) {
                try {
                    if (server.isInstance()) {
                        // if it's on instance, we should clean up
                        // the bits
                        deployment.undeploy(appName, deploymentContext);
                        deploymentContext.clean();
                        if (!Boolean.valueOf(application.getDirectoryDeployed()) && source.exists()) {
                            FileUtils.whack(new File(source.getURI()));
                        }
                        deployment.unregisterAppFromDomainXML(appName, target);
                    } else {
                        deployment.unregisterAppFromDomainXML(appName, target, true);
                    }
                } catch (TransactionFailure e) {
                    logger.warning("failed to delete application ref for " + appName);
                }
            }
        } catch (Exception e) {
            logger.log(Level.SEVERE, "Error during deleteing application ref ", e);
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setMessage(e.getMessage());
        }
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) ApplicationRef(com.sun.enterprise.config.serverbeans.ApplicationRef) URI(java.net.URI) VersioningException(org.glassfish.deployment.versioning.VersioningException) UndeployCommandParameters(org.glassfish.api.deployment.UndeployCommandParameters) Iterator(java.util.Iterator) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) Application(com.sun.enterprise.config.serverbeans.Application) 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