String dcrFile = file.getName();
// check if dcr file is already set
String dcrNewFile = null;
ConvergedLbConfigs clbConfigs = null;
ConvergedLbConfig clbConfig = null;
try {
clbConfigs = getConvergedLbConfigs();
if (clbConfigs == null) {
String msg = _strMgr.getString("NoLbConfigsElement");
throw new MBeanException(new ConfigException(msg));
}
clbConfig = clbConfigs.getConvergedLbConfigByName(clbConfigName);
if (clbConfig == null) {
String msg = _strMgr.getString("InvalidLbConfigName", clbConfigName);
throw new MBeanException(new ConfigException(msg));
}
MBeanServer mbs = AdminService.getAdminService().getAdminContext().getMBeanServer();
String[] types = new String[] {(new String[]{}).getClass().getName()};
// Get the value of config-file
Object[] returnValues = (Object[])mbs.invoke(
new ObjectName("com.sun.appserv:name=dotted-name-get-set,type=dotted-name-support"),
"dottedNameGet",
new Object[] {new String[] {"domain.converged-lb-configs." + clbConfigName + ".converged-lb-policy.dcr-file"}},
types);
Attribute attr = (Attribute) returnValues[0];
String dcrOldFile = (String) attr.getValue();
dcrNewFile = dcrFile;
if (dcrOldFile == null || (dcrOldFile != null && dcrOldFile.equals("")))
dcrOldFile = dcrFile;
String dcrOldFileWOVersion = null;
if (dcrOldFile.lastIndexOf(".v") != -1) {
int versionNumPos = dcrOldFile.lastIndexOf(".v");
dcrOldFileWOVersion = dcrOldFile.substring(0, versionNumPos);
} else
dcrOldFileWOVersion = dcrOldFile;
String iRoot = System.getProperty(SystemPropertyConstants.INSTANCE_ROOT_PROPERTY);
String sDcrOldFile = iRoot + File.separator + PEFileLayout.CONFIG_DIR + File.separator + dcrFile;
File oldFileName = new File(sDcrOldFile);
Object[] configsUsingCLBConfig = getConfigsUsingCLBConfig(clbConfigName);
// If clb config is not used by any CLB,
// do not copy the dcr file from the config directory to cluster config
if (isClbCfgUsed(clbConfigName)) {
if (dcrOldFileWOVersion.equals(dcrFile)) {
// Following gets executed when the uploaded dcr file name is same as previous dcr file name
dcrNewFile = ClbAdminEventHelper.getConfigFileNewValue(dcrOldFile);
try {
if (configsUsingCLBConfig != null) {
for (int i=0; i < configsUsingCLBConfig.length; i++) {
// Following copies the dcr file from config directory to config/<cluster-specific-config> directory
String sDcrNewFile = iRoot + File.separator + PEFileLayout.CONFIG_DIR + File.separator + configsUsingCLBConfig[i]
+ File.separator + dcrNewFile;
File newFileName = new File(sDcrNewFile);
FileUtils.copy(oldFileName, newFileName);
// Following deletes the dcr file under config/<cluster-specific-config> directory
// Do not delete the old dcr files if debug is set as true
if (!ClbAdminEventHelper.isClbDebug()) {
String tmp = iRoot + File.separator + PEFileLayout.CONFIG_DIR + File.separator + configsUsingCLBConfig[i]
+ File.separator + dcrOldFile;
File tmpFile = new File(tmp);
if (tmpFile.exists())
tmpFile.delete();
}
}
}
} catch (Exception e) {
throw new MBeanException(e);
}
} else {
// Following gets executed when the uploaded dcr file name is different from previous dcr file name
if (configsUsingCLBConfig != null) {
for (int i=0; i < configsUsingCLBConfig.length; i++) {
String sDcrNewFile = iRoot + File.separator + PEFileLayout.CONFIG_DIR + File.separator + configsUsingCLBConfig[i]
+ File.separator + dcrNewFile;
File newFileName = new File(sDcrNewFile);
FileUtils.copy(oldFileName, newFileName);
// Following deletes the dcr file under config/<cluster-specific-config> directory
// Do not delete the old dcr files if debug is set as true
if (!ClbAdminEventHelper.isClbDebug()) {
String tmp = iRoot + File.separator + PEFileLayout.CONFIG_DIR + File.separator + configsUsingCLBConfig[i]
+ File.separator + dcrOldFile;
File tmpFile = new File(tmp);
if (tmpFile.exists())
tmpFile.delete();
}
}
}
}
// Following deletes the dcr file under the domains/domain/config directory
// sDcrOldFile = iRoot + File.separator + PEFileLayout.CONFIG_DIR + File.separator + dcrFile;
// File tmpFile = new File(sDcrOldFile);
if (oldFileName.exists())
oldFileName.delete();
}
} catch (Exception e) {
throw new MBeanException(e);
}
ConvergedLbPolicy clbPolicy = clbConfig.getConvergedLbPolicy();
clbPolicy.setDcrFile(dcrNewFile);
}