*
*/
@Override
public void decorate(AdminCommandContext context, final LbConfig instance) throws TransactionFailure, PropertyVetoException {
Logger logger = LogDomains.getLogger(LbConfig.class, LogDomains.ADMIN_LOGGER);
LocalStringManagerImpl localStrings = new LocalStringManagerImpl(LbConfig.class);
if (config_name == null && target == null) {
String msg = localStrings.getLocalString("RequiredTargetOrConfig", "Neither LB config name nor target specified");
throw new TransactionFailure(msg);
}
// generate lb config name if not specified
if (config_name == null) {
config_name = target + "_LB_CONFIG";
}
LbConfigs lbconfigs = domain.getExtensionByType(LbConfigs.class);
//create load-balancers parent element if it does not exist
if (lbconfigs == null) {
Transaction transaction = new Transaction();
try {
ConfigBeanProxy domainProxy = transaction.enroll(domain);
lbconfigs = domainProxy.createChild(LbConfigs.class);
((Domain) domainProxy).getExtensions().add(lbconfigs);
transaction.commit();
} catch (TransactionFailure ex) {
transaction.rollback();
String msg = localStrings.getLocalString("LbConfigsCreationFailed", "Creation of parent element lb-configs failed");
throw new TransactionFailure(msg, ex);
} catch (RetryableException ex) {
transaction.rollback();
String msg = localStrings.getLocalString("LbConfigsCreationFailed", "Creation of parent element lb-configs failed");
throw new TransactionFailure(msg, ex);
}
}
if (lbconfigs.getLbConfig(config_name) != null) {
String msg = localStrings.getLocalString("LbConfigExists", config_name);
throw new TransactionFailure(msg);
}
instance.setName(config_name);
instance.setResponseTimeoutInSeconds(responsetimeout);
instance.setReloadPollIntervalInSeconds(reloadinterval);
instance.setMonitoringEnabled(monitor==null ? null : monitor.toString());
instance.setRouteCookieEnabled(routecookie==null ? null : routecookie.toString());
instance.setHttpsRouting(httpsrouting==null ? null : httpsrouting.toString());
// creates a reference to the target
if (target != null) {
if (domain.getClusterNamed(target) != null) {
ClusterRef cRef = instance.createChild(ClusterRef.class);
cRef.setRef(target);
instance.getClusterRefOrServerRef().add(cRef);
} else if (domain.isServer(target)) {
ServerRef sRef = instance.createChild(ServerRef.class);
sRef.setRef(target);
instance.getClusterRefOrServerRef().add(sRef);
} else {
String msg = localStrings.getLocalString("InvalidTarget", target);
throw new TransactionFailure(msg);
}
}
// add properties
if (properties != null) {
for (Object propname: properties.keySet()) {
Property newprop = instance.createChild(Property.class);
newprop.setName((String) propname);
newprop.setValue(properties.getProperty((String) propname));
instance.getProperty().add(newprop);
}
}
logger.info(localStrings.getLocalString("http_lb_admin.LbConfigCreated",
"Load balancer configuration {0} created.", config_name));
}