LOGGER.warn("Unable to reload Karaf instance list", e);
}
if (instances.get(cloneName) != null) {
throw new IllegalArgumentException("Instance " + cloneName + " already exists");
}
Instance instance = instances.get(name);
if (instance == null) {
throw new IllegalArgumentException("Instance " + name + " not found");
}
logInfo("Cloning instance %s into %s", printOutput, name, cloneName);
// define the clone instance location
String cloneLocationPath = settings.getLocation() != null ? settings.getLocation() : cloneName;
File cloneLocation = new File(cloneLocationPath);
if (!cloneLocation.isAbsolute()) {
cloneLocation = new File(storageLocation, cloneLocationPath);
}
// copy instance directory
String locationPath = instance.getLocation();
File location = new File(locationPath);
copy(location, cloneLocation);
// create the properties map including the instance name, location, ssh and rmi port numbers
HashMap<String, String> props = new HashMap<String, String>();
props.put(name, cloneName);
props.put(locationPath, cloneLocationPath);
if (settings.getSshPort() > 0)
props.put(new Integer(instance.getSshPort()).toString(), new Integer(settings.getSshPort()).toString());
if (settings.getRmiRegistryPort() > 0)
props.put(new Integer(instance.getRmiRegistryPort()).toString(), new Integer(settings.getRmiRegistryPort()).toString());
if (settings.getRmiServerPort() > 0)
props.put(new Integer(instance.getRmiServerPort()).toString(), new Integer(settings.getRmiServerPort()).toString());
// filtering clone files
filterResource(cloneLocation, "etc/custom.properties", props);
filterResource(cloneLocation, "etc/org.apache.karaf.management.cfg", props);
filterResource(cloneLocation, "etc/org.apache.karaf.shell.cfg", props);
filterResource(cloneLocation, "etc/org.ops4j.pax.logging.cfg", props);
filterResource(cloneLocation, "etc/system.properties", props);
filterResource(cloneLocation, "bin/karaf", props);
filterResource(cloneLocation, "bin/start", props);
filterResource(cloneLocation, "bin/stop", props);
filterResource(cloneLocation, "bin/karaf.bat", props);
filterResource(cloneLocation, "bin/start.bat", props);
filterResource(cloneLocation, "bin/stop.bat", props);
// create and add the clone instance in the registry
String javaOpts = settings.getJavaOpts();
if (javaOpts == null || javaOpts.length() == 0) {
javaOpts = "-server -Xmx512M -Dcom.sun.management.jmxremote";
}
Instance cloneInstance = new InstanceImpl(this, cloneName, cloneLocation.toString(), settings.getJavaOpts());
instances.put(cloneName, cloneInstance);
saveState();
return cloneInstance;
}