use of com.sun.enterprise.config.serverbeans.Server 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 com.sun.enterprise.config.serverbeans.Server 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.Server in project Payara by payara.
the class AbstractListCommandProxy method execute.
@Override
public final void execute(AdminCommandContext context) {
ActionReport actionReport = context.getActionReport();
Properties extraProperties = actionReport.getExtraProperties();
if (extraProperties == null) {
extraProperties = new Properties();
actionReport.setExtraProperties(extraProperties);
}
ActionReport subReport = null;
if (!preInvoke(context, actionReport)) {
commandsExitCode = ActionReport.ExitCode.FAILURE;
return;
}
if (targetUtil.isCluster(target)) {
for (Server serverInst : targetUtil.getInstances(target)) {
try {
subReport = executeInternalCommand(context, serverInst.getName());
break;
} catch (Throwable ex) {
logger.log(Level.INFO, "Got exception: " + ex.toString());
}
}
} else if (target.equals("server")) {
subReport = executeInternalCommand(context, target);
} else {
subReport = executeInternalCommand(context, target);
}
if (subReport != null) {
if (subReport.getExtraProperties() != null && subReport.getExtraProperties().size() > 0)
postInvoke(context, subReport);
else {
if (subReport.getSubActionsReport() != null && subReport.getSubActionsReport().size() > 0 && subReport.getSubActionsReport().get(0).getExtraProperties() != null) {
postInvoke(context, subReport.getSubActionsReport().get(0));
} else {
actionReport.setMessage(subReport.getMessage());
commandsExitCode = subReport.getActionExitCode();
}
}
}
actionReport.setActionExitCode(commandsExitCode);
}
use of com.sun.enterprise.config.serverbeans.Server in project Payara by payara.
the class RegistrationSupport method processResourceRef.
/**
* Examine the MBean to see if it is a ResourceRef that should be manifested under this server,
* and if so, register a JSR 77 MBean for it.
*/
public ObjectName processResourceRef(final ResourceRef ref) {
if (ref == null) {
throw new IllegalArgumentException("resource-ref is null");
}
if (!mServer.getName().equals(ref.getParent(Server.class).getName())) {
cdebug("ResourceRef is not a child of server " + getObjectName(mServer));
return null;
}
// find the referenced resource
Resource res = null;
List<Resource> resources = getDomain().getResources().getResources();
for (Resource resource : resources) {
String name = null;
if (resource instanceof BindableResource) {
name = ((BindableResource) resource).getJndiName();
}
if (resource instanceof Named) {
name = ((Named) resource).getName();
}
if (resource instanceof ResourcePool) {
name = ((ResourcePool) resource).getName();
}
if (name != null && name.equals(ref.getRef()))
res = resource;
}
if (res == null) {
throw new IllegalArgumentException("ResourceRef refers to non-existent resource: " + ref);
}
final String configType = Util.getTypeProp(getObjectName(res));
final Class<J2EEManagedObjectImplBase> implClass = CONFIG_RESOURCE_TYPES.get(configType);
if (implClass == null) {
mLogger.fine("Unrecognized resource type for JSR 77 purposes: " + getObjectName(res));
return null;
}
final Class<J2EEManagedObject> intf = (Class) ClassUtil.getFieldValue(implClass, "INTF");
ObjectName mbean77 = null;
try {
final MetadataImpl meta = new MetadataImpl();
meta.setCorrespondingRef(getObjectName(ref));
meta.setCorrespondingConfig(getObjectName(res));
mbean77 = registerJ2EEChild(mJ2EEServer.objectName(), meta, intf, implClass, Util.getNameProp(getObjectName(res)));
synchronized (mConfigRefTo77) {
mConfigRefTo77.put(getObjectName(ref), mbean77);
}
} catch (final Exception e) {
mLogger.log(Level.INFO, AMXEELoggerInfo.cantRegisterMbean, new Object[] { getObjectName(ref), e });
}
// cdebug( "Registered " + child + " for config resource " + amx.objectName() );
return mbean77;
}
use of com.sun.enterprise.config.serverbeans.Server in project Payara by payara.
the class DatabaseEJBTimerService method memberRemoved.
@Override
public void memberRemoved(MemberEvent event) {
// work out whether we should be attempting to migrate timers
String server = event.getServer();
String group = event.getServerGroup();
String thisServer = serverEnv.getInstanceName();
// check whether the server is any of the same clusters or deployment groups
// as the disappeared server and if so migrate timers
boolean migrate = false;
Cluster forServer = domain.getClusterForInstance(server);
if (forServer != null) {
for (Server instance : forServer.getInstances()) {
if (instance.getName().equals(thisServer)) {
// if I am in the same cluster
migrate = true;
break;
}
}
}
if (!migrate) {
for (DeploymentGroup deploymentGroup : domain.getDeploymentGroupsForInstance(server)) {
for (Server instance : deploymentGroup.getInstances()) {
if (instance.getName().equals(thisServer)) {
// if I am in the same cluster
migrate = true;
break;
}
}
}
}
if (migrate) {
migrateTimers(event.getServer());
}
}
Aggregations