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();
}
}
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();
}
}
Aggregations