From 6bf03f7dbbd389bd4ce5e91637a30553cad94954 Mon Sep 17 00:00:00 2001 From: alaskowski <alaskowski@ethz.ch> Date: Fri, 3 Mar 2023 14:48:48 +0100 Subject: [PATCH] SSDM-13251: switched lib-transactional-file-system to use lib-json library --- .../sis/afsjson/jackson/JsonObjectMapper.java | 33 +++++++++ lib-transactional-file-system/build.gradle | 3 +- lib-transactional-file-system/settings.gradle | 1 + .../afs/manager/TransactionConnection.java | 8 +-- .../sis/afs/manager/TransactionManager.java | 6 +- .../java/ch/ethz/sis/afs/startup/Main.java | 4 +- .../sis/shared/json/JSONObjectMapper.java | 25 ------- .../shared/json/jackson/JSONObjectMapper.java | 31 --------- .../json/jackson/JacksonObjectMapper.java | 69 ------------------- .../src/main/resources/afs-config.properties | 2 +- .../java/ch/ethz/sis/afs/AFSEnvironment.java | 2 +- .../AbstractTransactionConnectionTest.java | 4 +- 12 files changed, 49 insertions(+), 139 deletions(-) create mode 100644 lib-json/source/java/ch/ethz/sis/afsjson/jackson/JsonObjectMapper.java create mode 100644 lib-transactional-file-system/settings.gradle delete mode 100644 lib-transactional-file-system/src/main/java/ch/ethz/sis/shared/json/JSONObjectMapper.java delete mode 100644 lib-transactional-file-system/src/main/java/ch/ethz/sis/shared/json/jackson/JSONObjectMapper.java delete mode 100644 lib-transactional-file-system/src/main/java/ch/ethz/sis/shared/json/jackson/JacksonObjectMapper.java diff --git a/lib-json/source/java/ch/ethz/sis/afsjson/jackson/JsonObjectMapper.java b/lib-json/source/java/ch/ethz/sis/afsjson/jackson/JsonObjectMapper.java new file mode 100644 index 00000000000..c0e74656097 --- /dev/null +++ b/lib-json/source/java/ch/ethz/sis/afsjson/jackson/JsonObjectMapper.java @@ -0,0 +1,33 @@ +/* + * Copyright ETH 2023 Zürich, Scientific IT Services + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package ch.ethz.sis.afsjson.jackson; + +import java.io.InputStream; +import java.nio.charset.Charset; + +public interface JsonObjectMapper { + + Charset getCharset(); + + void setCharset(Charset charset); + + <T> T readValue(InputStream src, Class<T> valueType) throws Exception; + + byte[] writeValue(Object value) throws Exception; + +} diff --git a/lib-transactional-file-system/build.gradle b/lib-transactional-file-system/build.gradle index e9fc6a1dc72..d64c65cbecf 100644 --- a/lib-transactional-file-system/build.gradle +++ b/lib-transactional-file-system/build.gradle @@ -14,7 +14,8 @@ repositories { dependencies { annotationProcessor 'lombok:lombok:1.18.22' - implementation 'lombok:lombok:1.18.22', + implementation project(':lib-json'), + 'lombok:lombok:1.18.22', 'log4j:log4j-api:2.10.0', 'log4j:log4j-core:2.10.0', 'fasterxml:jackson-annotations:2.9.10', diff --git a/lib-transactional-file-system/settings.gradle b/lib-transactional-file-system/settings.gradle new file mode 100644 index 00000000000..048a4c86d15 --- /dev/null +++ b/lib-transactional-file-system/settings.gradle @@ -0,0 +1 @@ +includeFlat 'lib-json' \ No newline at end of file diff --git a/lib-transactional-file-system/src/main/java/ch/ethz/sis/afs/manager/TransactionConnection.java b/lib-transactional-file-system/src/main/java/ch/ethz/sis/afs/manager/TransactionConnection.java index fbb4bea9fe9..6b7780928c1 100644 --- a/lib-transactional-file-system/src/main/java/ch/ethz/sis/afs/manager/TransactionConnection.java +++ b/lib-transactional-file-system/src/main/java/ch/ethz/sis/afs/manager/TransactionConnection.java @@ -22,7 +22,7 @@ import ch.ethz.sis.afs.exception.AFSExceptions; import ch.ethz.sis.afs.api.dto.File; import ch.ethz.sis.afs.manager.operation.*; import ch.ethz.sis.shared.io.IOUtils; -import ch.ethz.sis.shared.json.JSONObjectMapper; +import ch.ethz.sis.afsjson.JsonObjectMapper; import ch.ethz.sis.afs.dto.Lock; import ch.ethz.sis.afs.dto.LockType; @@ -47,7 +47,7 @@ public class TransactionConnection implements TransactionalFileSystem { } private LockManager<UUID, String> lockManager; - private JSONObjectMapper jsonObjectMapper; + private JsonObjectMapper jsonObjectMapper; private Transaction transaction; private State state; private String writeAheadLogRoot; @@ -58,7 +58,7 @@ public class TransactionConnection implements TransactionalFileSystem { * Used only to create new transactions */ TransactionConnection(LockManager<UUID, String> lockManager, - JSONObjectMapper jsonObjectMapper, + JsonObjectMapper jsonObjectMapper, String writeAheadLogRoot, String storageRoot, RecoveredTransactions recoveredTransactions) { @@ -72,7 +72,7 @@ public class TransactionConnection implements TransactionalFileSystem { * Can be used to recover a committed transactions after a crash */ TransactionConnection(LockManager<UUID, String> lockManager, - JSONObjectMapper jsonObjectMapper, + JsonObjectMapper jsonObjectMapper, Transaction transaction) { this.lockManager = lockManager; this.jsonObjectMapper = jsonObjectMapper; diff --git a/lib-transactional-file-system/src/main/java/ch/ethz/sis/afs/manager/TransactionManager.java b/lib-transactional-file-system/src/main/java/ch/ethz/sis/afs/manager/TransactionManager.java index 47820c04c49..a45509625ed 100644 --- a/lib-transactional-file-system/src/main/java/ch/ethz/sis/afs/manager/TransactionManager.java +++ b/lib-transactional-file-system/src/main/java/ch/ethz/sis/afs/manager/TransactionManager.java @@ -17,7 +17,7 @@ package ch.ethz.sis.afs.manager; import ch.ethz.sis.afs.api.dto.File; import ch.ethz.sis.shared.io.IOUtils; -import ch.ethz.sis.shared.json.JSONObjectMapper; +import ch.ethz.sis.afsjson.JsonObjectMapper; import ch.ethz.sis.shared.log.LogManager; import ch.ethz.sis.shared.log.Logger; import ch.ethz.sis.afs.dto.Transaction; @@ -37,12 +37,12 @@ public class TransactionManager { private static final Logger logger = LogManager.getLogger(TransactionManager.class); private LockManager<UUID, String> lockManager; - private JSONObjectMapper jsonObjectMapper; + private JsonObjectMapper jsonObjectMapper; private String writeAheadLogRoot; private String storageRoot; private RecoveredTransactions recoveredTransactions; - public TransactionManager(JSONObjectMapper jsonObjectMapper, + public TransactionManager(JsonObjectMapper jsonObjectMapper, String writeAheadLogRoot, String storageRoot) throws IOException { this.lockManager = new LockManager<>(new PathLockFinder()); diff --git a/lib-transactional-file-system/src/main/java/ch/ethz/sis/afs/startup/Main.java b/lib-transactional-file-system/src/main/java/ch/ethz/sis/afs/startup/Main.java index 3249bb23dba..d0f442d14e9 100644 --- a/lib-transactional-file-system/src/main/java/ch/ethz/sis/afs/startup/Main.java +++ b/lib-transactional-file-system/src/main/java/ch/ethz/sis/afs/startup/Main.java @@ -16,7 +16,7 @@ package ch.ethz.sis.afs.startup; import ch.ethz.sis.afs.manager.TransactionManager; -import ch.ethz.sis.shared.json.JSONObjectMapper; +import ch.ethz.sis.afsjson.JsonObjectMapper; import ch.ethz.sis.shared.log.LogFactory; import ch.ethz.sis.shared.log.LogFactoryFactory; import ch.ethz.sis.shared.log.LogManager; @@ -48,7 +48,7 @@ public class Main LogManager.setLogFactory(logFactory); // - JSONObjectMapper jsonObjectMapper = + JsonObjectMapper jsonObjectMapper = configuration.getSharableInstance(AtomicFileSystemParameter.jsonObjectMapperClass); String writeAheadLogRoot = configuration.getStringProperty(AtomicFileSystemParameter.writeAheadLogRoot); diff --git a/lib-transactional-file-system/src/main/java/ch/ethz/sis/shared/json/JSONObjectMapper.java b/lib-transactional-file-system/src/main/java/ch/ethz/sis/shared/json/JSONObjectMapper.java deleted file mode 100644 index ab3befa85b9..00000000000 --- a/lib-transactional-file-system/src/main/java/ch/ethz/sis/shared/json/JSONObjectMapper.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright ETH 2018 - 2023 Zürich, Scientific IT Services - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package ch.ethz.sis.shared.json; - -import java.io.InputStream; - -public interface JSONObjectMapper { - <T> T readValue(InputStream src, Class<T> valueType) throws Exception; - - byte[] writeValue(Object value) throws Exception; - -} diff --git a/lib-transactional-file-system/src/main/java/ch/ethz/sis/shared/json/jackson/JSONObjectMapper.java b/lib-transactional-file-system/src/main/java/ch/ethz/sis/shared/json/jackson/JSONObjectMapper.java deleted file mode 100644 index 3f2bfcf0673..00000000000 --- a/lib-transactional-file-system/src/main/java/ch/ethz/sis/shared/json/jackson/JSONObjectMapper.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright ETH 2022 - 2023 Zürich, Scientific IT Services - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package ch.ethz.sis.shared.json.jackson; - -import java.io.InputStream; -import java.nio.charset.Charset; - -public interface JSONObjectMapper { - - Charset getCharset(); - - void setCharset(Charset charset); - - <T> T readValue(InputStream src, Class<T> valueType) throws Exception; - - byte[] writeValue(Object value) throws Exception; - -} diff --git a/lib-transactional-file-system/src/main/java/ch/ethz/sis/shared/json/jackson/JacksonObjectMapper.java b/lib-transactional-file-system/src/main/java/ch/ethz/sis/shared/json/jackson/JacksonObjectMapper.java deleted file mode 100644 index 4ec1f9e1f75..00000000000 --- a/lib-transactional-file-system/src/main/java/ch/ethz/sis/shared/json/jackson/JacksonObjectMapper.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright ETH 2018 - 2023 Zürich, Scientific IT Services - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package ch.ethz.sis.shared.json.jackson; - -import ch.ethz.sis.shared.json.JSONObjectMapper; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; -import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; - -import java.io.InputStream; - -public class JacksonObjectMapper implements JSONObjectMapper -{ - // - // Singleton - // - private static final JacksonObjectMapper jacksonObjectMapper; - - static - { - jacksonObjectMapper = new JacksonObjectMapper(); - } - - public static JSONObjectMapper getInstance() - { - return jacksonObjectMapper; - } - - // - // Class implementation - // - - private final ObjectMapper objectMapper; - - public JacksonObjectMapper() - { - objectMapper = new ObjectMapper(); - objectMapper.registerModule(new JavaTimeModule()); // new module, NOT JSR310Module - objectMapper.enable(SerializationFeature.INDENT_OUTPUT); - objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); - objectMapper.enableDefaultTyping(); - } - - @Override - public <T> T readValue(final InputStream src, final Class<T> valueType) throws Exception - { - return objectMapper.readValue(src, valueType); - } - - @Override - public byte[] writeValue(final Object value) throws Exception - { - return objectMapper.writeValueAsBytes(value); - } -} diff --git a/lib-transactional-file-system/src/main/resources/afs-config.properties b/lib-transactional-file-system/src/main/resources/afs-config.properties index 794e68d16b2..29f2cb57ea7 100755 --- a/lib-transactional-file-system/src/main/resources/afs-config.properties +++ b/lib-transactional-file-system/src/main/resources/afs-config.properties @@ -1,5 +1,5 @@ logFactoryClass=ch.ethz.sis.shared.log.log4j2.Log4J2LogFactory -jsonObjectMapperClass=ch.ethz.sis.shared.json.jackson.JacksonObjectMapper +jsonObjectMapperClass=ch.ethz.sis.afsjson.jackson.JacksonObjectMapper logConfigFile=afs-config-log4j2.xml # Where all the transactions information is written until the prepare step # For performance reasons should be on the save volume as the configured storage diff --git a/lib-transactional-file-system/src/test/java/ch/ethz/sis/afs/AFSEnvironment.java b/lib-transactional-file-system/src/test/java/ch/ethz/sis/afs/AFSEnvironment.java index 1d6a3fd97bb..1bded2ba242 100644 --- a/lib-transactional-file-system/src/test/java/ch/ethz/sis/afs/AFSEnvironment.java +++ b/lib-transactional-file-system/src/test/java/ch/ethz/sis/afs/AFSEnvironment.java @@ -15,7 +15,7 @@ */ package ch.ethz.sis.afs; -import ch.ethz.sis.shared.json.jackson.JacksonObjectMapper; +import ch.ethz.sis.afsjson.jackson.JacksonObjectMapper; import ch.ethz.sis.shared.startup.Configuration; import ch.ethz.sis.shared.log.log4j2.Log4J2LogFactory; import ch.ethz.sis.afs.startup.AtomicFileSystemParameter; diff --git a/lib-transactional-file-system/src/test/java/ch/ethz/sis/afs/manager/AbstractTransactionConnectionTest.java b/lib-transactional-file-system/src/test/java/ch/ethz/sis/afs/manager/AbstractTransactionConnectionTest.java index c82068ceee2..c0bd1714f14 100644 --- a/lib-transactional-file-system/src/test/java/ch/ethz/sis/afs/manager/AbstractTransactionConnectionTest.java +++ b/lib-transactional-file-system/src/test/java/ch/ethz/sis/afs/manager/AbstractTransactionConnectionTest.java @@ -17,7 +17,7 @@ package ch.ethz.sis.afs.manager; import ch.ethz.sis.afs.api.dto.File; import ch.ethz.sis.shared.io.IOUtils; -import ch.ethz.sis.shared.json.JSONObjectMapper; +import ch.ethz.sis.afsjson.JsonObjectMapper; import ch.ethz.sis.afs.AFSEnvironment; import ch.ethz.sis.afs.AbstractTest; import ch.ethz.sis.afs.dto.Transaction; @@ -38,7 +38,7 @@ import static ch.ethz.sis.shared.io.IOUtils.setFilePermissions; public abstract class AbstractTransactionConnectionTest extends AbstractTest { - private JSONObjectMapper jsonObjectMapper; + private JsonObjectMapper jsonObjectMapper; private LockManager<UUID, String> lockManager; private TransactionConnection transaction; -- GitLab