Search in sources :

Example 1 with DGServerRef

use of fish.payara.enterprise.config.serverbeans.DGServerRef 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)

Example 2 with DGServerRef

use of fish.payara.enterprise.config.serverbeans.DGServerRef 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)

Aggregations

ApplicationRef (com.sun.enterprise.config.serverbeans.ApplicationRef)2 ResourceRef (com.sun.enterprise.config.serverbeans.ResourceRef)2 Server (com.sun.enterprise.config.serverbeans.Server)2 DGServerRef (fish.payara.enterprise.config.serverbeans.DGServerRef)2 DeploymentGroup (fish.payara.enterprise.config.serverbeans.DeploymentGroup)2 ActionReport (org.glassfish.api.ActionReport)2 ParameterMap (org.glassfish.api.admin.ParameterMap)2 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)2 CommandRunner (org.glassfish.api.admin.CommandRunner)1 CommandInvocation (org.glassfish.api.admin.CommandRunner.CommandInvocation)1