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 0000000000000000000000000000000000000000..c0e74656097b7ec34f8181579f79c1cbc94b2336 --- /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 e9fc6a1dc7286f834adbd59fc556e30c349d190f..d64c65cbecff7d747737f62088d3990bea341472 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 0000000000000000000000000000000000000000..048a4c86d15e4deac0dbf45119c319fcf29fc615 --- /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 fbb4bea9fe957ab126e07658505617b27bf67a55..6b7780928c1f3499ba70e06ef74a982b3ef54859 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 47820c04c4987d0fb619df720d2b136e2703f287..a45509625ed372b12c3f74aea4d955241aece9f5 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 3249bb23dba457bb9b9fed85fcd626b0d5cbe24b..d0f442d14e91bbd36c7e6d83a975d44b4b57da95 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 ab3befa85b9dce77ae5bf607c6c50b8cab88ec2c..0000000000000000000000000000000000000000 --- 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 3f2bfcf067304029df9ba71ada88a7328345aed2..0000000000000000000000000000000000000000 --- 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 4ec1f9e1f75bb46437670c2e073bb6b0caf73eb7..0000000000000000000000000000000000000000 --- 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 794e68d16b2d5bdbfd5c2b386c14b47262b87d73..29f2cb57ea70e543136d27009381023e34c26a66 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 1d6a3fd97bb81a99ee13c4ec83b66b9f9740a2c5..1bded2ba24265f37ce5f0d8ea87aea373ec15cc5 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 c82068ceee204683e5ae31f7ba212a6b460ca8aa..c0bd1714f14b1c3d1501892a63c07c1f4677e041 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;