}
}
public String process(AdminCommandContext context) throws Exception {
LoadbalancerReader lbr = null;
if (lbName != null && lbConfigName == null && target == null) {
LoadBalancer lb = LbConfigHelper.getLoadBalancer(domain, lbName);
lbr = LbConfigHelper.getLbReader(domain, appRegistry, lb.getLbConfigName());
} else if (lbConfigName != null && lbName == null && target == null) {
lbr = LbConfigHelper.getLbReader(domain, appRegistry, lbConfigName);
} else if (target != null && lbName == null && lbConfigName == null) {
Set<String> clusters = new HashSet<String>();
clusters.addAll(target);
lbr = new LoadbalancerReaderImpl(domain, appRegistry, clusters, properties);
} else {
String msg = LbLogUtil.getStringManager().getString("ExportHttpLbConfigInvalidArgs");
throw new Exception(msg);
}
if (fileName == null) {
String configName = lbr.getName();
if (configName != null) {
fileName = DEFAULT_LB_XML_FILE_NAME + "." + configName;
} else {
fileName = DEFAULT_LB_XML_FILE_NAME;
}
}
File lbConfigFile = new File(fileName);
if (!lbConfigFile.isAbsolute() && !retrieveFile) {
File loadbalancerDir = new File(env.getInstanceRoot(),
"load-balancer");
if (!loadbalancerDir.exists()) {
loadbalancerDir.mkdir();
}
lbConfigFile = new File(loadbalancerDir, fileName);
}
if (type !=null){
if(!(type.equals("otd") || type.equals("apache"))){
String msg = LbLogUtil.getStringManager().getString(
"InvalidType");
throw new Exception(msg);
}
File tmpLbWorkerFile = null;
if (retrieveFile) {
if (type.equals("apache")) {
tmpLbWorkerFile = File.createTempFile("worker", ".properties");
} else {
tmpLbWorkerFile = File.createTempFile("otd", ".properties");
}
tmpLbWorkerFile.deleteOnExit();
} else {
if (lbConfigFile.exists()) {
String msg = LbLogUtil.getStringManager().getString(
"FileExists", lbConfigFile.getPath());
throw new Exception(msg);
}
if (!(lbConfigFile.getParentFile().exists())) {
String msg = LbLogUtil.getStringManager().getString(
"ParentFileMissing", lbConfigFile.getParent());
throw new Exception(msg);
}
tmpLbWorkerFile = lbConfigFile;
}
FileOutputStream fo = null;
try {
fo = new FileOutputStream(tmpLbWorkerFile);
if (type.equals("apache")) {
LbConfigHelper.exportWorkerProperties(lbr, fo);
} else {
LbConfigHelper.exportOtdProperties(lbr, fo);
}
if (retrieveFile) {
retrieveLbConfig(context, lbConfigFile, tmpLbWorkerFile);
}
LbConfig lbConfig = lbr.getLbConfig();
//Check for the case when lbtargets are provided
//In such a case, lbconfig will be null
if(lbConfig != null){
lbConfig.setLastExported();
}
String msg = LbLogUtil.getStringManager().getString(
"GeneratedFileLocation", lbConfigFile.toString());
return msg;
} finally {
if (fo != null) {
fo.close();
fo = null;
}
}
} else {
File tmpLbXmlFile = null;
if (retrieveFile) {
tmpLbXmlFile = File.createTempFile("load-balancer", ".xml");
tmpLbXmlFile.deleteOnExit();
} else {
if (lbConfigFile.exists()) {
String msg = LbLogUtil.getStringManager().getString(
"FileExists", lbConfigFile.getPath());
throw new Exception(msg);
}
if (!(lbConfigFile.getParentFile().exists())) {
String msg = LbLogUtil.getStringManager().getString(
"ParentFileMissing", lbConfigFile.getParent());
throw new Exception(msg);
}
tmpLbXmlFile = lbConfigFile;
}
FileOutputStream fo = null;
try {
fo = new FileOutputStream(tmpLbXmlFile);
LbConfigHelper.exportXml(lbr, fo);
if (retrieveFile) {
retrieveLbConfig(context, lbConfigFile, tmpLbXmlFile);
}
LbConfig lbConfig = lbr.getLbConfig();
//Check for the case when lbtargets are provided
//In such a case, lbconfig will be null
if(lbConfig != null){
lbConfig.setLastExported();
}