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

PAYARA-2522 Deploying an application to an Instance in a Deployment Group and the Deployment Group causes the application to only target the instance #2501

Merged
merged 4 commits into from Mar 7, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -37,7 +37,7 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
// Portions Copyright [2016-2017] [Payara Foundation and/or its affiliates.]
// Portions Copyright [2016-2018] [Payara Foundation and/or its affiliates.]

package com.sun.enterprise.v3.server;

Expand Down Expand Up @@ -1239,14 +1239,17 @@ public void registerAppInDomainXML(final ApplicationInfo
}
Server servr = domain.getServerNamed(target);
if (servr != 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);
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);
Expand All @@ -1273,10 +1276,13 @@ public void registerAppInDomainXML(final ApplicationInfo
setAppRefAttributes(appRef, deployParams);
((DeploymentGroup)dg_w).getApplicationRef().add(appRef);
for (Server svr : dg.getInstances() ) {
ConfigBeanProxy svr_w = t.enroll(svr);
ApplicationRef appRef2 = svr_w.createChild(ApplicationRef.class);
setAppRefAttributes(appRef2, deployParams);
((Server)svr_w).getApplicationRef().add(appRef2);
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);
}
}
}
}
Expand Down
Expand Up @@ -37,7 +37,7 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
// Portions Copyright [2017] [Payara Foundation and/or its affiliates]
// Portions Copyright [2017-2018] [Payara Foundation and/or its affiliates]
package org.glassfish.deployment.admin;

import com.sun.enterprise.admin.util.ClusterOperationUtil;
Expand All @@ -62,6 +62,7 @@
import org.glassfish.deployment.common.DeploymentContextImpl;
import com.sun.enterprise.util.LocalStringManagerImpl;
import com.sun.enterprise.deploy.shared.ArchiveFactory;
import fish.payara.enterprise.config.serverbeans.DeploymentGroup;
import org.glassfish.api.ActionReport;
import org.glassfish.api.I18n;
import org.glassfish.internal.deployment.Deployment;
Expand Down Expand Up @@ -334,6 +335,28 @@ public void execute(AdminCommandContext context) {
events.send(new Event<DeploymentContext>(Deployment.APPLICATION_PREPARED, deploymentContext), false);
}

final List<String> targets
= new ArrayList<String>(Arrays.asList(commandParams.target.split(",")));

List<String> deploymentTarget = new ArrayList<>();

// If targets contains Deployment Group, check if the application is already deployed to instances in it.
for (String target : targets) {
if (isDeploymentGroup(target)) {
List<Server> instances = domain.getDeploymentGroupNamed(target).getInstances();
for (Server instance : instances) {
List<Application> applications = domain.getApplicationsInTarget(instance.getName());
List<String> listOfApplications = new ArrayList<>();
for (Application application : applications) {
listOfApplications.add(application.getName());
}
if (!listOfApplications.contains(appName)) {
deploymentTarget.add(instance.getName());
}
}
}
}

if (report.getActionExitCode().equals(
ActionReport.ExitCode.SUCCESS)) {
try {
Expand All @@ -347,21 +370,15 @@ public void execute(AdminCommandContext context) {
if (!isVersionExpression && DeploymentUtils.isDASTarget(target)) {
return;
}

final ParameterMap paramMap
= deployment.prepareInstanceDeployParamMap(deploymentContext);

final ParameterMap paramMap =
deployment.prepareInstanceDeployParamMap(deploymentContext);
final List<String> targets =
new ArrayList<String>(Arrays.asList(commandParams.target.split(",")));

ClusterOperationUtil.replicateCommand(
"_deploy",
FailurePolicy.Error,
FailurePolicy.Warn,
FailurePolicy.Ignore,
targets,
context,
paramMap,
habitat);
if (!deploymentTarget.isEmpty()) {
replicateCommand(deploymentTarget, context, paramMap);
} else {
replicateCommand(targets, context, paramMap);
}

} catch(Exception e) {
logger.log(Level.SEVERE, "Error during creating application ref ", e);
Expand All @@ -377,6 +394,31 @@ public void execute(AdminCommandContext context) {
}
}

private void replicateCommand(List<String> targets, AdminCommandContext context, ParameterMap paramMap) {
ClusterOperationUtil.replicateCommand(
"_deploy",
FailurePolicy.Error,
FailurePolicy.Warn,
FailurePolicy.Ignore,
targets,
context,
paramMap,
habitat);
}

private boolean isDeploymentGroup(String target) {
boolean isDeploymentGroup = false;
List<DeploymentGroup> listOfDeploymentGroups = domain.getDeploymentGroups().getDeploymentGroup();

for (DeploymentGroup deploymentGroup : listOfDeploymentGroups) {
if (deploymentGroup.getName().equals(target)) {
isDeploymentGroup = true;
break;
}
}
return isDeploymentGroup;
}

private void handleLifecycleModule(AdminCommandContext context, Transaction t) {
final ActionReport report = context.getActionReport();
final Logger logger = context.getLogger();
Expand Down