Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FISH-407 List of enabled application targets is not always correct #4868

Merged
merged 2 commits into from
Sep 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1805,6 +1805,31 @@ public Object run(ConfigBeanProxy param) throws PropertyVetoException, Transacti
}
}
}

DeploymentGroup deploymentGroup = dmn.getDeploymentGroupNamed(target);
if (deploymentGroup != null) {
// update the application-ref from Deployment Group
for (ApplicationRef appRef
: deploymentGroup.getApplicationRef()) {
if (appRef.getRef().equals(appName)) {
ConfigBeanProxy appRef_w = t.enroll(appRef);
((ApplicationRef) appRef_w).setEnabled(String.valueOf(enabled));
break;
}
}

// update the application-ref from Deployment Group instances
for (Server svr : deploymentGroup.getInstances()) {
for (ApplicationRef appRef
: svr.getApplicationRef()) {
if (appRef.getRef().equals(appName)) {
ConfigBeanProxy appRef_w = t.enroll(appRef);
((ApplicationRef) appRef_w).setEnabled(String.valueOf(enabled));
break;
}
}
}
}
}
}
return Boolean.TRUE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
// Portions Copyright [2016] [Payara Foundation]
// Portions Copyright [2016-2020] [Payara Foundation]

package org.glassfish.deployment.admin;

Expand Down Expand Up @@ -385,7 +385,7 @@ public void execute(AdminCommandContext context) {

// SHOULD CHECK THAT WE ARE THE CORRECT TARGET BEFORE DISABLING
String serverName = server.getName();
if (serverName.equals(target) || isTargetCluster() || isTargetDeploymentGroup()) {
if (serverName.equals(target) || isTargetCluster() || isTargetDeploymentGroup() || isTargetInstanceInDeploymentGroup()) {
// wait until all applications are loaded. Otherwise we get "Application not registered"
startupProvider.get();
ApplicationInfo appInfo = deployment.get(appName);
Expand Down Expand Up @@ -437,13 +437,22 @@ private boolean isTargetCluster() {
}

private boolean isTargetDeploymentGroup() {
List<DeploymentGroup> deploymentGroups = server.getDeploymentGroup();
for (DeploymentGroup deploymentGroup : deploymentGroups) {
if (deploymentGroup.getName().equals(target)) {
if (domain.getDeploymentGroupNamed(target) != null) {
return true;
}

return false;
}

private boolean isTargetInstanceInDeploymentGroup() {
for (DeploymentGroup deploymentGroup : domain.getDeploymentGroups().getDeploymentGroup()) {

for (Server instance : deploymentGroup.getInstances()) {
if (instance.getName().equals(target)) {
return true;
}
}

}
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
* holder.
*/

// Portions Copyright [2020] [Payara Foundation]

package org.glassfish.deployment.admin;

import com.sun.enterprise.deploy.shared.ArchiveFactory;
Expand All @@ -56,6 +58,7 @@
import com.sun.enterprise.util.LocalStringManagerImpl;
import com.sun.enterprise.config.serverbeans.*;
import com.sun.enterprise.admin.util.ClusterOperationUtil;
import fish.payara.enterprise.config.serverbeans.DeploymentGroup;
import java.util.Collection;
import org.glassfish.api.ActionReport;
import org.glassfish.api.I18n;
Expand Down Expand Up @@ -255,21 +258,24 @@ public void execute(AdminCommandContext context) {
}
}

try {
Application app = applications.getApplication(name());
ApplicationRef appRef = domain.getApplicationRefInServer(server.getName(), name());

try {
// update enabled so anything that triggers an action during startup can see the
// application is enabled.
try {
deployment.updateAppEnabledAttributeInDomainXML(name(), target, true);
} catch(TransactionFailure e) {
logger.log(Level.WARNING, "failed to set enable attribute for " + name(), e);
logger.log(Level.WARNING, "failed to set enable attribute for " + name(), e);
}

DeploymentContext dc = deployment.enable(target, app, appRef, report, logger);
suppInfo.setDeploymentContext((ExtendedDeploymentContext)dc);


// SHOULD CHECK THAT WE ARE THE CORRECT TARGET BEFORE ENABLING
String serverName = server.getName();
if (serverName.equals(target) || isTargetCluster() || isTargetDeploymentGroup()) {
ApplicationRef appRef = domain.getApplicationRefInTarget(name(), target);
Application app = applications.getApplication(name());
DeploymentContext deploymentContext = deployment.enable(target, app, appRef, report, logger);
suppInfo.setDeploymentContext((ExtendedDeploymentContext) deploymentContext);
}

if (report.getActionExitCode().equals(ActionReport.ExitCode.FAILURE)) {
// update the domain.xml
try {
Expand All @@ -285,7 +291,29 @@ public void execute(AdminCommandContext context) {
}
}

private boolean isTargetCluster() {
Cluster cluster = server.getCluster();
if (cluster != null) {
if (cluster.getName().equals(target)) {
return true;
}
}

return false;
}

private boolean isTargetDeploymentGroup() {
List<DeploymentGroup> deploymentGroups = server.getDeploymentGroup();
for (DeploymentGroup deploymentGroup : deploymentGroups) {
if (deploymentGroup.getName().equals(target)) {
return true;
}
}

return false;
}

public String getTarget(ParameterMap parameters) {
return DeploymentCommandUtils.getTarget(parameters, OpsParams.Origin.load, deployment);
}
}
}