Skip to content

Commit e8796a7

Browse files
committed
Add a generic file-storage to modules.
1 parent 98e083a commit e8796a7

File tree

5 files changed

+196
-0
lines changed

5 files changed

+196
-0
lines changed

modules/file-storage/pom.xml

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
6+
<modelVersion>4.0.0</modelVersion>
7+
8+
<parent>
9+
<groupId>org.eclipse.osc</groupId>
10+
<artifactId>modules</artifactId>
11+
<version>1.0.0-SNAPSHOT</version>
12+
<relativePath>../pom.xml</relativePath>
13+
</parent>
14+
15+
<groupId>org.eclipse.osc.modules</groupId>
16+
<artifactId>file-storage</artifactId>
17+
<name>OSC :: Modules :: File Storage</name>
18+
19+
<dependencies>
20+
<dependency>
21+
<groupId>org.projectlombok</groupId>
22+
<artifactId>lombok</artifactId>
23+
<scope>provided</scope>
24+
</dependency>
25+
<dependency>
26+
<groupId>org.apache.karaf.minho</groupId>
27+
<artifactId>minho-boot</artifactId>
28+
</dependency>
29+
<dependency>
30+
<groupId>org.eclipse.osc.modules</groupId>
31+
<artifactId>ocl-loader</artifactId>
32+
<version>${project.version}</version>
33+
</dependency>
34+
<dependency>
35+
<groupId>org.slf4j</groupId>
36+
<artifactId>slf4j-api</artifactId>
37+
</dependency>
38+
39+
<dependency>
40+
<groupId>org.junit.jupiter</groupId>
41+
<artifactId>junit-jupiter-api</artifactId>
42+
<scope>test</scope>
43+
</dependency>
44+
<dependency>
45+
<groupId>org.junit.jupiter</groupId>
46+
<artifactId>junit-jupiter-params</artifactId>
47+
<scope>test</scope>
48+
</dependency>
49+
<dependency>
50+
<groupId>org.junit.jupiter</groupId>
51+
<artifactId>junit-jupiter-engine</artifactId>
52+
<scope>test</scope>
53+
</dependency>
54+
<dependency>
55+
<groupId>org.slf4j</groupId>
56+
<artifactId>slf4j-jdk14</artifactId>
57+
<scope>test</scope>
58+
</dependency>
59+
<dependency>
60+
<groupId>org.eclipse.osc.modules</groupId>
61+
<artifactId>orchestrator</artifactId>
62+
<version>1.0.0-SNAPSHOT</version>
63+
<scope>compile</scope>
64+
</dependency>
65+
<dependency>
66+
<groupId>org.eclipse.osc.modules</groupId>
67+
<artifactId>orchestrator</artifactId>
68+
<version>1.0.0-SNAPSHOT</version>
69+
<scope>compile</scope>
70+
</dependency>
71+
</dependencies>
72+
73+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package org.eclipse.osc.modules.file.storage;
2+
3+
import java.io.File;
4+
import java.io.FileInputStream;
5+
import java.io.FileOutputStream;
6+
import java.io.IOException;
7+
import java.util.Properties;
8+
import java.util.Set;
9+
import lombok.extern.slf4j.Slf4j;
10+
import org.apache.karaf.minho.boot.service.ConfigService;
11+
import org.apache.karaf.minho.boot.service.ServiceRegistry;
12+
import org.apache.karaf.minho.boot.spi.Service;
13+
import org.eclipse.osc.orchestrator.OrchestratorStorage;
14+
15+
@Slf4j
16+
public class FileOrchestratorStorage implements OrchestratorStorage, Service {
17+
18+
public static final String DEFAULT_FILENAME = "orchestrator.properties";
19+
20+
private final Properties properties = new Properties();
21+
private File file = new File(DEFAULT_FILENAME);
22+
23+
@Override
24+
public String name() {
25+
return "file-orchestrator-storage";
26+
}
27+
28+
@Override
29+
public void onRegister(ServiceRegistry serviceRegistry) {
30+
log.info("Registering file orchestrator storage service ...");
31+
ConfigService configService = serviceRegistry.get(ConfigService.class);
32+
file = new File(configService.getProperty("orchestrator.store.filename", DEFAULT_FILENAME));
33+
if (file.exists()) {
34+
try {
35+
try (var stream = new FileInputStream(file)) {
36+
properties.load(stream);
37+
}
38+
} catch (IOException ex) {
39+
throw new IllegalStateException("Read file failed " + file, ex);
40+
}
41+
}
42+
}
43+
44+
@Override
45+
public int priority() {
46+
return 900;
47+
}
48+
49+
@Override
50+
public synchronized void store(String sid) {
51+
properties.put(sid, sid);
52+
save();
53+
}
54+
55+
@Override
56+
public void store(String sid, String pluginName, String key, String value) {
57+
String propertyKey = sid + "__" + pluginName + "__" + key;
58+
properties.put(propertyKey, value);
59+
save();
60+
}
61+
62+
@Override
63+
public String getKey(String sid, String pluginName, String key) {
64+
String propertyKey = sid + "__" + pluginName + "__" + key;
65+
return properties.getProperty(propertyKey, "");
66+
}
67+
68+
@Override
69+
public boolean exists(String sid) {
70+
return properties.containsKey(sid);
71+
}
72+
73+
@Override
74+
public Set<String> services() {
75+
return properties.stringPropertyNames();
76+
}
77+
78+
@Override
79+
public synchronized void remove(String sid) {
80+
properties.remove(sid);
81+
save();
82+
}
83+
84+
private void save() {
85+
try (var stream = new FileOutputStream(file)) {
86+
properties.store(stream, null);
87+
} catch (IOException ex) {
88+
log.warn("Can't save orchestrator state", ex);
89+
}
90+
}
91+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.eclipse.osc.modules.file.storage.FileOrchestratorStorage

modules/pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<module>orchestrator</module>
2222
<module>api</module>
2323
<module>logging</module>
24+
<module>file-storage</module>
2425
</modules>
2526

2627
</project>

runtime/pom.xml

+30
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@
5656
<artifactId>logging</artifactId>
5757
<version>${project.version}</version>
5858
</dependency>
59+
<dependency>
60+
<groupId>org.eclipse.osc.modules</groupId>
61+
<artifactId>file-storage</artifactId>
62+
<version>${project.version}</version>
63+
</dependency>
5964
</dependencies>
6065

6166
<properties>
@@ -152,6 +157,31 @@
152157
</build>
153158

154159
<profiles>
160+
<profile>
161+
<id>file-storage</id>
162+
<dependencies>
163+
<dependency>
164+
<groupId>org.eclipse.osc.modules</groupId>
165+
<artifactId>file-storage</artifactId>
166+
<version>${project.version}</version>
167+
</dependency>
168+
</dependencies>
169+
<properties>
170+
<image.name>osc/osc-file-storage</image.name>
171+
</properties>
172+
<build>
173+
<plugins>
174+
<plugin>
175+
<groupId>org.apache.maven.plugins</groupId>
176+
<artifactId>maven-dependency-plugin</artifactId>
177+
</plugin>
178+
<plugin>
179+
<groupId>com.google.cloud.tools</groupId>
180+
<artifactId>jib-maven-plugin</artifactId>
181+
</plugin>
182+
</plugins>
183+
</build>
184+
</profile>
155185
<profile>
156186
<id>huaweicloud</id>
157187
<dependencies>

0 commit comments

Comments
 (0)