You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2015/10/09 16:38:45 UTC
karaf git commit: [KARAF-4005] Don't relay on KARAF_BASE/KARAF_HOME
to define the root instance
Repository: karaf
Updated Branches:
refs/heads/master cc455cc7c -> 693daef91
[KARAF-4005] Don't relay on KARAF_BASE/KARAF_HOME to define the root instance
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/693daef9
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/693daef9
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/693daef9
Branch: refs/heads/master
Commit: 693daef9186c323808b1236786bc6615e2281b4f
Parents: cc455cc
Author: Jean-Baptiste Onofré <jb...@apache.org>
Authored: Fri Oct 9 16:38:08 2015 +0200
Committer: Jean-Baptiste Onofré <jb...@apache.org>
Committed: Fri Oct 9 16:38:08 2015 +0200
----------------------------------------------------------------------
.../org/apache/karaf/main/InstanceHelper.java | 51 ++++++--------------
1 file changed, 16 insertions(+), 35 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/693daef9/main/src/main/java/org/apache/karaf/main/InstanceHelper.java
----------------------------------------------------------------------
diff --git a/main/src/main/java/org/apache/karaf/main/InstanceHelper.java b/main/src/main/java/org/apache/karaf/main/InstanceHelper.java
index dcbc369..309f1ad 100644
--- a/main/src/main/java/org/apache/karaf/main/InstanceHelper.java
+++ b/main/src/main/java/org/apache/karaf/main/InstanceHelper.java
@@ -43,13 +43,11 @@ public class InstanceHelper {
final String instanceName = System.getProperty("karaf.name");
final String pid = isStartingInstance ? getPid() : "0";
- final boolean isRoot = karafHome.equals(karafBase);
-
if (instanceName != null) {
String storage = System.getProperty("karaf.instances");
if (storage == null) {
throw new Exception("System property 'karaf.instances' is not set. \n" +
- "This property needs to be set to the full path of the instance.properties file.");
+ "This property needs to be set to the full path of the instance.properties file.");
}
File storageFile = new File(storage);
final File propertiesFile = new File(storageFile, "instance.properties");
@@ -87,45 +85,28 @@ public class InstanceHelper {
FileLockUtils.execute(propertiesFile, new FileLockUtils.RunnableWithProperties() {
public void run(Properties props) throws IOException {
if (props.isEmpty()) {
- if (isRoot) {
- props.setProperty("count", "1");
- props.setProperty("item.0.name", instanceName);
- props.setProperty("item.0.loc", karafHome.getAbsolutePath());
- props.setProperty("item.0.pid", pid);
- props.setProperty("item.0.root", "true");
- } else {
- String errMsg = "Child instance " + (isStartingInstance ? "started" : "stopped") + " but no root registered in ";
- throw new IllegalStateException(errMsg + propertiesFile);
-
- }
+ // it's the first instance running, so we consider as root
+ props.setProperty("count", "1");
+ props.setProperty("item.0.name", instanceName);
+ props.setProperty("item.0.loc", karafHome.getAbsolutePath());
+ props.setProperty("item.0.pid", pid);
+ props.setProperty("item.0.root", "true");
} else {
int count = Integer.parseInt(props.getProperty("count"));
- // update root name if karaf.name got updated since the last container start
- if (isRoot) {
- for (int i = 0; i < count; i++) {
- //looking for root instance entry
- boolean root = Boolean.parseBoolean(props.getProperty("item." + i + ".root", "false"));
- if (root) {
- props.setProperty("item." + i + ".name", instanceName);
- props.setProperty("item." + i + ".pid", pid);
- return;
- }
+ for (int i = 0; i < count; i++) {
+ String name = props.getProperty("item." + i + ".name");
+ if (name.equals(instanceName)) {
+ props.setProperty("item." + i + ".pid", pid);
+ return;
}
- throw new IllegalStateException("Unable to find root instance in " + propertiesFile);
- } else {
- for (int i = 0; i < count; i++) {
- String name = props.getProperty("item." + i + ".name");
- if (name.equals(instanceName)) {
- props.setProperty("item." + i + ".pid", pid);
- return;
- }
- }
- throw new IllegalStateException("Unable to find instance '" + instanceName + "'in " + propertiesFile);
}
+ // it's not found, let assume it's the root instance, so 0
+ props.setProperty("item.0.name", instanceName);
+ props.setProperty("item.0.pid", pid);
}
}
}, true);
- }
+ }
} catch (Exception e) {
System.err.println("Unable to update instance pid: " + e.getMessage());
}