use of fish.payara.enterprise.config.serverbeans.DeploymentGroup in project Payara by payara.
the class AddInstanceToDeploymentGroupCommand method execute.
@Override
public void execute(AdminCommandContext context) {
ActionReport report = context.getActionReport();
DeploymentGroup deploymentGroup = domain.getDeploymentGroupNamed(deploymentGroupName);
if (deploymentGroup == null && env.isDas()) {
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage("Deployment Group " + deploymentGroup + " does not exist");
return;
}
List<String> instances = Arrays.asList(instanceName.split(","));
for (String instance : instances) {
Server server = domain.getServerNamed(instance);
if (server == null && env.isDas()) {
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage("Instance " + instance + " does not exist");
return;
}
// OK set up the reference
try {
ConfigSupport.apply((DeploymentGroup dg1) -> {
DGServerRef deploymentGroupServerRef = dg1.createChild(DGServerRef.class);
deploymentGroupServerRef.setRef(instance);
dg1.getDGServerRef().add(deploymentGroupServerRef);
return deploymentGroupServerRef;
}, deploymentGroup);
} 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 : deploymentGroup.getApplicationRef()) {
CommandInvocation inv = commandRunner.getCommandInvocation("create-application-ref", report, context.getSubject());
ParameterMap parameters = new ParameterMap();
parameters.add("target", instance);
parameters.add("name", applicationRef.getRef());
String virtualServers = applicationRef.getVirtualServers();
if (virtualServers == null || virtualServers.isEmpty()) {
virtualServers = getVirtualServers(server);
}
parameters.add("virtualservers", virtualServers);
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 : deploymentGroup.getResourceRef()) {
CommandInvocation inv = commandRunner.getCommandInvocation("create-resource-ref", report, context.getSubject());
ParameterMap parameters = new ParameterMap();
parameters.add("target", instance);
parameters.add("reference_name", resourceRef.getRef());
parameters.add("enabled", resourceRef.getEnabled());
inv.parameters(parameters).execute();
}
}
}
use of fish.payara.enterprise.config.serverbeans.DeploymentGroup in project Payara by payara.
the class RemoveInstanceFromDeploymentGroupCommand method execute.
@Override
public void execute(AdminCommandContext context) {
ActionReport report = context.getActionReport();
DeploymentGroup deploymentGroup = domain.getDeploymentGroupNamed(deploymentGroupName);
if (deploymentGroup == null) {
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage("Deployment Group " + deploymentGroupName + " does not exist");
return;
}
List<String> instances = Arrays.asList(instanceName.split(","));
for (String instance : instances) {
Server server = domain.getServerNamed(instance);
if (server == null) {
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage("Instance " + instance + " does not exist");
return;
}
DGServerRef deploymentGroupServerRef = deploymentGroup.getDGServerRefByRef(instance);
if (deploymentGroupServerRef == null) {
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage("Deployment Group " + deploymentGroupName + " does not contain server " + instance);
return;
}
// OK set up the reference
try {
ConfigSupport.apply((DeploymentGroup dg1) -> {
dg1.getDGServerRef().remove(deploymentGroupServerRef);
return null;
}, deploymentGroup);
} 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 deploymentGroupServerRef to the instance
for (ApplicationRef applicationRef : deploymentGroup.getApplicationRef()) {
CommandRunner.CommandInvocation inv = commandRunner.getCommandInvocation("delete-application-ref", report, context.getSubject());
ParameterMap parameters = new ParameterMap();
parameters.add("target", instance);
parameters.add("name", applicationRef.getRef());
inv.parameters(parameters).execute();
}
// now run the command to remove resource deploymentGroupServerRef to the instance
for (ResourceRef resourceRef : deploymentGroup.getResourceRef()) {
CommandRunner.CommandInvocation inv = commandRunner.getCommandInvocation("delete-resource-ref", report, context.getSubject());
ParameterMap parameters = new ParameterMap();
parameters.add("target", instance);
parameters.add("reference_name", resourceRef.getRef());
inv.parameters(parameters).execute();
}
}
}
use of fish.payara.enterprise.config.serverbeans.DeploymentGroup in project Payara by payara.
the class Target method getInstances.
/**
* Given the name of a target, returns a list of Server objects. If given target is a standalone server,
* then the server's Server element is returned in the list. If the target is a cluster, then the list of Server
* elements that represent all server instances of that cluster is returned.
* @param targetName the name of the target
* @return list of Server elements that represent the target
*/
public List<Server> getInstances(String targetName) {
List<Server> instances = new ArrayList<Server>();
if (CommandTarget.DOMAIN.isValid(habitat, targetName))
return instances;
if (CommandTarget.DAS.isValid(habitat, targetName))
return instances;
if (CommandTarget.STANDALONE_INSTANCE.isValid(habitat, targetName)) {
instances.add(domain.getServerNamed(targetName));
}
if (CommandTarget.CLUSTER.isValid(habitat, targetName)) {
instances = getCluster(targetName).getInstances();
}
if (CommandTarget.CONFIG.isValid(habitat, targetName)) {
List<String> targets = domain.getAllTargets();
for (String aTarget : targets) {
if (CommandTarget.CLUSTER.isValid(habitat, aTarget) && getCluster(aTarget).getConfigRef().equals(targetName)) {
instances.addAll(getCluster(aTarget).getInstances());
}
if (CommandTarget.STANDALONE_INSTANCE.isValid(habitat, aTarget) && domain.getServerNamed(aTarget).getConfigRef().equals(targetName)) {
instances.add(domain.getServerNamed(aTarget));
}
}
}
if (CommandTarget.NODE.isValid(habitat, targetName)) {
List<Server> allInstances = getAllInstances();
for (Server s : allInstances) {
if (targetName.equals(s.getNodeRef()))
instances.add(s);
}
}
if (CommandTarget.DEPLOYMENT_GROUP.isValid(habitat, targetName)) {
DeploymentGroup dg = domain.getDeploymentGroupNamed(targetName);
instances.addAll(dg.getInstances());
}
return instances;
}
use of fish.payara.enterprise.config.serverbeans.DeploymentGroup in project Payara by payara.
the class ApplicationLifecycle method registerAppInDomainXML.
// register application information in domain.xml
@Override
public void registerAppInDomainXML(final ApplicationInfo applicationInfo, final DeploymentContext context, Transaction t, boolean appRefOnly) throws TransactionFailure {
final Properties appProps = context.getAppProps();
final DeployCommandParameters deployParams = context.getCommandParameters(DeployCommandParameters.class);
if (t != null) {
try {
if (!appRefOnly) {
Application app_w = context.getTransientAppMetaData(ServerTags.APPLICATION, Application.class);
// adding the application element
setRestAppAttributes(app_w, appProps);
Applications apps_w = t.enroll(applications);
apps_w.getModules().add(app_w);
if (applicationInfo != null) {
applicationInfo.save(app_w);
}
}
List<String> targets = new ArrayList<>();
if (!DeploymentUtils.isDomainTarget(deployParams.target)) {
targets.add(deployParams.target);
} else {
List<String> previousTargets = context.getTransientAppMetaData(DeploymentProperties.PREVIOUS_TARGETS, List.class);
if (previousTargets == null) {
previousTargets = domain.getAllReferencedTargetsForApplication(deployParams.name);
}
targets = previousTargets;
}
String origVS = deployParams.virtualservers;
Boolean origEnabled = deployParams.enabled;
Properties previousVirtualServers = context.getTransientAppMetaData(DeploymentProperties.PREVIOUS_VIRTUAL_SERVERS, Properties.class);
Properties previousEnabledAttributes = context.getTransientAppMetaData(DeploymentProperties.PREVIOUS_ENABLED_ATTRIBUTES, Properties.class);
for (String target : targets) {
// first reset the virtualservers, enabled attribute
deployParams.virtualservers = origVS;
deployParams.enabled = origEnabled;
// applicable
if (DeploymentUtils.isDomainTarget(deployParams.target)) {
String vs = previousVirtualServers.getProperty(target);
if (vs != null) {
deployParams.virtualservers = vs;
}
String enabledAttr = previousEnabledAttributes.getProperty(target);
if (enabledAttr != null) {
deployParams.enabled = Boolean.valueOf(enabledAttr);
}
}
if (deployParams.enabled == null) {
deployParams.enabled = Boolean.TRUE;
}
Server servr = domain.getServerNamed(target);
if (servr != null) {
ApplicationRef instanceApplicationRef = domain.getApplicationRefInTarget(deployParams.name, servr.getName());
if (instanceApplicationRef == null) {
// adding the application-ref element to the standalone
// server instance
ConfigBeanProxy servr_w = t.enroll(servr);
// adding the application-ref element to the standalone
// server instance
ApplicationRef appRef = servr_w.createChild(ApplicationRef.class);
setAppRefAttributes(appRef, deployParams);
((Server) servr_w).getApplicationRef().add(appRef);
}
}
Cluster cluster = domain.getClusterNamed(target);
if (cluster != null) {
// adding the application-ref element to the cluster
// and instances
ConfigBeanProxy cluster_w = t.enroll(cluster);
ApplicationRef appRef = cluster_w.createChild(ApplicationRef.class);
setAppRefAttributes(appRef, deployParams);
((Cluster) cluster_w).getApplicationRef().add(appRef);
for (Server svr : cluster.getInstances()) {
ConfigBeanProxy svr_w = t.enroll(svr);
ApplicationRef appRef2 = svr_w.createChild(ApplicationRef.class);
setAppRefAttributes(appRef2, deployParams);
((Server) svr_w).getApplicationRef().add(appRef2);
}
}
DeploymentGroup dg = domain.getDeploymentGroupNamed(target);
if (dg != null) {
ConfigBeanProxy dg_w = t.enroll(dg);
ApplicationRef appRef = dg_w.createChild(ApplicationRef.class);
setAppRefAttributes(appRef, deployParams);
((DeploymentGroup) dg_w).getApplicationRef().add(appRef);
for (Server svr : dg.getInstances()) {
ApplicationRef instanceApplicationRef = domain.getApplicationRefInTarget(deployParams.name, svr.getName());
if (instanceApplicationRef == null) {
ConfigBeanProxy svr_w = t.enroll(svr);
ApplicationRef appRef2 = svr_w.createChild(ApplicationRef.class);
setAppRefAttributes(appRef2, deployParams);
((Server) svr_w).getApplicationRef().add(appRef2);
}
}
}
}
} catch (TransactionFailure e) {
t.rollback();
throw e;
} catch (Exception e) {
t.rollback();
throw new TransactionFailure(e.getMessage(), e);
}
try {
t.commit();
} catch (RetryableException e) {
System.out.println("Retryable...");
// TODO : do something meaninful here
t.rollback();
} catch (TransactionFailure e) {
t.rollback();
throw e;
}
}
}
use of fish.payara.enterprise.config.serverbeans.DeploymentGroup in project Payara by payara.
the class SystemTasksImpl method setSystemPropertiesFromDomainXml.
private void setSystemPropertiesFromDomainXml() {
// precedence order from high to low
// 0. server
// 1. cluster
// 2. <server>-config or <cluster>-config
// 3. deployment-group
// 4. domain
// so we need to add System Properties in *reverse order* to get the
// right precedence.
List<SystemProperty> domainSPList = domain.getSystemProperty();
List<SystemProperty> configSPList = getConfigSystemProperties();
Cluster cluster = server.getCluster();
List<SystemProperty> clusterSPList = null;
List<DeploymentGroup> depGroups = server.getDeploymentGroup();
List<Property> depGroupProperties = new ArrayList<>();
for (DeploymentGroup group : depGroups) {
depGroupProperties.addAll(group.getProperty());
}
if (cluster != null) {
clusterSPList = cluster.getSystemProperty();
}
List<SystemProperty> serverSPList = server.getSystemProperty();
setSystemProperties(domainSPList);
setProperties(depGroupProperties);
setSystemProperties(configSPList);
if (clusterSPList != null) {
setSystemProperties(clusterSPList);
}
setSystemProperties(serverSPList);
}
Aggregations