@Override
public void decorate(AdminCommandContext context, Clusters parent, Cluster child) throws
PropertyVetoException, TransactionFailure{
Logger logger = ConfigApiLoggerInfo.getLogger();
LocalStringManagerImpl localStrings = new LocalStringManagerImpl(Cluster.class);
final ActionReport report = context.getActionReport();
// check to see if the clustering software is installed
AdminCommand command = runner.getCommand("copy-config", report, context.getLogger());
if (command == null) {
String msg = localStrings.getLocalString("cannot.execute.command",
"Cluster software is not installed");
throw new TransactionFailure(msg);
}
String instanceConfig = child.getConfigRef();
final Config config = configs.getConfigByName(instanceConfig);
Transaction t = Transaction.getTransaction(parent);
//check if the cluster contains instances throw error that cluster
//cannot be deleted
//issue 12172
List<ServerRef> serverRefs = child.getServerRef();
StringBuffer namesOfServers = new StringBuffer();
if (serverRefs.size() > 0) {
for (ServerRef serverRef: serverRefs){
namesOfServers.append(new StringBuffer( serverRef.getRef()).append( ','));
}
final String msg = localStrings.getLocalString(
"Cluster.hasInstances",
"Cluster {0} contains server instances {1} and must not contain any instances"
,child.getName() ,namesOfServers.toString()
);
logger.log(Level.SEVERE, ConfigApiLoggerInfo.clusterMustNotContainInstance,new Object[]{child.getName() ,namesOfServers.toString()});
throw new TransactionFailure(msg);
}
// remove GMS_LISTENER_PORT-clusterName prop from server config
Config serverConfig = configs.getConfigByName("server-config");
String propName = String.format(
"GMS_LISTENER_PORT-%s", child.getName());
SystemProperty gmsProp = serverConfig.getSystemProperty(propName);
if (gmsProp != null && t != null) {
Config c = t.enroll(serverConfig);
List<SystemProperty> propList = c.getSystemProperty();
propList.remove(gmsProp);
}
// check if the config is null or still in use by some other
// ReferenceContainer or is not <cluster-name>-config -- if so just return...
if(config == null || domain.getReferenceContainersOf(config).size() > 1 || !instanceConfig.equals(child.getName() + "-config"))
return;
try {
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, ConfigApiLoggerInfo.deleteConfigFailed, new Object[]{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;