public void deleteSystemProperty(String propertyName, String targetName)
throws ConfigException
{
try {
final ConfigContext configContext = getConfigContext();
final Target target = TargetBuilder.INSTANCE.createTarget(VALID_TYPES, targetName,
configContext);
if (target.getType().equals(TargetType.DOMAIN)) {
//create domain property
final Domain domain = ConfigAPIHelper.getDomainConfigBean(configContext);
final SystemProperty sysProp = domain.getSystemPropertyByName(propertyName);
//Ensure that the property specified exists
if (sysProp == null) {
throw new ConfigException(_strMgr.getString("propertyDoesNotExist",
propertyName, target.getName()));
}
//Remove the property
domain.removeSystemProperty(sysProp, OVERWRITE);
} else if (target.getType().equals(TargetType.CONFIG)){
//create configuration property
final Config config = ConfigAPIHelper.getConfigByName(configContext,
target.getName());
final SystemProperty sysProp = config.getSystemPropertyByName(propertyName);
//Ensure that the property specified exists
if (sysProp == null) {
throw new ConfigException(_strMgr.getString("propertyDoesNotExist",
propertyName, target.getName()));
}
//Remove the property
config.removeSystemProperty(sysProp, OVERWRITE);
} else if (target.getType().equals(TargetType.CLUSTER)) {
//create instance property
final Cluster cluster = ClusterHelper.getClusterByName(configContext,
target.getName());
final SystemProperty sysProp = cluster.getSystemPropertyByName(propertyName);
//Ensure that the property specified exists
if (sysProp == null) {
throw new ConfigException(_strMgr.getString("propertyDoesNotExist",
propertyName, target.getName()));
}
//Remove the property
cluster.removeSystemProperty(sysProp, OVERWRITE);
} else if (target.getType().equals(TargetType.SERVER) ||
target.getType().equals(TargetType.DAS)) {
//create instance property
final Server server = ServerHelper.getServerByName(configContext, target.getName());
final SystemProperty sysProp = server.getSystemPropertyByName(propertyName);
//Ensure that the property specified exists
if (sysProp == null) {
throw new ConfigException(_strMgr.getString("propertyDoesNotExist",
propertyName, target.getName()));
}
SystemProperty removedProp = new SystemProperty();
removedProp.setName(sysProp.getName());
removedProp.setValue(sysProp.getValue());
//Remove the property
server.removeSystemProperty(sysProp, OVERWRITE);
/*
*Fix for bug 6303353
*We do not have to check if the system-property being deleted in this server-instance
*is also being defined in another instance (on same machine).
*Ideally we want to check if this system-property is being referenced in any of
*the attributes in the associated config, and this is the only system-property that exists
*to specify that value (not even in the parent config). But this would be an extensive search
*to go through the whole config and the attributes of all elements in there, which isn't really
*worth, when you have to just delete a system property.
//Check for a port conflict after modifying server. If a port conflict occurs,
//we "rollback" the addition of the system properties.
try {
PortConflictCheckerConfigBean portChecker = getPortConflictCheckerConfigBean();
ServersConfigBean scb = getServersConfigBean();
portChecker.checkForPortConflicts(server, null,
scb.isRunning(server.getName()));
} catch (Exception ex2) {
server.addSystemProperty(removedProp, OVERWRITE);
//We do not want to propagate the PortInUseException up. It is a protected
//class used for internal use only
if (ex2 instanceof PortInUseException) {
throw new ConfigException(ex2.getMessage());
} else {
throw (ex2);
}
}
*/
} else {
//create node agent property. Shouldnt happen.
throw new ConfigException(_strMgr.getString("invalidPropertyTarget",
target.getName()));
}
//FIXTHIS: Not sure why we have to intentionally flush here. The changes get written to
//disk, but the runtime config context does not get updated!!! This is probably due to
//the fact that the config change was not handled and the server thinks it needs to
//restart