Committed by
Gerrit Code Review
Use karaf/OSGi bundle data path for persistence
Change-Id: If5a4eb1fb63ca3455200c29e9981c7a0f2dd044e
Showing
4 changed files
with
19 additions
and
14 deletions
... | @@ -12,16 +12,11 @@ target | ... | @@ -12,16 +12,11 @@ target |
12 | dependency-reduced-pom.xml | 12 | dependency-reduced-pom.xml |
13 | .idea | 13 | .idea |
14 | *.DS_Store | 14 | *.DS_Store |
15 | -localDB | ||
16 | -localDB.* | ||
17 | .buckd | 15 | .buckd |
18 | buck-out | 16 | buck-out |
19 | .buckconfig.local | 17 | .buckconfig.local |
20 | .buckjavaargs* | 18 | .buckjavaargs* |
21 | 19 | ||
22 | -core/store/trivial/data/ | ||
23 | -core/store/apps | ||
24 | -core/store/data | ||
25 | /bin/ | 20 | /bin/ |
26 | 21 | ||
27 | web/gui/src/main/webapp/tests/node_modules | 22 | web/gui/src/main/webapp/tests/node_modules | ... | ... |
... | @@ -46,6 +46,11 @@ | ... | @@ -46,6 +46,11 @@ |
46 | <artifactId>mapdb</artifactId> | 46 | <artifactId>mapdb</artifactId> |
47 | <version>1.0.9</version> | 47 | <version>1.0.9</version> |
48 | </dependency> | 48 | </dependency> |
49 | + | ||
50 | + <dependency> | ||
51 | + <groupId>org.osgi</groupId> | ||
52 | + <artifactId>org.osgi.core</artifactId> | ||
53 | + </dependency> | ||
49 | </dependencies> | 54 | </dependencies> |
50 | 55 | ||
51 | </project> | 56 | </project> | ... | ... |
... | @@ -25,12 +25,13 @@ import org.mapdb.DBMaker; | ... | @@ -25,12 +25,13 @@ import org.mapdb.DBMaker; |
25 | import org.onosproject.persistence.PersistenceService; | 25 | import org.onosproject.persistence.PersistenceService; |
26 | import org.onosproject.persistence.PersistentMapBuilder; | 26 | import org.onosproject.persistence.PersistentMapBuilder; |
27 | import org.onosproject.persistence.PersistentSetBuilder; | 27 | import org.onosproject.persistence.PersistentSetBuilder; |
28 | +import org.osgi.service.component.ComponentContext; | ||
28 | import org.slf4j.Logger; | 29 | import org.slf4j.Logger; |
29 | 30 | ||
31 | +import java.io.File; | ||
30 | import java.io.IOException; | 32 | import java.io.IOException; |
31 | import java.nio.file.Files; | 33 | import java.nio.file.Files; |
32 | import java.nio.file.Path; | 34 | import java.nio.file.Path; |
33 | -import java.nio.file.Paths; | ||
34 | import java.util.Map; | 35 | import java.util.Map; |
35 | import java.util.Set; | 36 | import java.util.Set; |
36 | import java.util.Timer; | 37 | import java.util.Timer; |
... | @@ -48,8 +49,7 @@ import static org.slf4j.LoggerFactory.getLogger; | ... | @@ -48,8 +49,7 @@ import static org.slf4j.LoggerFactory.getLogger; |
48 | @Service | 49 | @Service |
49 | public class PersistenceManager implements PersistenceService { | 50 | public class PersistenceManager implements PersistenceService { |
50 | 51 | ||
51 | - private static final String DATABASE_PATH = "../data/localDB"; | 52 | + private static final String DATABASE_PATH = "localDB"; |
52 | - private static final String ENCLOSING_FOLDER = "../data"; | ||
53 | 53 | ||
54 | static final String MAP_PREFIX = "map:"; | 54 | static final String MAP_PREFIX = "map:"; |
55 | 55 | ||
... | @@ -66,15 +66,18 @@ public class PersistenceManager implements PersistenceService { | ... | @@ -66,15 +66,18 @@ public class PersistenceManager implements PersistenceService { |
66 | private final CommitTask commitTask = new CommitTask(); | 66 | private final CommitTask commitTask = new CommitTask(); |
67 | 67 | ||
68 | @Activate | 68 | @Activate |
69 | - public void activate() { | 69 | + public void activate(ComponentContext context) { |
70 | timer = new Timer(); | 70 | timer = new Timer(); |
71 | - Path dbPath = Paths.get(DATABASE_PATH); | 71 | + // bundle's persistent storage area directory |
72 | - Path dbFolderPath = Paths.get(ENCLOSING_FOLDER); | 72 | + File dbFolderPath = context.getBundleContext().getDataFile(""); |
73 | + Path dbPath = dbFolderPath.toPath().resolve(DATABASE_PATH); | ||
74 | + log.debug("dbPath: {}", dbPath); | ||
75 | + | ||
73 | //Make sure the directory exists, if it does not, make it. | 76 | //Make sure the directory exists, if it does not, make it. |
74 | - if (!dbFolderPath.toFile().isDirectory()) { | 77 | + if (!dbFolderPath.isDirectory()) { |
75 | log.info("The specified folder location for the database did not exist and will be created."); | 78 | log.info("The specified folder location for the database did not exist and will be created."); |
76 | try { | 79 | try { |
77 | - Files.createDirectories(dbFolderPath); | 80 | + Files.createDirectories(dbFolderPath.toPath()); |
78 | } catch (IOException e) { | 81 | } catch (IOException e) { |
79 | log.error("Could not create the required folder for the database."); | 82 | log.error("Could not create the required folder for the database."); |
80 | throw new PersistenceException("Database folder could not be created."); | 83 | throw new PersistenceException("Database folder could not be created."); |
... | @@ -123,11 +126,13 @@ public class PersistenceManager implements PersistenceService { | ... | @@ -123,11 +126,13 @@ public class PersistenceManager implements PersistenceService { |
123 | log.info("Stopped"); | 126 | log.info("Stopped"); |
124 | } | 127 | } |
125 | 128 | ||
129 | + @Override | ||
126 | public <K, V> PersistentMapBuilder<K, V> persistentMapBuilder() { | 130 | public <K, V> PersistentMapBuilder<K, V> persistentMapBuilder() { |
127 | checkPermission(PERSISTENCE_WRITE); | 131 | checkPermission(PERSISTENCE_WRITE); |
128 | return new DefaultPersistentMapBuilder<>(localDB); | 132 | return new DefaultPersistentMapBuilder<>(localDB); |
129 | } | 133 | } |
130 | 134 | ||
135 | + @Override | ||
131 | public <E> PersistentSetBuilder<E> persistentSetBuilder() { | 136 | public <E> PersistentSetBuilder<E> persistentSetBuilder() { |
132 | checkPermission(PERSISTENCE_WRITE); | 137 | checkPermission(PERSISTENCE_WRITE); |
133 | return new DefaultPersistentSetBuilder<>(localDB); | 138 | return new DefaultPersistentSetBuilder<>(localDB); | ... | ... |
... | @@ -47,7 +47,7 @@ fi | ... | @@ -47,7 +47,7 @@ fi |
47 | # If clean option was specified, wipe-out existing installation | 47 | # If clean option was specified, wipe-out existing installation |
48 | if [ "$CLEAN" = "true" ]; then | 48 | if [ "$CLEAN" = "true" ]; then |
49 | echo "Removing existing ONOS Karaf, apps, data and config directories..." | 49 | echo "Removing existing ONOS Karaf, apps, data and config directories..." |
50 | - [ -d $KARAF_ROOT ] && rm -fr $KARAF_ROOT $STAGE/apps $STAGE/data $STAGE/config | 50 | + [ -d $KARAF_ROOT ] && rm -fr $KARAF_ROOT $KARAF_ROOT/data $STAGE/apps $STAGE/data $STAGE/config |
51 | fi | 51 | fi |
52 | 52 | ||
53 | # If IP was not given, nor configured attempt to use ONOS_NIC env. variable | 53 | # If IP was not given, nor configured attempt to use ONOS_NIC env. variable | ... | ... |
-
Please register or login to post a comment