private ServerEnvironment env;
@Override
public void decorate(AdminCommandContext context, Servers parent, final Server child) throws PropertyVetoException, TransactionFailure {
final Logger logger = LogDomains.getLogger(Server.class, LogDomains.ADMIN_LOGGER);
LocalStringManagerImpl localStrings = new LocalStringManagerImpl(Server.class);
final ActionReport report = context.getActionReport();
Transaction t = Transaction.getTransaction(parent);
Cluster cluster = domain.getClusterForInstance(child.getName());
boolean isStandAlone = cluster == null ? true : false;
/* setup supplemental */
if (!isStandAlone && env.isDas()) {
context.getActionReport().
setResultType(String.class, cluster.getName());
}
if (isStandAlone) { // remove config <instance>-config
String instanceConfig = child.getConfigRef();
final Config config = configs.getConfigByName(instanceConfig);
// bnevins June 2010
// don't delete the config is someone else holds a reference to it!
if (config != null && domain.getReferenceContainersOf(config).size() > 1) {
return;
}
// bnevins September 30, 2010
// don't delete the config if it wasn't auto-generated.
final String autoGeneratedName = child.getName() + "-config";
if (!autoGeneratedName.equals(instanceConfig))
return;
try {
if (config != null) {
File configConfigDir = new File(env.getConfigDirPath(), config.getName());
FileUtils.whack(configConfigDir);
}
}
catch (Exception e) {
// no big deal - just ignore
}
try {
if (t != null) {
Configs c = t.enroll(configs);
List<Config> configList = c.getConfig();
configList.remove(config);
}
}
catch (TransactionFailure ex) {
logger.log(Level.SEVERE,
localStrings.getLocalString("deleteConfigFailed",
"Unable to remove config {0}", instanceConfig), ex);
String msg = ex.getMessage() != null ? ex.getMessage()
: localStrings.getLocalString("deleteConfigFailed",
"Unable to remove config {0}", instanceConfig);
report.setMessage(msg);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(ex);
throw ex;
}
}
else { // remove server-ref from cluster
final String instanceName = child.getName();
if (t != null) {
try {
Cluster c = t.enroll(cluster);
List<ServerRef> serverRefList = c.getServerRef();
ServerRef serverRef = null;
for (ServerRef sr : serverRefList) {
if (sr.getRef().equals(instanceName)) {
serverRef = sr;
break;
}
}
if (serverRef != null) {
serverRefList.remove(serverRef);
}
}
catch (TransactionFailure ex) {
logger.log(Level.SEVERE,
localStrings.getLocalString("deleteServerRefFailed",
"Unable to remove server-ref {0} from cluster {1}", instanceName, cluster.getName()), ex);
String msg = ex.getMessage() != null ? ex.getMessage()
: localStrings.getLocalString("deleteServerRefFailed",
"Unable to remove server-ref {0} from cluster {1}", instanceName, cluster.getName());
report.setMessage(msg);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(ex);
throw ex;