Search in sources :

Example 11 with ApplicationRef

use of com.sun.enterprise.config.serverbeans.ApplicationRef in project Payara by payara.

the class ListApplicationRefsCommand method getAccessChecks.

@Override
public Collection<? extends AccessCheck> getAccessChecks() {
    final List<AccessCheck> accessChecks = new ArrayList<AccessCheck>();
    appRefs = domain.getApplicationRefsInTarget(target);
    for (ApplicationRef appRef : appRefs) {
        accessChecks.add(new AccessCheck(AccessRequired.Util.resourceNameFromConfigBeanProxy(appRef), "read"));
    }
    return accessChecks;
}
Also used : AccessCheck(org.glassfish.api.admin.AccessRequired.AccessCheck) ArrayList(java.util.ArrayList) ApplicationRef(com.sun.enterprise.config.serverbeans.ApplicationRef)

Example 12 with ApplicationRef

use of com.sun.enterprise.config.serverbeans.ApplicationRef in project Payara by payara.

the class ApplicationConfigListener method disableApplication.

private void disableApplication(String appName) {
    Application app = applications.getApplication(appName);
    ApplicationRef appRef = domain.getApplicationRefInServer(server.getName(), appName);
    // by the current server instance, do not unload
    if (app == null || appRef == null) {
        return;
    }
    ApplicationInfo appInfo = appRegistry.get(appName);
    if (appInfo == null || !appInfo.isLoaded()) {
        return;
    }
    try {
        ActionReport report = new HTMLActionReporter();
        UndeployCommandParameters commandParams = new UndeployCommandParameters();
        commandParams.name = appName;
        commandParams.target = server.getName();
        commandParams.origin = UndeployCommandParameters.Origin.unload;
        commandParams.command = UndeployCommandParameters.Command.disable;
        deployment.disable(commandParams, app, appInfo, report, logger);
        if (report.getActionExitCode().equals(ActionReport.ExitCode.FAILURE)) {
            throw new Exception(report.getMessage());
        }
    } catch (Exception e) {
        logger.log(Level.SEVERE, KernelLoggerInfo.loadingApplicationErrorDisable, e);
        throw new RuntimeException(e);
    }
}
Also used : UndeployCommandParameters(org.glassfish.api.deployment.UndeployCommandParameters) HTMLActionReporter(com.sun.enterprise.v3.common.HTMLActionReporter) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) ActionReport(org.glassfish.api.ActionReport) Application(com.sun.enterprise.config.serverbeans.Application) ApplicationRef(com.sun.enterprise.config.serverbeans.ApplicationRef)

Example 13 with ApplicationRef

use of com.sun.enterprise.config.serverbeans.ApplicationRef in project Payara by payara.

the class ShowComponentStatusCommand method execute.

public void execute(AdminCommandContext context) {
    ActionReport.MessagePart part;
    if (report == null) {
        // We could handle this more elegantly by requiring that report be passed as an argument.
        throw new IllegalStateException("Internal Error: The report should have been initializes by the preAuthorization method");
    } else {
        part = report.getTopMessagePart();
    }
    // for each matched version
    Iterator it = matchedVersions.iterator();
    while (it.hasNext()) {
        String appName = (String) it.next();
        String status = "disabled";
        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;
            }
        }
        if (domain.isAppEnabledInTarget(appName, target)) {
            status = "enabled";
        }
        ActionReport.MessagePart childPart = part.addChild();
        String message = localStrings.getLocalString("component.status", "Status of {0} is {1}.", appName, status);
        childPart.setMessage(message);
        childPart.addProperty(DeploymentProperties.STATE, status);
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : Iterator(java.util.Iterator) ActionReport(org.glassfish.api.ActionReport) ApplicationRef(com.sun.enterprise.config.serverbeans.ApplicationRef)

Example 14 with ApplicationRef

use of com.sun.enterprise.config.serverbeans.ApplicationRef in project Payara by payara.

the class DeleteVirtualServer method execute.

/**
 * Executes the command with the command parameters passed as Properties
 * where the keys are the parameter names and the values the parameter values
 *
 * @param context information
 */
public void execute(AdminCommandContext context) {
    Target targetUtil = services.getService(Target.class);
    Config newConfig = targetUtil.getConfig(target);
    if (newConfig != null) {
        config = newConfig;
    }
    ActionReport report = context.getActionReport();
    httpService = config.getHttpService();
    networkConfig = config.getNetworkConfig();
    if (!exists()) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_VIRTUAL_SERVER_NOT_EXISTS), vsid));
        report.setActionExitCode(ExitCode.FAILURE);
        return;
    }
    // reference check
    String referencedBy = getReferencingListener();
    if (referencedBy != null && referencedBy.length() != 0) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_VIRTUAL_SERVER_REFERENCED), vsid, referencedBy));
        report.setActionExitCode(ExitCode.FAILURE);
        return;
    }
    try {
        // we need to determine which deployed applications reference this virtual-server
        List<ApplicationRef> appRefs = new ArrayList<ApplicationRef>();
        for (ApplicationRef appRef : server.getApplicationRef()) {
            if (appRef.getVirtualServers() != null && appRef.getVirtualServers().contains(vsid)) {
                appRefs.add(appRef);
            }
        }
        // transfer into the array of arguments
        ConfigBeanProxy[] proxies = new ConfigBeanProxy[appRefs.size() + 1];
        proxies[0] = httpService;
        for (int i = 0; i < appRefs.size(); i++) {
            proxies[i + 1] = appRefs.get(i);
        }
        ConfigSupport.apply(new ConfigUpdate(vsid), proxies);
        report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    } catch (TransactionFailure e) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_VIRTUAL_SERVER_FAIL), vsid));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) Config(com.sun.enterprise.config.serverbeans.Config) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) ArrayList(java.util.ArrayList) ActionReport(org.glassfish.api.ActionReport) ApplicationRef(com.sun.enterprise.config.serverbeans.ApplicationRef)

Example 15 with ApplicationRef

use of com.sun.enterprise.config.serverbeans.ApplicationRef 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

ApplicationRef (com.sun.enterprise.config.serverbeans.ApplicationRef)23 ActionReport (org.glassfish.api.ActionReport)11 Application (com.sun.enterprise.config.serverbeans.Application)9 Server (com.sun.enterprise.config.serverbeans.Server)8 ArrayList (java.util.ArrayList)6 ApplicationInfo (org.glassfish.internal.data.ApplicationInfo)6 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)5 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)4 Applications (com.sun.enterprise.config.serverbeans.Applications)3 Cluster (com.sun.enterprise.config.serverbeans.Cluster)3 DeploymentGroup (fish.payara.enterprise.config.serverbeans.DeploymentGroup)3 Iterator (java.util.Iterator)3 Logger (java.util.logging.Logger)3 ParameterMap (org.glassfish.api.admin.ParameterMap)3 UndeployCommandParameters (org.glassfish.api.deployment.UndeployCommandParameters)3 ConfigCode (org.jvnet.hk2.config.ConfigCode)3 ResourceRef (com.sun.enterprise.config.serverbeans.ResourceRef)2 SystemApplications (com.sun.enterprise.config.serverbeans.SystemApplications)2 HTMLActionReporter (com.sun.enterprise.v3.common.HTMLActionReporter)2 DGServerRef (fish.payara.enterprise.config.serverbeans.DGServerRef)2