use of com.sun.enterprise.config.serverbeans.ApplicationRef 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();
}
}
use of com.sun.enterprise.config.serverbeans.ApplicationRef in project Payara by payara.
the class ApplicationConfigListener method transactionCommited.
public void transactionCommited(final List<PropertyChangeEvent> changes) {
boolean isUpdatingAttribute = true;
for (PropertyChangeEvent event : changes) {
Object oldValue = event.getOldValue();
Object newValue = event.getNewValue();
if (event.getSource() instanceof Applications) {
if (event.getPropertyName().equals(ServerTags.APPLICATION)) {
if (oldValue == null || newValue == null) {
// we are adding/removing application element here
// and updating existing attribute
isUpdatingAttribute = false;
break;
}
}
} else if (event.getSource() instanceof Server || event.getSource() instanceof Cluster) {
if (event.getPropertyName().equals(ServerTags.APPLICATION_REF)) {
if (oldValue == null || newValue == null) {
// we are adding/removing application-ref element here
// and updating existing attribute
isUpdatingAttribute = false;
break;
}
}
}
}
if (!isUpdatingAttribute) {
// skip the config listener
return;
}
for (PropertyChangeEvent event : changes) {
if (event.getSource() instanceof Application || event.getSource() instanceof ApplicationRef || event.getSource() instanceof Property) {
Object oldValue = event.getOldValue();
Object newValue = event.getNewValue();
String propertyName = null;
if (oldValue != null && newValue != null && oldValue instanceof String && newValue instanceof String && !((String) oldValue).equals((String) newValue)) {
// if it's an attribute change of the application
// element or application-ref element
Object parent = event.getSource();
String appName = null;
if (parent instanceof Application) {
appName = ((Application) parent).getName();
propertyName = event.getPropertyName();
} else if (parent instanceof ApplicationRef) {
appName = ((ApplicationRef) parent).getRef();
propertyName = event.getPropertyName();
} else if (parent instanceof Property) {
appName = ((Property) parent).getParent(Application.class).getName();
propertyName = ((Property) parent).getName();
}
// anything
if (applications.getApplication(appName) == null) {
return;
}
if (ServerTags.ENABLED.equals(propertyName)) {
// enable or disable application accordingly
handleAppEnableChange(event.getSource(), appName, Boolean.valueOf((String) newValue));
} else if (ServerTags.CONTEXT_ROOT.equals(propertyName) || ServerTags.VIRTUAL_SERVERS.equals(propertyName) || ServerTags.AVAILABILITY_ENABLED.equals(propertyName) || ServerTags.CDI_DEV_MODE_ENABLED_PROP.equals(propertyName)) {
// for other changes, reload the application
handleOtherAppConfigChanges(event.getSource(), appName);
}
}
}
}
}
use of com.sun.enterprise.config.serverbeans.ApplicationRef in project Payara by payara.
the class ApplicationConfigListener method enableApplication.
private void enableApplication(String appName) {
Application app = applications.getApplication(appName);
ApplicationRef appRef = domain.getApplicationRefInServer(server.getName(), appName);
// by the current server instance, do not load
if (app == null || appRef == null) {
return;
}
// if the application is not in enable state, do not load
if (!deployment.isAppEnabled(app)) {
return;
}
ApplicationInfo appInfo = appRegistry.get(appName);
if (appInfo == null || appInfo.isLoaded()) {
return;
}
long operationStartTime = Calendar.getInstance().getTimeInMillis();
try {
ActionReport report = new HTMLActionReporter();
deployment.enable(server.getName(), app, appRef, report, logger);
if (report.getActionExitCode().equals(ActionReport.ExitCode.SUCCESS)) {
logger.log(Level.INFO, KernelLoggerInfo.loadingApplicationTime, new Object[] { appName, (Calendar.getInstance().getTimeInMillis() - operationStartTime) });
} else if (report.getActionExitCode().equals(ActionReport.ExitCode.WARNING)) {
logger.log(Level.WARNING, KernelLoggerInfo.loadingApplicationWarning, new Object[] { appName, report.getMessage() });
} else if (report.getActionExitCode().equals(ActionReport.ExitCode.FAILURE)) {
throw new Exception(report.getMessage());
}
} catch (Exception e) {
logger.log(Level.SEVERE, KernelLoggerInfo.loadingApplicationErrorEnable, e);
throw new RuntimeException(e);
}
}
Aggregations