Search in sources :

Example 16 with ApplicationRef

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

the class DeleteLifecycleModuleCommand method execute.

public void execute(AdminCommandContext context) {
    ActionReport report = context.getActionReport();
    final Logger logger = context.getLogger();
    if (!deployment.isRegistered(name)) {
        report.setMessage(localStrings.getLocalString("lifecycle.notreg", "Lifecycle module {0} not registered", name));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (!DeploymentUtils.isDomainTarget(target)) {
        ApplicationRef ref = domain.getApplicationRefInTarget(name, target);
        if (ref == null) {
            report.setMessage(localStrings.getLocalString("lifecycle.not.referenced.target", "Lifecycle module {0} is not referenced by target {1}", name, target));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
    deployment.validateUndeploymentTarget(target, name);
    if (env.isDas() && DeploymentUtils.isDomainTarget(target)) {
        // replicate command to all referenced targets
        try {
            ParameterMapExtractor extractor = new ParameterMapExtractor(this);
            ParameterMap paramMap = extractor.extract(Collections.EMPTY_LIST);
            paramMap.set("DEFAULT", name);
            ClusterOperationUtil.replicateCommand("delete-lifecycle-module", FailurePolicy.Error, FailurePolicy.Ignore, FailurePolicy.Warn, targets, context, paramMap, habitat);
        } catch (Exception e) {
            report.failure(logger, e.getMessage());
            return;
        }
    }
    try {
        deployment.unregisterAppFromDomainXML(name, target);
    } catch (Exception e) {
        report.setMessage("Failed to delete lifecycle module: " + e);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : ParameterMapExtractor(org.glassfish.common.util.admin.ParameterMapExtractor) ParameterMap(org.glassfish.api.admin.ParameterMap) ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger) ApplicationRef(com.sun.enterprise.config.serverbeans.ApplicationRef)

Example 17 with ApplicationRef

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

the class ListAppRefsCommand method execute.

public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    ActionReport.MessagePart part = report.getTopMessagePart();
    part.setMessage(target);
    part.setChildrenType("application");
    for (ApplicationRef appRef : appRefs) {
        if (state.equals("all") || (state.equals("running") && Boolean.valueOf(appRef.getEnabled())) || (state.equals("non-running") && !Boolean.valueOf(appRef.getEnabled()))) {
            if (isApplicationOfThisType(appRef.getRef(), type)) {
                ActionReport.MessagePart childPart = part.addChild();
                childPart.setMessage(appRef.getRef());
            }
        }
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : ActionReport(org.glassfish.api.ActionReport) ApplicationRef(com.sun.enterprise.config.serverbeans.ApplicationRef)

Example 18 with ApplicationRef

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

the class ListApplicationRefsCommand 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 ActionReport subReport = report.addSubActionsReport();
    ColumnFormatter cf = new ColumnFormatter();
    ActionReport.MessagePart part = report.getTopMessagePart();
    int numOfApplications = 0;
    if (!terse && long_opt) {
        String[] headings = new String[] { "NAME", "STATUS" };
        cf = new ColumnFormatter(headings);
    }
    for (ApplicationRef ref : appRefs) {
        Object[] row = new Object[] { ref.getRef() };
        if (!terse && long_opt) {
            row = new Object[] { ref.getRef(), getLongStatus(ref) };
        }
        cf.addRow(row);
        numOfApplications++;
    }
    if (numOfApplications != 0) {
        report.setMessage(cf.toString());
    } else if (!terse) {
        subReport.setMessage(localStrings.getLocalString(DeployCommand.class, "NoSuchAppDeployed", "No applications are deployed to this target {0}.", new Object[] { this.target }));
        part.setMessage(localStrings.getLocalString("list.components.no.elements.to.list", "Nothing to List."));
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : ActionReport(org.glassfish.api.ActionReport) ApplicationRef(com.sun.enterprise.config.serverbeans.ApplicationRef) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter) RestEndpoint(org.glassfish.api.admin.RestEndpoint)

Example 19 with ApplicationRef

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

the class UpdateApplicationRefCommand method execute.

/**
 * Execution method for updating the configuration of an ApplicationRef.
 * Will be replicated if the target is a cluster.
 *
 * @param context context for the command.
 */
@Override
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    final Logger logger = context.getLogger();
    // Make a list of all ApplicationRefs that need to change
    List<ApplicationRef> applicationRefsToChange = new ArrayList<>();
    // Add the ApplicationRef which is being immediately targetted
    {
        ApplicationRef primaryApplicationRef = domain.getApplicationRefInTarget(name, target);
        if (primaryApplicationRef == null) {
            report.failure(logger, LOCAL_STRINGS.getLocalString("appref.not.exists", "Target {1} does not have a reference to application {0}.", name, target));
            return;
        }
        applicationRefsToChange.add(primaryApplicationRef);
    }
    // Add the implicitly targetted ApplicationRefs if the target is in a cluster or deployment group
    {
        Cluster cluster = domain.getClusterNamed(target);
        // if the target is a cluster
        if (cluster != null) {
            for (Server server : cluster.getInstances()) {
                ApplicationRef instanceAppRef = server.getApplicationRef(name);
                // if the server in the cluster contains the ApplicationRef
                if (instanceAppRef != null) {
                    applicationRefsToChange.add(instanceAppRef);
                }
            }
        }
        DeploymentGroup dg = domain.getDeploymentGroupNamed(target);
        if (dg != null) {
            for (Server server : dg.getInstances()) {
                ApplicationRef instanceAppRef = server.getApplicationRef(name);
                // if the server in the dg contains the ApplicationRef
                if (instanceAppRef != null) {
                    applicationRefsToChange.add(instanceAppRef);
                }
            }
        }
    }
    // Apply the configuration to the listed ApplicationRefs
    try {
        ConfigSupport.apply(new ConfigCode() {

            @Override
            public Object run(ConfigBeanProxy... params) throws PropertyVetoException, TransactionFailure {
                for (ConfigBeanProxy proxy : params) {
                    if (proxy instanceof ApplicationRef) {
                        ApplicationRef applicationRefProxy = (ApplicationRef) proxy;
                        if (enabled != null) {
                            applicationRefProxy.setEnabled(enabled.toString());
                        }
                        if (virtualservers != null) {
                            applicationRefProxy.setVirtualServers(virtualservers);
                        }
                        if (lbenabled != null) {
                            applicationRefProxy.setLbEnabled(lbenabled.toString());
                        }
                    }
                }
                report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                return true;
            }
        }, applicationRefsToChange.toArray(new ApplicationRef[] {}));
    } catch (TransactionFailure ex) {
        report.failure(logger, ex.getLocalizedMessage());
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Server(com.sun.enterprise.config.serverbeans.Server) ArrayList(java.util.ArrayList) Cluster(com.sun.enterprise.config.serverbeans.Cluster) ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger) ApplicationRef(com.sun.enterprise.config.serverbeans.ApplicationRef) PropertyVetoException(java.beans.PropertyVetoException) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) ConfigCode(org.jvnet.hk2.config.ConfigCode) DeploymentGroup(fish.payara.enterprise.config.serverbeans.DeploymentGroup)

Example 20 with ApplicationRef

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

the class AddInstanceToDeploymentGroupCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    Server server = domain.getServerNamed(instanceName);
    ActionReport report = context.getActionReport();
    if (server == null && env.isDas()) {
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage("Instance " + instanceName + " does not exist");
        return;
    }
    DeploymentGroup dg = domain.getDeploymentGroupNamed(deploymentGroup);
    if (dg == null && env.isDas()) {
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage("Deployment Group " + deploymentGroup + " does not exist");
        return;
    }
    // OK set up the reference
    try {
        ConfigSupport.apply((DeploymentGroup dg1) -> {
            DGServerRef ref = dg1.createChild(DGServerRef.class);
            ref.setRef(instanceName);
            dg1.getDGServerRef().add(ref);
            return ref;
        }, dg);
    } catch (TransactionFailure e) {
        report.setMessage("Failed to add instance to deployment group");
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
    }
    // now run the command to add application ref to the instance
    for (ApplicationRef applicationRef : dg.getApplicationRef()) {
        CommandInvocation inv = commandRunner.getCommandInvocation("create-application-ref", report, context.getSubject());
        ParameterMap parameters = new ParameterMap();
        parameters.add("target", instanceName);
        parameters.add("name", applicationRef.getRef());
        parameters.add("virtualservers", applicationRef.getVirtualServers());
        parameters.add("enabled", applicationRef.getEnabled());
        parameters.add("lbenabled", applicationRef.getLbEnabled());
        inv.parameters(parameters).execute();
    }
    // for all resource refs add resource ref to instance
    for (ResourceRef resourceRef : dg.getResourceRef()) {
        CommandInvocation inv = commandRunner.getCommandInvocation("create-resource-ref", report, context.getSubject());
        ParameterMap parameters = new ParameterMap();
        parameters.add("target", instanceName);
        parameters.add("reference_name", resourceRef.getRef());
        parameters.add("enabled", resourceRef.getEnabled());
        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) DeploymentGroup(fish.payara.enterprise.config.serverbeans.DeploymentGroup) CommandInvocation(org.glassfish.api.admin.CommandRunner.CommandInvocation)

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