Search in sources :

Example 21 with ApplicationRef

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

the class RemoveInstanceFromDeploymentGroupCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    Server server = domain.getServerNamed(instanceName);
    ActionReport report = context.getActionReport();
    if (server == null) {
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage("Instance " + instanceName + " does not exist");
        return;
    }
    DeploymentGroup dg = domain.getDeploymentGroupNamed(deploymentGroup);
    if (dg == null) {
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage("Deployment Group " + deploymentGroup + " does not exist");
        return;
    }
    DGServerRef ref = dg.getDGServerRefByRef(instanceName);
    if (ref == null) {
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage("Deployment Group " + deploymentGroup + " does not contain server " + instanceName);
        return;
    }
    // OK set up the reference
    try {
        ConfigSupport.apply((DeploymentGroup dg1) -> {
            dg1.getDGServerRef().remove(ref);
            return null;
        }, dg);
    } catch (TransactionFailure e) {
        report.setMessage("Failed to remove instance from the deployment group");
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
    }
    // now run the command to remove application ref to the instance
    for (ApplicationRef applicationRef : dg.getApplicationRef()) {
        CommandRunner.CommandInvocation inv = commandRunner.getCommandInvocation("delete-application-ref", report, context.getSubject());
        ParameterMap parameters = new ParameterMap();
        parameters.add("target", instanceName);
        parameters.add("name", applicationRef.getRef());
        inv.parameters(parameters).execute();
    }
    // now run the command to remove resource ref to the instance
    for (ResourceRef resourceRef : dg.getResourceRef()) {
        CommandRunner.CommandInvocation inv = commandRunner.getCommandInvocation("delete-resource-ref", report, context.getSubject());
        ParameterMap parameters = new ParameterMap();
        parameters.add("target", instanceName);
        parameters.add("reference_name", resourceRef.getRef());
        inv.parameters(parameters).execute();
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Server(com.sun.enterprise.config.serverbeans.Server) DGServerRef(fish.payara.enterprise.config.serverbeans.DGServerRef) ParameterMap(org.glassfish.api.admin.ParameterMap) ResourceRef(com.sun.enterprise.config.serverbeans.ResourceRef) ActionReport(org.glassfish.api.ActionReport) ApplicationRef(com.sun.enterprise.config.serverbeans.ApplicationRef) CommandRunner(org.glassfish.api.admin.CommandRunner) DeploymentGroup(fish.payara.enterprise.config.serverbeans.DeploymentGroup)

Example 22 with ApplicationRef

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

the class ApplicationConfigListener method transactionCommited.

public void transactionCommited(final List<PropertyChangeEvent> changes) {
    boolean isUpdatingAttribute = true;
    for (PropertyChangeEvent event : changes) {
        Object oldValue = event.getOldValue();
        Object newValue = event.getNewValue();
        if (event.getSource() instanceof Applications) {
            if (event.getPropertyName().equals(ServerTags.APPLICATION)) {
                if (oldValue == null || newValue == null) {
                    // we are adding/removing application element here
                    // and updating existing attribute
                    isUpdatingAttribute = false;
                    break;
                }
            }
        } else if (event.getSource() instanceof Server || event.getSource() instanceof Cluster) {
            if (event.getPropertyName().equals(ServerTags.APPLICATION_REF)) {
                if (oldValue == null || newValue == null) {
                    // we are adding/removing application-ref element here
                    // and updating existing attribute
                    isUpdatingAttribute = false;
                    break;
                }
            }
        }
    }
    if (!isUpdatingAttribute) {
        // skip the config listener
        return;
    }
    for (PropertyChangeEvent event : changes) {
        if (event.getSource() instanceof Application || event.getSource() instanceof ApplicationRef || event.getSource() instanceof Property) {
            Object oldValue = event.getOldValue();
            Object newValue = event.getNewValue();
            String propertyName = null;
            if (oldValue != null && newValue != null && oldValue instanceof String && newValue instanceof String && !((String) oldValue).equals((String) newValue)) {
                // if it's an attribute change of the application
                // element or application-ref element
                Object parent = event.getSource();
                String appName = null;
                if (parent instanceof Application) {
                    appName = ((Application) parent).getName();
                    propertyName = event.getPropertyName();
                } else if (parent instanceof ApplicationRef) {
                    appName = ((ApplicationRef) parent).getRef();
                    propertyName = event.getPropertyName();
                } else if (parent instanceof Property) {
                    appName = ((Property) parent).getParent(Application.class).getName();
                    propertyName = ((Property) parent).getName();
                }
                // anything
                if (applications.getApplication(appName) == null) {
                    return;
                }
                if (ServerTags.ENABLED.equals(propertyName)) {
                    // enable or disable application accordingly
                    handleAppEnableChange(event.getSource(), appName, Boolean.valueOf((String) newValue));
                } else if (ServerTags.CONTEXT_ROOT.equals(propertyName) || ServerTags.VIRTUAL_SERVERS.equals(propertyName) || ServerTags.AVAILABILITY_ENABLED.equals(propertyName) || ServerTags.CDI_DEV_MODE_ENABLED_PROP.equals(propertyName)) {
                    // for other changes, reload the application
                    handleOtherAppConfigChanges(event.getSource(), appName);
                }
            }
        }
    }
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) Applications(com.sun.enterprise.config.serverbeans.Applications) Server(com.sun.enterprise.config.serverbeans.Server) Cluster(com.sun.enterprise.config.serverbeans.Cluster) Application(com.sun.enterprise.config.serverbeans.Application) ApplicationRef(com.sun.enterprise.config.serverbeans.ApplicationRef) Property(org.jvnet.hk2.config.types.Property)

Example 23 with ApplicationRef

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

the class ApplicationConfigListener method enableApplication.

private void enableApplication(String appName) {
    Application app = applications.getApplication(appName);
    ApplicationRef appRef = domain.getApplicationRefInServer(server.getName(), appName);
    // by the current server instance, do not load
    if (app == null || appRef == null) {
        return;
    }
    // if the application is not in enable state, do not load
    if (!deployment.isAppEnabled(app)) {
        return;
    }
    ApplicationInfo appInfo = appRegistry.get(appName);
    if (appInfo == null || appInfo.isLoaded()) {
        return;
    }
    long operationStartTime = Calendar.getInstance().getTimeInMillis();
    try {
        ActionReport report = new HTMLActionReporter();
        deployment.enable(server.getName(), app, appRef, report, logger);
        if (report.getActionExitCode().equals(ActionReport.ExitCode.SUCCESS)) {
            logger.log(Level.INFO, KernelLoggerInfo.loadingApplicationTime, new Object[] { appName, (Calendar.getInstance().getTimeInMillis() - operationStartTime) });
        } else if (report.getActionExitCode().equals(ActionReport.ExitCode.WARNING)) {
            logger.log(Level.WARNING, KernelLoggerInfo.loadingApplicationWarning, new Object[] { appName, report.getMessage() });
        } else if (report.getActionExitCode().equals(ActionReport.ExitCode.FAILURE)) {
            throw new Exception(report.getMessage());
        }
    } catch (Exception e) {
        logger.log(Level.SEVERE, KernelLoggerInfo.loadingApplicationErrorEnable, e);
        throw new RuntimeException(e);
    }
}
Also used : 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)

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