Skip to content

Commit bb659c5

Browse files
committed
source methods and tests
1 parent b602336 commit bb659c5

File tree

20 files changed

+718
-57
lines changed

20 files changed

+718
-57
lines changed

dataline-api/src/main/openapi/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ paths:
222222
tags:
223223
- source_implementation
224224
summary: Get source implementations for workspace
225-
operationId: getSourceImplementationsForWorkspace
225+
operationId: listSourceImplementationsForWorkspace
226226
requestBody:
227227
content:
228228
application/json:

dataline-config-persistence/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
dependencies {
2+
implementation group: 'commons-io', name: 'commons-io', version: '2.7'
3+
24
implementation group: "com.fasterxml.jackson.core", name: "jackson-databind", version: "2.9.8"
35
implementation group: "com.networknt", name: "json-schema-validator", version: "1.0.42"
46

dataline-config-persistence/src/main/java/io/dataline/config/persistence/ConfigPersistenceImpl.java

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,32 @@
1212
import java.util.Optional;
1313
import java.util.Set;
1414
import java.util.stream.Collectors;
15+
import org.apache.commons.io.FileUtils;
1516

1617
// we force all interaction with disk storage to be effectively single threaded.
1718
public class ConfigPersistenceImpl implements ConfigPersistence {
1819
private static final Object lock = new Object();
19-
private static final String CONFIG_STORAGE_ROOT = "data/config/";
20-
private static final String CONFIG_SCHEMA_ROOT = "dataline-config/src/main/resources/json/";
20+
private static final String CONFIG_STORAGE_ROOT = "../data/config/";
21+
private static final String TEST_STORAGE_ROOT = "/tmp/data/config/";
22+
private static final String CONFIG_SCHEMA_ROOT = "../dataline-config/src/main/resources/json/";
2123

2224
private final ObjectMapper objectMapper;
23-
final JsonSchemaValidation jsonSchemaValidation;
25+
private final JsonSchemaValidation jsonSchemaValidation;
26+
private final String storageRoot;
27+
private final boolean testEnv;
2428

25-
public ConfigPersistenceImpl() {
26-
jsonSchemaValidation = JsonSchemaValidation.getInstance();
29+
public static ConfigPersistenceImpl get() {
30+
return new ConfigPersistenceImpl(CONFIG_STORAGE_ROOT, false);
31+
}
32+
33+
public static ConfigPersistenceImpl getTest() {
34+
return new ConfigPersistenceImpl(TEST_STORAGE_ROOT, true);
35+
}
36+
37+
private ConfigPersistenceImpl(String storageRoot, boolean testEnv) {
38+
this.storageRoot = storageRoot;
39+
this.testEnv = testEnv;
40+
jsonSchemaValidation = JsonSchemaValidation.getSingletonInstance();
2741
objectMapper = new ObjectMapper();
2842
}
2943

@@ -70,14 +84,28 @@ public <T> Set<T> getConfigs(PersistenceConfigType persistenceConfigType, Class<
7084
public <T> void writeConfig(
7185
PersistenceConfigType persistenceConfigType, String configId, T config) {
7286
synchronized (lock) {
87+
final String configPath = getConfigPath(persistenceConfigType, configId);
88+
ensureDirectory(getConfigDirectory(persistenceConfigType));
7389
try {
74-
objectMapper.writeValue(new File(getConfigPath(persistenceConfigType, configId)), config);
90+
objectMapper.writeValue(new File(configPath), config);
7591
} catch (IOException e) {
7692
throw new RuntimeException(e);
7793
}
7894
}
7995
}
8096

97+
public void deleteAll() {
98+
if (!testEnv) {
99+
throw new RuntimeException("deleteAll operation is only allowed in test environment");
100+
}
101+
102+
try {
103+
FileUtils.forceDelete(new File(storageRoot));
104+
} catch (IOException e) {
105+
throw new RuntimeException(e);
106+
}
107+
}
108+
81109
private JsonNode getSchema(PersistenceConfigType persistenceConfigType) {
82110
String configSchemaFilename =
83111
standardConfigTypeToConfigSchema(persistenceConfigType).getSchemaFilename();
@@ -99,7 +127,7 @@ private Set<Path> getFiles(PersistenceConfigType persistenceConfigType) {
99127
}
100128

101129
private String getConfigDirectory(PersistenceConfigType persistenceConfigType) {
102-
return String.format("%s/%s", CONFIG_STORAGE_ROOT, persistenceConfigType.toString());
130+
return String.format("%s/%s", storageRoot, persistenceConfigType.toString());
103131
}
104132

105133
private String getConfigPath(PersistenceConfigType persistenceConfigType, String configId) {
@@ -113,8 +141,8 @@ private Set<String> getConfigIds(PersistenceConfigType persistenceConfigType) {
113141
}
114142

115143
private Optional<Path> getFile(PersistenceConfigType persistenceConfigType, String id) {
116-
String configPath = getConfigPath(persistenceConfigType, id);
117-
final Path path = Paths.get(configPath);
144+
ensureDirectory(getConfigDirectory(persistenceConfigType));
145+
final Path path = Paths.get(getConfigPath(persistenceConfigType, id));
118146
if (Files.exists(path)) {
119147
return Optional.of(path);
120148
} else {
@@ -184,7 +212,10 @@ private File getFileOrThrow(PersistenceConfigType persistenceConfigType, String
184212
() ->
185213
new ConfigNotFoundException(
186214
String.format(
187-
"config type: %s id: %s not found", persistenceConfigType, configId)));
215+
"config type: %s id: %s not found in path %s",
216+
persistenceConfigType,
217+
configId,
218+
getConfigPath(persistenceConfigType, configId))));
188219
}
189220

190221
private <T> T fileToPojo(File file, Class<T> clazz) {
@@ -194,4 +225,12 @@ private <T> T fileToPojo(File file, Class<T> clazz) {
194225
throw new RuntimeException(e);
195226
}
196227
}
228+
229+
private void ensureDirectory(String path) {
230+
try {
231+
FileUtils.forceMkdir(new File(path));
232+
} catch (IOException e) {
233+
throw new RuntimeException(e);
234+
}
235+
}
197236
}

dataline-config-persistence/src/main/java/io/dataline/config/persistence/JsonSchemaValidation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class JsonSchemaValidation {
1111

1212
private static final JsonSchemaValidation INSTANCE = new JsonSchemaValidation();
1313

14-
public static JsonSchemaValidation getInstance() {
14+
public static JsonSchemaValidation getSingletonInstance() {
1515
return INSTANCE;
1616
}
1717

dataline-config/src/main/resources/json/SourceConnectionImplementation.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
"$id": "https://github.com/datalineio/dataline/blob/master/dataline-config/src/main/resources/json/SourceConnectionConfiguration.json",
44
"title": "SourceConnectionConfiguration",
55
"description": "information required for connection to a destination.", "type": "object",
6-
"required": ["sourceSpecificationId", "sourceImplementationId", "configuration"],
6+
"required": ["sourceSpecificationId", "sourceImplementationId", "workspaceId","configuration"],
77
"additionalProperties": false,
88
"properties": {
99
"sourceSpecificationId": {
1010
"type": "string",
1111
"format": "uuid"
1212
},
13+
"workspaceId": {
14+
"type": "string",
15+
"format": "uuid"
16+
},
1317
"sourceImplementationId": {
1418
"type": "string",
1519
"format": "uuid"

dataline-server/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ dependencies {
1414
implementation group: "com.fasterxml.jackson.core", name: "jackson-databind", version: "2.9.8"
1515
implementation group: "com.networknt", name: "json-schema-validator", version: "1.0.42"
1616

17+
1718
implementation project(':dataline-api')
1819
implementation project(':dataline-commons')
1920
implementation project(':dataline-config')

dataline-server/src/main/java/io/dataline/server/apis/ConfigurationApi.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class ConfigurationApi implements io.dataline.api.V1Api {
1818
private final SourceImplementationsHandler sourceImplementationsHandler;
1919

2020
public ConfigurationApi() {
21-
ConfigPersistence configPersistence = new ConfigPersistenceImpl();
21+
ConfigPersistence configPersistence = ConfigPersistenceImpl.get();
2222
workspacesHandler = new WorkspacesHandler(configPersistence);
2323
sourcesHandler = new SourcesHandler(configPersistence);
2424
sourceSpecificationsHandler = new SourceSpecificationsHandler(configPersistence);
@@ -69,22 +69,17 @@ public SourceImplementationRead createSourceImplementation(
6969
return sourceImplementationsHandler.createSourceImplementation(sourceImplementationCreate);
7070
}
7171

72-
@Override
73-
public SourceImplementationDiscoverSchemaRead discoverSchemaForSourceImplementation(
74-
@Valid SourceImplementationIdRequestBody sourceImplementationIdRequestBody) {
75-
return null;
76-
}
77-
7872
@Override
7973
public SourceImplementationRead getSourceImplementation(
8074
@Valid SourceImplementationIdRequestBody sourceImplementationIdRequestBody) {
81-
return null;
75+
return sourceImplementationsHandler.getSourceImplementation(sourceImplementationIdRequestBody);
8276
}
8377

8478
@Override
85-
public SourceImplementationReadList getSourceImplementationsForWorkspace(
79+
public SourceImplementationReadList listSourceImplementationsForWorkspace(
8680
@Valid WorkspaceIdRequestBody workspaceIdRequestBody) {
87-
return null;
81+
return sourceImplementationsHandler.listSourceImplementationsForWorkspace(
82+
workspaceIdRequestBody);
8883
}
8984

9085
@Override
@@ -96,6 +91,12 @@ public SourceImplementationTestConnectionRead testConnectionToSourceImplementati
9691
@Override
9792
public SourceImplementationRead updateSourceImplementation(
9893
@Valid SourceImplementationUpdate sourceImplementationUpdate) {
94+
return sourceImplementationsHandler.updateSourceImplementation(sourceImplementationUpdate);
95+
}
96+
97+
@Override
98+
public SourceImplementationDiscoverSchemaRead discoverSchemaForSourceImplementation(
99+
@Valid SourceImplementationIdRequestBody sourceImplementationIdRequestBody) {
99100
return null;
100101
}
101102

dataline-server/src/main/java/io/dataline/server/errors/CatchAllExceptionMapper.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44
import javax.ws.rs.core.Response;
55
import javax.ws.rs.ext.ExceptionMapper;
66
import javax.ws.rs.ext.Provider;
7+
import org.slf4j.Logger;
8+
import org.slf4j.LoggerFactory;
79

810
@Provider
911
public class CatchAllExceptionMapper implements ExceptionMapper<Throwable> {
12+
private static final Logger LOGGER = LoggerFactory.getLogger(CatchAllExceptionMapper.class);
1013

1114
@Override
1215
public Response toResponse(Throwable e) {
16+
LOGGER.debug("catch all exception", e);
1317
return Response.status(500)
1418
.entity(
1519
new ObjectMapper()

dataline-server/src/main/java/io/dataline/server/errors/KnownExceptionMapper.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@
44
import javax.ws.rs.core.Response;
55
import javax.ws.rs.ext.ExceptionMapper;
66
import javax.ws.rs.ext.Provider;
7+
import org.slf4j.Logger;
8+
import org.slf4j.LoggerFactory;
79

810
@Provider
911
public class KnownExceptionMapper implements ExceptionMapper<KnownException> {
12+
private static final Logger LOGGER = LoggerFactory.getLogger(KnownExceptionMapper.class);
1013

1114
@Override
1215
public Response toResponse(KnownException e) {
16+
LOGGER.debug("known exception", e);
1317
return Response.status(e.getHttpCode())
14-
.entity(new ObjectMapper().createObjectNode().put("message: ", e.getMessage()))
18+
.entity(new ObjectMapper().createObjectNode().put("message", e.getMessage()))
1519
.type("application/json")
1620
.build();
1721
}

0 commit comments

Comments
 (0)