diff --git a/.forgejo/workflows/dco.yml b/.forgejo/workflows/dco.yml deleted file mode 100644 index c8aa5e3..0000000 --- a/.forgejo/workflows/dco.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: DCO -on: [pull_request] - -jobs: - dco: - name: DCO - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Setup Go - uses: actions/setup-go@v3 - with: - go-version: '1.21' - - - name: Run commit format checker - uses: https://git.frostfs.info/TrueCloudLab/dco-go@v3 - with: - from: 'origin/${{ github.event.pull_request.base.ref }}' diff --git a/.forgejo/workflows/publish.yml b/.forgejo/workflows/publish.yml deleted file mode 100644 index 7c067ca..0000000 --- a/.forgejo/workflows/publish.yml +++ /dev/null @@ -1,22 +0,0 @@ -on: - push: - workflow_dispatch: - -jobs: - image: - name: Publish Maven packages - runs-on: docker - container: git.frostfs.info/truecloudlab/env:openjdk-11-maven-3.8.6 - steps: - - name: Clone git repo - uses: actions/checkout@v3 - - - name: Publish release packages - run: mvn clean --batch-mode --update-snapshots deploy - if: >- - startsWith(github.ref, 'refs/tags/v') && - (github.event_name == 'workflow_dispatch' || github.event_name == 'push') - env: - MAVEN_REGISTRY: TrueCloudLab - MAVEN_REGISTRY_USER: ${{secrets.MAVEN_REGISTRY_USER}} - MAVEN_REGISTRY_PASSWORD: ${{secrets.MAVEN_REGISTRY_PASSWORD}} diff --git a/.forgejo/workflows/verify-code.yaml b/.forgejo/workflows/verify-code.yaml deleted file mode 100644 index bb54d65..0000000 --- a/.forgejo/workflows/verify-code.yaml +++ /dev/null @@ -1,12 +0,0 @@ -name: Verify code phase -on: [pull_request] - -jobs: - verify-code: - name: Verify code - runs-on: docker - container: git.frostfs.info/truecloudlab/env:openjdk-11-maven-3.8.6 - steps: - - uses: actions/checkout@v3 - - name: Run the Maven verify phase - run: mvn --batch-mode --update-snapshots verify diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 82d73ff..0000000 --- a/.gitignore +++ /dev/null @@ -1,41 +0,0 @@ -### Maven ### -target/ -!.mvn/wrapper/maven-wrapper.jar -!**/src/main/**/target/ -!**/src/test/**/target/ -**/.flattened-pom.xml - -### IntelliJ IDEA ### -.idea/modules.xml -.idea/jarRepositories.xml -.idea/compiler.xml -.idea/libraries/ -.idea/ -*.iws -*.iml -*.ipr - -### Eclipse ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -build/ -!**/src/main/**/build/ -!**/src/test/**/build/ - -### VS Code ### -.vscode/ - -### Mac OS ### -.DS_Store \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index e859051..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,62 +0,0 @@ -# Changelog - -## [0.12.0] - 2025-04-24 - -### Fixed - -- Patch logic -- Patch payload requirements - -## [0.11.0] - 2025-04-23 - -### Added - -- Placement policy vectors - -## [0.10.0] - 2025-03-10 - -### Added - -- Auto deploy to forgejo - -## [0.9.0] - 2025-03-05 - -### Added - -- APE rule deserializer - -## [0.9.0] - 2025-03-05 - -### Added - -- APE rule deserializer - -## [0.8.0] - 2025-03-04 - -### Added - -- Creating client via wallet and password - -## [0.7.0] - 2025-02-20 - -### Added - -- Expanding the parameters for creating a container - -### Fixed - -- Creating a session for working with objects - -## [0.6.0] - 2025-02-13 - -### Added - -- APE rules serializer - -## [0.5.0] - 2025-02-11 - -### Fixed - -- Loading large objects in chunks -- .gitignore -- pom revision \ No newline at end of file diff --git a/CODEOWNERS b/CODEOWNERS deleted file mode 100644 index 0289d53..0000000 --- a/CODEOWNERS +++ /dev/null @@ -1,3 +0,0 @@ -.* @orikik -.forgejo/.* @potyarkin -Makefile @potyarkin diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index 6538ca1..0000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,156 +0,0 @@ -# Contribution guide - -First, thank you for contributing! We love and encourage pull requests from -everyone. Please follow the guidelines: - -- Check the open [issues](https://git.frostfs.info/TrueCloudLab/frostfs-sdk-java/issues) and - [pull requests](https://git.frostfs.info/TrueCloudLab/frostfs-sdk-java/pulls) for existing - discussions. - -- Open an issue first, to discuss a new feature or enhancement. - -- Write tests and make sure the test suite passes locally and on CI. - -- Open a pull request and reference the relevant issue(s). - -- Make sure your commits are logically separated and have good comments - explaining the details of your change. - -- After receiving a feedback, amend your commits or add new ones as - appropriate. - -- **Have fun!** - -## Development Workflow - -Start by forking the `frostfs-sdk-java` repository, make changes in a branch and then -send a pull request. We encourage pull requests to discuss code changes. Here -are the steps in details: - -### Set up your git repository -Fork [FrostFS S3 Gateway -upstream](https://git.frostfs.info/repo/fork/346) source repository -to your own personal repository. Copy the URL of your fork (you will need it for -the `git clone` command below). - -```sh -$ git clone https://git.frostfs.info//frostfs-sdk-java.git -``` - -### Set up git remote as ``upstream`` -```sh -$ cd frostfs-sdk-java -$ git remote add upstream https://git.frostfs.info/TrueCloudLab/frostfs-sdk-java.git -$ git fetch upstream -$ git merge upstream/master -... -``` - -### Create your feature branch -Before making code changes, make sure you create a separate branch for these -changes. Maybe you will find it convenient to name a branch in -`/-` format. - -``` -$ git checkout -b feature/123-something_awesome -``` - -### Test your changes -After your code changes, make sure - -- To add test cases for the new code. -- To run `mvn clean verify` -- To squash your commits into a single commit or a series of logically separated - commits with `git rebase -i`. It's okay to force update your pull request. -- To run `mvn clean package` successfully. - -### Commit changes -After verification, commit your changes. There is a [great -post](https://chris.beams.io/posts/git-commit/) on how to write useful commit -messages. Try following this template: - -``` -[#Issue] Summary - -Description - - - - -``` - -``` -$ git commit -ams '[#123] Add some feature' -``` - -### Push to the branch -Push your locally committed changes to the remote origin (your fork) -``` -$ git push origin feature/123-something_awesome -``` - -### Create a Pull Request -Pull requests can be created via Forgejo. Refer to [this -document](https://docs.codeberg.org/collaborating/pull-requests-and-git-flow/) for -detailed steps on how to create a pull request. After a Pull Request gets peer -reviewed and approved, it will be merged. - -## DCO Sign off - -All authors to the project retain copyright to their work. However, to ensure -that they are only submitting work that they have rights to, we require -everyone to acknowledge this by signing their work. - -Any copyright notices in this repository should specify the authors as "the -contributors". - -To sign your work, just add a line like this at the end of your commit message: - -``` -Signed-off-by: Samii Sakisaka -``` - -This can be easily done with the `--signoff` option to `git commit`. - -By doing this you state that you can certify the following (from [The Developer -Certificate of Origin](https://developercertificate.org/)): - -``` -Developer Certificate of Origin -Version 1.1 - -Copyright (C) 2004, 2006 The Linux Foundation and its contributors. -1 Letterman Drive -Suite D4700 -San Francisco, CA, 94129 - -Everyone is permitted to copy and distribute verbatim copies of this -license document, but changing it is not allowed. - - -Developer's Certificate of Origin 1.1 - -By making a contribution to this project, I certify that: - -(a) The contribution was created in whole or in part by me and I - have the right to submit it under the open source license - indicated in the file; or - -(b) The contribution is based upon previous work that, to the best - of my knowledge, is covered under an appropriate open source - license and I have the right under that license to submit that - work with modifications, whether created in whole or in part - by me, under the same open source license (unless I am - permitted to submit under a different license), as indicated - in the file; or - -(c) The contribution was provided directly to me by some other - person who certified (a), (b) or (c) and I have not modified - it. - -(d) I understand and agree that this project and the contribution - are public and that a record of the contribution (including all - personal information I submit with it, including my sign-off) is - maintained indefinitely and may be redistributed consistent with - this project or the open source license(s) involved. -``` \ No newline at end of file diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 7e04975..0000000 --- a/LICENSE +++ /dev/null @@ -1,74 +0,0 @@ -Apache License -Version 2.0, January 2004 -http://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - -"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. - -"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. - -"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. - -"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. - -"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. - -"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. - -"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). - -"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. - -"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." - -"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: - - (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. - - You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - -To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. - -Copyright 2024 TrueCloudLab - -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. - diff --git a/README.md b/README.md index 991c5fa..7463f9e 100644 --- a/README.md +++ b/README.md @@ -1,164 +1,3 @@ -# frostfs-sdk-java +# WIP area: this repo is just a fork! -Java implementation of FrostFS SDK - -## Prerequisites - -### Get the key for your wallet - -1. Get the address -```bash -cat | jq .accounts[0].address | tr -d '"' -``` - -2. Get the key -```bash -neo-go wallet export -w -d -``` - -## Example usage - -### Container operations - -```java -import info.frostfs.sdk.FrostFSClient; -import info.frostfs.sdk.dto.container.Container; -import info.frostfs.sdk.dto.netmap.PlacementPolicy; -import info.frostfs.sdk.dto.netmap.Replica; -import info.frostfs.sdk.jdo.ClientSettings; -import info.frostfs.sdk.jdo.parameters.CallContext; -import info.frostfs.sdk.jdo.parameters.container.PrmContainerCreate; -import info.frostfs.sdk.jdo.parameters.container.PrmContainerDelete; -import info.frostfs.sdk.jdo.parameters.container.PrmContainerGet; -import info.frostfs.sdk.jdo.parameters.container.PrmContainerGetAll; - -public class ContainerExample { - - public void example() { - var callContext = new CallContext(); - ClientSettings clientSettings = new ClientSettings(, ); - FrostFSClient frostFSClient = new FrostFSClient(clientSettings); - - // Create container - var placementPolicy = new PlacementPolicy(new Replica[]{new Replica(3)}, true, 1); - var prmContainerCreate = new PrmContainerCreate(new Container(placementPolicy)); - var containerId = frostFSClient.createContainer(prmContainerCreate, callContext); - - // Get container - var prmContainerGet = new PrmContainerGet(containerId); - var container = frostFSClient.getContainer(prmContainerGet, callContext); - - // List containers - var containerIds = frostFSClient.listContainers(new PrmContainerGetAll(), callContext); - - // Delete container - var prmContainerDelete = new PrmContainerDelete(containerId); - frostFSClient.deleteContainer(prmContainerDelete, callContext); - } -} -``` - -### Object operations - -```java -import info.frostfs.sdk.dto.object.*; -import info.frostfs.sdk.enums.ObjectType; -import info.frostfs.sdk.jdo.ClientSettings; -import info.frostfs.sdk.jdo.parameters.CallContext; -import info.frostfs.sdk.jdo.parameters.object.*; -import org.apache.commons.lang3.ArrayUtils; - -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; - -import static java.util.Objects.isNull; - -public class ObjectExample { - - public void example() { - CallContext callContext = new CallContext(); - ClientSettings clientSettings = new ClientSettings(, ); - FrostFSClient frostFSClient = new FrostFSClient(clientSettings); - - // Put object - ObjectId objectId; - try (FileInputStream file = new FileInputStream("/path/to/file/cat.jpg")) { - var attribute = new ObjectAttribute("Filename", "cat.jpg"); - var cat = new ObjectHeader(containerId, ObjectType.REGULAR, attribute); - var prmObjectPut = PrmObjectPut.builder().objectHeader(cat).build(); - var writer = frostFSClient.putObject(prmObjectPut, callContext); - - writer.write(file.readAllBytes()); - objectId = writer.complete(); - } catch (IOException e) { - throw new RuntimeException(e); - } - - // Get object - var prmObjectGet = new PrmObjectGet(containerId, oid); - ObjectFrostFS object = frostFSClient.getObject(prmObjectGet, callContext); - - var reader = object.getObjectReader(); - var chunk = reader.readChunk(); - var length = chunk.length; - byte[] buffer = null; - while (length > 0) { - buffer = isNull(buffer) ? chunk : ArrayHelper.concat(buffer, chunk); - - chunk = object.getObjectReader().readChunk(); - length = ArrayUtils.isEmpty(chunk) ? 0 : chunk.length; - } - - try (FileOutputStream fos = new FileOutputStream("/path/to/file/newCat.jpg")) { - fos.write(buffer); - } catch (Exception ignored) { - } - - // Get object header - var prmObjectHeadGet = new PrmObjectHeadGet(containerId, objectId); - var objectHeader = frostFSClient.getObjectHead(prmObjectHeadGet, callContext); - - // Search regular objects - var prmObjectSearch = new PrmObjectSearch(containerId, new ObjectFilter.FilterByRootObject()); - var objectIds = frostFSClient.searchObjects(prmObjectSearch, callContext); - - // Delete object - var prmObjectDelete = new PrmObjectDelete(containerId, objectId); - frostFSClient.deleteObject(prmObjectDelete, callContext); - } -} -``` - -### Pool init - -```java -import info.frostfs.sdk.jdo.ECDsa; -import info.frostfs.sdk.jdo.parameters.CallContext; -import info.frostfs.sdk.jdo.pool.NodeParameters; -import info.frostfs.sdk.jdo.pool.PoolInitParameters; -import info.frostfs.sdk.pool.Pool; - -public class PoolExample { - - public static void example() { - CallContext callContext = new CallContext(); - - //Init - var nodeParam1 = new NodeParameters(1, , 1); - var nodeParam2 = new NodeParameters(1, , 1); - var nodeParam3 = new NodeParameters(1, , 1); - var nodeParam4 = new NodeParameters(1, , 1); - - PoolInitParameters initParameters = new PoolInitParameters(); - initParameters.setKey(new ECDsa()); - initParameters.setNodeParams(new NodeParameters[]{nodeParam1, nodeParam2, nodeParam3, nodeParam4}); - - - Pool pool = new Pool(initParameters); - - //Dial (Required!) - pool.dial(callContext); - } -} -``` \ No newline at end of file +Useful things may be published only in [other branches](../../../branches) diff --git a/checkstyle.xml b/checkstyle.xml deleted file mode 100644 index 1bb24e7..0000000 --- a/checkstyle.xml +++ /dev/null @@ -1,84 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/client/pom.xml b/client/pom.xml deleted file mode 100644 index 2d87b21..0000000 --- a/client/pom.xml +++ /dev/null @@ -1,63 +0,0 @@ - - - 4.0.0 - - info.frostfs.sdk - frostfs-sdk-java - ${revision} - - - client - - - 11 - 11 - UTF-8 - - - - - info.frostfs.sdk - cryptography - ${revision} - - - info.frostfs.sdk - models - ${revision} - - - info.frostfs.sdk - exceptions - ${revision} - - - commons-codec - commons-codec - 1.17.0 - - - - io.prometheus - simpleclient - 0.16.0 - - - io.prometheus - simpleclient_hotspot - 0.16.0 - - - io.prometheus - simpleclient_common - 0.16.0 - - - org.slf4j - slf4j-api - 2.0.16 - - - \ No newline at end of file diff --git a/client/src/main/java/info/frostfs/sdk/FrostFSClient.java b/client/src/main/java/info/frostfs/sdk/FrostFSClient.java deleted file mode 100644 index 4aa685c..0000000 --- a/client/src/main/java/info/frostfs/sdk/FrostFSClient.java +++ /dev/null @@ -1,248 +0,0 @@ -package info.frostfs.sdk; - -import frostfs.accounting.Types; -import info.frostfs.sdk.dto.ape.Chain; -import info.frostfs.sdk.dto.container.Container; -import info.frostfs.sdk.dto.container.ContainerId; -import info.frostfs.sdk.dto.netmap.NetmapSnapshot; -import info.frostfs.sdk.dto.netmap.NodeInfo; -import info.frostfs.sdk.dto.netmap.Version; -import info.frostfs.sdk.dto.object.ObjectFrostFS; -import info.frostfs.sdk.dto.object.ObjectHeader; -import info.frostfs.sdk.dto.object.ObjectId; -import info.frostfs.sdk.dto.session.SessionToken; -import info.frostfs.sdk.exceptions.ProcessFrostFSException; -import info.frostfs.sdk.jdo.ClientEnvironment; -import info.frostfs.sdk.jdo.ClientSettings; -import info.frostfs.sdk.jdo.ECDsa; -import info.frostfs.sdk.jdo.NetworkSettings; -import info.frostfs.sdk.jdo.parameters.CallContext; -import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainAdd; -import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainList; -import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainRemove; -import info.frostfs.sdk.jdo.parameters.container.PrmContainerCreate; -import info.frostfs.sdk.jdo.parameters.container.PrmContainerDelete; -import info.frostfs.sdk.jdo.parameters.container.PrmContainerGet; -import info.frostfs.sdk.jdo.parameters.container.PrmContainerGetAll; -import info.frostfs.sdk.jdo.parameters.object.*; -import info.frostfs.sdk.jdo.parameters.object.patch.PrmObjectPatch; -import info.frostfs.sdk.jdo.parameters.object.patch.PrmRangeGet; -import info.frostfs.sdk.jdo.parameters.object.patch.PrmRangeHashGet; -import info.frostfs.sdk.jdo.parameters.session.PrmSessionCreate; -import info.frostfs.sdk.jdo.result.ObjectHeaderResult; -import info.frostfs.sdk.pool.SessionCache; -import info.frostfs.sdk.pool.WrapperPrm; -import info.frostfs.sdk.services.CommonClient; -import info.frostfs.sdk.services.impl.*; -import info.frostfs.sdk.services.impl.interceptor.Configuration; -import info.frostfs.sdk.services.impl.interceptor.MonitoringClientInterceptor; -import info.frostfs.sdk.services.impl.rwhelper.ObjectWriter; -import info.frostfs.sdk.services.impl.rwhelper.RangeReader; -import info.frostfs.sdk.utils.Validator; -import io.grpc.Channel; -import io.grpc.ClientInterceptors; -import io.grpc.ManagedChannel; -import org.apache.commons.lang3.StringUtils; - -import java.util.List; - -import static info.frostfs.sdk.constants.ErrorConst.VERSION_UNSUPPORTED_TEMPLATE; -import static info.frostfs.sdk.tools.GrpcClient.initGrpcChannel; -import static java.util.Objects.nonNull; - -public class FrostFSClient implements CommonClient { - private static final MonitoringClientInterceptor MONITORING_CLIENT_INTERCEPTOR = - MonitoringClientInterceptor.create(Configuration.allMetrics()); - - private final ContainerClientImpl containerClientImpl; - private final ObjectClientImpl objectClientImpl; - private final ApeManagerClientImpl apeManagerClient; - private final NetmapClientImpl netmapClientImpl; - private final SessionClientImpl sessionClientImpl; - private final ObjectToolsImpl objectToolsImpl; - private final AccountingClientImpl accountingClient; - private final ManagedChannel channel; - - public FrostFSClient(ClientSettings clientSettings) { - Validator.validate(clientSettings); - this.channel = nonNull(clientSettings.getChannel()) - ? clientSettings.getChannel() - : initGrpcChannel(clientSettings); - - var ecdsa = StringUtils.isBlank(clientSettings.getWif()) - ? new ECDsa(clientSettings.getWallet(), clientSettings.getPassword()) - : new ECDsa(clientSettings.getWif()); - Channel interceptChannel = ClientInterceptors.intercept(channel, MONITORING_CLIENT_INTERCEPTOR); - ClientEnvironment clientEnvironment = new ClientEnvironment( - ecdsa, interceptChannel, new Version(), this, new SessionCache(0) - ); - - Validator.validate(clientEnvironment); - - this.containerClientImpl = new ContainerClientImpl(clientEnvironment); - this.objectClientImpl = new ObjectClientImpl(clientEnvironment); - this.apeManagerClient = new ApeManagerClientImpl(clientEnvironment); - this.netmapClientImpl = new NetmapClientImpl(clientEnvironment); - this.sessionClientImpl = new SessionClientImpl(clientEnvironment); - this.objectToolsImpl = new ObjectToolsImpl(clientEnvironment); - this.accountingClient = new AccountingClientImpl(clientEnvironment); - checkFrostFSVersionSupport(clientEnvironment.getVersion()); - } - - public FrostFSClient(WrapperPrm prm, SessionCache cache) { - this.channel = initGrpcChannel(prm.getAddress()); - - Channel interceptChannel = ClientInterceptors.intercept(channel, MONITORING_CLIENT_INTERCEPTOR); - ClientEnvironment clientEnvironment = - new ClientEnvironment(prm.getKey(), interceptChannel, new Version(), this, cache); - - Validator.validate(clientEnvironment); - - this.containerClientImpl = new ContainerClientImpl(clientEnvironment); - this.objectClientImpl = new ObjectClientImpl(clientEnvironment); - this.apeManagerClient = new ApeManagerClientImpl(clientEnvironment); - this.netmapClientImpl = new NetmapClientImpl(clientEnvironment); - this.sessionClientImpl = new SessionClientImpl(clientEnvironment); - this.objectToolsImpl = new ObjectToolsImpl(clientEnvironment); - this.accountingClient = new AccountingClientImpl(clientEnvironment); - checkFrostFSVersionSupport(clientEnvironment.getVersion()); - } - - private void checkFrostFSVersionSupport(Version version) { - var localNodeInfo = netmapClientImpl.getLocalNodeInfo(new CallContext()); - if (!localNodeInfo.getVersion().isSupported(version)) { - throw new ProcessFrostFSException( - String.format(VERSION_UNSUPPORTED_TEMPLATE, localNodeInfo.getVersion()) - ); - } - } - - @Override - public Container getContainer(PrmContainerGet args, CallContext ctx) { - return containerClientImpl.getContainer(args, ctx); - } - - @Override - public List listContainers(PrmContainerGetAll args, CallContext ctx) { - return containerClientImpl.listContainers(args, ctx); - } - - @Override - public ContainerId createContainer(PrmContainerCreate args, CallContext ctx) { - return containerClientImpl.createContainer(args, ctx); - } - - @Override - public void deleteContainer(PrmContainerDelete args, CallContext ctx) { - containerClientImpl.deleteContainer(args, ctx); - } - - @Override - public ObjectHeaderResult getObjectHead(PrmObjectHeadGet args, CallContext ctx) { - return objectClientImpl.getObjectHead(args, ctx); - } - - @Override - public ObjectFrostFS getObject(PrmObjectGet args, CallContext ctx) { - return objectClientImpl.getObject(args, ctx); - } - - @Override - public ObjectWriter putObject(PrmObjectPut args, CallContext ctx) { - return objectClientImpl.putObject(args, ctx); - } - - @Override - public ObjectId putClientCutObject(PrmObjectClientCutPut args, CallContext ctx) { - return objectClientImpl.putClientCutObject(args, ctx); - } - - @Override - public ObjectId putSingleObject(PrmObjectSinglePut args, CallContext ctx) { - return objectClientImpl.putSingleObject(args, ctx); - } - - @Override - public void deleteObject(PrmObjectDelete args, CallContext ctx) { - objectClientImpl.deleteObject(args, ctx); - } - - @Override - public Iterable searchObjects(PrmObjectSearch args, CallContext ctx) { - return objectClientImpl.searchObjects(args, ctx); - } - - @Override - public RangeReader getRange(PrmRangeGet args, CallContext ctx) { - return objectClientImpl.getRange(args, ctx); - } - - @Override - public byte[][] getRangeHash(PrmRangeHashGet args, CallContext ctx) { - return objectClientImpl.getRangeHash(args, ctx); - } - - @Override - public ObjectId patchObject(PrmObjectPatch args, CallContext ctx) { - return objectClientImpl.patchObject(args, ctx); - } - - @Override - public byte[] addChain(PrmApeChainAdd args, CallContext ctx) { - return apeManagerClient.addChain(args, ctx); - } - - @Override - public void removeChain(PrmApeChainRemove args, CallContext ctx) { - apeManagerClient.removeChain(args, ctx); - } - - @Override - public List listChains(PrmApeChainList args, CallContext ctx) { - return apeManagerClient.listChains(args, ctx); - } - - @Override - public NetmapSnapshot getNetmapSnapshot(CallContext ctx) { - return netmapClientImpl.getNetmapSnapshot(ctx); - } - - @Override - public NodeInfo getLocalNodeInfo(CallContext ctx) { - return netmapClientImpl.getLocalNodeInfo(ctx); - } - - @Override - public NetworkSettings getNetworkSettings(CallContext ctx) { - return netmapClientImpl.getNetworkSettings(ctx); - } - - @Override - public SessionToken createSession(PrmSessionCreate args, CallContext ctx) { - return sessionClientImpl.createSession(args, ctx); - } - - public frostfs.session.Types.SessionToken createSessionInternal(PrmSessionCreate args, CallContext ctx) { - return sessionClientImpl.createSessionInternal(args, ctx); - } - - @Override - public ObjectId calculateObjectId(ObjectHeader header) { - return objectToolsImpl.calculateObjectId(header); - } - - @Override - public Types.Decimal getBalance(CallContext ctx) { - return accountingClient.getBalance(ctx); - } - - @Override - public String dial(CallContext ctx) { - accountingClient.getBalance(ctx); - return null; - } - - public void close() { - channel.shutdown(); - } -} diff --git a/client/src/main/java/info/frostfs/sdk/annotations/AtLeastOneIsFilled.java b/client/src/main/java/info/frostfs/sdk/annotations/AtLeastOneIsFilled.java deleted file mode 100644 index e10c4e6..0000000 --- a/client/src/main/java/info/frostfs/sdk/annotations/AtLeastOneIsFilled.java +++ /dev/null @@ -1,14 +0,0 @@ -package info.frostfs.sdk.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE}) -public @interface AtLeastOneIsFilled { - String message() default "At least one of the fields (%s) must be filled in"; - - String[] fields(); -} diff --git a/client/src/main/java/info/frostfs/sdk/annotations/ComplexAtLeastOneIsFilled.java b/client/src/main/java/info/frostfs/sdk/annotations/ComplexAtLeastOneIsFilled.java deleted file mode 100644 index eb3fe48..0000000 --- a/client/src/main/java/info/frostfs/sdk/annotations/ComplexAtLeastOneIsFilled.java +++ /dev/null @@ -1,12 +0,0 @@ -package info.frostfs.sdk.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE}) -public @interface ComplexAtLeastOneIsFilled { - AtLeastOneIsFilled[] value(); -} diff --git a/client/src/main/java/info/frostfs/sdk/annotations/NotBlank.java b/client/src/main/java/info/frostfs/sdk/annotations/NotBlank.java deleted file mode 100644 index 8f8c234..0000000 --- a/client/src/main/java/info/frostfs/sdk/annotations/NotBlank.java +++ /dev/null @@ -1,11 +0,0 @@ -package info.frostfs.sdk.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface NotBlank { -} diff --git a/client/src/main/java/info/frostfs/sdk/annotations/NotNull.java b/client/src/main/java/info/frostfs/sdk/annotations/NotNull.java deleted file mode 100644 index a23bdc4..0000000 --- a/client/src/main/java/info/frostfs/sdk/annotations/NotNull.java +++ /dev/null @@ -1,11 +0,0 @@ -package info.frostfs.sdk.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface NotNull { -} diff --git a/client/src/main/java/info/frostfs/sdk/annotations/Validate.java b/client/src/main/java/info/frostfs/sdk/annotations/Validate.java deleted file mode 100644 index ee412b6..0000000 --- a/client/src/main/java/info/frostfs/sdk/annotations/Validate.java +++ /dev/null @@ -1,11 +0,0 @@ -package info.frostfs.sdk.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface Validate { -} diff --git a/client/src/main/java/info/frostfs/sdk/constants/CryptoConst.java b/client/src/main/java/info/frostfs/sdk/constants/CryptoConst.java deleted file mode 100644 index fd8ef2c..0000000 --- a/client/src/main/java/info/frostfs/sdk/constants/CryptoConst.java +++ /dev/null @@ -1,14 +0,0 @@ -package info.frostfs.sdk.constants; - -public class CryptoConst { - public static final String SIGNATURE_ALGORITHM = "NONEwithECDSAinP1363Format"; - public static final int RFC6979_SIGNATURE_SIZE = 64; - public static final int HASH_SIGNATURE_SIZE = 65; - - public static final int MURMUR_MULTIPLIER = 33; - public static final long LANDAU_PRIME_DIVISOR_64BIT = 0xc4ceb9fe1a85ec53L; - public static final long LANDAU_PRIME_DIVISOR_65BIT = 0xff51afd7ed558ccdL; - - private CryptoConst() { - } -} diff --git a/client/src/main/java/info/frostfs/sdk/constants/PoolConst.java b/client/src/main/java/info/frostfs/sdk/constants/PoolConst.java deleted file mode 100644 index 30d853f..0000000 --- a/client/src/main/java/info/frostfs/sdk/constants/PoolConst.java +++ /dev/null @@ -1,14 +0,0 @@ -package info.frostfs.sdk.constants; - -public class PoolConst { - public static final int DEFAULT_SESSION_TOKEN_EXPIRATION_DURATION = 100; // in epochs - public static final int DEFAULT_ERROR_THRESHOLD = 100; - public static final int DEFAULT_GRACEFUL_CLOSE_ON_SWITCH_TIMEOUT = 10; // Seconds - public static final int DEFAULT_REBALANCE_INTERVAL = 15; // Seconds - public static final int DEFAULT_HEALTHCHECK_TIMEOUT = 4; // Seconds - public static final int DEFAULT_DIAL_TIMEOUT = 5; // Seconds - public static final int DEFAULT_STREAM_TIMEOUT = 10; // Seconds - - private PoolConst() { - } -} diff --git a/client/src/main/java/info/frostfs/sdk/constants/RuleConst.java b/client/src/main/java/info/frostfs/sdk/constants/RuleConst.java deleted file mode 100644 index 322b615..0000000 --- a/client/src/main/java/info/frostfs/sdk/constants/RuleConst.java +++ /dev/null @@ -1,30 +0,0 @@ -package info.frostfs.sdk.constants; - -public class RuleConst { - public static final byte VERSION = 0; - - public static final int BYTE_SIZE = 1; - public static final int U_INT_8_SIZE = BYTE_SIZE; - public static final int BOOL_SIZE = BYTE_SIZE; - - public static final long NULL_SLICE = -1L; - public static final int NULL_SLICE_SIZE = 1; - - public static final byte BYTE_TRUE = 1; - public static final byte BYTE_FALSE = 0; - - // maxSliceLen taken from - // https://github.com/neo-project/neo/blob/38218bbee5bbe8b33cd8f9453465a19381c9a547/src/Neo/IO/Helper.cs#L77 - public static final int MAX_SLICE_LENGTH = 0x1000000; - - public static final int MAX_VAR_INT_LENGTH = 10; - - public static final int CHAIN_MARSHAL_VERSION = 0; - - public static final long OFFSET127 = 0x7f; - public static final long OFFSET128 = 0x80; - public static final int UNSIGNED_SERIALIZE_SIZE = 7; - - private RuleConst() { - } -} diff --git a/client/src/main/java/info/frostfs/sdk/enums/HealthyStatus.java b/client/src/main/java/info/frostfs/sdk/enums/HealthyStatus.java deleted file mode 100644 index f88a8db..0000000 --- a/client/src/main/java/info/frostfs/sdk/enums/HealthyStatus.java +++ /dev/null @@ -1,23 +0,0 @@ -package info.frostfs.sdk.enums; - -public enum HealthyStatus { - // status HEALTHY is set when connection is ready to be used by the pool. - HEALTHY(1), - - // status UNHEALTHY_ON_REQUEST is set when communication after dialing to the - // endpoint is failed due to immediate or accumulated errors, connection is - // available and pool should close it before re-establishing connection once again. - UNHEALTHY_ON_REQUEST(2), - - // status UNHEALTHY_ON_DIAL is set when dialing to the endpoint is failed, - // so there is no connection to the endpoint, and pool should not close it - // before re-establishing connection once again. - UNHEALTHY_ON_DIAL(3), - ; - - public final int value; - - HealthyStatus(int value) { - this.value = value; - } -} diff --git a/client/src/main/java/info/frostfs/sdk/enums/MethodIndex.java b/client/src/main/java/info/frostfs/sdk/enums/MethodIndex.java deleted file mode 100644 index af8f4a5..0000000 --- a/client/src/main/java/info/frostfs/sdk/enums/MethodIndex.java +++ /dev/null @@ -1,29 +0,0 @@ -package info.frostfs.sdk.enums; - -public enum MethodIndex { - METHOD_BALANCE_GET("balanceGet"), - METHOD_CONTAINER_PUT("containerPut"), - METHOD_CONTAINER_GET("ContainerGet"), - METHOD_CONTAINER_LIST("ContainerList"), - METHOD_CONTAINER_DELETE("ContainerDelete"), - METHOD_ENDPOINT_INFO("EndpointInfo"), - METHOD_NETWORK_INFO("NetworkInfo"), - METHOD_NETMAP_SNAPSHOT("NetMapSnapshot"), - METHOD_OBJECT_PUT("ObjectPut"), - METHOD_OBJECT_DELETE("ObjectDelete"), - METHOD_OBJECT_GET("ObjectGet"), - METHOD_OBJECT_HEAD("ObjectHead"), - METHOD_OBJECT_RANGE("ObjectRange"), - METHOD_OBJECT_PATCH("ObjectPatch"), - METHOD_SESSION_CREATE("SessionCreate"), - METHOD_APE_MANAGER_ADD_CHAIN("APEManagerAddChain"), - METHOD_APE_MANAGER_REMOVE_CHAIN("APEManagerRemoveChain"), - METHOD_APE_MANAGER_LIST_CHAINS("APEManagerListChains"), - ; - - public final String methodName; - - MethodIndex(String methodName) { - this.methodName = methodName; - } -} diff --git a/client/src/main/java/info/frostfs/sdk/enums/WaitExpects.java b/client/src/main/java/info/frostfs/sdk/enums/WaitExpects.java deleted file mode 100644 index 82e4d0a..0000000 --- a/client/src/main/java/info/frostfs/sdk/enums/WaitExpects.java +++ /dev/null @@ -1,6 +0,0 @@ -package info.frostfs.sdk.enums; - -public enum WaitExpects { - EXISTS, - REMOVED -} diff --git a/client/src/main/java/info/frostfs/sdk/exceptions/ResponseFrostFSException.java b/client/src/main/java/info/frostfs/sdk/exceptions/ResponseFrostFSException.java deleted file mode 100644 index c266395..0000000 --- a/client/src/main/java/info/frostfs/sdk/exceptions/ResponseFrostFSException.java +++ /dev/null @@ -1,19 +0,0 @@ -package info.frostfs.sdk.exceptions; - -import info.frostfs.sdk.dto.response.ResponseStatus; -import lombok.Getter; - -@Getter -public class ResponseFrostFSException extends FrostFSException { - private final ResponseStatus status; - - public ResponseFrostFSException(ResponseStatus status) { - super(status.toString()); - this.status = status; - } - - public ResponseFrostFSException(String message) { - super(message); - this.status = null; - } -} diff --git a/client/src/main/java/info/frostfs/sdk/jdo/ClientEnvironment.java b/client/src/main/java/info/frostfs/sdk/jdo/ClientEnvironment.java deleted file mode 100644 index 387882e..0000000 --- a/client/src/main/java/info/frostfs/sdk/jdo/ClientEnvironment.java +++ /dev/null @@ -1,57 +0,0 @@ -package info.frostfs.sdk.jdo; - -import info.frostfs.sdk.FrostFSClient; -import info.frostfs.sdk.annotations.NotNull; -import info.frostfs.sdk.annotations.Validate; -import info.frostfs.sdk.dto.netmap.Version; -import info.frostfs.sdk.dto.object.OwnerId; -import info.frostfs.sdk.pool.SessionCache; -import io.grpc.Channel; -import lombok.Getter; -import lombok.Setter; -import org.apache.commons.lang3.StringUtils; - -import static info.frostfs.sdk.Helper.getHexString; -import static info.frostfs.sdk.pool.Pool.formCacheKey; - -@Getter -@Setter -public class ClientEnvironment { - - @NotNull - private final OwnerId ownerId; - @NotNull - private final Version version; - @NotNull - @Validate - private final ECDsa key; - @NotNull - private final Channel channel; - @NotNull - private final FrostFSClient frostFSClient; - - private String sessionKey; - private String address; - private NetworkSettings networkSettings; - - private SessionCache sessionCache; - - public ClientEnvironment(ECDsa key, Channel channel, Version version, FrostFSClient frostFSClient, - SessionCache sessionCache) { - this.key = key; - this.ownerId = new OwnerId(key.getAccount().getAddress()); - this.version = version; - this.channel = channel; - this.frostFSClient = frostFSClient; - this.sessionCache = sessionCache; - this.address = channel.authority(); - } - - public String getSessionKey() { - if (StringUtils.isBlank(sessionKey)) { - this.sessionKey = formCacheKey(address, getHexString(key.getPublicKeyByte())); - } - - return sessionKey; - } -} diff --git a/client/src/main/java/info/frostfs/sdk/jdo/ClientSettings.java b/client/src/main/java/info/frostfs/sdk/jdo/ClientSettings.java deleted file mode 100644 index 0bab648..0000000 --- a/client/src/main/java/info/frostfs/sdk/jdo/ClientSettings.java +++ /dev/null @@ -1,61 +0,0 @@ -package info.frostfs.sdk.jdo; - -import info.frostfs.sdk.annotations.AtLeastOneIsFilled; -import info.frostfs.sdk.annotations.ComplexAtLeastOneIsFilled; -import io.grpc.ChannelCredentials; -import io.grpc.ManagedChannel; -import lombok.Getter; -import lombok.experimental.FieldNameConstants; - -import java.io.File; - -@Getter -@FieldNameConstants -@ComplexAtLeastOneIsFilled(value = { - @AtLeastOneIsFilled(fields = {ClientSettings.Fields.host, ClientSettings.Fields.channel}), - @AtLeastOneIsFilled(fields = {ClientSettings.Fields.wif, ClientSettings.Fields.wallet}), -}) -public class ClientSettings { - - private String wif; - private File wallet; - private String password; - private String host; - private ChannelCredentials credentials; - private ManagedChannel channel; - - public ClientSettings(String wif, String host) { - this.wif = wif; - this.host = host; - } - - public ClientSettings(String wif, String host, ChannelCredentials credentials) { - this.wif = wif; - this.host = host; - this.credentials = credentials; - } - - public ClientSettings(String wif, ManagedChannel channel) { - this.wif = wif; - this.channel = channel; - } - - public ClientSettings(File wallet, String password, String host) { - this.wallet = wallet; - this.password = password; - this.host = host; - } - - public ClientSettings(File wallet, String password, String host, ChannelCredentials credentials) { - this.wallet = wallet; - this.password = password; - this.host = host; - this.credentials = credentials; - } - - public ClientSettings(File wallet, String password, ManagedChannel channel) { - this.wallet = wallet; - this.password = password; - this.channel = channel; - } -} diff --git a/client/src/main/java/info/frostfs/sdk/jdo/ECDsa.java b/client/src/main/java/info/frostfs/sdk/jdo/ECDsa.java deleted file mode 100644 index dcd5b0a..0000000 --- a/client/src/main/java/info/frostfs/sdk/jdo/ECDsa.java +++ /dev/null @@ -1,73 +0,0 @@ -package info.frostfs.sdk.jdo; - -import info.frostfs.sdk.annotations.NotNull; -import info.frostfs.sdk.exceptions.FrostFSException; -import info.frostfs.sdk.exceptions.ValidationFrostFSException; -import io.neow3j.wallet.Account; -import io.neow3j.wallet.nep6.NEP6Account; -import io.neow3j.wallet.nep6.NEP6Wallet; -import lombok.Getter; -import org.apache.commons.lang3.StringUtils; - -import java.io.File; -import java.io.FileInputStream; -import java.security.PrivateKey; -import java.util.Optional; - -import static info.frostfs.sdk.KeyExtension.loadPrivateKey; -import static info.frostfs.sdk.constants.ErrorConst.WALLET_IS_INVALID; -import static info.frostfs.sdk.constants.ErrorConst.WIF_IS_INVALID; -import static info.frostfs.sdk.constants.FieldConst.EMPTY_STRING; -import static io.neow3j.wallet.Wallet.OBJECT_MAPPER; -import static java.util.Objects.isNull; - -@Getter -public class ECDsa { - - @NotNull - private final byte[] publicKeyByte; - - @NotNull - private final byte[] privateKeyByte; - - @NotNull - private final PrivateKey privateKey; - - @NotNull - private final Account account; - - public ECDsa(String wif) { - if (StringUtils.isEmpty(wif)) { - throw new ValidationFrostFSException(WIF_IS_INVALID); - } - - this.account = Account.fromWIF(wif); - this.privateKeyByte = account.getECKeyPair().getPrivateKey().getBytes(); - this.publicKeyByte = account.getECKeyPair().getPublicKey().getEncoded(true); - this.privateKey = loadPrivateKey(privateKeyByte); - } - - public ECDsa(File walletFile, String password) { - if (isNull(walletFile)) { - throw new ValidationFrostFSException(WALLET_IS_INVALID); - } - - try (var walletStream = new FileInputStream(walletFile)) { - NEP6Wallet nep6Wallet = OBJECT_MAPPER.readValue(walletStream, NEP6Wallet.class); - Optional defaultAccount = nep6Wallet.getAccounts().stream() - .filter(NEP6Account::getDefault) - .findFirst(); - - var account = defaultAccount.map(Account::fromNEP6Account) - .orElseGet(() -> Account.fromNEP6Account(nep6Wallet.getAccounts().get(0))); - account.decryptPrivateKey(isNull(password) ? EMPTY_STRING : password); - - this.account = account; - this.privateKeyByte = account.getECKeyPair().getPrivateKey().getBytes(); - this.publicKeyByte = account.getECKeyPair().getPublicKey().getEncoded(true); - this.privateKey = loadPrivateKey(privateKeyByte); - } catch (Exception exp) { - throw new FrostFSException(exp.getMessage()); - } - } -} diff --git a/client/src/main/java/info/frostfs/sdk/jdo/NetworkSettings.java b/client/src/main/java/info/frostfs/sdk/jdo/NetworkSettings.java deleted file mode 100644 index 103cb64..0000000 --- a/client/src/main/java/info/frostfs/sdk/jdo/NetworkSettings.java +++ /dev/null @@ -1,28 +0,0 @@ -package info.frostfs.sdk.jdo; - -import lombok.Getter; -import lombok.Setter; - -import java.util.HashMap; -import java.util.Map; - -@Getter -@Setter -public class NetworkSettings { - - private Long auditFee; - private Long basicIncomeRate; - private Long containerFee; - private Long containerAliasFee; - private Long innerRingCandidateFee; - private Long withdrawFee; - private Long epochDuration; - private Long iRCandidateFee; - private Long maxObjectSize; - private Long maxECDataCount; - private Long maxECParityCount; - private Long withdrawalFee; - private Boolean homomorphicHashingDisabled; - private Boolean maintenanceModeAllowed; - private Map unnamedSettings = new HashMap<>(); -} diff --git a/client/src/main/java/info/frostfs/sdk/jdo/PutObjectResult.java b/client/src/main/java/info/frostfs/sdk/jdo/PutObjectResult.java deleted file mode 100644 index 4fb933b..0000000 --- a/client/src/main/java/info/frostfs/sdk/jdo/PutObjectResult.java +++ /dev/null @@ -1,13 +0,0 @@ -package info.frostfs.sdk.jdo; - -import info.frostfs.sdk.dto.object.ObjectId; -import lombok.AllArgsConstructor; -import lombok.Getter; - -@Getter -@AllArgsConstructor -public class PutObjectResult { - - private final ObjectId objectId; - private final int objectSize; -} diff --git a/client/src/main/java/info/frostfs/sdk/jdo/parameters/CallContext.java b/client/src/main/java/info/frostfs/sdk/jdo/parameters/CallContext.java deleted file mode 100644 index 4831e99..0000000 --- a/client/src/main/java/info/frostfs/sdk/jdo/parameters/CallContext.java +++ /dev/null @@ -1,23 +0,0 @@ -package info.frostfs.sdk.jdo.parameters; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; - -import java.util.concurrent.TimeUnit; - -import static info.frostfs.sdk.constants.AppConst.DEFAULT_GRPC_TIMEOUT; - -@Getter -@Builder -@AllArgsConstructor -public class CallContext { - private final long timeout; - private final TimeUnit timeUnit; - - public CallContext() { - this.timeout = DEFAULT_GRPC_TIMEOUT; - this.timeUnit = TimeUnit.SECONDS; - } -} - diff --git a/client/src/main/java/info/frostfs/sdk/jdo/parameters/PrmWait.java b/client/src/main/java/info/frostfs/sdk/jdo/parameters/PrmWait.java deleted file mode 100644 index c109bd4..0000000 --- a/client/src/main/java/info/frostfs/sdk/jdo/parameters/PrmWait.java +++ /dev/null @@ -1,26 +0,0 @@ -package info.frostfs.sdk.jdo.parameters; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -import java.time.Duration; -import java.time.LocalDateTime; - -@Getter -@AllArgsConstructor -public class PrmWait { - private static final Duration DEFAULT_TIMEOUT = Duration.ofSeconds(120); - private static final Duration DEFAULT_POLL_INTERVAL = Duration.ofSeconds(5); - - private final Duration timeout; - private final Duration pollInterval; - - public PrmWait() { - this.timeout = DEFAULT_TIMEOUT; - this.pollInterval = DEFAULT_POLL_INTERVAL; - } - - public LocalDateTime getDeadline() { - return LocalDateTime.now().plus(timeout); - } -} diff --git a/client/src/main/java/info/frostfs/sdk/jdo/parameters/ape/PrmApeChainAdd.java b/client/src/main/java/info/frostfs/sdk/jdo/parameters/ape/PrmApeChainAdd.java deleted file mode 100644 index e7ae05c..0000000 --- a/client/src/main/java/info/frostfs/sdk/jdo/parameters/ape/PrmApeChainAdd.java +++ /dev/null @@ -1,27 +0,0 @@ -package info.frostfs.sdk.jdo.parameters.ape; - -import info.frostfs.sdk.annotations.NotNull; -import info.frostfs.sdk.dto.ape.Chain; -import info.frostfs.sdk.dto.chain.ChainTarget; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; - -import java.util.Map; - -@Getter -@Builder -@AllArgsConstructor -public class PrmApeChainAdd { - @NotNull - private Chain chain; - @NotNull - private ChainTarget chainTarget; - - private Map xHeaders; - - public PrmApeChainAdd(Chain chain, ChainTarget chainTarget) { - this.chain = chain; - this.chainTarget = chainTarget; - } -} diff --git a/client/src/main/java/info/frostfs/sdk/jdo/parameters/ape/PrmApeChainList.java b/client/src/main/java/info/frostfs/sdk/jdo/parameters/ape/PrmApeChainList.java deleted file mode 100644 index 70dc193..0000000 --- a/client/src/main/java/info/frostfs/sdk/jdo/parameters/ape/PrmApeChainList.java +++ /dev/null @@ -1,23 +0,0 @@ -package info.frostfs.sdk.jdo.parameters.ape; - -import info.frostfs.sdk.annotations.NotNull; -import info.frostfs.sdk.dto.chain.ChainTarget; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; - -import java.util.Map; - -@Getter -@Builder -@AllArgsConstructor -public class PrmApeChainList { - @NotNull - private ChainTarget chainTarget; - - private Map xHeaders; - - public PrmApeChainList(ChainTarget chainTarget) { - this.chainTarget = chainTarget; - } -} diff --git a/client/src/main/java/info/frostfs/sdk/jdo/parameters/ape/PrmApeChainRemove.java b/client/src/main/java/info/frostfs/sdk/jdo/parameters/ape/PrmApeChainRemove.java deleted file mode 100644 index 00bc2e9..0000000 --- a/client/src/main/java/info/frostfs/sdk/jdo/parameters/ape/PrmApeChainRemove.java +++ /dev/null @@ -1,27 +0,0 @@ -package info.frostfs.sdk.jdo.parameters.ape; - -import info.frostfs.sdk.annotations.NotNull; -import info.frostfs.sdk.dto.chain.ChainTarget; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; - -import java.util.Map; - -@Getter -@Builder -@AllArgsConstructor -public class PrmApeChainRemove { - @NotNull - private byte[] chainId; - - @NotNull - private ChainTarget chainTarget; - - private Map xHeaders; - - public PrmApeChainRemove(byte[] chainId, ChainTarget chainTarget) { - this.chainId = chainId; - this.chainTarget = chainTarget; - } -} diff --git a/client/src/main/java/info/frostfs/sdk/jdo/parameters/container/PrmContainerCreate.java b/client/src/main/java/info/frostfs/sdk/jdo/parameters/container/PrmContainerCreate.java deleted file mode 100644 index 758bfd8..0000000 --- a/client/src/main/java/info/frostfs/sdk/jdo/parameters/container/PrmContainerCreate.java +++ /dev/null @@ -1,33 +0,0 @@ -package info.frostfs.sdk.jdo.parameters.container; - -import info.frostfs.sdk.annotations.NotNull; -import info.frostfs.sdk.dto.container.Container; -import info.frostfs.sdk.dto.session.SessionToken; -import info.frostfs.sdk.jdo.parameters.PrmWait; -import info.frostfs.sdk.jdo.parameters.session.SessionContext; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; - -import java.util.Map; - -@Getter -@Builder -@AllArgsConstructor -public class PrmContainerCreate implements SessionContext { - @NotNull - private Container container; - - private PrmWait waitParams; - private SessionToken sessionToken; - private Map xHeaders; - - public PrmContainerCreate(Container container, PrmWait waitParams) { - this.container = container; - this.waitParams = waitParams; - } - - public PrmContainerCreate(Container container) { - this.container = container; - } -} diff --git a/client/src/main/java/info/frostfs/sdk/jdo/parameters/container/PrmContainerDelete.java b/client/src/main/java/info/frostfs/sdk/jdo/parameters/container/PrmContainerDelete.java deleted file mode 100644 index c9baeaf..0000000 --- a/client/src/main/java/info/frostfs/sdk/jdo/parameters/container/PrmContainerDelete.java +++ /dev/null @@ -1,33 +0,0 @@ -package info.frostfs.sdk.jdo.parameters.container; - -import info.frostfs.sdk.annotations.NotNull; -import info.frostfs.sdk.dto.container.ContainerId; -import info.frostfs.sdk.dto.session.SessionToken; -import info.frostfs.sdk.jdo.parameters.PrmWait; -import info.frostfs.sdk.jdo.parameters.session.SessionContext; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; - -import java.util.Map; - -@Getter -@Builder -@AllArgsConstructor -public class PrmContainerDelete implements SessionContext { - @NotNull - private ContainerId containerId; - - private PrmWait waitParams; - private SessionToken sessionToken; - private Map xHeaders; - - public PrmContainerDelete(ContainerId containerId, PrmWait waitParams) { - this.containerId = containerId; - this.waitParams = waitParams; - } - - public PrmContainerDelete(ContainerId containerId) { - this.containerId = containerId; - } -} diff --git a/client/src/main/java/info/frostfs/sdk/jdo/parameters/container/PrmContainerGet.java b/client/src/main/java/info/frostfs/sdk/jdo/parameters/container/PrmContainerGet.java deleted file mode 100644 index aec9924..0000000 --- a/client/src/main/java/info/frostfs/sdk/jdo/parameters/container/PrmContainerGet.java +++ /dev/null @@ -1,23 +0,0 @@ -package info.frostfs.sdk.jdo.parameters.container; - -import info.frostfs.sdk.annotations.NotNull; -import info.frostfs.sdk.dto.container.ContainerId; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; - -import java.util.Map; - -@Getter -@Builder -@AllArgsConstructor -public class PrmContainerGet { - @NotNull - private ContainerId containerId; - - private Map xHeaders; - - public PrmContainerGet(ContainerId containerId) { - this.containerId = containerId; - } -} diff --git a/client/src/main/java/info/frostfs/sdk/jdo/parameters/container/PrmContainerGetAll.java b/client/src/main/java/info/frostfs/sdk/jdo/parameters/container/PrmContainerGetAll.java deleted file mode 100644 index 56b8d7b..0000000 --- a/client/src/main/java/info/frostfs/sdk/jdo/parameters/container/PrmContainerGetAll.java +++ /dev/null @@ -1,16 +0,0 @@ -package info.frostfs.sdk.jdo.parameters.container; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; - -import java.util.Map; - -@Getter -@Builder -@AllArgsConstructor -@NoArgsConstructor -public class PrmContainerGetAll { - private Map xHeaders; -} diff --git a/client/src/main/java/info/frostfs/sdk/jdo/parameters/object/PrmObjectClientCutPut.java b/client/src/main/java/info/frostfs/sdk/jdo/parameters/object/PrmObjectClientCutPut.java deleted file mode 100644 index 9703a4c..0000000 --- a/client/src/main/java/info/frostfs/sdk/jdo/parameters/object/PrmObjectClientCutPut.java +++ /dev/null @@ -1,28 +0,0 @@ -package info.frostfs.sdk.jdo.parameters.object; - -import info.frostfs.sdk.annotations.NotNull; -import info.frostfs.sdk.dto.object.ObjectHeader; -import info.frostfs.sdk.dto.session.SessionToken; -import info.frostfs.sdk.jdo.parameters.session.SessionContext; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; - -import java.io.InputStream; -import java.util.Map; - -@Getter -@Builder -@AllArgsConstructor -public class PrmObjectClientCutPut implements PrmObjectPutBase, SessionContext { - @NotNull - private final PutObjectContext putObjectContext = new PutObjectContext(); - @NotNull - private ObjectHeader objectHeader; - @NotNull - private InputStream payload; - private int bufferMaxSize; - private byte[] customerBuffer; - private SessionToken sessionToken; - private Map xHeaders; -} diff --git a/client/src/main/java/info/frostfs/sdk/jdo/parameters/object/PrmObjectDelete.java b/client/src/main/java/info/frostfs/sdk/jdo/parameters/object/PrmObjectDelete.java deleted file mode 100644 index 326834f..0000000 --- a/client/src/main/java/info/frostfs/sdk/jdo/parameters/object/PrmObjectDelete.java +++ /dev/null @@ -1,30 +0,0 @@ -package info.frostfs.sdk.jdo.parameters.object; - -import info.frostfs.sdk.annotations.NotNull; -import info.frostfs.sdk.dto.container.ContainerId; -import info.frostfs.sdk.dto.object.ObjectId; -import info.frostfs.sdk.dto.session.SessionToken; -import info.frostfs.sdk.jdo.parameters.session.SessionContext; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; - -import java.util.Map; - -@Getter -@Builder -@AllArgsConstructor -public class PrmObjectDelete implements SessionContext { - @NotNull - private ContainerId containerId; - @NotNull - private ObjectId objectId; - - private SessionToken sessionToken; - private Map xHeaders; - - public PrmObjectDelete(ContainerId containerId, ObjectId objectId) { - this.containerId = containerId; - this.objectId = objectId; - } -} diff --git a/client/src/main/java/info/frostfs/sdk/jdo/parameters/object/PrmObjectGet.java b/client/src/main/java/info/frostfs/sdk/jdo/parameters/object/PrmObjectGet.java deleted file mode 100644 index e8eb3d7..0000000 --- a/client/src/main/java/info/frostfs/sdk/jdo/parameters/object/PrmObjectGet.java +++ /dev/null @@ -1,30 +0,0 @@ -package info.frostfs.sdk.jdo.parameters.object; - -import info.frostfs.sdk.annotations.NotNull; -import info.frostfs.sdk.dto.container.ContainerId; -import info.frostfs.sdk.dto.object.ObjectId; -import info.frostfs.sdk.dto.session.SessionToken; -import info.frostfs.sdk.jdo.parameters.session.SessionContext; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; - -import java.util.Map; - -@Getter -@Builder -@AllArgsConstructor -public class PrmObjectGet implements SessionContext { - @NotNull - private ContainerId containerId; - @NotNull - private ObjectId objectId; - - private SessionToken sessionToken; - private Map xHeaders; - - public PrmObjectGet(ContainerId containerId, ObjectId objectId) { - this.containerId = containerId; - this.objectId = objectId; - } -} diff --git a/client/src/main/java/info/frostfs/sdk/jdo/parameters/object/PrmObjectHeadGet.java b/client/src/main/java/info/frostfs/sdk/jdo/parameters/object/PrmObjectHeadGet.java deleted file mode 100644 index 8263db7..0000000 --- a/client/src/main/java/info/frostfs/sdk/jdo/parameters/object/PrmObjectHeadGet.java +++ /dev/null @@ -1,31 +0,0 @@ -package info.frostfs.sdk.jdo.parameters.object; - -import info.frostfs.sdk.annotations.NotNull; -import info.frostfs.sdk.dto.container.ContainerId; -import info.frostfs.sdk.dto.object.ObjectId; -import info.frostfs.sdk.dto.session.SessionToken; -import info.frostfs.sdk.jdo.parameters.session.SessionContext; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; - -import java.util.Map; - -@Getter -@Builder -@AllArgsConstructor -public class PrmObjectHeadGet implements SessionContext { - @NotNull - private ContainerId containerId; - @NotNull - private ObjectId objectId; - - private boolean raw; - private SessionToken sessionToken; - private Map xHeaders; - - public PrmObjectHeadGet(ContainerId containerId, ObjectId objectId) { - this.containerId = containerId; - this.objectId = objectId; - } -} diff --git a/client/src/main/java/info/frostfs/sdk/jdo/parameters/object/PrmObjectPut.java b/client/src/main/java/info/frostfs/sdk/jdo/parameters/object/PrmObjectPut.java deleted file mode 100644 index ac99504..0000000 --- a/client/src/main/java/info/frostfs/sdk/jdo/parameters/object/PrmObjectPut.java +++ /dev/null @@ -1,28 +0,0 @@ -package info.frostfs.sdk.jdo.parameters.object; - -import info.frostfs.sdk.annotations.NotNull; -import info.frostfs.sdk.dto.object.ObjectHeader; -import info.frostfs.sdk.dto.session.SessionToken; -import info.frostfs.sdk.jdo.parameters.session.SessionContext; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; - -import java.util.Map; - -@Getter -@Builder -@AllArgsConstructor -public class PrmObjectPut implements PrmObjectPutBase, SessionContext { - @NotNull - private final PutObjectContext putObjectContext = new PutObjectContext(); - @NotNull - private ObjectHeader objectHeader; - - private SessionToken sessionToken; - private Map xHeaders; - - public PrmObjectPut(ObjectHeader objectHeader) { - this.objectHeader = objectHeader; - } -} diff --git a/client/src/main/java/info/frostfs/sdk/jdo/parameters/object/PrmObjectPutBase.java b/client/src/main/java/info/frostfs/sdk/jdo/parameters/object/PrmObjectPutBase.java deleted file mode 100644 index 7ddfafb..0000000 --- a/client/src/main/java/info/frostfs/sdk/jdo/parameters/object/PrmObjectPutBase.java +++ /dev/null @@ -1,12 +0,0 @@ -package info.frostfs.sdk.jdo.parameters.object; - -import info.frostfs.sdk.dto.object.ObjectHeader; -import info.frostfs.sdk.jdo.parameters.session.SessionContext; - -import java.util.Map; - -public interface PrmObjectPutBase extends SessionContext { - ObjectHeader getObjectHeader(); - - Map getXHeaders(); -} diff --git a/client/src/main/java/info/frostfs/sdk/jdo/parameters/object/PrmObjectSearch.java b/client/src/main/java/info/frostfs/sdk/jdo/parameters/object/PrmObjectSearch.java deleted file mode 100644 index 0bc414b..0000000 --- a/client/src/main/java/info/frostfs/sdk/jdo/parameters/object/PrmObjectSearch.java +++ /dev/null @@ -1,30 +0,0 @@ -package info.frostfs.sdk.jdo.parameters.object; - -import info.frostfs.sdk.annotations.NotNull; -import info.frostfs.sdk.dto.container.ContainerId; -import info.frostfs.sdk.dto.object.ObjectFilter; -import info.frostfs.sdk.dto.session.SessionToken; -import info.frostfs.sdk.jdo.parameters.session.SessionContext; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; - -import java.util.Map; - -@Getter -@Builder -@AllArgsConstructor -public class PrmObjectSearch implements SessionContext { - @NotNull - private ContainerId containerId; - @NotNull - private ObjectFilter[] filters; - - private SessionToken sessionToken; - private Map xHeaders; - - public PrmObjectSearch(ContainerId containerId, ObjectFilter... filters) { - this.containerId = containerId; - this.filters = filters; - } -} diff --git a/client/src/main/java/info/frostfs/sdk/jdo/parameters/object/PrmObjectSinglePut.java b/client/src/main/java/info/frostfs/sdk/jdo/parameters/object/PrmObjectSinglePut.java deleted file mode 100644 index 2965d0c..0000000 --- a/client/src/main/java/info/frostfs/sdk/jdo/parameters/object/PrmObjectSinglePut.java +++ /dev/null @@ -1,26 +0,0 @@ -package info.frostfs.sdk.jdo.parameters.object; - -import info.frostfs.sdk.annotations.NotNull; -import info.frostfs.sdk.dto.object.ObjectFrostFS; -import info.frostfs.sdk.dto.session.SessionToken; -import info.frostfs.sdk.jdo.parameters.session.SessionContext; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; - -import java.util.Map; - -@Getter -@Builder -@AllArgsConstructor -public class PrmObjectSinglePut implements SessionContext { - @NotNull - private ObjectFrostFS objectFrostFS; - - private SessionToken sessionToken; - private Map xHeaders; - - public PrmObjectSinglePut(ObjectFrostFS objectFrostFS) { - this.objectFrostFS = objectFrostFS; - } -} diff --git a/client/src/main/java/info/frostfs/sdk/jdo/parameters/object/PutObjectContext.java b/client/src/main/java/info/frostfs/sdk/jdo/parameters/object/PutObjectContext.java deleted file mode 100644 index fc97dd0..0000000 --- a/client/src/main/java/info/frostfs/sdk/jdo/parameters/object/PutObjectContext.java +++ /dev/null @@ -1,14 +0,0 @@ -package info.frostfs.sdk.jdo.parameters.object; - -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -@Getter -@Setter -@NoArgsConstructor -public class PutObjectContext { - private int maxObjectSizeCache; - private long currentStreamPosition; - private long fullLength; -} diff --git a/client/src/main/java/info/frostfs/sdk/jdo/parameters/object/patch/PrmObjectPatch.java b/client/src/main/java/info/frostfs/sdk/jdo/parameters/object/patch/PrmObjectPatch.java deleted file mode 100644 index 58849df..0000000 --- a/client/src/main/java/info/frostfs/sdk/jdo/parameters/object/patch/PrmObjectPatch.java +++ /dev/null @@ -1,42 +0,0 @@ -package info.frostfs.sdk.jdo.parameters.object.patch; - -import info.frostfs.sdk.annotations.NotNull; -import info.frostfs.sdk.dto.object.ObjectAttribute; -import info.frostfs.sdk.dto.object.patch.Address; -import info.frostfs.sdk.dto.object.patch.Range; -import info.frostfs.sdk.dto.session.SessionToken; -import info.frostfs.sdk.jdo.parameters.session.SessionContext; -import lombok.*; - -import java.io.InputStream; -import java.util.List; -import java.util.Map; - -@Getter -@Builder -@AllArgsConstructor -public class PrmObjectPatch implements SessionContext { - @NotNull - private Address address; - - private Range range; - private InputStream payload; - private List newAttributes; - private boolean replaceAttributes; - private int maxChunkLength; - private SessionToken sessionToken; - private Map xHeaders; - - public PrmObjectPatch(Address address, Range range, InputStream payload, int maxChunkLength) { - this.address = address; - this.range = range; - this.payload = payload; - this.maxChunkLength = maxChunkLength; - } - - public PrmObjectPatch(Address address, List newAttributes, boolean replaceAttributes) { - this.address = address; - this.newAttributes = newAttributes; - this.replaceAttributes = replaceAttributes; - } -} diff --git a/client/src/main/java/info/frostfs/sdk/jdo/parameters/object/patch/PrmRangeGet.java b/client/src/main/java/info/frostfs/sdk/jdo/parameters/object/patch/PrmRangeGet.java deleted file mode 100644 index add15b7..0000000 --- a/client/src/main/java/info/frostfs/sdk/jdo/parameters/object/patch/PrmRangeGet.java +++ /dev/null @@ -1,35 +0,0 @@ -package info.frostfs.sdk.jdo.parameters.object.patch; - -import info.frostfs.sdk.annotations.NotNull; -import info.frostfs.sdk.dto.container.ContainerId; -import info.frostfs.sdk.dto.object.ObjectId; -import info.frostfs.sdk.dto.object.patch.Range; -import info.frostfs.sdk.dto.session.SessionToken; -import info.frostfs.sdk.jdo.parameters.session.SessionContext; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; - -import java.util.Map; - -@Getter -@Builder -@AllArgsConstructor -public class PrmRangeGet implements SessionContext { - @NotNull - private ContainerId containerId; - @NotNull - private ObjectId objectId; - @NotNull - private Range range; - - private boolean raw; - private SessionToken sessionToken; - private Map xHeaders; - - public PrmRangeGet(ContainerId containerId, ObjectId objectId, Range range) { - this.containerId = containerId; - this.objectId = objectId; - this.range = range; - } -} diff --git a/client/src/main/java/info/frostfs/sdk/jdo/parameters/object/patch/PrmRangeHashGet.java b/client/src/main/java/info/frostfs/sdk/jdo/parameters/object/patch/PrmRangeHashGet.java deleted file mode 100644 index d860133..0000000 --- a/client/src/main/java/info/frostfs/sdk/jdo/parameters/object/patch/PrmRangeHashGet.java +++ /dev/null @@ -1,38 +0,0 @@ -package info.frostfs.sdk.jdo.parameters.object.patch; - -import info.frostfs.sdk.annotations.NotNull; -import info.frostfs.sdk.dto.container.ContainerId; -import info.frostfs.sdk.dto.object.ObjectId; -import info.frostfs.sdk.dto.object.patch.Range; -import info.frostfs.sdk.dto.session.SessionToken; -import info.frostfs.sdk.jdo.parameters.session.SessionContext; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; - -import java.util.List; -import java.util.Map; - -@Getter -@Builder -@AllArgsConstructor -public class PrmRangeHashGet implements SessionContext { - @NotNull - private ContainerId containerId; - @NotNull - private ObjectId objectId; - @NotNull - private List ranges; - @NotNull - private byte[] salt; - - private SessionToken sessionToken; - private Map xHeaders; - - public PrmRangeHashGet(ContainerId containerId, ObjectId objectId, List ranges, byte[] salt) { - this.containerId = containerId; - this.objectId = objectId; - this.ranges = ranges; - this.salt = salt; - } -} diff --git a/client/src/main/java/info/frostfs/sdk/jdo/parameters/session/PrmSessionCreate.java b/client/src/main/java/info/frostfs/sdk/jdo/parameters/session/PrmSessionCreate.java deleted file mode 100644 index c73dd2b..0000000 --- a/client/src/main/java/info/frostfs/sdk/jdo/parameters/session/PrmSessionCreate.java +++ /dev/null @@ -1,19 +0,0 @@ -package info.frostfs.sdk.jdo.parameters.session; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; - -import java.util.Map; - -@Getter -@Builder -@AllArgsConstructor -public class PrmSessionCreate { - private long expiration; //-1 is max - private Map xHeaders; - - public PrmSessionCreate(long expiration) { - this.expiration = expiration; - } -} diff --git a/client/src/main/java/info/frostfs/sdk/jdo/parameters/session/SessionContext.java b/client/src/main/java/info/frostfs/sdk/jdo/parameters/session/SessionContext.java deleted file mode 100644 index 536017a..0000000 --- a/client/src/main/java/info/frostfs/sdk/jdo/parameters/session/SessionContext.java +++ /dev/null @@ -1,7 +0,0 @@ -package info.frostfs.sdk.jdo.parameters.session; - -import info.frostfs.sdk.dto.session.SessionToken; - -public interface SessionContext { - SessionToken getSessionToken(); -} diff --git a/client/src/main/java/info/frostfs/sdk/jdo/pool/NodeParameters.java b/client/src/main/java/info/frostfs/sdk/jdo/pool/NodeParameters.java deleted file mode 100644 index 01c9df0..0000000 --- a/client/src/main/java/info/frostfs/sdk/jdo/pool/NodeParameters.java +++ /dev/null @@ -1,12 +0,0 @@ -package info.frostfs.sdk.jdo.pool; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -@Getter -@AllArgsConstructor -public class NodeParameters { - private final int priority; - private final String address; - private final double weight; -} diff --git a/client/src/main/java/info/frostfs/sdk/jdo/pool/PoolInitParameters.java b/client/src/main/java/info/frostfs/sdk/jdo/pool/PoolInitParameters.java deleted file mode 100644 index 71eb670..0000000 --- a/client/src/main/java/info/frostfs/sdk/jdo/pool/PoolInitParameters.java +++ /dev/null @@ -1,44 +0,0 @@ -package info.frostfs.sdk.jdo.pool; - -import info.frostfs.sdk.jdo.ECDsa; -import info.frostfs.sdk.pool.ClientWrapper; -import io.grpc.ClientInterceptors; -import io.netty.channel.ChannelOption; -import lombok.Getter; -import lombok.Setter; -import org.slf4j.Logger; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.function.Function; - -@Getter -@Setter -public class PoolInitParameters { - private ECDsa key; - - private long nodeDialTimeout; - - private long nodeStreamTimeout; - - private long healthCheckTimeout; - - private long clientRebalanceInterval; - - private long sessionExpirationDuration; - - private int errorThreshold; - - private NodeParameters[] nodeParams; - - private ChannelOption[] dialOptions; - - private Function clientBuilder; - - private long gracefulCloseOnSwitchTimeout; - - private Logger logger; - - private Collection interceptors = new ArrayList<>(); -} - diff --git a/client/src/main/java/info/frostfs/sdk/jdo/result/ObjectHeaderResult.java b/client/src/main/java/info/frostfs/sdk/jdo/result/ObjectHeaderResult.java deleted file mode 100644 index a3fbb1e..0000000 --- a/client/src/main/java/info/frostfs/sdk/jdo/result/ObjectHeaderResult.java +++ /dev/null @@ -1,15 +0,0 @@ -package info.frostfs.sdk.jdo.result; - -import info.frostfs.sdk.dto.object.ObjectHeader; -import info.frostfs.sdk.dto.object.SplitInfo; -import lombok.Builder; -import lombok.Getter; -import lombok.Setter; - -@Builder -@Getter -@Setter -public class ObjectHeaderResult { - private ObjectHeader headerInfo; - private SplitInfo splitInfo; -} diff --git a/client/src/main/java/info/frostfs/sdk/placement/Context.java b/client/src/main/java/info/frostfs/sdk/placement/Context.java deleted file mode 100644 index 64fcb28..0000000 --- a/client/src/main/java/info/frostfs/sdk/placement/Context.java +++ /dev/null @@ -1,369 +0,0 @@ -package info.frostfs.sdk.placement; - -import info.frostfs.sdk.dto.netmap.*; -import info.frostfs.sdk.enums.netmap.FilterOperation; -import info.frostfs.sdk.enums.netmap.SelectorClause; -import info.frostfs.sdk.exceptions.FrostFSException; -import lombok.Getter; -import lombok.Setter; -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.apache.commons.lang3.tuple.Pair; - -import java.util.*; -import java.util.function.Function; -import java.util.stream.Collectors; - -import static info.frostfs.sdk.constants.AttributeConst.ATTRIBUTE_CAPACITY; -import static info.frostfs.sdk.constants.AttributeConst.ATTRIBUTE_PRICE; -import static info.frostfs.sdk.constants.ErrorConst.*; - -@Getter -@Setter -public final class Context { - public static final String MAIN_FILTER_NAME = "*"; - public static final String LIKE_WILDCARD = "*"; - - // network map to operate on - private final NetmapSnapshot netMap; - - // cache of processed filters - private final Map processedFilters = new HashMap<>(); - - // cache of processed selectors - private final Map processedSelectors = new HashMap<>(); - - // stores results of selector processing - private final Map>> selections = new HashMap<>(); - - // cache of parsed numeric values - private final Map numCache = new HashMap<>(); - private final Map usedNodes = new HashMap<>(); - private final Function weightFunc; - private byte[] hrwSeed; - private long hrwSeedHash; - private int cbf; - private boolean strict; - - public Context(NetmapSnapshot netMap) { - this.netMap = netMap; - this.weightFunc = Tools.defaultWeightFunc(netMap.getNodeInfoCollection()); - } - - private static Pair calcNodesCount(Selector selector) { - return selector.getClause() == SelectorClause.SAME - ? new ImmutablePair<>(1, selector.getCount()) - : new ImmutablePair<>(selector.getCount(), 1); - } - - private static double calcBucketWeight(List ns, MeanIQRAgg a, Function wf) { - for (NodeInfo node : ns) { - a.add(wf.apply(node)); - } - return a.compute(); - } - - public void processFilters(PlacementPolicy policy) { - for (Filter filter : policy.getFilters()) { - processFilter(filter, true); - } - } - - private void processFilter(Filter filter, boolean top) { - String filterName = filter.getName(); - if (MAIN_FILTER_NAME.equals(filterName)) { - throw new FrostFSException(String.format(INVALID_FILTER_NAME_TEMPLATE, MAIN_FILTER_NAME)); - } - - if (top && (filterName == null || filterName.isEmpty())) { - throw new FrostFSException(UNNAMED_TOP_FILTER); - } - - if (!top && filterName != null && !filterName.isEmpty() && !processedFilters.containsKey(filterName)) { - throw new FrostFSException(FILTER_NOT_FOUND); - } - - if (filter.getOperation() == FilterOperation.AND || - filter.getOperation() == FilterOperation.OR || - filter.getOperation() == FilterOperation.NOT) { - - for (Filter f : filter.getFilters()) { - processFilter(f, false); - } - } else { - if (filter.getFilters().length != 0) { - throw new FrostFSException(NON_EMPTY_FILTERS); - } else if (!top && filterName != null && !filterName.isEmpty()) { - // named reference - return; - } - - switch (filter.getOperation()) { - case EQ: - case NE: - case LIKE: - break; - case GT: - case GE: - case LT: - case LE: - long n = Long.parseLong(filter.getValue()); - numCache.put(filter.getValue(), n); - break; - default: - throw new FrostFSException(String.format(INVALID_FILTER_OPERATION_TEMPLATE, filter.getOperation())); - } - } - - if (top) { - processedFilters.put(filterName, filter); - } - } - - public void processSelectors(PlacementPolicy policy) { - for (Selector selector : policy.getSelectors()) { - String filterName = selector.getFilter(); - if (!MAIN_FILTER_NAME.equals(filterName)) { - if (selector.getFilter() == null || !processedFilters.containsKey(selector.getFilter())) { - throw new FrostFSException(String.format(FILTER_NOT_FOUND_TEMPLATE, filterName)); - } - } - - processedSelectors.put(selector.getName(), selector); - List> selection = getSelection(selector); - selections.put(selector.getName(), selection); - } - } - - private NodeAttributePair[] getSelectionBase(Selector selector) { - String fName = selector.getFilter(); - if (fName == null) { - throw new FrostFSException(FILTER_NAME_IS_EMPTY); - } - - Filter f = processedFilters.get(fName); - boolean isMain = MAIN_FILTER_NAME.equals(fName); - List result = new ArrayList<>(); - - Map> nodeMap = new HashMap<>(); - String attr = selector.getAttribute(); - - for (NodeInfo node : netMap.getNodeInfoCollection()) { - if (usedNodes.containsKey(node.getHash())) { - continue; - } - - if (isMain || match(f, node)) { - if (attr == null) { - result.add(new NodeAttributePair("", new NodeInfo[]{node})); - } else { - String v = node.getAttributes().get(attr); - List nodes = nodeMap.computeIfAbsent(v, k -> new ArrayList<>()); - nodes.add(node); - } - } - } - - if (attr != null && !attr.isEmpty()) { - for (Map.Entry> entry : nodeMap.entrySet()) { - result.add(new NodeAttributePair(entry.getKey(), entry.getValue().toArray(NodeInfo[]::new))); - } - } - - if (hrwSeed != null && hrwSeed.length != 0) { - NodeAttributePair[] sortedNodes = new NodeAttributePair[result.size()]; - - for (int i = 0; i < result.size(); i++) { - double[] ws = new double[result.get(i).getNodes().length]; - NodeAttributePair res = result.get(i); - Tools.appendWeightsTo(res.getNodes(), weightFunc, ws); - sortedNodes[i] = new NodeAttributePair( - res.getAttr(), - Tools.sortHasherSliceByWeightValue(Arrays.asList(res.getNodes()), ws, hrwSeedHash) - .toArray(NodeInfo[]::new) - ); - } - - return sortedNodes; - } - return result.toArray(new NodeAttributePair[0]); - } - - public List> getSelection(Selector s) { - Pair counts = calcNodesCount(s); - int bucketCount = counts.getKey(); - int nodesInBucket = counts.getValue(); - - NodeAttributePair[] buckets = getSelectionBase(s); - - if (strict && buckets.length < bucketCount) { - throw new FrostFSException(String.format(NOT_ENOUGH_NODES_TEMPLATE, s.getName())); - } - - if (hrwSeed == null || hrwSeed.length == 0) { - if (s.getAttribute() == null || s.getAttribute().isEmpty()) { - Arrays.sort(buckets, Comparator.comparing(b -> b.getNodes()[0].getHash())); - } else { - Arrays.sort(buckets, Comparator.comparing(NodeAttributePair::getAttr)); - } - } - - int maxNodesInBucket = nodesInBucket * cbf; - - List> res = new ArrayList<>(buckets.length); - List> fallback = new ArrayList<>(buckets.length); - - for (NodeAttributePair bucket : buckets) { - List ns = Arrays.asList(bucket.getNodes()); - if (ns.size() >= maxNodesInBucket) { - res.add(new ArrayList<>(ns.subList(0, maxNodesInBucket))); - } else if (ns.size() >= nodesInBucket) { - fallback.add(new ArrayList<>(ns)); - } - } - - if (res.size() < bucketCount) { - res.addAll(fallback); - - if (strict && res.size() < bucketCount) { - throw new FrostFSException(String.format(NOT_ENOUGH_NODES_TEMPLATE, s.getName())); - } - } - - if (hrwSeed != null && hrwSeed.length != 0) { - double[] weights = new double[res.size()]; - var a = new MeanIQRAgg(); - - for (int i = 0; i < res.size(); i++) { - a.clear(); - weights[i] = calcBucketWeight(res.get(i), a, weightFunc); - } - - List hashers = res.stream() - .map(HasherList::new) - .collect(Collectors.toList()); - - hashers = Tools.sortHasherSliceByWeightValue(hashers, weights, hrwSeedHash); - - for (int i = 0; i < res.size(); i++) { - res.set(i, hashers.get(i).getNodes()); - } - } - - if (res.size() < bucketCount) { - if (strict && res.isEmpty()) { - throw new FrostFSException(NOT_ENOUGH_NODES); - } - bucketCount = res.size(); - } - - if (s.getAttribute() == null || s.getAttribute().isEmpty()) { - fallback = res.subList(bucketCount, res.size()); - res = new ArrayList<>(res.subList(0, bucketCount)); - - for (int i = 0; i < fallback.size(); i++) { - int index = i % bucketCount; - if (res.get(index).size() >= maxNodesInBucket) { - break; - } - res.get(index).addAll(fallback.get(i)); - } - } - - return res.subList(0, bucketCount); - } - - private boolean matchKeyValue(Filter f, NodeInfo nodeInfo) { - switch (f.getOperation()) { - case EQ: - return nodeInfo.getAttributes().containsKey(f.getKey()) && - nodeInfo.getAttributes().get(f.getKey()).equals(f.getValue()); - case LIKE: - boolean hasPrefix = f.getValue().startsWith(LIKE_WILDCARD); - boolean hasSuffix = f.getValue().endsWith(LIKE_WILDCARD); - - int start = hasPrefix ? LIKE_WILDCARD.length() : 0; - int end = hasSuffix ? f.getValue().length() - LIKE_WILDCARD.length() : f.getValue().length(); - String str = f.getValue().substring(start, end); - - if (hasPrefix && hasSuffix) { - return nodeInfo.getAttributes().get(f.getKey()).contains(str); - } - if (hasPrefix) { - return nodeInfo.getAttributes().get(f.getKey()).endsWith(str); - } - if (hasSuffix) { - return nodeInfo.getAttributes().get(f.getKey()).startsWith(str); - } - return nodeInfo.getAttributes().get(f.getKey()).equals(f.getValue()); - case NE: - return !nodeInfo.getAttributes().get(f.getKey()).equals(f.getValue()); - default: - long attr; - switch (f.getKey()) { - case ATTRIBUTE_PRICE: - attr = nodeInfo.getPrice().longValue(); - break; - case ATTRIBUTE_CAPACITY: - attr = nodeInfo.getCapacity().longValue(); - break; - default: - try { - attr = Long.parseLong(nodeInfo.getAttributes().get(f.getKey())); - } catch (NumberFormatException e) { - return false; - } - break; - } - - switch (f.getOperation()) { - case GT: - return attr > numCache.get(f.getValue()); - case GE: - return attr >= numCache.get(f.getValue()); - case LT: - return attr < numCache.get(f.getValue()); - case LE: - return attr <= numCache.get(f.getValue()); - default: - break; - } - break; - } - return false; - } - - boolean match(Filter f, NodeInfo nodeInfo) { - if (f == null) { - return false; - } - - switch (f.getOperation()) { - case NOT: - Filter[] inner = f.getFilters(); - Filter fSub = inner[0]; - - if (inner[0].getName() != null && !inner[0].getName().isEmpty()) { - fSub = processedFilters.get(inner[0].getName()); - } - return !match(fSub, nodeInfo); - case AND: - case OR: - for (int i = 0; i < f.getFilters().length; i++) { - Filter currentFilter = f.getFilters()[i]; - - if (currentFilter.getName() != null && !currentFilter.getName().isEmpty()) { - currentFilter = processedFilters.get(currentFilter.getName()); - } - - boolean ok = match(currentFilter, nodeInfo); - - if (ok == (f.getOperation() == FilterOperation.OR)) { - return ok; - } - } - return f.getOperation() == FilterOperation.AND; - default: - return matchKeyValue(f, nodeInfo); - } - } -} diff --git a/client/src/main/java/info/frostfs/sdk/placement/HasherList.java b/client/src/main/java/info/frostfs/sdk/placement/HasherList.java deleted file mode 100644 index ee5a7ce..0000000 --- a/client/src/main/java/info/frostfs/sdk/placement/HasherList.java +++ /dev/null @@ -1,20 +0,0 @@ -package info.frostfs.sdk.placement; - -import info.frostfs.sdk.dto.netmap.Hasher; -import info.frostfs.sdk.dto.netmap.NodeInfo; -import lombok.AllArgsConstructor; -import lombok.Getter; -import org.apache.commons.collections4.CollectionUtils; - -import java.util.List; - -@Getter -@AllArgsConstructor -public final class HasherList implements Hasher { - private final List nodes; - - @Override - public long getHash() { - return CollectionUtils.isNotEmpty(nodes) ? nodes.get(0).getHash() : 0L; - } -} diff --git a/client/src/main/java/info/frostfs/sdk/placement/MeanAgg.java b/client/src/main/java/info/frostfs/sdk/placement/MeanAgg.java deleted file mode 100644 index d3464d4..0000000 --- a/client/src/main/java/info/frostfs/sdk/placement/MeanAgg.java +++ /dev/null @@ -1,18 +0,0 @@ -package info.frostfs.sdk.placement; - -import java.math.BigInteger; - -public class MeanAgg { - private double mean; - private int count; - - public void add(BigInteger n) { - int c = count + 1; - mean = mean * count / c + n.doubleValue() / c; - count++; - } - - public double compute() { - return mean; - } -} diff --git a/client/src/main/java/info/frostfs/sdk/placement/MeanIQRAgg.java b/client/src/main/java/info/frostfs/sdk/placement/MeanIQRAgg.java deleted file mode 100644 index b61b25e..0000000 --- a/client/src/main/java/info/frostfs/sdk/placement/MeanIQRAgg.java +++ /dev/null @@ -1,57 +0,0 @@ -package info.frostfs.sdk.placement; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -public final class MeanIQRAgg { - private static final int MIN_LN = 4; - - private final List arr = new ArrayList<>(); - - public MeanIQRAgg() { - } - - public void add(double d) { - arr.add(d); - } - - public double compute() { - int length = arr.size(); - if (length == 0) { - return 0; - } - - List sorted = new ArrayList<>(arr); - Collections.sort(sorted); - - double minV, maxV; - - if (length < MIN_LN) { - minV = sorted.get(0); - maxV = sorted.get(length - 1); - } else { - int start = length / MIN_LN; - int end = length * 3 / MIN_LN - 1; - - minV = sorted.get(start); - maxV = sorted.get(end); - } - - int count = 0; - double sum = 0; - - for (var e : sorted) { - if (e >= minV && e <= maxV) { - sum += e; - count++; - } - } - - return count == 0 ? 0 : sum / count; - } - - public void clear() { - arr.clear(); - } -} diff --git a/client/src/main/java/info/frostfs/sdk/placement/MinAgg.java b/client/src/main/java/info/frostfs/sdk/placement/MinAgg.java deleted file mode 100644 index e2855b5..0000000 --- a/client/src/main/java/info/frostfs/sdk/placement/MinAgg.java +++ /dev/null @@ -1,24 +0,0 @@ -package info.frostfs.sdk.placement; - -import java.math.BigInteger; - -public class MinAgg { - private double min; - private boolean minFound; - - public void add(BigInteger n) { - if (!minFound) { - min = n.doubleValue(); - minFound = true; - return; - } - - if (n.doubleValue() < min) { - min = n.doubleValue(); - } - } - - public double compute() { - return min; - } -} diff --git a/client/src/main/java/info/frostfs/sdk/placement/NodeAttributePair.java b/client/src/main/java/info/frostfs/sdk/placement/NodeAttributePair.java deleted file mode 100644 index 9fd1660..0000000 --- a/client/src/main/java/info/frostfs/sdk/placement/NodeAttributePair.java +++ /dev/null @@ -1,15 +0,0 @@ -package info.frostfs.sdk.placement; - -import info.frostfs.sdk.dto.netmap.NodeInfo; -import lombok.Getter; - -@Getter -public class NodeAttributePair { - private final String attr; - private final NodeInfo[] nodes; - - NodeAttributePair(String attr, NodeInfo[] nodes) { - this.attr = attr; - this.nodes = nodes; - } -} diff --git a/client/src/main/java/info/frostfs/sdk/placement/Normalizer.java b/client/src/main/java/info/frostfs/sdk/placement/Normalizer.java deleted file mode 100644 index 587150d..0000000 --- a/client/src/main/java/info/frostfs/sdk/placement/Normalizer.java +++ /dev/null @@ -1,5 +0,0 @@ -package info.frostfs.sdk.placement; - -public interface Normalizer { - double normalize(double w); -} diff --git a/client/src/main/java/info/frostfs/sdk/placement/PlacementVector.java b/client/src/main/java/info/frostfs/sdk/placement/PlacementVector.java deleted file mode 100644 index f20c75f..0000000 --- a/client/src/main/java/info/frostfs/sdk/placement/PlacementVector.java +++ /dev/null @@ -1,197 +0,0 @@ -package info.frostfs.sdk.placement; - -import info.frostfs.sdk.dto.netmap.*; -import info.frostfs.sdk.exceptions.FrostFSException; -import lombok.AllArgsConstructor; -import org.apache.commons.codec.digest.MurmurHash3; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.function.Function; - -import static info.frostfs.sdk.constants.ErrorConst.SELECTOR_NOT_FOUND_TEMPLATE; -import static info.frostfs.sdk.constants.ErrorConst.VECTORS_IS_NULL; - -@AllArgsConstructor -public final class PlacementVector { - private final NetmapSnapshot netmapSnapshot; - - private static NodeInfo[] flattenNodes(List> nodes) { - int size = nodes.stream().mapToInt(List::size).sum(); - NodeInfo[] result = new NodeInfo[size]; - - int i = 0; - for (List ns : nodes) { - for (NodeInfo n : ns) { - result[i++] = n; - } - } - return result; - } - - /* - * PlacementVectors sorts container nodes returned by ContainerNodes method - * and returns placement vectors for the entity identified by the given pivot. - * For example, in order to build node list to store the object, - * binary-encoded object identifier can be used as pivot. - * Result is deterministic for the fixed NetMap and parameters. - * */ - public NodeInfo[][] placementVectors(NodeInfo[][] vectors, byte[] pivot) { - if (vectors == null) { - throw new FrostFSException(VECTORS_IS_NULL); - } - - long hash = MurmurHash3.hash128x64(pivot, 0, pivot.length, 0)[0]; - - Function wf = Tools.defaultWeightFunc(netmapSnapshot.getNodeInfoCollection()); - - NodeInfo[][] result = new NodeInfo[vectors.length][]; - int maxSize = Arrays.stream(vectors) - .mapToInt(v -> v.length) - .max() - .orElse(0); - - double[] spanWeights = new double[maxSize]; - - for (int i = 0; i < vectors.length; i++) { - result[i] = Arrays.copyOf(vectors[i], vectors[i].length); - - Tools.appendWeightsTo(result[i], wf, spanWeights); - - List sorted = Tools.sortHasherSliceByWeightValue( - Arrays.asList(result[i]), - spanWeights, - hash - ); - result[i] = sorted.toArray(new NodeInfo[0]); - } - - return result; - } - - /* - * SelectFilterNodes returns a two-dimensional list of nodes as a result of applying the given - * SelectFilterExpr to the NetMap. If the SelectFilterExpr contains only filters, the result contains - * a single row with the result of the last filter application. If the SelectFilterExpr contains only selectors, - * the result contains the selection rows of the last select application. - * */ - public List> selectFilterNodes(SelectFilterExpr expr) { - PlacementPolicy policy = new PlacementPolicy( - null, - false, - expr.getCbf(), - expr.getFilters().toArray(Filter[]::new), - new Selector[]{expr.getSelector()} - ); - - Context ctx = new Context(netmapSnapshot); - ctx.setCbf(expr.getCbf()); - - ctx.processFilters(policy); - ctx.processSelectors(policy); - - List> ret = new ArrayList<>(); - - if (expr.getSelector() == null) { - Filter lastFilter = expr.getFilters().get(expr.getFilters().size() - 1); - List subCollection = new ArrayList<>(); - ret.add(subCollection); - - for (NodeInfo nodeInfo : netmapSnapshot.getNodeInfoCollection()) { - if (ctx.match(ctx.getProcessedFilters().get(lastFilter.getName()), nodeInfo)) { - subCollection.add(nodeInfo); - } - } - } else if (expr.getSelector().getName() != null) { - List> sel = ctx.getSelection( - ctx.getProcessedSelectors().get(expr.getSelector().getName()) - ); - - for (List ns : sel) { - List subCollection = new ArrayList<>(ns); - ret.add(subCollection); - } - } - - return ret; - } - - /* - * ContainerNodes returns two-dimensional list of nodes as a result of applying given PlacementPolicy to the NetMap. - * Each line of the list corresponds to a replica descriptor. - * Line order corresponds to order of ReplicaDescriptor list in the policy. - * Nodes are pre-filtered according to the Filter list from the policy, and then selected by Selector list. - * Result is deterministic for the fixed NetMap and parameters. - * - * Result can be used in PlacementVectors. - * */ - public NodeInfo[][] containerNodes(PlacementPolicy p, byte[] pivot) { - Context c = new Context(netmapSnapshot); - c.setCbf(p.getBackupFactory() == 0 ? 3 : p.getBackupFactory()); - - if (pivot != null && pivot.length > 0) { - c.setHrwSeed(pivot); - - var hash = MurmurHash3.hash128x64(pivot, 0, pivot.length, 0)[0]; - c.setHrwSeedHash(hash); - } - - c.processFilters(p); - c.processSelectors(p); - - boolean unique = p.isUnique(); - - List> result = new ArrayList<>(p.getReplicas().length); - for (int i = 0; i < p.getReplicas().length; i++) { - result.add(new ArrayList<>()); - } - - for (int i = 0; i < p.getReplicas().length; i++) { - String sName = p.getReplicas()[i].getSelector(); - - if ((sName == null || sName.isEmpty()) && - !(p.getReplicas().length == 1 && p.getSelectors().length == 1)) { - - Selector s = new Selector( - "", p.getReplicas()[i].getCountNodes(), null, null, - Context.MAIN_FILTER_NAME - ); - - List> nodes = c.getSelection(s); - result.get(i).addAll(Arrays.asList(flattenNodes(nodes))); - - if (unique) { - for (NodeInfo n : result.get(i)) { - c.getUsedNodes().put(n.getHash(), true); - } - } - continue; - } - - if (unique) { - Selector s = c.getProcessedSelectors().get(sName); - if (s == null) { - throw new FrostFSException(String.format(SELECTOR_NOT_FOUND_TEMPLATE, sName)); - } - - List> nodes = c.getSelection(s); - result.get(i).addAll(Arrays.asList(flattenNodes(nodes))); - - for (NodeInfo n : result.get(i)) { - c.getUsedNodes().put(n.getHash(), true); - } - } else { - List> nodes = c.getSelections().get(sName); - result.get(i).addAll(Arrays.asList(flattenNodes(nodes))); - } - } - - NodeInfo[][] collection = new NodeInfo[result.size()][]; - for (int i = 0; i < result.size(); i++) { - collection[i] = result.get(i).toArray(new NodeInfo[0]); - } - - return collection; - } -} diff --git a/client/src/main/java/info/frostfs/sdk/placement/ReverseMinNorm.java b/client/src/main/java/info/frostfs/sdk/placement/ReverseMinNorm.java deleted file mode 100644 index 1bcc03a..0000000 --- a/client/src/main/java/info/frostfs/sdk/placement/ReverseMinNorm.java +++ /dev/null @@ -1,14 +0,0 @@ -package info.frostfs.sdk.placement; - -public class ReverseMinNorm implements Normalizer { - private final double min; - - public ReverseMinNorm(double min) { - this.min = min; - } - - @Override - public double normalize(double w) { - return (min + 1) / (w + 1); - } -} diff --git a/client/src/main/java/info/frostfs/sdk/placement/SelectFilterExpr.java b/client/src/main/java/info/frostfs/sdk/placement/SelectFilterExpr.java deleted file mode 100644 index b7dd898..0000000 --- a/client/src/main/java/info/frostfs/sdk/placement/SelectFilterExpr.java +++ /dev/null @@ -1,16 +0,0 @@ -package info.frostfs.sdk.placement; - -import info.frostfs.sdk.dto.netmap.Filter; -import info.frostfs.sdk.dto.netmap.Selector; -import lombok.AllArgsConstructor; -import lombok.Getter; - -import java.util.List; - -@Getter -@AllArgsConstructor -public class SelectFilterExpr { - private final int cbf; - private final Selector selector; - private final List filters; -} diff --git a/client/src/main/java/info/frostfs/sdk/placement/SigmoidNorm.java b/client/src/main/java/info/frostfs/sdk/placement/SigmoidNorm.java deleted file mode 100644 index c0e867a..0000000 --- a/client/src/main/java/info/frostfs/sdk/placement/SigmoidNorm.java +++ /dev/null @@ -1,19 +0,0 @@ -package info.frostfs.sdk.placement; - -public class SigmoidNorm implements Normalizer { - private final double scale; - - public SigmoidNorm(double scale) { - this.scale = scale; - } - - @Override - public double normalize(double w) { - if (scale == 0) { - return 0; - } - - double x = w / scale; - return x / (1 + x); - } -} diff --git a/client/src/main/java/info/frostfs/sdk/placement/Tools.java b/client/src/main/java/info/frostfs/sdk/placement/Tools.java deleted file mode 100644 index 0140078..0000000 --- a/client/src/main/java/info/frostfs/sdk/placement/Tools.java +++ /dev/null @@ -1,123 +0,0 @@ -package info.frostfs.sdk.placement; - -import info.frostfs.sdk.dto.netmap.Hasher; -import info.frostfs.sdk.dto.netmap.NodeInfo; - -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Comparator; -import java.util.List; -import java.util.function.Function; - -import static info.frostfs.sdk.constants.AppConst.UNSIGNED_LONG_MASK; -import static info.frostfs.sdk.constants.CryptoConst.*; - -public final class Tools { - private Tools() { - } - - public static long distance(long x, long y) { - long acc = x ^ y; - acc ^= acc >>> MURMUR_MULTIPLIER; - acc *= LANDAU_PRIME_DIVISOR_65BIT; - acc ^= acc >>> MURMUR_MULTIPLIER; - acc *= LANDAU_PRIME_DIVISOR_64BIT; - acc ^= acc >>> MURMUR_MULTIPLIER; - return acc; - } - - public static void appendWeightsTo(NodeInfo[] nodes, Function wf, double[] weights) { - if (weights.length < nodes.length) { - weights = new double[nodes.length]; - } - for (int i = 0; i < nodes.length; i++) { - weights[i] = wf.apply(nodes[i]); - } - } - - public static List sortHasherSliceByWeightValue(List nodes, double[] weights, long hash) { - if (nodes.isEmpty()) { - return nodes; - } - - boolean allEquals = true; - if (weights.length > 1) { - for (int i = 1; i < weights.length; i++) { - if (weights[i] != weights[0]) { - allEquals = false; - break; - } - } - } - - Double[] dist = new Double[nodes.size()]; - - if (allEquals) { - for (int i = 0; i < dist.length; i++) { - long x = nodes.get(i).getHash(); - dist[i] = toUnsignedBigInteger(distance(x, hash)).doubleValue(); - } - return sortHasherByDistance(nodes, dist, true); - } - - for (int i = 0; i < dist.length; i++) { - var reverse = UNSIGNED_LONG_MASK.subtract(toUnsignedBigInteger(distance(nodes.get(i).getHash(), hash))); - dist[i] = reverse.doubleValue() * weights[i]; - } - - return sortHasherByDistance(nodes, dist, false); - } - - public static > List sortHasherByDistance( - List nodes, N[] dist, boolean asc - ) { - IndexedValue[] indexes = new IndexedValue[nodes.size()]; - for (int i = 0; i < dist.length; i++) { - indexes[i] = new IndexedValue<>(nodes.get(i), dist[i]); - } - - if (asc) { - Arrays.sort(indexes, Comparator.comparing(iv -> iv.dist)); - } else { - Arrays.sort(indexes, (iv1, iv2) -> iv2.dist.compareTo(iv1.dist)); - } - - List result = new ArrayList<>(); - for (IndexedValue iv : indexes) { - result.add(iv.nodeInfo); - } - return result; - } - - public static Function defaultWeightFunc(List nodes) { - MeanAgg mean = new MeanAgg(); - MinAgg minV = new MinAgg(); - - for (NodeInfo node : nodes) { - mean.add(node.getCapacity()); - minV.add(node.getPrice()); - } - - return newWeightFunc(new SigmoidNorm(mean.compute()), new ReverseMinNorm(minV.compute())); - } - - private static BigInteger toUnsignedBigInteger(long i) { - return i >= 0 ? BigInteger.valueOf(i) : BigInteger.valueOf(i).and(UNSIGNED_LONG_MASK); - } - - private static Function newWeightFunc(Normalizer capNorm, Normalizer priceNorm) { - return nodeInfo -> capNorm.normalize(nodeInfo.getCapacity().doubleValue()) - * priceNorm.normalize(nodeInfo.getPrice().doubleValue()); - } - - private static class IndexedValue { - final T nodeInfo; - final N dist; - - IndexedValue(T nodeInfo, N dist) { - this.nodeInfo = nodeInfo; - this.dist = dist; - } - } -} diff --git a/client/src/main/java/info/frostfs/sdk/pool/ClientStatus.java b/client/src/main/java/info/frostfs/sdk/pool/ClientStatus.java deleted file mode 100644 index 53b04c1..0000000 --- a/client/src/main/java/info/frostfs/sdk/pool/ClientStatus.java +++ /dev/null @@ -1,27 +0,0 @@ -package info.frostfs.sdk.pool; - -public interface ClientStatus { - // isHealthy checks if the connection can handle requests. - boolean isHealthy(); - - // isDialed checks if the connection was created. - boolean isDialed(); - - // setUnhealthy marks client as unhealthy. - void setUnhealthy(); - - // address return address of endpoint. - String getAddress(); - - // currentErrorRate returns current errors rate. - // After specific threshold connection is considered as unhealthy. - // Pool.startRebalance routine can make this connection healthy again. - int getCurrentErrorRate(); - - // overallErrorRate returns the number of all happened errors. - long getOverallErrorRate(); - - // methodsStatus returns statistic for all used methods. - StatusSnapshot[] getMethodsStatus(); -} - diff --git a/client/src/main/java/info/frostfs/sdk/pool/ClientStatusMonitor.java b/client/src/main/java/info/frostfs/sdk/pool/ClientStatusMonitor.java deleted file mode 100644 index 0770482..0000000 --- a/client/src/main/java/info/frostfs/sdk/pool/ClientStatusMonitor.java +++ /dev/null @@ -1,114 +0,0 @@ -package info.frostfs.sdk.pool; - -import info.frostfs.sdk.enums.HealthyStatus; -import info.frostfs.sdk.enums.MethodIndex; -import info.frostfs.sdk.utils.FrostFSMessages; -import lombok.Getter; -import lombok.Setter; -import org.slf4j.Logger; - -import java.util.Arrays; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.locks.ReentrantLock; - -@Getter -@Setter -public class ClientStatusMonitor implements ClientStatus { - private final ReentrantLock lock = new ReentrantLock(); - private final Logger logger; - private final AtomicInteger healthy = new AtomicInteger(); - - private final String address; - private final MethodStatus[] methods; - - private int errorThreshold; - private int currentErrorCount; - private long overallErrorCount; - - public ClientStatusMonitor(Logger logger, String address) { - this.logger = logger; - this.healthy.set(HealthyStatus.HEALTHY.value); - - this.address = address; - this.methods = Arrays.stream(MethodIndex.values()) - .map(t -> new MethodStatus(t.methodName)) - .toArray(MethodStatus[]::new); - } - - @Override - public boolean isHealthy() { - return healthy.get() == HealthyStatus.HEALTHY.value; - } - - @Override - public boolean isDialed() { - return healthy.get() != HealthyStatus.UNHEALTHY_ON_DIAL.value; - } - - public void setHealthy() { - healthy.set(HealthyStatus.HEALTHY.ordinal()); - } - - @Override - public void setUnhealthy() { - healthy.set(HealthyStatus.UNHEALTHY_ON_REQUEST.value); - } - - public void setUnhealthyOnDial() { - healthy.set(HealthyStatus.UNHEALTHY_ON_DIAL.value); - } - - public void incErrorRate() { - boolean thresholdReached; - lock.lock(); - try { - currentErrorCount++; - overallErrorCount++; - - thresholdReached = currentErrorCount >= errorThreshold; - - if (thresholdReached) { - setUnhealthy(); - currentErrorCount = 0; - } - } finally { - lock.unlock(); - } - - if (thresholdReached && logger != null) { - FrostFSMessages.errorThresholdReached(logger, address, errorThreshold); - } - } - - @Override - public int getCurrentErrorRate() { - lock.lock(); - try { - return currentErrorCount; - } finally { - lock.unlock(); - } - } - - @Override - public long getOverallErrorRate() { - lock.lock(); - try { - return overallErrorCount; - } finally { - lock.unlock(); - } - } - - @Override - public StatusSnapshot[] getMethodsStatus() { - StatusSnapshot[] result = new StatusSnapshot[methods.length]; - - for (int i = 0; i < result.length; i++) { - result[i] = methods[i].getSnapshot(); - } - - return result; - } -} - diff --git a/client/src/main/java/info/frostfs/sdk/pool/ClientWrapper.java b/client/src/main/java/info/frostfs/sdk/pool/ClientWrapper.java deleted file mode 100644 index 54163d1..0000000 --- a/client/src/main/java/info/frostfs/sdk/pool/ClientWrapper.java +++ /dev/null @@ -1,131 +0,0 @@ -package info.frostfs.sdk.pool; - -import info.frostfs.sdk.FrostFSClient; -import info.frostfs.sdk.enums.MethodIndex; -import info.frostfs.sdk.exceptions.ResponseFrostFSException; -import info.frostfs.sdk.exceptions.ValidationFrostFSException; -import info.frostfs.sdk.jdo.parameters.CallContext; -import info.frostfs.sdk.utils.WaitUtil; -import lombok.AccessLevel; -import lombok.Getter; -import org.apache.commons.lang3.StringUtils; - -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; - -import static info.frostfs.sdk.constants.ErrorConst.POOL_CLIENT_UNHEALTHY; - -@Getter -public class ClientWrapper extends ClientStatusMonitor { - @Getter(value = AccessLevel.NONE) - private final Lock lock = new ReentrantLock(); - private final SessionCache sessionCache; - private final WrapperPrm wrapperPrm; - private FrostFSClient client; - - public ClientWrapper(WrapperPrm wrapperPrm, Pool pool) { - super(wrapperPrm.getLogger(), wrapperPrm.getAddress()); - this.wrapperPrm = wrapperPrm; - setErrorThreshold(wrapperPrm.getErrorThreshold()); - - this.sessionCache = pool.getSessionCache(); - this.client = new FrostFSClient(wrapperPrm, sessionCache); - } - - - public FrostFSClient getClient() { - lock.lock(); - try { - if (isHealthy()) { - return client; - } - return null; - } finally { - lock.unlock(); - } - } - - public void dial(CallContext ctx) { - FrostFSClient client = getClient(); - if (client == null) { - throw new ValidationFrostFSException(POOL_CLIENT_UNHEALTHY); - } - client.dial(ctx); - } - - public void handleError(Exception exp) { - if (exp instanceof ResponseFrostFSException && ((ResponseFrostFSException) exp).getStatus() != null) { - switch (((ResponseFrostFSException) exp).getStatus().getCode()) { - case INTERNAL: - case WRONG_MAGIC_NUMBER: - case SIGNATURE_VERIFICATION_FAILURE: - case NODE_UNDER_MAINTENANCE: - incErrorRate(); - } - return; - } - - incErrorRate(); - } - - private void scheduleGracefulClose() { - if (client == null) { - return; - } - - WaitUtil.sleep(wrapperPrm.getGracefulCloseOnSwitchTimeout()); - client.close(); - } - - public CompletableFuture restartIfUnhealthy(CallContext ctx) { - try { - client.getLocalNodeInfo(ctx); - return CompletableFuture.completedFuture(false); - } catch (Exception ignored) { - } - - if (isDialed()) { - scheduleGracefulClose(); - } - - return CompletableFuture.completedFuture(restartClient(ctx)); - } - - private boolean restartClient(CallContext ctx) { - FrostFSClient newClient = null; - try { - newClient = new FrostFSClient(wrapperPrm, sessionCache); - - var error = newClient.dial(ctx); - if (StringUtils.isNotBlank(error)) { - setUnhealthyOnDial(); - newClient.close(); - return true; - } - - lock.lock(); - client = newClient; - lock.unlock(); - } catch (Exception exp) { - if (newClient != null) { - newClient.close(); - } - } - - try { - client.getLocalNodeInfo(ctx); - } catch (Exception exp) { - setUnhealthy(); - return true; - } - - setHealthy(); - return false; - } - - public void incRequests(long elapsed, MethodIndex method) { - var methodStat = getMethods()[method.ordinal()]; - methodStat.incRequests(elapsed); - } -} diff --git a/client/src/main/java/info/frostfs/sdk/pool/InnerPool.java b/client/src/main/java/info/frostfs/sdk/pool/InnerPool.java deleted file mode 100644 index 94a8be4..0000000 --- a/client/src/main/java/info/frostfs/sdk/pool/InnerPool.java +++ /dev/null @@ -1,54 +0,0 @@ -package info.frostfs.sdk.pool; - -import java.util.concurrent.locks.ReentrantLock; - -class InnerPool { - private static final int ATTEMPTS_COUNT = 3; - private final ReentrantLock lock = new ReentrantLock(); - private final ClientWrapper[] clients; - private Sampler sampler; - - InnerPool(Sampler sampler, ClientWrapper[] clients) { - this.sampler = sampler; - this.clients = clients; - } - - Sampler getSampler() { - return sampler; - } - - void setSampler(Sampler sampler) { - this.sampler = sampler; - } - - ClientWrapper[] getClients() { - return clients; - } - - ClientWrapper connection() { - lock.lock(); - try { - if (clients.length == 1) { - ClientWrapper client = clients[0]; - if (client.isHealthy()) { - return client; - } - } else { - int attempts = ATTEMPTS_COUNT * clients.length; - - for (int i = 0; i < attempts; i++) { - int index = sampler.next(); - - if (clients[index].isHealthy()) { - return clients[index]; - } - } - } - - return null; - } finally { - lock.unlock(); - } - } -} - diff --git a/client/src/main/java/info/frostfs/sdk/pool/MethodStatus.java b/client/src/main/java/info/frostfs/sdk/pool/MethodStatus.java deleted file mode 100644 index 5309c93..0000000 --- a/client/src/main/java/info/frostfs/sdk/pool/MethodStatus.java +++ /dev/null @@ -1,31 +0,0 @@ -package info.frostfs.sdk.pool; - -import lombok.AccessLevel; -import lombok.Getter; -import lombok.Setter; - -import java.util.concurrent.locks.ReentrantLock; - -@Setter -@Getter -public class MethodStatus { - @Getter(AccessLevel.NONE) - private final ReentrantLock lock = new ReentrantLock(); - private final String name; - private StatusSnapshot snapshot; - - public MethodStatus(String name) { - this.name = name; - this.snapshot = new StatusSnapshot(); - } - - void incRequests(long elapsed) { - lock.lock(); - try { - snapshot.setAllTime(snapshot.getAllTime() + elapsed); - snapshot.setAllRequests(snapshot.getAllRequests() + 1); - } finally { - lock.unlock(); - } - } -} diff --git a/client/src/main/java/info/frostfs/sdk/pool/NodeStatistic.java b/client/src/main/java/info/frostfs/sdk/pool/NodeStatistic.java deleted file mode 100644 index 2ad4cdc..0000000 --- a/client/src/main/java/info/frostfs/sdk/pool/NodeStatistic.java +++ /dev/null @@ -1,13 +0,0 @@ -package info.frostfs.sdk.pool; - -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -public class NodeStatistic { - private String address; - private StatusSnapshot[] methods; - private long overallErrors; - private int currentErrors; -} diff --git a/client/src/main/java/info/frostfs/sdk/pool/NodesParam.java b/client/src/main/java/info/frostfs/sdk/pool/NodesParam.java deleted file mode 100644 index 0221852..0000000 --- a/client/src/main/java/info/frostfs/sdk/pool/NodesParam.java +++ /dev/null @@ -1,19 +0,0 @@ -package info.frostfs.sdk.pool; - -import lombok.Getter; - -import java.util.ArrayList; -import java.util.List; - -@Getter -public class NodesParam { - private final int priority; - private final List address; - private final List weight; - - public NodesParam(int priority) { - this.priority = priority; - this.address = new ArrayList<>(); - this.weight = new ArrayList<>(); - } -} diff --git a/client/src/main/java/info/frostfs/sdk/pool/Pool.java b/client/src/main/java/info/frostfs/sdk/pool/Pool.java deleted file mode 100644 index 2191643..0000000 --- a/client/src/main/java/info/frostfs/sdk/pool/Pool.java +++ /dev/null @@ -1,558 +0,0 @@ -package info.frostfs.sdk.pool; - -import frostfs.refs.Types; -import info.frostfs.sdk.dto.ape.Chain; -import info.frostfs.sdk.dto.container.Container; -import info.frostfs.sdk.dto.container.ContainerId; -import info.frostfs.sdk.dto.netmap.NetmapSnapshot; -import info.frostfs.sdk.dto.netmap.NodeInfo; -import info.frostfs.sdk.dto.object.ObjectFrostFS; -import info.frostfs.sdk.dto.object.ObjectHeader; -import info.frostfs.sdk.dto.object.ObjectId; -import info.frostfs.sdk.dto.object.OwnerId; -import info.frostfs.sdk.dto.session.SessionToken; -import info.frostfs.sdk.exceptions.FrostFSException; -import info.frostfs.sdk.exceptions.SessionExpiredFrostFSException; -import info.frostfs.sdk.exceptions.SessionNotFoundFrostFSException; -import info.frostfs.sdk.exceptions.ValidationFrostFSException; -import info.frostfs.sdk.jdo.ECDsa; -import info.frostfs.sdk.jdo.NetworkSettings; -import info.frostfs.sdk.jdo.parameters.CallContext; -import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainAdd; -import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainList; -import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainRemove; -import info.frostfs.sdk.jdo.parameters.container.PrmContainerCreate; -import info.frostfs.sdk.jdo.parameters.container.PrmContainerDelete; -import info.frostfs.sdk.jdo.parameters.container.PrmContainerGet; -import info.frostfs.sdk.jdo.parameters.container.PrmContainerGetAll; -import info.frostfs.sdk.jdo.parameters.object.*; -import info.frostfs.sdk.jdo.parameters.object.patch.PrmObjectPatch; -import info.frostfs.sdk.jdo.parameters.object.patch.PrmRangeGet; -import info.frostfs.sdk.jdo.parameters.object.patch.PrmRangeHashGet; -import info.frostfs.sdk.jdo.parameters.session.PrmSessionCreate; -import info.frostfs.sdk.jdo.pool.NodeParameters; -import info.frostfs.sdk.jdo.pool.PoolInitParameters; -import info.frostfs.sdk.jdo.result.ObjectHeaderResult; -import info.frostfs.sdk.services.CommonClient; -import info.frostfs.sdk.services.impl.rwhelper.ObjectWriter; -import info.frostfs.sdk.services.impl.rwhelper.RangeReader; -import info.frostfs.sdk.utils.FrostFSMessages; -import info.frostfs.sdk.utils.WaitUtil; -import lombok.Getter; -import org.slf4j.Logger; - -import java.util.*; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicReference; -import java.util.concurrent.locks.ReentrantLock; -import java.util.function.Function; - -import static info.frostfs.sdk.Helper.getHexString; -import static info.frostfs.sdk.constants.ErrorConst.*; -import static info.frostfs.sdk.constants.PoolConst.*; - -@Getter -public class Pool implements CommonClient { - - private final ReentrantLock lock = new ReentrantLock(); - private final ECDsa key; - private final SessionCache sessionCache; - private final long sessionTokenDuration; - private final RebalanceParameters rebalanceParams; - private final Function clientBuilder; - private final Logger logger; - private InnerPool[] innerPools; - private Types.OwnerID ownerID; - private OwnerId ownerId; - private boolean disposedValue; - private long maxObjectSize; - private ClientStatus clientStatus; - - public Pool(PoolInitParameters options) { - if (options == null || options.getKey() == null) { - throw new ValidationFrostFSException( - String.format( - PARAMS_ARE_MISSING_TEMPLATE, - String.join( - FIELDS_DELIMITER_COMMA, PoolInitParameters.class.getName(), ECDsa.class.getName() - ) - ) - ); - } - - List nodesParams = adjustNodeParams(options.getNodeParams()); - SessionCache cache = new SessionCache(options.getSessionExpirationDuration()); - fillDefaultInitParams(options, this); - - this.key = options.getKey(); - this.sessionCache = cache; - this.logger = options.getLogger(); - this.sessionTokenDuration = options.getSessionExpirationDuration(); - - this.rebalanceParams = new RebalanceParameters( - nodesParams.toArray(new NodesParam[0]), - options.getHealthCheckTimeout(), - options.getClientRebalanceInterval(), - options.getSessionExpirationDuration()); - - this.clientBuilder = options.getClientBuilder(); - } - - private static List adjustNodeParams(NodeParameters[] nodeParams) { - if (nodeParams == null || nodeParams.length == 0) { - throw new ValidationFrostFSException(POOL_PEERS_IS_MISSING); - } - - Map nodesParamsDict = new HashMap<>(nodeParams.length); - for (NodeParameters nodeParam : nodeParams) { - var nodesParam = nodesParamsDict - .computeIfAbsent(nodeParam.getPriority(), k -> new NodesParam(nodeParam.getPriority())); - nodesParam.getAddress().add(nodeParam.getAddress()); - nodesParam.getWeight().add(nodeParam.getWeight()); - } - - List nodesParams = new ArrayList<>(nodesParamsDict.values()); - nodesParams.sort(Comparator.comparingInt(NodesParam::getPriority)); - - for (NodesParam nodes : nodesParams) { - double[] newWeights = adjustWeights(nodes.getWeight().stream().mapToDouble(Double::doubleValue).toArray()); - nodes.getWeight().clear(); - for (double weight : newWeights) { - nodes.getWeight().add(weight); - } - } - - return nodesParams; - } - - private static double[] adjustWeights(double[] weights) { - double[] adjusted = new double[weights.length]; - double sum = Arrays.stream(weights).sum(); - - if (sum > 0) { - for (int i = 0; i < weights.length; i++) { - adjusted[i] = weights[i] / sum; - } - } - - return adjusted; - } - - private static void fillDefaultInitParams(PoolInitParameters parameters, Pool pool) { - if (parameters.getSessionExpirationDuration() == 0) { - parameters.setSessionExpirationDuration(DEFAULT_SESSION_TOKEN_EXPIRATION_DURATION); - } - - if (parameters.getErrorThreshold() == 0) { - parameters.setErrorThreshold(DEFAULT_ERROR_THRESHOLD); - } - - if (parameters.getClientRebalanceInterval() <= 0) { - parameters.setClientRebalanceInterval(DEFAULT_REBALANCE_INTERVAL); - } - - if (parameters.getGracefulCloseOnSwitchTimeout() <= 0) { - parameters.setGracefulCloseOnSwitchTimeout(DEFAULT_GRACEFUL_CLOSE_ON_SWITCH_TIMEOUT); - } - - if (parameters.getHealthCheckTimeout() <= 0) { - parameters.setHealthCheckTimeout(DEFAULT_HEALTHCHECK_TIMEOUT); - } - - if (parameters.getNodeDialTimeout() <= 0) { - parameters.setNodeDialTimeout(DEFAULT_DIAL_TIMEOUT); - } - - if (parameters.getNodeStreamTimeout() <= 0) { - parameters.setNodeStreamTimeout(DEFAULT_STREAM_TIMEOUT); - } - - if (parameters.getSessionExpirationDuration() == 0) { - parameters.setSessionExpirationDuration(DEFAULT_SESSION_TOKEN_EXPIRATION_DURATION); - } - - if (parameters.getClientBuilder() == null) { - parameters.setClientBuilder(address -> { - WrapperPrm wrapperPrm = new WrapperPrm(); - wrapperPrm.setAddress(address); - wrapperPrm.setKey(parameters.getKey()); - wrapperPrm.setLogger(parameters.getLogger()); - wrapperPrm.setDialTimeout(parameters.getNodeDialTimeout()); - wrapperPrm.setStreamTimeout(parameters.getNodeStreamTimeout()); - wrapperPrm.setErrorThreshold(parameters.getErrorThreshold()); - wrapperPrm.setGracefulCloseOnSwitchTimeout(parameters.getGracefulCloseOnSwitchTimeout()); - wrapperPrm.setInterceptors(parameters.getInterceptors()); - return new ClientWrapper(wrapperPrm, pool); - }); - } - } - - private static SessionToken initSessionForDuration(CallContext ctx, ClientWrapper cw, long duration) { - var client = cw.getClient(); - NetworkSettings networkInfo = client.getNetworkSettings(ctx); - - long epoch = networkInfo.getEpochDuration(); - long exp = (Long.MAX_VALUE - epoch < duration) ? Long.MAX_VALUE : (epoch + duration); - - return client.createSession(new PrmSessionCreate(exp), ctx); - } - - public static String formCacheKey(String address, String key) { - return address + key; - } - - @Override - public String dial(CallContext ctx) { - InnerPool[] inner = new InnerPool[rebalanceParams.getNodesParams().length]; - boolean atLeastOneHealthy = false; - int i = 0; - - for (NodesParam nodeParams : rebalanceParams.getNodesParams()) { - ClientWrapper[] clients = new ClientWrapper[nodeParams.getWeight().size()]; - - for (int j = 0; j < nodeParams.getAddress().size(); j++) { - ClientWrapper client = clients[j] = clientBuilder.apply(nodeParams.getAddress().get(j)); - boolean dialed = false; - - try { - client.dial(ctx); - dialed = true; - - SessionToken token = initSessionForDuration( - ctx, client, rebalanceParams.getSessionExpirationDuration() - ); - String cacheKey = formCacheKey( - nodeParams.getAddress().get(j), - getHexString(key.getPublicKeyByte()) - ); - sessionCache.setValue(cacheKey, token); - - atLeastOneHealthy = true; - } catch (ValidationFrostFSException exp) { - break; - } catch (Exception exp) { - if (!dialed) { - client.setUnhealthyOnDial(); - } else { - client.setUnhealthy(); - } - - if (logger != null) { - FrostFSMessages - .sessionCreationError(logger, client.getWrapperPrm().getAddress(), exp.getMessage()); - } - } - } - - Sampler sampler = new Sampler(nodeParams.getWeight().stream().mapToDouble(Double::doubleValue).toArray()); - inner[i] = new InnerPool(sampler, clients); - i++; - } - - if (!atLeastOneHealthy) { - return POOL_NODES_UNHEALTHY; - } - - this.innerPools = inner; - - NetworkSettings networkSettings = getNetworkSettings(ctx); - - this.maxObjectSize = networkSettings.getMaxObjectSize(); - startRebalance(ctx); - - return null; - } - - private ClientWrapper connection() { - for (InnerPool pool : innerPools) { - ClientWrapper client = pool.connection(); - if (client != null) { - return client; - } - } - - throw new FrostFSException(POOL_CLIENTS_UNHEALTHY); - } - - public void close() { - if (innerPools != null) { - for (InnerPool innerPool : innerPools) { - for (ClientWrapper client : innerPool.getClients()) { - if (client.isDialed()) { - client.getClient().close(); - } - } - } - } - } - - public void startRebalance(CallContext ctx) { - double[][] buffers = new double[rebalanceParams.getNodesParams().length][]; - - for (int i = 0; i < rebalanceParams.getNodesParams().length; i++) { - NodesParam parameters = rebalanceParams.getNodesParams()[i]; - buffers[i] = new double[parameters.getWeight().size()]; - - CompletableFuture.runAsync(() -> { - WaitUtil.sleep(rebalanceParams.getClientRebalanceInterval()); - updateNodesHealth(ctx, buffers); - }); - } - } - - private void updateNodesHealth(CallContext ctx, double[][] buffers) { - CompletableFuture[] tasks = new CompletableFuture[innerPools.length]; - - for (int i = 0; i < innerPools.length; i++) { - double[] bufferWeights = buffers[i]; - int finalI = i; - tasks[i] = CompletableFuture.runAsync(() -> updateInnerNodesHealth(ctx, finalI, bufferWeights)); - } - - CompletableFuture.allOf(tasks).join(); - } - - private void updateInnerNodesHealth(CallContext ctx, int poolIndex, double[] bufferWeights) { - if (poolIndex > innerPools.length - 1) { - return; - } - - InnerPool pool = innerPools[poolIndex]; - RebalanceParameters options = rebalanceParams; - int[] healthyChanged = {0}; - - CompletableFuture[] tasks = new CompletableFuture[pool.getClients().length]; - - for (int j = 0; j < pool.getClients().length; j++) { - ClientWrapper client = pool.getClients()[j]; - AtomicBoolean healthy = new AtomicBoolean(false); - AtomicReference error = new AtomicReference<>(); - AtomicBoolean changed = new AtomicBoolean(false); - - int finalJ = j; - tasks[j] = client.restartIfUnhealthy(ctx).handle((unused, throwable) -> { - if (throwable != null) { - error.set(throwable.getMessage()); - bufferWeights[finalJ] = 0; - sessionCache.deleteByPrefix(client.getAddress()); - } else { - changed.set(unused); - healthy.set(true); - bufferWeights[finalJ] = options.getNodesParams()[poolIndex].getWeight().get(finalJ); - } - return null; - }).thenRun(() -> { - if (changed.get()) { - if (error.get() != null && logger != null) { - FrostFSMessages.healthChanged(logger, client.getAddress(), healthy.get(), error.get()); - } - healthyChanged[0] = 1; - } - }); - } - - CompletableFuture.allOf(tasks).thenRun(() -> { - if (healthyChanged[0] == 1) { - double[] probabilities = adjustWeights(bufferWeights); - lock.lock(); - try { - pool.setSampler(new Sampler(probabilities)); - } finally { - lock.unlock(); - } - } - }); - } - - private boolean checkSessionTokenErr(Exception error, String address) { - if (error == null) { - return false; - } - - if (error instanceof SessionNotFoundFrostFSException || error instanceof SessionExpiredFrostFSException) { - sessionCache.deleteByPrefix(address); - return true; - } - - return false; - } - - public Statistic statistic() { - if (innerPools == null) { - throw new ValidationFrostFSException(POOL_NOT_DIALED); - } - - Statistic statistics = new Statistic(); - - for (InnerPool inner : innerPools) { - int valueIndex = 0; - String[] nodes = new String[inner.getClients().length]; - - lock.lock(); - try { - for (ClientWrapper client : inner.getClients()) { - if (client.isHealthy()) { - nodes[valueIndex] = client.getAddress(); - } - - NodeStatistic node = new NodeStatistic(); - node.setAddress(client.getAddress()); - node.setMethods(client.getMethodsStatus()); - node.setOverallErrors(client.getOverallErrorRate()); - node.setCurrentErrors(client.getCurrentErrorRate()); - - statistics.getNodes().add(node); - valueIndex++; - statistics.setOverallErrors(statistics.getOverallErrors() + node.getOverallErrors()); - } - - if (statistics.getCurrentNodes() == null || statistics.getCurrentNodes().length == 0) { - statistics.setCurrentNodes(nodes); - } - } finally { - lock.unlock(); - } - } - - return statistics; - } - - @Override - public Container getContainer(PrmContainerGet args, CallContext ctx) { - ClientWrapper client = connection(); - return client.getClient().getContainer(args, ctx); - } - - @Override - public List listContainers(PrmContainerGetAll args, CallContext ctx) { - ClientWrapper client = connection(); - return client.getClient().listContainers(args, ctx); - } - - @Override - public ContainerId createContainer(PrmContainerCreate args, CallContext ctx) { - ClientWrapper client = connection(); - return client.getClient().createContainer(args, ctx); - } - - @Override - public void deleteContainer(PrmContainerDelete args, CallContext ctx) { - ClientWrapper client = connection(); - client.getClient().deleteContainer(args, ctx); - } - - @Override - public ObjectHeaderResult getObjectHead(PrmObjectHeadGet args, CallContext ctx) { - ClientWrapper client = connection(); - return client.getClient().getObjectHead(args, ctx); - } - - @Override - public ObjectFrostFS getObject(PrmObjectGet args, CallContext ctx) { - ClientWrapper client = connection(); - return client.getClient().getObject(args, ctx); - } - - @Override - public ObjectWriter putObject(PrmObjectPut args, CallContext ctx) { - ClientWrapper client = connection(); - return client.getClient().putObject(args, ctx); - } - - @Override - public ObjectId putClientCutObject(PrmObjectClientCutPut args, CallContext ctx) { - ClientWrapper client = connection(); - return client.getClient().putClientCutObject(args, ctx); - } - - @Override - public ObjectId putSingleObject(PrmObjectSinglePut args, CallContext ctx) { - ClientWrapper client = connection(); - return client.getClient().putSingleObject(args, ctx); - } - - @Override - public void deleteObject(PrmObjectDelete args, CallContext ctx) { - ClientWrapper client = connection(); - client.getClient().deleteObject(args, ctx); - } - - @Override - public Iterable searchObjects(PrmObjectSearch args, CallContext ctx) { - ClientWrapper client = connection(); - return client.getClient().searchObjects(args, ctx); - } - - @Override - public RangeReader getRange(PrmRangeGet args, CallContext ctx) { - ClientWrapper client = connection(); - return client.getClient().getRange(args, ctx); - } - - @Override - public byte[][] getRangeHash(PrmRangeHashGet args, CallContext ctx) { - ClientWrapper client = connection(); - return client.getClient().getRangeHash(args, ctx); - } - - @Override - public ObjectId patchObject(PrmObjectPatch args, CallContext ctx) { - ClientWrapper client = connection(); - return client.getClient().patchObject(args, ctx); - } - - @Override - public byte[] addChain(PrmApeChainAdd args, CallContext ctx) { - ClientWrapper client = connection(); - return client.getClient().addChain(args, ctx); - } - - @Override - public void removeChain(PrmApeChainRemove args, CallContext ctx) { - ClientWrapper client = connection(); - client.getClient().removeChain(args, ctx); - } - - @Override - public List listChains(PrmApeChainList args, CallContext ctx) { - ClientWrapper client = connection(); - return client.getClient().listChains(args, ctx); - } - - @Override - public NetmapSnapshot getNetmapSnapshot(CallContext ctx) { - ClientWrapper client = connection(); - return client.getClient().getNetmapSnapshot(ctx); - } - - @Override - public NodeInfo getLocalNodeInfo(CallContext ctx) { - ClientWrapper client = connection(); - return client.getClient().getLocalNodeInfo(ctx); - } - - @Override - public NetworkSettings getNetworkSettings(CallContext ctx) { - ClientWrapper client = connection(); - return client.getClient().getNetworkSettings(ctx); - } - - @Override - public SessionToken createSession(PrmSessionCreate args, CallContext ctx) { - ClientWrapper client = connection(); - return client.getClient().createSession(args, ctx); - } - - @Override - public ObjectId calculateObjectId(ObjectHeader header) { - ClientWrapper client = connection(); - return client.getClient().calculateObjectId(header); - } - - @Override - public frostfs.accounting.Types.Decimal getBalance(CallContext ctx) { - ClientWrapper client = connection(); - return client.getClient().getBalance(ctx); - } -} diff --git a/client/src/main/java/info/frostfs/sdk/pool/RebalanceParameters.java b/client/src/main/java/info/frostfs/sdk/pool/RebalanceParameters.java deleted file mode 100644 index d7bd790..0000000 --- a/client/src/main/java/info/frostfs/sdk/pool/RebalanceParameters.java +++ /dev/null @@ -1,15 +0,0 @@ -package info.frostfs.sdk.pool; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@AllArgsConstructor -public class RebalanceParameters { - private NodesParam[] nodesParams; - private long nodeRequestTimeout; - private long clientRebalanceInterval; - private long sessionExpirationDuration; -} diff --git a/client/src/main/java/info/frostfs/sdk/pool/RequestInfo.java b/client/src/main/java/info/frostfs/sdk/pool/RequestInfo.java deleted file mode 100644 index 68d8312..0000000 --- a/client/src/main/java/info/frostfs/sdk/pool/RequestInfo.java +++ /dev/null @@ -1,15 +0,0 @@ -package info.frostfs.sdk.pool; - -import info.frostfs.sdk.enums.MethodIndex; -import lombok.Getter; -import lombok.Setter; - -import java.time.Duration; - -@Getter -@Setter -public class RequestInfo { - private String address; - private MethodIndex methodIndex; - private Duration elapsed; -} diff --git a/client/src/main/java/info/frostfs/sdk/pool/Sampler.java b/client/src/main/java/info/frostfs/sdk/pool/Sampler.java deleted file mode 100644 index 505243a..0000000 --- a/client/src/main/java/info/frostfs/sdk/pool/Sampler.java +++ /dev/null @@ -1,77 +0,0 @@ -package info.frostfs.sdk.pool; - -import java.util.ArrayList; -import java.util.Random; - -class Sampler { - private final Object lock = new Object(); - private final Random random = new Random(); - private final double[] probabilities; - private final int[] alias; - - Sampler(double[] probabilities) { - ArrayList small = new ArrayList<>(); - ArrayList large = new ArrayList<>(); - - int n = probabilities.length; - - this.probabilities = new double[n]; - this.alias = new int[n]; - - // Compute scaled probabilities. - double[] p = new double[n]; - - for (int i = 0; i < n; i++) { - p[i] = probabilities[i] * n; - if (p[i] < 1) { - small.add(i); - } else { - large.add(i); - } - } - - while (!small.isEmpty() && !large.isEmpty()) { - int l = small.remove(small.size() - 1); - int g = large.remove(large.size() - 1); - - this.probabilities[l] = p[l]; - this.alias[l] = g; - - p[g] = p[g] + p[l] - 1; - - if (p[g] < 1) { - small.add(g); - } else { - large.add(g); - } - } - - while (!large.isEmpty()) { - int g = large.remove(large.size() - 1); - this.probabilities[g] = 1; - } - - while (!small.isEmpty()) { - int l = small.remove(small.size() - 1); - probabilities[l] = 1; - } - } - - int next() { - int n = alias.length; - - int i; - double f; - synchronized (lock) { - i = random.nextInt(n); - f = random.nextDouble(); - } - - if (f < probabilities[i]) { - return i; - } - - return alias[i]; - } -} - diff --git a/client/src/main/java/info/frostfs/sdk/pool/SessionCache.java b/client/src/main/java/info/frostfs/sdk/pool/SessionCache.java deleted file mode 100644 index 998beb6..0000000 --- a/client/src/main/java/info/frostfs/sdk/pool/SessionCache.java +++ /dev/null @@ -1,37 +0,0 @@ -package info.frostfs.sdk.pool; - -import info.frostfs.sdk.dto.session.SessionToken; -import org.apache.commons.lang3.StringUtils; - -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - -public class SessionCache { - private final ConcurrentMap cache = new ConcurrentHashMap<>(); - private final long tokenDuration; - private long currentEpoch; - - public SessionCache(long sessionExpirationDuration) { - this.tokenDuration = sessionExpirationDuration; - } - - public boolean contains(String key) { - return cache.containsKey(key); - } - - public SessionToken tryGetValue(String key) { - return StringUtils.isBlank(key) ? null : cache.get(key); - } - - public void setValue(String key, SessionToken value) { - if (key != null) { - cache.put(key, value); - } - } - - public void deleteByPrefix(String prefix) { - cache.keySet().removeIf(key -> key.startsWith(prefix)); - } -} - - diff --git a/client/src/main/java/info/frostfs/sdk/pool/Statistic.java b/client/src/main/java/info/frostfs/sdk/pool/Statistic.java deleted file mode 100644 index c7bc2ea..0000000 --- a/client/src/main/java/info/frostfs/sdk/pool/Statistic.java +++ /dev/null @@ -1,15 +0,0 @@ -package info.frostfs.sdk.pool; - -import lombok.Getter; -import lombok.Setter; - -import java.util.ArrayList; -import java.util.List; - -@Getter -@Setter -public class Statistic { - private long overallErrors; - private List nodes = new ArrayList<>(); - private String[] currentNodes; -} diff --git a/client/src/main/java/info/frostfs/sdk/pool/StatusSnapshot.java b/client/src/main/java/info/frostfs/sdk/pool/StatusSnapshot.java deleted file mode 100644 index 99a797b..0000000 --- a/client/src/main/java/info/frostfs/sdk/pool/StatusSnapshot.java +++ /dev/null @@ -1,13 +0,0 @@ -package info.frostfs.sdk.pool; - -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -public class StatusSnapshot { - private long allTime; - private long allRequests; -} - - diff --git a/client/src/main/java/info/frostfs/sdk/pool/WorkList.java b/client/src/main/java/info/frostfs/sdk/pool/WorkList.java deleted file mode 100644 index 7e7a455..0000000 --- a/client/src/main/java/info/frostfs/sdk/pool/WorkList.java +++ /dev/null @@ -1,22 +0,0 @@ -package info.frostfs.sdk.pool; - -import java.util.ArrayList; -import java.util.List; - -class WorkList { - private final List elements = new ArrayList<>(); - - private int getLength() { - return elements.size(); - } - - private void add(int element) { - elements.add(element); - } - - private int remove() { - int last = elements.get(elements.size() - 1); - elements.remove(elements.size() - 1); - return last; - } -} diff --git a/client/src/main/java/info/frostfs/sdk/pool/WrapperPrm.java b/client/src/main/java/info/frostfs/sdk/pool/WrapperPrm.java deleted file mode 100644 index d03efc4..0000000 --- a/client/src/main/java/info/frostfs/sdk/pool/WrapperPrm.java +++ /dev/null @@ -1,26 +0,0 @@ -package info.frostfs.sdk.pool; - -import info.frostfs.sdk.jdo.ECDsa; -import io.grpc.ClientInterceptors; -import io.grpc.ManagedChannelBuilder; -import lombok.Getter; -import lombok.Setter; -import org.slf4j.Logger; - -import java.util.Collection; - -@Getter -@Setter -public class WrapperPrm { - private Logger logger; - private String address; - private ECDsa key; - private long dialTimeout; - private long streamTimeout; - private int errorThreshold; - private Runnable responseInfoCallback; - private Runnable poolRequestInfoCallback; - private ManagedChannelBuilder grpcChannelOptions; - private long gracefulCloseOnSwitchTimeout; - private Collection interceptors; -} diff --git a/client/src/main/java/info/frostfs/sdk/services/AccountingClient.java b/client/src/main/java/info/frostfs/sdk/services/AccountingClient.java deleted file mode 100644 index 28c2516..0000000 --- a/client/src/main/java/info/frostfs/sdk/services/AccountingClient.java +++ /dev/null @@ -1,8 +0,0 @@ -package info.frostfs.sdk.services; - -import frostfs.accounting.Types; -import info.frostfs.sdk.jdo.parameters.CallContext; - -public interface AccountingClient { - Types.Decimal getBalance(CallContext ctx); -} diff --git a/client/src/main/java/info/frostfs/sdk/services/ApeManagerClient.java b/client/src/main/java/info/frostfs/sdk/services/ApeManagerClient.java deleted file mode 100644 index 47d7827..0000000 --- a/client/src/main/java/info/frostfs/sdk/services/ApeManagerClient.java +++ /dev/null @@ -1,17 +0,0 @@ -package info.frostfs.sdk.services; - -import info.frostfs.sdk.dto.ape.Chain; -import info.frostfs.sdk.jdo.parameters.CallContext; -import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainAdd; -import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainList; -import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainRemove; - -import java.util.List; - -public interface ApeManagerClient { - byte[] addChain(PrmApeChainAdd args, CallContext ctx); - - void removeChain(PrmApeChainRemove args, CallContext ctx); - - List listChains(PrmApeChainList args, CallContext ctx); -} diff --git a/client/src/main/java/info/frostfs/sdk/services/CommonClient.java b/client/src/main/java/info/frostfs/sdk/services/CommonClient.java deleted file mode 100644 index ce0dcba..0000000 --- a/client/src/main/java/info/frostfs/sdk/services/CommonClient.java +++ /dev/null @@ -1,9 +0,0 @@ -package info.frostfs.sdk.services; - -import info.frostfs.sdk.jdo.parameters.CallContext; - -public interface CommonClient extends - AccountingClient, ApeManagerClient, ContainerClient, NetmapClient, ObjectClient, SessionClient, ToolsClient { - - String dial(CallContext ctx); -} diff --git a/client/src/main/java/info/frostfs/sdk/services/ContainerClient.java b/client/src/main/java/info/frostfs/sdk/services/ContainerClient.java deleted file mode 100644 index 121bc80..0000000 --- a/client/src/main/java/info/frostfs/sdk/services/ContainerClient.java +++ /dev/null @@ -1,21 +0,0 @@ -package info.frostfs.sdk.services; - -import info.frostfs.sdk.dto.container.Container; -import info.frostfs.sdk.dto.container.ContainerId; -import info.frostfs.sdk.jdo.parameters.CallContext; -import info.frostfs.sdk.jdo.parameters.container.PrmContainerCreate; -import info.frostfs.sdk.jdo.parameters.container.PrmContainerDelete; -import info.frostfs.sdk.jdo.parameters.container.PrmContainerGet; -import info.frostfs.sdk.jdo.parameters.container.PrmContainerGetAll; - -import java.util.List; - -public interface ContainerClient { - Container getContainer(PrmContainerGet args, CallContext ctx); - - List listContainers(PrmContainerGetAll args, CallContext ctx); - - ContainerId createContainer(PrmContainerCreate args, CallContext ctx); - - void deleteContainer(PrmContainerDelete args, CallContext ctx); -} diff --git a/client/src/main/java/info/frostfs/sdk/services/ContextAccessor.java b/client/src/main/java/info/frostfs/sdk/services/ContextAccessor.java deleted file mode 100644 index 8663d53..0000000 --- a/client/src/main/java/info/frostfs/sdk/services/ContextAccessor.java +++ /dev/null @@ -1,13 +0,0 @@ -package info.frostfs.sdk.services; - -import info.frostfs.sdk.jdo.ClientEnvironment; -import lombok.Getter; - -@Getter -public class ContextAccessor { - private final ClientEnvironment context; - - public ContextAccessor(ClientEnvironment context) { - this.context = context; - } -} diff --git a/client/src/main/java/info/frostfs/sdk/services/NetmapClient.java b/client/src/main/java/info/frostfs/sdk/services/NetmapClient.java deleted file mode 100644 index 067c836..0000000 --- a/client/src/main/java/info/frostfs/sdk/services/NetmapClient.java +++ /dev/null @@ -1,14 +0,0 @@ -package info.frostfs.sdk.services; - -import info.frostfs.sdk.dto.netmap.NetmapSnapshot; -import info.frostfs.sdk.dto.netmap.NodeInfo; -import info.frostfs.sdk.jdo.NetworkSettings; -import info.frostfs.sdk.jdo.parameters.CallContext; - -public interface NetmapClient { - NetmapSnapshot getNetmapSnapshot(CallContext ctx); - - NodeInfo getLocalNodeInfo(CallContext ctx); - - NetworkSettings getNetworkSettings(CallContext ctx); -} diff --git a/client/src/main/java/info/frostfs/sdk/services/ObjectClient.java b/client/src/main/java/info/frostfs/sdk/services/ObjectClient.java deleted file mode 100644 index 5e8362c..0000000 --- a/client/src/main/java/info/frostfs/sdk/services/ObjectClient.java +++ /dev/null @@ -1,34 +0,0 @@ -package info.frostfs.sdk.services; - -import info.frostfs.sdk.dto.object.ObjectFrostFS; -import info.frostfs.sdk.dto.object.ObjectId; -import info.frostfs.sdk.jdo.parameters.CallContext; -import info.frostfs.sdk.jdo.parameters.object.*; -import info.frostfs.sdk.jdo.parameters.object.patch.PrmObjectPatch; -import info.frostfs.sdk.jdo.parameters.object.patch.PrmRangeGet; -import info.frostfs.sdk.jdo.parameters.object.patch.PrmRangeHashGet; -import info.frostfs.sdk.jdo.result.ObjectHeaderResult; -import info.frostfs.sdk.services.impl.rwhelper.ObjectWriter; -import info.frostfs.sdk.services.impl.rwhelper.RangeReader; - -public interface ObjectClient { - ObjectHeaderResult getObjectHead(PrmObjectHeadGet args, CallContext ctx); - - ObjectFrostFS getObject(PrmObjectGet args, CallContext ctx); - - ObjectWriter putObject(PrmObjectPut args, CallContext ctx); - - ObjectId putClientCutObject(PrmObjectClientCutPut args, CallContext ctx); - - ObjectId putSingleObject(PrmObjectSinglePut args, CallContext ctx); - - void deleteObject(PrmObjectDelete args, CallContext ctx); - - Iterable searchObjects(PrmObjectSearch args, CallContext ctx); - - RangeReader getRange(PrmRangeGet args, CallContext ctx); - - byte[][] getRangeHash(PrmRangeHashGet args, CallContext ctx); - - ObjectId patchObject(PrmObjectPatch args, CallContext ctx); -} diff --git a/client/src/main/java/info/frostfs/sdk/services/SessionClient.java b/client/src/main/java/info/frostfs/sdk/services/SessionClient.java deleted file mode 100644 index 4e5f0a9..0000000 --- a/client/src/main/java/info/frostfs/sdk/services/SessionClient.java +++ /dev/null @@ -1,9 +0,0 @@ -package info.frostfs.sdk.services; - -import info.frostfs.sdk.dto.session.SessionToken; -import info.frostfs.sdk.jdo.parameters.CallContext; -import info.frostfs.sdk.jdo.parameters.session.PrmSessionCreate; - -public interface SessionClient { - SessionToken createSession(PrmSessionCreate args, CallContext ctx); -} diff --git a/client/src/main/java/info/frostfs/sdk/services/SessionTools.java b/client/src/main/java/info/frostfs/sdk/services/SessionTools.java deleted file mode 100644 index b389235..0000000 --- a/client/src/main/java/info/frostfs/sdk/services/SessionTools.java +++ /dev/null @@ -1,9 +0,0 @@ -package info.frostfs.sdk.services; - -import info.frostfs.sdk.dto.session.SessionToken; -import info.frostfs.sdk.jdo.ClientEnvironment; -import info.frostfs.sdk.jdo.parameters.CallContext; - -public interface SessionTools { - SessionToken getOrCreateSession(ClientEnvironment env, CallContext ctx); -} diff --git a/client/src/main/java/info/frostfs/sdk/services/ToolsClient.java b/client/src/main/java/info/frostfs/sdk/services/ToolsClient.java deleted file mode 100644 index e8ce342..0000000 --- a/client/src/main/java/info/frostfs/sdk/services/ToolsClient.java +++ /dev/null @@ -1,8 +0,0 @@ -package info.frostfs.sdk.services; - -import info.frostfs.sdk.dto.object.ObjectHeader; -import info.frostfs.sdk.dto.object.ObjectId; - -public interface ToolsClient { - ObjectId calculateObjectId(ObjectHeader header); -} diff --git a/client/src/main/java/info/frostfs/sdk/services/impl/AccountingClientImpl.java b/client/src/main/java/info/frostfs/sdk/services/impl/AccountingClientImpl.java deleted file mode 100644 index 7aee62b..0000000 --- a/client/src/main/java/info/frostfs/sdk/services/impl/AccountingClientImpl.java +++ /dev/null @@ -1,48 +0,0 @@ -package info.frostfs.sdk.services.impl; - -import frostfs.accounting.AccountingServiceGrpc; -import frostfs.accounting.Service; -import frostfs.accounting.Types; -import info.frostfs.sdk.jdo.ClientEnvironment; -import info.frostfs.sdk.jdo.parameters.CallContext; -import info.frostfs.sdk.mappers.object.OwnerIdMapper; -import info.frostfs.sdk.services.AccountingClient; -import info.frostfs.sdk.services.ContextAccessor; -import info.frostfs.sdk.tools.RequestConstructor; -import info.frostfs.sdk.tools.RequestSigner; -import info.frostfs.sdk.tools.Verifier; - -import static info.frostfs.sdk.utils.DeadLineUtil.deadLineAfter; - -public class AccountingClientImpl extends ContextAccessor implements AccountingClient { - private final AccountingServiceGrpc.AccountingServiceBlockingStub serviceBlockingStub; - - public AccountingClientImpl(ClientEnvironment clientEnvironment) { - super(clientEnvironment); - this.serviceBlockingStub = AccountingServiceGrpc.newBlockingStub(getContext().getChannel()); - } - - @Override - public Types.Decimal getBalance(CallContext ctx) { - var request = createGetRequest(); - - var service = deadLineAfter(serviceBlockingStub, ctx.getTimeout(), ctx.getTimeUnit()); - var response = service.balance(request); - - Verifier.checkResponse(response); - return response.getBody().getBalance(); - } - - private Service.BalanceRequest createGetRequest() { - var body = Service.BalanceRequest.Body.newBuilder() - .setOwnerId(OwnerIdMapper.toGrpcMessage(getContext().getOwnerId())) - .build(); - var request = Service.BalanceRequest.newBuilder() - .setBody(body); - - RequestConstructor.addMetaHeader(request); - RequestSigner.sign(request, getContext().getKey()); - - return request.build(); - } -} diff --git a/client/src/main/java/info/frostfs/sdk/services/impl/ApeManagerClientImpl.java b/client/src/main/java/info/frostfs/sdk/services/impl/ApeManagerClientImpl.java deleted file mode 100644 index 6e10fe3..0000000 --- a/client/src/main/java/info/frostfs/sdk/services/impl/ApeManagerClientImpl.java +++ /dev/null @@ -1,123 +0,0 @@ -package info.frostfs.sdk.services.impl; - -import com.google.protobuf.ByteString; -import frostfs.ape.Types; -import frostfs.apemanager.APEManagerServiceGrpc; -import frostfs.apemanager.Service; -import info.frostfs.sdk.dto.ape.Chain; -import info.frostfs.sdk.jdo.ClientEnvironment; -import info.frostfs.sdk.jdo.parameters.CallContext; -import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainAdd; -import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainList; -import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainRemove; -import info.frostfs.sdk.mappers.chain.ChainTargetMapper; -import info.frostfs.sdk.services.ApeManagerClient; -import info.frostfs.sdk.services.ContextAccessor; -import info.frostfs.sdk.tools.RequestConstructor; -import info.frostfs.sdk.tools.RequestSigner; -import info.frostfs.sdk.tools.Verifier; -import info.frostfs.sdk.tools.ape.RuleDeserializer; -import info.frostfs.sdk.tools.ape.RuleSerializer; - -import java.util.List; -import java.util.stream.Collectors; - -import static info.frostfs.sdk.utils.DeadLineUtil.deadLineAfter; -import static info.frostfs.sdk.utils.Validator.validate; - -public class ApeManagerClientImpl extends ContextAccessor implements ApeManagerClient { - private final APEManagerServiceGrpc.APEManagerServiceBlockingStub apeManagerServiceClient; - - public ApeManagerClientImpl(ClientEnvironment clientEnvironment) { - super(clientEnvironment); - this.apeManagerServiceClient = APEManagerServiceGrpc.newBlockingStub(getContext().getChannel()); - } - - @Override - public byte[] addChain(PrmApeChainAdd args, CallContext ctx) { - validate(args); - - var request = createAddChainRequest(args); - - var service = deadLineAfter(apeManagerServiceClient, ctx.getTimeout(), ctx.getTimeUnit()); - var response = service.addChain(request); - - Verifier.checkResponse(response); - - return response.getBody().getChainId().toByteArray(); - } - - @Override - public void removeChain(PrmApeChainRemove args, CallContext ctx) { - validate(args); - - var request = createRemoveChainRequest(args); - - var service = deadLineAfter(apeManagerServiceClient, ctx.getTimeout(), ctx.getTimeUnit()); - var response = service.removeChain(request); - - Verifier.checkResponse(response); - } - - @Override - public List listChains(PrmApeChainList args, CallContext ctx) { - validate(args); - - var request = createListChainsRequest(args); - - var service = deadLineAfter(apeManagerServiceClient, ctx.getTimeout(), ctx.getTimeUnit()); - var response = service.listChains(request); - - Verifier.checkResponse(response); - - return response.getBody().getChainsList().stream() - .map(chain -> RuleDeserializer.deserialize(chain.getRaw().toByteArray())) - .collect(Collectors.toList()); - } - - private Service.AddChainRequest createAddChainRequest(PrmApeChainAdd args) { - var raw = RuleSerializer.serialize(args.getChain()); - - var chainGrpc = Types.Chain.newBuilder() - .setRaw(ByteString.copyFrom(raw)) - .build(); - var body = Service.AddChainRequest.Body.newBuilder() - .setChain(chainGrpc) - .setTarget(ChainTargetMapper.toGrpcMessage(args.getChainTarget())) - .build(); - var request = Service.AddChainRequest.newBuilder() - .setBody(body); - - RequestConstructor.addMetaHeader(request, args.getXHeaders()); - RequestSigner.sign(request, getContext().getKey()); - - return request.build(); - } - - private Service.RemoveChainRequest createRemoveChainRequest(PrmApeChainRemove args) { - var body = Service.RemoveChainRequest.Body.newBuilder() - .setChainId(ByteString.copyFrom(args.getChainId())) - .setTarget(ChainTargetMapper.toGrpcMessage(args.getChainTarget())) - .build(); - var request = Service.RemoveChainRequest.newBuilder() - .setBody(body); - - RequestConstructor.addMetaHeader(request, args.getXHeaders()); - RequestSigner.sign(request, getContext().getKey()); - - return request.build(); - } - - private Service.ListChainsRequest createListChainsRequest(PrmApeChainList args) { - var body = Service.ListChainsRequest.Body.newBuilder() - .setTarget(ChainTargetMapper.toGrpcMessage(args.getChainTarget())) - .build(); - var request = Service.ListChainsRequest.newBuilder() - .setBody(body); - - RequestConstructor.addMetaHeader(request, args.getXHeaders()); - RequestSigner.sign(request, getContext().getKey()); - - return request.build(); - } -} diff --git a/client/src/main/java/info/frostfs/sdk/services/impl/ContainerClientImpl.java b/client/src/main/java/info/frostfs/sdk/services/impl/ContainerClientImpl.java deleted file mode 100644 index 7e32ca1..0000000 --- a/client/src/main/java/info/frostfs/sdk/services/impl/ContainerClientImpl.java +++ /dev/null @@ -1,253 +0,0 @@ -package info.frostfs.sdk.services.impl; - -import frostfs.container.ContainerServiceGrpc; -import frostfs.container.Service; -import frostfs.refs.Types; -import info.frostfs.sdk.dto.container.Container; -import info.frostfs.sdk.dto.container.ContainerId; -import info.frostfs.sdk.dto.session.SessionToken; -import info.frostfs.sdk.enums.StatusCode; -import info.frostfs.sdk.enums.WaitExpects; -import info.frostfs.sdk.exceptions.ResponseFrostFSException; -import info.frostfs.sdk.exceptions.TimeoutFrostFSException; -import info.frostfs.sdk.jdo.ClientEnvironment; -import info.frostfs.sdk.jdo.parameters.CallContext; -import info.frostfs.sdk.jdo.parameters.PrmWait; -import info.frostfs.sdk.jdo.parameters.container.PrmContainerCreate; -import info.frostfs.sdk.jdo.parameters.container.PrmContainerDelete; -import info.frostfs.sdk.jdo.parameters.container.PrmContainerGet; -import info.frostfs.sdk.jdo.parameters.container.PrmContainerGetAll; -import info.frostfs.sdk.jdo.parameters.session.SessionContext; -import info.frostfs.sdk.mappers.container.ContainerIdMapper; -import info.frostfs.sdk.mappers.container.ContainerMapper; -import info.frostfs.sdk.mappers.netmap.VersionMapper; -import info.frostfs.sdk.mappers.object.OwnerIdMapper; -import info.frostfs.sdk.services.ContainerClient; -import info.frostfs.sdk.services.ContextAccessor; -import info.frostfs.sdk.tools.RequestConstructor; -import info.frostfs.sdk.tools.RequestSigner; -import info.frostfs.sdk.tools.Verifier; -import info.frostfs.sdk.utils.WaitUtil; - -import java.time.LocalDateTime; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import static info.frostfs.sdk.constants.AttributeConst.DISABLE_HOMOMORPHIC_HASHING_ATTRIBUTE; -import static info.frostfs.sdk.utils.DeadLineUtil.deadLineAfter; -import static info.frostfs.sdk.utils.Validator.validate; -import static java.util.Objects.isNull; -import static java.util.Objects.nonNull; - -public class ContainerClientImpl extends ContextAccessor implements ContainerClient { - private final ContainerServiceGrpc.ContainerServiceBlockingStub serviceBlockingStub; - private final SessionToolsImpl sessionTools; - - public ContainerClientImpl(ClientEnvironment clientEnvironment) { - super(clientEnvironment); - this.serviceBlockingStub = ContainerServiceGrpc.newBlockingStub(clientEnvironment.getChannel()); - this.sessionTools = new SessionToolsImpl(clientEnvironment); - } - - public SessionToken getOrCreateSession(SessionContext sessionContext, CallContext ctx) { - return isNull(sessionContext.getSessionToken()) - ? sessionTools.getOrCreateSession(getContext(), ctx) - : sessionContext.getSessionToken(); - } - - @Override - public Container getContainer(PrmContainerGet args, CallContext ctx) { - validate(args); - - var request = createGetRequest(args); - - var service = deadLineAfter(serviceBlockingStub, ctx.getTimeout(), ctx.getTimeUnit()); - var response = service.get(request); - - Verifier.checkResponse(response); - return ContainerMapper.toModel(response.getBody().getContainer()); - } - - @Override - public List listContainers(PrmContainerGetAll args, CallContext ctx) { - validate(args); - - var request = createListRequest(args); - - var service = deadLineAfter(serviceBlockingStub, ctx.getTimeout(), ctx.getTimeUnit()); - var response = service.list(request); - - Verifier.checkResponse(response); - - return response.getBody().getContainerIdsList().stream() - .map(cid -> new ContainerId(cid.getValue().toByteArray())) - .collect(Collectors.toList()); - } - - @Override - public ContainerId createContainer(PrmContainerCreate args, CallContext ctx) { - validate(args); - - var request = createPutRequest(args, ctx); - - var service = deadLineAfter(serviceBlockingStub, ctx.getTimeout(), ctx.getTimeUnit()); - var response = service.put(request); - - Verifier.checkResponse(response); - - waitForContainer(WaitExpects.EXISTS, response.getBody().getContainerId(), args.getWaitParams()); - - return new ContainerId(response.getBody().getContainerId().getValue().toByteArray()); - } - - @Override - public void deleteContainer(PrmContainerDelete args, CallContext ctx) { - validate(args); - - var request = createDeleteRequest(args, ctx); - - var service = deadLineAfter(serviceBlockingStub, ctx.getTimeout(), ctx.getTimeUnit()); - var response = service.delete(request); - - Verifier.checkResponse(response); - - waitForContainer(WaitExpects.REMOVED, request.getBody().getContainerId(), args.getWaitParams()); - } - - private void waitForContainer(WaitExpects expect, Types.ContainerID cid, PrmWait waitParams) { - var request = createGetRequest(cid, null); - - waitParams = isNull(waitParams) ? new PrmWait() : waitParams; - var deadLine = waitParams.getDeadline(); - - while (true) { - try { - var response = serviceBlockingStub.get(request); - Verifier.checkResponse(response); - - if (expect == WaitExpects.EXISTS) { - break; - } - - if (LocalDateTime.now().isAfter(deadLine)) { - throw new TimeoutFrostFSException(); - } - - WaitUtil.sleep(waitParams.getPollInterval().toMillis()); - } catch (ResponseFrostFSException exp) { - if (LocalDateTime.now().isAfter(deadLine)) { - throw new TimeoutFrostFSException(); - } - - if (exp.getStatus().getCode() != StatusCode.CONTAINER_NOT_FOUND) { - throw exp; - } - - if (expect == WaitExpects.REMOVED) { - break; - } - - WaitUtil.sleep(waitParams.getPollInterval().toMillis()); - } - } - } - - private Service.GetRequest createGetRequest(PrmContainerGet args) { - var cid = ContainerIdMapper.toGrpcMessage(args.getContainerId()); - return createGetRequest(cid, args.getXHeaders()); - } - - private Service.GetRequest createGetRequest(Types.ContainerID cid, Map xHeaders) { - var body = Service.GetRequest.Body.newBuilder() - .setContainerId(cid) - .build(); - var request = Service.GetRequest.newBuilder() - .setBody(body); - - RequestConstructor.addMetaHeader(request, xHeaders); - RequestSigner.sign(request, getContext().getKey()); - - return request.build(); - } - - private Service.ListRequest createListRequest(PrmContainerGetAll args) { - var body = Service.ListRequest.Body.newBuilder() - .setOwnerId(OwnerIdMapper.toGrpcMessage(getContext().getOwnerId())) - .build(); - var request = Service.ListRequest.newBuilder() - .setBody(body); - - RequestConstructor.addMetaHeader(request, args.getXHeaders()); - RequestSigner.sign(request, getContext().getKey()); - - return request.build(); - } - - private Service.PutRequest createPutRequest(PrmContainerCreate args, CallContext ctx) { - syncContainerWithNetwork(args.getContainer(), ctx); - var builder = ContainerMapper.toGrpcMessage(args.getContainer()); - if (!builder.hasOwnerId()) { - builder.setOwnerId(OwnerIdMapper.toGrpcMessage(getContext().getOwnerId())); - } - if (!builder.hasVersion()) { - builder.setVersion(VersionMapper.toGrpcMessage(getContext().getVersion())); - } - - var container = builder.build(); - var body = Service.PutRequest.Body.newBuilder() - .setContainer(container) - .setSignature(RequestSigner.signRFC6979(getContext().getKey(), container)) - .build(); - var request = Service.PutRequest.newBuilder() - .setBody(body); - - var sessionToken = getOrCreateSession(args, ctx); - var protoToken = RequestConstructor.createContainerTokenContext( - sessionToken, - null, - frostfs.session.Types.ContainerSessionContext.Verb.PUT, - container.getOwnerId(), - getContext().getKey() - ); - - RequestConstructor.addMetaHeader(request, args.getXHeaders(), protoToken); - RequestSigner.sign(request, getContext().getKey()); - - return request.build(); - } - - private Service.DeleteRequest createDeleteRequest(PrmContainerDelete args, CallContext ctx) { - var cid = ContainerIdMapper.toGrpcMessage(args.getContainerId()); - - var body = Service.DeleteRequest.Body.newBuilder() - .setContainerId(cid) - .setSignature(RequestSigner.signRFC6979(getContext().getKey(), cid.getValue())) - .build(); - var request = Service.DeleteRequest.newBuilder() - .setBody(body); - - var sessionToken = getOrCreateSession(args, ctx); - var protoToken = RequestConstructor.createContainerTokenContext( - sessionToken, - null, - frostfs.session.Types.ContainerSessionContext.Verb.DELETE, - null, - getContext().getKey() - ); - - RequestConstructor.addMetaHeader(request, args.getXHeaders(), protoToken); - RequestSigner.sign(request, getContext().getKey()); - - return request.build(); - } - - private void syncContainerWithNetwork(Container container, CallContext callContext) { - var settings = getContext().getFrostFSClient().getNetworkSettings(callContext); - if (nonNull(settings.getHomomorphicHashingDisabled()) && settings.getHomomorphicHashingDisabled()) { - container.getAttributes().put(DISABLE_HOMOMORPHIC_HASHING_ATTRIBUTE, Boolean.TRUE.toString()); - } else { - container.getAttributes().remove(DISABLE_HOMOMORPHIC_HASHING_ATTRIBUTE, Boolean.TRUE.toString()); - } - } -} diff --git a/client/src/main/java/info/frostfs/sdk/services/impl/NetmapClientImpl.java b/client/src/main/java/info/frostfs/sdk/services/impl/NetmapClientImpl.java deleted file mode 100644 index a32abac..0000000 --- a/client/src/main/java/info/frostfs/sdk/services/impl/NetmapClientImpl.java +++ /dev/null @@ -1,160 +0,0 @@ -package info.frostfs.sdk.services.impl; - -import frostfs.netmap.NetmapServiceGrpc; -import frostfs.netmap.Service; -import frostfs.netmap.Types; -import info.frostfs.sdk.dto.netmap.NetmapSnapshot; -import info.frostfs.sdk.dto.netmap.NodeInfo; -import info.frostfs.sdk.jdo.ClientEnvironment; -import info.frostfs.sdk.jdo.NetworkSettings; -import info.frostfs.sdk.jdo.parameters.CallContext; -import info.frostfs.sdk.mappers.netmap.NetmapSnapshotMapper; -import info.frostfs.sdk.mappers.netmap.NodeInfoMapper; -import info.frostfs.sdk.services.ContextAccessor; -import info.frostfs.sdk.services.NetmapClient; -import info.frostfs.sdk.tools.RequestConstructor; -import info.frostfs.sdk.tools.Verifier; - -import java.nio.charset.StandardCharsets; - -import static info.frostfs.sdk.tools.RequestSigner.sign; -import static info.frostfs.sdk.utils.DeadLineUtil.deadLineAfter; -import static java.util.Objects.nonNull; - -public class NetmapClientImpl extends ContextAccessor implements NetmapClient { - private final NetmapServiceGrpc.NetmapServiceBlockingStub netmapServiceClient; - - public NetmapClientImpl(ClientEnvironment clientEnvironment) { - super(clientEnvironment); - this.netmapServiceClient = NetmapServiceGrpc.newBlockingStub(getContext().getChannel()); - } - - private static boolean getBoolValue(byte[] bytes) { - for (var byteValue : bytes) { - if (byteValue != 0) { - return true; - } - } - - return false; - } - - private static long getLongValue(byte[] bytes) { - long val = 0; - for (var i = bytes.length - 1; i >= 0; i--) { - val = (val << Byte.SIZE) + bytes[i]; - } - - return val; - } - - private static void setNetworksParam(Types.NetworkConfig.Parameter param, NetworkSettings settings) { - var key = new String(param.getKey().toByteArray(), StandardCharsets.UTF_8); - - var valueBytes = param.getValue().toByteArray(); - switch (key) { - case "AuditFee": - settings.setAuditFee(getLongValue(valueBytes)); - break; - case "BasicIncomeRate": - settings.setBasicIncomeRate(getLongValue(valueBytes)); - break; - case "ContainerFee": - settings.setContainerFee(getLongValue(valueBytes)); - break; - case "ContainerAliasFee": - settings.setContainerAliasFee(getLongValue(valueBytes)); - break; - case "EpochDuration": - settings.setEpochDuration(getLongValue(valueBytes)); - break; - case "InnerRingCandidateFee": - settings.setIRCandidateFee(getLongValue(valueBytes)); - break; - case "MaxECDataCount": - settings.setMaxECDataCount(getLongValue(valueBytes)); - break; - case "MaxECParityCount": - settings.setMaxECParityCount(getLongValue(valueBytes)); - break; - case "MaxObjectSize": - settings.setMaxObjectSize(getLongValue(valueBytes)); - break; - case "WithdrawFee": - settings.setWithdrawalFee(getLongValue(valueBytes)); - break; - case "HomomorphicHashingDisabled": - settings.setHomomorphicHashingDisabled(getBoolValue(valueBytes)); - break; - case "MaintenanceModeAllowed": - settings.setMaintenanceModeAllowed(getBoolValue(valueBytes)); - break; - default: - settings.getUnnamedSettings().put(key, valueBytes); - break; - } - } - - @Override - public NetworkSettings getNetworkSettings(CallContext ctx) { - if (nonNull(getContext().getNetworkSettings())) { - return getContext().getNetworkSettings(); - } - - var info = getNetworkInfo(ctx); - - var settings = new NetworkSettings(); - - for (var param : info.getBody().getNetworkInfo().getNetworkConfig().getParametersList()) { - setNetworksParam(param, settings); - } - - getContext().setNetworkSettings(settings); - - return settings; - } - - @Override - public NodeInfo getLocalNodeInfo(CallContext ctx) { - var request = Service.LocalNodeInfoRequest.newBuilder(); - - RequestConstructor.addMetaHeader(request); - sign(request, getContext().getKey()); - - var service = deadLineAfter(netmapServiceClient, ctx.getTimeout(), ctx.getTimeUnit()); - var response = service.localNodeInfo(request.build()); - - Verifier.checkResponse(response); - - return NodeInfoMapper.toModel(response.getBody()); - } - - public Service.NetworkInfoResponse getNetworkInfo(CallContext ctx) { - var request = Service.NetworkInfoRequest.newBuilder(); - - RequestConstructor.addMetaHeader(request); - sign(request, getContext().getKey()); - - var service = deadLineAfter(netmapServiceClient, ctx.getTimeout(), ctx.getTimeUnit()); - var response = service.networkInfo(request.build()); - - Verifier.checkResponse(response); - - return response; - } - - @Override - public NetmapSnapshot getNetmapSnapshot(CallContext ctx) { - var request = Service.NetmapSnapshotRequest.newBuilder(); - - RequestConstructor.addMetaHeader(request); - sign(request, getContext().getKey()); - - var service = deadLineAfter(netmapServiceClient, ctx.getTimeout(), ctx.getTimeUnit()); - var response = service.netmapSnapshot(request.build()); - - Verifier.checkResponse(response); - - return NetmapSnapshotMapper.toModel(response); - } -} diff --git a/client/src/main/java/info/frostfs/sdk/services/impl/ObjectClientImpl.java b/client/src/main/java/info/frostfs/sdk/services/impl/ObjectClientImpl.java deleted file mode 100644 index 71741e8..0000000 --- a/client/src/main/java/info/frostfs/sdk/services/impl/ObjectClientImpl.java +++ /dev/null @@ -1,668 +0,0 @@ -package info.frostfs.sdk.services.impl; - -import com.google.common.collect.Iterables; -import com.google.protobuf.ByteString; -import frostfs.object.ObjectServiceGrpc; -import frostfs.object.Service; -import frostfs.refs.Types; -import info.frostfs.sdk.constants.AppConst; -import info.frostfs.sdk.dto.object.*; -import info.frostfs.sdk.dto.session.SessionToken; -import info.frostfs.sdk.enums.ObjectType; -import info.frostfs.sdk.exceptions.ProcessFrostFSException; -import info.frostfs.sdk.jdo.ClientEnvironment; -import info.frostfs.sdk.jdo.PutObjectResult; -import info.frostfs.sdk.jdo.parameters.CallContext; -import info.frostfs.sdk.jdo.parameters.object.*; -import info.frostfs.sdk.jdo.parameters.object.patch.PrmObjectPatch; -import info.frostfs.sdk.jdo.parameters.object.patch.PrmRangeGet; -import info.frostfs.sdk.jdo.parameters.object.patch.PrmRangeHashGet; -import info.frostfs.sdk.jdo.parameters.session.SessionContext; -import info.frostfs.sdk.jdo.result.ObjectHeaderResult; -import info.frostfs.sdk.mappers.container.ContainerIdMapper; -import info.frostfs.sdk.mappers.object.*; -import info.frostfs.sdk.mappers.object.patch.AddressMapper; -import info.frostfs.sdk.mappers.object.patch.RangeMapper; -import info.frostfs.sdk.services.ContextAccessor; -import info.frostfs.sdk.services.ObjectClient; -import info.frostfs.sdk.services.impl.rwhelper.*; -import info.frostfs.sdk.tools.RequestConstructor; -import info.frostfs.sdk.tools.Verifier; -import org.apache.commons.collections4.CollectionUtils; - -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; - -import static info.frostfs.sdk.constants.ErrorConst.PROTO_MESSAGE_IS_EMPTY_TEMPLATE; -import static info.frostfs.sdk.tools.RequestSigner.sign; -import static info.frostfs.sdk.utils.DeadLineUtil.deadLineAfter; -import static info.frostfs.sdk.utils.Validator.validate; -import static java.util.Objects.isNull; -import static java.util.Objects.nonNull; - -public class ObjectClientImpl extends ContextAccessor implements ObjectClient { - private final ObjectServiceGrpc.ObjectServiceBlockingStub objectServiceBlockingClient; - private final ObjectServiceGrpc.ObjectServiceStub objectServiceClient; - private final ObjectToolsImpl objectToolsImpl; - private final SessionToolsImpl sessionTools; - - public ObjectClientImpl(ClientEnvironment clientEnvironment) { - super(clientEnvironment); - this.objectServiceBlockingClient = ObjectServiceGrpc.newBlockingStub(getContext().getChannel()); - this.objectServiceClient = ObjectServiceGrpc.newStub(getContext().getChannel()); - this.objectToolsImpl = new ObjectToolsImpl(clientEnvironment); - this.sessionTools = new SessionToolsImpl(clientEnvironment); - } - - public SessionToken getOrCreateSession(SessionContext sessionContext, CallContext ctx) { - return isNull(sessionContext.getSessionToken()) - ? sessionTools.getOrCreateSession(getContext(), ctx) - : sessionContext.getSessionToken(); - } - - @Override - public ObjectHeaderResult getObjectHead(PrmObjectHeadGet args, CallContext ctx) { - validate(args); - - var request = createHeadRequest(args, ctx); - - var service = deadLineAfter(objectServiceBlockingClient, ctx.getTimeout(), ctx.getTimeUnit()); - var response = service.head(request); - - Verifier.checkResponse(response); - - return ObjectHeaderResult.builder() - .headerInfo(ObjectHeaderMapper.toModel(response.getBody().getHeader().getHeader())) - .splitInfo(SplitInfoMapper.toModel(response.getBody().getSplitInfo())) - .build(); - } - - @Override - public ObjectFrostFS getObject(PrmObjectGet args, CallContext ctx) { - validate(args); - - var request = createGetRequest(args, ctx); - - return getObject(request, ctx); - } - - @Override - public void deleteObject(PrmObjectDelete args, CallContext ctx) { - validate(args); - - var request = createDeleteRequest(args, ctx); - - var service = deadLineAfter(objectServiceBlockingClient, ctx.getTimeout(), ctx.getTimeUnit()); - var response = service.delete(request); - - Verifier.checkResponse(response); - } - - @Override - public Iterable searchObjects(PrmObjectSearch args, CallContext ctx) { - validate(args); - - var request = createSearchRequest(args, ctx); - - var objectsIds = searchObjects(request, ctx); - - return Iterables.transform(objectsIds, input -> new ObjectId(input.getValue().toByteArray())); - } - - @Override - public ObjectWriter putObject(PrmObjectPut args, CallContext ctx) { - validate(args); - - return new ObjectWriter(getContext(), args, getUploadStream(args, ctx)); - } - - @Override - public ObjectId putClientCutObject(PrmObjectClientCutPut args, CallContext ctx) { - validate(args); - - var header = args.getObjectHeader(); - var fullLength = header.getPayloadLength() == 0 ? getStreamSize(args.getPayload()) : header.getPayloadLength(); - args.getPutObjectContext().setFullLength(fullLength); - - if (args.getPutObjectContext().getMaxObjectSizeCache() == 0) { - var networkSettings = getContext().getFrostFSClient().getNetworkSettings(ctx); - args.getPutObjectContext().setMaxObjectSizeCache(networkSettings.getMaxObjectSize().intValue()); - } - - var restBytes = fullLength - args.getPutObjectContext().getCurrentStreamPosition(); - var objectSize = restBytes > 0 - ? Math.min(args.getPutObjectContext().getMaxObjectSizeCache(), restBytes) - : args.getPutObjectContext().getMaxObjectSizeCache(); - - //define collection capacity - var restPart = (restBytes % objectSize) > 0 ? 1 : 0; - var objectsCount = fullLength > 0 ? (int) (restBytes / objectSize) + restPart : 0; - - List sentObjectIds = new ArrayList<>(objectsCount); - - // keep attributes for the large object - var attributes = args.getObjectHeader().getAttributes(); - - Split split = new Split(); - args.getObjectHeader().setAttributes(new ArrayList<>()); - - // send all parts except the last one as separate Objects - while (restBytes > (long) args.getPutObjectContext().getMaxObjectSizeCache()) { - var previous = CollectionUtils.isNotEmpty(sentObjectIds) - ? sentObjectIds.get(sentObjectIds.size() - 1) - : null; - split.setPrevious(previous); - args.getObjectHeader().setSplit(split); - - var result = putMultipartStreamObject(args, ctx); - - sentObjectIds.add(result.getObjectId()); - - restBytes -= result.getObjectSize(); - } - - // send the last part and create linkObject - if (CollectionUtils.isNotEmpty(sentObjectIds)) { - var largeObjectHeader = new ObjectHeader( - header.getContainerId(), ObjectType.REGULAR, attributes, fullLength, header.getVersion() - ); - largeObjectHeader.setOwnerId(header.getOwnerId()); - - split.setParentHeader(largeObjectHeader); - - var result = putMultipartStreamObject(args, ctx); - - sentObjectIds.add(result.getObjectId()); - - var linkObject = new LinkObject(header.getContainerId(), split.getSplitId(), largeObjectHeader); - linkObject.addChildren(sentObjectIds); - - putSingleObject(new PrmObjectSinglePut(linkObject), ctx); - - return split.getParent(); - } - - // We are here if the payload is placed to one Object. It means no cut action, just simple PUT. - var singlePartResult = putMultipartStreamObject(args, ctx); - - return singlePartResult.getObjectId(); - } - - @Override - public ObjectId putSingleObject(PrmObjectSinglePut args, CallContext ctx) { - var grpcObject = objectToolsImpl.createObject(args.getObjectFrostFS()); - var request = createPutSingleRequest(grpcObject, args, ctx); - - var service = deadLineAfter(objectServiceBlockingClient, ctx.getTimeout(), ctx.getTimeUnit()); - var response = service.putSingle(request); - - Verifier.checkResponse(response); - - return new ObjectId(grpcObject.getObjectId().getValue().toByteArray()); - } - - @Override - public RangeReader getRange(PrmRangeGet args, CallContext ctx) { - validate(args); - - var request = createGetRangeRequest(args, ctx); - - var service = deadLineAfter(objectServiceBlockingClient, ctx.getTimeout(), ctx.getTimeUnit()); - return new RangeReader(service.getRange(request)); - } - - @Override - public byte[][] getRangeHash(PrmRangeHashGet args, CallContext ctx) { - validate(args); - - var request = createGetRangeHashRequest(args, ctx); - - var service = deadLineAfter(objectServiceBlockingClient, ctx.getTimeout(), ctx.getTimeUnit()); - var response = service.getRangeHash(request); - - Verifier.checkResponse(response); - - return response.getBody().getHashListList().stream().map(ByteString::toByteArray).toArray(byte[][]::new); - } - - @Override - public ObjectId patchObject(PrmObjectPatch args, CallContext ctx) { - validate(args); - - var service = deadLineAfter(objectServiceClient, ctx.getTimeout(), ctx.getTimeUnit()); - PatchStreamer writer = new PatchStreamer(service); - - var request = createInitPatchRequest(args, ctx); - writer.write(request.build()); - - if (nonNull(args.getPayload())) { - patchObjectPayload(request, args, writer); - } - - var response = writer.complete(); - - Verifier.checkResponse(response); - - return ObjectIdMapper.toModel(response.getBody().getObjectId()); - } - - private void patchObjectPayload(Service.PatchRequest.Builder request, PrmObjectPatch args, PatchStreamer writer) { - var currentPos = args.getRange().getOffset(); - - var chunkSize = args.getMaxChunkLength() > 0 ? args.getMaxChunkLength() : AppConst.OBJECT_CHUNK_SIZE; - byte[] chunkBuffer = new byte[chunkSize]; - - var bytesCount = readNBytes(args.getPayload(), chunkBuffer, chunkSize); - while (bytesCount > 0) { - var range = Service.Range.newBuilder() - .setOffset(currentPos) - .setLength(bytesCount) - .build(); - - var patch = Service.PatchRequest.Body.Patch.newBuilder() - .setChunk(ByteString.copyFrom(chunkBuffer, 0, bytesCount)) - .setSourceRange(range) - .build(); - - var body = Service.PatchRequest.Body.newBuilder() - .setAddress(request.getBody().getAddress()) - .setPatch(patch) - .build(); - request.setBody(body); - - RequestConstructor.addMetaHeader(request, args.getXHeaders(), request.getMetaHeader().getSessionToken()); - sign(request, getContext().getKey()); - - writer.write(request.build()); - - currentPos += bytesCount; - bytesCount = readNBytes(args.getPayload(), chunkBuffer, chunkSize); - } - } - - private ObjectFrostFS getObject(Service.GetRequest request, CallContext ctx) { - var reader = getObjectInit(request, ctx); - - var grpcObject = reader.readHeader(); - var modelObject = ObjectFrostFSMapper.toModel(grpcObject); - - modelObject.setObjectReader(reader); - - return modelObject; - } - - private ObjectReaderImpl getObjectInit(Service.GetRequest initRequest, CallContext ctx) { - if (initRequest.getSerializedSize() == 0) { - throw new ProcessFrostFSException( - String.format(PROTO_MESSAGE_IS_EMPTY_TEMPLATE, initRequest.getClass().getName()) - ); - } - - var service = deadLineAfter(objectServiceBlockingClient, ctx.getTimeout(), ctx.getTimeUnit()); - return new ObjectReaderImpl(service.get(initRequest)); - } - - private PutObjectResult putMultipartStreamObject(PrmObjectClientCutPut args, CallContext ctx) { - var chunkSize = args.getBufferMaxSize() > 0 ? args.getBufferMaxSize() : AppConst.OBJECT_CHUNK_SIZE; - - var restBytes = - args.getPutObjectContext().getFullLength() - args.getPutObjectContext().getCurrentStreamPosition(); - - chunkSize = (int) Math.min(restBytes, chunkSize); - - byte[] chunkBuffer = args.getCustomerBuffer() != null - ? args.getCustomerBuffer() - : new byte[chunkSize];//todo change to pool - - var sentBytes = 0; - - // 0 means no limit from client, so server side cut is performed - var objectLimitSize = args.getPutObjectContext().getMaxObjectSizeCache(); - - var stream = getUploadStream(args, ctx); - - while (objectLimitSize == 0 || sentBytes < objectLimitSize) { - // send chunks limited to default or user's settings - var bufferSize = objectLimitSize > 0 ? Math.min(objectLimitSize - sentBytes, chunkSize) : chunkSize; - - var bytesCount = readNBytes(args.getPayload(), chunkBuffer, bufferSize); - - if (bytesCount == 0) { - break; - } - - sentBytes += bytesCount; - - var body = Service.PutRequest.Body.newBuilder() - .setChunk(ByteString.copyFrom(chunkBuffer, 0, bytesCount)) - .build(); - var chunkRequest = Service.PutRequest.newBuilder() - .setBody(body) - .clearVerifyHeader(); - - RequestConstructor.addMetaHeader(chunkRequest, args.getXHeaders()); - sign(chunkRequest, getContext().getKey()); - - stream.write(chunkRequest.build()); - } - - var response = stream.complete(); - Verifier.checkResponse(response); - - var objectId = new ObjectId(response.getBody().getObjectId().getValue().toByteArray()); - return new PutObjectResult(objectId, sentBytes); - } - - private ObjectStreamer getUploadStream(PrmObjectPutBase args, CallContext ctx) { - var header = args.getObjectHeader(); - - header.setOwnerId(getContext().getOwnerId()); - header.setVersion(getContext().getVersion()); - - var grpcHeader = ObjectHeaderMapper.toGrpcMessage(header); - - if (nonNull(header.getSplit())) { - grpcHeader = objectToolsImpl.updateSplitValues(grpcHeader, header.getSplit()); - } - - var initRequest = createInitPutRequest(grpcHeader, args, ctx); - - return putObjectInit(initRequest, ctx); - } - - private ObjectStreamer putObjectInit(Service.PutRequest initRequest, CallContext ctx) { - if (initRequest.getSerializedSize() == 0) { - throw new ProcessFrostFSException( - String.format(PROTO_MESSAGE_IS_EMPTY_TEMPLATE, initRequest.getClass().getName()) - ); - } - - var service = deadLineAfter(objectServiceClient, ctx.getTimeout(), ctx.getTimeUnit()); - ObjectStreamer writer = new ObjectStreamer(service); - writer.write(initRequest); - return writer; - } - - private Iterable searchObjects(Service.SearchRequest request, CallContext ctx) { - var reader = getSearchReader(request, ctx); - var ids = reader.read(); - List result = new ArrayList<>(); - - while (CollectionUtils.isNotEmpty(ids)) { - result.addAll(ids); - ids = reader.read(); - } - - return result;//todo return yield - } - - private SearchReader getSearchReader(Service.SearchRequest initRequest, CallContext ctx) { - if (initRequest.getSerializedSize() == 0) { - throw new ProcessFrostFSException( - String.format(PROTO_MESSAGE_IS_EMPTY_TEMPLATE, initRequest.getClass().getName()) - ); - } - - var service = deadLineAfter(objectServiceBlockingClient, ctx.getTimeout(), ctx.getTimeUnit()); - return new SearchReader(service.search(initRequest)); - } - - private int readNBytes(InputStream inputStream, byte[] buffer, int size) { - try { - return inputStream.readNBytes(buffer, 0, size); - } catch (IOException exp) { - throw new ProcessFrostFSException(exp.getMessage()); - } - } - - private long getStreamSize(InputStream inputStream) { - try { - return inputStream.available(); - } catch (IOException exp) { - throw new ProcessFrostFSException(exp.getMessage()); - } - } - - private Service.HeadRequest createHeadRequest(PrmObjectHeadGet args, CallContext ctx) { - var address = Types.Address.newBuilder() - .setContainerId(ContainerIdMapper.toGrpcMessage(args.getContainerId())) - .setObjectId(ObjectIdMapper.toGrpcMessage(args.getObjectId())) - .build(); - var body = Service.HeadRequest.Body.newBuilder() - .setAddress(address) - .setRaw(args.isRaw()) - .build(); - var request = Service.HeadRequest.newBuilder() - .setBody(body); - - var sessionToken = getOrCreateSession(args, ctx); - var protoToken = RequestConstructor.createObjectTokenContext( - sessionToken, - address, - frostfs.session.Types.ObjectSessionContext.Verb.HEAD, - getContext().getKey() - ); - - RequestConstructor.addMetaHeader(request, args.getXHeaders(), protoToken); - sign(request, getContext().getKey()); - - return request.build(); - } - - private Service.GetRequest createGetRequest(PrmObjectGet args, CallContext ctx) { - var address = Types.Address.newBuilder() - .setContainerId(ContainerIdMapper.toGrpcMessage(args.getContainerId())) - .setObjectId(ObjectIdMapper.toGrpcMessage(args.getObjectId())) - .build(); - var body = Service.GetRequest.Body.newBuilder() - .setAddress(address) - .build(); - var request = Service.GetRequest.newBuilder() - .setBody(body); - - var sessionToken = getOrCreateSession(args, ctx); - var protoToken = RequestConstructor.createObjectTokenContext( - sessionToken, - address, - frostfs.session.Types.ObjectSessionContext.Verb.GET, - getContext().getKey() - ); - - RequestConstructor.addMetaHeader(request, args.getXHeaders(), protoToken); - sign(request, getContext().getKey()); - - return request.build(); - } - - private Service.DeleteRequest createDeleteRequest(PrmObjectDelete args, CallContext ctx) { - var address = Types.Address.newBuilder() - .setContainerId(ContainerIdMapper.toGrpcMessage(args.getContainerId())) - .setObjectId(ObjectIdMapper.toGrpcMessage(args.getObjectId())) - .build(); - var body = Service.DeleteRequest.Body.newBuilder() - .setAddress(address) - .build(); - var request = Service.DeleteRequest.newBuilder() - .setBody(body); - - var sessionToken = getOrCreateSession(args, ctx); - var protoToken = RequestConstructor.createObjectTokenContext( - sessionToken, - address, - frostfs.session.Types.ObjectSessionContext.Verb.DELETE, - getContext().getKey() - ); - - RequestConstructor.addMetaHeader(request, args.getXHeaders(), protoToken); - sign(request, getContext().getKey()); - - return request.build(); - } - - private Service.SearchRequest createSearchRequest(PrmObjectSearch args, CallContext ctx) { - var cid = ContainerIdMapper.toGrpcMessage(args.getContainerId()); - - var address = Types.Address.newBuilder() - .setContainerId(cid) - .build(); - - var body = Service.SearchRequest.Body.newBuilder() - .setContainerId(cid) - .setVersion(1);// TODO: clarify this param - - for (ObjectFilter filter : args.getFilters()) { - body.addFilters(ObjectFilterMapper.toGrpcMessage(filter)); - } - - var request = Service.SearchRequest.newBuilder() - .setBody(body.build()); - - var sessionToken = getOrCreateSession(args, ctx); - var protoToken = RequestConstructor.createObjectTokenContext( - sessionToken, - address, - frostfs.session.Types.ObjectSessionContext.Verb.SEARCH, - getContext().getKey() - ); - - RequestConstructor.addMetaHeader(request, args.getXHeaders(), protoToken); - sign(request, getContext().getKey()); - - return request.build(); - } - - private Service.PutRequest createInitPutRequest(frostfs.object.Types.Header header, - PrmObjectPutBase args, - CallContext ctx) { - var address = Types.Address.newBuilder() - .setContainerId(header.getContainerId()) - .build(); - var init = Service.PutRequest.Body.Init.newBuilder() - .setHeader(header) - .build(); - var body = Service.PutRequest.Body.newBuilder() - .setInit(init) - .build(); - var request = Service.PutRequest.newBuilder() - .setBody(body); - - var sessionToken = getOrCreateSession(args, ctx); - var protoToken = RequestConstructor.createObjectTokenContext( - sessionToken, - address, - frostfs.session.Types.ObjectSessionContext.Verb.PUT, - getContext().getKey() - ); - - RequestConstructor.addMetaHeader(request, args.getXHeaders(), protoToken); - sign(request, getContext().getKey()); - - return request.build(); - } - - private Service.PutSingleRequest createPutSingleRequest(frostfs.object.Types.Object grpcObject, - PrmObjectSinglePut args, - CallContext ctx) { - var address = Types.Address.newBuilder() - .setContainerId(grpcObject.getHeader().getContainerId()) - .build(); - var body = Service.PutSingleRequest.Body.newBuilder() - .setObject(grpcObject) - .build(); - var request = Service.PutSingleRequest.newBuilder() - .setBody(body); - - var sessionToken = getOrCreateSession(args, ctx); - var protoToken = RequestConstructor.createObjectTokenContext( - sessionToken, - address, - frostfs.session.Types.ObjectSessionContext.Verb.PUT, - getContext().getKey() - ); - - RequestConstructor.addMetaHeader(request, args.getXHeaders(), protoToken); - sign(request, getContext().getKey()); - - return request.build(); - } - - private Service.GetRangeRequest createGetRangeRequest(PrmRangeGet args, CallContext ctx) { - var address = Types.Address.newBuilder() - .setContainerId(ContainerIdMapper.toGrpcMessage(args.getContainerId())) - .setObjectId(ObjectIdMapper.toGrpcMessage(args.getObjectId())) - .build(); - var body = Service.GetRangeRequest.Body.newBuilder() - .setAddress(address) - .setRange(RangeMapper.toGrpcMessage(args.getRange())) - .setRaw(args.isRaw()) - .build(); - var request = Service.GetRangeRequest.newBuilder() - .setBody(body); - - var sessionToken = getOrCreateSession(args, ctx); - var protoToken = RequestConstructor.createObjectTokenContext( - sessionToken, - address, - frostfs.session.Types.ObjectSessionContext.Verb.RANGE, - getContext().getKey() - ); - - RequestConstructor.addMetaHeader(request, args.getXHeaders(), protoToken); - sign(request, getContext().getKey()); - - return request.build(); - } - - private Service.GetRangeHashRequest createGetRangeHashRequest(PrmRangeHashGet args, CallContext ctx) { - var address = Types.Address.newBuilder() - .setContainerId(ContainerIdMapper.toGrpcMessage(args.getContainerId())) - .setObjectId(ObjectIdMapper.toGrpcMessage(args.getObjectId())) - .build(); - var body = Service.GetRangeHashRequest.Body.newBuilder() - .setAddress(address) - .setType(Types.ChecksumType.SHA256) - .setSalt(ByteString.copyFrom(args.getSalt())) - .addAllRanges(RangeMapper.toGrpcMessages(args.getRanges())) - .build(); - var request = Service.GetRangeHashRequest.newBuilder() - .setBody(body); - - var sessionToken = getOrCreateSession(args, ctx); - var protoToken = RequestConstructor.createObjectTokenContext( - sessionToken, - address, - frostfs.session.Types.ObjectSessionContext.Verb.RANGEHASH, - getContext().getKey() - ); - - RequestConstructor.addMetaHeader(request, args.getXHeaders(), protoToken); - sign(request, getContext().getKey()); - - return request.build(); - } - - private Service.PatchRequest.Builder createInitPatchRequest(PrmObjectPatch args, CallContext ctx) { - var address = AddressMapper.toGrpcMessage(args.getAddress()); - var body = Service.PatchRequest.Body.newBuilder() - .setAddress(address) - .setReplaceAttributes(args.isReplaceAttributes()) - .addAllNewAttributes(ObjectAttributeMapper.toGrpcMessages(args.getNewAttributes())) - .build(); - var request = Service.PatchRequest.newBuilder() - .setBody(body); - - var protoToken = RequestConstructor.createObjectTokenContext( - getOrCreateSession(args, ctx), - request.getBody().getAddress(), - frostfs.session.Types.ObjectSessionContext.Verb.PATCH, - getContext().getKey() - ); - - RequestConstructor.addMetaHeader(request, args.getXHeaders(), protoToken); - sign(request, getContext().getKey()); - - return request; - } -} diff --git a/client/src/main/java/info/frostfs/sdk/services/impl/ObjectToolsImpl.java b/client/src/main/java/info/frostfs/sdk/services/impl/ObjectToolsImpl.java deleted file mode 100644 index f0f4e1c..0000000 --- a/client/src/main/java/info/frostfs/sdk/services/impl/ObjectToolsImpl.java +++ /dev/null @@ -1,126 +0,0 @@ -package info.frostfs.sdk.services.impl; - -import com.google.protobuf.ByteString; -import frostfs.object.Types; -import info.frostfs.sdk.dto.object.ObjectFrostFS; -import info.frostfs.sdk.dto.object.ObjectHeader; -import info.frostfs.sdk.dto.object.ObjectId; -import info.frostfs.sdk.dto.object.Split; -import info.frostfs.sdk.jdo.ClientEnvironment; -import info.frostfs.sdk.mappers.netmap.VersionMapper; -import info.frostfs.sdk.mappers.object.ObjectHeaderMapper; -import info.frostfs.sdk.mappers.object.ObjectIdMapper; -import info.frostfs.sdk.mappers.object.OwnerIdMapper; -import info.frostfs.sdk.services.ContextAccessor; -import info.frostfs.sdk.services.ToolsClient; -import org.apache.commons.collections4.CollectionUtils; - -import java.util.stream.Collectors; - -import static info.frostfs.sdk.Helper.getSha256; -import static info.frostfs.sdk.tools.RequestSigner.signData; -import static java.util.Objects.isNull; -import static java.util.Objects.nonNull; - -public class ObjectToolsImpl extends ContextAccessor implements ToolsClient { - public ObjectToolsImpl(ClientEnvironment context) { - super(context); - } - - private static frostfs.refs.Types.Checksum sha256Checksum(byte[] data) { - return frostfs.refs.Types.Checksum.newBuilder() - .setType(frostfs.refs.Types.ChecksumType.SHA256) - .setSum(ByteString.copyFrom(getSha256(data))) - .build(); - } - - @Override - public ObjectId calculateObjectId(ObjectHeader header) { - var grpcHeader = createHeader(header, new byte[]{}); - - if (nonNull(header.getSplit())) { - grpcHeader = updateSplitValues(grpcHeader, header.getSplit()); - } - - return ObjectIdMapper.toModel( - frostfs.refs.Types.ObjectID.newBuilder().setValue(getSha256(grpcHeader)).build() - ); - } - - public Types.Object createObject(ObjectFrostFS objectFrostFS) { - objectFrostFS.getHeader().setOwnerId(getContext().getOwnerId()); - objectFrostFS.getHeader().setVersion(getContext().getVersion()); - objectFrostFS.getHeader().setPayloadLength(objectFrostFS.getPayload().length); - - var grpcHeader = ObjectHeaderMapper.toGrpcMessage(objectFrostFS.getHeader()).toBuilder() - .setPayloadHash(sha256Checksum(objectFrostFS.getPayload())) - .build(); - - var split = objectFrostFS.getHeader().getSplit(); - if (nonNull(split)) { - grpcHeader = updateSplitValues(grpcHeader, split); - } - - var objectId = frostfs.refs.Types.ObjectID.newBuilder().setValue(getSha256(grpcHeader)).build(); - var sig = frostfs.refs.Types.Signature.newBuilder() - .setKey(ByteString.copyFrom(getContext().getKey().getPublicKeyByte())) - .setSign(ByteString.copyFrom(signData(getContext().getKey(), objectId.toByteArray()))); - return Types.Object.newBuilder() - .setHeader(grpcHeader) - .setObjectId(objectId) - .setPayload(ByteString.copyFrom(objectFrostFS.getPayload())) - .setSignature(sig) - .build(); - } - - public Types.Header updateSplitValues(Types.Header grpcHeader, Split split) { - if (isNull(split)) { - return grpcHeader; - } - - var grpcSplit = grpcHeader.getSplit().toBuilder() - .setSplitId(ByteString.copyFrom(split.getSplitId().toBinary())); - - if (CollectionUtils.isNotEmpty(split.getChildren())) { - var grpcChildren = split.getChildren().stream() - .map(ObjectIdMapper::toGrpcMessage) - .collect(Collectors.toList()); - grpcSplit.addAllChildren(grpcChildren); - } - - if (nonNull(split.getParentHeader())) { - var grpcParentHeader = createHeader(split.getParentHeader(), new byte[]{}); - var parentObjectId = frostfs.refs.Types.ObjectID.newBuilder().setValue(getSha256(grpcParentHeader)).build(); - var signature = frostfs.refs.Types.Signature.newBuilder() - .setKey(ByteString.copyFrom(getContext().getKey().getPublicKeyByte())) - .setSign(ByteString.copyFrom(signData(getContext().getKey(), parentObjectId.toByteArray()))) - .build(); - - - grpcSplit - .setParent(parentObjectId) - .setParentHeader(grpcParentHeader) - .setParentSignature(signature); - - split.setParent(ObjectIdMapper.toModel(parentObjectId)); - } - - if (nonNull(split.getPrevious())) { - grpcSplit.setPrevious(ObjectIdMapper.toGrpcMessage(split.getPrevious())).build(); - } - - return grpcHeader.toBuilder().setSplit(grpcSplit.build()).build(); - } - - private Types.Header createHeader(ObjectHeader header, byte[] payload) { - var grpcHeader = ObjectHeaderMapper.toGrpcMessage(header).toBuilder() - .setOwnerId(OwnerIdMapper.toGrpcMessage(getContext().getOwnerId())) - .setVersion(VersionMapper.toGrpcMessage(getContext().getVersion())); - - if (payload != null) { - grpcHeader.setPayloadHash(sha256Checksum(payload)); - } - - return grpcHeader.build(); - } -} diff --git a/client/src/main/java/info/frostfs/sdk/services/impl/SessionClientImpl.java b/client/src/main/java/info/frostfs/sdk/services/impl/SessionClientImpl.java deleted file mode 100644 index 7b999ce..0000000 --- a/client/src/main/java/info/frostfs/sdk/services/impl/SessionClientImpl.java +++ /dev/null @@ -1,72 +0,0 @@ -package info.frostfs.sdk.services.impl; - -import frostfs.session.Service; -import frostfs.session.SessionServiceGrpc; -import frostfs.session.Types; -import info.frostfs.sdk.dto.session.SessionToken; -import info.frostfs.sdk.jdo.ClientEnvironment; -import info.frostfs.sdk.jdo.parameters.CallContext; -import info.frostfs.sdk.jdo.parameters.session.PrmSessionCreate; -import info.frostfs.sdk.mappers.object.OwnerIdMapper; -import info.frostfs.sdk.mappers.session.SessionMapper; -import info.frostfs.sdk.services.ContextAccessor; -import info.frostfs.sdk.services.SessionClient; -import info.frostfs.sdk.tools.RequestConstructor; -import info.frostfs.sdk.tools.Verifier; - -import static info.frostfs.sdk.tools.RequestSigner.sign; -import static info.frostfs.sdk.utils.DeadLineUtil.deadLineAfter; - -public class SessionClientImpl extends ContextAccessor implements SessionClient { - private final SessionServiceGrpc.SessionServiceBlockingStub serviceBlockingStub; - - public SessionClientImpl(ClientEnvironment clientEnvironment) { - super(clientEnvironment); - this.serviceBlockingStub = SessionServiceGrpc.newBlockingStub(getContext().getChannel()); - } - - @Override - public SessionToken createSession(PrmSessionCreate args, CallContext ctx) { - var sessionToken = createSessionInternal(args, ctx); - var token = SessionMapper.serialize(sessionToken); - return new SessionToken(token); - } - - public Types.SessionToken createSessionInternal(PrmSessionCreate args, CallContext ctx) { - var body = Service.CreateRequest.Body.newBuilder() - .setOwnerId(OwnerIdMapper.toGrpcMessage(getContext().getOwnerId())) - .setExpiration(args.getExpiration()) - .build(); - var request = Service.CreateRequest.newBuilder() - .setBody(body); - - RequestConstructor.addMetaHeader(request); - sign(request, getContext().getKey()); - - return createSession(request.build(), ctx); - } - - private Types.SessionToken createSession(Service.CreateRequest request, CallContext ctx) { - var service = deadLineAfter(serviceBlockingStub, ctx.getTimeout(), ctx.getTimeUnit()); - var response = service.create(request); - - Verifier.checkResponse(response); - - var lifetime = Types.SessionToken.Body.TokenLifetime.newBuilder() - .setExp(request.getBody().getExpiration()) - .setIat(response.getMetaHeader().getEpoch()) - .setNbf(response.getMetaHeader().getEpoch()) - .build(); - - var body = Types.SessionToken.Body.newBuilder() - .setId(response.getBody().getId()) - .setSessionKey(response.getBody().getSessionKey()) - .setOwnerId(request.getBody().getOwnerId()) - .setLifetime(lifetime) - .build(); - - return Types.SessionToken.newBuilder() - .setBody(body) - .build(); - } -} diff --git a/client/src/main/java/info/frostfs/sdk/services/impl/SessionToolsImpl.java b/client/src/main/java/info/frostfs/sdk/services/impl/SessionToolsImpl.java deleted file mode 100644 index c51b673..0000000 --- a/client/src/main/java/info/frostfs/sdk/services/impl/SessionToolsImpl.java +++ /dev/null @@ -1,35 +0,0 @@ -package info.frostfs.sdk.services.impl; - -import info.frostfs.sdk.dto.session.SessionToken; -import info.frostfs.sdk.exceptions.FrostFSException; -import info.frostfs.sdk.jdo.ClientEnvironment; -import info.frostfs.sdk.jdo.parameters.CallContext; -import info.frostfs.sdk.jdo.parameters.session.PrmSessionCreate; -import info.frostfs.sdk.services.ContextAccessor; -import info.frostfs.sdk.services.SessionTools; - -import static info.frostfs.sdk.constants.ErrorConst.SESSION_CREATE_FAILED; -import static java.util.Objects.isNull; - -public class SessionToolsImpl extends ContextAccessor implements SessionTools { - - public SessionToolsImpl(ClientEnvironment clientEnvironment) { - super(clientEnvironment); - } - - @Override - public SessionToken getOrCreateSession(ClientEnvironment env, CallContext ctx) { - var token = env.getSessionCache().tryGetValue(env.getSessionKey()); - - if (isNull(token)) { - token = env.getFrostFSClient().createSession(new PrmSessionCreate(-1), ctx); - if (isNull(token)) { - throw new FrostFSException(SESSION_CREATE_FAILED); - } - - env.getSessionCache().setValue(env.getSessionKey(), token); - } - - return token; - } -} diff --git a/client/src/main/java/info/frostfs/sdk/services/impl/interceptor/ClientMetrics.java b/client/src/main/java/info/frostfs/sdk/services/impl/interceptor/ClientMetrics.java deleted file mode 100644 index 656d19f..0000000 --- a/client/src/main/java/info/frostfs/sdk/services/impl/interceptor/ClientMetrics.java +++ /dev/null @@ -1,174 +0,0 @@ -package info.frostfs.sdk.services.impl.interceptor; - -import io.grpc.Metadata; -import io.grpc.Status; -import io.prometheus.client.CollectorRegistry; -import io.prometheus.client.Counter; -import io.prometheus.client.Histogram; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Optional; - -import static info.frostfs.sdk.services.impl.interceptor.Labels.*; - -public class ClientMetrics { - private static final List defaultRequestLabels = - Arrays.asList("grpc_target", "grpc_type", "grpc_service", "grpc_method"); - - private static final List defaultResponseLabels = - Arrays.asList("grpc_target", "grpc_type", "grpc_service", "grpc_method", "code", "grpc_code"); - - private static final Counter.Builder rpcStartedBuilder = - Counter.build() - .namespace("grpc") - .subsystem("client") - .name("started") - .help("Total number of RPCs started on the client."); - - private static final Counter.Builder rpcCompletedBuilder = - Counter.build() - .namespace("grpc") - .subsystem("client") - .name("completed") - .help("Total number of RPCs completed on the client, regardless of success or failure."); - - private static final Histogram.Builder completedLatencySecondsBuilder = - Histogram.build() - .namespace("grpc") - .subsystem("client") - .name("completed_latency_seconds") - .help("Histogram of rpc response latency (in seconds) for completed rpcs."); - - private static final Counter.Builder streamMessagesReceivedBuilder = - Counter.build() - .namespace("grpc") - .subsystem("client") - .name("msg_received") - .help("Total number of stream messages received from the server."); - - private static final Counter.Builder streamMessagesSentBuilder = - Counter.build() - .namespace("grpc") - .subsystem("client") - .name("msg_sent") - .help("Total number of stream messages sent by the client."); - - private final List> labelHeaderKeys; - private final Counter rpcStarted; - private final Counter rpcCompleted; - private final Counter streamMessagesReceived; - private final Counter streamMessagesSent; - private final Optional completedLatencySeconds; - - private final GrpcMethod method; - - private ClientMetrics( - List> labelHeaderKeys, - GrpcMethod method, - Counter rpcStarted, - Counter rpcCompleted, - Counter streamMessagesReceived, - Counter streamMessagesSent, - Optional completedLatencySeconds) { - this.labelHeaderKeys = labelHeaderKeys; - this.method = method; - this.rpcStarted = rpcStarted; - this.rpcCompleted = rpcCompleted; - this.streamMessagesReceived = streamMessagesReceived; - this.streamMessagesSent = streamMessagesSent; - this.completedLatencySeconds = completedLatencySeconds; - } - - public void recordCallStarted(Metadata metadata) { - addLabels(rpcStarted, customLabels(metadata, labelHeaderKeys), method).inc(); - } - - public void recordClientHandled(Status.Code code, Metadata metadata) { - List allLabels = new ArrayList<>(); - allLabels.add(code.toString()); - allLabels.add(code.toString()); - allLabels.addAll(customLabels(metadata, labelHeaderKeys)); - addLabels(rpcCompleted, allLabels, method).inc(); - } - - public void recordStreamMessageSent(Metadata metadata) { - addLabels(streamMessagesSent, customLabels(metadata, labelHeaderKeys), method).inc(); - } - - public void recordStreamMessageReceived(Metadata metadata) { - addLabels(streamMessagesReceived, customLabels(metadata, labelHeaderKeys), method).inc(); - } - - /** - * Only has any effect if monitoring is configured to include latency histograms. Otherwise, this - * does nothing. - */ - public void recordLatency(double latencySec, Metadata metadata) { - if (completedLatencySeconds.isEmpty()) { - return; - } - addLabels(completedLatencySeconds.get(), customLabels(metadata, labelHeaderKeys), method) - .observe(latencySec); - } - - /** - * Knows how to produce {@link ClientMetrics} instances for individual methods. - */ - static class Factory { - private final List> labelHeaderKeys; - private final Counter rpcStarted; - private final Counter rpcCompleted; - private final Counter streamMessagesReceived; - private final Counter streamMessagesSent; - private final Optional completedLatencySeconds; - - Factory(Configuration configuration) { - CollectorRegistry registry = configuration.getCollectorRegistry(); - this.labelHeaderKeys = metadataKeys(configuration.getLabelHeaders()); - this.rpcStarted = - rpcStartedBuilder - .labelNames(asArray(defaultRequestLabels, configuration.getSanitizedLabelHeaders())) - .register(registry); - this.rpcCompleted = - rpcCompletedBuilder - .labelNames(asArray(defaultResponseLabels, configuration.getSanitizedLabelHeaders())) - .register(registry); - this.streamMessagesReceived = - streamMessagesReceivedBuilder - .labelNames(asArray(defaultRequestLabels, configuration.getSanitizedLabelHeaders())) - .register(registry); - this.streamMessagesSent = - streamMessagesSentBuilder - .labelNames(asArray(defaultRequestLabels, configuration.getSanitizedLabelHeaders())) - .register(registry); - - if (configuration.isIncludeLatencyHistograms()) { - this.completedLatencySeconds = - Optional.of( - ClientMetrics.completedLatencySecondsBuilder - .buckets(configuration.getLatencyBuckets()) - .labelNames( - asArray(defaultRequestLabels, configuration.getSanitizedLabelHeaders())) - .register(registry)); - } else { - this.completedLatencySeconds = Optional.empty(); - } - } - - /** - * Creates a {@link ClientMetrics} for the supplied gRPC method. - */ - ClientMetrics createMetricsForMethod(GrpcMethod grpcMethod) { - return new ClientMetrics( - labelHeaderKeys, - grpcMethod, - rpcStarted, - rpcCompleted, - streamMessagesReceived, - streamMessagesSent, - completedLatencySeconds); - } - } -} diff --git a/client/src/main/java/info/frostfs/sdk/services/impl/interceptor/Configuration.java b/client/src/main/java/info/frostfs/sdk/services/impl/interceptor/Configuration.java deleted file mode 100644 index cfc9193..0000000 --- a/client/src/main/java/info/frostfs/sdk/services/impl/interceptor/Configuration.java +++ /dev/null @@ -1,168 +0,0 @@ -package info.frostfs.sdk.services.impl.interceptor; - - -import io.prometheus.client.CollectorRegistry; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -public class Configuration { - private static final double[] DEFAULT_LATENCY_BUCKETS = - new double[]{.001, .005, .01, .05, 0.075, .1, .25, .5, 1, 2, 5, 10}; - - private final boolean isIncludeLatencyHistograms; - private final CollectorRegistry collectorRegistry; - private final double[] latencyBuckets; - private final List labelHeaders; - private final boolean isAddCodeLabelToHistograms; - - private Configuration( - boolean isIncludeLatencyHistograms, - CollectorRegistry collectorRegistry, - double[] latencyBuckets, - List labelHeaders, - boolean isAddCodeLabelToHistograms) { - this.isIncludeLatencyHistograms = isIncludeLatencyHistograms; - this.collectorRegistry = collectorRegistry; - this.latencyBuckets = latencyBuckets; - this.labelHeaders = labelHeaders; - this.isAddCodeLabelToHistograms = isAddCodeLabelToHistograms; - } - - - /** - * Returns a {@link Configuration} for recording all cheap metrics about the rpcs. - */ - public static Configuration cheapMetricsOnly() { - return new Configuration( - false /* isIncludeLatencyHistograms */, - CollectorRegistry.defaultRegistry, - DEFAULT_LATENCY_BUCKETS, - new ArrayList<>(), - false /* isAddCodeLabelToHistograms */); - } - - /** - * Returns a {@link Configuration} for recording all metrics about the rpcs. This includes metrics - * which might produce a lot of data, such as latency histograms. - */ - public static Configuration allMetrics() { - return new Configuration( - true /* isIncludeLatencyHistograms */, - CollectorRegistry.defaultRegistry, - DEFAULT_LATENCY_BUCKETS, - new ArrayList<>(), - false); - } - - /** - * Returns a copy {@link Configuration} with the difference that Prometheus metrics are recorded - * using the supplied {@link CollectorRegistry}. - */ - public Configuration withCollectorRegistry(CollectorRegistry collectorRegistry) { - return new Configuration( - isIncludeLatencyHistograms, - collectorRegistry, - latencyBuckets, - labelHeaders, - isAddCodeLabelToHistograms); - } - - /** - * Returns a copy {@link Configuration} with the difference that the latency histogram values are - * recorded with the specified set of buckets. - */ - public Configuration withLatencyBuckets(double[] buckets) { - return new Configuration( - isIncludeLatencyHistograms, - collectorRegistry, - buckets, - labelHeaders, - isAddCodeLabelToHistograms); - } - - /** - * Returns a copy {@link Configuration} that recognizes the given list of header names and uses - * their value from each request as prometheus labels. - * - *

Since hyphens is a common character in header names, and since Prometheus does not allow - * hyphens in label names, All hyphens in the list of header names will be converted to - * underscores before being added as metric label names. - * - *

If one of the headers added here is absent in one of the requests, its metric value for that - * request will be an empty string. - * - *

Example: {@code withLabelHeaders(Arrays.asList("User-Agent"))} will make all metrics carry a - * label "User_Agent", with label value filled in from the value of the "User-Agent" header of - * each request. - */ - public Configuration withLabelHeaders(List headers) { - List newHeaders = new ArrayList<>(labelHeaders); - newHeaders.addAll(headers); - return new Configuration( - isIncludeLatencyHistograms, - collectorRegistry, - latencyBuckets, - newHeaders, - isAddCodeLabelToHistograms); - } - - /** - * Returns a copy {@link Configuration} with the difference that status code label will be added - * to latency histogram. If latency histogram itself is disabled, this takes no effect. Warning: - * this will increase the number of histograms by a factor of actually happened codes (up to - * {@link io.grpc.Status.Code} values count), which could lead to additional local memory usage - * and load on prometheus (storage and memory usage, query-time complexity) - */ - public Configuration withCodeLabelInLatencyHistogram() { - return new Configuration( - isIncludeLatencyHistograms, - collectorRegistry, - latencyBuckets, - labelHeaders, - true /* isAddCodeLabelToHistograms */); - } - - /** - * Returns whether or not latency histograms for calls should be included. - */ - public boolean isIncludeLatencyHistograms() { - return isIncludeLatencyHistograms; - } - - /** - * Returns the {@link CollectorRegistry} used to record stats. - */ - public CollectorRegistry getCollectorRegistry() { - return collectorRegistry; - } - - /** - * Returns the histogram buckets to use for latency metrics. - */ - public double[] getLatencyBuckets() { - return latencyBuckets; - } - - /** - * Returns the configured list of headers to be used as labels. - */ - public List getLabelHeaders() { - return labelHeaders; - } - - /** - * Returns whether or not status code label should be added to latency histogram. - */ - public boolean isAddCodeLabelToHistograms() { - return isAddCodeLabelToHistograms; - } - - /** - * Returns the sanitized version of the label headers, after turning all hyphens to underscores. - */ - public List getSanitizedLabelHeaders() { - return labelHeaders.stream().map(h -> h.replaceAll("-", "_")).collect(Collectors.toList()); - } -} diff --git a/client/src/main/java/info/frostfs/sdk/services/impl/interceptor/GrpcMethod.java b/client/src/main/java/info/frostfs/sdk/services/impl/interceptor/GrpcMethod.java deleted file mode 100644 index 41e4ef1..0000000 --- a/client/src/main/java/info/frostfs/sdk/services/impl/interceptor/GrpcMethod.java +++ /dev/null @@ -1,51 +0,0 @@ -package info.frostfs.sdk.services.impl.interceptor; - -import io.grpc.Channel; -import io.grpc.MethodDescriptor; -import io.grpc.MethodDescriptor.MethodType; - -public class GrpcMethod { - private final String targetName; - private final String serviceName; - private final String methodName; - private final MethodType type; - - private GrpcMethod(String targetName, String serviceName, String methodName, MethodType type) { - this.targetName = targetName; - this.serviceName = serviceName; - this.methodName = methodName; - this.type = type; - } - - static GrpcMethod of(MethodDescriptor method, Channel channel) { - String serviceName = MethodDescriptor.extractFullServiceName(method.getFullMethodName()); - - // Full method names are of the form: "full.serviceName/MethodName". We extract the last part. - String methodName = method.getFullMethodName().substring(serviceName.length() + 1); - return new GrpcMethod(channel.authority(), serviceName, methodName, method.getType()); - } - - String targetName() { - return targetName; - } - - String serviceName() { - return serviceName; - } - - String methodName() { - return methodName; - } - - String type() { - return type.toString(); - } - - boolean streamsRequests() { - return type == MethodType.CLIENT_STREAMING || type == MethodType.BIDI_STREAMING; - } - - boolean streamsResponses() { - return type == MethodType.SERVER_STREAMING || type == MethodType.BIDI_STREAMING; - } -} diff --git a/client/src/main/java/info/frostfs/sdk/services/impl/interceptor/Labels.java b/client/src/main/java/info/frostfs/sdk/services/impl/interceptor/Labels.java deleted file mode 100644 index e728a79..0000000 --- a/client/src/main/java/info/frostfs/sdk/services/impl/interceptor/Labels.java +++ /dev/null @@ -1,63 +0,0 @@ -package info.frostfs.sdk.services.impl.interceptor; - -import io.grpc.Metadata; -import io.grpc.Metadata.Key; -import io.prometheus.client.SimpleCollector; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -public class Labels { - private Labels() { - } - - /** - * Merges two string lists into an array, maintaining order of first list then second list. - */ - static String[] asArray(List firstList, List secondList) { - List list = new ArrayList<>(firstList); - list.addAll(secondList); - return list.toArray(new String[0]); - } - - /** - * Converts a list of strings to a list of grpc metadata keys. - */ - static List> metadataKeys(List headerNames) { - List> keys = new ArrayList<>(); - for (String name : headerNames) { - keys.add(Key.of(name, Metadata.ASCII_STRING_MARSHALLER)); - } - return Collections.unmodifiableList(keys); - } - - /** - * Returns the ordered list of custom label values, by looking into metadata for values of - * selected custom headers. - */ - static List customLabels(Metadata metadata, List> labelHeaderKeys) { - List labels = new ArrayList<>(); - for (Key key : labelHeaderKeys) { - if (metadata.containsKey(key)) { - labels.add(metadata.get(key)); - } else { - labels.add(""); - } - } - return Collections.unmodifiableList(labels); - } - - /** - * Adds standard labels, as well as custom ones, in order, to a given collector. - */ - static T addLabels(SimpleCollector collector, List labels, GrpcMethod method) { - List allLabels = new ArrayList<>(); - allLabels.add(method.targetName()); - allLabels.add(method.type()); - allLabels.add(method.serviceName()); - allLabels.add(method.methodName()); - allLabels.addAll(labels); - return collector.labels(allLabels.toArray(new String[0])); - } -} diff --git a/client/src/main/java/info/frostfs/sdk/services/impl/interceptor/MonitoringClientCall.java b/client/src/main/java/info/frostfs/sdk/services/impl/interceptor/MonitoringClientCall.java deleted file mode 100644 index c116ca7..0000000 --- a/client/src/main/java/info/frostfs/sdk/services/impl/interceptor/MonitoringClientCall.java +++ /dev/null @@ -1,47 +0,0 @@ -package info.frostfs.sdk.services.impl.interceptor; - -import io.grpc.ClientCall; -import io.grpc.ForwardingClientCall; -import io.grpc.Metadata; - -import java.time.Clock; - -public class MonitoringClientCall extends ForwardingClientCall.SimpleForwardingClientCall { - private final ClientMetrics clientMetrics; - private final GrpcMethod grpcMethod; - private final Configuration configuration; - private final Clock clock; - private Metadata requestMetadata; - - MonitoringClientCall( - ClientCall delegate, - ClientMetrics clientMetrics, - GrpcMethod grpcMethod, - Configuration configuration, - Clock clock) { - super(delegate); - this.clientMetrics = clientMetrics; - this.grpcMethod = grpcMethod; - this.configuration = configuration; - this.clock = clock; - } - - @Override - public void start(Listener delegate, Metadata metadata) { - this.requestMetadata = metadata; - clientMetrics.recordCallStarted(metadata); - super.start( - new MonitoringClientCallListener<>( - delegate, clientMetrics, grpcMethod, configuration, clock, metadata), - metadata); - } - - @Override - public void sendMessage(R requestMessage) { - if (grpcMethod.streamsRequests()) { - clientMetrics.recordStreamMessageSent( - requestMetadata == null ? new Metadata() : requestMetadata); - } - super.sendMessage(requestMessage); - } -} diff --git a/client/src/main/java/info/frostfs/sdk/services/impl/interceptor/MonitoringClientCallListener.java b/client/src/main/java/info/frostfs/sdk/services/impl/interceptor/MonitoringClientCallListener.java deleted file mode 100644 index e8c9caf..0000000 --- a/client/src/main/java/info/frostfs/sdk/services/impl/interceptor/MonitoringClientCallListener.java +++ /dev/null @@ -1,61 +0,0 @@ -package info.frostfs.sdk.services.impl.interceptor; - -import io.grpc.ClientCall; -import io.grpc.ForwardingClientCallListener; -import io.grpc.Metadata; -import io.grpc.Status; - -import java.time.Clock; -import java.time.Instant; - -public class MonitoringClientCallListener extends ForwardingClientCallListener { - private static final long MILLIS_PER_SECOND = 1000L; - - private final ClientCall.Listener delegate; - private final ClientMetrics clientMetrics; - private final GrpcMethod grpcMethod; - private final Configuration configuration; - private final Clock clock; - private final Instant startInstant; - private final Metadata requestMetadata; - - MonitoringClientCallListener( - ClientCall.Listener delegate, - ClientMetrics clientMetrics, - GrpcMethod grpcMethod, - Configuration configuration, - Clock clock, - Metadata requestMetadata) { - this.delegate = delegate; - this.clientMetrics = clientMetrics; - this.grpcMethod = grpcMethod; - this.configuration = configuration; - this.clock = clock; - this.startInstant = clock.instant(); - this.requestMetadata = requestMetadata; - } - - @Override - protected ClientCall.Listener delegate() { - return delegate; - } - - @Override - public void onClose(Status status, Metadata metadata) { - clientMetrics.recordClientHandled(status.getCode(), requestMetadata); - if (configuration.isIncludeLatencyHistograms()) { - double latencySec = - (clock.millis() - startInstant.toEpochMilli()) / (double) MILLIS_PER_SECOND; - clientMetrics.recordLatency(latencySec, requestMetadata); - } - super.onClose(status, metadata); - } - - @Override - public void onMessage(S responseMessage) { - if (grpcMethod.streamsResponses()) { - clientMetrics.recordStreamMessageReceived(requestMetadata); - } - super.onMessage(responseMessage); - } -} diff --git a/client/src/main/java/info/frostfs/sdk/services/impl/interceptor/MonitoringClientInterceptor.java b/client/src/main/java/info/frostfs/sdk/services/impl/interceptor/MonitoringClientInterceptor.java deleted file mode 100644 index 4654487..0000000 --- a/client/src/main/java/info/frostfs/sdk/services/impl/interceptor/MonitoringClientInterceptor.java +++ /dev/null @@ -1,33 +0,0 @@ -package info.frostfs.sdk.services.impl.interceptor; - -import io.grpc.*; - -import java.time.Clock; - - -public class MonitoringClientInterceptor implements ClientInterceptor { - private final Clock clock; - private final Configuration configuration; - private final ClientMetrics.Factory clientMetricsFactory; - - private MonitoringClientInterceptor( - Clock clock, Configuration configuration, ClientMetrics.Factory clientMetricsFactory) { - this.clock = clock; - this.configuration = configuration; - this.clientMetricsFactory = clientMetricsFactory; - } - - public static MonitoringClientInterceptor create(Configuration configuration) { - return new MonitoringClientInterceptor( - Clock.systemDefaultZone(), configuration, new ClientMetrics.Factory(configuration)); - } - - @Override - public ClientCall interceptCall( - MethodDescriptor methodDescriptor, CallOptions callOptions, Channel channel) { - GrpcMethod grpcMethod = GrpcMethod.of(methodDescriptor, channel); - ClientMetrics metrics = clientMetricsFactory.createMetricsForMethod(grpcMethod); - return new MonitoringClientCall<>( - channel.newCall(methodDescriptor, callOptions), metrics, grpcMethod, configuration, clock); - } -} diff --git a/client/src/main/java/info/frostfs/sdk/services/impl/rwhelper/ObjectReaderImpl.java b/client/src/main/java/info/frostfs/sdk/services/impl/rwhelper/ObjectReaderImpl.java deleted file mode 100644 index 5b53c7c..0000000 --- a/client/src/main/java/info/frostfs/sdk/services/impl/rwhelper/ObjectReaderImpl.java +++ /dev/null @@ -1,65 +0,0 @@ -package info.frostfs.sdk.services.impl.rwhelper; - -import frostfs.object.Service; -import frostfs.object.Types; -import info.frostfs.sdk.dto.object.ObjectReader; -import info.frostfs.sdk.exceptions.ProcessFrostFSException; -import info.frostfs.sdk.tools.Verifier; - -import java.util.Iterator; - -import static info.frostfs.sdk.constants.ErrorConst.UNEXPECTED_MESSAGE_TYPE_TEMPLATE; -import static info.frostfs.sdk.constants.ErrorConst.UNEXPECTED_STREAM; - -public class ObjectReaderImpl implements ObjectReader { - public Iterator call; - - public ObjectReaderImpl(Iterator call) { - this.call = call; - } - - public Types.Object readHeader() { - if (!call.hasNext()) { - throw new ProcessFrostFSException(UNEXPECTED_STREAM); - } - - var response = call.next(); - Verifier.checkResponse(response); - - if (response.getBody().getObjectPartCase().getNumber() != Service.GetResponse.Body.INIT_FIELD_NUMBER) { - throw new ProcessFrostFSException( - String.format( - UNEXPECTED_MESSAGE_TYPE_TEMPLATE, - Service.GetResponse.Body.INIT_FIELD_NUMBER, - response.getBody().getObjectPartCase().getNumber() - ) - ); - } - - return Types.Object.newBuilder() - .setObjectId(response.getBody().getInit().getObjectId()) - .setHeader(response.getBody().getInit().getHeader()) - .build(); - } - - public byte[] readChunk() { - if (!call.hasNext()) { - return null; - } - - var response = call.next(); - Verifier.checkResponse(response); - - if (response.getBody().getObjectPartCase().getNumber() != Service.GetResponse.Body.CHUNK_FIELD_NUMBER) { - throw new ProcessFrostFSException( - String.format( - UNEXPECTED_MESSAGE_TYPE_TEMPLATE, - Service.GetResponse.Body.CHUNK_FIELD_NUMBER, - response.getBody().getObjectPartCase().getNumber() - ) - ); - } - - return response.getBody().getChunk().toByteArray(); - } -} diff --git a/client/src/main/java/info/frostfs/sdk/services/impl/rwhelper/ObjectStreamer.java b/client/src/main/java/info/frostfs/sdk/services/impl/rwhelper/ObjectStreamer.java deleted file mode 100644 index cadfbf1..0000000 --- a/client/src/main/java/info/frostfs/sdk/services/impl/rwhelper/ObjectStreamer.java +++ /dev/null @@ -1,62 +0,0 @@ -package info.frostfs.sdk.services.impl.rwhelper; - -import frostfs.object.ObjectServiceGrpc; -import frostfs.object.Service; -import info.frostfs.sdk.exceptions.ProcessFrostFSException; -import info.frostfs.sdk.utils.WaitUtil; -import io.grpc.stub.StreamObserver; -import lombok.Getter; - -import static info.frostfs.sdk.constants.AppConst.DEFAULT_POLL_INTERVAL; -import static info.frostfs.sdk.constants.ErrorConst.PROTO_MESSAGE_IS_EMPTY_TEMPLATE; -import static java.util.Objects.isNull; - -public class ObjectStreamer { - private final StreamObserver requestObserver; - private final PutResponseCallback responseObserver; - - public ObjectStreamer(ObjectServiceGrpc.ObjectServiceStub objectServiceStub) { - PutResponseCallback responseObserver = new PutResponseCallback(); - - this.responseObserver = responseObserver; - this.requestObserver = objectServiceStub.put(responseObserver); - } - - public void write(Service.PutRequest request) { - if (isNull(request)) { - throw new ProcessFrostFSException( - String.format(PROTO_MESSAGE_IS_EMPTY_TEMPLATE, Service.PutRequest.class.getName()) - ); - } - requestObserver.onNext(request); - } - - public Service.PutResponse complete() { - requestObserver.onCompleted(); - - while (isNull(responseObserver.getResponse())) { - WaitUtil.sleep(DEFAULT_POLL_INTERVAL); - } - - return responseObserver.getResponse(); - } - - @Getter - private static class PutResponseCallback implements StreamObserver { - private Service.PutResponse response; - - @Override - public void onNext(Service.PutResponse putResponse) { - this.response = putResponse; - } - - @Override - public void onError(Throwable throwable) { - throw new ProcessFrostFSException(throwable); - } - - @Override - public void onCompleted() { - } - } -} diff --git a/client/src/main/java/info/frostfs/sdk/services/impl/rwhelper/ObjectWriter.java b/client/src/main/java/info/frostfs/sdk/services/impl/rwhelper/ObjectWriter.java deleted file mode 100644 index 9650dbf..0000000 --- a/client/src/main/java/info/frostfs/sdk/services/impl/rwhelper/ObjectWriter.java +++ /dev/null @@ -1,43 +0,0 @@ -package info.frostfs.sdk.services.impl.rwhelper; - -import com.google.protobuf.ByteString; -import frostfs.object.Service; -import info.frostfs.sdk.dto.object.ObjectId; -import info.frostfs.sdk.jdo.ClientEnvironment; -import info.frostfs.sdk.jdo.parameters.object.PrmObjectPutBase; -import info.frostfs.sdk.tools.RequestConstructor; -import info.frostfs.sdk.tools.Verifier; -import lombok.AllArgsConstructor; -import lombok.Getter; - -import static info.frostfs.sdk.tools.RequestSigner.sign; - -//todo specify a deadline for each stream request, not for the entire stream -@Getter -@AllArgsConstructor -public class ObjectWriter { - private final ClientEnvironment environment; - private final PrmObjectPutBase args; - private final ObjectStreamer streamer; - - public void write(byte[] buffer) { - var body = Service.PutRequest.Body.newBuilder() - .setChunk(ByteString.copyFrom(buffer)) - .build(); - var chunkRequest = Service.PutRequest.newBuilder() - .setBody(body) - .clearVerifyHeader(); - - RequestConstructor.addMetaHeader(chunkRequest, args.getXHeaders()); - sign(chunkRequest, environment.getKey()); - - streamer.write(chunkRequest.build()); - } - - public ObjectId complete() { - var response = streamer.complete(); - Verifier.checkResponse(response); - - return new ObjectId(response.getBody().getObjectId().getValue().toByteArray()); - } -} diff --git a/client/src/main/java/info/frostfs/sdk/services/impl/rwhelper/PatchStreamer.java b/client/src/main/java/info/frostfs/sdk/services/impl/rwhelper/PatchStreamer.java deleted file mode 100644 index 4cdee35..0000000 --- a/client/src/main/java/info/frostfs/sdk/services/impl/rwhelper/PatchStreamer.java +++ /dev/null @@ -1,62 +0,0 @@ -package info.frostfs.sdk.services.impl.rwhelper; - -import frostfs.object.ObjectServiceGrpc; -import frostfs.object.Service; -import info.frostfs.sdk.exceptions.ProcessFrostFSException; -import info.frostfs.sdk.utils.WaitUtil; -import io.grpc.stub.StreamObserver; -import lombok.Getter; - -import static info.frostfs.sdk.constants.AppConst.DEFAULT_POLL_INTERVAL; -import static info.frostfs.sdk.constants.ErrorConst.PROTO_MESSAGE_IS_EMPTY_TEMPLATE; -import static java.util.Objects.isNull; - -public class PatchStreamer { - private final StreamObserver requestObserver; - private final PatchResponseCallback responseObserver; - - public PatchStreamer(ObjectServiceGrpc.ObjectServiceStub objectServiceStub) { - PatchResponseCallback responseObserver = new PatchResponseCallback(); - - this.responseObserver = responseObserver; - this.requestObserver = objectServiceStub.patch(responseObserver); - } - - public void write(Service.PatchRequest request) { - if (isNull(request)) { - throw new ProcessFrostFSException( - String.format(PROTO_MESSAGE_IS_EMPTY_TEMPLATE, Service.PutRequest.class.getName()) - ); - } - requestObserver.onNext(request); - } - - public Service.PatchResponse complete() { - requestObserver.onCompleted(); - - while (isNull(responseObserver.getResponse())) { - WaitUtil.sleep(DEFAULT_POLL_INTERVAL); - } - - return responseObserver.getResponse(); - } - - @Getter - private static class PatchResponseCallback implements StreamObserver { - private Service.PatchResponse response; - - @Override - public void onNext(Service.PatchResponse patchResponse) { - this.response = patchResponse; - } - - @Override - public void onError(Throwable throwable) { - throw new ProcessFrostFSException(throwable); - } - - @Override - public void onCompleted() { - } - } -} diff --git a/client/src/main/java/info/frostfs/sdk/services/impl/rwhelper/RangeReader.java b/client/src/main/java/info/frostfs/sdk/services/impl/rwhelper/RangeReader.java deleted file mode 100644 index 75c4c64..0000000 --- a/client/src/main/java/info/frostfs/sdk/services/impl/rwhelper/RangeReader.java +++ /dev/null @@ -1,25 +0,0 @@ -package info.frostfs.sdk.services.impl.rwhelper; - -import frostfs.object.Service; -import info.frostfs.sdk.tools.Verifier; - -import java.util.Iterator; - -public class RangeReader { - public Iterator call; - - public RangeReader(Iterator call) { - this.call = call; - } - - public byte[] readChunk() { - if (!call.hasNext()) { - return null; - } - - var response = call.next(); - Verifier.checkResponse(response); - - return response.getBody().getChunk().toByteArray(); - } -} diff --git a/client/src/main/java/info/frostfs/sdk/services/impl/rwhelper/SearchReader.java b/client/src/main/java/info/frostfs/sdk/services/impl/rwhelper/SearchReader.java deleted file mode 100644 index ec42c05..0000000 --- a/client/src/main/java/info/frostfs/sdk/services/impl/rwhelper/SearchReader.java +++ /dev/null @@ -1,26 +0,0 @@ -package info.frostfs.sdk.services.impl.rwhelper; - -import frostfs.object.Service; -import info.frostfs.sdk.tools.Verifier; - -import java.util.Iterator; -import java.util.List; - -public class SearchReader { - public Iterator call; - - public SearchReader(Iterator call) { - this.call = call; - } - - public List read() { - if (!call.hasNext()) { - return null; - } - - var response = call.next(); - Verifier.checkResponse(response); - - return response.getBody().getIdListList(); - } -} diff --git a/client/src/main/java/info/frostfs/sdk/tools/GrpcClient.java b/client/src/main/java/info/frostfs/sdk/tools/GrpcClient.java deleted file mode 100644 index 9692e3a..0000000 --- a/client/src/main/java/info/frostfs/sdk/tools/GrpcClient.java +++ /dev/null @@ -1,46 +0,0 @@ -package info.frostfs.sdk.tools; - -import info.frostfs.sdk.exceptions.ValidationFrostFSException; -import info.frostfs.sdk.jdo.ClientSettings; -import info.frostfs.sdk.utils.Validator; -import io.grpc.ManagedChannel; -import io.grpc.netty.NettyChannelBuilder; - -import java.net.URI; -import java.net.URISyntaxException; - -import static info.frostfs.sdk.constants.ErrorConst.INVALID_HOST_TEMPLATE; -import static java.util.Objects.isNull; - -public class GrpcClient { - private GrpcClient() { - } - - public static ManagedChannel initGrpcChannel(ClientSettings clientSettings) { - Validator.validate(clientSettings); - - try { - URI uri = new URI(clientSettings.getHost()); - var channelBuilder = isNull(clientSettings.getCredentials()) - ? NettyChannelBuilder.forAddress(uri.getHost(), uri.getPort()).usePlaintext() - : NettyChannelBuilder.forAddress(uri.getHost(), uri.getPort(), clientSettings.getCredentials()); - - return channelBuilder.build(); - } catch (URISyntaxException exp) { - throw new ValidationFrostFSException( - String.format(INVALID_HOST_TEMPLATE, clientSettings.getHost(), exp.getMessage()) - ); - } - } - - public static ManagedChannel initGrpcChannel(String address) { - try { - URI uri = new URI(address); - return NettyChannelBuilder.forAddress(uri.getHost(), uri.getPort()).usePlaintext().build(); - } catch (URISyntaxException exp) { - throw new ValidationFrostFSException( - String.format(INVALID_HOST_TEMPLATE, address, exp.getMessage()) - ); - } - } -} diff --git a/client/src/main/java/info/frostfs/sdk/tools/RequestConstructor.java b/client/src/main/java/info/frostfs/sdk/tools/RequestConstructor.java deleted file mode 100644 index 17a011c..0000000 --- a/client/src/main/java/info/frostfs/sdk/tools/RequestConstructor.java +++ /dev/null @@ -1,127 +0,0 @@ -package info.frostfs.sdk.tools; - -import com.google.protobuf.ByteString; -import com.google.protobuf.Message; -import frostfs.session.Types; -import info.frostfs.sdk.dto.response.MetaHeader; -import info.frostfs.sdk.dto.session.SessionToken; -import info.frostfs.sdk.exceptions.ValidationFrostFSException; -import info.frostfs.sdk.jdo.ECDsa; -import info.frostfs.sdk.mappers.response.MetaHeaderMapper; -import info.frostfs.sdk.mappers.session.SessionMapper; -import org.apache.commons.collections4.MapUtils; - -import java.util.Map; -import java.util.stream.Collectors; - -import static info.frostfs.sdk.constants.ErrorConst.REQUIRED_PROTO_FIELD_TEMPLATE; -import static info.frostfs.sdk.constants.FieldConst.META_HEADER_FIELD_NAME; -import static info.frostfs.sdk.tools.RequestSigner.signMessagePart; -import static info.frostfs.sdk.utils.MessageHelper.getField; -import static info.frostfs.sdk.utils.MessageHelper.setField; -import static java.util.Objects.isNull; -import static java.util.Objects.nonNull; - -public class RequestConstructor { - private RequestConstructor() { - } - - public static void addMetaHeader(Message.Builder request) { - addMetaHeader(request, null, null); - } - - public static void addMetaHeader(Message.Builder request, Map xHeaders) { - addMetaHeader(request, xHeaders, null); - } - - public static void addMetaHeader(Message.Builder request, - Map xHeaders, - Types.SessionToken sessionToken) { - if (isNull(request)) { - return; - } - - if (isNull(request.getDescriptorForType().findFieldByName(META_HEADER_FIELD_NAME))) { - throw new ValidationFrostFSException(String.format(REQUIRED_PROTO_FIELD_TEMPLATE, META_HEADER_FIELD_NAME)); - } - - if (((Types.RequestMetaHeader) getField(request, META_HEADER_FIELD_NAME)).getSerializedSize() > 0) { - return; - } - - var metaHeader = MetaHeaderMapper.toGrpcMessageBuilder(new MetaHeader()); - - if (nonNull(sessionToken) && sessionToken.getSerializedSize() > 0) { - metaHeader.setSessionToken(sessionToken); - } - - if (MapUtils.isNotEmpty(xHeaders)) { - var grpcXHeaders = xHeaders.entrySet() - .stream() - .map(e -> Types.XHeader.newBuilder().setKey(e.getKey()).setValue(e.getValue()).build()) - .collect(Collectors.toList()); - - metaHeader.addAllXHeaders(grpcXHeaders); - } - - setField(request, META_HEADER_FIELD_NAME, metaHeader.build()); - } - - public static Types.SessionToken createObjectTokenContext(SessionToken sessionToken, - frostfs.refs.Types.Address address, - Types.ObjectSessionContext.Verb verb, - ECDsa key) { - var protoToken = SessionMapper.deserializeSessionToken(sessionToken.getToken()); - - var target = Types.ObjectSessionContext.Target.newBuilder() - .setContainer(address.getContainerId()); - - if (address.getObjectId().getSerializedSize() > 0) { - target.addObjects(address.getObjectId()); - } - - var ctx = Types.ObjectSessionContext.newBuilder() - .setTarget(target.build()) - .setVerb(verb) - .build(); - var body = protoToken.getBody().toBuilder() - .setObject(ctx) - .build(); - - return protoToken.toBuilder() - .setSignature(signMessagePart(key, body)) - .setBody(body) - .build(); - } - - public static Types.SessionToken createContainerTokenContext(SessionToken sessionToken, - frostfs.refs.Types.ContainerID containerId, - Types.ContainerSessionContext.Verb verb, - frostfs.refs.Types.OwnerID ownerId, - ECDsa key) { - var protoToken = SessionMapper.deserializeSessionToken(sessionToken.getToken()); - - var containerSession = Types.ContainerSessionContext.newBuilder().setVerb(verb); - - if (isNull(containerId) || containerId.getSerializedSize() == 0) { - containerSession.setWildcard(true); - } else { - containerSession.setContainerId(containerId); - } - - var bodyBuilder = protoToken.getBody().toBuilder() - .setContainer(containerSession) - .setSessionKey(ByteString.copyFrom(key.getPublicKeyByte())); - - if (nonNull(ownerId) && ownerId.getSerializedSize() > 0) { - bodyBuilder.setOwnerId(ownerId); - } - - var body = bodyBuilder.build(); - - return protoToken.toBuilder() - .setSignature(signMessagePart(key, body)) - .setBody(body) - .build(); - } -} diff --git a/client/src/main/java/info/frostfs/sdk/tools/RequestSigner.java b/client/src/main/java/info/frostfs/sdk/tools/RequestSigner.java deleted file mode 100644 index a01e4c7..0000000 --- a/client/src/main/java/info/frostfs/sdk/tools/RequestSigner.java +++ /dev/null @@ -1,122 +0,0 @@ -package info.frostfs.sdk.tools; - -import com.google.protobuf.ByteString; -import com.google.protobuf.Message; -import frostfs.session.Types; -import info.frostfs.sdk.constants.CryptoConst; -import info.frostfs.sdk.exceptions.ProcessFrostFSException; -import info.frostfs.sdk.jdo.ECDsa; -import info.frostfs.sdk.utils.MessageHelper; -import org.apache.commons.codec.digest.DigestUtils; -import org.bouncycastle.asn1.sec.SECNamedCurves; -import org.bouncycastle.asn1.sec.SECObjectIdentifiers; -import org.bouncycastle.crypto.params.ECDomainParameters; -import org.bouncycastle.crypto.params.ECPrivateKeyParameters; -import org.bouncycastle.crypto.signers.ECDSASigner; -import org.bouncycastle.crypto.signers.HMacDSAKCalculator; - -import java.math.BigInteger; -import java.security.Signature; - -import static info.frostfs.sdk.constants.CryptoConst.HASH_SIGNATURE_SIZE; -import static info.frostfs.sdk.constants.CryptoConst.RFC6979_SIGNATURE_SIZE; -import static info.frostfs.sdk.constants.ErrorConst.UNSUPPORTED_PROTO_MESSAGE_TYPE_TEMPLATE; -import static info.frostfs.sdk.constants.FieldConst.*; -import static org.bouncycastle.crypto.util.DigestFactory.createSHA256; -import static org.bouncycastle.util.BigIntegers.asUnsignedByteArray; - -public class RequestSigner { - private RequestSigner() { - } - - public static byte[] signData(ECDsa key, byte[] data) { - var hash = new byte[HASH_SIGNATURE_SIZE]; - hash[0] = 0x04; - try { - Signature signature = Signature.getInstance(CryptoConst.SIGNATURE_ALGORITHM); - signature.initSign(key.getPrivateKey()); - signature.update(DigestUtils.sha512(data)); - byte[] sig = signature.sign(); - System.arraycopy(sig, 0, hash, 1, sig.length); - } catch (Exception exp) { - throw new ProcessFrostFSException(exp); - } - - return hash; - } - - public static byte[] signRFC6979(ECDsa key, byte[] data) { - var digest = createSHA256(); - var secp256R1 = SECNamedCurves.getByOID(SECObjectIdentifiers.secp256r1); - - var ecParameters = new ECDomainParameters(secp256R1.getCurve(), secp256R1.getG(), secp256R1.getN()); - var ecPrivateKey = new ECPrivateKeyParameters(new BigInteger(1, key.getPrivateKeyByte()), ecParameters); - var signer = new ECDSASigner(new HMacDSAKCalculator(digest)); - var hash = new byte[digest.getDigestSize()]; - - digest.update(data, 0, data.length); - digest.doFinal(hash, 0); - signer.init(true, ecPrivateKey); - - var rs = signer.generateSignature(hash); - var rBytes = asUnsignedByteArray(rs[0]); - var sBytes = asUnsignedByteArray(rs[1]); - - var signature = new byte[RFC6979_SIGNATURE_SIZE]; - var index = RFC6979_SIGNATURE_SIZE / 2 - rBytes.length; - System.arraycopy(rBytes, 0, signature, index, rBytes.length); - index = RFC6979_SIGNATURE_SIZE - sBytes.length; - System.arraycopy(sBytes, 0, signature, index, sBytes.length); - return signature; - } - - public static frostfs.refs.Types.SignatureRFC6979 signRFC6979(ECDsa key, Message message) { - return frostfs.refs.Types.SignatureRFC6979.newBuilder() - .setKey(ByteString.copyFrom(key.getPublicKeyByte())) - .setSign(ByteString.copyFrom(signRFC6979(key, message.toByteArray()))) - .build(); - } - - public static frostfs.refs.Types.SignatureRFC6979 signRFC6979(ECDsa key, ByteString data) { - return frostfs.refs.Types.SignatureRFC6979.newBuilder() - .setKey(ByteString.copyFrom(key.getPublicKeyByte())) - .setSign(ByteString.copyFrom(signRFC6979(key, data.toByteArray()))) - .build(); - } - - public static frostfs.refs.Types.Signature signMessagePart(ECDsa key, Message data) { - var data2Sign = data.getSerializedSize() == 0 ? new byte[]{} : data.toByteArray(); - return frostfs.refs.Types.Signature.newBuilder() - .setKey(ByteString.copyFrom(key.getPublicKeyByte())) - .setSign(ByteString.copyFrom(signData(key, data2Sign))) - .build(); - } - - public static void sign(Message.Builder request, ECDsa key) { - var meta = (Message) MessageHelper.getField(request, META_HEADER_FIELD_NAME); - var body = (Message) MessageHelper.getField(request, BODY_FIELD_NAME); - var verify = (Message) MessageHelper.getField(request, VERIFY_HEADER_FIELD_NAME); - var verifyOrigin = (Message) MessageHelper.getField(verify, ORIGIN_FIELD_NAME); - - Message.Builder verifyBuilder; - if (verify instanceof Types.RequestVerificationHeader) { - verifyBuilder = Types.RequestVerificationHeader.newBuilder(); - } else if (verify instanceof Types.ResponseVerificationHeader) { - verifyBuilder = Types.ResponseVerificationHeader.newBuilder(); - } else { - throw new ProcessFrostFSException( - String.format(UNSUPPORTED_PROTO_MESSAGE_TYPE_TEMPLATE, verify.getClass().getName()) - ); - } - - if (verifyOrigin.getSerializedSize() == 0) { - MessageHelper.setField(verifyBuilder, BODY_SIGNATURE_FIELD_NAME, signMessagePart(key, body)); - } else { - MessageHelper.setField(verifyBuilder, ORIGIN_FIELD_NAME, verifyOrigin); - } - - MessageHelper.setField(verifyBuilder, META_SIGNATURE_FIELD_NAME, signMessagePart(key, meta)); - MessageHelper.setField(verifyBuilder, ORIGIN_SIGNATURE_FIELD_NAME, signMessagePart(key, verifyOrigin)); - MessageHelper.setField(request, VERIFY_HEADER_FIELD_NAME, verifyBuilder.build()); - } -} diff --git a/client/src/main/java/info/frostfs/sdk/tools/Verifier.java b/client/src/main/java/info/frostfs/sdk/tools/Verifier.java deleted file mode 100644 index 8a5e968..0000000 --- a/client/src/main/java/info/frostfs/sdk/tools/Verifier.java +++ /dev/null @@ -1,140 +0,0 @@ -package info.frostfs.sdk.tools; - -import com.google.protobuf.Message; -import frostfs.session.Types; -import info.frostfs.sdk.constants.CryptoConst; -import info.frostfs.sdk.exceptions.ProcessFrostFSException; -import info.frostfs.sdk.exceptions.ResponseFrostFSException; -import info.frostfs.sdk.exceptions.ValidationFrostFSException; -import info.frostfs.sdk.mappers.response.ResponseStatusMapper; -import info.frostfs.sdk.utils.MessageHelper; -import org.apache.commons.codec.digest.DigestUtils; -import org.bouncycastle.asn1.sec.SECNamedCurves; -import org.bouncycastle.asn1.sec.SECObjectIdentifiers; -import org.bouncycastle.crypto.params.ECDomainParameters; -import org.bouncycastle.crypto.params.ECPublicKeyParameters; -import org.bouncycastle.crypto.signers.ECDSASigner; -import org.bouncycastle.crypto.signers.HMacDSAKCalculator; - -import java.math.BigInteger; -import java.security.PublicKey; -import java.security.Signature; -import java.util.Arrays; - -import static info.frostfs.sdk.KeyExtension.getPublicKeyFromBytes; -import static info.frostfs.sdk.constants.CryptoConst.RFC6979_SIGNATURE_SIZE; -import static info.frostfs.sdk.constants.ErrorConst.INVALID_RESPONSE; -import static info.frostfs.sdk.constants.ErrorConst.WRONG_SIGNATURE_SIZE_TEMPLATE; -import static info.frostfs.sdk.constants.FieldConst.*; -import static java.util.Objects.isNull; -import static org.bouncycastle.crypto.util.DigestFactory.createSHA256; -import static org.bouncycastle.util.BigIntegers.fromUnsignedByteArray; - -public class Verifier { - private Verifier() { - } - - public static boolean verifyRFC6979(frostfs.refs.Types.SignatureRFC6979 signature, Message data) { - return verifyRFC6979(signature.getKey().toByteArray(), data.toByteArray(), signature.getSign().toByteArray()); - } - - public static boolean verifyRFC6979(byte[] publicKey, byte[] data, byte[] sig) { - if (isNull(publicKey) || isNull(data) || isNull(sig)) { - return false; - } - - var rs = decodeSignature(sig); - var digest = createSHA256(); - var signer = new ECDSASigner(new HMacDSAKCalculator(digest)); - var secp256R1 = SECNamedCurves.getByOID(SECObjectIdentifiers.secp256r1); - var ecParameters = new ECDomainParameters(secp256R1.getCurve(), secp256R1.getG(), secp256R1.getN()); - var ecPublicKey = new ECPublicKeyParameters(secp256R1.getCurve().decodePoint(publicKey), ecParameters); - var hash = new byte[digest.getDigestSize()]; - digest.update(data, 0, data.length); - digest.doFinal(hash, 0); - signer.init(false, ecPublicKey); - return signer.verifySignature(hash, rs[0], rs[1]); - } - - private static BigInteger[] decodeSignature(byte[] sig) { - if (sig.length != RFC6979_SIGNATURE_SIZE) { - throw new ValidationFrostFSException( - String.format(WRONG_SIGNATURE_SIZE_TEMPLATE, RFC6979_SIGNATURE_SIZE, sig.length) - ); - } - - var rs = new BigInteger[2]; - - rs[0] = fromUnsignedByteArray(Arrays.copyOfRange(sig, 0, (RFC6979_SIGNATURE_SIZE / 2) - 1)); - rs[1] = fromUnsignedByteArray( - Arrays.copyOfRange(sig, RFC6979_SIGNATURE_SIZE / 2, RFC6979_SIGNATURE_SIZE - 1) - ); - return rs; - } - - public static void checkResponse(Message response) { - if (!verify(response)) { - throw new ResponseFrostFSException(INVALID_RESPONSE); - } - - var metaHeader = (Types.ResponseMetaHeader) MessageHelper.getField(response, META_HEADER_FIELD_NAME); - if (isNull(metaHeader) || metaHeader.getSerializedSize() == 0) { - return; - } - - var status = ResponseStatusMapper.toModel(metaHeader.getStatus()); - if (!status.isSuccess()) { - throw new ResponseFrostFSException(status); - } - } - - public static boolean verify(Message response) { - var body = (Message) MessageHelper.getField(response, BODY_FIELD_NAME); - var metaHeader = (Types.ResponseMetaHeader) MessageHelper.getField(response, META_HEADER_FIELD_NAME); - var verifyHeader = (Types.ResponseVerificationHeader) - MessageHelper.getField(response, VERIFY_HEADER_FIELD_NAME); - - return verifyMatryoshkaLevel(body, metaHeader, verifyHeader); - } - - public static boolean verifyMatryoshkaLevel(Message data, - frostfs.session.Types.ResponseMetaHeader meta, - frostfs.session.Types.ResponseVerificationHeader verification) { - if (!verifyMessagePart(verification.getMetaSignature(), meta)) { - return false; - } - - var origin = verification.getOrigin(); - if (!verifyMessagePart(verification.getOriginSignature(), origin)) { - return false; - } - - if (origin.getSerializedSize() == 0) { - return verifyMessagePart(verification.getBodySignature(), data); - } - return verification.getBodySignature().getSerializedSize() == 0 - && verifyMatryoshkaLevel(data, meta.getOrigin(), origin); - } - - public static boolean verifyMessagePart(frostfs.refs.Types.Signature sig, Message data) { - if (sig.getSerializedSize() == 0 || sig.getKey().isEmpty() || sig.getSign().isEmpty()) { - return false; - } - - var publicKey = getPublicKeyFromBytes(sig.getKey().toByteArray()); - - var data2Verify = data.getSerializedSize() == 0 ? new byte[]{} : data.toByteArray(); - return verifyData(publicKey, data2Verify, sig.getSign().toByteArray()); - } - - public static boolean verifyData(PublicKey publicKey, byte[] data, byte[] sig) { - try { - Signature signature = Signature.getInstance(CryptoConst.SIGNATURE_ALGORITHM); - signature.initVerify(publicKey); - signature.update(DigestUtils.sha512(data)); - return signature.verify(Arrays.copyOfRange(sig, 1, sig.length)); - } catch (Exception exp) { - throw new ProcessFrostFSException(exp); - } - } -} diff --git a/client/src/main/java/info/frostfs/sdk/tools/ape/MarshalFunction.java b/client/src/main/java/info/frostfs/sdk/tools/ape/MarshalFunction.java deleted file mode 100644 index 1b08d5c..0000000 --- a/client/src/main/java/info/frostfs/sdk/tools/ape/MarshalFunction.java +++ /dev/null @@ -1,5 +0,0 @@ -package info.frostfs.sdk.tools.ape; - -public interface MarshalFunction { - int marshal(byte[] buf, int offset, T t); -} diff --git a/client/src/main/java/info/frostfs/sdk/tools/ape/RuleDeserializer.java b/client/src/main/java/info/frostfs/sdk/tools/ape/RuleDeserializer.java deleted file mode 100644 index cbba2e2..0000000 --- a/client/src/main/java/info/frostfs/sdk/tools/ape/RuleDeserializer.java +++ /dev/null @@ -1,198 +0,0 @@ -package info.frostfs.sdk.tools.ape; - -import info.frostfs.sdk.dto.ape.*; -import info.frostfs.sdk.enums.ConditionKindType; -import info.frostfs.sdk.enums.ConditionType; -import info.frostfs.sdk.enums.RuleMatchType; -import info.frostfs.sdk.enums.RuleStatus; -import info.frostfs.sdk.exceptions.FrostFSException; -import info.frostfs.sdk.exceptions.ValidationFrostFSException; -import org.apache.commons.lang3.ArrayUtils; - -import java.lang.reflect.Array; -import java.nio.charset.StandardCharsets; -import java.util.concurrent.atomic.AtomicInteger; - -import static info.frostfs.sdk.constants.ErrorConst.*; -import static info.frostfs.sdk.constants.FieldConst.EMPTY_STRING; -import static info.frostfs.sdk.constants.RuleConst.*; - -public class RuleDeserializer { - private RuleDeserializer() { - } - - public static Chain deserialize(byte[] data) { - if (ArrayUtils.isEmpty(data)) { - throw new ValidationFrostFSException(INPUT_PARAM_IS_MISSING); - } - - AtomicInteger offset = new AtomicInteger(0); - Chain chain = new Chain(); - - var version = uInt8Unmarshal(data, offset); - if (version != VERSION) { - throw new FrostFSException(String.format(UNSUPPORTED_MARSHALLER_VERSION_TEMPLATE, version)); - } - - var chainVersion = uInt8Unmarshal(data, offset); - if (chainVersion != CHAIN_MARSHAL_VERSION) { - throw new FrostFSException(String.format(UNSUPPORTED_CHAIN_VERSION_TEMPLATE, chainVersion)); - } - - chain.setId(sliceUnmarshal(data, offset, Byte.class, RuleDeserializer::uInt8Unmarshal)); - chain.setRules(sliceUnmarshal(data, offset, Rule.class, RuleDeserializer::unmarshalRule)); - chain.setMatchType(RuleMatchType.get(uInt8Unmarshal(data, offset))); - - verifyUnmarshal(data, offset); - - return chain; - } - - private static Byte uInt8Unmarshal(byte[] buf, AtomicInteger offset) { - if (buf.length - offset.get() < 1) { - throw new FrostFSException( - String.format(BYTES_ARE_OVER_FOR_DESERIALIZE_TEMPLATE, Byte.class.getName(), offset.get())); - } - - return buf[offset.getAndAdd(1)]; - } - - public static long varInt(byte[] buf, AtomicInteger offset) { - long ux = uVarInt(buf, offset); // ok to continue in presence of error - long x = ux >> 1; - if ((ux & 1) != 0) { - x = ~x; - } - return x; - } - - - public static long uVarInt(byte[] buf, AtomicInteger offset) { - long x = 0; - int s = 0; - - for (int i = offset.get(); i < buf.length; i++) { - long b = buf[i]; - if (i == MAX_VAR_INT_LENGTH) { - offset.set(-(i + 1)); - return 0; // overflow - } - if (b >= 0) { - if (i == MAX_VAR_INT_LENGTH - 1 && b > 1) { - offset.set(-(i + 1)); - return 0; // overflow - } - offset.set(i + 1); - return x | (b << s); - } - x |= (b & OFFSET127) << s; - s += UNSIGNED_SERIALIZE_SIZE; - } - offset.set(0); - return 0; - } - - private static T[] sliceUnmarshal(byte[] buf, - AtomicInteger offset, - Class clazz, - UnmarshalFunction unmarshalT) { - var size = (int) varInt(buf, offset); - if (size == NULL_SLICE) { - return null; - } - - if (size > MAX_SLICE_LENGTH) { - throw new ValidationFrostFSException(String.format(SLICE_IS_TOO_BIG_TEMPLATE, size)); - } - - if (size < 0) { - throw new ValidationFrostFSException(String.format(SLICE_SIZE_IS_INVALID_TEMPLATE, size)); - } - - T[] result = (T[]) Array.newInstance(clazz, size); - for (int i = 0; i < result.length; i++) { - result[i] = unmarshalT.unmarshal(buf, offset); - } - - return result; - } - - private static boolean boolUnmarshal(byte[] buf, AtomicInteger offset) { - return uInt8Unmarshal(buf, offset) == BYTE_TRUE; - } - - private static long int64Unmarshal(byte[] buf, AtomicInteger offset) { - if (buf.length - offset.get() < Long.BYTES) { - throw new ValidationFrostFSException( - String.format(BYTES_ARE_OVER_FOR_DESERIALIZE_TEMPLATE, Long.class.getName(), offset.get()) - ); - } - - return varInt(buf, offset); - } - - private static String stringUnmarshal(byte[] buf, AtomicInteger offset) { - int size = (int) int64Unmarshal(buf, offset); - if (size == 0) { - return EMPTY_STRING; - } - - if (size > MAX_SLICE_LENGTH) { - throw new ValidationFrostFSException(String.format(STRING_IS_TOO_BIG_TEMPLATE, size)); - } - - if (size < 0) { - throw new ValidationFrostFSException(String.format(STRING_SIZE_IS_INVALID_TEMPLATE, size)); - } - - if (buf.length - offset.get() < size) { - throw new ValidationFrostFSException( - String.format(BYTES_ARE_OVER_FOR_DESERIALIZE_TEMPLATE, String.class.getName(), offset.get()) - ); - } - - return new String(buf, offset.getAndAdd(size), size, StandardCharsets.UTF_8); - } - - private static Actions unmarshalActions(byte[] buf, AtomicInteger offset) { - Actions actions = new Actions(); - actions.setInverted(boolUnmarshal(buf, offset)); - actions.setNames(sliceUnmarshal(buf, offset, String.class, RuleDeserializer::stringUnmarshal)); - return actions; - } - - private static Condition unmarshalCondition(byte[] buf, AtomicInteger offset) { - Condition condition = new Condition(); - condition.setOp(ConditionType.get(uInt8Unmarshal(buf, offset))); - condition.setKind(ConditionKindType.get(uInt8Unmarshal(buf, offset))); - condition.setKey(stringUnmarshal(buf, offset)); - condition.setValue(stringUnmarshal(buf, offset)); - - return condition; - } - - private static Rule unmarshalRule(byte[] buf, AtomicInteger offset) { - Rule rule = new Rule(); - rule.setStatus(RuleStatus.get(uInt8Unmarshal(buf, offset))); - rule.setActions(unmarshalActions(buf, offset)); - rule.setResources(unmarshalResources(buf, offset)); - rule.setAny(boolUnmarshal(buf, offset)); - rule.setConditions(sliceUnmarshal(buf, offset, Condition.class, RuleDeserializer::unmarshalCondition)); - - return rule; - } - - private static Resources unmarshalResources(byte[] buf, AtomicInteger offset) { - Resources resources = new Resources(); - resources.setInverted(boolUnmarshal(buf, offset)); - resources.setNames(sliceUnmarshal(buf, offset, String.class, RuleDeserializer::stringUnmarshal)); - - return resources; - } - - private static void verifyUnmarshal(byte[] buf, AtomicInteger offset) { - if (buf.length != offset.get()) { - throw new ValidationFrostFSException(UNMARSHAL_SIZE_DIFFERS); - } - } -} diff --git a/client/src/main/java/info/frostfs/sdk/tools/ape/RuleSerializer.java b/client/src/main/java/info/frostfs/sdk/tools/ape/RuleSerializer.java deleted file mode 100644 index 43e7210..0000000 --- a/client/src/main/java/info/frostfs/sdk/tools/ape/RuleSerializer.java +++ /dev/null @@ -1,260 +0,0 @@ -package info.frostfs.sdk.tools.ape; - -import info.frostfs.sdk.dto.ape.*; -import info.frostfs.sdk.exceptions.ValidationFrostFSException; -import org.apache.commons.lang3.StringUtils; - -import java.nio.charset.StandardCharsets; -import java.util.function.Function; - -import static info.frostfs.sdk.constants.ErrorConst.*; -import static info.frostfs.sdk.constants.RuleConst.*; -import static java.util.Objects.isNull; -import static java.util.Objects.nonNull; - -public class RuleSerializer { - private RuleSerializer() { - } - - public static byte[] serialize(Chain chain) { - if (isNull(chain)) { - throw new ValidationFrostFSException(String.format(INPUT_PARAM_IS_MISSING_TEMPLATE, Chain.class.getName())); - } - - int s = U_INT_8_SIZE // Marshaller version - + U_INT_8_SIZE // Chain version - + sliceSize(chain.getId(), b -> BYTE_SIZE) - + sliceSize(chain.getRules(), RuleSerializer::ruleSize) - + U_INT_8_SIZE; // MatchType - - byte[] buf = new byte[s]; - - int offset = uInt8Marshal(buf, 0, VERSION); - offset = uInt8Marshal(buf, offset, (byte) CHAIN_MARSHAL_VERSION); - offset = sliceMarshal(buf, offset, chain.getId(), RuleSerializer::byteMarshal); - offset = sliceMarshal(buf, offset, chain.getRules(), RuleSerializer::marshalRule); - offset = uInt8Marshal(buf, offset, (byte) chain.getMatchType().value); - - verifyMarshal(buf, offset); - - return buf; - } - - private static int sliceSize(T[] slice, Function sizeOf) { - if (isNull(slice)) { - return NULL_SLICE_SIZE; - } - - // Assuming int64Size is the size of the slice - int size = int64Size(slice.length); - for (T v : slice) { - size += sizeOf.apply(v); - } - - return size; - } - - /* - * https://cs.opensource.google/go/go/+/master:src/encoding/binary/varint.go;l=92;drc=dac9b9ddbd5160c5f4552410f5f828 - * 1bd5eed38c - * - * and - * - * https://cs.opensource.google/go/go/+/master:src/encoding/binary/varint.go;l=41;drc=dac9b9ddbd5160c5f4552410f5f828 - * 1bd5eed38c - * */ - private static int int64Size(long value) { - long ux = value << 1; - if (value < 0) { - ux = ~ux; - } - - int size = 0; - while (ux >= OFFSET128) { - size++; - ux >>>= UNSIGNED_SERIALIZE_SIZE; - } - - return size + 1; - } - - private static int stringSize(String s) { - int len = nonNull(s) ? s.length() : 0; - return int64Size(len) + len; - } - - private static int actionsSize(Actions action) { - return BOOL_SIZE // Inverted - + (nonNull(action) ? sliceSize(action.getNames(), RuleSerializer::stringSize) : 0); - } - - private static int resourcesSize(Resources resource) { - return BOOL_SIZE // Inverted - + (nonNull(resource) ? sliceSize(resource.getNames(), RuleSerializer::stringSize) : 0); - } - - private static int conditionSize(Condition condition) { - if (isNull(condition)) { - throw new ValidationFrostFSException(String.format(REQUIRED_FIELD_TEMPLATE, Rule.class.getName())); - } - - return BYTE_SIZE // Op - + BYTE_SIZE // Object - + stringSize(condition.getKey()) - + stringSize(condition.getValue()); - } - - private static int ruleSize(Rule rule) { - if (isNull(rule)) { - throw new ValidationFrostFSException(String.format(REQUIRED_FIELD_TEMPLATE, Rule.class.getName())); - } - - return BYTE_SIZE // Status - + actionsSize(rule.getActions()) - + resourcesSize(rule.getResources()) - + BOOL_SIZE // Any - + sliceSize(rule.getConditions(), RuleSerializer::conditionSize); - } - - private static int uInt8Marshal(byte[] buf, int offset, byte value) { - if (buf.length - offset < 1) { - throw new ValidationFrostFSException( - String.format(BYTES_ARE_OVER_FOR_SERIALIZE_TEMPLATE, Byte.class.getName(), 1) - ); - } - - buf[offset] = value; - - return offset + 1; - } - - private static int byteMarshal(byte[] buf, int offset, byte value) { - return uInt8Marshal(buf, offset, value); - } - - // putVarInt encodes an int64 into buf and returns the number of bytes written. - private static int putVarInt(byte[] buf, int offset, long x) { - long ux = x << 1; - if (x < 0) { - ux = ~ux; - } - - return putUVarInt(buf, offset, ux); - } - - private static int putUVarInt(byte[] buf, int offset, long x) { - while (x >= OFFSET128) { - buf[offset] = (byte) (x | OFFSET128); - x >>>= UNSIGNED_SERIALIZE_SIZE; - offset++; - } - buf[offset] = (byte) x; - return offset + 1; - } - - private static int int64Marshal(byte[] buf, int offset, long v) { - var size = int64Size(v); - if (buf.length - offset < size) { - throw new ValidationFrostFSException( - String.format(BYTES_ARE_OVER_FOR_SERIALIZE_TEMPLATE, Long.class.getName(), size) - ); - } - - return putVarInt(buf, offset, v); - } - - private static int sliceMarshal(byte[] buf, int offset, T[] slice, MarshalFunction marshalT) { - if (isNull(slice)) { - return int64Marshal(buf, offset, NULL_SLICE); - } - - if (slice.length > MAX_SLICE_LENGTH) { - throw new ValidationFrostFSException(String.format(SLICE_IS_TOO_BIG_TEMPLATE, slice.length)); - } - - offset = int64Marshal(buf, offset, slice.length); - for (T v : slice) { - offset = marshalT.marshal(buf, offset, v); - } - - return offset; - } - - private static int boolMarshal(byte[] buf, int offset, boolean value) { - return uInt8Marshal(buf, offset, value ? BYTE_TRUE : BYTE_FALSE); - } - - private static int stringMarshal(byte[] buf, int offset, String value) { - if (StringUtils.isBlank(value)) { - throw new ValidationFrostFSException(STRING_IS_BLANK); - } - - if (value.length() > MAX_SLICE_LENGTH) { - throw new ValidationFrostFSException(String.format(STRING_IS_TOO_BIG_TEMPLATE, value.length())); - } - - if (buf.length - offset < int64Size(value.length()) + value.length()) { - throw new ValidationFrostFSException( - String.format(BYTES_ARE_OVER_FOR_SERIALIZE_TEMPLATE, String.class.getName(), value.length()) - ); - } - - offset = int64Marshal(buf, offset, value.length()); - if (value.isEmpty()) { - return offset; - } - - byte[] stringBytes = value.getBytes(StandardCharsets.UTF_8); - - // Copy exactly value.length() bytes as in the original code - System.arraycopy(stringBytes, 0, buf, offset, value.length()); - return offset + value.length(); - } - - private static int marshalActions(byte[] buf, int offset, Actions action) { - if (isNull(action)) { - throw new ValidationFrostFSException(String.format(REQUIRED_FIELD_TEMPLATE, Actions.class.getName())); - } - - offset = boolMarshal(buf, offset, action.isInverted()); - return sliceMarshal(buf, offset, action.getNames(), RuleSerializer::stringMarshal); - } - - private static int marshalCondition(byte[] buf, int offset, Condition condition) { - if (isNull(condition)) { - throw new ValidationFrostFSException(String.format(REQUIRED_FIELD_TEMPLATE, Condition.class.getName())); - } - - offset = byteMarshal(buf, offset, (byte) condition.getOp().value); - offset = byteMarshal(buf, offset, (byte) condition.getKind().value); - offset = stringMarshal(buf, offset, condition.getKey()); - return stringMarshal(buf, offset, condition.getValue()); - } - - private static int marshalRule(byte[] buf, int offset, Rule rule) { - if (isNull(rule)) { - throw new ValidationFrostFSException(String.format(REQUIRED_FIELD_TEMPLATE, Rule.class.getName())); - } - - offset = byteMarshal(buf, offset, (byte) rule.getStatus().value); - offset = marshalActions(buf, offset, rule.getActions()); - offset = marshalResources(buf, offset, rule.getResources()); - offset = boolMarshal(buf, offset, rule.isAny()); - return sliceMarshal(buf, offset, rule.getConditions(), RuleSerializer::marshalCondition); - } - - private static int marshalResources(byte[] buf, int offset, Resources resources) { - if (isNull(resources)) { - throw new ValidationFrostFSException(String.format(REQUIRED_FIELD_TEMPLATE, Resources.class.getName())); - } - - offset = boolMarshal(buf, offset, resources.isInverted()); - return sliceMarshal(buf, offset, resources.getNames(), RuleSerializer::stringMarshal); - } - - private static void verifyMarshal(byte[] buf, int lastOffset) { - if (buf.length != lastOffset) { - throw new ValidationFrostFSException(MARSHAL_SIZE_DIFFERS); - } - } -} diff --git a/client/src/main/java/info/frostfs/sdk/tools/ape/UnmarshalFunction.java b/client/src/main/java/info/frostfs/sdk/tools/ape/UnmarshalFunction.java deleted file mode 100644 index ce0977e..0000000 --- a/client/src/main/java/info/frostfs/sdk/tools/ape/UnmarshalFunction.java +++ /dev/null @@ -1,7 +0,0 @@ -package info.frostfs.sdk.tools.ape; - -import java.util.concurrent.atomic.AtomicInteger; - -public interface UnmarshalFunction { - T unmarshal(byte[] buf, AtomicInteger offset); -} diff --git a/client/src/main/java/info/frostfs/sdk/utils/DeadLineUtil.java b/client/src/main/java/info/frostfs/sdk/utils/DeadLineUtil.java deleted file mode 100644 index 96ea46f..0000000 --- a/client/src/main/java/info/frostfs/sdk/utils/DeadLineUtil.java +++ /dev/null @@ -1,25 +0,0 @@ -package info.frostfs.sdk.utils; - -import info.frostfs.sdk.exceptions.ValidationFrostFSException; -import io.grpc.stub.AbstractStub; - -import java.util.concurrent.TimeUnit; - -import static info.frostfs.sdk.constants.ErrorConst.PARAM_IS_MISSING_TEMPLATE; -import static java.util.Objects.isNull; - -public class DeadLineUtil { - private DeadLineUtil() { - } - - public static > T deadLineAfter(T stub, long deadLine, TimeUnit timeUnit) { - if (isNull(stub)) { - throw new ValidationFrostFSException( - String.format(PARAM_IS_MISSING_TEMPLATE, AbstractStub.class.getName()) - ); - } - - timeUnit = isNull(timeUnit) ? TimeUnit.MILLISECONDS : timeUnit; - return deadLine > 0 ? stub.withDeadlineAfter(deadLine, timeUnit) : stub; - } -} diff --git a/client/src/main/java/info/frostfs/sdk/utils/FrostFSMessages.java b/client/src/main/java/info/frostfs/sdk/utils/FrostFSMessages.java deleted file mode 100644 index 04b7dab..0000000 --- a/client/src/main/java/info/frostfs/sdk/utils/FrostFSMessages.java +++ /dev/null @@ -1,20 +0,0 @@ -package info.frostfs.sdk.utils; - -import org.slf4j.Logger; - -public class FrostFSMessages { - private FrostFSMessages() { - } - - public static void sessionCreationError(Logger logger, String address, String error) { - logger.warn("Failed to create frostfs session token for client. Address {}, {}", address, error); - } - - public static void errorThresholdReached(Logger logger, String address, long threshold) { - logger.warn("Error threshold reached. Address {}, threshold {}", address, threshold); - } - - public static void healthChanged(Logger logger, String address, boolean healthy, String error) { - logger.warn("Health has changed: {} healthy {}, reason {}", address, healthy, error); - } -} diff --git a/client/src/main/java/info/frostfs/sdk/utils/MessageHelper.java b/client/src/main/java/info/frostfs/sdk/utils/MessageHelper.java deleted file mode 100644 index 5c9da50..0000000 --- a/client/src/main/java/info/frostfs/sdk/utils/MessageHelper.java +++ /dev/null @@ -1,30 +0,0 @@ -package info.frostfs.sdk.utils; - -import com.google.protobuf.Message; -import com.google.protobuf.MessageOrBuilder; -import info.frostfs.sdk.exceptions.ValidationFrostFSException; -import org.apache.commons.lang3.StringUtils; - -import static info.frostfs.sdk.constants.ErrorConst.SOME_PARAM_IS_MISSING; -import static java.util.Objects.isNull; - -public class MessageHelper { - private MessageHelper() { - } - - public static Object getField(MessageOrBuilder messageOrBuilder, String fieldName) { - if (isNull(messageOrBuilder) || StringUtils.isBlank(fieldName)) { - throw new ValidationFrostFSException(SOME_PARAM_IS_MISSING); - } - - return messageOrBuilder.getField(messageOrBuilder.getDescriptorForType().findFieldByName(fieldName)); - } - - public static void setField(Message.Builder builder, String fieldName, Object value) { - if (isNull(builder) || StringUtils.isBlank(fieldName) || isNull(value)) { - throw new ValidationFrostFSException(SOME_PARAM_IS_MISSING); - } - - builder.setField(builder.getDescriptorForType().findFieldByName(fieldName), value); - } -} diff --git a/client/src/main/java/info/frostfs/sdk/utils/Validator.java b/client/src/main/java/info/frostfs/sdk/utils/Validator.java deleted file mode 100644 index 5d61493..0000000 --- a/client/src/main/java/info/frostfs/sdk/utils/Validator.java +++ /dev/null @@ -1,140 +0,0 @@ -package info.frostfs.sdk.utils; - -import info.frostfs.sdk.annotations.*; -import info.frostfs.sdk.constants.ErrorConst; -import info.frostfs.sdk.exceptions.ProcessFrostFSException; -import info.frostfs.sdk.exceptions.ValidationFrostFSException; -import org.apache.commons.lang3.StringUtils; - -import java.lang.reflect.Field; - -import static info.frostfs.sdk.constants.ErrorConst.FIELDS_DELIMITER_COMMA; -import static java.util.Objects.isNull; - -public class Validator { - private Validator() { - } - - public static void validate(T object) { - StringBuilder errorMessage = new StringBuilder(); - process(object, errorMessage); - - if (errorMessage.length() != 0) { - errorMessage.insert(0, System.lineSeparator()); - throw new ValidationFrostFSException(errorMessage.toString()); - } - } - - - private static void process(T object, StringBuilder errorMessage) { - if (isNull(object)) { - errorMessage.append(ErrorConst.OBJECT_IS_NULL); - return; - } - - Class clazz = object.getClass(); - - if (clazz.isAnnotationPresent(ComplexAtLeastOneIsFilled.class)) { - processComplexAtLeastOneIsFilled(object, clazz, errorMessage); - } - - if (clazz.isAnnotationPresent(AtLeastOneIsFilled.class)) { - processAtLeastOneIsFilled(object, clazz, errorMessage); - } - - for (Field field : clazz.getDeclaredFields()) { - field.setAccessible(true); - - if (field.isAnnotationPresent(Validate.class)) { - processValidate(object, errorMessage, field); - } - - if (field.isAnnotationPresent(NotNull.class)) { - processNotNull(object, errorMessage, field); - } - - if (field.isAnnotationPresent(NotBlank.class)) { - processNotBlank(object, errorMessage, field); - } - } - } - - private static void processNotNull(T object, StringBuilder errorMessage, Field field) { - if (isNull(getFieldValue(object, field))) { - errorMessage - .append(String.format(ErrorConst.REQUIRED_FIELD_TEMPLATE, field.getName())) - .append(System.lineSeparator()); - } - } - - private static void processNotBlank(T object, StringBuilder errorMessage, Field field) { - var value = getFieldValue(object, field); - if (isNull(value) || (value instanceof String && StringUtils.isBlank((String) value))) { - errorMessage - .append(String.format(ErrorConst.REQUIRED_FIELD_TEMPLATE, field.getName())) - .append(System.lineSeparator()); - } - } - - private static void processValidate(T object, StringBuilder errorMessage, Field field) { - if (isNull(object)) { - return; - } - - process(getFieldValue(object, field), errorMessage); - } - - private static void processComplexAtLeastOneIsFilled(T object, Class clazz, StringBuilder errorMessage) { - var annotation = clazz.getAnnotation(ComplexAtLeastOneIsFilled.class); - for (AtLeastOneIsFilled value : annotation.value()) { - processAtLeastOneIsFilled(object, clazz, errorMessage, value); - } - } - - private static void processAtLeastOneIsFilled(T object, Class clazz, StringBuilder errorMessage) { - var annotation = clazz.getAnnotation(AtLeastOneIsFilled.class); - processAtLeastOneIsFilled(object, clazz, errorMessage, annotation); - } - - private static void processAtLeastOneIsFilled(T object, - Class clazz, - StringBuilder errorMessage, - AtLeastOneIsFilled annotation) { - var emptyFieldsCount = 0; - for (String fieldName : annotation.fields()) { - var field = getField(clazz, fieldName); - field.setAccessible(true); - - var value = getFieldValue(object, field); - if (isNull(value) || (value instanceof String && StringUtils.isBlank((String) value))) { - emptyFieldsCount++; - } - } - - if (emptyFieldsCount == annotation.fields().length) { - errorMessage - .append(String.format( - annotation.message(), - String.join(FIELDS_DELIMITER_COMMA, annotation.fields()) - )) - .append(System.lineSeparator()); - } - } - - - private static Object getFieldValue(T object, Field field) { - try { - return field.get(object); - } catch (IllegalAccessException e) { - throw new ProcessFrostFSException(e); - } - } - - private static Field getField(Class clazz, String fieldName) { - try { - return clazz.getDeclaredField(fieldName); - } catch (NoSuchFieldException e) { - throw new ProcessFrostFSException(e); - } - } -} diff --git a/client/src/main/java/info/frostfs/sdk/utils/WaitUtil.java b/client/src/main/java/info/frostfs/sdk/utils/WaitUtil.java deleted file mode 100644 index 2016c43..0000000 --- a/client/src/main/java/info/frostfs/sdk/utils/WaitUtil.java +++ /dev/null @@ -1,14 +0,0 @@ -package info.frostfs.sdk.utils; - -public class WaitUtil { - private WaitUtil() { - } - - public static void sleep(long ms) { - try { - Thread.sleep(ms); - } catch (InterruptedException ex) { - Thread.currentThread().interrupt(); - } - } -} diff --git a/client/src/test/java/info/frostfs/sdk/placement/PlacementVectorTest.java b/client/src/test/java/info/frostfs/sdk/placement/PlacementVectorTest.java deleted file mode 100644 index 8ae8d48..0000000 --- a/client/src/test/java/info/frostfs/sdk/placement/PlacementVectorTest.java +++ /dev/null @@ -1,238 +0,0 @@ -package info.frostfs.sdk.placement; - -import info.frostfs.sdk.dto.netmap.*; -import info.frostfs.sdk.enums.netmap.FilterOperation; -import info.frostfs.sdk.enums.netmap.NodeState; -import info.frostfs.sdk.enums.netmap.SelectorClause; -import lombok.Getter; -import lombok.SneakyThrows; -import org.junit.jupiter.api.Test; -import org.yaml.snakeyaml.Yaml; - -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.*; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static org.junit.jupiter.api.Assertions.*; - -public class PlacementVectorTest { - private static final Yaml YAML = new Yaml(); - - private static void compareNodes(Map attrs, NodeInfo nodeInfo) { - assertEquals(attrs.size(), nodeInfo.getAttributes().size()); - assertEquals( - attrs.entrySet().stream().sorted(Map.Entry.comparingByKey()).collect(Collectors.toList()), - nodeInfo.getAttributes().entrySet().stream().sorted(Map.Entry.comparingByKey()).collect(Collectors.toList()) - ); - } - - @SneakyThrows - @Test - public void placementTest() { - Path resourceDirYaml = Paths.get(Objects.requireNonNull(getClass().getClassLoader() - .getResource("placement")).toURI()); - - List yamlFiles; - try (Stream paths = Files.walk(resourceDirYaml)) { - yamlFiles = paths.filter(Files::isRegularFile).collect(Collectors.toList()); - } - - Version v = new Version(2, 13); - String[] addresses = {"localhost", "server1"}; - - for (Path file : yamlFiles) { - TestCase testCase = YAML.loadAs(Files.newInputStream(file), TestCase.class); - - assertNotNull(testCase); - assertNotNull(testCase.nodes); - assertTrue(testCase.nodes.length > 0); - - List nodes = Arrays.stream(testCase.nodes) - .map(n -> new NodeInfo( - n.state, - v, - List.of(addresses), - n.attributes != null ? - Arrays.stream(n.attributes) - .collect(Collectors.toMap(KeyValuePair::getKey, KeyValuePair::getValue)) : - Collections.emptyMap(), - n.getPublicKeyBytes() - )) - .collect(Collectors.toList()); - - NetmapSnapshot netmap = new NetmapSnapshot(100L, nodes); - - assertNotNull(testCase.tests); - - for (var entry : testCase.tests.entrySet()) { - var test = entry.getValue(); - PlacementPolicy policy = new PlacementPolicy( - test.policy.replicas != null ? - Arrays.stream(test.policy.replicas) - .map(r -> new Replica(r.count, r.selector)) - .toArray(Replica[]::new) : - new Replica[0], - test.policy.unique, - test.policy.containerBackupFactor, - test.policy.filters != null - ? Arrays.stream(test.policy.filters) - .map(FilterDto::getFilter) - .toArray(Filter[]::new) - : new Filter[]{}, - test.policy.selectors != null - ? Arrays.stream(test.policy.selectors) - .map(SelectorDto::getSelector) - .toArray(Selector[]::new) - : new Selector[]{} - ); - - try { - var vector = new PlacementVector(netmap); - NodeInfo[][] result = vector.containerNodes(policy, test.getPivotBytes()); - - if (test.result == null) { - if (test.error != null && !test.error.isEmpty()) { - fail("Error is expected but has not been thrown"); - } else { - assertNotNull(test.policy.replicas); - assertEquals(result.length, test.policy.replicas.length); - - for (NodeInfo[] nodesArr : result) { - assertEquals(0, nodesArr.length); - } - } - } else { - assertEquals(test.result.length, result.length); - - for (int i = 0; i < test.result.length; i++) { - assertEquals(test.result[i].length, result[i].length); - for (int j = 0; j < test.result[i].length; j++) { - compareNodes(nodes.get(test.result[i][j]).getAttributes(), result[i][j]); - } - } - - if (test.placement != null - && test.placement.result != null - && test.placement.getPivotBytes() != null) { - NodeInfo[][] placementResult = vector.placementVectors( - result, test.placement.getPivotBytes() - ); - - assertEquals(test.placement.result.length, placementResult.length); - - for (int i = 0; i < placementResult.length; i++) { - assertEquals(test.placement.result[i].length, placementResult[i].length); - for (int j = 0; j < placementResult[i].length; j++) { - compareNodes( - nodes.get(test.placement.result[i][j]).getAttributes(), - placementResult[i][j] - ); - } - } - } - } - } catch (Exception ex) { - if (test.error != null && !test.error.isEmpty()) { - assertTrue(ex.getMessage().contains(test.error)); - } else { - throw ex; - } - } - } - } - } - - - public static class TestCase { - public String name; - public String comment; - public Node[] nodes; - public Map tests; - } - - public static class Node { - public KeyValuePair[] attributes; - public String publicKey; - public String[] addresses; - public NodeState state = NodeState.ONLINE; - - public byte[] getPublicKeyBytes() { - return publicKey == null || publicKey.isEmpty() ? new byte[0] : Base64.getDecoder().decode(publicKey); - } - } - - @Getter - public static class KeyValuePair { - public String key; - public String value; - } - - public static class TestData { - public PolicyDto policy; - public String pivot; - public int[][] result; - public String error; - public ResultData placement; - - public byte[] getPivotBytes() { - return pivot == null ? null : Base64.getDecoder().decode(pivot); - } - } - - public static class PolicyDto { - public boolean unique; - public int containerBackupFactor; - public FilterDto[] filters; - public ReplicaDto[] replicas; - public SelectorDto[] selectors; - } - - public static class SelectorDto { - public int count; - public String name; - public SelectorClause clause; - public String attribute; - public String filter; - - public Selector getSelector() { - return new Selector(name != null ? name : "", count, clause, attribute, filter); - } - } - - public static class FilterDto { - public String name; - public String key; - public FilterOperation op; - public String value; - public FilterDto[] filters; - - public Filter getFilter() { - return new Filter( - name != null ? name : "", - key != null ? key : "", - op, - value != null ? value : "", - filters != null - ? Arrays.stream(filters).map(FilterDto::getFilter).toArray(Filter[]::new) - : new Filter[0] - ); - } - } - - public static class ReplicaDto { - public int count; - public String selector; - } - - public static class ResultData { - public String pivot; - public int[][] result; - - public byte[] getPivotBytes() { - return pivot == null ? null : Base64.getDecoder().decode(pivot); - } - } -} diff --git a/client/src/test/java/info/frostfs/sdk/services/AccountingClientTest.java b/client/src/test/java/info/frostfs/sdk/services/AccountingClientTest.java deleted file mode 100644 index 741475c..0000000 --- a/client/src/test/java/info/frostfs/sdk/services/AccountingClientTest.java +++ /dev/null @@ -1,103 +0,0 @@ -package info.frostfs.sdk.services; - -import frostfs.accounting.AccountingServiceGrpc; -import frostfs.accounting.Service; -import info.frostfs.sdk.dto.object.OwnerId; -import info.frostfs.sdk.jdo.ClientEnvironment; -import info.frostfs.sdk.jdo.parameters.CallContext; -import info.frostfs.sdk.services.impl.AccountingClientImpl; -import info.frostfs.sdk.testgenerator.AccountingGenerator; -import info.frostfs.sdk.tools.RequestConstructor; -import info.frostfs.sdk.tools.RequestSigner; -import info.frostfs.sdk.tools.Verifier; -import io.grpc.Channel; -import io.neow3j.crypto.Base58; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.junit.platform.commons.util.ReflectionUtils; -import org.mockito.ArgumentCaptor; -import org.mockito.Mock; -import org.mockito.MockedStatic; -import org.mockito.Mockito; -import org.mockito.junit.jupiter.MockitoExtension; - -import java.lang.reflect.Field; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.Mockito.*; - -@ExtendWith(MockitoExtension.class) -class AccountingClientTest { - private static final String OWNER_ID = "NVxUSpEEJzYXZZtUs18PrJTD9QZkLLNQ8S"; - - private AccountingClientImpl accountingClient; - - @Mock - private AccountingServiceGrpc.AccountingServiceBlockingStub AccountingServiceClient; - @Mock - private ClientEnvironment clientEnvironment; - @Mock - private Channel channel; - - private MockedStatic verifierMock; - private MockedStatic requestConstructorMock; - private MockedStatic requestSignerMock; - - @BeforeEach - void setUp() throws IllegalAccessException { - when(clientEnvironment.getChannel()).thenReturn(channel); - when(clientEnvironment.getOwnerId()).thenReturn(new OwnerId(OWNER_ID)); - - accountingClient = new AccountingClientImpl(clientEnvironment); - - Field field = ReflectionUtils.findFields(AccountingClientImpl.class, - f -> f.getName().equals("serviceBlockingStub"), - ReflectionUtils.HierarchyTraversalMode.TOP_DOWN) - .get(0); - - field.setAccessible(true); - field.set(accountingClient, AccountingServiceClient); - - verifierMock = Mockito.mockStatic(Verifier.class); - requestConstructorMock = Mockito.mockStatic(RequestConstructor.class); - requestSignerMock = Mockito.mockStatic(RequestSigner.class); - } - - @AfterEach - void cleanUp() { - verifierMock.close(); - requestConstructorMock.close(); - requestSignerMock.close(); - } - - @Test - void getBalance_success() { - //Given - var response = AccountingGenerator.generateBalanceResponse(); - - var captor = ArgumentCaptor.forClass(Service.BalanceRequest.class); - - when(AccountingServiceClient.balance(captor.capture())).thenReturn(response); - - //When - var result = accountingClient.getBalance(new CallContext(0, null)); - - //Then - requestConstructorMock.verify( - () -> RequestConstructor.addMetaHeader(any(Service.BalanceRequest.Builder.class)), - times(1) - ); - requestSignerMock.verify( - () -> RequestSigner.sign(any(Service.BalanceRequest.Builder.class), eq(null)), - times(1) - ); - verifierMock.verify(() -> Verifier.checkResponse(response), times(1)); - - assertEquals(response.getBody().getBalance(), result); - - var request = captor.getValue(); - assertEquals(OWNER_ID, Base58.encode(request.getBody().getOwnerId().getValue().toByteArray())); - } -} diff --git a/client/src/test/java/info/frostfs/sdk/services/ApeManagerClientTest.java b/client/src/test/java/info/frostfs/sdk/services/ApeManagerClientTest.java deleted file mode 100644 index d6a4e4b..0000000 --- a/client/src/test/java/info/frostfs/sdk/services/ApeManagerClientTest.java +++ /dev/null @@ -1,249 +0,0 @@ -package info.frostfs.sdk.services; - -import frostfs.apemanager.APEManagerServiceGrpc; -import frostfs.apemanager.Service; -import info.frostfs.sdk.dto.ape.*; -import info.frostfs.sdk.dto.chain.ChainTarget; -import info.frostfs.sdk.enums.*; -import info.frostfs.sdk.exceptions.ValidationFrostFSException; -import info.frostfs.sdk.jdo.ClientEnvironment; -import info.frostfs.sdk.jdo.parameters.CallContext; -import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainAdd; -import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainList; -import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainRemove; -import info.frostfs.sdk.services.impl.ApeManagerClientImpl; -import info.frostfs.sdk.testgenerator.ApeManagerGenerator; -import info.frostfs.sdk.tools.RequestConstructor; -import info.frostfs.sdk.tools.RequestSigner; -import info.frostfs.sdk.tools.Verifier; -import io.grpc.Channel; -import org.apache.commons.lang3.ArrayUtils; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.junit.platform.commons.util.ReflectionUtils; -import org.mockito.ArgumentCaptor; -import org.mockito.Mock; -import org.mockito.MockedStatic; -import org.mockito.Mockito; -import org.mockito.junit.jupiter.MockitoExtension; - -import java.lang.reflect.Field; -import java.nio.charset.StandardCharsets; -import java.util.Base64; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.Mockito.*; - -@ExtendWith(MockitoExtension.class) -class ApeManagerClientTest { - private static final String CHAIN_BASE64 = - "AAAaY2hhaW4taWQtdGVzdAIAAAISR2V0T2JqZWN0AAIebmF0aXZlOm9iamVjdC8qAAIAABREZXBhcnRtZW50BEhSAA=="; - - private ApeManagerClientImpl apeManagerClient; - - @Mock - private APEManagerServiceGrpc.APEManagerServiceBlockingStub apeManagerServiceClient; - @Mock - private ClientEnvironment clientEnvironment; - @Mock - private Channel channel; - - private MockedStatic verifierMock; - private MockedStatic requestConstructorMock; - private MockedStatic requestSignerMock; - - @BeforeEach - void setUp() throws IllegalAccessException { - when(clientEnvironment.getChannel()).thenReturn(channel); - apeManagerClient = new ApeManagerClientImpl(clientEnvironment); - - Field field = ReflectionUtils.findFields(ApeManagerClientImpl.class, - f -> f.getName().equals("apeManagerServiceClient"), - ReflectionUtils.HierarchyTraversalMode.TOP_DOWN) - .get(0); - - field.setAccessible(true); - field.set(apeManagerClient, apeManagerServiceClient); - - verifierMock = Mockito.mockStatic(Verifier.class); - requestConstructorMock = Mockito.mockStatic(RequestConstructor.class); - requestSignerMock = Mockito.mockStatic(RequestSigner.class); - } - - @AfterEach - void cleanUp() { - verifierMock.close(); - requestConstructorMock.close(); - requestSignerMock.close(); - } - - @Test - void addChain_success() { - //Given - Chain chain = generateChain(); - ChainTarget chainTarget = generateChainTarget(); - PrmApeChainAdd params = new PrmApeChainAdd(chain, chainTarget); - - var response = ApeManagerGenerator.generateAddChainResponse(); - - var captor = ArgumentCaptor.forClass(Service.AddChainRequest.class); - - when(apeManagerServiceClient.addChain(captor.capture())).thenReturn(response); - - //When - var result = apeManagerClient.addChain(params, new CallContext(0, null)); - - //Then - requestConstructorMock.verify( - () -> RequestConstructor.addMetaHeader(any(Service.AddChainRequest.Builder.class), eq(null)), - times(1) - ); - requestSignerMock.verify( - () -> RequestSigner.sign(any(Service.AddChainRequest.Builder.class), eq(null)), - times(1) - ); - verifierMock.verify(() -> Verifier.checkResponse(response), times(1)); - - assertThat(result).containsOnly(response.getBody().getChainId().toByteArray()); - - var request = captor.getValue(); - assertEquals( - Base64.getEncoder().encodeToString(request.getBody().getChain().getRaw().toByteArray()), CHAIN_BASE64) - ; - assertEquals(chainTarget.getName(), request.getBody().getTarget().getName()); - assertEquals(chainTarget.getType().value, request.getBody().getTarget().getType().getNumber()); - } - - @Test - void addChain_wrongParams() { - //Given - Chain chain = generateChain(); - ChainTarget chainTarget = generateChainTarget(); - PrmApeChainAdd params1 = new PrmApeChainAdd(null, chainTarget); - PrmApeChainAdd params2 = new PrmApeChainAdd(chain, null); - PrmApeChainAdd params3 = new PrmApeChainAdd(null, null); - - - //When + Then - assertThrows(ValidationFrostFSException.class, () -> apeManagerClient.addChain(params1, new CallContext())); - assertThrows(ValidationFrostFSException.class, () -> apeManagerClient.addChain(params2, new CallContext())); - assertThrows(ValidationFrostFSException.class, () -> apeManagerClient.addChain(params3, new CallContext())); - } - - @Test - void removeChain_success() { - //Given - Chain chain = generateChain(); - ChainTarget chainTarget = generateChainTarget(); - PrmApeChainRemove params = new PrmApeChainRemove(Base64.getDecoder().decode(CHAIN_BASE64), chainTarget); - - var response = ApeManagerGenerator.generateRemoveChainResponse(); - - var captor = ArgumentCaptor.forClass(Service.RemoveChainRequest.class); - - when(apeManagerServiceClient.removeChain(captor.capture())).thenReturn(response); - - //When - apeManagerClient.removeChain(params, new CallContext(0, null)); - - //Then - requestConstructorMock.verify( - () -> RequestConstructor.addMetaHeader(any(Service.RemoveChainRequest.Builder.class), eq(null)), - times(1) - ); - requestSignerMock.verify( - () -> RequestSigner.sign(any(Service.RemoveChainRequest.Builder.class), eq(null)), - times(1) - ); - verifierMock.verify(() -> Verifier.checkResponse(response), times(1)); - - var request = captor.getValue(); - assertThat(request.getBody().getChainId().toByteArray()).containsOnly(Base64.getDecoder().decode(CHAIN_BASE64)); - assertEquals(chainTarget.getName(), request.getBody().getTarget().getName()); - assertEquals(chainTarget.getType().value, request.getBody().getTarget().getType().getNumber()); - } - - @Test - void removeChain_wrongParams() { - //Given - Chain chain = generateChain(); - ChainTarget chainTarget = generateChainTarget(); - PrmApeChainRemove params1 = new PrmApeChainRemove(null, chainTarget); - PrmApeChainRemove params2 = new PrmApeChainRemove(Base64.getDecoder().decode(CHAIN_BASE64), null); - PrmApeChainRemove params3 = new PrmApeChainRemove(null, null); - - //When + Then - assertThrows(ValidationFrostFSException.class, () -> apeManagerClient.removeChain(params1, new CallContext())); - assertThrows(ValidationFrostFSException.class, () -> apeManagerClient.removeChain(params2, new CallContext())); - assertThrows(ValidationFrostFSException.class, () -> apeManagerClient.removeChain(params3, new CallContext())); - } - - @Test - void listChain_success() { - //Given - ChainTarget chainTarget = generateChainTarget(); - PrmApeChainList params = new PrmApeChainList(chainTarget); - - var response = ApeManagerGenerator.generateListChainsResponse(); - - var captor = ArgumentCaptor.forClass(Service.ListChainsRequest.class); - - when(apeManagerServiceClient.listChains(captor.capture())).thenReturn(response); - - //When - var result = apeManagerClient.listChains(params, new CallContext(0, null)); - - //Then - requestConstructorMock.verify( - () -> RequestConstructor.addMetaHeader(any(Service.ListChainsRequest.Builder.class), eq(null)), - times(1) - ); - requestSignerMock.verify( - () -> RequestSigner.sign(any(Service.ListChainsRequest.Builder.class), eq(null)), - times(1) - ); - verifierMock.verify(() -> Verifier.checkResponse(response), times(1)); - - assertThat(result).hasSize(10); - - var request = captor.getValue(); - assertEquals(chainTarget.getName(), request.getBody().getTarget().getName()); - assertEquals(chainTarget.getType().value, request.getBody().getTarget().getType().getNumber()); - } - - @Test - void listChain_wrongParams() { - //When + Then - assertThrows(ValidationFrostFSException.class, - () -> apeManagerClient.listChains(new PrmApeChainList(null), new CallContext())); - } - - private Chain generateChain() { - var resources = new Resources(false, new String[]{"native:object/*"}); - var actions = new Actions(false, new String[]{"GetObject"}); - var condition = new Condition( - ConditionType.COND_STRING_EQUALS, ConditionKindType.RESOURCE, "Department", "HR" - ); - - var rule = new Rule(); - rule.setStatus(RuleStatus.ALLOW); - rule.setResources(resources); - rule.setActions(actions); - rule.setAny(false); - rule.setConditions(new Condition[]{condition}); - - var chain = new Chain(); - chain.setId(ArrayUtils.toObject("chain-id-test".getBytes(StandardCharsets.UTF_8))); - chain.setRules(new Rule[]{rule}); - chain.setMatchType(RuleMatchType.DENY_PRIORITY); - return chain; - } - - private ChainTarget generateChainTarget() { - return new ChainTarget("BzQw5HH3feoxFDD5tCT87Y1726qzgLfxEE7wgtoRzB3R", TargetType.NAMESPACE); - } -} diff --git a/client/src/test/java/info/frostfs/sdk/testgenerator/AccountingGenerator.java b/client/src/test/java/info/frostfs/sdk/testgenerator/AccountingGenerator.java deleted file mode 100644 index 13a59d2..0000000 --- a/client/src/test/java/info/frostfs/sdk/testgenerator/AccountingGenerator.java +++ /dev/null @@ -1,42 +0,0 @@ -package info.frostfs.sdk.testgenerator; - -import frostfs.accounting.Service; -import frostfs.accounting.Types; - -public class AccountingGenerator { - - public static Service.BalanceRequest generateBalanceRequest() { - return Service.BalanceRequest.newBuilder() - .setBody(generateBalanceRequestBody()) - .setMetaHeader(SessionGenerator.generateRequestMetaHeader()) - .setVerifyHeader(SessionGenerator.generateRequestVerificationHeader()) - .build(); - } - - public static Service.BalanceRequest.Body generateBalanceRequestBody() { - return Service.BalanceRequest.Body.newBuilder() - .setOwnerId(RefsGenerator.generateOwnerID()) - .build(); - } - - public static Service.BalanceResponse generateBalanceResponse() { - return Service.BalanceResponse.newBuilder() - .setBody(generateBalanceResponseBody()) - .setMetaHeader(SessionGenerator.generateResponseMetaHeader()) - .setVerifyHeader(SessionGenerator.generateResponseVerificationHeader()) - .build(); - } - - public static Service.BalanceResponse.Body generateBalanceResponseBody() { - return Service.BalanceResponse.Body.newBuilder() - .setBalance(generateDecimal()) - .build(); - } - - public static Types.Decimal generateDecimal() { - return Types.Decimal.newBuilder() - .setValue(1) - .setPrecision(2) - .build(); - } -} diff --git a/client/src/test/java/info/frostfs/sdk/testgenerator/ApeManagerGenerator.java b/client/src/test/java/info/frostfs/sdk/testgenerator/ApeManagerGenerator.java deleted file mode 100644 index a050114..0000000 --- a/client/src/test/java/info/frostfs/sdk/testgenerator/ApeManagerGenerator.java +++ /dev/null @@ -1,123 +0,0 @@ -package info.frostfs.sdk.testgenerator; - -import com.google.protobuf.ByteString; -import frostfs.ape.Types; -import frostfs.apemanager.Service; -import info.frostfs.sdk.Helper; -import org.bouncycastle.util.encoders.Base64; - -import java.util.ArrayList; - -public class ApeManagerGenerator { - private static final String BASE64_CHAIN = "AAAaY2hhaW4taWQtdGVzdAIAAAICKgACHm5hdGl2ZTpvYmplY3QvKgAAAA=="; - - private static ByteString generateChainID() { - return ByteString.copyFrom(Helper.getByteArrayFromHex("616c6c6f774f626a476574436e72")); - } - - private static Types.Chain generateRawChain() { - return Types.Chain.newBuilder() - .setRaw(ByteString.copyFrom(Base64.decode(BASE64_CHAIN))) - .build(); - } - - private static Iterable generateRawChains(int size) { - var list = new ArrayList(size); - for (int i = 0; i < size; i++) { - list.add(generateRawChain()); - } - - return list; - } - - private static Types.ChainTarget generateChainTarget() { - return Types.ChainTarget.newBuilder() - .setType(Types.TargetType.CONTAINER) - .setName("BzQw5HH3feoxFDD5tCT87Y1726qzgLfxEE7wgtoRzB3R") - .build(); - } - - public static Service.AddChainRequest.Body generateAddChainRequestBody() { - return Service.AddChainRequest.Body.newBuilder() - .setTarget(generateChainTarget()) - .setChain(generateRawChain()) - .build(); - } - - public static Service.AddChainRequest generateAddChainRequest() { - return Service.AddChainRequest.newBuilder() - .setBody(generateAddChainRequestBody()) - .setMetaHeader(SessionGenerator.generateRequestMetaHeader()) - .setVerifyHeader(SessionGenerator.generateRequestVerificationHeader()) - .build(); - } - - public static Service.AddChainResponse.Body generateAddChainResponseBody() { - return Service.AddChainResponse.Body.newBuilder() - .setChainId(generateChainID()) - .build(); - } - - public static Service.AddChainResponse generateAddChainResponse() { - return Service.AddChainResponse.newBuilder() - .setBody(generateAddChainResponseBody()) - .setMetaHeader(SessionGenerator.generateResponseMetaHeader()) - .setVerifyHeader(SessionGenerator.generateResponseVerificationHeader()) - .build(); - } - - public static Service.RemoveChainRequest.Body generateRemoveChainRequestBody() { - return Service.RemoveChainRequest.Body.newBuilder() - .setChainId(generateChainID()) - .setTarget(generateChainTarget()) - .build(); - } - - public static Service.RemoveChainRequest generateRemoveChainRequest() { - return Service.RemoveChainRequest.newBuilder() - .setBody(generateRemoveChainRequestBody()) - .setMetaHeader(SessionGenerator.generateRequestMetaHeader()) - .setVerifyHeader(SessionGenerator.generateRequestVerificationHeader()) - .build(); - } - - public static Service.RemoveChainResponse.Body generateRemoveChainResponseBody() { - return Service.RemoveChainResponse.Body.getDefaultInstance(); - } - - public static Service.RemoveChainResponse generateRemoveChainResponse() { - return Service.RemoveChainResponse.newBuilder() - .setBody(generateRemoveChainResponseBody()) - .setMetaHeader(SessionGenerator.generateResponseMetaHeader()) - .setVerifyHeader(SessionGenerator.generateResponseVerificationHeader()) - .build(); - } - - public static Service.ListChainsRequest.Body generateListChainsRequestBody() { - return Service.ListChainsRequest.Body.newBuilder() - .setTarget(generateChainTarget()) - .build(); - } - - public static Service.ListChainsRequest generateListChainsRequest() { - return Service.ListChainsRequest.newBuilder() - .setBody(generateListChainsRequestBody()) - .setMetaHeader(SessionGenerator.generateRequestMetaHeader()) - .setVerifyHeader(SessionGenerator.generateRequestVerificationHeader()) - .build(); - } - - public static Service.ListChainsResponse.Body generateListChainsResponseBody() { - return Service.ListChainsResponse.Body.newBuilder() - .addAllChains(generateRawChains(10)) - .build(); - } - - public static Service.ListChainsResponse generateListChainsResponse() { - return Service.ListChainsResponse.newBuilder() - .setBody(generateListChainsResponseBody()) - .setMetaHeader(SessionGenerator.generateResponseMetaHeader()) - .setVerifyHeader(SessionGenerator.generateResponseVerificationHeader()) - .build(); - } -} diff --git a/client/src/test/java/info/frostfs/sdk/testgenerator/RefsGenerator.java b/client/src/test/java/info/frostfs/sdk/testgenerator/RefsGenerator.java deleted file mode 100644 index c91e1f7..0000000 --- a/client/src/test/java/info/frostfs/sdk/testgenerator/RefsGenerator.java +++ /dev/null @@ -1,65 +0,0 @@ -package info.frostfs.sdk.testgenerator; - -import com.google.protobuf.ByteString; -import frostfs.refs.Types; - -import java.util.Arrays; -import java.util.Random; - -public class RefsGenerator { - - public static Types.Version generateVersion() { - return Types.Version.newBuilder() - .setMajor(2) - .setMinor(1) - .build(); - } - - public static Types.OwnerID generateOwnerID() { - return Types.OwnerID.newBuilder() - .setValue(ByteString.copyFrom(new byte[]{1, 2, 3})) - .build(); - } - - public static Types.Address generateAddress() { - return Types.Address.newBuilder() - .setObjectId(generateObjectID()) - .setContainerId(generateContainerID()) - .build(); - } - - public static Types.ObjectID generateObjectID() { - return Types.ObjectID.newBuilder() - .setValue(ByteString.copyFrom(new byte[]{1, 2, 3})) - .build(); - } - - public static Iterable generateObjectIDs() { - return Arrays.asList(generateObjectID(), generateObjectID()); - } - - public static Types.ContainerID generateContainerID() { - return Types.ContainerID.newBuilder() - .setValue(ByteString.copyFrom(new byte[]{1, 2, 3})) - .build(); - } - - public static Iterable generateContainerIDs() { - return Arrays.asList(generateContainerID(), generateContainerID()); - } - - public static Types.Signature generateSignature() { - return Types.Signature.newBuilder() - .setKey(ByteString.copyFrom(new byte[]{1})) - .setSign(ByteString.copyFrom(new byte[]{2})) - .setScheme(Types.SignatureScheme.forNumber(new Random().nextInt(3))) - .build(); - } - - public static Types.Checksum generateChecksum() { - return Types.Checksum.newBuilder() - .setType(Types.ChecksumType.SHA256) - .setSum(ByteString.copyFrom(new byte[]{1, 2, 3})) - .build(); - } -} diff --git a/client/src/test/java/info/frostfs/sdk/testgenerator/SessionGenerator.java b/client/src/test/java/info/frostfs/sdk/testgenerator/SessionGenerator.java deleted file mode 100644 index baa1825..0000000 --- a/client/src/test/java/info/frostfs/sdk/testgenerator/SessionGenerator.java +++ /dev/null @@ -1,178 +0,0 @@ -package info.frostfs.sdk.testgenerator; - -import com.google.protobuf.ByteString; -import frostfs.session.Service; -import frostfs.session.Types; - -import java.util.Arrays; -import java.util.Random; - -public class SessionGenerator { - - public static Service.CreateRequest.Body generateCreateRequestBody() { - return Service.CreateRequest.Body.newBuilder() - .setExpiration(555) - .setOwnerId(RefsGenerator.generateOwnerID()) - .build(); - } - - public static Service.CreateRequest generateCreateRequest() { - return Service.CreateRequest.newBuilder() - .setBody(generateCreateRequestBody()) - .setMetaHeader(generateRequestMetaHeader()) - .setVerifyHeader(generateRequestVerificationHeader()) - .build(); - } - - public static Service.CreateResponse.Body generateCreateResponseBody() { - return Service.CreateResponse.Body.newBuilder() - .setId(ByteString.copyFrom(new byte[]{1, 2, 3})) - .setSessionKey(ByteString.copyFrom(new byte[]{4, 5, 6})) - .build(); - } - - public static Service.CreateResponse generateCreateResponse() { - return Service.CreateResponse.newBuilder() - .setBody(generateCreateResponseBody()) - .setMetaHeader(generateResponseMetaHeader()) - .setVerifyHeader(generateResponseVerificationHeader()) - .build(); - } - - public static Types.ResponseVerificationHeader generateResponseVerificationHeader() { - return generateResponseVerificationHeader(true); - } - - public static Types.ResponseVerificationHeader generateResponseVerificationHeader(boolean withOrigin) { - var builder = Types.ResponseVerificationHeader.newBuilder() - .setBodySignature(RefsGenerator.generateSignature()) - .setMetaSignature(RefsGenerator.generateSignature()) - .setOriginSignature(RefsGenerator.generateSignature()); - - if (withOrigin) { - builder.setOrigin(generateResponseVerificationHeader(false)); - } - - return builder.build(); - } - - public static Types.ResponseMetaHeader generateResponseMetaHeader() { - return generateResponseMetaHeader(true); - } - - public static Types.ResponseMetaHeader generateResponseMetaHeader(boolean withOrigin) { - var builder = Types.ResponseMetaHeader.newBuilder() - .setEpoch(13) - .setTtl(100) - .addAllXHeaders(generateXHeaders()) - .setVersion(RefsGenerator.generateVersion()) - .setStatus(StatusGenerator.generateStatus()); - - if (withOrigin) { - builder.setOrigin(generateResponseMetaHeader(false)); - } - - return builder.build(); - } - - public static Types.RequestVerificationHeader generateRequestVerificationHeader() { - return generateRequestVerificationHeader(true); - } - - public static Types.RequestVerificationHeader generateRequestVerificationHeader(boolean withOrigin) { - var builder = Types.RequestVerificationHeader.newBuilder() - .setBodySignature(RefsGenerator.generateSignature()) - .setMetaSignature(RefsGenerator.generateSignature()) - .setOriginSignature(RefsGenerator.generateSignature()); - - if (withOrigin) { - builder.setOrigin(generateRequestVerificationHeader(false)); - } - - return builder.build(); - } - - public static Types.RequestMetaHeader generateRequestMetaHeader() { - return generateRequestMetaHeader(true); - } - - public static Types.RequestMetaHeader generateRequestMetaHeader(boolean withOrigin) { - var builder = Types.RequestMetaHeader.newBuilder() - .setEpoch(13) - .setTtl(100) - .setMagicNumber(1337) - .addAllXHeaders(generateXHeaders()) - .setVersion(RefsGenerator.generateVersion()) - .setSessionToken(generateSessionToken()); - - if (withOrigin) { - builder.setOrigin(generateRequestMetaHeader(false)); - } - - return builder.build(); - } - - public static Types.SessionToken.Body.TokenLifetime generateTokenLifeTime() { - return Types.SessionToken.Body.TokenLifetime.newBuilder() - .setExp(1) - .setIat(2) - .setNbf(3) - .build(); - } - - public static Types.SessionToken.Body generateSessionTokenBody() { - var builder = Types.SessionToken.Body.newBuilder() - .setId(ByteString.copyFrom(new byte[]{1})) - .setSessionKey(ByteString.copyFrom(new byte[]{2})) - .setOwnerId(RefsGenerator.generateOwnerID()) - .setLifetime(generateTokenLifeTime()); - - if (new Random().nextBoolean()) { - builder.setContainer(generateContainerSessionContext()); - } else { - builder.setObject(generateObjectSessionContext()); - } - - return builder.build(); - } - - public static Types.SessionToken generateSessionToken() { - return Types.SessionToken.newBuilder() - .setBody(generateSessionTokenBody()) - .setSignature(RefsGenerator.generateSignature()) - .build(); - } - - public static Types.ObjectSessionContext.Target generateObjectSessionContextTarget() { - return Types.ObjectSessionContext.Target.newBuilder() - .setContainer(RefsGenerator.generateContainerID()) - .addObjects(RefsGenerator.generateObjectID()) - .build(); - } - - public static Types.ObjectSessionContext generateObjectSessionContext() { - return Types.ObjectSessionContext.newBuilder() - .setVerb(Types.ObjectSessionContext.Verb.HEAD) - .setTarget(generateObjectSessionContextTarget()) - .build(); - } - - public static Types.ContainerSessionContext generateContainerSessionContext() { - return Types.ContainerSessionContext.newBuilder() - .setVerb(Types.ContainerSessionContext.Verb.DELETE) - .setWildcard(true) - .setContainerId(RefsGenerator.generateContainerID()) - .build(); - } - - public static Types.XHeader generateXHeader() { - return Types.XHeader.newBuilder() - .setKey("key") - .setValue("val") - .build(); - } - - public static Iterable generateXHeaders() { - return Arrays.asList(generateXHeader(), generateXHeader()); - } -} diff --git a/client/src/test/java/info/frostfs/sdk/testgenerator/StatusGenerator.java b/client/src/test/java/info/frostfs/sdk/testgenerator/StatusGenerator.java deleted file mode 100644 index 0a8fb83..0000000 --- a/client/src/test/java/info/frostfs/sdk/testgenerator/StatusGenerator.java +++ /dev/null @@ -1,29 +0,0 @@ -package info.frostfs.sdk.testgenerator; - -import com.google.protobuf.ByteString; -import frostfs.status.Types; - -import java.util.Arrays; - -public class StatusGenerator { - - public static Types.Status.Detail generateDetail() { - return Types.Status.Detail.newBuilder() - .setId(345) - .setValue(ByteString.copyFrom("value".getBytes())) - .build(); - } - - public static Iterable generateDetails() { - return Arrays.asList(generateDetail(), generateDetail()); - } - - public static Types.Status generateStatus() { - return Types.Status.newBuilder() - .setCode(2) - .setMessage("some string") - .addAllDetails(generateDetails()) - .build(); - } - -} diff --git a/client/src/test/java/info/frostfs/sdk/tools/ape/ApeRuleTest.java b/client/src/test/java/info/frostfs/sdk/tools/ape/ApeRuleTest.java deleted file mode 100644 index e3df60c..0000000 --- a/client/src/test/java/info/frostfs/sdk/tools/ape/ApeRuleTest.java +++ /dev/null @@ -1,179 +0,0 @@ -package info.frostfs.sdk.tools.ape; - -import info.frostfs.sdk.dto.ape.*; -import info.frostfs.sdk.enums.ConditionKindType; -import info.frostfs.sdk.enums.ConditionType; -import info.frostfs.sdk.enums.RuleMatchType; -import info.frostfs.sdk.enums.RuleStatus; -import info.frostfs.sdk.exceptions.FrostFSException; -import info.frostfs.sdk.exceptions.ValidationFrostFSException; -import org.apache.commons.lang3.ArrayUtils; -import org.bouncycastle.util.encoders.Base64; -import org.junit.jupiter.api.Test; - -import java.nio.charset.StandardCharsets; - -import static java.util.Objects.isNull; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; - -public class ApeRuleTest { - - @Test - void apeRuleTest() { - //Given - var resources = new Resources(false, new String[]{"native:object/*"}); - var actions = new Actions(false, new String[]{"*"}); - var rule = new Rule(); - rule.setStatus(RuleStatus.ALLOW); - rule.setResources(resources); - rule.setActions(actions); - rule.setAny(false); - rule.setConditions(new Condition[]{}); - - - var chain = new Chain(); - chain.setId(ArrayUtils.toObject("chain-id-test".getBytes(StandardCharsets.UTF_8))); - chain.setRules(new Rule[]{rule}); - chain.setMatchType(RuleMatchType.DENY_PRIORITY); - - //When - var serialized = RuleSerializer.serialize(chain); - var t = Base64.encode(serialized); - var restoredChain = RuleDeserializer.deserialize(serialized); - - //Then - assertThat(restoredChain.getId()).isNotEmpty().containsOnly(chain.getId()); - assertEquals(chain.getMatchType(), restoredChain.getMatchType()); - compareRules(chain.getRules(), restoredChain.getRules()); - } - - @Test - void apeRuleTest2() { - //Given - var resources = new Resources(true, new String[]{"native:object/*", "U.S.S. ENTERPRISE"}); - var actions = new Actions(true, new String[]{"put", "get"}); - var cond1 = new Condition( - ConditionType.COND_STRING_EQUALS, ConditionKindType.RESOURCE, "key1", "value1" - ); - var cond2 = new Condition( - ConditionType.COND_NUMERIC_GREATER_THAN, ConditionKindType.REQUEST, "key2", "value2" - ); - var rule = new Rule(); - rule.setStatus(RuleStatus.ACCESS_DENIED); - rule.setResources(resources); - rule.setActions(actions); - rule.setAny(true); - rule.setConditions(new Condition[]{cond1, cond2}); - - - var chain = new Chain(); - chain.setId(ArrayUtils.toObject("dumptext".getBytes(StandardCharsets.UTF_8))); - chain.setRules(new Rule[]{rule}); - chain.setMatchType(RuleMatchType.FIRST_MATCH); - - //When - var serialized = RuleSerializer.serialize(chain); - var restoredChain = RuleDeserializer.deserialize(serialized); - - //Then - assertThat(restoredChain.getId()).isNotEmpty().containsOnly(chain.getId()); - assertEquals(chain.getMatchType(), restoredChain.getMatchType()); - compareRules(chain.getRules(), restoredChain.getRules()); - } - - @Test - void apeRuleTest3() { - //Given - var chain = new Chain(); - chain.setMatchType(RuleMatchType.DENY_PRIORITY); - - //When - var serialized = RuleSerializer.serialize(chain); - var restoredChain = RuleDeserializer.deserialize(serialized); - - //Then - assertNull(restoredChain.getId()); - assertEquals(chain.getMatchType(), restoredChain.getMatchType()); - assertNull(restoredChain.getRules()); - } - - @Test - void apeRule_deserialize_wrong() { - //When + Then - assertThrows(ValidationFrostFSException.class, () -> RuleDeserializer.deserialize(null)); - assertThrows(ValidationFrostFSException.class, () -> RuleDeserializer.deserialize(new byte[]{})); - assertThrows(FrostFSException.class, () -> RuleDeserializer.deserialize(new byte[]{1, 2, 3})); - assertThrows(ValidationFrostFSException.class, () -> RuleDeserializer.deserialize(new byte[]{ - 0x00, 0x00, 0x3A, 0x77, 0x73, 0x3A, 0x69, 0x61, 0x6D, 0x3A, 0x3A, 0x6E, 0x61, 0x6D, 0x65, 0x73, - 0x70, 0x61, 0x63, 0x65, 0x3A, 0x67, 0x72, 0x6F, 0x75, 0x70, 0x2F, 0x73, 0x6F, (byte) 0x82, (byte) 0x82, - (byte) 0x82, (byte) 0x82, (byte) 0x82, (byte) 0x82, 0x75, (byte) 0x82 - })); - } - - @Test - void apeRule_serialize_wrong() { - //When + Then - assertThrows(ValidationFrostFSException.class, () -> RuleSerializer.serialize(null)); - } - - private void compareRules(Rule[] rules1, Rule[] rules2) { - assertThat(rules1).isNotEmpty(); - assertThat(rules2).isNotEmpty(); - - assertEquals(rules1.length, rules2.length); - - for (int ri = 0; ri < rules1.length; ri++) { - var rule1 = rules1[ri]; - var rule2 = rules2[ri]; - - assertEquals(rule1.getStatus(), rule2.getStatus()); - assertEquals(rule1.isAny(), rule2.isAny()); - - compareActions(rule1.getActions(), rule2.getActions()); - compareResources(rule1.getResources(), rule2.getResources()); - compareConditions(rule1.getConditions(), rule2.getConditions()); - } - } - - private void compareActions(Actions actions1, Actions actions2) { - if (isNull(actions1) && isNull(actions2)) { - return; - } - - assertEquals(actions1.isInverted(), actions2.isInverted()); - if (ArrayUtils.isEmpty(actions1.getNames()) && ArrayUtils.isEmpty(actions2.getNames())) { - return; - } - - assertThat(actions2.getNames()).hasSize(actions1.getNames().length).containsOnly(actions1.getNames()); - } - - private void compareResources(Resources resources1, Resources resources2) { - if (isNull(resources1) && isNull(resources2)) { - return; - } - - assertEquals(resources1.isInverted(), resources2.isInverted()); - if (ArrayUtils.isEmpty(resources1.getNames()) && ArrayUtils.isEmpty(resources2.getNames())) { - return; - } - - assertThat(resources2.getNames()).hasSize(resources1.getNames().length).containsOnly(resources1.getNames()); - } - - private void compareConditions(Condition[] conditions1, Condition[] conditions2) { - if (ArrayUtils.isEmpty(conditions1) && ArrayUtils.isEmpty(conditions2)) { - return; - } - - assertEquals(conditions1.length, conditions2.length); - for (int i = 0; i < conditions1.length; i++) { - assertEquals(conditions1[i].getOp(), conditions2[i].getOp()); - assertEquals(conditions1[i].getKind(), conditions2[i].getKind()); - assertEquals(conditions1[i].getKey(), conditions2[i].getKey()); - assertEquals(conditions1[i].getValue(), conditions2[i].getValue()); - } - } - -} diff --git a/client/src/test/resources/placement/cbf_default.yml b/client/src/test/resources/placement/cbf_default.yml deleted file mode 100644 index c43a703..0000000 --- a/client/src/test/resources/placement/cbf_default.yml +++ /dev/null @@ -1,48 +0,0 @@ -name: default CBF is 3 -nodes: - - attributes: - - key: Location - value: Europe - - key: Country - value: RU - - key: City - value: St.Petersburg - - attributes: - - key: Location - value: Europe - - key: Country - value: RU - - key: City - value: Moscow - - attributes: - - key: Location - value: Europe - - key: Country - value: DE - - key: City - value: Berlin - - attributes: - - key: Location - value: Europe - - key: Country - value: FR - - key: City - value: Paris -tests: - set default CBF: - policy: - replicas: - - count: 1 - selector: EU - containerBackupFactor: 0 - selectors: - - name: EU - count: 1 - clause: SAME - attribute: Location - filter: '*' - filters: [] - result: - - - 0 - - 1 - - 2 diff --git a/client/src/test/resources/placement/cbf_minimal.yml b/client/src/test/resources/placement/cbf_minimal.yml deleted file mode 100644 index 2fe2642..0000000 --- a/client/src/test/resources/placement/cbf_minimal.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: Real node count multiplier is in range [1, specified CBF] -nodes: - - attributes: - - key: ID - value: '1' - - key: Country - value: DE - - attributes: - - key: ID - value: '2' - - key: Country - value: DE - - attributes: - - key: ID - value: '3' - - key: Country - value: DE -tests: - select 2, CBF is 2: - policy: - replicas: - - count: 1 - selector: X - containerBackupFactor: 2 - selectors: - - name: X - count: 2 - clause: SAME - attribute: Country - filter: '*' - filters: [] - result: - - - 0 - - 1 - - 2 - select 3, CBF is 2: - policy: - replicas: - - count: 1 - selector: X - containerBackupFactor: 2 - selectors: - - name: X - count: 3 - clause: SAME - attribute: Country - filter: '*' - filters: [] - result: - - - 0 - - 1 - - 2 diff --git a/client/src/test/resources/placement/cbf_requirements.yml b/client/src/test/resources/placement/cbf_requirements.yml deleted file mode 100644 index ccd58d4..0000000 --- a/client/src/test/resources/placement/cbf_requirements.yml +++ /dev/null @@ -1,82 +0,0 @@ -name: CBF requirements -nodes: - - attributes: - - key: ID - value: '1' - - key: Attr - value: Same - - attributes: - - key: ID - value: '2' - - key: Attr - value: Same - - attributes: - - key: ID - value: '3' - - key: Attr - value: Same - - attributes: - - key: ID - value: '4' - - key: Attr - value: Same -tests: - default CBF, no selector: - policy: - replicas: - - count: 2 - containerBackupFactor: 0 - selectors: [] - filters: [] - result: - - - 0 - - 2 - - 1 - - 3 - explicit CBF, no selector: - policy: - replicas: - - count: 2 - containerBackupFactor: 3 - selectors: [] - filters: [] - result: - - - 0 - - 2 - - 1 - - 3 - select distinct, weak CBF: - policy: - replicas: - - count: 2 - selector: X - containerBackupFactor: 3 - selectors: - - name: X - count: 2 - clause: DISTINCT - filter: '*' - filters: [] - result: - - - 0 - - 2 - - 1 - - 3 - select same, weak CBF: - policy: - replicas: - - count: 2 - selector: X - containerBackupFactor: 3 - selectors: - - name: X - count: 2 - clause: SAME - attribute: Attr - filter: '*' - filters: [] - result: - - - 0 - - 1 - - 2 - - 3 diff --git a/client/src/test/resources/placement/filter_complex.yml b/client/src/test/resources/placement/filter_complex.yml deleted file mode 100644 index 1abc46a..0000000 --- a/client/src/test/resources/placement/filter_complex.yml +++ /dev/null @@ -1,207 +0,0 @@ -name: compound filter -nodes: - - attributes: - - key: Storage - value: SSD - - key: Rating - value: '10' - - key: IntField - value: '100' - - key: Param - value: Value1 -tests: - good: - policy: - replicas: - - count: 1 - selector: S - containerBackupFactor: 1 - selectors: - - name: S - count: 1 - clause: DISTINCT - filter: Main - filters: - - name: StorageSSD - key: Storage - op: EQ - value: SSD - filters: [] - - name: GoodRating - key: Rating - op: GE - value: '4' - filters: [] - - name: Main - op: AND - filters: - - name: StorageSSD - op: OPERATION_UNSPECIFIED - filters: [] - - name: '' - key: IntField - op: LT - value: '123' - filters: [] - - name: GoodRating - op: OPERATION_UNSPECIFIED - filters: [] - - op: OR - filters: - - key: Param - op: EQ - value: Value1 - filters: [] - - key: Param - op: EQ - value: Value2 - filters: [] - result: - - - 0 - bad storage type: - policy: - replicas: - - count: 1 - selector: S - containerBackupFactor: 1 - selectors: - - name: S - count: 1 - clause: DISTINCT - filter: Main - filters: - - name: StorageSSD - key: Storage - op: EQ - value: HDD - filters: [] - - name: GoodRating - key: Rating - op: GE - value: '4' - filters: [] - - name: Main - op: AND - filters: - - name: StorageSSD - op: OPERATION_UNSPECIFIED - filters: [] - - name: '' - key: IntField - op: LT - value: '123' - filters: [] - - name: GoodRating - op: OPERATION_UNSPECIFIED - filters: [] - - name: '' - op: OR - filters: - - name: '' - key: Param - op: EQ - value: Value1 - filters: [] - - name: '' - key: Param - op: EQ - value: Value2 - filters: [] - bad rating: - policy: - replicas: - - count: 1 - selector: S - containerBackupFactor: 1 - selectors: - - name: S - count: 1 - clause: DISTINCT - filter: Main - filters: - - name: StorageSSD - key: Storage - op: EQ - value: SSD - filters: [] - - name: GoodRating - key: Rating - op: GE - value: '15' - filters: [] - - name: Main - op: AND - filters: - - name: StorageSSD - op: OPERATION_UNSPECIFIED - filters: [] - - name: '' - key: IntField - op: LT - value: '123' - filters: [] - - name: GoodRating - op: OPERATION_UNSPECIFIED - filters: [] - - name: '' - op: OR - filters: - - name: '' - key: Param - op: EQ - value: Value1 - filters: [] - - name: '' - key: Param - op: EQ - value: Value2 - filters: [] - bad param: - policy: - replicas: - - count: 1 - selector: S - containerBackupFactor: 1 - selectors: - - name: S - count: 1 - clause: DISTINCT - filter: Main - filters: - - name: StorageSSD - key: Storage - op: EQ - value: SSD - filters: [] - - name: GoodRating - key: Rating - op: GE - value: '4' - filters: [] - - name: Main - op: AND - filters: - - name: StorageSSD - op: OPERATION_UNSPECIFIED - filters: [] - - name: '' - key: IntField - op: LT - value: '123' - filters: [] - - name: GoodRating - op: OPERATION_UNSPECIFIED - filters: [] - - name: '' - op: OR - filters: - - name: '' - key: Param - op: EQ - value: Value0 - filters: [] - - name: '' - key: Param - op: EQ - value: Value2 - filters: [] diff --git a/client/src/test/resources/placement/filter_invalid_integer.yml b/client/src/test/resources/placement/filter_invalid_integer.yml deleted file mode 100644 index 6674246..0000000 --- a/client/src/test/resources/placement/filter_invalid_integer.yml +++ /dev/null @@ -1,43 +0,0 @@ -name: invalid integer field -nodes: - - attributes: - - key: IntegerField - value: 'true' - - attributes: - - key: IntegerField - value: str -tests: - empty string is not casted to 0: - policy: - replicas: - - count: 1 - selector: S - containerBackupFactor: 1 - selectors: - - name: S - count: 1 - clause: DISTINCT - filter: Main - filters: - - name: Main - key: IntegerField - op: LE - value: '8' - filters: [] - non-empty string is not casted to a number: - policy: - replicas: - - count: 1 - selector: S - containerBackupFactor: 1 - selectors: - - name: S - count: 1 - clause: DISTINCT - filter: Main - filters: - - name: Main - key: IntegerField - op: GE - value: '0' - filters: [] diff --git a/client/src/test/resources/placement/filter_simple.yml b/client/src/test/resources/placement/filter_simple.yml deleted file mode 100644 index 7fdd84a..0000000 --- a/client/src/test/resources/placement/filter_simple.yml +++ /dev/null @@ -1,224 +0,0 @@ -name: single-op filters -nodes: - - attributes: - - key: Rating - value: '4' - - key: Country - value: Germany -tests: - GE true: - policy: - replicas: - - count: 1 - selector: S - containerBackupFactor: 1 - selectors: - - name: S - count: 1 - clause: DISTINCT - filter: Main - filters: - - name: Main - key: Rating - op: GE - value: '4' - filters: [] - result: - - - 0 - GE false: - policy: - replicas: - - count: 1 - selector: S - containerBackupFactor: 1 - selectors: - - name: S - count: 1 - clause: DISTINCT - filter: Main - filters: - - name: Main - key: Rating - op: GE - value: '5' - filters: [] - GT true: - policy: - replicas: - - count: 1 - selector: S - containerBackupFactor: 1 - selectors: - - name: S - count: 1 - clause: DISTINCT - filter: Main - filters: - - name: Main - key: Rating - op: GT - value: '3' - filters: [] - result: - - - 0 - GT false: - policy: - replicas: - - count: 1 - selector: S - containerBackupFactor: 1 - selectors: - - name: S - count: 1 - clause: DISTINCT - filter: Main - filters: - - name: Main - key: Rating - op: GT - value: '4' - filters: [] - LE true: - policy: - replicas: - - count: 1 - selector: S - containerBackupFactor: 1 - selectors: - - name: S - count: 1 - clause: DISTINCT - filter: Main - filters: - - name: Main - key: Rating - op: LE - value: '4' - filters: [] - result: - - - 0 - LE false: - policy: - replicas: - - count: 1 - selector: S - containerBackupFactor: 1 - selectors: - - name: S - count: 1 - clause: DISTINCT - filter: Main - filters: - - name: Main - key: Rating - op: LE - value: '3' - filters: [] - LT true: - policy: - replicas: - - count: 1 - selector: S - containerBackupFactor: 1 - selectors: - - name: S - count: 1 - clause: DISTINCT - filter: Main - filters: - - name: Main - key: Rating - op: LT - value: '5' - filters: [] - result: - - - 0 - LT false: - policy: - replicas: - - count: 1 - selector: S - containerBackupFactor: 1 - selectors: - - name: S - count: 1 - clause: DISTINCT - filter: Main - filters: - - name: Main - key: Rating - op: LT - value: '4' - filters: [] - EQ true: - policy: - replicas: - - count: 1 - selector: S - containerBackupFactor: 1 - selectors: - - name: S - count: 1 - clause: DISTINCT - filter: Main - filters: - - name: Main - key: Country - op: EQ - value: Germany - filters: [] - result: - - - 0 - EQ false: - policy: - replicas: - - count: 1 - selector: S - containerBackupFactor: 1 - selectors: - - name: S - count: 1 - clause: DISTINCT - filter: Main - filters: - - name: Main - key: Country - op: EQ - value: China - filters: [] - NE true: - policy: - replicas: - - count: 1 - selector: S - containerBackupFactor: 1 - selectors: - - name: S - count: 1 - clause: DISTINCT - filter: Main - filters: - - name: Main - key: Country - op: NE - value: France - filters: [] - result: - - - 0 - NE false: - policy: - replicas: - - count: 1 - selector: S - containerBackupFactor: 1 - selectors: - - name: S - count: 1 - clause: DISTINCT - filter: Main - filters: - - name: Main - key: Country - op: NE - value: Germany - filters: [] diff --git a/client/src/test/resources/placement/hrw_sort.yml b/client/src/test/resources/placement/hrw_sort.yml deleted file mode 100644 index c84f7c9..0000000 --- a/client/src/test/resources/placement/hrw_sort.yml +++ /dev/null @@ -1,118 +0,0 @@ -name: HRW ordering -nodes: - - attributes: - - key: Country - value: Germany - - key: Price - value: '2' - - key: Capacity - value: '10000' - - attributes: - - key: Country - value: Germany - - key: Price - value: '4' - - key: Capacity - value: '1' - - attributes: - - key: Country - value: France - - key: Price - value: '3' - - key: Capacity - value: '10' - - attributes: - - key: Country - value: Russia - - key: Price - value: '2' - - key: Capacity - value: '10000' - - attributes: - - key: Country - value: Russia - - key: Price - value: '1' - - key: Capacity - value: '10000' - - attributes: - - key: Country - value: Russia - - key: Capacity - value: '10000' - - attributes: - - key: Country - value: France - - key: Price - value: '100' - - key: Capacity - value: '1' - - attributes: - - key: Country - value: France - - key: Price - value: '7' - - key: Capacity - value: '10000' - - attributes: - - key: Country - value: Russia - - key: Price - value: '2' - - key: Capacity - value: '1' -tests: - select 3 nodes in 3 distinct countries, same placement: - policy: - replicas: - - count: 1 - selector: Main - containerBackupFactor: 1 - selectors: - - name: Main - count: 3 - clause: DISTINCT - attribute: Country - filter: '*' - filters: [] - pivot: Y29udGFpbmVySUQ= - result: - - - 5 - - 0 - - 7 - placement: - pivot: b2JqZWN0SUQ= - result: - - - 5 - - 0 - - 7 - select 6 nodes in 3 distinct countries, different placement: - policy: - replicas: - - count: 1 - selector: Main - containerBackupFactor: 2 - selectors: - - name: Main - count: 3 - clause: DISTINCT - attribute: Country - filter: '*' - filters: [] - pivot: Y29udGFpbmVySUQ= - result: - - - 5 - - 4 - - 0 - - 1 - - 7 - - 2 - placement: - pivot: b2JqZWN0SUQ= - result: - - - 5 - - 4 - - 0 - - 7 - - 2 - - 1 diff --git a/client/src/test/resources/placement/issue213.yml b/client/src/test/resources/placement/issue213.yml deleted file mode 100644 index 8e8aea4..0000000 --- a/client/src/test/resources/placement/issue213.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: unnamed selector (nspcc-dev/neofs-api-go#213) -nodes: - - attributes: - - key: Location - value: Europe - - key: Country - value: Russia - - key: City - value: Moscow - - attributes: - - key: Location - value: Europe - - key: Country - value: Russia - - key: City - value: Saint-Petersburg - - attributes: - - key: Location - value: Europe - - key: Country - value: Sweden - - key: City - value: Stockholm - - attributes: - - key: Location - value: Europe - - key: Country - value: Finalnd - - key: City - value: Helsinki -tests: - test: - policy: - replicas: - - count: 4 - containerBackupFactor: 1 - selectors: - - name: '' - count: 4 - clause: DISTINCT - filter: LOC_EU - filters: - - name: LOC_EU - key: Location - op: EQ - value: Europe - filters: [] - result: - - - 0 - - 1 - - 2 - - 3 diff --git a/client/src/test/resources/placement/many_selects.yml b/client/src/test/resources/placement/many_selects.yml deleted file mode 100644 index 29efd43..0000000 --- a/client/src/test/resources/placement/many_selects.yml +++ /dev/null @@ -1,141 +0,0 @@ -name: single-op filters -nodes: - - attributes: - - key: Country - value: Russia - - key: Rating - value: '1' - - key: City - value: SPB - - attributes: - - key: Country - value: Germany - - key: Rating - value: '5' - - key: City - value: Berlin - - attributes: - - key: Country - value: Russia - - key: Rating - value: '6' - - key: City - value: Moscow - - attributes: - - key: Country - value: France - - key: Rating - value: '4' - - key: City - value: Paris - - attributes: - - key: Country - value: France - - key: Rating - value: '1' - - key: City - value: Lyon - - attributes: - - key: Country - value: Russia - - key: Rating - value: '5' - - key: City - value: SPB - - attributes: - - key: Country - value: Russia - - key: Rating - value: '7' - - key: City - value: Moscow - - attributes: - - key: Country - value: Germany - - key: Rating - value: '3' - - key: City - value: Darmstadt - - attributes: - - key: Country - value: Germany - - key: Rating - value: '7' - - key: City - value: Frankfurt - - attributes: - - key: Country - value: Russia - - key: Rating - value: '9' - - key: City - value: SPB - - attributes: - - key: Country - value: Russia - - key: Rating - value: '9' - - key: City - value: SPB -tests: - Select: - policy: - replicas: - - count: 1 - selector: SameRU - - count: 1 - selector: DistinctRU - - count: 1 - selector: Good - - count: 1 - selector: Main - containerBackupFactor: 2 - selectors: - - name: SameRU - count: 2 - clause: SAME - attribute: City - filter: FromRU - - name: DistinctRU - count: 2 - clause: DISTINCT - attribute: City - filter: FromRU - - name: Good - count: 2 - clause: DISTINCT - attribute: Country - filter: Good - - name: Main - count: 3 - clause: DISTINCT - attribute: Country - filter: '*' - filters: - - name: FromRU - key: Country - op: EQ - value: Russia - - name: Good - key: Rating - op: GE - value: '4' - result: - - - 0 - - 5 - - 9 - - 10 - - - 2 - - 6 - - 0 - - 5 - - - 1 - - 8 - - 2 - - 5 - - - 3 - - 4 - - 1 - - 7 - - 0 - - 2 diff --git a/client/src/test/resources/placement/multiple_rep.yml b/client/src/test/resources/placement/multiple_rep.yml deleted file mode 100644 index 448214f..0000000 --- a/client/src/test/resources/placement/multiple_rep.yml +++ /dev/null @@ -1,46 +0,0 @@ -name: multiple replicas (#215) -nodes: - - attributes: - - key: City - value: Saint-Petersburg - - attributes: - - key: City - value: Moscow - - attributes: - - key: City - value: Berlin - - attributes: - - key: City - value: Paris -tests: - test: - policy: - replicas: - - count: 1 - selector: LOC_SPB_PLACE - - count: 1 - selector: LOC_MSK_PLACE - containerBackupFactor: 1 - selectors: - - name: LOC_SPB_PLACE - count: 1 - clause: CLAUSE_UNSPECIFIED - filter: LOC_SPB - - name: LOC_MSK_PLACE - count: 1 - clause: CLAUSE_UNSPECIFIED - filter: LOC_MSK - filters: - - name: LOC_SPB - key: City - op: EQ - value: Saint-Petersburg - filters: [] - - name: LOC_MSK - key: City - op: EQ - value: Moscow - filters: [] - result: - - - 0 - - - 1 diff --git a/client/src/test/resources/placement/multiple_rep_asymmetric.yml b/client/src/test/resources/placement/multiple_rep_asymmetric.yml deleted file mode 100644 index 61f8f76..0000000 --- a/client/src/test/resources/placement/multiple_rep_asymmetric.yml +++ /dev/null @@ -1,162 +0,0 @@ -name: multiple REP, asymmetric -nodes: - - attributes: - - key: ID - value: '1' - - key: Country - value: RU - - key: City - value: St.Petersburg - - key: SSD - value: '0' - - attributes: - - key: ID - value: '2' - - key: Country - value: RU - - key: City - value: St.Petersburg - - key: SSD - value: '1' - - attributes: - - key: ID - value: '3' - - key: Country - value: RU - - key: City - value: Moscow - - key: SSD - value: '1' - - attributes: - - key: ID - value: '4' - - key: Country - value: RU - - key: City - value: Moscow - - key: SSD - value: '1' - - attributes: - - key: ID - value: '5' - - key: Country - value: RU - - key: City - value: St.Petersburg - - key: SSD - value: '1' - - attributes: - - key: ID - value: '6' - - key: Continent - value: NA - - key: City - value: NewYork - - attributes: - - key: ID - value: '7' - - key: Continent - value: AF - - key: City - value: Cairo - - attributes: - - key: ID - value: '8' - - key: Continent - value: AF - - key: City - value: Cairo - - attributes: - - key: ID - value: '9' - - key: Continent - value: SA - - key: City - value: Lima - - attributes: - - key: ID - value: '10' - - key: Continent - value: AF - - key: City - value: Cairo - - attributes: - - key: ID - value: '11' - - key: Continent - value: NA - - key: City - value: NewYork - - attributes: - - key: ID - value: '12' - - key: Continent - value: NA - - key: City - value: LosAngeles - - attributes: - - key: ID - value: '13' - - key: Continent - value: SA - - key: City - value: Lima -tests: - test: - policy: - replicas: - - count: 1 - selector: SPB - - count: 2 - selector: Americas - containerBackupFactor: 2 - selectors: - - name: SPB - count: 1 - clause: SAME - attribute: City - filter: SPBSSD - - name: Americas - count: 2 - clause: DISTINCT - attribute: City - filter: Americas - filters: - - name: SPBSSD - op: AND - filters: - - name: '' - key: Country - op: EQ - value: RU - filters: [] - - name: '' - key: City - op: EQ - value: St.Petersburg - filters: [] - - name: '' - key: SSD - op: EQ - value: '1' - filters: [] - - name: Americas - op: OR - filters: - - name: '' - key: Continent - op: EQ - value: NA - filters: [] - - name: '' - key: Continent - op: EQ - value: SA - filters: [] - result: - - - 1 - - 4 - - - 8 - - 12 - - 5 - - 10 diff --git a/client/src/test/resources/placement/non_strict.yml b/client/src/test/resources/placement/non_strict.yml deleted file mode 100644 index a01986d..0000000 --- a/client/src/test/resources/placement/non_strict.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: non-strict selections -comment: These test specify loose selection behaviour, to allow fetching already PUT - objects even when there is not enough nodes to select from. -nodes: - - attributes: - - key: Country - value: Russia - - attributes: - - key: Country - value: Germany - - attributes: [] -tests: - not enough nodes (backup factor): - policy: - replicas: - - count: 1 - selector: MyStore - containerBackupFactor: 2 - selectors: - - name: MyStore - count: 2 - clause: DISTINCT - attribute: Country - filter: FromRU - filters: - - name: FromRU - key: Country - op: EQ - value: Russia - filters: [] - result: - - - 0 - not enough nodes (buckets): - policy: - replicas: - - count: 1 - selector: MyStore - containerBackupFactor: 1 - selectors: - - name: MyStore - count: 2 - clause: DISTINCT - attribute: Country - filter: FromRU - filters: - - name: FromRU - key: Country - op: EQ - value: Russia - filters: [] - result: - - - 0 diff --git a/client/src/test/resources/placement/rep_only.yml b/client/src/test/resources/placement/rep_only.yml deleted file mode 100644 index b354591..0000000 --- a/client/src/test/resources/placement/rep_only.yml +++ /dev/null @@ -1,62 +0,0 @@ -name: REP X -nodes: - - publicKey: '' - addresses: [] - attributes: - - key: City - value: Saint-Petersburg - state: UNSPECIFIED - - publicKey: '' - addresses: [] - attributes: - - key: City - value: Moscow - state: UNSPECIFIED - - publicKey: '' - addresses: [] - attributes: - - key: City - value: Berlin - state: UNSPECIFIED - - publicKey: '' - addresses: [] - attributes: - - key: City - value: Paris - state: UNSPECIFIED -tests: - REP 1: - policy: - replicas: - - count: 1 - containerBackupFactor: 0 - selectors: [] - filters: [] - result: - - - 0 - - 1 - - 2 - REP 3: - policy: - replicas: - - count: 3 - containerBackupFactor: 0 - selectors: [] - filters: [] - result: - - - 0 - - 3 - - 1 - - 2 - REP 5: - policy: - replicas: - - count: 5 - containerBackupFactor: 0 - selectors: [] - filters: [] - result: - - - 0 - - 1 - - 2 - - 3 diff --git a/client/src/test/resources/placement/select_no_attribute.yml b/client/src/test/resources/placement/select_no_attribute.yml deleted file mode 100644 index 02046f3..0000000 --- a/client/src/test/resources/placement/select_no_attribute.yml +++ /dev/null @@ -1,56 +0,0 @@ -name: select with unspecified attribute -nodes: - - attributes: - - key: ID - value: '1' - - key: Country - value: RU - - key: City - value: St.Petersburg - - key: SSD - value: '0' - - attributes: - - key: ID - value: '2' - - key: Country - value: RU - - key: City - value: St.Petersburg - - key: SSD - value: '1' - - attributes: - - key: ID - value: '3' - - key: Country - value: RU - - key: City - value: Moscow - - key: SSD - value: '1' - - attributes: - - key: ID - value: '4' - - key: Country - value: RU - - key: City - value: Moscow - - key: SSD - value: '1' -tests: - test: - policy: - replicas: - - count: 1 - selector: X - containerBackupFactor: 1 - selectors: - - name: X - count: 4 - clause: DISTINCT - filter: '*' - filters: [] - result: - - - 0 - - 1 - - 2 - - 3 diff --git a/client/src/test/resources/placement/selector_invalid.yml b/client/src/test/resources/placement/selector_invalid.yml deleted file mode 100644 index 9b0a539..0000000 --- a/client/src/test/resources/placement/selector_invalid.yml +++ /dev/null @@ -1,47 +0,0 @@ -name: invalid selections -nodes: - - attributes: - - key: Country - value: Russia - - attributes: - - key: Country - value: Germany - - attributes: [] -tests: - missing filter: - policy: - replicas: - - count: 1 - selector: MyStore - containerBackupFactor: 1 - selectors: - - name: MyStore - count: 1 - clause: DISTINCT - attribute: Country - filter: FromNL - filters: - - name: FromRU - key: Country - op: EQ - value: Russia - filters: [] - error: filter not found - not enough nodes (filter results in empty set): - policy: - replicas: - - count: 1 - selector: MyStore - containerBackupFactor: 2 - selectors: - - name: MyStore - count: 2 - clause: DISTINCT - attribute: Country - filter: FromMoon - filters: - - name: FromMoon - key: Country - op: EQ - value: Moon - filters: [] diff --git a/cryptography/pom.xml b/cryptography/pom.xml deleted file mode 100644 index e9e2c6b..0000000 --- a/cryptography/pom.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - 4.0.0 - - info.frostfs.sdk - frostfs-sdk-java - ${revision} - - - cryptography - - - 11 - 11 - UTF-8 - - - - - info.frostfs.sdk - exceptions - ${revision} - - - com.google.protobuf - protobuf-java - ${protobuf.version} - - - org.bouncycastle - bcprov-jdk18on - 1.78.1 - - - - \ No newline at end of file diff --git a/cryptography/src/main/java/info/frostfs/sdk/ArrayHelper.java b/cryptography/src/main/java/info/frostfs/sdk/ArrayHelper.java deleted file mode 100644 index 3820e62..0000000 --- a/cryptography/src/main/java/info/frostfs/sdk/ArrayHelper.java +++ /dev/null @@ -1,23 +0,0 @@ -package info.frostfs.sdk; - -import info.frostfs.sdk.exceptions.ValidationFrostFSException; - -import static info.frostfs.sdk.constants.ErrorConst.SOME_PARAM_IS_MISSING; -import static java.util.Objects.isNull; - -public class ArrayHelper { - private ArrayHelper() { - } - - public static byte[] concat(byte[] startArray, byte[] endArray) { - if (isNull(startArray) || isNull(endArray)) { - throw new ValidationFrostFSException(SOME_PARAM_IS_MISSING); - } - - byte[] joinedArray = new byte[startArray.length + endArray.length]; - - System.arraycopy(startArray, 0, joinedArray, 0, startArray.length); - System.arraycopy(endArray, 0, joinedArray, startArray.length, endArray.length); - return joinedArray; - } -} diff --git a/cryptography/src/main/java/info/frostfs/sdk/Helper.java b/cryptography/src/main/java/info/frostfs/sdk/Helper.java deleted file mode 100644 index 0ca1dab..0000000 --- a/cryptography/src/main/java/info/frostfs/sdk/Helper.java +++ /dev/null @@ -1,61 +0,0 @@ -package info.frostfs.sdk; - -import com.google.protobuf.ByteString; -import com.google.protobuf.Message; -import info.frostfs.sdk.exceptions.ValidationFrostFSException; -import org.apache.commons.lang3.StringUtils; - -import java.math.BigInteger; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - -import static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_IS_MISSING; -import static java.util.Objects.isNull; - -public class Helper { - private static final String SHA256 = "SHA-256"; - private static final int HEX_RADIX = 16; - - private Helper() { - } - - public static MessageDigest getSha256Instance() { - try { - return MessageDigest.getInstance(SHA256); - } catch (NoSuchAlgorithmException e) { - throw new RuntimeException(e); - } - } - - public static byte[] getSha256(byte[] value) { - if (isNull(value)) { - throw new ValidationFrostFSException(INPUT_PARAM_IS_MISSING); - } - - return getSha256Instance().digest(value); - } - - public static ByteString getSha256(Message value) { - if (isNull(value)) { - throw new ValidationFrostFSException(INPUT_PARAM_IS_MISSING); - } - - return ByteString.copyFrom(getSha256(value.toByteArray())); - } - - public static String getHexString(byte[] value) { - if (isNull(value) || value.length == 0) { - throw new ValidationFrostFSException(INPUT_PARAM_IS_MISSING); - } - - return String.format("%0" + (value.length << 1) + "x", new BigInteger(1, value)); - } - - public static byte[] getByteArrayFromHex(String hex) { - if (StringUtils.isBlank(hex)) { - throw new ValidationFrostFSException(INPUT_PARAM_IS_MISSING); - } - - return new BigInteger(hex, HEX_RADIX).toByteArray(); - } -} diff --git a/cryptography/src/main/java/info/frostfs/sdk/KeyExtension.java b/cryptography/src/main/java/info/frostfs/sdk/KeyExtension.java deleted file mode 100644 index 248b717..0000000 --- a/cryptography/src/main/java/info/frostfs/sdk/KeyExtension.java +++ /dev/null @@ -1,93 +0,0 @@ -package info.frostfs.sdk; - -import info.frostfs.sdk.exceptions.ProcessFrostFSException; -import info.frostfs.sdk.exceptions.ValidationFrostFSException; -import org.bouncycastle.asn1.sec.SECNamedCurves; -import org.bouncycastle.asn1.sec.SECObjectIdentifiers; -import org.bouncycastle.asn1.x9.X9ECParameters; -import org.bouncycastle.crypto.params.ECDomainParameters; -import org.bouncycastle.crypto.params.ECPrivateKeyParameters; -import org.bouncycastle.crypto.params.ECPublicKeyParameters; -import org.bouncycastle.jce.spec.ECNamedCurveSpec; - -import java.security.KeyFactory; -import java.security.NoSuchAlgorithmException; -import java.security.PrivateKey; -import java.security.PublicKey; -import java.security.spec.ECParameterSpec; -import java.security.spec.ECPrivateKeySpec; -import java.security.spec.ECPublicKeySpec; -import java.security.spec.InvalidKeySpecException; - -import static info.frostfs.sdk.constants.ErrorConst.COMPRESSED_PUBLIC_KEY_WRONG_LENGTH_TEMPLATE; -import static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_IS_MISSING; -import static java.util.Objects.isNull; -import static org.bouncycastle.util.BigIntegers.fromUnsignedByteArray; - -public class KeyExtension { - private static final String CURVE_NAME = "secp256r1"; - private static final String SECURITY_ALGORITHM = "EC"; - private static final int COMPRESSED_PUBLIC_KEY_LENGTH = 33; - - private KeyExtension() { - } - - public static PrivateKey loadPrivateKey(byte[] privateKey) { - checkInputValue(privateKey); - - X9ECParameters params = SECNamedCurves.getByOID(SECObjectIdentifiers.secp256r1); - ECDomainParameters domain = new ECDomainParameters( - params.getCurve(), params.getG(), params.getN(), params.getH() - ); - ECPrivateKeyParameters ecParams = new ECPrivateKeyParameters(fromUnsignedByteArray(privateKey), domain); - - ECParameterSpec ecParameterSpec = new ECNamedCurveSpec( - CURVE_NAME, params.getCurve(), params.getG(), params.getN(), params.getH() - ); - ECPrivateKeySpec privateKeySpec = new ECPrivateKeySpec(ecParams.getD(), ecParameterSpec); - try { - KeyFactory kf = KeyFactory.getInstance(SECURITY_ALGORITHM); - return kf.generatePrivate(privateKeySpec); - } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { - throw new ProcessFrostFSException(e); - } - } - - public static PublicKey getPublicKeyFromBytes(byte[] publicKey) { - checkInputValue(publicKey); - - if (publicKey.length != COMPRESSED_PUBLIC_KEY_LENGTH) { - throw new ValidationFrostFSException(String.format( - COMPRESSED_PUBLIC_KEY_WRONG_LENGTH_TEMPLATE, COMPRESSED_PUBLIC_KEY_LENGTH, publicKey.length - )); - } - - X9ECParameters secp256R1 = SECNamedCurves.getByOID(SECObjectIdentifiers.secp256r1); - ECDomainParameters domain = new ECDomainParameters( - secp256R1.getCurve(), secp256R1.getG(), secp256R1.getN(), secp256R1.getH() - ); - var ecPoint = secp256R1.getCurve().decodePoint(publicKey); - var publicParams = new ECPublicKeyParameters(ecPoint, domain); - java.security.spec.ECPoint point = new java.security.spec.ECPoint( - publicParams.getQ().getRawXCoord().toBigInteger(), publicParams.getQ().getRawYCoord().toBigInteger() - ); - ECParameterSpec ecParameterSpec = new ECNamedCurveSpec( - CURVE_NAME, secp256R1.getCurve(), secp256R1.getG(), secp256R1.getN(), secp256R1.getH(), - secp256R1.getSeed() - ); - ECPublicKeySpec publicKeySpec = new ECPublicKeySpec(point, ecParameterSpec); - - try { - KeyFactory kf = KeyFactory.getInstance(SECURITY_ALGORITHM); - return kf.generatePublic(publicKeySpec); - } catch (Exception e) { - throw new ProcessFrostFSException(e); - } - } - - private static void checkInputValue(byte[] data) { - if (isNull(data) || data.length == 0) { - throw new ValidationFrostFSException(INPUT_PARAM_IS_MISSING); - } - } -} diff --git a/cryptography/src/test/java/info/frostfs/sdk/ArrayHelperTest.java b/cryptography/src/test/java/info/frostfs/sdk/ArrayHelperTest.java deleted file mode 100644 index 0d11b0e..0000000 --- a/cryptography/src/test/java/info/frostfs/sdk/ArrayHelperTest.java +++ /dev/null @@ -1,67 +0,0 @@ -package info.frostfs.sdk; - -import info.frostfs.sdk.exceptions.ValidationFrostFSException; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; - -public class ArrayHelperTest { - - @Test - void concatTest_success() { - //Given - var startBytes = new byte[]{1, 2, 3, 4, 5}; - var endBytes = new byte[]{6, 7, 8, 9}; - - //When - var result = ArrayHelper.concat(startBytes, endBytes); - - //Then - assertThat(startBytes).hasSize(5); - assertThat(endBytes).hasSize(4); - assertThat(result).hasSize(9).startsWith(startBytes).endsWith(endBytes); - } - - @Test - void concatTest_endArrayIsEmpty() { - //Given - var startBytes = new byte[]{1, 2, 3, 4, 5}; - var endBytes = new byte[]{}; - - //When - var result = ArrayHelper.concat(startBytes, endBytes); - - //Then - assertThat(startBytes).hasSize(5); - assertThat(endBytes).hasSize(0); - assertThat(result).hasSize(5).startsWith(startBytes); - } - - @Test - void concatTest_startArrayIsEmpty() { - //Given - var startBytes = new byte[]{}; - var endBytes = new byte[]{6, 7, 8, 9}; - - //When - var result = ArrayHelper.concat(startBytes, endBytes); - - //Then - assertThat(startBytes).hasSize(0); - assertThat(endBytes).hasSize(4); - assertThat(result).hasSize(4).startsWith(endBytes); - } - - @Test - void concatTest_givenParamsIsNull() { - //Given - var startBytes = new byte[]{1, 2, 3, 4, 5}; - var endBytes = new byte[]{6, 7, 8, 9}; - - //When + Then - assertThrows(ValidationFrostFSException.class, () -> ArrayHelper.concat(startBytes, null)); - assertThrows(ValidationFrostFSException.class, () -> ArrayHelper.concat(null, endBytes)); - assertThrows(ValidationFrostFSException.class, () -> ArrayHelper.concat(null, null)); - } -} diff --git a/cryptography/src/test/java/info/frostfs/sdk/HelperTest.java b/cryptography/src/test/java/info/frostfs/sdk/HelperTest.java deleted file mode 100644 index 00a9121..0000000 --- a/cryptography/src/test/java/info/frostfs/sdk/HelperTest.java +++ /dev/null @@ -1,98 +0,0 @@ -package info.frostfs.sdk; - -import com.google.protobuf.Message; -import info.frostfs.sdk.exceptions.ValidationFrostFSException; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; - -public class HelperTest { - - @Test - void getSha256Instance() { - //When - var result = Helper.getSha256Instance(); - - //Then - assertEquals("SHA-256", result.getAlgorithm()); - } - - @Test - void getSha256_bytes_success() { - //Given - var value = new byte[]{1, 2, 3, 4, 5}; - var expected = new byte[]{ - 116, -8, 31, -31, 103, -39, -101, 76, -76, 29, 109, 12, -51, -88, 34, 120, -54, -18, -97, 62, 47, 37, - -43, -27, -93, -109, 111, -13, -36, -20, 96, -48 - }; - - //When - var result = Helper.getSha256(value); - - //Then - assertThat(result).hasSize(32).containsExactly(expected); - } - - @Test - void getSha256_bytes_givenParamIsNull() { - //When + Then - assertThrows(ValidationFrostFSException.class, () -> Helper.getSha256((byte[]) null)); - assertThrows(ValidationFrostFSException.class, () -> Helper.getSha256((Message) null)); - } - - @Test - void getSha256_bytes_givenParamsIsEmpty() { - //Given - var value = new byte[]{}; - var expected = new byte[]{ - -29, -80, -60, 66, -104, -4, 28, 20, -102, -5, -12, -56, -103, 111, -71, 36, 39, -82, 65, -28, 100, - -101, -109, 76, -92, -107, -103, 27, 120, 82, -72, 85 - }; - - //When - var result = Helper.getSha256(value); - - //Then - assertThat(result).hasSize(32).containsExactly(expected); - } - - @Test - void getHexString_success() { - //Given - var value = new byte[]{1, 2, 3, 4, 5}; - - //When - var result = Helper.getHexString(value); - - //Then - assertEquals("0102030405", result); - } - - @Test - void getHexString_wrong() { - //When + Then - assertThrows(ValidationFrostFSException.class, () -> Helper.getHexString(null)); - assertThrows(ValidationFrostFSException.class, () -> Helper.getHexString(new byte[]{})); - } - - @Test - void getByteArrayFromHex_success() { - //Given - var value = "0102030405"; - - //When - var result = Helper.getByteArrayFromHex(value); - - //Then - assertThat(result).containsOnly(new byte[]{1, 2, 3, 4, 5}); - } - - @Test - void getByteArrayFromHex_wrong() { - //When + Then - assertThrows(ValidationFrostFSException.class, () -> Helper.getByteArrayFromHex(null)); - assertThrows(ValidationFrostFSException.class, () -> Helper.getByteArrayFromHex("")); - } -} diff --git a/cryptography/src/test/java/info/frostfs/sdk/KeyExtensionTest.java b/cryptography/src/test/java/info/frostfs/sdk/KeyExtensionTest.java deleted file mode 100644 index a99fe4d..0000000 --- a/cryptography/src/test/java/info/frostfs/sdk/KeyExtensionTest.java +++ /dev/null @@ -1,61 +0,0 @@ -package info.frostfs.sdk; - -import info.frostfs.sdk.exceptions.ValidationFrostFSException; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; - -public class KeyExtensionTest { - private static final byte[] PRIVATE_KEY = new byte[]{ - -128, -5, 30, -36, -118, 85, -67, -6, 81, 43, 93, -38, 106, 21, -88, 127, 15, 125, -79, -17, -40, 77, -15, - 122, -88, 72, 109, -47, 125, -80, -40, -38 - }; - private static final byte[] PUBLIC_KEY = new byte[]{ - 3, 80, -111, 65, 23, 36, -4, -69, 80, 102, 98, -13, 13, -79, 24, 126, -116, 90, 56, 44, 127, 106, -125, 99, - -48, -94, 104, 81, 120, -110, 30, 80, 70 - }; - private static final byte[] UNCOMPRESSED_PUBLIC_KEY = new byte[]{ - 4, 80, -111, 65, 23, 36, -4, -69, 80, 102, 98, -13, 13, -79, 24, 126, -116, 90, 56, 44, 127, 106, -125, 99, - -48, -94, 104, 81, 120, -110, 30, 80, 70, 76, -18, 53, -9, 79, -8, -25, -69, 12, 89, -103, 15, 126, 118, - -68, -73, 65, -57, -26, 75, 4, -51, -40, -20, 75, 89, -59, 111, 96, -80, 56, 13 - }; - - @Test - void loadPrivateKey_success() { - //When - var privateKey = KeyExtension.loadPrivateKey(PRIVATE_KEY); - - //Then - assertThat(privateKey.getEncoded()).hasSize(67).endsWith(PRIVATE_KEY); - assertEquals("EC", privateKey.getAlgorithm()); - assertEquals("PKCS#8", privateKey.getFormat()); - } - - @Test - void loadPrivateKey_wrong() { - //When + Then - assertThrows(ValidationFrostFSException.class, () -> KeyExtension.loadPrivateKey(null)); - assertThrows(ValidationFrostFSException.class, () -> KeyExtension.loadPrivateKey(new byte[]{})); - } - - @Test - void getPublicKeyFromBytes_success() { - //When - var publicKey = KeyExtension.getPublicKeyFromBytes(PUBLIC_KEY); - - //Then - assertThat(publicKey.getEncoded()).hasSize(91).endsWith(UNCOMPRESSED_PUBLIC_KEY); - assertEquals("EC", publicKey.getAlgorithm()); - assertEquals("X.509", publicKey.getFormat()); - } - - @Test - void getPublicKeyFromBytes_wrong() { - //When + Then - assertThrows(ValidationFrostFSException.class, () -> KeyExtension.getPublicKeyFromBytes(null)); - assertThrows(ValidationFrostFSException.class, () -> KeyExtension.getPublicKeyFromBytes(new byte[]{})); - assertThrows(ValidationFrostFSException.class, () -> KeyExtension.getPublicKeyFromBytes(PRIVATE_KEY)); - } -} diff --git a/exceptions/pom.xml b/exceptions/pom.xml deleted file mode 100644 index c3b4546..0000000 --- a/exceptions/pom.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - 4.0.0 - - info.frostfs.sdk - frostfs-sdk-java - ${revision} - - - exceptions - - - 11 - 11 - UTF-8 - - - \ No newline at end of file diff --git a/exceptions/src/main/java/info/frostfs/sdk/constants/ErrorConst.java b/exceptions/src/main/java/info/frostfs/sdk/constants/ErrorConst.java deleted file mode 100644 index 8c248c9..0000000 --- a/exceptions/src/main/java/info/frostfs/sdk/constants/ErrorConst.java +++ /dev/null @@ -1,76 +0,0 @@ -package info.frostfs.sdk.constants; - -public class ErrorConst { - public static final String OBJECT_IS_NULL = "object must not be null"; - public static final String STRING_IS_BLANK = "string must not be blank"; - public static final String INPUT_PARAM_IS_MISSING = "input parameter is not present"; - public static final String SOME_PARAM_IS_MISSING = "one of the input parameters is not present"; - public static final String PARAM_IS_MISSING_TEMPLATE = "param %s is not present"; - public static final String PARAMS_ARE_MISSING_TEMPLATE = "params %s are not present"; - public static final String INPUT_PARAM_IS_MISSING_TEMPLATE = "%s value is not present"; - - public static final String INPUT_PARAM_GREATER_OR_EQUAL_ZERO = "%s must be greater than or equal to zero"; - public static final String INPUT_PARAM_GREATER_ZERO = "%s must be greater than zero"; - - public static final String REQUIRED_FIELD_TEMPLATE = "%s required field"; - - public static final String REQUIRED_PROTO_FIELD_TEMPLATE = "the proto message does not contain a field %s"; - public static final String UNSUPPORTED_PROTO_MESSAGE_TYPE_TEMPLATE = "unsupported proto message type: %s"; - public static final String PROTO_MESSAGE_IS_EMPTY_TEMPLATE = "proto message %s must not be empty"; - public static final String UNEXPECTED_MESSAGE_TYPE_TEMPLATE = "unexpected message type, expected %s, actually %s"; - - public static final String WIF_IS_INVALID = "WIF is invalid"; - public static final String WALLET_IS_INVALID = "wallet is not present"; - public static final String UNEXPECTED_STREAM = "unexpected end of stream"; - public static final String INVALID_HOST_TEMPLATE = "host %s has invalid format. Error: %s"; - public static final String INVALID_RESPONSE = "invalid response"; - public static final String VERSION_UNSUPPORTED_TEMPLATE = "frostFS %s is not supported."; - - public static final String UNKNOWN_ENUM_VALUE_TEMPLATE = "unknown %s value: %s"; - - public static final String INPUT_PARAM_IS_NOT_SHA256 = "%s must be a sha256 hash"; - public static final String WRONG_SIGNATURE_SIZE_TEMPLATE = "wrong signature size. Expected length=%s, actual=%s"; - public static final String COMPRESSED_PUBLIC_KEY_WRONG_LENGTH_TEMPLATE = - "decompress argument isn't compressed public key. Expected length=%s, actual=%s"; - - public static final String WRONG_UUID_SIZE_TEMPLATE = "uuid byte array length must be %s"; - - public static final String POOL_CLIENT_UNHEALTHY = "pool client unhealthy"; - public static final String POOL_PEERS_IS_MISSING = "no FrostFS peers configured"; - public static final String POOL_NODES_UNHEALTHY = "at least one node must be healthy"; - public static final String POOL_CLIENTS_UNHEALTHY = "cannot find alive client"; - public static final String POOL_NOT_DIALED = "pool not dialed"; - - public static final String SESSION_CREATE_FAILED = "cannot create session"; - - public static final String FIELDS_DELIMITER_COMMA = ", "; - public static final String FIELDS_DELIMITER_OR = " or "; - - public static final String UNSUPPORTED_MARSHALLER_VERSION_TEMPLATE = "unsupported marshaller version %s"; - public static final String UNSUPPORTED_CHAIN_VERSION_TEMPLATE = "unsupported chain version %s"; - public static final String MARSHAL_SIZE_DIFFERS = "actual data size differs from expected"; - public static final String UNMARSHAL_SIZE_DIFFERS = "unmarshalled bytes left"; - public static final String BYTES_ARE_OVER_FOR_SERIALIZE_TEMPLATE = - "not enough bytes left to serialize value of type %s with length=%s"; - public static final String BYTES_ARE_OVER_FOR_DESERIALIZE_TEMPLATE = - "not enough bytes left to deserialize a value of type %s from offset=%s"; - public static final String SLICE_IS_TOO_BIG_TEMPLATE = "slice size is too big=%s"; - public static final String SLICE_SIZE_IS_INVALID_TEMPLATE = "invalid slice size=%s"; - public static final String STRING_IS_TOO_BIG_TEMPLATE = "string size is too big=%s"; - public static final String STRING_SIZE_IS_INVALID_TEMPLATE = "invalid string size=%s"; - - public static final String FILTER_NAME_IS_EMPTY = "Filter name for selector is empty"; - public static final String INVALID_FILTER_NAME_TEMPLATE = "filter name is invalid: '%s' is reserved"; - public static final String INVALID_FILTER_OPERATION_TEMPLATE = "invalid filter operation: %s"; - public static final String FILTER_NOT_FOUND = "filter not found"; - public static final String FILTER_NOT_FOUND_TEMPLATE = "filter not found: SELECT FROM '%s'"; - public static final String NON_EMPTY_FILTERS = "simple filter contains sub-filters"; - public static final String NOT_ENOUGH_NODES = "not enough nodes"; - public static final String NOT_ENOUGH_NODES_TEMPLATE = "not enough nodes to SELECT from '%s'"; - public static final String UNNAMED_TOP_FILTER = "unnamed top-level filter"; - public static final String VECTORS_IS_NULL = "vectors cannot be null"; - public static final String SELECTOR_NOT_FOUND_TEMPLATE = "selector not found: %s"; - - private ErrorConst() { - } -} diff --git a/exceptions/src/main/java/info/frostfs/sdk/exceptions/FrostFSException.java b/exceptions/src/main/java/info/frostfs/sdk/exceptions/FrostFSException.java deleted file mode 100644 index fc41bb9..0000000 --- a/exceptions/src/main/java/info/frostfs/sdk/exceptions/FrostFSException.java +++ /dev/null @@ -1,15 +0,0 @@ -package info.frostfs.sdk.exceptions; - -public class FrostFSException extends RuntimeException { - - public FrostFSException() { - } - - public FrostFSException(String message) { - super(message); - } - - public FrostFSException(Throwable cause) { - super(cause); - } -} diff --git a/exceptions/src/main/java/info/frostfs/sdk/exceptions/ProcessFrostFSException.java b/exceptions/src/main/java/info/frostfs/sdk/exceptions/ProcessFrostFSException.java deleted file mode 100644 index 6cd3560..0000000 --- a/exceptions/src/main/java/info/frostfs/sdk/exceptions/ProcessFrostFSException.java +++ /dev/null @@ -1,11 +0,0 @@ -package info.frostfs.sdk.exceptions; - -public class ProcessFrostFSException extends FrostFSException { - public ProcessFrostFSException(String message) { - super(message); - } - - public ProcessFrostFSException(Throwable cause) { - super(cause); - } -} diff --git a/exceptions/src/main/java/info/frostfs/sdk/exceptions/SessionExpiredFrostFSException.java b/exceptions/src/main/java/info/frostfs/sdk/exceptions/SessionExpiredFrostFSException.java deleted file mode 100644 index 1a3a1e8..0000000 --- a/exceptions/src/main/java/info/frostfs/sdk/exceptions/SessionExpiredFrostFSException.java +++ /dev/null @@ -1,8 +0,0 @@ -package info.frostfs.sdk.exceptions; - -public class SessionExpiredFrostFSException extends FrostFSException { - - public SessionExpiredFrostFSException(String message) { - super(message); - } -} diff --git a/exceptions/src/main/java/info/frostfs/sdk/exceptions/SessionNotFoundFrostFSException.java b/exceptions/src/main/java/info/frostfs/sdk/exceptions/SessionNotFoundFrostFSException.java deleted file mode 100644 index 0e8522b..0000000 --- a/exceptions/src/main/java/info/frostfs/sdk/exceptions/SessionNotFoundFrostFSException.java +++ /dev/null @@ -1,8 +0,0 @@ -package info.frostfs.sdk.exceptions; - -public class SessionNotFoundFrostFSException extends FrostFSException { - - public SessionNotFoundFrostFSException(String message) { - super(message); - } -} diff --git a/exceptions/src/main/java/info/frostfs/sdk/exceptions/TimeoutFrostFSException.java b/exceptions/src/main/java/info/frostfs/sdk/exceptions/TimeoutFrostFSException.java deleted file mode 100644 index 5e1ee20..0000000 --- a/exceptions/src/main/java/info/frostfs/sdk/exceptions/TimeoutFrostFSException.java +++ /dev/null @@ -1,6 +0,0 @@ -package info.frostfs.sdk.exceptions; - -public class TimeoutFrostFSException extends FrostFSException { - public TimeoutFrostFSException() { - } -} diff --git a/exceptions/src/main/java/info/frostfs/sdk/exceptions/ValidationFrostFSException.java b/exceptions/src/main/java/info/frostfs/sdk/exceptions/ValidationFrostFSException.java deleted file mode 100644 index 74e5259..0000000 --- a/exceptions/src/main/java/info/frostfs/sdk/exceptions/ValidationFrostFSException.java +++ /dev/null @@ -1,7 +0,0 @@ -package info.frostfs.sdk.exceptions; - -public class ValidationFrostFSException extends FrostFSException { - public ValidationFrostFSException(String message) { - super(message); - } -} diff --git a/models/pom.xml b/models/pom.xml deleted file mode 100644 index e913463..0000000 --- a/models/pom.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - 4.0.0 - - info.frostfs.sdk - frostfs-sdk-java - ${revision} - - - models - - - 11 - 11 - UTF-8 - - - - - info.frostfs.sdk - cryptography - ${revision} - - - info.frostfs.sdk - protos - ${revision} - - - info.frostfs.sdk - exceptions - ${revision} - - - - \ No newline at end of file diff --git a/models/src/main/java/info/frostfs/sdk/UuidExtension.java b/models/src/main/java/info/frostfs/sdk/UuidExtension.java deleted file mode 100644 index 5060baa..0000000 --- a/models/src/main/java/info/frostfs/sdk/UuidExtension.java +++ /dev/null @@ -1,40 +0,0 @@ -package info.frostfs.sdk; - -import info.frostfs.sdk.exceptions.ValidationFrostFSException; - -import java.nio.ByteBuffer; -import java.util.UUID; - -import static info.frostfs.sdk.constants.AppConst.UUID_BYTE_ARRAY_LENGTH; -import static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_IS_MISSING_TEMPLATE; -import static info.frostfs.sdk.constants.ErrorConst.WRONG_UUID_SIZE_TEMPLATE; -import static java.util.Objects.isNull; - -public class UuidExtension { - private UuidExtension() { - } - - public static UUID asUuid(byte[] bytes) { - if (isNull(bytes) || bytes.length != UUID_BYTE_ARRAY_LENGTH) { - throw new ValidationFrostFSException(String.format(WRONG_UUID_SIZE_TEMPLATE, UUID_BYTE_ARRAY_LENGTH)); - } - - ByteBuffer bb = ByteBuffer.wrap(bytes); - long firstLong = bb.getLong(); - long secondLong = bb.getLong(); - return new UUID(firstLong, secondLong); - } - - public static byte[] asBytes(UUID uuid) { - if (isNull(uuid)) { - throw new ValidationFrostFSException( - String.format(INPUT_PARAM_IS_MISSING_TEMPLATE, UUID.class.getName()) - ); - } - - ByteBuffer bb = ByteBuffer.allocate(UUID_BYTE_ARRAY_LENGTH); - bb.putLong(uuid.getMostSignificantBits()); - bb.putLong(uuid.getLeastSignificantBits()); - return bb.array(); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/constants/AppConst.java b/models/src/main/java/info/frostfs/sdk/constants/AppConst.java deleted file mode 100644 index 58b0041..0000000 --- a/models/src/main/java/info/frostfs/sdk/constants/AppConst.java +++ /dev/null @@ -1,24 +0,0 @@ -package info.frostfs.sdk.constants; - -import java.math.BigInteger; - -public class AppConst { - public static final String RESERVED_PREFIX = "__SYSTEM__"; - - public static final int DEFAULT_MAJOR_VERSION = 2; - public static final int DEFAULT_MINOR_VERSION = 13; - public static final int BYTE_SHIFT = 10; - public static final int BYTE = 1; - public static final int KIB = BYTE << BYTE_SHIFT; - public static final int MIB = KIB << BYTE_SHIFT; - public static final int OBJECT_CHUNK_SIZE = 3 * MIB; - public static final int SHA256_HASH_LENGTH = 32; - public static final int UUID_BYTE_ARRAY_LENGTH = 16; - public static final int DEFAULT_GRPC_TIMEOUT = 5; - public static final long DEFAULT_POLL_INTERVAL = 10; - - public static final BigInteger UNSIGNED_LONG_MASK = BigInteger.ONE.shiftLeft(Long.SIZE).subtract(BigInteger.ONE); - - private AppConst() { - } -} diff --git a/models/src/main/java/info/frostfs/sdk/constants/AttributeConst.java b/models/src/main/java/info/frostfs/sdk/constants/AttributeConst.java deleted file mode 100644 index 964b3d4..0000000 --- a/models/src/main/java/info/frostfs/sdk/constants/AttributeConst.java +++ /dev/null @@ -1,21 +0,0 @@ -package info.frostfs.sdk.constants; - -import static info.frostfs.sdk.constants.AppConst.RESERVED_PREFIX; - -public class AttributeConst { - public static final String DISABLE_HOMOMORPHIC_HASHING_ATTRIBUTE = RESERVED_PREFIX + "DISABLE_HOMOMORPHIC_HASHING"; - - /* - * ATTRIBUTE_PRICE is a key to the node attribute that indicates - * the price in GAS tokens for storing one GB of data during one Epoch. - * */ - public static final String ATTRIBUTE_PRICE = "Price"; - - /* - * ATTRIBUTE_CAPACITY is a key to the node attribute that indicates the total available disk space in Gigabytes. - * */ - public static final String ATTRIBUTE_CAPACITY = "Capacity"; - - private AttributeConst() { - } -} diff --git a/models/src/main/java/info/frostfs/sdk/constants/FieldConst.java b/models/src/main/java/info/frostfs/sdk/constants/FieldConst.java deleted file mode 100644 index 636df86..0000000 --- a/models/src/main/java/info/frostfs/sdk/constants/FieldConst.java +++ /dev/null @@ -1,15 +0,0 @@ -package info.frostfs.sdk.constants; - -public class FieldConst { - public static final String META_HEADER_FIELD_NAME = "meta_header"; - public static final String META_SIGNATURE_FIELD_NAME = "meta_signature"; - public static final String BODY_FIELD_NAME = "body"; - public static final String BODY_SIGNATURE_FIELD_NAME = "body_signature"; - public static final String ORIGIN_FIELD_NAME = "origin"; - public static final String ORIGIN_SIGNATURE_FIELD_NAME = "origin_signature"; - public static final String VERIFY_HEADER_FIELD_NAME = "verify_header"; - public static final String EMPTY_STRING = ""; - - private FieldConst() { - } -} diff --git a/models/src/main/java/info/frostfs/sdk/constants/FilterConst.java b/models/src/main/java/info/frostfs/sdk/constants/FilterConst.java deleted file mode 100644 index 5b28055..0000000 --- a/models/src/main/java/info/frostfs/sdk/constants/FilterConst.java +++ /dev/null @@ -1,52 +0,0 @@ -package info.frostfs.sdk.constants; - -public class FilterConst { - - // HEADER_PREFIX is a prefix of key to object header value or property. - public static final String HEADER_PREFIX = "$Object:"; - - // FILTER_HEADER_VERSION is a filter key to "version" field of the object header. - public static final String FILTER_HEADER_VERSION = HEADER_PREFIX + "version"; - - // FILTER_HEADER_OBJECT_ID is a filter key to "object_id" field of the object. - public static final String FILTER_HEADER_OBJECT_ID = HEADER_PREFIX + "objectID"; - - // FILTER_HEADER_CONTAINER_ID is a filter key to "container_id" field of the object header. - public static final String FILTER_HEADER_CONTAINER_ID = HEADER_PREFIX + "containerID"; - - // FILTER_HEADER_OWNER_ID is a filter key to "owner_id" field of the object header. - public static final String FILTER_HEADER_OWNER_ID = HEADER_PREFIX + "ownerID"; - - // FILTER_HEADER_CREATION_EPOCH is a filter key to "creation_epoch" field of the object header. - public static final String FILTER_HEADER_CREATION_EPOCH = HEADER_PREFIX + "creationEpoch"; - - // FILTER_HEADER_PAYLOAD_LENGTH is a filter key to "payload_length" field of the object header. - public static final String FILTER_HEADER_PAYLOAD_LENGTH = HEADER_PREFIX + "payloadLength"; - - // FILTER_HEADER_PAYLOAD_HASH is a filter key to "payload_hash" field of the object header. - public static final String FILTER_HEADER_PAYLOAD_HASH = HEADER_PREFIX + "payloadHash"; - - // FILTER_HEADER_OBJECT_TYPE is a filter key to "object_type" field of the object header. - public static final String FILTER_HEADER_OBJECT_TYPE = HEADER_PREFIX + "objectType"; - - // FILTER_HEADER_HOMOMORPHIC_HASH is a filter key to "homomorphic_hash" field of the object header. - public static final String FILTER_HEADER_HOMOMORPHIC_HASH = HEADER_PREFIX + "homomorphicHash"; - - // FILTER_HEADER_PARENT is a filter key to "split.parent" field of the object header. - public static final String FILTER_HEADER_PARENT = HEADER_PREFIX + "split.parent"; - - // FILTER_HEADER_SPLIT_ID is a filter key to "split.splitID" field of the object header. - public static final String FILTER_HEADER_SPLIT_ID = HEADER_PREFIX + "split.splitID"; - - // FILTER_HEADER_EC_PARENT is a filter key to "ec.parent" field of the object header. - public static final String FILTER_HEADER_EC_PARENT = HEADER_PREFIX + "ec.parent"; - - // FILTER_HEADER_ROOT is a filter key to check if regular object is on top of split hierarchy. - public static final String FILTER_HEADER_ROOT = HEADER_PREFIX + "ROOT"; - - // FILTER_HEADER_PHY is a filter key to check if an object physically stored on a node. - public static final String FILTER_HEADER_PHY = HEADER_PREFIX + "PHY"; - - private FilterConst() { - } -} diff --git a/models/src/main/java/info/frostfs/sdk/constants/XHeaderConst.java b/models/src/main/java/info/frostfs/sdk/constants/XHeaderConst.java deleted file mode 100644 index 805762a..0000000 --- a/models/src/main/java/info/frostfs/sdk/constants/XHeaderConst.java +++ /dev/null @@ -1,11 +0,0 @@ -package info.frostfs.sdk.constants; - -import static info.frostfs.sdk.constants.AppConst.RESERVED_PREFIX; - -public class XHeaderConst { - public static final String XHEADER_NETMAP_EPOCH = RESERVED_PREFIX + "NETMAP_EPOCH"; - public static final String XHEADER_NETMAP_LOOKUP_DEPTH = RESERVED_PREFIX + "NETMAP_LOOKUP_DEPTH"; - - private XHeaderConst() { - } -} diff --git a/models/src/main/java/info/frostfs/sdk/dto/CheckSum.java b/models/src/main/java/info/frostfs/sdk/dto/CheckSum.java deleted file mode 100644 index c414572..0000000 --- a/models/src/main/java/info/frostfs/sdk/dto/CheckSum.java +++ /dev/null @@ -1,21 +0,0 @@ -package info.frostfs.sdk.dto; - -import info.frostfs.sdk.Helper; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -public class CheckSum { - // type is always Sha256 - public byte[] hash; - - public CheckSum(byte[] content) { - this.hash = Helper.getSha256(content); - } - - @Override - public String toString() { - return Helper.getHexString(hash); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/dto/ape/Actions.java b/models/src/main/java/info/frostfs/sdk/dto/ape/Actions.java deleted file mode 100644 index 83415a4..0000000 --- a/models/src/main/java/info/frostfs/sdk/dto/ape/Actions.java +++ /dev/null @@ -1,15 +0,0 @@ -package info.frostfs.sdk.dto.ape; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -@Getter -@Setter -@AllArgsConstructor -@NoArgsConstructor -public class Actions { - private boolean inverted; - private String[] names; -} diff --git a/models/src/main/java/info/frostfs/sdk/dto/ape/Chain.java b/models/src/main/java/info/frostfs/sdk/dto/ape/Chain.java deleted file mode 100644 index 0e8385f..0000000 --- a/models/src/main/java/info/frostfs/sdk/dto/ape/Chain.java +++ /dev/null @@ -1,17 +0,0 @@ -package info.frostfs.sdk.dto.ape; - -import info.frostfs.sdk.enums.RuleMatchType; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -@Getter -@Setter -@AllArgsConstructor -@NoArgsConstructor -public class Chain { - private Byte[] id; - private Rule[] rules; - private RuleMatchType matchType; -} diff --git a/models/src/main/java/info/frostfs/sdk/dto/ape/Condition.java b/models/src/main/java/info/frostfs/sdk/dto/ape/Condition.java deleted file mode 100644 index 8334f94..0000000 --- a/models/src/main/java/info/frostfs/sdk/dto/ape/Condition.java +++ /dev/null @@ -1,19 +0,0 @@ -package info.frostfs.sdk.dto.ape; - -import info.frostfs.sdk.enums.ConditionKindType; -import info.frostfs.sdk.enums.ConditionType; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -@Getter -@Setter -@AllArgsConstructor -@NoArgsConstructor -public class Condition { - private ConditionType op; - private ConditionKindType kind; - private String key; - private String value; -} diff --git a/models/src/main/java/info/frostfs/sdk/dto/ape/Resources.java b/models/src/main/java/info/frostfs/sdk/dto/ape/Resources.java deleted file mode 100644 index 017ed4a..0000000 --- a/models/src/main/java/info/frostfs/sdk/dto/ape/Resources.java +++ /dev/null @@ -1,15 +0,0 @@ -package info.frostfs.sdk.dto.ape; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -@Getter -@Setter -@AllArgsConstructor -@NoArgsConstructor -public class Resources { - private boolean inverted; - private String[] names; -} diff --git a/models/src/main/java/info/frostfs/sdk/dto/ape/Rule.java b/models/src/main/java/info/frostfs/sdk/dto/ape/Rule.java deleted file mode 100644 index 14e462f..0000000 --- a/models/src/main/java/info/frostfs/sdk/dto/ape/Rule.java +++ /dev/null @@ -1,27 +0,0 @@ -package info.frostfs.sdk.dto.ape; - -import info.frostfs.sdk.enums.RuleStatus; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -@Getter -@Setter -@AllArgsConstructor -@NoArgsConstructor -public class Rule { - private RuleStatus status; - - // Actions the operation is applied to. - private Actions actions; - - // List of the resources the operation is applied to. - private Resources resources; - - // True if individual conditions must be combined with the logical OR. - // By default, AND is used, so _each_ condition must pass. - private boolean any; - - private Condition[] conditions; -} diff --git a/models/src/main/java/info/frostfs/sdk/dto/chain/ChainTarget.java b/models/src/main/java/info/frostfs/sdk/dto/chain/ChainTarget.java deleted file mode 100644 index c03a179..0000000 --- a/models/src/main/java/info/frostfs/sdk/dto/chain/ChainTarget.java +++ /dev/null @@ -1,17 +0,0 @@ -package info.frostfs.sdk.dto.chain; - -import info.frostfs.sdk.enums.TargetType; -import lombok.EqualsAndHashCode; -import lombok.Getter; - -@Getter -@EqualsAndHashCode -public class ChainTarget { - private final TargetType type; - private final String name; - - public ChainTarget(String name, TargetType type) { - this.name = name; - this.type = type; - } -} diff --git a/models/src/main/java/info/frostfs/sdk/dto/container/Container.java b/models/src/main/java/info/frostfs/sdk/dto/container/Container.java deleted file mode 100644 index b9a0ea4..0000000 --- a/models/src/main/java/info/frostfs/sdk/dto/container/Container.java +++ /dev/null @@ -1,28 +0,0 @@ -package info.frostfs.sdk.dto.container; - -import info.frostfs.sdk.dto.netmap.PlacementPolicy; -import info.frostfs.sdk.dto.netmap.Version; -import info.frostfs.sdk.dto.object.OwnerId; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Setter; - -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -@Getter -@Setter -@AllArgsConstructor -public class Container { - private UUID nonce; - private PlacementPolicy placementPolicy; - private Version version; - private OwnerId ownerId; - private Map attributes = new HashMap<>(); - - public Container(PlacementPolicy placementPolicy) { - this.nonce = UUID.randomUUID(); - this.placementPolicy = placementPolicy; - } -} diff --git a/models/src/main/java/info/frostfs/sdk/dto/container/ContainerId.java b/models/src/main/java/info/frostfs/sdk/dto/container/ContainerId.java deleted file mode 100644 index def97fd..0000000 --- a/models/src/main/java/info/frostfs/sdk/dto/container/ContainerId.java +++ /dev/null @@ -1,46 +0,0 @@ -package info.frostfs.sdk.dto.container; - -import info.frostfs.sdk.constants.AppConst; -import info.frostfs.sdk.exceptions.ValidationFrostFSException; -import io.neow3j.crypto.Base58; -import lombok.Getter; -import org.apache.commons.lang3.StringUtils; - -import static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_IS_MISSING_TEMPLATE; -import static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_IS_NOT_SHA256; -import static java.util.Objects.isNull; - -@Getter -public class ContainerId { - - private final String value; - - public ContainerId(String value) { - if (StringUtils.isEmpty(value)) { - throw new ValidationFrostFSException( - String.format(INPUT_PARAM_IS_MISSING_TEMPLATE, ContainerId.class.getName()) - ); - } - - this.value = value; - } - - public ContainerId(byte[] hash) { - if (isNull(hash) || hash.length != AppConst.SHA256_HASH_LENGTH) { - throw new ValidationFrostFSException( - String.format(INPUT_PARAM_IS_NOT_SHA256, ContainerId.class.getName()) - ); - } - - this.value = Base58.encode(hash); - } - - @Override - public String toString() { - return value; - } - - public byte[] toHash() { - return Base58.decode(value); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/dto/netmap/Filter.java b/models/src/main/java/info/frostfs/sdk/dto/netmap/Filter.java deleted file mode 100644 index a957dce..0000000 --- a/models/src/main/java/info/frostfs/sdk/dto/netmap/Filter.java +++ /dev/null @@ -1,15 +0,0 @@ -package info.frostfs.sdk.dto.netmap; - -import info.frostfs.sdk.enums.netmap.FilterOperation; -import lombok.AllArgsConstructor; -import lombok.Getter; - -@Getter -@AllArgsConstructor -public class Filter { - private final String name; - private final String key; - private final FilterOperation operation; - private final String value; - private final Filter[] filters; -} diff --git a/models/src/main/java/info/frostfs/sdk/dto/netmap/Hasher.java b/models/src/main/java/info/frostfs/sdk/dto/netmap/Hasher.java deleted file mode 100644 index 286f77f..0000000 --- a/models/src/main/java/info/frostfs/sdk/dto/netmap/Hasher.java +++ /dev/null @@ -1,5 +0,0 @@ -package info.frostfs.sdk.dto.netmap; - -public interface Hasher { - long getHash(); -} diff --git a/models/src/main/java/info/frostfs/sdk/dto/netmap/NetmapSnapshot.java b/models/src/main/java/info/frostfs/sdk/dto/netmap/NetmapSnapshot.java deleted file mode 100644 index 6cde815..0000000 --- a/models/src/main/java/info/frostfs/sdk/dto/netmap/NetmapSnapshot.java +++ /dev/null @@ -1,13 +0,0 @@ -package info.frostfs.sdk.dto.netmap; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -import java.util.List; - -@Getter -@AllArgsConstructor -public class NetmapSnapshot { - private final Long epoch; - private final List nodeInfoCollection; -} diff --git a/models/src/main/java/info/frostfs/sdk/dto/netmap/NodeInfo.java b/models/src/main/java/info/frostfs/sdk/dto/netmap/NodeInfo.java deleted file mode 100644 index a46cf2a..0000000 --- a/models/src/main/java/info/frostfs/sdk/dto/netmap/NodeInfo.java +++ /dev/null @@ -1,59 +0,0 @@ -package info.frostfs.sdk.dto.netmap; - -import info.frostfs.sdk.enums.netmap.NodeState; -import lombok.Getter; -import org.apache.commons.codec.digest.MurmurHash3; - -import java.math.BigInteger; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -import static info.frostfs.sdk.constants.AppConst.UNSIGNED_LONG_MASK; -import static info.frostfs.sdk.constants.AttributeConst.ATTRIBUTE_CAPACITY; -import static info.frostfs.sdk.constants.AttributeConst.ATTRIBUTE_PRICE; -import static java.util.Objects.isNull; - -@Getter -public class NodeInfo implements Hasher { - private final NodeState state; - private final Version version; - private final List addresses; - private final Map attributes; - private final byte[] publicKey; - - private long hash; - private BigInteger price = UNSIGNED_LONG_MASK; - - - public NodeInfo(NodeState state, Version version, List addresses, - Map attributes, byte[] publicKey) { - this.state = state; - this.version = version; - this.addresses = Collections.unmodifiableList(addresses); - this.attributes = Collections.unmodifiableMap(attributes); - this.publicKey = publicKey; - } - - public long getHash() { - if (hash == 0) { - hash = MurmurHash3.hash128x64(publicKey, 0, publicKey.length, 0)[0]; - } - - return hash; - } - - public BigInteger getCapacity() { - var capacity = attributes.get(ATTRIBUTE_CAPACITY); - return isNull(capacity) ? BigInteger.valueOf(0) : new BigInteger(capacity); - } - - public BigInteger getPrice() { - if (price.equals(UNSIGNED_LONG_MASK)) { - var priceString = attributes.get(ATTRIBUTE_PRICE); - price = isNull(priceString) ? BigInteger.valueOf(0) : new BigInteger(priceString); - } - - return price; - } -} diff --git a/models/src/main/java/info/frostfs/sdk/dto/netmap/PlacementPolicy.java b/models/src/main/java/info/frostfs/sdk/dto/netmap/PlacementPolicy.java deleted file mode 100644 index d25808b..0000000 --- a/models/src/main/java/info/frostfs/sdk/dto/netmap/PlacementPolicy.java +++ /dev/null @@ -1,22 +0,0 @@ -package info.frostfs.sdk.dto.netmap; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -@Getter -@AllArgsConstructor -public class PlacementPolicy { - private final Replica[] replicas; - private final boolean unique; - private final int backupFactory; - private final Filter[] filters; - private final Selector[] selectors; - - public PlacementPolicy(Replica[] replicas, boolean unique, int backupFactory) { - this.replicas = replicas; - this.unique = unique; - this.backupFactory = backupFactory; - this.filters = null; - this.selectors = null; - } -} diff --git a/models/src/main/java/info/frostfs/sdk/dto/netmap/Replica.java b/models/src/main/java/info/frostfs/sdk/dto/netmap/Replica.java deleted file mode 100644 index 09d059d..0000000 --- a/models/src/main/java/info/frostfs/sdk/dto/netmap/Replica.java +++ /dev/null @@ -1,50 +0,0 @@ -package info.frostfs.sdk.dto.netmap; - -import info.frostfs.sdk.exceptions.ValidationFrostFSException; -import lombok.Getter; -import lombok.experimental.FieldNameConstants; -import org.apache.commons.lang3.StringUtils; - -import static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_GREATER_ZERO; -import static info.frostfs.sdk.constants.FieldConst.EMPTY_STRING; - -@Getter -@FieldNameConstants -public class Replica { - private final int count; - private final String selector; - private long ecDataCount; - private long ecParityCount; - - public Replica(int count, String selector, int ecDataCount, int ecParityCount) { - this(count, selector); - this.ecDataCount = Integer.toUnsignedLong(ecDataCount); - this.ecParityCount = Integer.toUnsignedLong(ecParityCount); - } - - public Replica(int count, String selector) { - if (count <= 0) { - throw new ValidationFrostFSException( - String.format(INPUT_PARAM_GREATER_ZERO, Fields.count) - ); - } - - this.count = count; - this.selector = StringUtils.isEmpty(selector) ? EMPTY_STRING : selector; - } - - public Replica(int count) { - if (count <= 0) { - throw new ValidationFrostFSException( - String.format(INPUT_PARAM_GREATER_ZERO, Fields.count) - ); - } - - this.count = count; - this.selector = EMPTY_STRING; - } - - public int getCountNodes() { - return count != 0 ? count : (int) (ecDataCount + ecParityCount); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/dto/netmap/Selector.java b/models/src/main/java/info/frostfs/sdk/dto/netmap/Selector.java deleted file mode 100644 index 4dee15c..0000000 --- a/models/src/main/java/info/frostfs/sdk/dto/netmap/Selector.java +++ /dev/null @@ -1,17 +0,0 @@ -package info.frostfs.sdk.dto.netmap; - -import info.frostfs.sdk.enums.netmap.SelectorClause; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@AllArgsConstructor -public class Selector { - private final String name; - private int count; - private SelectorClause clause; - private String attribute; - private String filter; -} diff --git a/models/src/main/java/info/frostfs/sdk/dto/netmap/Version.java b/models/src/main/java/info/frostfs/sdk/dto/netmap/Version.java deleted file mode 100644 index cab01cf..0000000 --- a/models/src/main/java/info/frostfs/sdk/dto/netmap/Version.java +++ /dev/null @@ -1,33 +0,0 @@ -package info.frostfs.sdk.dto.netmap; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -import static info.frostfs.sdk.constants.AppConst.DEFAULT_MAJOR_VERSION; -import static info.frostfs.sdk.constants.AppConst.DEFAULT_MINOR_VERSION; -import static java.util.Objects.isNull; - -@Getter -@AllArgsConstructor -public class Version { - private final int major; - private final int minor; - - public Version() { - this.major = DEFAULT_MAJOR_VERSION; - this.minor = DEFAULT_MINOR_VERSION; - } - - @Override - public String toString() { - return "v" + major + "." + minor; - } - - public boolean isSupported(Version version) { - if (isNull(version)) { - return false; - } - - return major == version.getMajor(); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/dto/object/LargeObject.java b/models/src/main/java/info/frostfs/sdk/dto/object/LargeObject.java deleted file mode 100644 index 915b745..0000000 --- a/models/src/main/java/info/frostfs/sdk/dto/object/LargeObject.java +++ /dev/null @@ -1,34 +0,0 @@ -package info.frostfs.sdk.dto.object; - -import info.frostfs.sdk.dto.container.ContainerId; - -import java.security.MessageDigest; - -import static info.frostfs.sdk.Helper.getSha256Instance; -import static java.util.Objects.isNull; - -public class LargeObject extends ObjectFrostFS { - private final MessageDigest payloadHash; - - public LargeObject(ContainerId cid) { - super(cid, new byte[]{}); - this.payloadHash = getSha256Instance(); - } - - public void appendBlock(byte[] bytes, int count) { - if (count == 0 || isNull(bytes) || bytes.length == 0) { - return; - } - - this.getHeader().increasePayloadLength(count); - this.payloadHash.update(bytes, 0, count); - } - - public void calculateHash() { - this.getHeader().setPayloadCheckSum(this.payloadHash.digest()); - } - - public long getPayloadLength() { - return getHeader().getPayloadLength(); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/dto/object/LinkObject.java b/models/src/main/java/info/frostfs/sdk/dto/object/LinkObject.java deleted file mode 100644 index a2ffb6f..0000000 --- a/models/src/main/java/info/frostfs/sdk/dto/object/LinkObject.java +++ /dev/null @@ -1,24 +0,0 @@ -package info.frostfs.sdk.dto.object; - -import info.frostfs.sdk.dto.container.ContainerId; -import org.apache.commons.collections4.CollectionUtils; - -import java.util.List; - -public class LinkObject extends ObjectFrostFS { - - public LinkObject(ContainerId cid, SplitId splitId, ObjectHeader largeObjectHeader) { - super(cid, new byte[]{}); - var split = new Split(splitId); - split.setParentHeader(largeObjectHeader); - this.getHeader().setSplit(split); - } - - public void addChildren(List objectIds) { - if (CollectionUtils.isEmpty(objectIds)) { - return; - } - - this.getHeader().getSplit().getChildren().addAll(objectIds); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/dto/object/ObjectAttribute.java b/models/src/main/java/info/frostfs/sdk/dto/object/ObjectAttribute.java deleted file mode 100644 index b9602c2..0000000 --- a/models/src/main/java/info/frostfs/sdk/dto/object/ObjectAttribute.java +++ /dev/null @@ -1,22 +0,0 @@ -package info.frostfs.sdk.dto.object; - -import info.frostfs.sdk.exceptions.ValidationFrostFSException; -import lombok.Getter; -import org.apache.commons.lang3.StringUtils; - -import static info.frostfs.sdk.constants.ErrorConst.SOME_PARAM_IS_MISSING; - -@Getter -public class ObjectAttribute { - private final String key; - private final String value; - - public ObjectAttribute(String key, String value) { - if (StringUtils.isEmpty(key) || StringUtils.isEmpty(value)) { - throw new ValidationFrostFSException(SOME_PARAM_IS_MISSING); - } - - this.key = key; - this.value = value; - } -} diff --git a/models/src/main/java/info/frostfs/sdk/dto/object/ObjectFilter.java b/models/src/main/java/info/frostfs/sdk/dto/object/ObjectFilter.java deleted file mode 100644 index ef046b5..0000000 --- a/models/src/main/java/info/frostfs/sdk/dto/object/ObjectFilter.java +++ /dev/null @@ -1,103 +0,0 @@ -package info.frostfs.sdk.dto.object; - -import info.frostfs.sdk.constants.FieldConst; -import info.frostfs.sdk.constants.FilterConst; -import info.frostfs.sdk.dto.CheckSum; -import info.frostfs.sdk.dto.container.ContainerId; -import info.frostfs.sdk.dto.netmap.Version; -import info.frostfs.sdk.enums.ObjectMatchType; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@AllArgsConstructor -public abstract class ObjectFilter { - private ObjectMatchType matchType; - private String key; - private T value; - - public String getSerializedValue() { - return value.toString(); - } - - public static class FilterByAttribute extends ObjectFilter { - public FilterByAttribute(ObjectMatchType matchType, String key, String value) { - super(matchType, key, value); - } - } - - public static class FilterByObjectId extends ObjectFilter { - public FilterByObjectId(ObjectMatchType matchType, ObjectId value) { - super(matchType, FilterConst.FILTER_HEADER_OBJECT_ID, value); - } - } - - public static class FilterByOwnerId extends ObjectFilter { - public FilterByOwnerId(ObjectMatchType matchType, OwnerId value) { - super(matchType, FilterConst.FILTER_HEADER_OWNER_ID, value); - } - } - - public static class FilterByVersion extends ObjectFilter { - public FilterByVersion(ObjectMatchType matchType, Version value) { - super(matchType, FilterConst.FILTER_HEADER_VERSION, value); - } - } - - public static class FilterByContainerId extends ObjectFilter { - public FilterByContainerId(ObjectMatchType matchType, ContainerId value) { - super(matchType, FilterConst.FILTER_HEADER_CONTAINER_ID, value); - } - } - - public static class FilterByEpoch extends ObjectFilter { - public FilterByEpoch(ObjectMatchType matchType, long value) { - super(matchType, FilterConst.FILTER_HEADER_CREATION_EPOCH, value); - } - } - - public static class FilterByPayloadLength extends ObjectFilter { - public FilterByPayloadLength(ObjectMatchType matchType, long value) { - super(matchType, FilterConst.FILTER_HEADER_PAYLOAD_LENGTH, value); - } - } - - public static class FilterByPayloadHash extends ObjectFilter { - public FilterByPayloadHash(ObjectMatchType matchType, CheckSum value) { - super(matchType, FilterConst.FILTER_HEADER_PAYLOAD_HASH, value); - } - } - - public static class FilterByParent extends ObjectFilter { - public FilterByParent(ObjectMatchType matchType, ObjectId value) { - super(matchType, FilterConst.FILTER_HEADER_PARENT, value); - } - } - - public static class FilterBySplitId extends ObjectFilter { - public FilterBySplitId(ObjectMatchType matchType, SplitId value) { - super(matchType, FilterConst.FILTER_HEADER_SPLIT_ID, value); - } - } - - - public static class FilterByECParent extends ObjectFilter { - public FilterByECParent(ObjectMatchType matchType, ObjectId value) { - super(matchType, FilterConst.FILTER_HEADER_EC_PARENT, value); - } - } - - public static class FilterByRootObject extends ObjectFilter { - public FilterByRootObject() { - super(ObjectMatchType.UNSPECIFIED, FilterConst.FILTER_HEADER_ROOT, FieldConst.EMPTY_STRING); - } - } - - public static class FilterByPhysicallyStored extends ObjectFilter { - public FilterByPhysicallyStored() { - super(ObjectMatchType.UNSPECIFIED, FilterConst.FILTER_HEADER_PHY, FieldConst.EMPTY_STRING); - } - } -} diff --git a/models/src/main/java/info/frostfs/sdk/dto/object/ObjectFrostFS.java b/models/src/main/java/info/frostfs/sdk/dto/object/ObjectFrostFS.java deleted file mode 100644 index 155f973..0000000 --- a/models/src/main/java/info/frostfs/sdk/dto/object/ObjectFrostFS.java +++ /dev/null @@ -1,69 +0,0 @@ -package info.frostfs.sdk.dto.object; - -import info.frostfs.sdk.dto.container.ContainerId; -import info.frostfs.sdk.enums.ObjectType; -import info.frostfs.sdk.exceptions.ValidationFrostFSException; -import lombok.Getter; -import lombok.Setter; - -import java.util.List; - -import static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_IS_MISSING_TEMPLATE; -import static java.util.Objects.isNull; - -@Getter -@Setter -public class ObjectFrostFS { - private final ObjectHeader header; - private ObjectId objectId; - private byte[] payload; - private ObjectReader objectReader; - - public ObjectFrostFS(ObjectHeader header, ObjectId objectId, byte[] payload) { - if (isNull(header)) { - throw new ValidationFrostFSException( - String.format(INPUT_PARAM_IS_MISSING_TEMPLATE, ObjectHeader.class.getName()) - ); - } - - this.header = header; - this.objectId = objectId; - this.payload = payload; - } - - public ObjectFrostFS(ContainerId containerId, byte[] payload) { - this.payload = payload; - this.header = new ObjectHeader(containerId); - } - - public ObjectFrostFS(ContainerId containerId, byte[] payload, ObjectType objectType) { - this.payload = payload; - this.header = new ObjectHeader(containerId, objectType); - } - - public void setSplit(Split split) { - header.setSplit(split); - } - - public void addAttribute(String key, String value) { - header.getAttributes().add(new ObjectAttribute(key, value)); - } - - public void addAttribute(ObjectAttribute attribute) { - header.getAttributes().add(attribute); - } - - public void addAttributes(List attributes) { - header.getAttributes().addAll(attributes); - } - - public void setParent(LargeObject largeObject) { - if (isNull(header.getSplit())) { - throw new ValidationFrostFSException( - String.format(INPUT_PARAM_IS_MISSING_TEMPLATE, Split.class.getName()) - ); - } - - header.getSplit().setParentHeader(largeObject.getHeader()); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/dto/object/ObjectHeader.java b/models/src/main/java/info/frostfs/sdk/dto/object/ObjectHeader.java deleted file mode 100644 index 0fdd3ef..0000000 --- a/models/src/main/java/info/frostfs/sdk/dto/object/ObjectHeader.java +++ /dev/null @@ -1,75 +0,0 @@ -package info.frostfs.sdk.dto.object; - -import info.frostfs.sdk.dto.container.ContainerId; -import info.frostfs.sdk.dto.netmap.Version; -import info.frostfs.sdk.enums.ObjectType; -import info.frostfs.sdk.exceptions.ValidationFrostFSException; -import lombok.Getter; -import lombok.Setter; - -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -import static info.frostfs.sdk.constants.ErrorConst.FIELDS_DELIMITER_OR; -import static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_IS_MISSING_TEMPLATE; -import static java.util.Objects.isNull; - -@Getter -@Setter -public class ObjectHeader { - private final ContainerId containerId; - private final ObjectType objectType; - private List attributes; - private Version version; - private OwnerId ownerId; - private long payloadLength; - private byte[] payloadCheckSum; - private Split split; - - public ObjectHeader(ContainerId containerId, ObjectType objectType, - List attributes, long payloadLength, Version version) { - if (isNull(containerId) || isNull(objectType)) { - throw new ValidationFrostFSException( - String.format( - INPUT_PARAM_IS_MISSING_TEMPLATE, - String.join(FIELDS_DELIMITER_OR, ContainerId.class.getName(), ObjectType.class.getName()) - ) - ); - } - - this.attributes = attributes; - this.containerId = containerId; - this.payloadLength = payloadLength; - this.objectType = objectType; - this.version = version; - } - - public ObjectHeader(ContainerId containerId, ObjectType objectType, ObjectAttribute... attributes) { - this( - containerId, - objectType, - Arrays.stream(attributes).collect(Collectors.toList()), - 0L, - null - ); - } - - public ObjectHeader(ContainerId containerId, ObjectAttribute... attributes) { - this(containerId, ObjectType.REGULAR, attributes); - } - - public void increasePayloadLength(long payloadLength) { - this.payloadLength += payloadLength; - } - - public void setSplit(Split split) { - if (isNull(split)) { - throw new ValidationFrostFSException( - String.format(INPUT_PARAM_IS_MISSING_TEMPLATE, Split.class.getName()) - ); - } - - this.split = split; - } -} diff --git a/models/src/main/java/info/frostfs/sdk/dto/object/ObjectId.java b/models/src/main/java/info/frostfs/sdk/dto/object/ObjectId.java deleted file mode 100644 index 35e9ab2..0000000 --- a/models/src/main/java/info/frostfs/sdk/dto/object/ObjectId.java +++ /dev/null @@ -1,45 +0,0 @@ -package info.frostfs.sdk.dto.object; - -import info.frostfs.sdk.constants.AppConst; -import info.frostfs.sdk.exceptions.ValidationFrostFSException; -import io.neow3j.crypto.Base58; -import lombok.Getter; -import org.apache.commons.lang3.StringUtils; - -import static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_IS_MISSING_TEMPLATE; -import static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_IS_NOT_SHA256; -import static java.util.Objects.isNull; - -@Getter -public class ObjectId { - private final String value; - - public ObjectId(String value) { - if (StringUtils.isEmpty(value)) { - throw new ValidationFrostFSException( - String.format(INPUT_PARAM_IS_MISSING_TEMPLATE, ObjectId.class.getName()) - ); - } - - this.value = value; - } - - public ObjectId(byte[] hash) { - if (isNull(hash) || hash.length != AppConst.SHA256_HASH_LENGTH) { - throw new ValidationFrostFSException( - String.format(INPUT_PARAM_IS_NOT_SHA256, ObjectId.class.getName()) - ); - } - - this.value = Base58.encode(hash); - } - - @Override - public String toString() { - return value; - } - - public byte[] toHash() { - return Base58.decode(value); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/dto/object/ObjectReader.java b/models/src/main/java/info/frostfs/sdk/dto/object/ObjectReader.java deleted file mode 100644 index 1647c3c..0000000 --- a/models/src/main/java/info/frostfs/sdk/dto/object/ObjectReader.java +++ /dev/null @@ -1,5 +0,0 @@ -package info.frostfs.sdk.dto.object; - -public interface ObjectReader { - byte[] readChunk(); -} diff --git a/models/src/main/java/info/frostfs/sdk/dto/object/OwnerId.java b/models/src/main/java/info/frostfs/sdk/dto/object/OwnerId.java deleted file mode 100644 index 82886e1..0000000 --- a/models/src/main/java/info/frostfs/sdk/dto/object/OwnerId.java +++ /dev/null @@ -1,32 +0,0 @@ -package info.frostfs.sdk.dto.object; - -import info.frostfs.sdk.exceptions.ValidationFrostFSException; -import io.neow3j.crypto.Base58; -import lombok.Getter; -import org.apache.commons.lang3.StringUtils; - -import static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_IS_MISSING_TEMPLATE; - -@Getter -public class OwnerId { - private final String value; - - public OwnerId(String value) { - if (StringUtils.isBlank(value)) { - throw new ValidationFrostFSException( - String.format(INPUT_PARAM_IS_MISSING_TEMPLATE, OwnerId.class.getName()) - ); - } - - this.value = value; - } - - public byte[] toHash() { - return Base58.decode(value); - } - - @Override - public String toString() { - return value; - } -} diff --git a/models/src/main/java/info/frostfs/sdk/dto/object/Split.java b/models/src/main/java/info/frostfs/sdk/dto/object/Split.java deleted file mode 100644 index 7132de3..0000000 --- a/models/src/main/java/info/frostfs/sdk/dto/object/Split.java +++ /dev/null @@ -1,40 +0,0 @@ -package info.frostfs.sdk.dto.object; - -import frostfs.refs.Types; -import info.frostfs.sdk.dto.response.Signature; -import info.frostfs.sdk.exceptions.ValidationFrostFSException; -import lombok.Getter; -import lombok.Setter; - -import java.util.ArrayList; -import java.util.List; - -import static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_IS_MISSING_TEMPLATE; -import static java.util.Objects.isNull; - -@Getter -@Setter -public class Split { - private final List children; - private final SplitId splitId; - private ObjectId parent; - private ObjectId previous; - private Signature parentSignature; - private ObjectHeader parentHeader; - private Types.Signature parentSignatureGrpc; - - public Split() { - this(new SplitId()); - } - - public Split(SplitId splitId) { - if (isNull(splitId)) { - throw new ValidationFrostFSException( - String.format(INPUT_PARAM_IS_MISSING_TEMPLATE, SplitId.class.getName()) - ); - } - - this.splitId = splitId; - this.children = new ArrayList<>(); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/dto/object/SplitId.java b/models/src/main/java/info/frostfs/sdk/dto/object/SplitId.java deleted file mode 100644 index 260d739..0000000 --- a/models/src/main/java/info/frostfs/sdk/dto/object/SplitId.java +++ /dev/null @@ -1,39 +0,0 @@ -package info.frostfs.sdk.dto.object; - -import lombok.Getter; - -import java.util.UUID; - -import static info.frostfs.sdk.UuidExtension.asBytes; -import static info.frostfs.sdk.UuidExtension.asUuid; -import static java.util.Objects.isNull; - -@Getter -public class SplitId { - private final UUID id; - - public SplitId() { - this.id = UUID.randomUUID(); - } - - public SplitId(UUID uuid) { - this.id = uuid; - } - - public SplitId(byte[] binary) { - this.id = asUuid(binary); - } - - public SplitId(String string) { - this.id = UUID.fromString(string); - } - - @Override - public String toString() { - return id.toString(); - } - - public byte[] toBinary() { - return isNull(id) ? null : asBytes(id); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/dto/object/SplitInfo.java b/models/src/main/java/info/frostfs/sdk/dto/object/SplitInfo.java deleted file mode 100644 index cbd9e17..0000000 --- a/models/src/main/java/info/frostfs/sdk/dto/object/SplitInfo.java +++ /dev/null @@ -1,17 +0,0 @@ -package info.frostfs.sdk.dto.object; - -import frostfs.object.Types; -import lombok.AllArgsConstructor; -import lombok.Getter; - -@Getter -@AllArgsConstructor -public class SplitInfo { - private final Types.SplitInfo splitInfo; - - private final SplitId splitId; - - private final ObjectId link; - - private final ObjectId lastPart; -} diff --git a/models/src/main/java/info/frostfs/sdk/dto/object/patch/Address.java b/models/src/main/java/info/frostfs/sdk/dto/object/patch/Address.java deleted file mode 100644 index ae30880..0000000 --- a/models/src/main/java/info/frostfs/sdk/dto/object/patch/Address.java +++ /dev/null @@ -1,13 +0,0 @@ -package info.frostfs.sdk.dto.object.patch; - -import info.frostfs.sdk.dto.container.ContainerId; -import info.frostfs.sdk.dto.object.ObjectId; -import lombok.AllArgsConstructor; -import lombok.Getter; - -@Getter -@AllArgsConstructor -public class Address { - private final ObjectId objectId; - private final ContainerId containerId; -} diff --git a/models/src/main/java/info/frostfs/sdk/dto/object/patch/Range.java b/models/src/main/java/info/frostfs/sdk/dto/object/patch/Range.java deleted file mode 100644 index 67a56aa..0000000 --- a/models/src/main/java/info/frostfs/sdk/dto/object/patch/Range.java +++ /dev/null @@ -1,11 +0,0 @@ -package info.frostfs.sdk.dto.object.patch; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -@Getter -@AllArgsConstructor -public class Range { - private long offset; - private long length; -} diff --git a/models/src/main/java/info/frostfs/sdk/dto/response/MetaHeader.java b/models/src/main/java/info/frostfs/sdk/dto/response/MetaHeader.java deleted file mode 100644 index af1d2ab..0000000 --- a/models/src/main/java/info/frostfs/sdk/dto/response/MetaHeader.java +++ /dev/null @@ -1,61 +0,0 @@ -package info.frostfs.sdk.dto.response; - -import info.frostfs.sdk.dto.netmap.Version; -import info.frostfs.sdk.exceptions.ValidationFrostFSException; -import lombok.Getter; -import lombok.experimental.FieldNameConstants; - -import static info.frostfs.sdk.constants.AppConst.DEFAULT_MAJOR_VERSION; -import static info.frostfs.sdk.constants.AppConst.DEFAULT_MINOR_VERSION; -import static info.frostfs.sdk.constants.ErrorConst.*; -import static java.util.Objects.isNull; - -@Getter -@FieldNameConstants -public class MetaHeader { - private Version version; - private int epoch; - private int ttl; - - public MetaHeader(Version version, int epoch, int ttl) { - setVersion(version); - setEpoch(epoch); - setTtl(ttl); - } - - public MetaHeader() { - this.version = new Version(DEFAULT_MAJOR_VERSION, DEFAULT_MINOR_VERSION); - this.epoch = 0; - this.ttl = 2; - } - - public void setVersion(Version version) { - if (isNull(version)) { - throw new ValidationFrostFSException( - String.format(INPUT_PARAM_IS_MISSING_TEMPLATE, Version.class.getName()) - ); - } - - this.version = version; - } - - public void setEpoch(int epoch) { - if (epoch < 0) { - throw new ValidationFrostFSException( - String.format(INPUT_PARAM_GREATER_OR_EQUAL_ZERO, Fields.epoch) - ); - } - - this.epoch = epoch; - } - - public void setTtl(int ttl) { - if (ttl <= 0) { - throw new ValidationFrostFSException( - String.format(INPUT_PARAM_GREATER_ZERO, Fields.ttl) - ); - } - - this.ttl = ttl; - } -} diff --git a/models/src/main/java/info/frostfs/sdk/dto/response/ResponseStatus.java b/models/src/main/java/info/frostfs/sdk/dto/response/ResponseStatus.java deleted file mode 100644 index 02602f1..0000000 --- a/models/src/main/java/info/frostfs/sdk/dto/response/ResponseStatus.java +++ /dev/null @@ -1,36 +0,0 @@ -package info.frostfs.sdk.dto.response; - -import info.frostfs.sdk.enums.StatusCode; -import lombok.Getter; -import lombok.Setter; -import org.apache.commons.lang3.StringUtils; - -import static info.frostfs.sdk.constants.FieldConst.EMPTY_STRING; - -@Getter -@Setter -public class ResponseStatus { - private StatusCode code; - private String message; - private String details; - - public ResponseStatus(StatusCode code, String message, String details) { - this.code = code; - this.message = StringUtils.isBlank(message) ? EMPTY_STRING : message; - this.details = StringUtils.isBlank(details) ? EMPTY_STRING : details; - } - - public ResponseStatus(StatusCode code) { - this.code = code; - this.message = EMPTY_STRING; - } - - @Override - public String toString() { - return String.format("Response status: %s. Message: %s. Details: %s", code, message, details); - } - - public boolean isSuccess() { - return StatusCode.SUCCESS.equals(code); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/dto/response/Signature.java b/models/src/main/java/info/frostfs/sdk/dto/response/Signature.java deleted file mode 100644 index 2a871a3..0000000 --- a/models/src/main/java/info/frostfs/sdk/dto/response/Signature.java +++ /dev/null @@ -1,13 +0,0 @@ -package info.frostfs.sdk.dto.response; - -import info.frostfs.sdk.enums.SignatureScheme; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -public class Signature { - private byte[] key; - private byte[] sign; - private SignatureScheme scheme; -} diff --git a/models/src/main/java/info/frostfs/sdk/dto/session/SessionToken.java b/models/src/main/java/info/frostfs/sdk/dto/session/SessionToken.java deleted file mode 100644 index eb4e0a3..0000000 --- a/models/src/main/java/info/frostfs/sdk/dto/session/SessionToken.java +++ /dev/null @@ -1,10 +0,0 @@ -package info.frostfs.sdk.dto.session; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -@Getter -@AllArgsConstructor -public class SessionToken { - private final byte[] token; -} diff --git a/models/src/main/java/info/frostfs/sdk/enums/ConditionKindType.java b/models/src/main/java/info/frostfs/sdk/enums/ConditionKindType.java deleted file mode 100644 index 9f1bc0e..0000000 --- a/models/src/main/java/info/frostfs/sdk/enums/ConditionKindType.java +++ /dev/null @@ -1,31 +0,0 @@ -package info.frostfs.sdk.enums; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -public enum ConditionKindType { - RESOURCE(0), - REQUEST(1), - ; - - private static final Map ENUM_MAP_BY_VALUE; - - static { - Map map = new HashMap<>(); - for (ConditionKindType conditionKindType : ConditionKindType.values()) { - map.put(conditionKindType.value, conditionKindType); - } - ENUM_MAP_BY_VALUE = Collections.unmodifiableMap(map); - } - - public final int value; - - ConditionKindType(int value) { - this.value = value; - } - - public static ConditionKindType get(int value) { - return ENUM_MAP_BY_VALUE.get(value); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/enums/ConditionType.java b/models/src/main/java/info/frostfs/sdk/enums/ConditionType.java deleted file mode 100644 index dca427d..0000000 --- a/models/src/main/java/info/frostfs/sdk/enums/ConditionType.java +++ /dev/null @@ -1,54 +0,0 @@ -package info.frostfs.sdk.enums; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -public enum ConditionType { - COND_STRING_EQUALS(0), - COND_STRING_NOT_EQUALS(1), - COND_STRING_EQUALS_IGNORE_CASE(2), - COND_STRING_NOT_EQUALS_IGNORE_CASE(3), - - COND_STRING_LIKE(4), - COND_STRING_NOT_LIKE(5), - - COND_STRING_LESS_THAN(6), - COND_STRING_LESS_THAN_EQUALS(7), - COND_STRING_GREATER_THAN(8), - COND_STRING_GREATER_THAN_EQUALS(9), - - COND_NUMERIC_EQUALS(10), - COND_NUMERIC_NOT_EQUALS(11), - - COND_NUMERIC_LESS_THAN(12), - COND_NUMERIC_LESS_THAN_EQUALS(13), - COND_NUMERIC_GREATER_THAN(14), - COND_NUMERIC_GREATER_THAN_EQUALS(15), - - COND_SLICE_CONTAINS(16), - - COND_IP_ADDRESS(17), - COND_NOT_IP_ADDRESS(18), - ; - - private static final Map ENUM_MAP_BY_VALUE; - - static { - Map map = new HashMap<>(); - for (ConditionType conditionType : ConditionType.values()) { - map.put(conditionType.value, conditionType); - } - ENUM_MAP_BY_VALUE = Collections.unmodifiableMap(map); - } - - public final int value; - - ConditionType(int value) { - this.value = value; - } - - public static ConditionType get(int value) { - return ENUM_MAP_BY_VALUE.get(value); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/enums/ObjectMatchType.java b/models/src/main/java/info/frostfs/sdk/enums/ObjectMatchType.java deleted file mode 100644 index 2122ad6..0000000 --- a/models/src/main/java/info/frostfs/sdk/enums/ObjectMatchType.java +++ /dev/null @@ -1,16 +0,0 @@ -package info.frostfs.sdk.enums; - -public enum ObjectMatchType { - UNSPECIFIED(0), - EQUALS(1), - NOT_EQUALS(2), - KEY_ABSENT(3), - STARTS_WITH(4), - ; - - public final int value; - - ObjectMatchType(int value) { - this.value = value; - } -} diff --git a/models/src/main/java/info/frostfs/sdk/enums/ObjectType.java b/models/src/main/java/info/frostfs/sdk/enums/ObjectType.java deleted file mode 100644 index d252a7a..0000000 --- a/models/src/main/java/info/frostfs/sdk/enums/ObjectType.java +++ /dev/null @@ -1,32 +0,0 @@ -package info.frostfs.sdk.enums; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -public enum ObjectType { - REGULAR(0), - TOMBSTONE(1), - LOCK(3), - ; - - private static final Map ENUM_MAP_BY_VALUE; - - static { - Map map = new HashMap<>(); - for (ObjectType objectType : ObjectType.values()) { - map.put(objectType.value, objectType); - } - ENUM_MAP_BY_VALUE = Collections.unmodifiableMap(map); - } - - public final int value; - - ObjectType(int value) { - this.value = value; - } - - public static ObjectType get(int value) { - return ENUM_MAP_BY_VALUE.get(value); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/enums/RuleMatchType.java b/models/src/main/java/info/frostfs/sdk/enums/RuleMatchType.java deleted file mode 100644 index 6bbbe82..0000000 --- a/models/src/main/java/info/frostfs/sdk/enums/RuleMatchType.java +++ /dev/null @@ -1,34 +0,0 @@ -package info.frostfs.sdk.enums; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -public enum RuleMatchType { - // DENY_PRIORITY rejects the request if any `Deny` is specified. - DENY_PRIORITY(0), - - // FIRST_MATCH returns the first rule action matched to the request. - FIRST_MATCH(1), - ; - - private static final Map ENUM_MAP_BY_VALUE; - - static { - Map map = new HashMap<>(); - for (RuleMatchType ruleMatchType : RuleMatchType.values()) { - map.put(ruleMatchType.value, ruleMatchType); - } - ENUM_MAP_BY_VALUE = Collections.unmodifiableMap(map); - } - - public final int value; - - RuleMatchType(int value) { - this.value = value; - } - - public static RuleMatchType get(int value) { - return ENUM_MAP_BY_VALUE.get(value); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/enums/RuleStatus.java b/models/src/main/java/info/frostfs/sdk/enums/RuleStatus.java deleted file mode 100644 index 45289d0..0000000 --- a/models/src/main/java/info/frostfs/sdk/enums/RuleStatus.java +++ /dev/null @@ -1,33 +0,0 @@ -package info.frostfs.sdk.enums; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -public enum RuleStatus { - ALLOW(0), - NO_RULE_FOUND(1), - ACCESS_DENIED(2), - QUOTA_LIMIT_REACHED(3), - ; - - private static final Map ENUM_MAP_BY_VALUE; - - static { - Map map = new HashMap<>(); - for (RuleStatus ruleStatus : RuleStatus.values()) { - map.put(ruleStatus.value, ruleStatus); - } - ENUM_MAP_BY_VALUE = Collections.unmodifiableMap(map); - } - - public final int value; - - RuleStatus(int value) { - this.value = value; - } - - public static RuleStatus get(int value) { - return ENUM_MAP_BY_VALUE.get(value); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/enums/SignatureScheme.java b/models/src/main/java/info/frostfs/sdk/enums/SignatureScheme.java deleted file mode 100644 index 7bb7511..0000000 --- a/models/src/main/java/info/frostfs/sdk/enums/SignatureScheme.java +++ /dev/null @@ -1,14 +0,0 @@ -package info.frostfs.sdk.enums; - -public enum SignatureScheme { - ECDSA_SHA512(0), - ECDSA_RFC6979_SHA256(1), - ECDSA_RFC6979_SHA256_WALLET_CONNECT(2), - ; - - public final int value; - - SignatureScheme(int value) { - this.value = value; - } -} diff --git a/models/src/main/java/info/frostfs/sdk/enums/StatusCode.java b/models/src/main/java/info/frostfs/sdk/enums/StatusCode.java deleted file mode 100644 index b67e766..0000000 --- a/models/src/main/java/info/frostfs/sdk/enums/StatusCode.java +++ /dev/null @@ -1,46 +0,0 @@ -package info.frostfs.sdk.enums; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -public enum StatusCode { - SUCCESS(0), - INTERNAL(1024), - WRONG_MAGIC_NUMBER(1025), - SIGNATURE_VERIFICATION_FAILURE(1026), - NODE_UNDER_MAINTENANCE(1027), - OBJECT_ACCESS_DENIED(2048), - OBJECT_NOT_FOUND(2049), - OBJECT_LOCKED(2050), - LOCK_NOT_REGULAR_OBJECT(2051), - OBJECT_ALREADY_REMOVED(2052), - OUT_OF_RANGE(2053), - CONTAINER_NOT_FOUND(3072), - E_ACL_NOT_FOUND(3073), - CONTAINER_ACCESS_DENIED(3074), - TOKEN_NOT_FOUND(4096), - TOKEN_EXPIRED(4097), - APE_MANAGER_ACCESS_DENIED(5120), - ; - - private static final Map ENUM_MAP_BY_VALUE; - - static { - Map map = new HashMap<>(); - for (StatusCode statusCode : StatusCode.values()) { - map.put(statusCode.value, statusCode); - } - ENUM_MAP_BY_VALUE = Collections.unmodifiableMap(map); - } - - public final int value; - - StatusCode(int value) { - this.value = value; - } - - public static StatusCode get(int value) { - return ENUM_MAP_BY_VALUE.get(value); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/enums/TargetType.java b/models/src/main/java/info/frostfs/sdk/enums/TargetType.java deleted file mode 100644 index d9abde0..0000000 --- a/models/src/main/java/info/frostfs/sdk/enums/TargetType.java +++ /dev/null @@ -1,34 +0,0 @@ -package info.frostfs.sdk.enums; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -public enum TargetType { - UNDEFINED(0), - NAMESPACE(1), - CONTAINER(2), - USER(3), - GROUP(4), - ; - - private static final Map ENUM_MAP_BY_VALUE; - - static { - Map map = new HashMap<>(); - for (TargetType targetType : TargetType.values()) { - map.put(targetType.value, targetType); - } - ENUM_MAP_BY_VALUE = Collections.unmodifiableMap(map); - } - - public final int value; - - TargetType(int value) { - this.value = value; - } - - public static TargetType get(int value) { - return ENUM_MAP_BY_VALUE.get(value); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/enums/netmap/FilterOperation.java b/models/src/main/java/info/frostfs/sdk/enums/netmap/FilterOperation.java deleted file mode 100644 index 69513c8..0000000 --- a/models/src/main/java/info/frostfs/sdk/enums/netmap/FilterOperation.java +++ /dev/null @@ -1,40 +0,0 @@ -package info.frostfs.sdk.enums.netmap; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -public enum FilterOperation { - OPERATION_UNSPECIFIED(0), - EQ(1), - NE(2), - GT(3), - GE(4), - LT(5), - LE(6), - OR(7), - AND(8), - NOT(9), - LIKE(10), - ; - - private static final Map ENUM_MAP_BY_VALUE; - - static { - Map map = new HashMap<>(); - for (FilterOperation nodeState : FilterOperation.values()) { - map.put(nodeState.value, nodeState); - } - ENUM_MAP_BY_VALUE = Collections.unmodifiableMap(map); - } - - public final int value; - - FilterOperation(int value) { - this.value = value; - } - - public static FilterOperation get(int value) { - return ENUM_MAP_BY_VALUE.get(value); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/enums/netmap/NodeState.java b/models/src/main/java/info/frostfs/sdk/enums/netmap/NodeState.java deleted file mode 100644 index ac6ae78..0000000 --- a/models/src/main/java/info/frostfs/sdk/enums/netmap/NodeState.java +++ /dev/null @@ -1,33 +0,0 @@ -package info.frostfs.sdk.enums.netmap; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -public enum NodeState { - UNSPECIFIED(0), - ONLINE(1), - OFFLINE(2), - MAINTENANCE(3), - ; - - private static final Map ENUM_MAP_BY_VALUE; - - static { - Map map = new HashMap<>(); - for (NodeState nodeState : NodeState.values()) { - map.put(nodeState.value, nodeState); - } - ENUM_MAP_BY_VALUE = Collections.unmodifiableMap(map); - } - - public final int value; - - NodeState(int value) { - this.value = value; - } - - public static NodeState get(int value) { - return ENUM_MAP_BY_VALUE.get(value); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/enums/netmap/SelectorClause.java b/models/src/main/java/info/frostfs/sdk/enums/netmap/SelectorClause.java deleted file mode 100644 index f375f88..0000000 --- a/models/src/main/java/info/frostfs/sdk/enums/netmap/SelectorClause.java +++ /dev/null @@ -1,32 +0,0 @@ -package info.frostfs.sdk.enums.netmap; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -public enum SelectorClause { - CLAUSE_UNSPECIFIED(0), - SAME(1), - DISTINCT(2), - ; - - private static final Map ENUM_MAP_BY_VALUE; - - static { - Map map = new HashMap<>(); - for (SelectorClause nodeState : SelectorClause.values()) { - map.put(nodeState.value, nodeState); - } - ENUM_MAP_BY_VALUE = Collections.unmodifiableMap(map); - } - - public final int value; - - SelectorClause(int value) { - this.value = value; - } - - public static SelectorClause get(int value) { - return ENUM_MAP_BY_VALUE.get(value); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/mappers/chain/ChainTargetMapper.java b/models/src/main/java/info/frostfs/sdk/mappers/chain/ChainTargetMapper.java deleted file mode 100644 index 0751060..0000000 --- a/models/src/main/java/info/frostfs/sdk/mappers/chain/ChainTargetMapper.java +++ /dev/null @@ -1,33 +0,0 @@ -package info.frostfs.sdk.mappers.chain; - -import frostfs.ape.Types; -import info.frostfs.sdk.dto.chain.ChainTarget; -import info.frostfs.sdk.exceptions.ProcessFrostFSException; - -import static info.frostfs.sdk.constants.ErrorConst.UNKNOWN_ENUM_VALUE_TEMPLATE; -import static java.util.Objects.isNull; - -public class ChainTargetMapper { - private ChainTargetMapper() { - } - - public static Types.ChainTarget toGrpcMessage(ChainTarget chainTarget) { - if (isNull(chainTarget)) { - return null; - } - - var targetType = Types.TargetType.forNumber(chainTarget.getType().value); - if (isNull(targetType)) { - throw new ProcessFrostFSException(String.format( - UNKNOWN_ENUM_VALUE_TEMPLATE, - Types.ChainTarget.class.getName(), - chainTarget.getType().name() - )); - } - - return Types.ChainTarget.newBuilder() - .setType(targetType) - .setName(chainTarget.getName()) - .build(); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/mappers/container/ContainerIdMapper.java b/models/src/main/java/info/frostfs/sdk/mappers/container/ContainerIdMapper.java deleted file mode 100644 index 4daf0fc..0000000 --- a/models/src/main/java/info/frostfs/sdk/mappers/container/ContainerIdMapper.java +++ /dev/null @@ -1,22 +0,0 @@ -package info.frostfs.sdk.mappers.container; - -import com.google.protobuf.ByteString; -import frostfs.refs.Types; -import info.frostfs.sdk.dto.container.ContainerId; - -import static java.util.Objects.isNull; - -public class ContainerIdMapper { - private ContainerIdMapper() { - } - - public static Types.ContainerID toGrpcMessage(ContainerId containerId) { - if (isNull(containerId)) { - return null; - } - - return Types.ContainerID.newBuilder() - .setValue(ByteString.copyFrom(containerId.toHash())) - .build(); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/mappers/container/ContainerMapper.java b/models/src/main/java/info/frostfs/sdk/mappers/container/ContainerMapper.java deleted file mode 100644 index 0c96e32..0000000 --- a/models/src/main/java/info/frostfs/sdk/mappers/container/ContainerMapper.java +++ /dev/null @@ -1,62 +0,0 @@ -package info.frostfs.sdk.mappers.container; - -import com.google.protobuf.ByteString; -import frostfs.container.Types; -import info.frostfs.sdk.dto.container.Container; -import info.frostfs.sdk.mappers.netmap.PlacementPolicyMapper; -import info.frostfs.sdk.mappers.netmap.VersionMapper; -import info.frostfs.sdk.mappers.object.OwnerIdMapper; - -import java.util.Optional; -import java.util.stream.Collectors; - -import static info.frostfs.sdk.UuidExtension.asBytes; -import static info.frostfs.sdk.UuidExtension.asUuid; -import static java.util.Objects.isNull; - -public class ContainerMapper { - private ContainerMapper() { - } - - public static Types.Container.Builder toGrpcMessage(Container container) { - if (isNull(container)) { - return null; - } - - var attributes = container.getAttributes().entrySet().stream() - .map(entry -> - Types.Container.Attribute.newBuilder() - .setKey(entry.getKey()) - .setValue(entry.getValue()) - .build() - ) - .collect(Collectors.toList()); - - var containerGrpc = Types.Container.newBuilder() - .setPlacementPolicy(PlacementPolicyMapper.toGrpcMessage(container.getPlacementPolicy())) - .setNonce(ByteString.copyFrom(asBytes(container.getNonce()))) - .addAllAttributes(attributes); - - Optional.ofNullable(OwnerIdMapper.toGrpcMessage(container.getOwnerId())).ifPresent(containerGrpc::setOwnerId); - Optional.ofNullable(VersionMapper.toGrpcMessage(container.getVersion())).ifPresent(containerGrpc::setVersion); - - return containerGrpc; - } - - public static Container toModel(Types.Container containerGrpc) { - if (isNull(containerGrpc) || containerGrpc.getSerializedSize() == 0) { - return null; - } - - var attributes = containerGrpc.getAttributesList().stream() - .collect(Collectors.toMap(Types.Container.Attribute::getKey, Types.Container.Attribute::getValue)); - - return new Container( - asUuid(containerGrpc.getNonce().toByteArray()), - PlacementPolicyMapper.toModel(containerGrpc.getPlacementPolicy()), - VersionMapper.toModel(containerGrpc.getVersion()), - OwnerIdMapper.toModel(containerGrpc.getOwnerId()), - attributes - ); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/mappers/netmap/FilterMapper.java b/models/src/main/java/info/frostfs/sdk/mappers/netmap/FilterMapper.java deleted file mode 100644 index 529b26d..0000000 --- a/models/src/main/java/info/frostfs/sdk/mappers/netmap/FilterMapper.java +++ /dev/null @@ -1,85 +0,0 @@ -package info.frostfs.sdk.mappers.netmap; - -import frostfs.netmap.Types; -import info.frostfs.sdk.dto.netmap.Filter; -import info.frostfs.sdk.enums.netmap.FilterOperation; -import info.frostfs.sdk.exceptions.ProcessFrostFSException; -import info.frostfs.sdk.exceptions.ValidationFrostFSException; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.ArrayUtils; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; - -import static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_IS_MISSING_TEMPLATE; -import static info.frostfs.sdk.constants.ErrorConst.UNKNOWN_ENUM_VALUE_TEMPLATE; -import static java.util.Objects.isNull; - -public class FilterMapper { - private FilterMapper() { - } - - public static List toGrpcMessages(Filter[] filters) { - if (ArrayUtils.isEmpty(filters)) { - return Collections.emptyList(); - } - - return Arrays.stream(filters).map(FilterMapper::toGrpcMessage).collect(Collectors.toList()); - } - - public static Types.Filter toGrpcMessage(Filter filter) { - if (isNull(filter)) { - throw new ValidationFrostFSException( - String.format(INPUT_PARAM_IS_MISSING_TEMPLATE, Filter.class.getName()) - ); - } - - var operation = Types.Operation.forNumber(filter.getOperation().value); - if (isNull(operation)) { - throw new ProcessFrostFSException(String.format( - UNKNOWN_ENUM_VALUE_TEMPLATE, - Types.Operation.class.getName(), - filter.getOperation().name() - )); - } - - return Types.Filter.newBuilder() - .setName(filter.getName()) - .setKey(filter.getKey()) - .setOp(operation) - .setValue(filter.getValue()) - .addAllFilters(toGrpcMessages(filter.getFilters())) - .build(); - } - - public static Filter[] toModels(List filters) { - if (CollectionUtils.isEmpty(filters)) { - return null; - } - - return filters.stream().map(FilterMapper::toModel).toArray(Filter[]::new); - } - - public static Filter toModel(Types.Filter filter) { - if (isNull(filter) || filter.getSerializedSize() == 0) { - return null; - } - - var operation = FilterOperation.get(filter.getOpValue()); - if (isNull(operation)) { - throw new ProcessFrostFSException( - String.format(UNKNOWN_ENUM_VALUE_TEMPLATE, FilterOperation.class.getName(), filter.getOp()) - ); - } - - return new Filter( - filter.getName(), - filter.getKey(), - operation, - filter.getValue(), - toModels(filter.getFiltersList()) - ); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/mappers/netmap/NetmapSnapshotMapper.java b/models/src/main/java/info/frostfs/sdk/mappers/netmap/NetmapSnapshotMapper.java deleted file mode 100644 index 7cad56b..0000000 --- a/models/src/main/java/info/frostfs/sdk/mappers/netmap/NetmapSnapshotMapper.java +++ /dev/null @@ -1,26 +0,0 @@ -package info.frostfs.sdk.mappers.netmap; - -import frostfs.netmap.Service; -import info.frostfs.sdk.dto.netmap.NetmapSnapshot; - -import java.util.stream.Collectors; - -import static java.util.Objects.isNull; - -public class NetmapSnapshotMapper { - private NetmapSnapshotMapper() { - } - - public static NetmapSnapshot toModel(Service.NetmapSnapshotResponse netmap) { - if (isNull(netmap) || netmap.getSerializedSize() == 0) { - return null; - } - - return new NetmapSnapshot( - netmap.getBody().getNetmap().getEpoch(), - netmap.getBody().getNetmap().getNodesList().stream() - .map(node -> NodeInfoMapper.toModel(node, netmap.getMetaHeader().getVersion())) - .collect(Collectors.toList()) - ); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/mappers/netmap/NodeInfoMapper.java b/models/src/main/java/info/frostfs/sdk/mappers/netmap/NodeInfoMapper.java deleted file mode 100644 index c28cd35..0000000 --- a/models/src/main/java/info/frostfs/sdk/mappers/netmap/NodeInfoMapper.java +++ /dev/null @@ -1,47 +0,0 @@ -package info.frostfs.sdk.mappers.netmap; - -import frostfs.netmap.Service; -import frostfs.netmap.Types; -import frostfs.netmap.Types.NodeInfo.Attribute; -import info.frostfs.sdk.dto.netmap.NodeInfo; -import info.frostfs.sdk.enums.netmap.NodeState; -import info.frostfs.sdk.exceptions.ProcessFrostFSException; - -import java.util.stream.Collectors; - -import static info.frostfs.sdk.constants.ErrorConst.UNKNOWN_ENUM_VALUE_TEMPLATE; -import static java.util.Objects.isNull; - -public class NodeInfoMapper { - private NodeInfoMapper() { - } - - public static NodeInfo toModel(Service.LocalNodeInfoResponse.Body nodeInfo) { - if (isNull(nodeInfo) || nodeInfo.getSerializedSize() == 0) { - return null; - } - - return toModel(nodeInfo.getNodeInfo(), nodeInfo.getVersion()); - } - - public static NodeInfo toModel(Types.NodeInfo nodeInfo, frostfs.refs.Types.Version version) { - if (isNull(nodeInfo) || nodeInfo.getSerializedSize() == 0) { - return null; - } - - NodeState nodeState = NodeState.get(nodeInfo.getState().getNumber()); - if (isNull(nodeState)) { - throw new ProcessFrostFSException( - String.format(UNKNOWN_ENUM_VALUE_TEMPLATE, NodeState.class.getName(), nodeInfo.getState()) - ); - } - - return new NodeInfo( - nodeState, - VersionMapper.toModel(version), - nodeInfo.getAddressesList(), - nodeInfo.getAttributesList().stream().collect(Collectors.toMap(Attribute::getKey, Attribute::getValue)), - nodeInfo.getPublicKey().toByteArray() - ); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/mappers/netmap/PlacementPolicyMapper.java b/models/src/main/java/info/frostfs/sdk/mappers/netmap/PlacementPolicyMapper.java deleted file mode 100644 index 03cdc5f..0000000 --- a/models/src/main/java/info/frostfs/sdk/mappers/netmap/PlacementPolicyMapper.java +++ /dev/null @@ -1,39 +0,0 @@ -package info.frostfs.sdk.mappers.netmap; - -import frostfs.netmap.Types; -import info.frostfs.sdk.dto.netmap.PlacementPolicy; - -import static java.util.Objects.isNull; - -public class PlacementPolicyMapper { - private PlacementPolicyMapper() { - } - - public static Types.PlacementPolicy toGrpcMessage(PlacementPolicy placementPolicy) { - if (isNull(placementPolicy)) { - return null; - } - - return Types.PlacementPolicy.newBuilder() - .setUnique(placementPolicy.isUnique()) - .setContainerBackupFactor(placementPolicy.getBackupFactory()) - .addAllFilters(FilterMapper.toGrpcMessages(placementPolicy.getFilters())) - .addAllSelectors(SelectorMapper.toGrpcMessages(placementPolicy.getSelectors())) - .addAllReplicas(ReplicaMapper.toGrpcMessages(placementPolicy.getReplicas())) - .build(); - } - - public static PlacementPolicy toModel(Types.PlacementPolicy placementPolicy) { - if (isNull(placementPolicy) || placementPolicy.getSerializedSize() == 0) { - return null; - } - - return new PlacementPolicy( - ReplicaMapper.toModels(placementPolicy.getReplicasList()), - placementPolicy.getUnique(), - placementPolicy.getContainerBackupFactor(), - FilterMapper.toModels(placementPolicy.getFiltersList()), - SelectorMapper.toModels(placementPolicy.getSelectorsList()) - ); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/mappers/netmap/ReplicaMapper.java b/models/src/main/java/info/frostfs/sdk/mappers/netmap/ReplicaMapper.java deleted file mode 100644 index 3ac0105..0000000 --- a/models/src/main/java/info/frostfs/sdk/mappers/netmap/ReplicaMapper.java +++ /dev/null @@ -1,64 +0,0 @@ -package info.frostfs.sdk.mappers.netmap; - -import frostfs.netmap.Types; -import info.frostfs.sdk.dto.netmap.Replica; -import info.frostfs.sdk.exceptions.ValidationFrostFSException; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.ArrayUtils; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; - -import static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_IS_MISSING_TEMPLATE; -import static java.util.Objects.isNull; - -public class ReplicaMapper { - private ReplicaMapper() { - } - - public static List toGrpcMessages(Replica[] replicas) { - if (ArrayUtils.isEmpty(replicas)) { - return Collections.emptyList(); - } - - return Arrays.stream(replicas).map(ReplicaMapper::toGrpcMessage).collect(Collectors.toList()); - } - - public static Types.Replica toGrpcMessage(Replica replica) { - if (isNull(replica)) { - throw new ValidationFrostFSException( - String.format(INPUT_PARAM_IS_MISSING_TEMPLATE, Replica.class.getName()) - ); - } - - return Types.Replica.newBuilder() - .setCount(replica.getCount()) - .setSelector(replica.getSelector()) - .setEcDataCount((int) replica.getEcDataCount()) - .setEcParityCount((int) replica.getEcParityCount()) - .build(); - } - - public static Replica[] toModels(List replicas) { - if (CollectionUtils.isEmpty(replicas)) { - return null; - } - - return replicas.stream().map(ReplicaMapper::toModel).toArray(Replica[]::new); - } - - public static Replica toModel(Types.Replica replica) { - if (isNull(replica) || replica.getSerializedSize() == 0) { - return null; - } - - return new Replica( - replica.getCount(), - replica.getSelector(), - replica.getEcDataCount(), - replica.getEcParityCount() - ); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/mappers/netmap/SelectorMapper.java b/models/src/main/java/info/frostfs/sdk/mappers/netmap/SelectorMapper.java deleted file mode 100644 index 462519a..0000000 --- a/models/src/main/java/info/frostfs/sdk/mappers/netmap/SelectorMapper.java +++ /dev/null @@ -1,85 +0,0 @@ -package info.frostfs.sdk.mappers.netmap; - -import frostfs.netmap.Types; -import info.frostfs.sdk.dto.netmap.Selector; -import info.frostfs.sdk.enums.netmap.SelectorClause; -import info.frostfs.sdk.exceptions.ProcessFrostFSException; -import info.frostfs.sdk.exceptions.ValidationFrostFSException; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.ArrayUtils; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; - -import static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_IS_MISSING_TEMPLATE; -import static info.frostfs.sdk.constants.ErrorConst.UNKNOWN_ENUM_VALUE_TEMPLATE; -import static java.util.Objects.isNull; - -public class SelectorMapper { - private SelectorMapper() { - } - - public static List toGrpcMessages(Selector[] selectors) { - if (ArrayUtils.isEmpty(selectors)) { - return Collections.emptyList(); - } - - return Arrays.stream(selectors).map(SelectorMapper::toGrpcMessage).collect(Collectors.toList()); - } - - public static Types.Selector toGrpcMessage(Selector selector) { - if (isNull(selector)) { - throw new ValidationFrostFSException( - String.format(INPUT_PARAM_IS_MISSING_TEMPLATE, Selector.class.getName()) - ); - } - - var clause = Types.Clause.forNumber(selector.getClause().value); - if (isNull(clause)) { - throw new ProcessFrostFSException(String.format( - UNKNOWN_ENUM_VALUE_TEMPLATE, - Types.Clause.class.getName(), - selector.getClause().name() - )); - } - - return Types.Selector.newBuilder() - .setName(selector.getName()) - .setCount(selector.getCount()) - .setClause(clause) - .setAttribute(selector.getAttribute()) - .setFilter(selector.getFilter()) - .build(); - } - - public static Selector[] toModels(List selectors) { - if (CollectionUtils.isEmpty(selectors)) { - return null; - } - - return selectors.stream().map(SelectorMapper::toModel).toArray(Selector[]::new); - } - - public static Selector toModel(Types.Selector selector) { - if (isNull(selector) || selector.getSerializedSize() == 0) { - return null; - } - - var clause = SelectorClause.get(selector.getClauseValue()); - if (isNull(clause)) { - throw new ProcessFrostFSException( - String.format(UNKNOWN_ENUM_VALUE_TEMPLATE, SelectorClause.class.getName(), selector.getClause()) - ); - } - - return new Selector( - selector.getName(), - selector.getCount(), - clause, - selector.getAttribute(), - selector.getFilter() - ); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/mappers/netmap/VersionMapper.java b/models/src/main/java/info/frostfs/sdk/mappers/netmap/VersionMapper.java deleted file mode 100644 index ecfdd57..0000000 --- a/models/src/main/java/info/frostfs/sdk/mappers/netmap/VersionMapper.java +++ /dev/null @@ -1,30 +0,0 @@ -package info.frostfs.sdk.mappers.netmap; - -import frostfs.refs.Types; -import info.frostfs.sdk.dto.netmap.Version; - -import static java.util.Objects.isNull; - -public class VersionMapper { - private VersionMapper() { - } - - public static Types.Version toGrpcMessage(Version version) { - if (isNull(version)) { - return null; - } - - return Types.Version.newBuilder() - .setMajor(version.getMajor()) - .setMinor(version.getMinor()) - .build(); - } - - public static Version toModel(Types.Version version) { - if (isNull(version) || version.getSerializedSize() == 0) { - return null; - } - - return new Version(version.getMajor(), version.getMinor()); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/mappers/object/ObjectAttributeMapper.java b/models/src/main/java/info/frostfs/sdk/mappers/object/ObjectAttributeMapper.java deleted file mode 100644 index c0c55a6..0000000 --- a/models/src/main/java/info/frostfs/sdk/mappers/object/ObjectAttributeMapper.java +++ /dev/null @@ -1,43 +0,0 @@ -package info.frostfs.sdk.mappers.object; - -import frostfs.object.Types; -import info.frostfs.sdk.dto.object.ObjectAttribute; -import org.apache.commons.collections4.CollectionUtils; - -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; - -import static java.util.Objects.isNull; - -public class ObjectAttributeMapper { - private ObjectAttributeMapper() { - } - - public static List toGrpcMessages(List attributes) { - if (CollectionUtils.isEmpty(attributes)) { - return Collections.emptyList(); - } - - return attributes.stream().map(ObjectAttributeMapper::toGrpcMessage).collect(Collectors.toList()); - } - - public static Types.Header.Attribute toGrpcMessage(ObjectAttribute attribute) { - if (isNull(attribute)) { - return null; - } - - return Types.Header.Attribute.newBuilder() - .setKey(attribute.getKey()) - .setValue(attribute.getValue()) - .build(); - } - - public static ObjectAttribute toModel(Types.Header.Attribute attribute) { - if (isNull(attribute) || attribute.getSerializedSize() == 0) { - return null; - } - - return new ObjectAttribute(attribute.getKey(), attribute.getValue()); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/mappers/object/ObjectFilterMapper.java b/models/src/main/java/info/frostfs/sdk/mappers/object/ObjectFilterMapper.java deleted file mode 100644 index a9f2c7d..0000000 --- a/models/src/main/java/info/frostfs/sdk/mappers/object/ObjectFilterMapper.java +++ /dev/null @@ -1,35 +0,0 @@ -package info.frostfs.sdk.mappers.object; - -import frostfs.object.Service; -import frostfs.object.Types; -import info.frostfs.sdk.dto.object.ObjectFilter; -import info.frostfs.sdk.exceptions.ProcessFrostFSException; - -import static info.frostfs.sdk.constants.ErrorConst.UNKNOWN_ENUM_VALUE_TEMPLATE; -import static java.util.Objects.isNull; - -public class ObjectFilterMapper { - private ObjectFilterMapper() { - } - - public static Service.SearchRequest.Body.Filter toGrpcMessage(ObjectFilter filter) { - if (isNull(filter)) { - return null; - } - - var objectMatchType = Types.MatchType.forNumber(filter.getMatchType().value); - if (isNull(objectMatchType)) { - throw new ProcessFrostFSException(String.format( - UNKNOWN_ENUM_VALUE_TEMPLATE, - Types.MatchType.class.getName(), - filter.getMatchType().name() - )); - } - - return Service.SearchRequest.Body.Filter.newBuilder() - .setMatchType(objectMatchType) - .setKey(filter.getKey()) - .setValue(filter.getSerializedValue()) - .build(); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/mappers/object/ObjectFrostFSMapper.java b/models/src/main/java/info/frostfs/sdk/mappers/object/ObjectFrostFSMapper.java deleted file mode 100644 index 2427a7b..0000000 --- a/models/src/main/java/info/frostfs/sdk/mappers/object/ObjectFrostFSMapper.java +++ /dev/null @@ -1,24 +0,0 @@ -package info.frostfs.sdk.mappers.object; - -import frostfs.object.Types; -import info.frostfs.sdk.dto.object.ObjectFrostFS; -import info.frostfs.sdk.dto.object.ObjectId; - -import static java.util.Objects.isNull; - -public class ObjectFrostFSMapper { - private ObjectFrostFSMapper() { - } - - public static ObjectFrostFS toModel(Types.Object object) { - if (isNull(object) || object.getSerializedSize() == 0) { - return null; - } - - return new ObjectFrostFS( - ObjectHeaderMapper.toModel(object.getHeader()), - new ObjectId(object.getObjectId().getValue().toByteArray()), - object.getPayload().toByteArray() - ); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/mappers/object/ObjectHeaderMapper.java b/models/src/main/java/info/frostfs/sdk/mappers/object/ObjectHeaderMapper.java deleted file mode 100644 index 2deeef6..0000000 --- a/models/src/main/java/info/frostfs/sdk/mappers/object/ObjectHeaderMapper.java +++ /dev/null @@ -1,85 +0,0 @@ -package info.frostfs.sdk.mappers.object; - -import com.google.protobuf.ByteString; -import frostfs.object.Types; -import info.frostfs.sdk.dto.container.ContainerId; -import info.frostfs.sdk.dto.object.ObjectAttribute; -import info.frostfs.sdk.dto.object.ObjectHeader; -import info.frostfs.sdk.enums.ObjectType; -import info.frostfs.sdk.exceptions.ProcessFrostFSException; -import info.frostfs.sdk.exceptions.ValidationFrostFSException; -import info.frostfs.sdk.mappers.container.ContainerIdMapper; -import info.frostfs.sdk.mappers.netmap.VersionMapper; -import org.apache.commons.collections4.ListUtils; - -import java.util.stream.Collectors; - -import static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_IS_MISSING_TEMPLATE; -import static info.frostfs.sdk.constants.ErrorConst.UNKNOWN_ENUM_VALUE_TEMPLATE; -import static java.util.Objects.isNull; -import static java.util.Objects.nonNull; - -public class ObjectHeaderMapper { - private ObjectHeaderMapper() { - } - - public static Types.Header toGrpcMessage(ObjectHeader header) { - if (isNull(header)) { - throw new ValidationFrostFSException( - String.format(INPUT_PARAM_IS_MISSING_TEMPLATE, ObjectHeader.class.getName()) - ); - } - - var objectType = Types.ObjectType.forNumber(header.getObjectType().value); - if (isNull(objectType)) { - throw new ProcessFrostFSException(String.format( - UNKNOWN_ENUM_VALUE_TEMPLATE, - Types.ObjectType.class.getName(), - header.getObjectType().name() - )); - } - - var head = Types.Header.newBuilder() - .setOwnerId(OwnerIdMapper.toGrpcMessage(header.getOwnerId())) - .setVersion(VersionMapper.toGrpcMessage(header.getVersion())) - .setContainerId(ContainerIdMapper.toGrpcMessage(header.getContainerId())) - .setObjectType(objectType) - .setPayloadLength(header.getPayloadLength()); - - for (ObjectAttribute objectAttribute : header.getAttributes()) { - head.addAttributes(ObjectAttributeMapper.toGrpcMessage(objectAttribute)); - } - - if (nonNull(header.getSplit())) { - var grpcSplit = Types.Header.Split.newBuilder() - .setSplitId(ByteString.copyFrom(header.getSplit().getSplitId().toBinary())) - .build(); - head.setSplit(grpcSplit); - } - - return head.build(); - } - - public static ObjectHeader toModel(Types.Header header) { - if (isNull(header) || header.getSerializedSize() == 0) { - return null; - } - - var objectType = ObjectType.get(header.getObjectTypeValue()); - if (isNull(objectType)) { - throw new ProcessFrostFSException( - String.format(UNKNOWN_ENUM_VALUE_TEMPLATE, ObjectType.class.getName(), header.getObjectType()) - ); - } - - return new ObjectHeader( - new ContainerId(header.getContainerId().getValue().toByteArray()), - objectType, - ListUtils.emptyIfNull(header.getAttributesList()).stream() - .map(ObjectAttributeMapper::toModel) - .collect(Collectors.toList()), - header.getPayloadLength(), - VersionMapper.toModel(header.getVersion()) - ); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/mappers/object/ObjectIdMapper.java b/models/src/main/java/info/frostfs/sdk/mappers/object/ObjectIdMapper.java deleted file mode 100644 index e095244..0000000 --- a/models/src/main/java/info/frostfs/sdk/mappers/object/ObjectIdMapper.java +++ /dev/null @@ -1,30 +0,0 @@ -package info.frostfs.sdk.mappers.object; - -import com.google.protobuf.ByteString; -import frostfs.refs.Types; -import info.frostfs.sdk.dto.object.ObjectId; - -import static java.util.Objects.isNull; - -public class ObjectIdMapper { - private ObjectIdMapper() { - } - - public static Types.ObjectID toGrpcMessage(ObjectId objectId) { - if (isNull(objectId)) { - return null; - } - - return Types.ObjectID.newBuilder() - .setValue(ByteString.copyFrom(objectId.toHash())) - .build(); - } - - public static ObjectId toModel(Types.ObjectID objectId) { - if (isNull(objectId) || objectId.getSerializedSize() == 0) { - return null; - } - - return new ObjectId(objectId.getValue().toByteArray()); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/mappers/object/OwnerIdMapper.java b/models/src/main/java/info/frostfs/sdk/mappers/object/OwnerIdMapper.java deleted file mode 100644 index 535905f..0000000 --- a/models/src/main/java/info/frostfs/sdk/mappers/object/OwnerIdMapper.java +++ /dev/null @@ -1,31 +0,0 @@ -package info.frostfs.sdk.mappers.object; - -import com.google.protobuf.ByteString; -import frostfs.refs.Types; -import info.frostfs.sdk.dto.object.OwnerId; -import io.neow3j.crypto.Base58; - -import static java.util.Objects.isNull; - -public class OwnerIdMapper { - private OwnerIdMapper() { - } - - public static Types.OwnerID toGrpcMessage(OwnerId ownerId) { - if (isNull(ownerId)) { - return null; - } - - return Types.OwnerID.newBuilder() - .setValue(ByteString.copyFrom(ownerId.toHash())) - .build(); - } - - public static OwnerId toModel(Types.OwnerID ownerId) { - if (isNull(ownerId) || ownerId.getSerializedSize() == 0) { - return null; - } - - return new OwnerId(Base58.encode(ownerId.getValue().toByteArray())); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/mappers/object/SplitInfoMapper.java b/models/src/main/java/info/frostfs/sdk/mappers/object/SplitInfoMapper.java deleted file mode 100644 index ac5f6ae..0000000 --- a/models/src/main/java/info/frostfs/sdk/mappers/object/SplitInfoMapper.java +++ /dev/null @@ -1,30 +0,0 @@ -package info.frostfs.sdk.mappers.object; - -import frostfs.object.Types; -import info.frostfs.sdk.dto.object.ObjectId; -import info.frostfs.sdk.dto.object.SplitId; -import info.frostfs.sdk.dto.object.SplitInfo; - -import static info.frostfs.sdk.UuidExtension.asUuid; -import static java.util.Objects.isNull; - -public class SplitInfoMapper { - private SplitInfoMapper() { - } - - public static SplitInfo toModel(Types.SplitInfo splitInfo) { - if (isNull(splitInfo) || splitInfo.getSerializedSize() == 0) { - return null; - } - - var splitId = new SplitId(asUuid(splitInfo.getSplitId().toByteArray())); - var link = splitInfo.getLink().getSerializedSize() == 0 - ? null - : new ObjectId(splitInfo.getLink().getValue().toByteArray()); - var lastPart = splitInfo.getLastPart().getSerializedSize() == 0 - ? null - : new ObjectId(splitInfo.getLastPart().getValue().toByteArray()); - - return new SplitInfo(splitInfo, splitId, link, lastPart); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/mappers/object/patch/AddressMapper.java b/models/src/main/java/info/frostfs/sdk/mappers/object/patch/AddressMapper.java deleted file mode 100644 index 1e34d62..0000000 --- a/models/src/main/java/info/frostfs/sdk/mappers/object/patch/AddressMapper.java +++ /dev/null @@ -1,24 +0,0 @@ -package info.frostfs.sdk.mappers.object.patch; - -import frostfs.refs.Types; -import info.frostfs.sdk.dto.object.patch.Address; -import info.frostfs.sdk.mappers.container.ContainerIdMapper; -import info.frostfs.sdk.mappers.object.ObjectIdMapper; - -import static java.util.Objects.isNull; - -public class AddressMapper { - private AddressMapper() { - } - - public static Types.Address toGrpcMessage(Address address) { - if (isNull(address)) { - return null; - } - - return Types.Address.newBuilder() - .setContainerId(ContainerIdMapper.toGrpcMessage(address.getContainerId())) - .setObjectId(ObjectIdMapper.toGrpcMessage(address.getObjectId())) - .build(); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/mappers/object/patch/RangeMapper.java b/models/src/main/java/info/frostfs/sdk/mappers/object/patch/RangeMapper.java deleted file mode 100644 index 0e3ebe5..0000000 --- a/models/src/main/java/info/frostfs/sdk/mappers/object/patch/RangeMapper.java +++ /dev/null @@ -1,35 +0,0 @@ -package info.frostfs.sdk.mappers.object.patch; - -import frostfs.object.Service; -import info.frostfs.sdk.dto.object.patch.Range; -import org.apache.commons.collections4.CollectionUtils; - -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; - -import static java.util.Objects.isNull; - -public class RangeMapper { - private RangeMapper() { - } - - public static List toGrpcMessages(List ranges) { - if (CollectionUtils.isEmpty(ranges)) { - return Collections.emptyList(); - } - - return ranges.stream().map(RangeMapper::toGrpcMessage).collect(Collectors.toList()); - } - - public static Service.Range toGrpcMessage(Range range) { - if (isNull(range)) { - return null; - } - - return Service.Range.newBuilder() - .setOffset(range.getOffset()) - .setLength(range.getLength()) - .build(); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/mappers/response/MetaHeaderMapper.java b/models/src/main/java/info/frostfs/sdk/mappers/response/MetaHeaderMapper.java deleted file mode 100644 index c9031b4..0000000 --- a/models/src/main/java/info/frostfs/sdk/mappers/response/MetaHeaderMapper.java +++ /dev/null @@ -1,37 +0,0 @@ -package info.frostfs.sdk.mappers.response; - -import frostfs.session.Types; -import info.frostfs.sdk.dto.response.MetaHeader; -import info.frostfs.sdk.exceptions.ValidationFrostFSException; -import info.frostfs.sdk.mappers.netmap.VersionMapper; - -import static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_IS_MISSING_TEMPLATE; -import static java.util.Objects.isNull; - -public class MetaHeaderMapper { - private MetaHeaderMapper() { - } - - public static Types.RequestMetaHeader toGrpcMessage(MetaHeader metaHeader) { - if (isNull(metaHeader)) { - throw new ValidationFrostFSException( - String.format(INPUT_PARAM_IS_MISSING_TEMPLATE, MetaHeader.class.getName()) - ); - } - - return toGrpcMessageBuilder(metaHeader).build(); - } - - public static Types.RequestMetaHeader.Builder toGrpcMessageBuilder(MetaHeader metaHeader) { - if (isNull(metaHeader)) { - throw new ValidationFrostFSException( - String.format(INPUT_PARAM_IS_MISSING_TEMPLATE, MetaHeader.class.getName()) - ); - } - - return Types.RequestMetaHeader.newBuilder() - .setVersion(VersionMapper.toGrpcMessage(metaHeader.getVersion())) - .setEpoch(metaHeader.getEpoch()) - .setTtl(metaHeader.getTtl()); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/mappers/response/ResponseStatusMapper.java b/models/src/main/java/info/frostfs/sdk/mappers/response/ResponseStatusMapper.java deleted file mode 100644 index 59c1563..0000000 --- a/models/src/main/java/info/frostfs/sdk/mappers/response/ResponseStatusMapper.java +++ /dev/null @@ -1,36 +0,0 @@ -package info.frostfs.sdk.mappers.response; - -import frostfs.status.Types; -import info.frostfs.sdk.dto.response.ResponseStatus; -import info.frostfs.sdk.enums.StatusCode; -import info.frostfs.sdk.exceptions.ProcessFrostFSException; - -import java.util.stream.Collectors; - -import static info.frostfs.sdk.constants.ErrorConst.FIELDS_DELIMITER_COMMA; -import static info.frostfs.sdk.constants.ErrorConst.UNKNOWN_ENUM_VALUE_TEMPLATE; -import static java.util.Objects.isNull; - -public class ResponseStatusMapper { - private ResponseStatusMapper() { - } - - public static ResponseStatus toModel(Types.Status status) { - if (isNull(status)) { - return new ResponseStatus(StatusCode.SUCCESS); - } - - var statusCode = StatusCode.get(status.getCode()); - if (isNull(statusCode)) { - throw new ProcessFrostFSException( - String.format(UNKNOWN_ENUM_VALUE_TEMPLATE, StatusCode.class.getName(), status.getCode()) - ); - } - - var stringDetails = status.getDetailsList().stream() - .map(t -> t.getValue().toStringUtf8()) - .collect(Collectors.toList()); - - return new ResponseStatus(statusCode, status.getMessage(), String.join(FIELDS_DELIMITER_COMMA, stringDetails)); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/mappers/response/SignatureMapper.java b/models/src/main/java/info/frostfs/sdk/mappers/response/SignatureMapper.java deleted file mode 100644 index 02905ac..0000000 --- a/models/src/main/java/info/frostfs/sdk/mappers/response/SignatureMapper.java +++ /dev/null @@ -1,35 +0,0 @@ -package info.frostfs.sdk.mappers.response; - -import com.google.protobuf.ByteString; -import frostfs.refs.Types; -import info.frostfs.sdk.dto.response.Signature; -import info.frostfs.sdk.exceptions.ProcessFrostFSException; - -import static info.frostfs.sdk.constants.ErrorConst.UNKNOWN_ENUM_VALUE_TEMPLATE; -import static java.util.Objects.isNull; - -public class SignatureMapper { - private SignatureMapper() { - } - - public static Types.Signature toGrpcMessage(Signature signature) { - if (isNull(signature)) { - return null; - } - - var scheme = Types.SignatureScheme.forNumber(signature.getScheme().value); - if (isNull(scheme)) { - throw new ProcessFrostFSException(String.format( - UNKNOWN_ENUM_VALUE_TEMPLATE, - Types.SignatureScheme.class.getName(), - signature.getScheme().name() - )); - } - - return Types.Signature.newBuilder() - .setKey(ByteString.copyFrom(signature.getKey())) - .setSign(ByteString.copyFrom(signature.getSign())) - .setScheme(scheme) - .build(); - } -} diff --git a/models/src/main/java/info/frostfs/sdk/mappers/session/SessionMapper.java b/models/src/main/java/info/frostfs/sdk/mappers/session/SessionMapper.java deleted file mode 100644 index e9f76e5..0000000 --- a/models/src/main/java/info/frostfs/sdk/mappers/session/SessionMapper.java +++ /dev/null @@ -1,48 +0,0 @@ -package info.frostfs.sdk.mappers.session; - -import com.google.protobuf.CodedOutputStream; -import com.google.protobuf.InvalidProtocolBufferException; -import frostfs.session.Types; -import info.frostfs.sdk.exceptions.ProcessFrostFSException; -import info.frostfs.sdk.exceptions.ValidationFrostFSException; - -import java.io.IOException; - -import static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_IS_MISSING_TEMPLATE; -import static java.util.Objects.isNull; - -public class SessionMapper { - private SessionMapper() { - } - - public static byte[] serialize(Types.SessionToken token) { - if (isNull(token)) { - throw new ValidationFrostFSException( - String.format(INPUT_PARAM_IS_MISSING_TEMPLATE, Types.SessionToken.class.getName()) - ); - } - - try { - byte[] bytes = new byte[token.getSerializedSize()]; - CodedOutputStream stream = CodedOutputStream.newInstance(bytes); - token.writeTo(stream); - return bytes; - } catch (IOException exp) { - throw new ProcessFrostFSException(exp.getMessage()); - } - } - - public static Types.SessionToken deserializeSessionToken(byte[] bytes) { - if (isNull(bytes) || bytes.length == 0) { - throw new ValidationFrostFSException( - String.format(INPUT_PARAM_IS_MISSING_TEMPLATE, Types.SessionToken.class.getName()) - ); - } - - try { - return Types.SessionToken.newBuilder().mergeFrom(bytes).build(); - } catch (InvalidProtocolBufferException exp) { - throw new ProcessFrostFSException(exp.getMessage()); - } - } -} diff --git a/models/src/test/java/info/frostfs/sdk/UuidExtensionTest.java b/models/src/test/java/info/frostfs/sdk/UuidExtensionTest.java deleted file mode 100644 index 9353b73..0000000 --- a/models/src/test/java/info/frostfs/sdk/UuidExtensionTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package info.frostfs.sdk; - -import info.frostfs.sdk.exceptions.ValidationFrostFSException; -import org.junit.jupiter.api.Test; - -import java.util.UUID; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; - -public class UuidExtensionTest { - private static final UUID TEST_UUID = UUID.fromString("ca70c669-0294-432d-8b83-05fc1475a579"); - private static final byte[] TEST_UUID_BYTES = - new byte[]{-54, 112, -58, 105, 2, -108, 67, 45, -117, -125, 5, -4, 20, 117, -91, 121}; - - @Test - void uuidAsBytes_success() { - //When - var result = UuidExtension.asBytes(TEST_UUID); - - //Then - assertThat(result).hasSize(16).containsExactly(TEST_UUID_BYTES); - } - - @Test - void uuidAsBytes_givenParamsIsNull() { - //When + Then - assertThrows(ValidationFrostFSException.class, () -> UuidExtension.asBytes(null)); - } - - @Test - void bytesAsUuid_success() { - //When - var result = UuidExtension.asUuid(TEST_UUID_BYTES); - - //Then - assertEquals(TEST_UUID, result); - } - - @Test - void bytesAsUuid_givenParamsIsNull() { - //When + Then - assertThrows(ValidationFrostFSException.class, () -> UuidExtension.asUuid(null)); - } - - @Test - void bytesAsUuid_wrongArraySize() { - //Given - var valueLength15 = new byte[]{-54, 112, -58, 105, 2, -108, 67, 45, -117, -125, 5, -4, 20, 117, -91}; - var valueLength17 = new byte[]{-54, 112, -58, 105, 2, -108, 67, 45, -117, -125, 5, -4, 20, 117, -91, 121, 12}; - - - //When + Then - assertThrows(ValidationFrostFSException.class, () -> UuidExtension.asUuid(valueLength15)); - assertThrows(ValidationFrostFSException.class, () -> UuidExtension.asUuid(valueLength17)); - } -} diff --git a/models/src/test/java/info/frostfs/sdk/mappers/chain/ChainTargetMapperTest.java b/models/src/test/java/info/frostfs/sdk/mappers/chain/ChainTargetMapperTest.java deleted file mode 100644 index b23b3b1..0000000 --- a/models/src/test/java/info/frostfs/sdk/mappers/chain/ChainTargetMapperTest.java +++ /dev/null @@ -1,52 +0,0 @@ -package info.frostfs.sdk.mappers.chain; - -import frostfs.ape.Types; -import info.frostfs.sdk.dto.chain.ChainTarget; -import info.frostfs.sdk.enums.TargetType; -import info.frostfs.sdk.exceptions.ProcessFrostFSException; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.EnumSource; -import org.mockito.MockedStatic; - -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.mockStatic; - -public class ChainTargetMapperTest { - - @ParameterizedTest - @EnumSource(value = TargetType.class) - void toGrpcMessage_success(TargetType targetType) { - //Given - var target = new ChainTarget("BzQw5HH3feoxFDD5tCT87Y1726qzgLfxEE7wgtoRzB3R", targetType); - - - //When - var result = ChainTargetMapper.toGrpcMessage(target); - - //Then - assertNotNull(result); - assertEquals(target.getName(), result.getName()); - assertEquals(target.getType().value, result.getTypeValue()); - } - - @Test - void toGrpcMessage_null() { - //When + Then - assertNull(ChainTargetMapper.toGrpcMessage(null)); - } - - @Test - void toGrpcMessage_notValidScheme() { - //Given - var target = new ChainTarget("BzQw5HH3feoxFDD5tCT87Y1726qzgLfxEE7wgtoRzB3R", TargetType.UNDEFINED); - - //When + Then - try (MockedStatic mockStatic = mockStatic(Types.TargetType.class)) { - mockStatic.when(() -> Types.TargetType.forNumber(target.getType().value)) - .thenReturn(null); - - assertThrows(ProcessFrostFSException.class, () -> ChainTargetMapper.toGrpcMessage(target)); - } - } -} diff --git a/models/src/test/java/info/frostfs/sdk/mappers/container/ContainerIdMapperTest.java b/models/src/test/java/info/frostfs/sdk/mappers/container/ContainerIdMapperTest.java deleted file mode 100644 index a421415..0000000 --- a/models/src/test/java/info/frostfs/sdk/mappers/container/ContainerIdMapperTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package info.frostfs.sdk.mappers.container; - -import info.frostfs.sdk.dto.container.ContainerId; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; - -public class ContainerIdMapperTest { - - @Test - void toGrpcMessage_success() { - //Given - var containerId = new ContainerId("EQGx2QeYHJb53uRwYGzcQaW191sZpdNrjutk6veUSV2R"); - - //When - var result = ContainerIdMapper.toGrpcMessage(containerId); - - //Then - assertNotNull(result); - assertEquals(containerId.getValue(), new ContainerId(result.getValue().toByteArray()).getValue()); - } - - @Test - void toGrpcMessage_null() { - //When + Then - assertNull(ContainerIdMapper.toGrpcMessage(null)); - } -} diff --git a/models/src/test/java/info/frostfs/sdk/mappers/container/ContainerMapperTest.java b/models/src/test/java/info/frostfs/sdk/mappers/container/ContainerMapperTest.java deleted file mode 100644 index c390e40..0000000 --- a/models/src/test/java/info/frostfs/sdk/mappers/container/ContainerMapperTest.java +++ /dev/null @@ -1,175 +0,0 @@ -package info.frostfs.sdk.mappers.container; - -import com.google.protobuf.ByteString; -import frostfs.container.Types; -import info.frostfs.sdk.dto.container.Container; -import info.frostfs.sdk.dto.netmap.PlacementPolicy; -import info.frostfs.sdk.dto.netmap.Replica; -import info.frostfs.sdk.dto.netmap.Version; -import info.frostfs.sdk.dto.object.OwnerId; -import info.frostfs.sdk.mappers.object.OwnerIdMapper; -import org.junit.jupiter.api.Test; - -import java.util.UUID; - -import static info.frostfs.sdk.UuidExtension.asBytes; -import static info.frostfs.sdk.UuidExtension.asUuid; -import static info.frostfs.sdk.constants.AttributeConst.DISABLE_HOMOMORPHIC_HASHING_ATTRIBUTE; -import static org.junit.jupiter.api.Assertions.*; - -public class ContainerMapperTest { - private static final String OWNER_ID = "NVxUSpEEJzYXZZtUs18PrJTD9QZkLLNQ8S"; - - @Test - void toGrpcMessage_successFullMessage() { - //Given - var placementPolicy = new PlacementPolicy(new Replica[]{new Replica(3)}, true, 1); - var container = new Container(placementPolicy); - container.getAttributes().put("key1", "val1"); - container.getAttributes().put(DISABLE_HOMOMORPHIC_HASHING_ATTRIBUTE, "false"); - container.setVersion(new Version()); - container.setOwnerId(new OwnerId(OWNER_ID)); - - //When - var result = ContainerMapper.toGrpcMessage(container); - - //Then - assertNotNull(result); - assertEquals(container.getNonce(), asUuid(result.getNonce().toByteArray())); - assertEquals(container.getPlacementPolicy().isUnique(), result.getPlacementPolicy().getUnique()); - assertEquals( - container.getPlacementPolicy().getBackupFactory(), - result.getPlacementPolicy().getContainerBackupFactor() - ); - assertEquals(placementPolicy.getReplicas().length, result.getPlacementPolicy().getReplicasCount()); - assertEquals( - container.getPlacementPolicy().getReplicas()[0].getCount(), - result.getPlacementPolicy().getReplicasList().get(0).getCount() - ); - assertEquals( - container.getPlacementPolicy().getReplicas()[0].getSelector(), - result.getPlacementPolicy().getReplicasList().get(0).getSelector() - ); - - assertEquals("key1", result.getAttributes(0).getKey()); - assertEquals("val1", result.getAttributes(0).getValue()); - assertEquals(DISABLE_HOMOMORPHIC_HASHING_ATTRIBUTE, result.getAttributes(1).getKey()); - assertEquals("false", result.getAttributes(1).getValue()); - - assertEquals(container.getVersion().getMajor(), result.getVersion().getMajor()); - assertEquals(container.getVersion().getMinor(), result.getVersion().getMinor()); - assertEquals(container.getOwnerId().toString(), OwnerIdMapper.toModel(result.getOwnerId()).toString()); - } - - @Test - void toGrpcMessage_success() { - //Given - var placementPolicy = new PlacementPolicy(new Replica[]{new Replica(3)}, true, 1); - var container = new Container(placementPolicy); - container.getAttributes().put("key1", "val1"); - container.getAttributes().put(DISABLE_HOMOMORPHIC_HASHING_ATTRIBUTE, "false"); - - //When - var result = ContainerMapper.toGrpcMessage(container); - - //Then - assertNotNull(result); - assertEquals(container.getNonce(), asUuid(result.getNonce().toByteArray())); - assertEquals(container.getPlacementPolicy().isUnique(), result.getPlacementPolicy().getUnique()); - assertEquals( - container.getPlacementPolicy().getBackupFactory(), - result.getPlacementPolicy().getContainerBackupFactor() - ); - assertEquals(placementPolicy.getReplicas().length, result.getPlacementPolicy().getReplicasCount()); - assertEquals( - container.getPlacementPolicy().getReplicas()[0].getCount(), - result.getPlacementPolicy().getReplicasList().get(0).getCount() - ); - assertEquals( - container.getPlacementPolicy().getReplicas()[0].getSelector(), - result.getPlacementPolicy().getReplicasList().get(0).getSelector() - ); - - assertEquals("key1", result.getAttributes(0).getKey()); - assertEquals("val1", result.getAttributes(0).getValue()); - assertEquals(DISABLE_HOMOMORPHIC_HASHING_ATTRIBUTE, result.getAttributes(1).getKey()); - assertEquals("false", result.getAttributes(1).getValue()); - } - - @Test - void toGrpcMessage_null() { - //When + Then - assertNull(ContainerMapper.toGrpcMessage(null)); - } - - @Test - void toModel_success() { - //Given - var version = frostfs.refs.Types.Version.newBuilder() - .setMajor(1) - .setMinor(2) - .build(); - - var replica = frostfs.netmap.Types.Replica.newBuilder() - .setCount(1) - .setSelector("") - .build(); - - var placementPolicy = frostfs.netmap.Types.PlacementPolicy.newBuilder() - .setUnique(true) - .addReplicas(replica) - .setContainerBackupFactor(2) - .build(); - - var attribute1 = Types.Container.Attribute.newBuilder() - .setKey("key1") - .setValue("val1") - .build(); - - var attribute2 = Types.Container.Attribute.newBuilder() - .setKey("key2") - .setValue("val2") - .build(); - - var container = Types.Container.newBuilder() - .setNonce(ByteString.copyFrom(asBytes(UUID.randomUUID()))) - .setVersion(version) - .setPlacementPolicy(placementPolicy) - .addAttributes(attribute1) - .addAttributes(attribute2) - .build(); - - //When - var result = ContainerMapper.toModel(container); - - //Then - assertNotNull(result); - assertEquals(asUuid(container.getNonce().toByteArray()), result.getNonce()); - assertEquals(container.getPlacementPolicy().getUnique(), result.getPlacementPolicy().isUnique()); - assertEquals( - container.getPlacementPolicy().getContainerBackupFactor(), - result.getPlacementPolicy().getBackupFactory() - ); - assertEquals(placementPolicy.getReplicasCount(), result.getPlacementPolicy().getReplicas().length); - assertEquals( - container.getPlacementPolicy().getReplicasList().get(0).getCount(), - result.getPlacementPolicy().getReplicas()[0].getCount() - ); - assertEquals( - container.getPlacementPolicy().getReplicasList().get(0).getSelector(), - result.getPlacementPolicy().getReplicas()[0].getSelector() - ); - assertEquals(version.getMajor(), result.getVersion().getMajor()); - assertEquals(version.getMinor(), result.getVersion().getMinor()); - - assertEquals(attribute1.getValue(), result.getAttributes().get(attribute1.getKey())); - assertEquals(attribute2.getValue(), result.getAttributes().get(attribute2.getKey())); - } - - @Test - void toModel_null() { - //When + Then - assertNull(ContainerMapper.toModel(null)); - assertNull(ContainerMapper.toModel(Types.Container.getDefaultInstance())); - } -} diff --git a/models/src/test/java/info/frostfs/sdk/mappers/netmap/FilterMapperTest.java b/models/src/test/java/info/frostfs/sdk/mappers/netmap/FilterMapperTest.java deleted file mode 100644 index 788d71e..0000000 --- a/models/src/test/java/info/frostfs/sdk/mappers/netmap/FilterMapperTest.java +++ /dev/null @@ -1,209 +0,0 @@ -package info.frostfs.sdk.mappers.netmap; - -import frostfs.netmap.Types; -import info.frostfs.sdk.dto.netmap.Filter; -import info.frostfs.sdk.enums.netmap.FilterOperation; -import info.frostfs.sdk.exceptions.ProcessFrostFSException; -import info.frostfs.sdk.exceptions.ValidationFrostFSException; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.EnumSource; -import org.mockito.MockedStatic; - -import java.util.Collections; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.mockStatic; - -public class FilterMapperTest { - - @ParameterizedTest - @EnumSource(value = FilterOperation.class) - void toGrpcMessages_success(FilterOperation operation) { - //Given - var filter1 = new Filter("name1", "key1", operation, "value1", null); - var filter2 = new Filter("name2", "key2", operation, "value2", null); - - //When - var result = FilterMapper.toGrpcMessages(new Filter[]{filter1, filter2}); - - //Then - assertThat(result).isNotNull().hasSize(2); - - assertEquals(filter1.getKey(), result.get(0).getKey()); - assertEquals(filter1.getName(), result.get(0).getName()); - assertEquals(filter1.getOperation().value, result.get(0).getOpValue()); - assertEquals(filter1.getValue(), result.get(0).getValue()); - assertEquals(0, result.get(0).getFiltersCount()); - - assertEquals(filter2.getKey(), result.get(1).getKey()); - assertEquals(filter2.getName(), result.get(1).getName()); - assertEquals(filter2.getOperation().value, result.get(1).getOpValue()); - assertEquals(filter2.getValue(), result.get(1).getValue()); - assertEquals(0, result.get(1).getFiltersCount()); - } - - @Test - void toGrpcMessages_null() { - //When + Then - assertEquals(Collections.emptyList(), FilterMapper.toGrpcMessages(null)); - assertEquals(Collections.emptyList(), FilterMapper.toGrpcMessages(new Filter[]{})); - } - - @ParameterizedTest - @EnumSource(value = FilterOperation.class) - void toGrpcMessage_success(FilterOperation operation) { - //Given - var filterChild = new Filter("name1", "key1", operation, "value1", null); - var filterParent = new Filter("name2", "key2", operation, "value2", new Filter[]{filterChild}); - - //When - var result = FilterMapper.toGrpcMessage(filterParent); - - //Then - assertNotNull(result); - assertEquals(filterParent.getKey(), result.getKey()); - assertEquals(filterParent.getName(), result.getName()); - assertEquals(filterParent.getOperation().value, result.getOpValue()); - assertEquals(filterParent.getValue(), result.getValue()); - assertEquals(filterParent.getFilters().length, result.getFiltersCount()); - - var filterChildGrpc = result.getFilters(0); - assertEquals(filterChild.getKey(), filterChildGrpc.getKey()); - assertEquals(filterChild.getName(), filterChildGrpc.getName()); - assertEquals(filterChild.getOperation().value, filterChildGrpc.getOpValue()); - assertEquals(filterChild.getValue(), filterChildGrpc.getValue()); - assertEquals(0, filterChildGrpc.getFiltersCount()); - } - - @Test - void toGrpcMessage_null() { - //When + Then - assertThrows(ValidationFrostFSException.class, () -> FilterMapper.toGrpcMessage(null)); - } - - @Test - void toGrpcMessage_notValidOperation() { - //Given - var filter = new Filter("name1", "key1", FilterOperation.EQ, "value1", null); - - - //When + Then - try (MockedStatic mockStatic = mockStatic(Types.Operation.class)) { - mockStatic.when(() -> Types.Operation.forNumber(filter.getOperation().value)) - .thenReturn(null); - - assertThrows(ProcessFrostFSException.class, () -> FilterMapper.toGrpcMessage(filter)); - } - } - - @ParameterizedTest - @EnumSource(value = Types.Operation.class, names = "UNRECOGNIZED", mode = EnumSource.Mode.EXCLUDE) - void toModels_success(Types.Operation operation) { - //Given - var filter1 = Types.Filter.newBuilder() - .setName("name1") - .setKey("key1") - .setOp(operation) - .setValue("value1") - .build(); - var filter2 = Types.Filter.newBuilder() - .setName("name2") - .setKey("key2") - .setOp(operation) - .setValue("value2") - .build(); - - //When - var result = FilterMapper.toModels(List.of(filter1, filter2)); - - //Then - assertThat(result).isNotNull().hasSize(2); - - - assertNotNull(result); - assertEquals(filter1.getKey(), result[0].getKey()); - assertEquals(filter1.getName(), result[0].getName()); - assertEquals(filter1.getOpValue(), result[0].getOperation().value); - assertEquals(filter1.getValue(), result[0].getValue()); - assertNull(result[0].getFilters()); - - assertEquals(filter2.getKey(), result[1].getKey()); - assertEquals(filter2.getName(), result[1].getName()); - assertEquals(filter2.getOpValue(), result[1].getOperation().value); - assertEquals(filter2.getValue(), result[1].getValue()); - assertNull(result[1].getFilters()); - } - - @Test - void toModels_null() { - //When + Then - assertNull(FilterMapper.toModels(null)); - assertNull(FilterMapper.toModels(Collections.emptyList())); - } - - @ParameterizedTest - @EnumSource(value = Types.Operation.class, names = "UNRECOGNIZED", mode = EnumSource.Mode.EXCLUDE) - void toModel_success(Types.Operation operation) { - //Given - var filterChild = Types.Filter.newBuilder() - .setName("name1") - .setKey("key1") - .setOp(operation) - .setValue("value1") - .build(); - var filterParent = Types.Filter.newBuilder() - .setName("name2") - .setKey("key2") - .setOp(operation) - .setValue("value2") - .addFilters(filterChild) - .build(); - - //When - var result = FilterMapper.toModel(filterParent); - - //Then - assertNotNull(result); - assertEquals(filterParent.getKey(), result.getKey()); - assertEquals(filterParent.getName(), result.getName()); - assertEquals(filterParent.getOpValue(), result.getOperation().value); - assertEquals(filterParent.getValue(), result.getValue()); - assertEquals(filterParent.getFiltersCount(), result.getFilters().length); - - var filterChildModel = result.getFilters()[0]; - assertEquals(filterChild.getKey(), filterChildModel.getKey()); - assertEquals(filterChild.getName(), filterChildModel.getName()); - assertEquals(filterChild.getOpValue(), filterChildModel.getOperation().value); - assertEquals(filterChild.getValue(), filterChildModel.getValue()); - assertNull(filterChildModel.getFilters()); - } - - @Test - void toModel_null() { - //When + Then - assertNull(FilterMapper.toModel(null)); - assertNull(FilterMapper.toModel(Types.Filter.getDefaultInstance())); - } - - @Test - void toModel_notValidScheme() { - //Given - var filter = Types.Filter.newBuilder() - .setName("name1") - .setKey("key1") - .setOp(Types.Operation.EQ) - .setValue("value1") - .build(); - - //When + Then - try (MockedStatic mockStatic = mockStatic(FilterOperation.class)) { - mockStatic.when(() -> FilterOperation.get(Types.Operation.EQ.getNumber())) - .thenReturn(null); - - assertThrows(ProcessFrostFSException.class, () -> FilterMapper.toModel(filter)); - } - } -} diff --git a/models/src/test/java/info/frostfs/sdk/mappers/netmap/NetmapSnapshotMapperTest.java b/models/src/test/java/info/frostfs/sdk/mappers/netmap/NetmapSnapshotMapperTest.java deleted file mode 100644 index 731eb51..0000000 --- a/models/src/test/java/info/frostfs/sdk/mappers/netmap/NetmapSnapshotMapperTest.java +++ /dev/null @@ -1,98 +0,0 @@ -package info.frostfs.sdk.mappers.netmap; - -import com.google.protobuf.ByteString; -import frostfs.netmap.Service; -import frostfs.netmap.Types; -import org.junit.jupiter.api.Test; - -import java.util.Map; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; - -public class NetmapSnapshotMapperTest { - - @Test - void toModel_success() { - //Given - var version = frostfs.refs.Types.Version.newBuilder() - .setMajor(1) - .setMinor(2) - .build(); - - var nodeInfo1 = Types.NodeInfo.newBuilder() - .setPublicKey(ByteString.copyFrom(new byte[]{1, 2, 3, 4, 5, 6})) - .addAttributes(Types.NodeInfo.Attribute.newBuilder().setKey("key1").setValue("value1").build()) - .addAttributes(Types.NodeInfo.Attribute.newBuilder().setKey("key2").setValue("value2").build()) - .addAddresses("address1") - .addAddresses("address2") - .setState(Types.NodeInfo.State.ONLINE) - .build(); - - var nodeInfo2 = Types.NodeInfo.newBuilder() - .setPublicKey(ByteString.copyFrom(new byte[]{7, 8, 9, 10})) - .addAttributes(Types.NodeInfo.Attribute.newBuilder().setKey("key3").setValue("value3").build()) - .addAttributes(Types.NodeInfo.Attribute.newBuilder().setKey("key4").setValue("value4").build()) - .addAddresses("address3") - .addAddresses("address4") - .setState(Types.NodeInfo.State.MAINTENANCE) - .build(); - - var netmap = Types.Netmap.newBuilder() - .setEpoch(10) - .addNodes(nodeInfo1) - .addNodes(nodeInfo2) - .build(); - - var body = Service.NetmapSnapshotResponse.Body.newBuilder() - .setNetmap(netmap) - .build(); - - var response = Service.NetmapSnapshotResponse.newBuilder() - .setBody(body) - .setMetaHeader(frostfs.session.Types.ResponseMetaHeader.newBuilder().setVersion(version).build()) - .build(); - - //When - var result = NetmapSnapshotMapper.toModel(response); - - //Then - assertNotNull(result); - - var resultNode1 = result.getNodeInfoCollection().get(0); - var resultNode2 = result.getNodeInfoCollection().get(1); - - - assertEquals(netmap.getEpoch(), result.getEpoch()); - assertEquals(netmap.getNodesCount(), result.getNodeInfoCollection().size()); - - assertThat(resultNode1.getPublicKey()).containsExactly(nodeInfo1.getPublicKey().toByteArray()); - assertEquals(nodeInfo1.getState().getNumber(), resultNode1.getState().value); - assertEquals(version.getMajor(), resultNode1.getVersion().getMajor()); - assertEquals(version.getMinor(), resultNode1.getVersion().getMinor()); - assertThat(resultNode1.getAddresses()) - .hasSize(2) - .containsAll(nodeInfo1.getAddressesList()); - assertThat(resultNode1.getAttributes()) - .hasSize(2) - .contains(Map.entry("key1", "value1"), Map.entry("key2", "value2")); - - assertThat(resultNode2.getPublicKey()).containsExactly(nodeInfo2.getPublicKey().toByteArray()); - assertEquals(nodeInfo2.getState().getNumber(), resultNode2.getState().value); - assertEquals(version.getMajor(), resultNode2.getVersion().getMajor()); - assertEquals(version.getMinor(), resultNode2.getVersion().getMinor()); - assertThat(resultNode2.getAddresses()) - .hasSize(2) - .containsAll(nodeInfo2.getAddressesList()); - assertThat(resultNode2.getAttributes()) - .hasSize(2) - .contains(Map.entry("key3", "value3"), Map.entry("key4", "value4")); - } - - @Test - void toModel_null() { - //When + Then - assertNull(NetmapSnapshotMapper.toModel(null)); - assertNull(NetmapSnapshotMapper.toModel(Service.NetmapSnapshotResponse.getDefaultInstance())); - } -} diff --git a/models/src/test/java/info/frostfs/sdk/mappers/netmap/NodeInfoMapperTest.java b/models/src/test/java/info/frostfs/sdk/mappers/netmap/NodeInfoMapperTest.java deleted file mode 100644 index dd2dc1f..0000000 --- a/models/src/test/java/info/frostfs/sdk/mappers/netmap/NodeInfoMapperTest.java +++ /dev/null @@ -1,124 +0,0 @@ -package info.frostfs.sdk.mappers.netmap; - -import com.google.protobuf.ByteString; -import frostfs.netmap.Service; -import frostfs.netmap.Types; -import info.frostfs.sdk.enums.netmap.NodeState; -import info.frostfs.sdk.exceptions.ProcessFrostFSException; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.EnumSource; -import org.mockito.MockedStatic; - -import java.util.Map; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.mockStatic; - -public class NodeInfoMapperTest { - - @ParameterizedTest - @EnumSource(value = Types.NodeInfo.State.class, names = "UNRECOGNIZED", mode = EnumSource.Mode.EXCLUDE) - void toModel_success(Types.NodeInfo.State state) { - //Given - var version = frostfs.refs.Types.Version.newBuilder() - .setMajor(1) - .setMinor(2) - .build(); - - var nodeInfo = Types.NodeInfo.newBuilder() - .setPublicKey(ByteString.copyFrom(new byte[]{1, 2, 3, 4, 5, 6})) - .addAttributes(Types.NodeInfo.Attribute.newBuilder().setKey("key1").setValue("value1").build()) - .addAttributes(Types.NodeInfo.Attribute.newBuilder().setKey("key2").setValue("value2").build()) - .addAddresses("address1") - .addAddresses("address2") - .setState(state) - .build(); - - var body = Service.LocalNodeInfoResponse.Body.newBuilder() - .setNodeInfo(nodeInfo) - .setVersion(version) - .build(); - - //When - var result = NodeInfoMapper.toModel(body); - - //Then - assertNotNull(result); - assertThat(result.getPublicKey()).containsExactly(nodeInfo.getPublicKey().toByteArray()); - assertEquals(nodeInfo.getState().getNumber(), result.getState().value); - assertEquals(version.getMajor(), result.getVersion().getMajor()); - assertEquals(version.getMinor(), result.getVersion().getMinor()); - assertThat(result.getAddresses()) - .hasSize(2) - .containsAll(nodeInfo.getAddressesList()); - assertThat(result.getAttributes()) - .hasSize(2) - .contains(Map.entry("key1", "value1"), Map.entry("key2", "value2")); - } - - @ParameterizedTest - @EnumSource(value = Types.NodeInfo.State.class, names = "UNRECOGNIZED", mode = EnumSource.Mode.EXCLUDE) - void toModel2_success(Types.NodeInfo.State state) { - //Given - var version = frostfs.refs.Types.Version.newBuilder() - .setMajor(1) - .setMinor(2) - .build(); - - var nodeInfo = Types.NodeInfo.newBuilder() - .setPublicKey(ByteString.copyFrom(new byte[]{1, 2, 3, 4, 5, 6})) - .addAttributes(Types.NodeInfo.Attribute.newBuilder().setKey("key1").setValue("value1").build()) - .addAttributes(Types.NodeInfo.Attribute.newBuilder().setKey("key2").setValue("value2").build()) - .addAddresses("address1") - .addAddresses("address2") - .setState(state) - .build(); - - //When - var result = NodeInfoMapper.toModel(nodeInfo, version); - - //Then - assertNotNull(result); - assertThat(result.getPublicKey()).containsExactly(nodeInfo.getPublicKey().toByteArray()); - assertEquals(nodeInfo.getState().getNumber(), result.getState().value); - assertEquals(version.getMajor(), result.getVersion().getMajor()); - assertEquals(version.getMinor(), result.getVersion().getMinor()); - assertThat(result.getAddresses()) - .hasSize(2) - .containsAll(nodeInfo.getAddressesList()); - assertThat(result.getAttributes()) - .hasSize(2) - .contains(Map.entry("key1", "value1"), Map.entry("key2", "value2")); - } - - @Test - void toModel_null() { - //When + Then - assertNull(NodeInfoMapper.toModel(null)); - assertNull(NodeInfoMapper.toModel(null, null)); - assertNull(NodeInfoMapper.toModel(Service.LocalNodeInfoResponse.Body.getDefaultInstance())); - assertNull(NodeInfoMapper.toModel(Types.NodeInfo.getDefaultInstance(), null)); - } - - @Test - void toModel_notValidScheme() { - //Given - var nodeInfo = Types.NodeInfo.newBuilder() - .setState(Types.NodeInfo.State.ONLINE) - .build(); - - var body = Service.LocalNodeInfoResponse.Body.newBuilder() - .setNodeInfo(nodeInfo) - .build(); - - //When + Then - try (MockedStatic mockStatic = mockStatic(NodeState.class)) { - mockStatic.when(() -> NodeState.get(Types.NodeInfo.State.ONLINE.getNumber())) - .thenReturn(null); - - assertThrows(ProcessFrostFSException.class, () -> NodeInfoMapper.toModel(body)); - } - } -} diff --git a/models/src/test/java/info/frostfs/sdk/mappers/netmap/PlacementPolicyMapperTest.java b/models/src/test/java/info/frostfs/sdk/mappers/netmap/PlacementPolicyMapperTest.java deleted file mode 100644 index 793ad92..0000000 --- a/models/src/test/java/info/frostfs/sdk/mappers/netmap/PlacementPolicyMapperTest.java +++ /dev/null @@ -1,80 +0,0 @@ -package info.frostfs.sdk.mappers.netmap; - -import frostfs.netmap.Types; -import info.frostfs.sdk.dto.netmap.PlacementPolicy; -import info.frostfs.sdk.dto.netmap.Replica; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; - -public class PlacementPolicyMapperTest { - - @Test - void toGrpcMessage_success() { - //Given - var replica1 = new Replica(1, "test1"); - var replica2 = new Replica(2, "test2"); - - var placementPolicy = new PlacementPolicy(new Replica[]{replica1, replica2}, true, 1); - - //When - var result = PlacementPolicyMapper.toGrpcMessage(placementPolicy); - - //Then - assertNotNull(result); - assertEquals(placementPolicy.isUnique(), result.getUnique()); - assertEquals(placementPolicy.getBackupFactory(), result.getContainerBackupFactor()); - assertEquals(placementPolicy.getReplicas().length, result.getReplicasCount()); - assertEquals(replica1.getCount(), result.getReplicas(0).getCount()); - assertEquals(replica1.getSelector(), result.getReplicas(0).getSelector()); - assertEquals(replica2.getCount(), result.getReplicas(1).getCount()); - assertEquals(replica2.getSelector(), result.getReplicas(1).getSelector()); - } - - @Test - void toGrpcMessage_null() { - //When + Then - assertNull(PlacementPolicyMapper.toGrpcMessage(null)); - } - - @Test - void toModel_success() { - //Given - var replica1 = Types.Replica.newBuilder() - .setCount(1) - .setSelector("test1") - .build(); - - var replica2 = Types.Replica.newBuilder() - .setCount(2) - .setSelector("test2") - .build(); - - var placementPolicy = Types.PlacementPolicy.newBuilder() - .setUnique(true) - .addReplicas(replica1) - .addReplicas(replica2) - .setContainerBackupFactor(1) - .build(); - - //When - var result = PlacementPolicyMapper.toModel(placementPolicy); - - //Then - assertNotNull(result); - assertEquals(placementPolicy.getUnique(), result.isUnique()); - assertEquals(placementPolicy.getContainerBackupFactor(), result.getBackupFactory()); - assertEquals(placementPolicy.getReplicasCount(), result.getReplicas().length); - assertEquals(replica1.getCount(), result.getReplicas()[0].getCount()); - assertEquals(replica1.getSelector(), result.getReplicas()[0].getSelector()); - assertEquals(replica2.getCount(), result.getReplicas()[1].getCount()); - assertEquals(replica2.getSelector(), result.getReplicas()[1].getSelector()); - } - - @Test - void toModel_null() { - //When + Then - assertNull(PlacementPolicyMapper.toModel(null)); - assertNull(PlacementPolicyMapper.toModel(Types.PlacementPolicy.getDefaultInstance())); - } -} diff --git a/models/src/test/java/info/frostfs/sdk/mappers/netmap/ReplicaMapperTest.java b/models/src/test/java/info/frostfs/sdk/mappers/netmap/ReplicaMapperTest.java deleted file mode 100644 index ca486dc..0000000 --- a/models/src/test/java/info/frostfs/sdk/mappers/netmap/ReplicaMapperTest.java +++ /dev/null @@ -1,55 +0,0 @@ -package info.frostfs.sdk.mappers.netmap; - -import frostfs.netmap.Types; -import info.frostfs.sdk.dto.netmap.Replica; -import info.frostfs.sdk.exceptions.ValidationFrostFSException; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; - -public class ReplicaMapperTest { - - @Test - void toGrpcMessage_success() { - //Given - var replica = new Replica(1); - - //When - var result = ReplicaMapper.toGrpcMessage(replica); - - //Then - assertNotNull(result); - assertEquals(replica.getCount(), result.getCount()); - assertEquals(replica.getSelector(), result.getSelector()); - } - - @Test - void toGrpcMessage_null() { - //When + Then - assertThrows(ValidationFrostFSException.class, () -> ReplicaMapper.toGrpcMessage(null)); - } - - @Test - void toModel_success() { - //Given - var replica = Types.Replica.newBuilder() - .setCount(1) - .setSelector("") - .build(); - - //When - var result = ReplicaMapper.toModel(replica); - - //Then - assertNotNull(result); - assertEquals(replica.getCount(), result.getCount()); - assertEquals(replica.getSelector(), result.getSelector()); - } - - @Test - void toModel_null() { - //When + Then - assertNull(ReplicaMapper.toModel(null)); - assertNull(ReplicaMapper.toModel(Types.Replica.getDefaultInstance())); - } -} diff --git a/models/src/test/java/info/frostfs/sdk/mappers/netmap/SelectorMapperTest.java b/models/src/test/java/info/frostfs/sdk/mappers/netmap/SelectorMapperTest.java deleted file mode 100644 index 6d46553..0000000 --- a/models/src/test/java/info/frostfs/sdk/mappers/netmap/SelectorMapperTest.java +++ /dev/null @@ -1,191 +0,0 @@ -package info.frostfs.sdk.mappers.netmap; - -import frostfs.netmap.Types; -import info.frostfs.sdk.dto.netmap.Selector; -import info.frostfs.sdk.enums.netmap.SelectorClause; -import info.frostfs.sdk.exceptions.ProcessFrostFSException; -import info.frostfs.sdk.exceptions.ValidationFrostFSException; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.EnumSource; -import org.mockito.MockedStatic; - -import java.util.Collections; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.mockStatic; - -public class SelectorMapperTest { - - @ParameterizedTest - @EnumSource(value = SelectorClause.class) - void toGrpcMessages_success(SelectorClause clause) { - //Given - var selector1 = new Selector("name1", 1, clause, "attribute1", "filter1"); - var selector2 = new Selector("name2", 2, clause, "attribute2", "filter2"); - - //When - var result = SelectorMapper.toGrpcMessages(new Selector[]{selector1, selector2}); - - //Then - assertThat(result).isNotNull().hasSize(2); - - assertEquals(selector1.getName(), result.get(0).getName()); - assertEquals(selector1.getCount(), result.get(0).getCount()); - assertEquals(selector1.getClause().value, result.get(0).getClauseValue()); - assertEquals(selector1.getAttribute(), result.get(0).getAttribute()); - assertEquals(selector1.getFilter(), result.get(0).getFilter()); - - assertEquals(selector2.getName(), result.get(1).getName()); - assertEquals(selector2.getCount(), result.get(1).getCount()); - assertEquals(selector2.getClause().value, result.get(1).getClauseValue()); - assertEquals(selector2.getAttribute(), result.get(1).getAttribute()); - assertEquals(selector2.getFilter(), result.get(1).getFilter()); - } - - @Test - void toGrpcMessages_null() { - //When + Then - assertEquals(Collections.emptyList(), SelectorMapper.toGrpcMessages(null)); - assertEquals(Collections.emptyList(), SelectorMapper.toGrpcMessages(new Selector[]{})); - } - - @ParameterizedTest - @EnumSource(value = SelectorClause.class) - void toGrpcMessage_success(SelectorClause clause) { - //Given - var selector = new Selector("name", 1, clause, "attribute", "filter"); - - //When - var result = SelectorMapper.toGrpcMessage(selector); - - //Then - assertNotNull(result); - assertEquals(selector.getName(), result.getName()); - assertEquals(selector.getCount(), result.getCount()); - assertEquals(selector.getClause().value, result.getClauseValue()); - assertEquals(selector.getAttribute(), result.getAttribute()); - assertEquals(selector.getFilter(), result.getFilter()); - } - - @Test - void toGrpcMessage_null() { - //When + Then - assertThrows(ValidationFrostFSException.class, () -> SelectorMapper.toGrpcMessage(null)); - } - - @Test - void toGrpcMessage_notValidOperation() { - //Given - var selector = new Selector("name", 1, SelectorClause.SAME, "attribute", "filter"); - - - //When + Then - try (MockedStatic mockStatic = mockStatic(Types.Clause.class)) { - mockStatic.when(() -> Types.Clause.forNumber(selector.getClause().value)) - .thenReturn(null); - - assertThrows(ProcessFrostFSException.class, () -> SelectorMapper.toGrpcMessage(selector)); - } - } - - @ParameterizedTest - @EnumSource(value = Types.Clause.class, names = "UNRECOGNIZED", mode = EnumSource.Mode.EXCLUDE) - void toModels_success(Types.Clause clause) { - //Given - var selector1 = Types.Selector.newBuilder() - .setName("name1") - .setCount(1) - .setClause(clause) - .setAttribute("attribute1") - .setFilter("filter1") - .build(); - var selector2 = Types.Selector.newBuilder() - .setName("name2") - .setCount(2) - .setClause(clause) - .setAttribute("attribute2") - .setFilter("filter2") - .build(); - - //When - var result = SelectorMapper.toModels(List.of(selector1, selector2)); - - //Then - assertThat(result).isNotNull().hasSize(2); - - - assertNotNull(result); - assertEquals(selector1.getName(), result[0].getName()); - assertEquals(selector1.getCount(), result[0].getCount()); - assertEquals(selector1.getClauseValue(), result[0].getClause().value); - assertEquals(selector1.getAttribute(), result[0].getAttribute()); - assertEquals(selector1.getFilter(), result[0].getFilter()); - - assertEquals(selector2.getName(), result[1].getName()); - assertEquals(selector2.getCount(), result[1].getCount()); - assertEquals(selector2.getClauseValue(), result[1].getClause().value); - assertEquals(selector2.getAttribute(), result[1].getAttribute()); - assertEquals(selector2.getFilter(), result[1].getFilter()); - } - - @Test - void toModels_null() { - //When + Then - assertNull(SelectorMapper.toModels(null)); - assertNull(SelectorMapper.toModels(Collections.emptyList())); - } - - @ParameterizedTest - @EnumSource(value = Types.Clause.class, names = "UNRECOGNIZED", mode = EnumSource.Mode.EXCLUDE) - void toModel_success(Types.Clause clause) { - //Given - var selector = Types.Selector.newBuilder() - .setName("name") - .setCount(1) - .setClause(clause) - .setAttribute("attribute") - .setFilter("filter") - .build(); - - //When - var result = SelectorMapper.toModel(selector); - - //Then - assertNotNull(result); - assertEquals(selector.getName(), result.getName()); - assertEquals(selector.getCount(), result.getCount()); - assertEquals(selector.getClauseValue(), result.getClause().value); - assertEquals(selector.getAttribute(), result.getAttribute()); - assertEquals(selector.getFilter(), result.getFilter()); - } - - @Test - void toModel_null() { - //When + Then - assertNull(SelectorMapper.toModel(null)); - assertNull(SelectorMapper.toModel(Types.Selector.getDefaultInstance())); - } - - @Test - void toModel_notValidScheme() { - //Given - var selector = Types.Selector.newBuilder() - .setName("name") - .setCount(1) - .setClause(Types.Clause.SAME) - .setAttribute("attribute") - .setFilter("filter") - .build(); - - //When + Then - try (MockedStatic mockStatic = mockStatic(SelectorClause.class)) { - mockStatic.when(() -> SelectorClause.get(Types.Clause.SAME.getNumber())) - .thenReturn(null); - - assertThrows(ProcessFrostFSException.class, () -> SelectorMapper.toModel(selector)); - } - } -} diff --git a/models/src/test/java/info/frostfs/sdk/mappers/netmap/VersionMapperTest.java b/models/src/test/java/info/frostfs/sdk/mappers/netmap/VersionMapperTest.java deleted file mode 100644 index 25aa403..0000000 --- a/models/src/test/java/info/frostfs/sdk/mappers/netmap/VersionMapperTest.java +++ /dev/null @@ -1,54 +0,0 @@ -package info.frostfs.sdk.mappers.netmap; - -import frostfs.refs.Types; -import info.frostfs.sdk.dto.netmap.Version; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; - -public class VersionMapperTest { - - @Test - void toGrpcMessage_success() { - //Given - var version = new Version(1, 2); - - //When - var result = VersionMapper.toGrpcMessage(version); - - //Then - assertNotNull(result); - assertEquals(version.getMajor(), result.getMajor()); - assertEquals(version.getMinor(), result.getMinor()); - } - - @Test - void toGrpcMessage_null() { - //When + Then - assertNull(VersionMapper.toGrpcMessage(null)); - } - - @Test - void toModel_success() { - //Given - var version = Types.Version.newBuilder() - .setMajor(1) - .setMinor(2) - .build(); - - //When - var result = VersionMapper.toModel(version); - - //Then - assertNotNull(result); - assertEquals(version.getMajor(), result.getMajor()); - assertEquals(version.getMinor(), result.getMinor()); - } - - @Test - void toModel_null() { - //When + Then - assertNull(VersionMapper.toModel(null)); - assertNull(VersionMapper.toModel(Types.Version.getDefaultInstance())); - } -} diff --git a/models/src/test/java/info/frostfs/sdk/mappers/object/ObjectAttributeMapperTest.java b/models/src/test/java/info/frostfs/sdk/mappers/object/ObjectAttributeMapperTest.java deleted file mode 100644 index 4eb5501..0000000 --- a/models/src/test/java/info/frostfs/sdk/mappers/object/ObjectAttributeMapperTest.java +++ /dev/null @@ -1,84 +0,0 @@ -package info.frostfs.sdk.mappers.object; - -import frostfs.object.Types; -import info.frostfs.sdk.dto.object.ObjectAttribute; -import org.apache.commons.collections4.CollectionUtils; -import org.junit.jupiter.api.Test; - -import java.util.Arrays; -import java.util.Collections; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; - -public class ObjectAttributeMapperTest { - - @Test - void toGrpcMessages_success() { - //Given - var objectAttribute1 = new ObjectAttribute("key1", "value1"); - var objectAttribute2 = new ObjectAttribute("key2", "value2"); - - //When - var result = ObjectAttributeMapper.toGrpcMessages(Arrays.asList(objectAttribute1, objectAttribute2)); - - //Then - assertNotNull(result); - assertThat(result).isNotNull().hasSize(2); - assertEquals(objectAttribute1.getKey(), result.get(0).getKey()); - assertEquals(objectAttribute1.getValue(), result.get(0).getValue()); - assertEquals(objectAttribute2.getKey(), result.get(1).getKey()); - assertEquals(objectAttribute2.getValue(), result.get(1).getValue()); - } - - @Test - void toGrpcMessages_null() { - //When + Then - assertTrue(CollectionUtils.isEmpty(ObjectAttributeMapper.toGrpcMessages(null))); - assertTrue(CollectionUtils.isEmpty(ObjectAttributeMapper.toGrpcMessages(Collections.emptyList()))); - } - - @Test - void toGrpcMessage_success() { - //Given - var objectAttribute = new ObjectAttribute("key", "value"); - - //When - var result = ObjectAttributeMapper.toGrpcMessage(objectAttribute); - - //Then - assertNotNull(result); - assertEquals(objectAttribute.getKey(), result.getKey()); - assertEquals(objectAttribute.getValue(), result.getValue()); - } - - @Test - void toGrpcMessage_null() { - //When + Then - assertNull(ObjectAttributeMapper.toGrpcMessage(null)); - } - - @Test - void toModel_success() { - //Given - var objectAttribute = Types.Header.Attribute.newBuilder() - .setKey("key") - .setValue("value") - .build(); - - //When - var result = ObjectAttributeMapper.toModel(objectAttribute); - - //Then - assertNotNull(result); - assertEquals(objectAttribute.getKey(), result.getKey()); - assertEquals(objectAttribute.getValue(), result.getValue()); - } - - @Test - void toModel_null() { - //When + Then - assertNull(ObjectAttributeMapper.toModel(null)); - assertNull(ObjectAttributeMapper.toModel(Types.Header.Attribute.getDefaultInstance())); - } -} diff --git a/models/src/test/java/info/frostfs/sdk/mappers/object/ObjectFilterMapperTest.java b/models/src/test/java/info/frostfs/sdk/mappers/object/ObjectFilterMapperTest.java deleted file mode 100644 index 268bf43..0000000 --- a/models/src/test/java/info/frostfs/sdk/mappers/object/ObjectFilterMapperTest.java +++ /dev/null @@ -1,54 +0,0 @@ -package info.frostfs.sdk.mappers.object; - -import frostfs.object.Types; -import info.frostfs.sdk.dto.object.ObjectFilter; -import info.frostfs.sdk.enums.ObjectMatchType; -import info.frostfs.sdk.exceptions.ProcessFrostFSException; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.EnumSource; -import org.mockito.MockedStatic; - -import static info.frostfs.sdk.enums.ObjectMatchType.UNSPECIFIED; -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.mockStatic; - -public class ObjectFilterMapperTest { - - @ParameterizedTest - @EnumSource(value = ObjectMatchType.class) - void toGrpcMessage_success(ObjectMatchType type) { - //Given - var objectFilter = new ObjectFilter.FilterByAttribute(type, "key", "value"); - - //When - var result = ObjectFilterMapper.toGrpcMessage(objectFilter); - - //Then - assertNotNull(result); - assertEquals(objectFilter.getKey(), result.getKey()); - assertEquals(objectFilter.getValue(), result.getValue()); - assertEquals(objectFilter.getMatchType().value, result.getMatchType().getNumber()); - - } - - @Test - void toGrpcMessage_null() { - //When + Then - assertNull(ObjectFilterMapper.toGrpcMessage(null)); - } - - @Test - void toGrpcMessage_notValidType() { - //Given - var objectFilter = new ObjectFilter.FilterByAttribute(UNSPECIFIED, "key", "value"); - - //When + Then - try (MockedStatic mockStatic = mockStatic(Types.MatchType.class)) { - mockStatic.when(() -> Types.MatchType.forNumber(objectFilter.getMatchType().value)) - .thenReturn(null); - - assertThrows(ProcessFrostFSException.class, () -> ObjectFilterMapper.toGrpcMessage(objectFilter)); - } - } -} diff --git a/models/src/test/java/info/frostfs/sdk/mappers/object/ObjectFrostFSMapperTest.java b/models/src/test/java/info/frostfs/sdk/mappers/object/ObjectFrostFSMapperTest.java deleted file mode 100644 index dbcf9b7..0000000 --- a/models/src/test/java/info/frostfs/sdk/mappers/object/ObjectFrostFSMapperTest.java +++ /dev/null @@ -1,60 +0,0 @@ -package info.frostfs.sdk.mappers.object; - -import com.google.protobuf.ByteString; -import frostfs.object.Types; -import info.frostfs.sdk.dto.container.ContainerId; -import info.frostfs.sdk.dto.object.ObjectId; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; - -public class ObjectFrostFSMapperTest { - @Test - void toModel_success() { - //Given - var containerId = new ContainerId("EQGx2QeYHJb53uRwYGzcQaW191sZpdNrjutk6veUSV2R"); - var cid = frostfs.refs.Types.ContainerID.newBuilder() - .setValue(ByteString.copyFrom(containerId.toHash())) - .build(); - var version = frostfs.refs.Types.Version.newBuilder() - .setMajor(1) - .setMinor(2) - .build(); - var header = Types.Header.newBuilder() - .setObjectType(Types.ObjectType.REGULAR) - .setVersion(version) - .setContainerId(cid) - .setPayloadLength(10) - .build(); - - var objectId = new ObjectId("85orCLKSu3X1jGiTFmwmTUsBU88RBARNwuRwrEy5pyww"); - var object = Types.Object.newBuilder() - .setObjectId(ObjectIdMapper.toGrpcMessage(objectId)) - .setPayload(ByteString.copyFrom(new byte[]{1, 2, 3, 4, 5})) - .setHeader(header) - .build(); - - //When - var result = ObjectFrostFSMapper.toModel(object); - - //Then - assertNotNull(result); - assertEquals(objectId.getValue(), result.getObjectId().getValue()); - assertThat(result.getPayload()).containsExactly(object.getPayload().toByteArray()); - assertThat(result.getHeader().getAttributes()).hasSize(0); - assertEquals(header.getObjectTypeValue(), result.getHeader().getObjectType().value); - assertEquals(version.getMajor(), result.getHeader().getVersion().getMajor()); - assertEquals(version.getMinor(), result.getHeader().getVersion().getMinor()); - assertEquals(header.getPayloadLength(), result.getHeader().getPayloadLength()); - assertEquals(containerId.getValue(), result.getHeader().getContainerId().getValue()); - } - - @Test - void toModel_null() { - //When + Then - assertNull(ObjectFrostFSMapper.toModel(null)); - assertNull(ObjectFrostFSMapper.toModel(Types.Object.getDefaultInstance())); - } - -} diff --git a/models/src/test/java/info/frostfs/sdk/mappers/object/ObjectHeaderMapperTest.java b/models/src/test/java/info/frostfs/sdk/mappers/object/ObjectHeaderMapperTest.java deleted file mode 100644 index 76a7fe9..0000000 --- a/models/src/test/java/info/frostfs/sdk/mappers/object/ObjectHeaderMapperTest.java +++ /dev/null @@ -1,132 +0,0 @@ -package info.frostfs.sdk.mappers.object; - -import com.google.protobuf.ByteString; -import frostfs.object.Types; -import info.frostfs.sdk.dto.container.ContainerId; -import info.frostfs.sdk.dto.netmap.Version; -import info.frostfs.sdk.dto.object.ObjectAttribute; -import info.frostfs.sdk.dto.object.ObjectHeader; -import info.frostfs.sdk.dto.object.OwnerId; -import info.frostfs.sdk.enums.ObjectType; -import info.frostfs.sdk.exceptions.ProcessFrostFSException; -import info.frostfs.sdk.exceptions.ValidationFrostFSException; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.EnumSource; -import org.mockito.MockedStatic; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.mockStatic; - -public class ObjectHeaderMapperTest { - - @ParameterizedTest - @EnumSource(value = ObjectType.class) - void toGrpcMessage_success(ObjectType type) { - //Given - var containerId = new ContainerId("EQGx2QeYHJb53uRwYGzcQaW191sZpdNrjutk6veUSV2R"); - var objectHeader = new ObjectHeader( - containerId, - type, - new ObjectAttribute("Filename", "cat.jpg"), - new ObjectAttribute("Filename2", "cat2.jpg") - ); - objectHeader.setOwnerId(new OwnerId("NVxUSpEEJzYXZZtUs18PrJTD9QZkLLNQ8S")); - objectHeader.setVersion(new Version(1, 2)); - - //When - var result = ObjectHeaderMapper.toGrpcMessage(objectHeader); - - //Then - assertNotNull(result); - assertEquals( - objectHeader.getContainerId().getValue(), - new ContainerId(result.getContainerId().getValue().toByteArray()).getValue() - ); - assertEquals(objectHeader.getObjectType().value, result.getObjectType().getNumber()); - assertEquals(objectHeader.getAttributes().size(), result.getAttributesCount()); - - assertEquals(objectHeader.getAttributes().get(0).getKey(), result.getAttributes(0).getKey()); - assertEquals(objectHeader.getAttributes().get(0).getValue(), result.getAttributes(0).getValue()); - - assertEquals(objectHeader.getAttributes().get(1).getKey(), result.getAttributes(1).getKey()); - assertEquals(objectHeader.getAttributes().get(1).getValue(), result.getAttributes(1).getValue()); - } - - @Test - void toGrpcMessage_null() { - //When + Then - assertThrows(ValidationFrostFSException.class, () -> ObjectHeaderMapper.toGrpcMessage(null)); - } - - @Test - void toGrpcMessage_notValidScheme() { - //Given - var containerId = new ContainerId("EQGx2QeYHJb53uRwYGzcQaW191sZpdNrjutk6veUSV2R"); - var objectHeader = new ObjectHeader(containerId, ObjectType.REGULAR); - - //When + Then - try (MockedStatic mockStatic = mockStatic(Types.ObjectType.class)) { - mockStatic.when(() -> Types.ObjectType.forNumber(objectHeader.getObjectType().value)) - .thenReturn(null); - - assertThrows(ProcessFrostFSException.class, () -> ObjectHeaderMapper.toGrpcMessage(objectHeader)); - } - } - - @ParameterizedTest - @EnumSource(value = Types.ObjectType.class, names = "UNRECOGNIZED", mode = EnumSource.Mode.EXCLUDE) - void toModel_success(Types.ObjectType type) { - //Given - var containerId = new ContainerId("EQGx2QeYHJb53uRwYGzcQaW191sZpdNrjutk6veUSV2R"); - var cid = frostfs.refs.Types.ContainerID.newBuilder() - .setValue(ByteString.copyFrom(containerId.toHash())) - .build(); - var version = frostfs.refs.Types.Version.newBuilder() - .setMajor(1) - .setMinor(2) - .build(); - var header = Types.Header.newBuilder() - .setObjectType(type) - .setVersion(version) - .setContainerId(cid) - .setPayloadLength(10) - .build(); - - //When - var result = ObjectHeaderMapper.toModel(header); - - //Then - assertNotNull(result); - assertThat(result.getAttributes()).hasSize(0); - assertEquals(header.getObjectTypeValue(), result.getObjectType().value); - assertEquals(version.getMajor(), result.getVersion().getMajor()); - assertEquals(version.getMinor(), result.getVersion().getMinor()); - assertEquals(header.getPayloadLength(), result.getPayloadLength()); - assertEquals(containerId.getValue(), result.getContainerId().getValue()); - } - - @Test - void toModel_null() { - //When + Then - assertNull(ObjectHeaderMapper.toModel(null)); - assertNull(ObjectHeaderMapper.toModel(Types.Header.getDefaultInstance())); - } - - @Test - void toModel_notValidScheme() { - //Given - var header = Types.Header.newBuilder() - .setObjectType(Types.ObjectType.TOMBSTONE) - .build(); - - //When + Then - try (MockedStatic mockStatic = mockStatic(ObjectType.class)) { - mockStatic.when(() -> ObjectType.get(Types.ObjectType.TOMBSTONE.getNumber())) - .thenReturn(null); - - assertThrows(ProcessFrostFSException.class, () -> ObjectHeaderMapper.toModel(header)); - } - } -} diff --git a/models/src/test/java/info/frostfs/sdk/mappers/object/ObjectIdMapperTest.java b/models/src/test/java/info/frostfs/sdk/mappers/object/ObjectIdMapperTest.java deleted file mode 100644 index ab5a722..0000000 --- a/models/src/test/java/info/frostfs/sdk/mappers/object/ObjectIdMapperTest.java +++ /dev/null @@ -1,53 +0,0 @@ -package info.frostfs.sdk.mappers.object; - -import com.google.protobuf.ByteString; -import frostfs.refs.Types; -import info.frostfs.sdk.dto.object.ObjectId; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; - -public class ObjectIdMapperTest { - - @Test - void toGrpcMessage_success() { - //Given - var objectId = new ObjectId("85orCLKSu3X1jGiTFmwmTUsBU88RBARNwuRwrEy5pyww"); - - //When - var result = ObjectIdMapper.toGrpcMessage(objectId); - - //Then - assertNotNull(result); - assertEquals(objectId.getValue(), new ObjectId(result.getValue().toByteArray()).getValue()); - } - - @Test - void toGrpcMessage_null() { - //When + Then - assertNull(ObjectIdMapper.toGrpcMessage(null)); - } - - @Test - void toModel_success() { - //Given - var objectId = new ObjectId("85orCLKSu3X1jGiTFmwmTUsBU88RBARNwuRwrEy5pyww"); - var objectIdGrpc = Types.ObjectID.newBuilder() - .setValue(ByteString.copyFrom(objectId.toHash())) - .build(); - - //When - var result = ObjectIdMapper.toModel(objectIdGrpc); - - //Then - assertNotNull(result); - assertEquals(objectId.getValue(), result.getValue()); - } - - @Test - void toModel_null() { - //When + Then - assertNull(ObjectIdMapper.toModel(null)); - assertNull(ObjectIdMapper.toModel(Types.ObjectID.getDefaultInstance())); - } -} diff --git a/models/src/test/java/info/frostfs/sdk/mappers/object/OwnerIdMapperTest.java b/models/src/test/java/info/frostfs/sdk/mappers/object/OwnerIdMapperTest.java deleted file mode 100644 index e9ac8c6..0000000 --- a/models/src/test/java/info/frostfs/sdk/mappers/object/OwnerIdMapperTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package info.frostfs.sdk.mappers.object; - -import info.frostfs.sdk.dto.object.OwnerId; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class OwnerIdMapperTest { - private static final String OWNER_ID = "NVxUSpEEJzYXZZtUs18PrJTD9QZkLLNQ8S"; - - @Test - void toGrpcMessage_success() { - //Given - var ownerId = new OwnerId(OWNER_ID); - var expected = new byte[]{ - 53, 110, 42, -125, -76, -25, -44, -94, 22, -98, 117, -100, -5, 103, 74, -128, -51, 37, -116, -102, 71, - -1, 95, -4, 3 - }; - - //When - var result = OwnerIdMapper.toGrpcMessage(ownerId); - - //Then - assertNotNull(result); - assertThat(result.getValue().toByteArray()).hasSize(25).containsExactly(expected); - } - - @Test - void toGrpcMessage_null() { - //When + Then - assertNull(OwnerIdMapper.toGrpcMessage(null)); - } -} diff --git a/models/src/test/java/info/frostfs/sdk/mappers/object/SplitInfoMapperTest.java b/models/src/test/java/info/frostfs/sdk/mappers/object/SplitInfoMapperTest.java deleted file mode 100644 index 3e9ca2b..0000000 --- a/models/src/test/java/info/frostfs/sdk/mappers/object/SplitInfoMapperTest.java +++ /dev/null @@ -1,61 +0,0 @@ -package info.frostfs.sdk.mappers.object; - -import com.google.protobuf.ByteString; -import frostfs.object.Types; -import info.frostfs.sdk.dto.object.ObjectId; -import info.frostfs.sdk.dto.object.SplitId; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; - -public class SplitInfoMapperTest { - @Test - void toModel_successLastPart() { - //Given - var splitId = new SplitId(); - var objectId = new ObjectId("85orCLKSu3X1jGiTFmwmTUsBU88RBARNwuRwrEy5pyww"); - var splitInfo = Types.SplitInfo.newBuilder() - .setSplitId(ByteString.copyFrom(splitId.toBinary())) - .setLastPart(ObjectIdMapper.toGrpcMessage(objectId)) - .build(); - - //When - var result = SplitInfoMapper.toModel(splitInfo); - - //Then - assertNotNull(result); - assertNull(result.getLink()); - assertThat(result.getSplitInfo()).isEqualTo(splitInfo); - assertThat(result.getSplitId().toBinary()).containsExactly(splitId.toBinary()); - assertEquals(objectId.getValue(), result.getLastPart().getValue()); - } - - @Test - void toModel_successLink() { - //Given - var splitId = new SplitId(); - var objectId = new ObjectId("85orCLKSu3X1jGiTFmwmTUsBU88RBARNwuRwrEy5pyww"); - var splitInfo = Types.SplitInfo.newBuilder() - .setSplitId(ByteString.copyFrom(splitId.toBinary())) - .setLink(ObjectIdMapper.toGrpcMessage(objectId)) - .build(); - - //When - var result = SplitInfoMapper.toModel(splitInfo); - - //Then - assertNotNull(result); - assertNull(result.getLastPart()); - assertThat(result.getSplitInfo()).isEqualTo(splitInfo); - assertThat(result.getSplitId().toBinary()).containsExactly(splitId.toBinary()); - assertEquals(objectId.getValue(), result.getLink().getValue()); - } - - @Test - void toModel_null() { - //When + Then - assertNull(SplitInfoMapper.toModel(null)); - assertNull(SplitInfoMapper.toModel(Types.SplitInfo.getDefaultInstance())); - } -} diff --git a/models/src/test/java/info/frostfs/sdk/mappers/object/patch/AddressMapperTest.java b/models/src/test/java/info/frostfs/sdk/mappers/object/patch/AddressMapperTest.java deleted file mode 100644 index b53ff87..0000000 --- a/models/src/test/java/info/frostfs/sdk/mappers/object/patch/AddressMapperTest.java +++ /dev/null @@ -1,39 +0,0 @@ -package info.frostfs.sdk.mappers.object.patch; - -import info.frostfs.sdk.dto.container.ContainerId; -import info.frostfs.sdk.dto.object.ObjectId; -import info.frostfs.sdk.dto.object.patch.Address; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; - -public class AddressMapperTest { - - @Test - void toGrpcMessage_success() { - //Given - var objectId = new ObjectId("85orCLKSu3X1jGiTFmwmTUsBU88RBARNwuRwrEy5pyww"); - var containerId = new ContainerId("EQGx2QeYHJb53uRwYGzcQaW191sZpdNrjutk6veUSV2R"); - var address = new Address(objectId, containerId); - - //When - var result = AddressMapper.toGrpcMessage(address); - - //Then - assertNotNull(result); - assertEquals( - address.getContainerId().getValue(), - new ContainerId(result.getContainerId().getValue().toByteArray()).getValue() - ); - assertEquals( - address.getObjectId().getValue(), - new ObjectId(result.getObjectId().getValue().toByteArray()).getValue() - ); - } - - @Test - void toGrpcMessage_null() { - //When + Then - assertNull(AddressMapper.toGrpcMessage(null)); - } -} diff --git a/models/src/test/java/info/frostfs/sdk/mappers/object/patch/RangeMapperTest.java b/models/src/test/java/info/frostfs/sdk/mappers/object/patch/RangeMapperTest.java deleted file mode 100644 index f78a482..0000000 --- a/models/src/test/java/info/frostfs/sdk/mappers/object/patch/RangeMapperTest.java +++ /dev/null @@ -1,59 +0,0 @@ -package info.frostfs.sdk.mappers.object.patch; - -import info.frostfs.sdk.dto.object.patch.Range; -import org.apache.commons.collections4.CollectionUtils; -import org.junit.jupiter.api.Test; - -import java.util.Arrays; -import java.util.Collections; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; - -public class RangeMapperTest { - - @Test - void toGrpcMessages_success() { - //Given - var range1 = new Range(1, 10); - var range2 = new Range(2, 20); - - //When - var result = RangeMapper.toGrpcMessages(Arrays.asList(range1, range2)); - - //Then - assertNotNull(result); - assertThat(result).isNotNull().hasSize(2); - assertEquals(range1.getOffset(), result.get(0).getOffset()); - assertEquals(range1.getLength(), result.get(0).getLength()); - assertEquals(range2.getOffset(), result.get(1).getOffset()); - assertEquals(range2.getLength(), result.get(1).getLength()); - } - - @Test - void toGrpcMessages_null() { - //When + Then - assertTrue(CollectionUtils.isEmpty(RangeMapper.toGrpcMessages(null))); - assertTrue(CollectionUtils.isEmpty(RangeMapper.toGrpcMessages(Collections.emptyList()))); - } - - @Test - void toGrpcMessage_success() { - //Given - var range = new Range(1, 10); - - //When - var result = RangeMapper.toGrpcMessage(range); - - //Then - assertNotNull(result); - assertEquals(range.getOffset(), result.getOffset()); - assertEquals(range.getLength(), result.getLength()); - } - - @Test - void toGrpcMessage_null() { - //When + Then - assertNull(RangeMapper.toGrpcMessage(null)); - } -} diff --git a/models/src/test/java/info/frostfs/sdk/mappers/response/MetaHeaderMapperTest.java b/models/src/test/java/info/frostfs/sdk/mappers/response/MetaHeaderMapperTest.java deleted file mode 100644 index ad13e4f..0000000 --- a/models/src/test/java/info/frostfs/sdk/mappers/response/MetaHeaderMapperTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package info.frostfs.sdk.mappers.response; - -import frostfs.session.Types; -import info.frostfs.sdk.dto.netmap.Version; -import info.frostfs.sdk.dto.response.MetaHeader; -import info.frostfs.sdk.exceptions.ValidationFrostFSException; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; - -public class MetaHeaderMapperTest { - - @Test - void toGrpcMessage_success() { - //Given - var version = new Version(1, 2); - var metaHeader = new MetaHeader(version, 1, 2); - - //When - Types.RequestMetaHeader result = MetaHeaderMapper.toGrpcMessage(metaHeader); - - //Then - assertNotNull(result); - assertEquals(metaHeader.getEpoch(), result.getEpoch()); - assertEquals(metaHeader.getTtl(), result.getTtl()); - assertEquals(metaHeader.getVersion().getMajor(), result.getVersion().getMajor()); - assertEquals(metaHeader.getVersion().getMinor(), result.getVersion().getMinor()); - } - - @Test - void toGrpcMessage_null() { - //When + Then - assertThrows(ValidationFrostFSException.class, () -> MetaHeaderMapper.toGrpcMessage(null)); - } - - @Test - void toGrpcMessageBuilder_success() { - //Given - var version = new Version(1, 2); - var metaHeader = new MetaHeader(version, 1, 2); - - //When - Types.RequestMetaHeader.Builder result = MetaHeaderMapper.toGrpcMessageBuilder(metaHeader); - - //Then - assertNotNull(result); - assertEquals(metaHeader.getEpoch(), result.getEpoch()); - assertEquals(metaHeader.getTtl(), result.getTtl()); - assertEquals(metaHeader.getVersion().getMajor(), result.getVersion().getMajor()); - assertEquals(metaHeader.getVersion().getMinor(), result.getVersion().getMinor()); - } - - @Test - void toGrpcMessageBuilder_null() { - //When + Then - assertThrows(ValidationFrostFSException.class, () -> MetaHeaderMapper.toGrpcMessageBuilder(null)); - } -} diff --git a/models/src/test/java/info/frostfs/sdk/mappers/response/ResponseStatusMapperTest.java b/models/src/test/java/info/frostfs/sdk/mappers/response/ResponseStatusMapperTest.java deleted file mode 100644 index 09bb763..0000000 --- a/models/src/test/java/info/frostfs/sdk/mappers/response/ResponseStatusMapperTest.java +++ /dev/null @@ -1,54 +0,0 @@ -package info.frostfs.sdk.mappers.response; - -import frostfs.status.Types; -import info.frostfs.sdk.enums.StatusCode; -import info.frostfs.sdk.exceptions.ProcessFrostFSException; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.EnumSource; - -import static org.junit.jupiter.api.Assertions.*; - -public class ResponseStatusMapperTest { - - @ParameterizedTest - @EnumSource(value = StatusCode.class) - void toModel_success(StatusCode statusCode) { - //Given - var status = Types.Status.newBuilder() - .setCode(statusCode.value) - .setMessage("test") - .build(); - - //When - var result = ResponseStatusMapper.toModel(status); - - //Then - assertNotNull(result); - assertEquals(status.getCode(), result.getCode().value); - assertEquals(status.getMessage(), result.getMessage()); - } - - @Test - void toModel_null() { - //When - var result = ResponseStatusMapper.toModel(null); - - //Then - assertNotNull(result); - assertEquals(StatusCode.SUCCESS.value, result.getCode().value); - assertEquals("", result.getMessage()); - } - - @Test - void toModel_notValid() { - //Given - var status = Types.Status.newBuilder() - .setCode(-1) - .setMessage("test") - .build(); - - //When + Then - assertThrows(ProcessFrostFSException.class, () -> ResponseStatusMapper.toModel(status)); - } -} diff --git a/models/src/test/java/info/frostfs/sdk/mappers/response/SignatureMapperTest.java b/models/src/test/java/info/frostfs/sdk/mappers/response/SignatureMapperTest.java deleted file mode 100644 index c9a4474..0000000 --- a/models/src/test/java/info/frostfs/sdk/mappers/response/SignatureMapperTest.java +++ /dev/null @@ -1,57 +0,0 @@ -package info.frostfs.sdk.mappers.response; - -import frostfs.refs.Types; -import info.frostfs.sdk.dto.response.Signature; -import info.frostfs.sdk.enums.SignatureScheme; -import info.frostfs.sdk.exceptions.ProcessFrostFSException; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.EnumSource; -import org.mockito.MockedStatic; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.mockStatic; - -public class SignatureMapperTest { - - @ParameterizedTest - @EnumSource(value = SignatureScheme.class) - void toGrpcMessage_success(SignatureScheme scheme) { - //Given - var signature = new Signature(); - signature.setKey(new byte[]{1, 2, 3}); - signature.setSign(new byte[]{4, 5, 6}); - signature.setScheme(scheme); - - //When - var result = SignatureMapper.toGrpcMessage(signature); - - //Then - assertNotNull(result); - assertThat(result.getKey().toByteArray()).containsExactly(signature.getKey()); - assertThat(result.getSign().toByteArray()).containsExactly(signature.getSign()); - assertEquals(signature.getScheme().value, result.getScheme().getNumber()); - } - - @Test - void toGrpcMessage_null() { - //When + Then - assertNull(SignatureMapper.toGrpcMessage(null)); - } - - @Test - void toGrpcMessage_notValidScheme() { - //Given - var signature = new Signature(); - signature.setScheme(SignatureScheme.ECDSA_SHA512); - - //When + Then - try (MockedStatic mockStatic = mockStatic(Types.SignatureScheme.class)) { - mockStatic.when(() -> Types.SignatureScheme.forNumber(signature.getScheme().value)) - .thenReturn(null); - - assertThrows(ProcessFrostFSException.class, () -> SignatureMapper.toGrpcMessage(signature)); - } - } -} diff --git a/models/src/test/java/info/frostfs/sdk/mappers/session/SessionMapperTest.java b/models/src/test/java/info/frostfs/sdk/mappers/session/SessionMapperTest.java deleted file mode 100644 index b85e0ce..0000000 --- a/models/src/test/java/info/frostfs/sdk/mappers/session/SessionMapperTest.java +++ /dev/null @@ -1,68 +0,0 @@ -package info.frostfs.sdk.mappers.session; - -import com.google.protobuf.ByteString; -import frostfs.session.Types; -import info.frostfs.sdk.exceptions.ValidationFrostFSException; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; - -public class SessionMapperTest { - private static final byte[] SERIALIZED_TOKEN = new byte[] - {10, 21, 10, 5, 1, 2, 3, 4, 5, 26, 6, 8, 1, 16, 3, 24, 2, 34, 4, 6, 7, 8, 9}; - - @Test - void serialize_success() { - //Given - var sessionToken = createSessionToken(); - - //When - var result = SessionMapper.serialize(sessionToken); - - //Then - assertNotNull(result); - assertThat(result).hasSize(23).containsExactly(SERIALIZED_TOKEN); - } - - @Test - void serialize_wrong() { - //When + Then - assertThrows(ValidationFrostFSException.class, () -> SessionMapper.serialize(null)); - } - - @Test - void deserialize_success() { - //When - var result = SessionMapper.deserializeSessionToken(SERIALIZED_TOKEN); - - //Then - assertNotNull(result); - assertEquals(createSessionToken(), result); - } - - @Test - void deserialize_wrong() { - //When + Then - assertThrows(ValidationFrostFSException.class, () -> SessionMapper.deserializeSessionToken(null)); - assertThrows(ValidationFrostFSException.class, () -> SessionMapper.deserializeSessionToken(new byte[]{})); - } - - private Types.SessionToken createSessionToken() { - var lifetime = Types.SessionToken.Body.TokenLifetime.newBuilder() - .setExp(1) - .setIat(2) - .setNbf(3) - .build(); - - var body = Types.SessionToken.Body.newBuilder() - .setId(ByteString.copyFrom(new byte[]{1, 2, 3, 4, 5})) - .setSessionKey(ByteString.copyFrom(new byte[]{6, 7, 8, 9})) - .setLifetime(lifetime) - .build(); - - return Types.SessionToken.newBuilder() - .setBody(body) - .build(); - } -} diff --git a/pom.xml b/pom.xml deleted file mode 100644 index d8de384..0000000 --- a/pom.xml +++ /dev/null @@ -1,189 +0,0 @@ - - - 4.0.0 - - info.frostfs.sdk - frostfs-sdk-java - ${revision} - pom - - client - cryptography - models - protos - exceptions - - - - 0.12.0 - - 11 - 11 - UTF-8 - checkstyle.xml - 5.14.2 - 5.10.3 - 3.26.3 - 1.18.34 - 3.23.0 - 3.23.0 - - - - - org.apache.commons - commons-collections4 - 4.4 - - - org.apache.commons - commons-lang3 - 3.14.0 - - - commons-codec - commons-codec - 1.18.0 - - - org.projectlombok - lombok - ${lombok.version} - provided - true - - - io.neow3j - contract - ${neow3j.version} - - - org.junit.jupiter - junit-jupiter - ${junit.version} - test - - - org.assertj - assertj-core - ${assertj.version} - test - - - org.mockito - mockito-core - ${mockito.version} - test - - - org.mockito - mockito-junit-jupiter - ${mockito.version} - test - - - org.yaml - snakeyaml - 2.4 - - - - - - - org.apache.maven.plugins - maven-checkstyle-plugin - - - checkstyle - validate - - check - - - true - - - - 3.4.0 - - - org.apache.maven.plugins - maven-surefire-plugin - 2.22.0 - - - org.apache.maven.plugins - maven-failsafe-plugin - 2.22.0 - - - org.apache.maven.plugins - maven-resources-plugin - 3.3.0 - - - copy-resources - package - - copy-resources - - - ../target/ - - - ${basedir}/target - - /client* - - - - - - - - - org.codehaus.mojo - flatten-maven-plugin - 1.0.0 - - true - - - - flatten - process-resources - - flatten - - - - flatten.clean - clean - - clean - - - - - - - - - TrueCloudLab - https://git.frostfs.info/api/packages/TrueCloudLab/maven - - - - - TrueCloudLab - https://git.frostfs.info/api/packages/TrueCloudLab/maven - - - TrueCloudLab - https://git.frostfs.info/api/packages/TrueCloudLab/maven - - - diff --git a/protos/pom.xml b/protos/pom.xml deleted file mode 100644 index f5ea90a..0000000 --- a/protos/pom.xml +++ /dev/null @@ -1,105 +0,0 @@ - - - 4.0.0 - - info.frostfs.sdk - frostfs-sdk-java - ${revision} - - - protos - - - 11 - 11 - 1.65.1 - UTF-8 - - - - - io.grpc - grpc-netty - ${grpc.version} - - - io.grpc - grpc-protobuf - ${grpc.version} - - - io.grpc - grpc-stub - ${grpc.version} - - - io.grpc - grpc-services - ${grpc.version} - runtime - - - javax.annotation - javax.annotation-api - 1.3.2 - - - com.google.protobuf - protobuf-java - ${protobuf.version} - - - - - - - io.grpc - grpc-bom - ${grpc.version} - pom - import - - - - - - - - kr.motd.maven - os-maven-plugin - 1.6.2 - - - - - org.xolstice.maven.plugins - protobuf-maven-plugin - 0.6.1 - - - com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier} - - grpc-java - - io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier} - - - - - - compile - compile-custom - - test-compile - test-compile-custom - - - - - - - - \ No newline at end of file diff --git a/protos/src/main/proto/accounting/service.proto b/protos/src/main/proto/accounting/service.proto deleted file mode 100644 index 39e838a..0000000 --- a/protos/src/main/proto/accounting/service.proto +++ /dev/null @@ -1,70 +0,0 @@ -syntax = "proto3"; - -package neo.fs.v2.accounting; - -option java_package = "frostfs.accounting"; - -import "accounting/types.proto"; -import "refs/types.proto"; -import "session/types.proto"; - -// Accounting service provides methods for interaction with FrostFS sidechain -// via other FrostFS nodes to get information about the account balance. Deposit -// and Withdraw operations can't be implemented here, as they require Mainnet -// FrostFS smart contract invocation. Transfer operations between internal -// FrostFS accounts are possible if both use the same token type. -service AccountingService { - // Returns the amount of funds in GAS token for the requested FrostFS account. - // - // Statuses: - // - **OK** (0, SECTION_SUCCESS): - // balance has been successfully read; - // - Common failures (SECTION_FAILURE_COMMON). - rpc Balance(BalanceRequest) returns (BalanceResponse); -} - -// BalanceRequest message -message BalanceRequest { - // To indicate the account for which the balance is requested, its identifier - // is used. It can be any existing account in FrostFS sidechain `Balance` - // smart contract. If omitted, client implementation MUST set it to the - // request's signer `OwnerID`. - message Body { - // Valid user identifier in `OwnerID` format for which the balance is - // requested. Required field. - neo.fs.v2.refs.OwnerID owner_id = 1; - } - // Body of the balance request message. - Body body = 1; - - // Carries request meta information. Header data is used only to regulate - // message transport and does not affect request execution. - neo.fs.v2.session.RequestMetaHeader meta_header = 2; - - // Carries request verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.RequestVerificationHeader verify_header = 3; -} - -// BalanceResponse message -message BalanceResponse { - // The amount of funds in GAS token for the `OwnerID`'s account requested. - // Balance is given in the `Decimal` format to avoid precision issues with - // rounding. - message Body { - // Amount of funds in GAS token for the requested account. - Decimal balance = 1; - } - // Body of the balance response message. - Body body = 1; - - // Carries response meta information. Header data is used only to regulate - // message transport and does not affect request execution. - neo.fs.v2.session.ResponseMetaHeader meta_header = 2; - - // Carries response verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.ResponseVerificationHeader verify_header = 3; -} diff --git a/protos/src/main/proto/accounting/types.proto b/protos/src/main/proto/accounting/types.proto deleted file mode 100644 index db85a59..0000000 --- a/protos/src/main/proto/accounting/types.proto +++ /dev/null @@ -1,21 +0,0 @@ -syntax = "proto3"; - -package neo.fs.v2.accounting; - -option java_package = "frostfs.accounting"; - -// Standard floating point data type can't be used in FrostFS due to inexactness -// of the result when doing lots of small number operations. To solve the lost -// precision issue, special `Decimal` format is used for monetary computations. -// -// Please see [The General Decimal Arithmetic -// Specification](http://speleotrove.com/decimal/) for detailed problem -// description. -message Decimal { - // Number in the smallest Token fractions. - int64 value = 1 [ json_name = "value" ]; - - // Precision value indicating how many smallest fractions can be in one - // integer. - uint32 precision = 2 [ json_name = "precision" ]; -} diff --git a/protos/src/main/proto/acl/types.proto b/protos/src/main/proto/acl/types.proto deleted file mode 100644 index 981e946..0000000 --- a/protos/src/main/proto/acl/types.proto +++ /dev/null @@ -1,248 +0,0 @@ -syntax = "proto3"; - -package neo.fs.v2.acl; - -option java_package = "frostfs.acl"; - -import "refs/types.proto"; -import "ape/types.proto"; - -// Target role of the access control rule in access control list. -enum Role { - // Unspecified role, default value - ROLE_UNSPECIFIED = 0; - - // User target rule is applied if sender is the owner of the container - USER = 1; - - // System target rule is applied if sender is a storage node within the - // container or an inner ring node - SYSTEM = 2; - - // Others target rule is applied if sender is neither a user nor a system - // target - OTHERS = 3; -} - -// MatchType is an enumeration of match types. -enum MatchType { - // Unspecified match type, default value. - MATCH_TYPE_UNSPECIFIED = 0; - - // Return true if strings are equal - STRING_EQUAL = 1; - - // Return true if strings are different - STRING_NOT_EQUAL = 2; -} - -// Request's operation type to match if the rule is applicable to a particular -// request. -enum Operation { - // Unspecified operation, default value - OPERATION_UNSPECIFIED = 0; - - // Get - GET = 1; - - // Head - HEAD = 2; - - // Put - PUT = 3; - - // Delete - DELETE = 4; - - // Search - SEARCH = 5; - - // GetRange - GETRANGE = 6; - - // GetRangeHash - GETRANGEHASH = 7; -} - -// Rule execution result action. Either allows or denies access if the rule's -// filters match. -enum Action { - // Unspecified action, default value - ACTION_UNSPECIFIED = 0; - - // Allow action - ALLOW = 1; - - // Deny action - DENY = 2; -} - -// Enumeration of possible sources of Headers to apply filters. -enum HeaderType { - // Unspecified header, default value. - HEADER_UNSPECIFIED = 0; - - // Filter request headers - REQUEST = 1; - - // Filter object headers - OBJECT = 2; - - // Filter service headers. These are not processed by FrostFS nodes and - // exist for service use only. - SERVICE = 3; -} - -// Describes a single eACL rule. -message EACLRecord { - // FrostFS request Verb to match - Operation operation = 1 [ json_name = "operation" ]; - - // Rule execution result. Either allows or denies access if filters match. - Action action = 2 [ json_name = "action" ]; - - // Filter to check particular properties of the request or the object. - // - // By default `key` field refers to the corresponding object's `Attribute`. - // Some Object's header fields can also be accessed by adding `$Object:` - // prefix to the name. Here is the list of fields available via this prefix: - // - // * $Object:version \ - // version - // * $Object:objectID \ - // object_id - // * $Object:containerID \ - // container_id - // * $Object:ownerID \ - // owner_id - // * $Object:creationEpoch \ - // creation_epoch - // * $Object:payloadLength \ - // payload_length - // * $Object:payloadHash \ - // payload_hash - // * $Object:objectType \ - // object_type - // * $Object:homomorphicHash \ - // homomorphic_hash - // - // Please note, that if request or response does not have object's headers of - // full object (Range, RangeHash, Search, Delete), it will not be possible to - // filter by object header fields or user attributes. From the well-known list - // only `$Object:objectID` and `$Object:containerID` will be available, as - // it's possible to take that information from the requested address. - message Filter { - // Define if Object or Request header will be used - HeaderType header_type = 1 [ json_name = "headerType" ]; - - // Match operation type - MatchType match_type = 2 [ json_name = "matchType" ]; - - // Name of the Header to use - string key = 3 [ json_name = "key" ]; - - // Expected Header Value or pattern to match - string value = 4 [ json_name = "value" ]; - } - - // List of filters to match and see if rule is applicable - repeated Filter filters = 3 [ json_name = "filters" ]; - - // Target to apply ACL rule. Can be a subject's role class or a list of public - // keys to match. - message Target { - // Target subject's role class - Role role = 1 [ json_name = "role" ]; - - // List of public keys to identify target subject - repeated bytes keys = 2 [ json_name = "keys" ]; - } - // List of target subjects to apply ACL rule to - repeated Target targets = 4 [ json_name = "targets" ]; -} - -// Extended ACL rules table. A list of ACL rules defined additionally to Basic -// ACL. Extended ACL rules can be attached to a container and can be updated -// or may be defined in `BearerToken` structure. Please see the corresponding -// FrostFS Technical Specification section for detailed description. -message EACLTable { - // eACL format version. Effectively, the version of API library used to create - // eACL Table. - neo.fs.v2.refs.Version version = 1 [ json_name = "version" ]; - - // Identifier of the container that should use given access control rules - neo.fs.v2.refs.ContainerID container_id = 2 [ json_name = "containerID" ]; - - // List of Extended ACL rules - repeated EACLRecord records = 3 [ json_name = "records" ]; -} - -// BearerToken allows to attach signed Extended ACL rules to the request in -// `RequestMetaHeader`. If container's Basic ACL rules allow, the attached rule -// set will be checked instead of one attached to the container itself. Just -// like [JWT](https://jwt.io), it has a limited lifetime and scope, hence can be -// used in the similar use cases, like providing authorisation to externally -// authenticated party. -// -// BearerToken can be issued only by the container's owner and must be signed -// using the key associated with the container's `OwnerID`. -message BearerToken { - // Bearer Token body structure contains Extended ACL table issued by the - // container owner with additional information preventing token abuse. - message Body { - // Table of Extended ACL rules to use instead of the ones attached to the - // container. If it contains `container_id` field, bearer token is only - // valid for this specific container. Otherwise, any container of the same - // owner is allowed. - // - // Deprecated: eACL tables are no longer relevant - `APEOverrides` should be - // used instead. - EACLTable eacl_table = 1 [ json_name = "eaclTable" ]; - - // `OwnerID` defines to whom the token was issued. It must match the request - // originator's `OwnerID`. If empty, any token bearer will be accepted. - neo.fs.v2.refs.OwnerID owner_id = 2 [ json_name = "ownerID" ]; - - // Lifetime parameters of the token. Field names taken from - // [rfc7519](https://tools.ietf.org/html/rfc7519). - message TokenLifetime { - // Expiration Epoch - uint64 exp = 1 [ json_name = "exp" ]; - - // Not valid before Epoch - uint64 nbf = 2 [ json_name = "nbf" ]; - - // Issued at Epoch - uint64 iat = 3 [ json_name = "iat" ]; - } - // Token expiration and valid time period parameters - TokenLifetime lifetime = 3 [ json_name = "lifetime" ]; - - // AllowImpersonate flag to consider token signer as request owner. - // If this field is true extended ACL table in token body isn't processed. - bool allow_impersonate = 4 [ json_name = "allowImpersonate" ]; - - // APEOverride is the list of APE chains defined for a target. - // These chains are meant to serve as overrides to the already defined (or - // even undefined) APE chains for the target (see contract `Policy`). - // - // The server-side processing of the bearer token with set APE overrides - // must verify if a client is permitted to override chains for the target, - // preventing unauthorized access through the APE mechanism. - message APEOverride { - // Target for which chains are applied. - frostfs.v2.ape.ChainTarget target = 1 [ json_name = "target" ]; - - // The list of APE chains. - repeated frostfs.v2.ape.Chain chains = 2 [ json_name = "chains" ]; - } - - // APE override for the target. - APEOverride ape_override = 5 [ json_name = "apeOverride" ]; - } - // Bearer Token body - Body body = 1 [ json_name = "body" ]; - - // Signature of BearerToken body - neo.fs.v2.refs.Signature signature = 2 [ json_name = "signature" ]; -} diff --git a/protos/src/main/proto/ape/types.proto b/protos/src/main/proto/ape/types.proto deleted file mode 100644 index 96578bc..0000000 --- a/protos/src/main/proto/ape/types.proto +++ /dev/null @@ -1,33 +0,0 @@ -syntax = "proto3"; - -package frostfs.v2.ape; - -option java_package = "frostfs.ape"; - -// TargetType is a type target to which a rule chain is defined. -enum TargetType { - UNDEFINED = 0; - - NAMESPACE = 1; - - CONTAINER = 2; - - USER = 3; - - GROUP = 4; -} - -// ChainTarget is an object to which a rule chain is defined. -message ChainTarget { - TargetType type = 1; - - string name = 2; -} - -// Chain is a chain of rules defined for a specific target. -message Chain { - oneof kind { - // Raw representation of a serizalized rule chain. - bytes raw = 1; - } -} diff --git a/protos/src/main/proto/apemanager/service.proto b/protos/src/main/proto/apemanager/service.proto deleted file mode 100644 index f75f013..0000000 --- a/protos/src/main/proto/apemanager/service.proto +++ /dev/null @@ -1,171 +0,0 @@ -syntax = "proto3"; - -package frostfs.v2.apemanager; - -option java_package = "frostfs.apemanager"; - -import "ape/types.proto"; -import "session/types.proto"; - -// `APEManagerService` provides API to manage rule chains within sidechain's -// `Policy` smart contract. -service APEManagerService { - // Add a rule chain for a specific target to `Policy` smart contract. - // - // Statuses: - // - **OK** (0, SECTION_SUCCESS): \ - // the chain has been successfully added; - // - Common failures (SECTION_FAILURE_COMMON); - // - **CONTAINER_NOT_FOUND** (3072, SECTION_CONTAINER): \ - // container (as target) not found; - // - **APE_MANAGER_ACCESS_DENIED** (5120, SECTION_APE_MANAGER): \ - // the operation is denied by the service. - rpc AddChain(AddChainRequest) returns (AddChainResponse); - - // Remove a rule chain for a specific target from `Policy` smart contract. - // RemoveChain is an idempotent operation: removal of non-existing rule chain - // also means success. - // - // Statuses: - // - **OK** (0, SECTION_SUCCESS): \ - // the chain has been successfully removed; - // - Common failures (SECTION_FAILURE_COMMON); - // - **CONTAINER_NOT_FOUND** (3072, SECTION_CONTAINER): \ - // container (as target) not found; - // - **APE_MANAGER_ACCESS_DENIED** (5120, SECTION_APE_MANAGER): \ - // the operation is denied by the service. - rpc RemoveChain(RemoveChainRequest) returns (RemoveChainResponse); - - // List chains defined for a specific target from `Policy` smart contract. - // - // Statuses: - // - **OK** (0, SECTION_SUCCESS): \ - // chains have been successfully listed; - // - Common failures (SECTION_FAILURE_COMMON); - // - **CONTAINER_NOT_FOUND** (3072, SECTION_CONTAINER): \ - // container (as target) not found; - // - **APE_MANAGER_ACCESS_DENIED** (5120, SECTION_APE_MANAGER): \ - // the operation is denied by the service. - rpc ListChains(ListChainsRequest) returns (ListChainsResponse); -} - -message AddChainRequest { - message Body { - // A target for which a rule chain is added. - frostfs.v2.ape.ChainTarget target = 1; - - // The chain to set for the target. - frostfs.v2.ape.Chain chain = 2; - } - - // The request's body. - Body body = 1; - - // Carries request meta information. Header data is used only to regulate - // message transport and does not affect request execution. - neo.fs.v2.session.RequestMetaHeader meta_header = 2; - - // Carries request verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.RequestVerificationHeader verify_header = 3; -} - -message AddChainResponse { - message Body { - // Chain ID assigned for the added rule chain. - // If chain ID is left empty in the request, then - // it will be generated. - bytes chain_id = 1; - } - - // The response's body. - Body body = 1; - - // Carries response meta information. Header data is used only to regulate - // message transport and does not affect request execution. - neo.fs.v2.session.ResponseMetaHeader meta_header = 2; - - // Carries response verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.ResponseVerificationHeader verify_header = 3; -} - -message RemoveChainRequest { - message Body { - // Target for which a rule chain is removed. - frostfs.v2.ape.ChainTarget target = 1; - - // Chain ID assigned for the rule chain. - bytes chain_id = 2; - } - - // The request's body. - Body body = 1; - - // Carries request meta information. Header data is used only to regulate - // message transport and does not affect request execution. - neo.fs.v2.session.RequestMetaHeader meta_header = 2; - - // Carries request verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.RequestVerificationHeader verify_header = 3; -} - -message RemoveChainResponse { - // Since RemoveChain is an idempotent operation, then the only indicator that - // operation could not be performed is an error returning to a client. - message Body {} - - // The response's body. - Body body = 1; - - // Carries response meta information. Header data is used only to regulate - // message transport and does not affect request execution. - neo.fs.v2.session.ResponseMetaHeader meta_header = 2; - - // Carries response verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.ResponseVerificationHeader verify_header = 3; -} - -message ListChainsRequest { - message Body { - // Target for which rule chains are listed. - frostfs.v2.ape.ChainTarget target = 1; - } - - // The request's body. - Body body = 1; - - // Carries request meta information. Header data is used only to regulate - // message transport and does not affect request execution. - neo.fs.v2.session.RequestMetaHeader meta_header = 2; - - // Carries request verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.RequestVerificationHeader verify_header = 3; -} - -message ListChainsResponse { - message Body { - // The list of chains defined for the reqeusted target. - repeated frostfs.v2.ape.Chain chains = 1; - } - - // The response's body. - Body body = 1; - - // Carries response meta information. Header data is used only to regulate - // message transport and does not affect request execution. - neo.fs.v2.session.ResponseMetaHeader meta_header = 2; - - // Carries response verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.ResponseVerificationHeader verify_header = 3; -} diff --git a/protos/src/main/proto/container/service.proto b/protos/src/main/proto/container/service.proto deleted file mode 100644 index a650502..0000000 --- a/protos/src/main/proto/container/service.proto +++ /dev/null @@ -1,246 +0,0 @@ -syntax = "proto3"; - -package neo.fs.v2.container; - -option java_package = "frostfs.container"; - -import "container/types.proto"; -import "refs/types.proto"; -import "session/types.proto"; - -// `ContainerService` provides API to interact with `Container` smart contract -// in FrostFS sidechain via other FrostFS nodes. All of those actions can be -// done equivalently by directly issuing transactions and RPC calls to sidechain -// nodes. -service ContainerService { - // `Put` invokes `Container` smart contract's `Put` method and returns - // response immediately. After a new block is issued in sidechain, request is - // verified by Inner Ring nodes. After one more block in sidechain, the - // container is added into smart contract storage. - // - // Statuses: - // - **OK** (0, SECTION_SUCCESS): \ - // request to save the container has been sent to the sidechain; - // - Common failures (SECTION_FAILURE_COMMON); - // - **CONTAINER_ACCESS_DENIED** (3074, SECTION_CONTAINER): \ - // container create access denied. - rpc Put(PutRequest) returns (PutResponse); - - // `Delete` invokes `Container` smart contract's `Delete` method and returns - // response immediately. After a new block is issued in sidechain, request is - // verified by Inner Ring nodes. After one more block in sidechain, the - // container is added into smart contract storage. - // - // Statuses: - // - **OK** (0, SECTION_SUCCESS): \ - // request to remove the container has been sent to the sidechain; - // - Common failures (SECTION_FAILURE_COMMON); - // - **CONTAINER_ACCESS_DENIED** (3074, SECTION_CONTAINER): \ - // container delete access denied. - rpc Delete(DeleteRequest) returns (DeleteResponse); - - // Returns container structure from `Container` smart contract storage. - // - // Statuses: - // - **OK** (0, SECTION_SUCCESS): \ - // container has been successfully read; - // - Common failures (SECTION_FAILURE_COMMON); - // - **CONTAINER_NOT_FOUND** (3072, SECTION_CONTAINER): \ - // requested container not found; - // - **CONTAINER_ACCESS_DENIED** (3074, SECTION_CONTAINER): \ - // access to container is denied. - rpc Get(GetRequest) returns (GetResponse); - - // Returns all owner's containers from 'Container` smart contract' storage. - // - // Statuses: - // - **OK** (0, SECTION_SUCCESS): \ - // container list has been successfully read; - // - Common failures (SECTION_FAILURE_COMMON); - // - **CONTAINER_ACCESS_DENIED** (3074, SECTION_CONTAINER): \ - // container list access denied. - rpc List(ListRequest) returns (ListResponse); -} - -// New FrostFS Container creation request -message PutRequest { - // Container creation request has container structure's signature as a - // separate field. It's not stored in sidechain, just verified on container - // creation by `Container` smart contract. `ContainerID` is a SHA256 hash of - // the stable-marshalled container strucutre, hence there is no need for - // additional signature checks. - message Body { - // Container structure to register in FrostFS - container.Container container = 1; - - // Signature of a stable-marshalled container according to RFC-6979. - neo.fs.v2.refs.SignatureRFC6979 signature = 2; - } - // Body of container put request message. - Body body = 1; - - // Carries request meta information. Header data is used only to regulate - // message transport and does not affect request execution. - neo.fs.v2.session.RequestMetaHeader meta_header = 2; - - // Carries request verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.RequestVerificationHeader verify_header = 3; -} - -// New FrostFS Container creation response -message PutResponse { - // Container put response body contains information about the newly registered - // container as seen by `Container` smart contract. `ContainerID` can be - // calculated beforehand from the container structure and compared to the one - // returned here to make sure everything has been done as expected. - message Body { - // Unique identifier of the newly created container - neo.fs.v2.refs.ContainerID container_id = 1; - } - // Body of container put response message. - Body body = 1; - - // Carries response meta information. Header data is used only to regulate - // message transport and does not affect request execution. - neo.fs.v2.session.ResponseMetaHeader meta_header = 2; - - // Carries response verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.ResponseVerificationHeader verify_header = 3; -} - -// Container removal request -message DeleteRequest { - // Container removal request body has signed `ContainerID` as a proof of - // the container owner's intent. The signature will be verified by `Container` - // smart contract, so signing algorithm must be supported by NeoVM. - message Body { - // Identifier of the container to delete from FrostFS - neo.fs.v2.refs.ContainerID container_id = 1; - - // `ContainerID` signed with the container owner's key according to - // RFC-6979. - neo.fs.v2.refs.SignatureRFC6979 signature = 2; - } - // Body of container delete request message. - Body body = 1; - - // Carries request meta information. Header data is used only to regulate - // message transport and does not affect request execution. - neo.fs.v2.session.RequestMetaHeader meta_header = 2; - - // Carries request verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.RequestVerificationHeader verify_header = 3; -} - -// `DeleteResponse` has an empty body because delete operation is asynchronous -// and done via consensus in Inner Ring nodes. -message DeleteResponse { - // `DeleteResponse` has an empty body because delete operation is asynchronous - // and done via consensus in Inner Ring nodes. - message Body {} - // Body of container delete response message. - Body body = 1; - - // Carries response meta information. Header data is used only to regulate - // message transport and does not affect request execution. - neo.fs.v2.session.ResponseMetaHeader meta_header = 2; - - // Carries response verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.ResponseVerificationHeader verify_header = 3; -} - -// Get container structure -message GetRequest { - // Get container structure request body. - message Body { - // Identifier of the container to get - neo.fs.v2.refs.ContainerID container_id = 1; - } - // Body of container get request message. - Body body = 1; - - // Carries request meta information. Header data is used only to regulate - // message transport and does not affect request execution. - neo.fs.v2.session.RequestMetaHeader meta_header = 2; - - // Carries request verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.RequestVerificationHeader verify_header = 3; -} - -// Get container structure -message GetResponse { - // Get container response body does not have container structure signature. It - // has been already verified upon container creation. - message Body { - // Requested container structure - Container container = 1; - - // Signature of a stable-marshalled container according to RFC-6979. - neo.fs.v2.refs.SignatureRFC6979 signature = 2; - - // Session token if the container has been created within the session - neo.fs.v2.session.SessionToken session_token = 3; - } - // Body of container get response message. - Body body = 1; - - // Carries response meta information. Header data is used only to regulate - // message transport and does not affect request execution. - neo.fs.v2.session.ResponseMetaHeader meta_header = 2; - - // Carries response verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.ResponseVerificationHeader verify_header = 3; -} - -// List containers -message ListRequest { - // List containers request body. - message Body { - // Identifier of the container owner - neo.fs.v2.refs.OwnerID owner_id = 1; - } - // Body of list containers request message - Body body = 1; - - // Carries request meta information. Header data is used only to regulate - // message transport and does not affect request execution. - neo.fs.v2.session.RequestMetaHeader meta_header = 2; - - // Carries request verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.RequestVerificationHeader verify_header = 3; -} - -// List containers -message ListResponse { - // List containers response body. - message Body { - // List of `ContainerID`s belonging to the requested `OwnerID` - repeated refs.ContainerID container_ids = 1; - } - - // Body of list containers response message. - Body body = 1; - - // Carries response meta information. Header data is used only to regulate - // message transport and does not affect request execution. - neo.fs.v2.session.ResponseMetaHeader meta_header = 2; - - // Carries response verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.ResponseVerificationHeader verify_header = 3; -} diff --git a/protos/src/main/proto/container/types.proto b/protos/src/main/proto/container/types.proto deleted file mode 100644 index 7fbc8e5..0000000 --- a/protos/src/main/proto/container/types.proto +++ /dev/null @@ -1,75 +0,0 @@ -syntax = "proto3"; - -package neo.fs.v2.container; - -option java_package = "frostfs.container"; - -import "netmap/types.proto"; -import "refs/types.proto"; - -// Container is a structure that defines object placement behaviour. Objects can -// be stored only within containers. They define placement rule, attributes and -// access control information. An ID of a container is a 32 byte long SHA256 -// hash of stable-marshalled container message. -message Container { - // Container format version. Effectively, the version of API library used to - // create the container. - neo.fs.v2.refs.Version version = 1 [ json_name = "version" ]; - - // Identifier of the container owner - neo.fs.v2.refs.OwnerID owner_id = 2 [ json_name = "ownerID" ]; - - // Nonce is a 16 byte UUIDv4, used to avoid collisions of `ContainerID`s - bytes nonce = 3 [ json_name = "nonce" ]; - - // `BasicACL` contains access control rules for the owner, system and others - // groups, as well as permission bits for `BearerToken` and `Extended ACL` - uint32 basic_acl = 4 [ json_name = "basicACL" ]; - - // `Attribute` is a user-defined Key-Value metadata pair attached to the - // container. Container attributes are immutable. They are set at the moment - // of container creation and can never be added or updated. - // - // Key name must be a container-unique valid UTF-8 string. Value can't be - // empty. Containers with duplicated attribute names or attributes with empty - // values will be considered invalid. - // - // There are some "well-known" attributes affecting system behaviour: - // - // * [ __SYSTEM__NAME ] \ - // (`__NEOFS__NAME` is deprecated) \ - // String of a human-friendly container name registered as a domain in - // NNS contract. - // * [ __SYSTEM__ZONE ] \ - // (`__NEOFS__ZONE` is deprecated) \ - // String of a zone for `__SYSTEM__NAME` (`__NEOFS__NAME` is deprecated). - // Used as a TLD of a domain name in NNS contract. If no zone is specified, - // use default zone: `container`. - // * [ __SYSTEM__DISABLE_HOMOMORPHIC_HASHING ] \ - // (`__NEOFS__DISABLE_HOMOMORPHIC_HASHING` is deprecated) \ - // Disables homomorphic hashing for the container if the value equals "true" - // string. Any other values are interpreted as missing attribute. Container - // could be accepted in a FrostFS network only if the global network hashing - // configuration value corresponds with that attribute's value. After - // container inclusion, network setting is ignored. - // - // And some well-known attributes used by applications only: - // - // * Name \ - // Human-friendly name - // * Timestamp \ - // User-defined local time of container creation in Unix Timestamp format - message Attribute { - // Attribute name key - string key = 1 [ json_name = "key" ]; - - // Attribute value - string value = 2 [ json_name = "value" ]; - } - // Attributes represent immutable container's meta data - repeated Attribute attributes = 5 [ json_name = "attributes" ]; - - // Placement policy for the object inside the container - neo.fs.v2.netmap.PlacementPolicy placement_policy = 6 - [ json_name = "placementPolicy" ]; -} diff --git a/protos/src/main/proto/lock/types.proto b/protos/src/main/proto/lock/types.proto deleted file mode 100644 index 0578882..0000000 --- a/protos/src/main/proto/lock/types.proto +++ /dev/null @@ -1,18 +0,0 @@ -syntax = "proto3"; - -package neo.fs.v2.lock; - -option java_package = "frostfs.lock"; - -import "refs/types.proto"; - -// Lock objects protects a list of objects from being deleted. The lifetime of a -// lock object is limited similar to regular objects in -// `__SYSTEM__EXPIRATION_EPOCH` (`__NEOFS__EXPIRATION_EPOCH` is deprecated) -// attribute. Lock object MUST have expiration epoch. It is impossible to delete -// a lock object via ObjectService.Delete RPC call. -message Lock { - // List of objects to lock. Must not be empty or carry empty IDs. - // All members must be of the `REGULAR` type. - repeated neo.fs.v2.refs.ObjectID members = 1 [ json_name = "members" ]; -} diff --git a/protos/src/main/proto/netmap/service.proto b/protos/src/main/proto/netmap/service.proto deleted file mode 100644 index ef78107..0000000 --- a/protos/src/main/proto/netmap/service.proto +++ /dev/null @@ -1,161 +0,0 @@ -syntax = "proto3"; - -package neo.fs.v2.netmap; - -option java_package = "frostfs.netmap"; - -import "netmap/types.proto"; -import "refs/types.proto"; -import "session/types.proto"; - -// `NetmapService` provides methods to work with `Network Map` and the -// information required to build it. The resulting `Network Map` is stored in -// sidechain `Netmap` smart contract, while related information can be obtained -// from other FrostFS nodes. -service NetmapService { - // Get NodeInfo structure from the particular node directly. - // Node information can be taken from `Netmap` smart contract. In some cases, - // though, one may want to get recent information directly or to talk to the - // node not yet present in the `Network Map` to find out what API version can - // be used for further communication. This can be also used to check if a node - // is up and running. - // - // Statuses: - // - **OK** (0, SECTION_SUCCESS): - // information about the server has been successfully read; - // - Common failures (SECTION_FAILURE_COMMON). - rpc LocalNodeInfo(LocalNodeInfoRequest) returns (LocalNodeInfoResponse); - - // Read recent information about the FrostFS network. - // - // Statuses: - // - **OK** (0, SECTION_SUCCESS): - // information about the current network state has been successfully read; - // - Common failures (SECTION_FAILURE_COMMON). - rpc NetworkInfo(NetworkInfoRequest) returns (NetworkInfoResponse); - - // Returns network map snapshot of the current FrostFS epoch. - // - // Statuses: - // - **OK** (0, SECTION_SUCCESS): - // information about the current network map has been successfully read; - // - Common failures (SECTION_FAILURE_COMMON). - rpc NetmapSnapshot(NetmapSnapshotRequest) returns (NetmapSnapshotResponse); -} - -// Get NodeInfo structure directly from a particular node -message LocalNodeInfoRequest { - // LocalNodeInfo request body is empty. - message Body {} - // Body of the LocalNodeInfo request message - Body body = 1; - - // Carries request meta information. Header data is used only to regulate - // message transport and does not affect request execution. - neo.fs.v2.session.RequestMetaHeader meta_header = 2; - - // Carries request verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.RequestVerificationHeader verify_header = 3; -} - -// Local Node Info, including API Version in use -message LocalNodeInfoResponse { - // Local Node Info, including API Version in use. - message Body { - // Latest FrostFS API version in use - neo.fs.v2.refs.Version version = 1; - - // NodeInfo structure with recent information from node itself - NodeInfo node_info = 2; - } - // Body of the balance response message. - Body body = 1; - - // Carries response meta information. Header data is used only to regulate - // message transport and does not affect response execution. - neo.fs.v2.session.ResponseMetaHeader meta_header = 2; - - // Carries response verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.ResponseVerificationHeader verify_header = 3; -} - -// Get NetworkInfo structure with the network view from a particular node. -message NetworkInfoRequest { - // NetworkInfo request body is empty. - message Body {} - // Body of the NetworkInfo request message - Body body = 1; - - // Carries request meta information. Header data is used only to regulate - // message transport and does not affect request execution. - neo.fs.v2.session.RequestMetaHeader meta_header = 2; - - // Carries request verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.RequestVerificationHeader verify_header = 3; -} - -// Response with NetworkInfo structure including current epoch and -// sidechain magic number. -message NetworkInfoResponse { - // Information about the network. - message Body { - // NetworkInfo structure with recent information. - NetworkInfo network_info = 1; - } - // Body of the NetworkInfo response message. - Body body = 1; - - // Carries response meta information. Header data is used only to regulate - // message transport and does not affect response execution. - neo.fs.v2.session.ResponseMetaHeader meta_header = 2; - - // Carries response verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.ResponseVerificationHeader verify_header = 3; -} - -// Get netmap snapshot request -message NetmapSnapshotRequest { - // Get netmap snapshot request body. - message Body {} - - // Body of get netmap snapshot request message. - Body body = 1; - - // Carries request meta information. Header data is used only to regulate - // message transport and does not affect request execution. - neo.fs.v2.session.RequestMetaHeader meta_header = 2; - - // Carries request verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.RequestVerificationHeader verify_header = 3; -} - -// Response with current netmap snapshot -message NetmapSnapshotResponse { - // Get netmap snapshot response body - message Body { - // Structure of the requested network map. - Netmap netmap = 1 [ json_name = "netmap" ]; - } - - // Body of get netmap snapshot response message. - Body body = 1; - - // Carries response meta information. Header data is used only to regulate - // message transport and does not affect response execution. - neo.fs.v2.session.ResponseMetaHeader meta_header = 2; - - // Carries response verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.ResponseVerificationHeader verify_header = 3; -} diff --git a/protos/src/main/proto/netmap/types.proto b/protos/src/main/proto/netmap/types.proto deleted file mode 100644 index f861317..0000000 --- a/protos/src/main/proto/netmap/types.proto +++ /dev/null @@ -1,356 +0,0 @@ -syntax = "proto3"; - -package neo.fs.v2.netmap; - -option java_package = "frostfs.netmap"; - -// Operations on filters -enum Operation { - // No Operation defined - OPERATION_UNSPECIFIED = 0; - - // Equal - EQ = 1; - - // Not Equal - NE = 2; - - // Greater then - GT = 3; - - // Greater or equal - GE = 4; - - // Less then - LT = 5; - - // Less or equal - LE = 6; - - // Logical OR - OR = 7; - - // Logical AND - AND = 8; - - // Logical negation - NOT = 9; - - // Matches pattern - LIKE = 10; -} - -// Selector modifier shows how the node set will be formed. By default selector -// just groups nodes into a bucket by attribute, selecting nodes only by their -// hash distance. -enum Clause { - // No modifier defined. Nodes will be selected from the bucket randomly - CLAUSE_UNSPECIFIED = 0; - - // SAME will select only nodes having the same value of bucket attribute - SAME = 1; - - // DISTINCT will select nodes having different values of bucket attribute - DISTINCT = 2; -} - -// This filter will return the subset of nodes from `NetworkMap` or another -// filter's results that will satisfy filter's conditions. -message Filter { - // Name of the filter or a reference to a named filter. '*' means - // application to the whole unfiltered NetworkMap. At top level it's used as a - // filter name. At lower levels it's considered to be a reference to another - // named filter - string name = 1 [ json_name = "name" ]; - - // Key to filter - string key = 2 [ json_name = "key" ]; - - // Filtering operation - Operation op = 3 [ json_name = "op" ]; - - // Value to match - string value = 4 [ json_name = "value" ]; - - // List of inner filters. Top level operation will be applied to the whole - // list. - repeated Filter filters = 5 [ json_name = "filters" ]; -} - -// Selector chooses a number of nodes from the bucket taking the nearest nodes -// to the provided `ContainerID` by hash distance. -message Selector { - // Selector name to reference in object placement section - string name = 1 [ json_name = "name" ]; - - // How many nodes to select from the bucket - uint32 count = 2 [ json_name = "count" ]; - - // Selector modifier showing how to form a bucket - Clause clause = 3 [ json_name = "clause" ]; - - // Bucket attribute to select from - string attribute = 4 [ json_name = "attribute" ]; - - // Filter reference to select from - string filter = 5 [ json_name = "filter" ]; -} - -// Number of object replicas in a set of nodes from the defined selector. If no -// selector set, the root bucket containing all possible nodes will be used by -// default. -message Replica { - // How many object replicas to put - uint32 count = 1 [ json_name = "count" ]; - - // Named selector bucket to put replicas - string selector = 2 [ json_name = "selector" ]; - - // Data shards count - uint32 ec_data_count = 3 [ json_name = "ecDataCount" ]; - - // Parity shards count - uint32 ec_parity_count = 4 [ json_name = "ecParityCount" ]; -} - -// Set of rules to select a subset of nodes from `NetworkMap` able to store -// container's objects. The format is simple enough to transpile from different -// storage policy definition languages. -message PlacementPolicy { - // Rules to set number of object replicas and place each one into a named - // bucket - repeated Replica replicas = 1 [ json_name = "replicas" ]; - - // Container backup factor controls how deep FrostFS will search for nodes - // alternatives to include into container's nodes subset - uint32 container_backup_factor = 2 [ json_name = "containerBackupFactor" ]; - - // Set of Selectors to form the container's nodes subset - repeated Selector selectors = 3 [ json_name = "selectors" ]; - - // List of named filters to reference in selectors - repeated Filter filters = 4 [ json_name = "filters" ]; - - // Unique flag defines non-overlapping application for replicas - bool unique = 5 [ json_name = "unique" ]; -} - -// FrostFS node description -message NodeInfo { - // Public key of the FrostFS node in a binary format - bytes public_key = 1 [ json_name = "publicKey" ]; - - // Ways to connect to a node - repeated string addresses = 2 [ json_name = "addresses" ]; - - // Administrator-defined Attributes of the FrostFS Storage Node. - // - // `Attribute` is a Key-Value metadata pair. Key name must be a valid UTF-8 - // string. Value can't be empty. - // - // Attributes can be constructed into a chain of attributes: any attribute can - // have a parent attribute and a child attribute (except the first and the - // last one). A string representation of the chain of attributes in FrostFS - // Storage Node configuration uses ":" and "/" symbols, e.g.: - // - // `FrostFS_NODE_ATTRIBUTE_1=key1:val1/key2:val2` - // - // Therefore the string attribute representation in the Node configuration - // must use "\:", "\/" and "\\" escaped symbols if any of them appears in an - // attribute's key or value. - // - // Node's attributes are mostly used during Storage Policy evaluation to - // calculate object's placement and find a set of nodes satisfying policy - // requirements. There are some "well-known" node attributes common to all the - // Storage Nodes in the network and used implicitly with default values if not - // explicitly set: - // - // * Capacity \ - // Total available disk space in Gigabytes. - // * Price \ - // Price in GAS tokens for storing one GB of data during one Epoch. In node - // attributes it's a string presenting floating point number with comma or - // point delimiter for decimal part. In the Network Map it will be saved as - // 64-bit unsigned integer representing number of minimal token fractions. - // * UN-LOCODE \ - // Node's geographic location in - // [UN/LOCODE](https://www.unece.org/cefact/codesfortrade/codes_index.html) - // format approximated to the nearest point defined in the standard. - // * CountryCode \ - // Country code in - // [ISO 3166-1_alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) - // format. Calculated automatically from `UN-LOCODE` attribute. - // * Country \ - // Country short name in English, as defined in - // [ISO-3166](https://www.iso.org/obp/ui/#search). Calculated automatically - // from `UN-LOCODE` attribute. - // * Location \ - // Place names are given, whenever possible, in their national language - // versions as expressed in the Roman alphabet using the 26 characters of - // the character set adopted for international trade data interchange, - // written without diacritics . Calculated automatically from `UN-LOCODE` - // attribute. - // * SubDivCode \ - // Country's administrative subdivision where node is located. Calculated - // automatically from `UN-LOCODE` attribute based on `SubDiv` field. - // Presented in [ISO 3166-2](https://en.wikipedia.org/wiki/ISO_3166-2) - // format. - // * SubDiv \ - // Country's administrative subdivision name, as defined in - // [ISO 3166-2](https://en.wikipedia.org/wiki/ISO_3166-2). Calculated - // automatically from `UN-LOCODE` attribute. - // * Continent \ - // Node's continent name according to the [Seven-Continent - // model](https://en.wikipedia.org/wiki/Continent#Number). Calculated - // automatically from `UN-LOCODE` attribute. - // * ExternalAddr - // Node's preferred way for communications with external clients. - // Clients SHOULD use these addresses if possible. - // Must contain a comma-separated list of multi-addresses. - // - // For detailed description of each well-known attribute please see the - // corresponding section in FrostFS Technical Specification. - message Attribute { - // Key of the node attribute - string key = 1 [ json_name = "key" ]; - - // Value of the node attribute - string value = 2 [ json_name = "value" ]; - - // Parent keys, if any. For example for `City` it could be `Region` and - // `Country`. - repeated string parents = 3 [ json_name = "parents" ]; - } - // Carries list of the FrostFS node attributes in a key-value form. Key name - // must be a node-unique valid UTF-8 string. Value can't be empty. NodeInfo - // structures with duplicated attribute names or attributes with empty values - // will be considered invalid. - repeated Attribute attributes = 3 [ json_name = "attributes" ]; - - // Represents the enumeration of various states of the FrostFS node. - enum State { - // Unknown state - UNSPECIFIED = 0; - - // Active state in the network - ONLINE = 1; - - // Network unavailable state - OFFLINE = 2; - - // Maintenance state - MAINTENANCE = 3; - } - - // Carries state of the FrostFS node - State state = 4 [ json_name = "state" ]; -} - -// Network map structure -message Netmap { - // Network map revision number. - uint64 epoch = 1 [ json_name = "epoch" ]; - - // Nodes presented in network. - repeated NodeInfo nodes = 2 [ json_name = "nodes" ]; -} - -// FrostFS network configuration -message NetworkConfig { - // Single configuration parameter. Key MUST be network-unique. - // - // System parameters: - // - **AuditFee** \ - // Fee paid by the storage group owner to the Inner Ring member. - // Value: little-endian integer. Default: 0. - // - **BasicIncomeRate** \ - // Cost of storing one gigabyte of data for a period of one epoch. Paid by - // container owner to container nodes. - // Value: little-endian integer. Default: 0. - // - **ContainerAliasFee** \ - // Fee paid for named container's creation by the container owner. - // Value: little-endian integer. Default: 0. - // - **ContainerFee** \ - // Fee paid for container creation by the container owner. - // Value: little-endian integer. Default: 0. - // - **EpochDuration** \ - // FrostFS epoch duration measured in Sidechain blocks. - // Value: little-endian integer. Default: 0. - // - **HomomorphicHashingDisabled** \ - // Flag of disabling the homomorphic hashing of objects' payload. - // Value: true if any byte != 0. Default: false. - // - **InnerRingCandidateFee** \ - // Fee for entrance to the Inner Ring paid by the candidate. - // Value: little-endian integer. Default: 0. - // - **MaintenanceModeAllowed** \ - // Flag allowing setting the MAINTENANCE state to storage nodes. - // Value: true if any byte != 0. Default: false. - // - **MaxObjectSize** \ - // Maximum size of physically stored FrostFS object measured in bytes. - // Value: little-endian integer. Default: 0. - // - // This value refers to the maximum size of a **physically** stored object - // in FrostFS. However, from a user's perspective, the **logical** size of a - // stored object can be significantly larger. The relationship between the - // physical and logical object sizes is governed by the following formula - // - // ```math - // \mathrm{Stored\ Object\ Size} \le - // \frac{ - // \left(\mathrm{Max\ Object\ Size}\right)^2 - // }{ - // \mathrm{Object\ ID\ Size} - // } - // ``` - // - // This arises from the fact that a tombstone, also being an object, stores - // the IDs of inhumed objects and cannot be divided into smaller objects, - // thus having an upper limit for its size. - // - // For example, if: - // * Max Object Size Size = 64 MiB; - // * Object ID Size = 32 B; - // - // then: - // ```math - // \mathrm{Stored\ Object\ Size} \le - // \frac{\left(64\ \mathrm{MiB}\right)^2}{32\ \mathrm{B}} = - // \frac{2^{52}}{2^5}\ \mathrm{B} = - // 2^{47}\ \mathrm{B} = - // 128\ \mathrm{TiB} - // ``` - // - **WithdrawFee** \ - // Fee paid for withdrawal of funds paid by the account owner. - // Value: little-endian integer. Default: 0. - // - **MaxECDataCount** \ - // Maximum number of data shards for EC placement policy. - // Value: little-endian integer. Default: 0. - // - **MaxECParityCount** \ - // Maximum number of parity shards for EC placement policy. - // Value: little-endian integer. Default: 0. - message Parameter { - // Parameter key. UTF-8 encoded string - bytes key = 1 [ json_name = "key" ]; - - // Parameter value - bytes value = 2 [ json_name = "value" ]; - } - // List of parameter values - repeated Parameter parameters = 1 [ json_name = "parameters" ]; -} - -// Information about FrostFS network -message NetworkInfo { - // Number of the current epoch in the FrostFS network - uint64 current_epoch = 1 [ json_name = "currentEpoch" ]; - - // Magic number of the sidechain of the FrostFS network - uint64 magic_number = 2 [ json_name = "magicNumber" ]; - - // MillisecondsPerBlock network parameter of the sidechain of the FrostFS - // network - int64 ms_per_block = 3 [ json_name = "msPerBlock" ]; - - // FrostFS network configuration - NetworkConfig network_config = 4 [ json_name = "networkConfig" ]; -} diff --git a/protos/src/main/proto/object/service.proto b/protos/src/main/proto/object/service.proto deleted file mode 100644 index d1c816b..0000000 --- a/protos/src/main/proto/object/service.proto +++ /dev/null @@ -1,938 +0,0 @@ -syntax = "proto3"; - -package neo.fs.v2.object; - -option java_package = "frostfs.object"; - -import "object/types.proto"; -import "refs/types.proto"; -import "session/types.proto"; - -// `ObjectService` provides API for manipulating objects. Object operations do -// not affect the sidechain and are only served by nodes in p2p style. -service ObjectService { - // Receive full object structure, including Headers and payload. Response uses - // gRPC stream. First response message carries the object with the requested - // address. Chunk messages are parts of the object's payload if it is needed. - // All messages, except the first one, carry payload chunks. The requested - // object can be restored by concatenation of object message payload and all - // chunks keeping the receiving order. - // - // Extended headers can change `Get` behaviour: - // * [ __SYSTEM__NETMAP_EPOCH ] \ - // (`__NEOFS__NETMAP_EPOCH` is deprecated) \ - // Will use the requsted version of Network Map for object placement - // calculation. - // * [ __SYSTEM__NETMAP_LOOKUP_DEPTH ] \ - // (`__NEOFS__NETMAP_LOOKUP_DEPTH` is deprecated) \ - // Will try older versions (starting from `__SYSTEM__NETMAP_EPOCH` - // (`__NEOFS__NETMAP_EPOCH` is deprecated) if specified or the latest one - // otherwise) of Network Map to find an object until the depth limit is - // reached. - // - // Please refer to detailed `XHeader` description. - // - // Statuses: - // - **OK** (0, SECTION_SUCCESS): \ - // object has been successfully read; - // - Common failures (SECTION_FAILURE_COMMON); - // - **ACCESS_DENIED** (2048, SECTION_OBJECT): \ - // read access to the object is denied; - // - **OBJECT_NOT_FOUND** (2049, SECTION_OBJECT): \ - // object not found in container; - // - **OBJECT_ALREADY_REMOVED** (2052, SECTION_OBJECT): \ - // the requested object has been marked as deleted; - // - **CONTAINER_NOT_FOUND** (3072, SECTION_CONTAINER): \ - // object container not found; - // - **CONTAINER_ACCESS_DENIED** (3074, SECTION_CONTAINER): \ - // access to container is denied; - // - **TOKEN_EXPIRED** (4097, SECTION_SESSION): \ - // provided session token has expired. - rpc Get(GetRequest) returns (stream GetResponse); - - // Put the object into container. Request uses gRPC stream. First message - // SHOULD be of PutHeader type. `ContainerID` and `OwnerID` of an object - // SHOULD be set. Session token SHOULD be obtained before `PUT` operation (see - // session package). Chunk messages are considered by server as a part of an - // object payload. All messages, except first one, SHOULD be payload chunks. - // Chunk messages SHOULD be sent in the direct order of fragmentation. - // - // Extended headers can change `Put` behaviour: - // * [ __SYSTEM__NETMAP_EPOCH \ - // (`__NEOFS__NETMAP_EPOCH` is deprecated) \ - // Will use the requsted version of Network Map for object placement - // calculation. - // - // Please refer to detailed `XHeader` description. - // - // Statuses: - // - **OK** (0, SECTION_SUCCESS): \ - // object has been successfully saved in the container; - // - Common failures (SECTION_FAILURE_COMMON); - // - **ACCESS_DENIED** (2048, SECTION_OBJECT): \ - // write access to the container is denied; - // - **LOCKED** (2050, SECTION_OBJECT): \ - // placement of an object of type TOMBSTONE that includes at least one - // locked object is prohibited; - // - **LOCK_NON_REGULAR_OBJECT** (2051, SECTION_OBJECT): \ - // placement of an object of type LOCK that includes at least one object of - // type other than REGULAR is prohibited; - // - **CONTAINER_NOT_FOUND** (3072, SECTION_CONTAINER): \ - // object storage container not found; - // - **CONTAINER_ACCESS_DENIED** (3074, SECTION_CONTAINER): \ - // access to container is denied; - // - **TOKEN_NOT_FOUND** (4096, SECTION_SESSION): \ - // (for trusted object preparation) session private key does not exist or - // has - // been deleted; - // - **TOKEN_EXPIRED** (4097, SECTION_SESSION): \ - // provided session token has expired. - rpc Put(stream PutRequest) returns (PutResponse); - - // Delete the object from a container. There is no immediate removal - // guarantee. Object will be marked for removal and deleted eventually. - // - // Extended headers can change `Delete` behaviour: - // * [ __SYSTEM__NETMAP_EPOCH ] \ - // (`__NEOFS__NETMAP_EPOCH` is deprecated) \ - // Will use the requested version of Network Map for object placement - // calculation. - // - // Please refer to detailed `XHeader` description. - // - // Statuses: - // - **OK** (0, SECTION_SUCCESS): \ - // object has been successfully marked to be removed from the container; - // - Common failures (SECTION_FAILURE_COMMON); - // - **ACCESS_DENIED** (2048, SECTION_OBJECT): \ - // delete access to the object is denied; - // - **OBJECT_NOT_FOUND** (2049, SECTION_OBJECT): \ - // the object could not be deleted because it has not been \ - // found within the container; - // - **LOCKED** (2050, SECTION_OBJECT): \ - // deleting a locked object is prohibited; - // - **CONTAINER_NOT_FOUND** (3072, SECTION_CONTAINER): \ - // object container not found; - // - **CONTAINER_ACCESS_DENIED** (3074, SECTION_CONTAINER): \ - // access to container is denied; - // - **TOKEN_EXPIRED** (4097, SECTION_SESSION): \ - // provided session token has expired. - rpc Delete(DeleteRequest) returns (DeleteResponse); - - // Returns the object Headers without data payload. By default full header is - // returned. If `main_only` request field is set, the short header with only - // the very minimal information will be returned instead. - // - // Extended headers can change `Head` behaviour: - // * [ __SYSTEM__NETMAP_EPOCH ] \ - // (`__NEOFS__NETMAP_EPOCH` is deprecated) \ - // Will use the requested version of Network Map for object placement - // calculation. - // - // Please refer to detailed `XHeader` description. - // - // Statuses: - // - **OK** (0, SECTION_SUCCESS): \ - // object header has been successfully read; - // - Common failures (SECTION_FAILURE_COMMON); - // - **ACCESS_DENIED** (2048, SECTION_OBJECT): \ - // access to operation HEAD of the object is denied; - // - **OBJECT_NOT_FOUND** (2049, SECTION_OBJECT): \ - // object not found in container; - // - **OBJECT_ALREADY_REMOVED** (2052, SECTION_OBJECT): \ - // the requested object has been marked as deleted; - // - **CONTAINER_NOT_FOUND** (3072, SECTION_CONTAINER): \ - // object container not found; - // - **CONTAINER_ACCESS_DENIED** (3074, SECTION_CONTAINER): \ - // access to container is denied; - // - **TOKEN_EXPIRED** (4097, SECTION_SESSION): \ - // provided session token has expired. - rpc Head(HeadRequest) returns (HeadResponse); - - // Search objects in container. Search query allows to match by Object - // Header's filed values. Please see the corresponding FrostFS Technical - // Specification section for more details. - // - // Extended headers can change `Search` behaviour: - // * [ __SYSTEM__NETMAP_EPOCH ] \ - // (`__NEOFS__NETMAP_EPOCH` is deprecated) \ - // Will use the requested version of Network Map for object placement - // calculation. - // - // Please refer to detailed `XHeader` description. - // - // Statuses: - // - **OK** (0, SECTION_SUCCESS): \ - // objects have been successfully selected; - // - Common failures (SECTION_FAILURE_COMMON); - // - **ACCESS_DENIED** (2048, SECTION_OBJECT): \ - // access to operation SEARCH of the object is denied; - // - **CONTAINER_NOT_FOUND** (3072, SECTION_CONTAINER): \ - // search container not found; - // - **CONTAINER_ACCESS_DENIED** (3074, SECTION_CONTAINER): \ - // access to container is denied; - // - **TOKEN_EXPIRED** (4097, SECTION_SESSION): \ - // provided session token has expired. - rpc Search(SearchRequest) returns (stream SearchResponse); - - // Get byte range of data payload. Range is set as an (offset, length) tuple. - // Like in `Get` method, the response uses gRPC stream. Requested range can be - // restored by concatenation of all received payload chunks keeping the - // receiving order. - // - // Extended headers can change `GetRange` behaviour: - // * [ __SYSTEM__NETMAP_EPOCH ] \ - // (`__NEOFS__NETMAP_EPOCH` is deprecated) \ - // Will use the requested version of Network Map for object placement - // calculation. - // * [ __SYSTEM__NETMAP_LOOKUP_DEPTH ] \ - // (`__NEOFS__NETMAP_LOOKUP_DEPTH` is deprecated) \ - // Will try older versions of Network Map to find an object until the depth - // limit is reached. - // - // Please refer to detailed `XHeader` description. - // - // Statuses: - // - **OK** (0, SECTION_SUCCESS): \ - // data range of the object payload has been successfully read; - // - Common failures (SECTION_FAILURE_COMMON); - // - **ACCESS_DENIED** (2048, SECTION_OBJECT): \ - // access to operation RANGE of the object is denied; - // - **OBJECT_NOT_FOUND** (2049, SECTION_OBJECT): \ - // object not found in container; - // - **OBJECT_ALREADY_REMOVED** (2052, SECTION_OBJECT): \ - // the requested object has been marked as deleted. - // - **OUT_OF_RANGE** (2053, SECTION_OBJECT): \ - // the requested range is out of bounds; - // - **CONTAINER_NOT_FOUND** (3072, SECTION_CONTAINER): \ - // object container not found; - // - **CONTAINER_ACCESS_DENIED** (3074, SECTION_CONTAINER): \ - // access to container is denied; - // - **TOKEN_EXPIRED** (4097, SECTION_SESSION): \ - // provided session token has expired. - rpc GetRange(GetRangeRequest) returns (stream GetRangeResponse); - - // Returns homomorphic or regular hash of object's payload range after - // applying XOR operation with the provided `salt`. Ranges are set of (offset, - // length) tuples. Hashes order in response corresponds to the ranges order in - // the request. Note that hash is calculated for XORed data. - // - // Extended headers can change `GetRangeHash` behaviour: - // * [ __SYSTEM__NETMAP_EPOCH ] \ - // (`__NEOFS__NETMAP_EPOCH` is deprecated) \ - // Will use the requested version of Network Map for object placement - // calculation. - // * [ __SYSTEM__NETMAP_LOOKUP_DEPTH ] \ - // (`__NEOFS__NETMAP_LOOKUP_DEPTH` is deprecated) \ - // Will try older versions of Network Map to find an object until the depth - // limit is reached. - // - // Please refer to detailed `XHeader` description. - // - // Statuses: - // - **OK** (0, SECTION_SUCCESS): \ - // data range of the object payload has been successfully hashed; - // - Common failures (SECTION_FAILURE_COMMON); - // - **ACCESS_DENIED** (2048, SECTION_OBJECT): \ - // access to operation RANGEHASH of the object is denied; - // - **OBJECT_NOT_FOUND** (2049, SECTION_OBJECT): \ - // object not found in container; - // - **OUT_OF_RANGE** (2053, SECTION_OBJECT): \ - // the requested range is out of bounds; - // - **CONTAINER_NOT_FOUND** (3072, SECTION_CONTAINER): \ - // object container not found; - // - **CONTAINER_ACCESS_DENIED** (3074, SECTION_CONTAINER): \ - // access to container is denied; - // - **TOKEN_EXPIRED** (4097, SECTION_SESSION): \ - // provided session token has expired. - rpc GetRangeHash(GetRangeHashRequest) returns (GetRangeHashResponse); - - // Put the prepared object into container. - // `ContainerID`, `ObjectID`, `OwnerID`, `PayloadHash` and `PayloadLength` of - // an object MUST be set. - // - // Extended headers can change `Put` behaviour: - // * [ __SYSTEM__NETMAP_EPOCH \ - // (`__NEOFS__NETMAP_EPOCH` is deprecated) \ - // Will use the requested version of Network Map for object placement - // calculation. - // - // Please refer to detailed `XHeader` description. - // - // Statuses: - // - **OK** (0, SECTION_SUCCESS): \ - // object has been successfully saved in the container; - // - Common failures (SECTION_FAILURE_COMMON); - // - **ACCESS_DENIED** (2048, SECTION_OBJECT): \ - // write access to the container is denied; - // - **LOCKED** (2050, SECTION_OBJECT): \ - // placement of an object of type TOMBSTONE that includes at least one - // locked object is prohibited; - // - **LOCK_NON_REGULAR_OBJECT** (2051, SECTION_OBJECT): \ - // placement of an object of type LOCK that includes at least one object of - // type other than REGULAR is prohibited; - // - **CONTAINER_NOT_FOUND** (3072, SECTION_CONTAINER): \ - // object storage container not found; - // - **CONTAINER_ACCESS_DENIED** (3074, SECTION_CONTAINER): \ - // access to container is denied; - // - **TOKEN_NOT_FOUND** (4096, SECTION_SESSION): \ - // (for trusted object preparation) session private key does not exist or - // has - // been deleted; - // - **TOKEN_EXPIRED** (4097, SECTION_SESSION): \ - // provided session token has expired. - rpc PutSingle(PutSingleRequest) returns (PutSingleResponse); - - // Patch the object. Request uses gRPC stream. First message must set - // the address of the object that is going to get patched. If the object's - // attributes are patched, then these attrubutes must be set only within the - // first stream message. - // - // If the patch request is performed by NOT the object's owner but if the - // actor has the permission to perform the patch, then `OwnerID` of the object - // is changed. In this case the object's owner loses the object's ownership - // after the patch request is successfully done. - // - // As objects are content-addressable the patching causes new object ID - // generation for the patched object. This object id is set witihn - // `PatchResponse`. But the object id may remain unchanged in such cases: - // 1. The chunk of the applying patch contains the same value as the object's - // payload within the same range; - // 2. The patch that reverts the changes applied by preceding patch; - // 3. The application of the same patches for the object a few times. - // - // Extended headers can change `Patch` behaviour: - // * [ __SYSTEM__NETMAP_EPOCH \ - // (`__NEOFS__NETMAP_EPOCH` is deprecated) \ - // Will use the requsted version of Network Map for object placement - // calculation. - // - // Please refer to detailed `XHeader` description. - // - // Statuses: - // - **OK** (0, SECTION_SUCCESS): \ - // object has been successfully patched and saved in the container; - // - Common failures (SECTION_FAILURE_COMMON); - // - **ACCESS_DENIED** (2048, SECTION_OBJECT): \ - // write access to the container is denied; - // - **OBJECT_NOT_FOUND** (2049, SECTION_OBJECT): \ - // object not found in container; - // - **OBJECT_ALREADY_REMOVED** (2052, SECTION_OBJECT): \ - // the requested object has been marked as deleted. - // - **OUT_OF_RANGE** (2053, SECTION_OBJECT): \ - // the requested range is out of bounds; - // - **CONTAINER_NOT_FOUND** (3072, SECTION_CONTAINER): \ - // object storage container not found; - // - **CONTAINER_ACCESS_DENIED** (3074, SECTION_CONTAINER): \ - // access to container is denied; - // - **TOKEN_NOT_FOUND** (4096, SECTION_SESSION): \ - // (for trusted object preparation) session private key does not exist or - // has been deleted; - // - **TOKEN_EXPIRED** (4097, SECTION_SESSION): \ - // provided session token has expired. - rpc Patch(stream PatchRequest) returns (PatchResponse); -} - -// GET object request -message GetRequest { - // GET Object request body - message Body { - // Address of the requested object - neo.fs.v2.refs.Address address = 1; - - // If `raw` flag is set, request will work only with objects that are - // physically stored on the peer node - bool raw = 2; - } - // Body of get object request message. - Body body = 1; - - // Carries request meta information. Header data is used only to regulate - // message transport and does not affect request execution. - neo.fs.v2.session.RequestMetaHeader meta_header = 2; - - // Carries request verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.RequestVerificationHeader verify_header = 3; -} - -// GET object response -message GetResponse { - // GET Object Response body - message Body { - // Initial part of the `Object` structure stream. Technically it's a - // set of all `Object` structure's fields except `payload`. - message Init { - // Object's unique identifier. - neo.fs.v2.refs.ObjectID object_id = 1; - - // Signed `ObjectID` - neo.fs.v2.refs.Signature signature = 2; - - // Object metadata headers - Header header = 3; - } - // Single message in the response stream. - oneof object_part { - // Initial part of the object stream - Init init = 1; - - // Chunked object payload - bytes chunk = 2; - - // Meta information of split hierarchy for object assembly. - SplitInfo split_info = 3; - - // Meta information for EC object assembly. - ECInfo ec_info = 4; - } - } - // Body of get object response message. - Body body = 1; - - // Carries response meta information. Header data is used only to regulate - // message transport and does not affect request execution. - neo.fs.v2.session.ResponseMetaHeader meta_header = 2; - - // Carries response verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.ResponseVerificationHeader verify_header = 3; -} - -// PUT object request -message PutRequest { - // PUT request body - message Body { - // Newly created object structure parameters. If some optional parameters - // are not set, they will be calculated by a peer node. - message Init { - // ObjectID if available. - neo.fs.v2.refs.ObjectID object_id = 1; - - // Object signature if available - neo.fs.v2.refs.Signature signature = 2; - - // Object's Header - Header header = 3; - - // Number of copies of the object to store within the RPC call. By - // default, object is processed according to the container's placement - // policy. Can be one of: - // 1. A single number; applied to the whole request and is treated as - // a minimal number of nodes that must store an object to complete the - // request successfully. - // 2. An ordered array; every number is treated as a minimal number of - // nodes in a corresponding placement vector that must store an object - // to complete the request successfully. The length MUST equal the - // placement vectors number, otherwise request is considered malformed. - repeated uint32 copies_number = 4; - } - // Single message in the request stream. - oneof object_part { - // Initial part of the object stream - Init init = 1; - - // Chunked object payload - bytes chunk = 2; - } - } - // Body of put object request message. - Body body = 1; - - // Carries request meta information. Header data is used only to regulate - // message transport and does not affect request execution. - neo.fs.v2.session.RequestMetaHeader meta_header = 2; - - // Carries request verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.RequestVerificationHeader verify_header = 3; -} - -// PUT Object response -message PutResponse { - // PUT Object response body - message Body { - // Identifier of the saved object - neo.fs.v2.refs.ObjectID object_id = 1; - } - // Body of put object response message. - Body body = 1; - - // Carries response meta information. Header data is used only to regulate - // message transport and does not affect request execution. - neo.fs.v2.session.ResponseMetaHeader meta_header = 2; - - // Carries response verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.ResponseVerificationHeader verify_header = 3; -} - -// Object DELETE request -message DeleteRequest { - // Object DELETE request body - message Body { - // Address of the object to be deleted - neo.fs.v2.refs.Address address = 1; - } - // Body of delete object request message. - Body body = 1; - - // Carries request meta information. Header data is used only to regulate - // message transport and does not affect request execution. - neo.fs.v2.session.RequestMetaHeader meta_header = 2; - - // Carries request verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.RequestVerificationHeader verify_header = 3; -} - -// DeleteResponse body is empty because we cannot guarantee permanent object -// removal in distributed system. -message DeleteResponse { - // Object DELETE Response has an empty body. - message Body { - // Address of the tombstone created for the deleted object - neo.fs.v2.refs.Address tombstone = 1; - } - - // Body of delete object response message. - Body body = 1; - - // Carries response meta information. Header data is used only to regulate - // message transport and does not affect request execution. - neo.fs.v2.session.ResponseMetaHeader meta_header = 2; - - // Carries response verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.ResponseVerificationHeader verify_header = 3; -} - -// Object HEAD request -message HeadRequest { - // Object HEAD request body - message Body { - // Address of the object with the requested Header - neo.fs.v2.refs.Address address = 1; - - // Return only minimal header subset - bool main_only = 2; - - // If `raw` flag is set, request will work only with objects that are - // physically stored on the peer node - bool raw = 3; - } - // Body of head object request message. - Body body = 1; - - // Carries request meta information. Header data is used only to regulate - // message transport and does not affect request execution. - neo.fs.v2.session.RequestMetaHeader meta_header = 2; - - // Carries request verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.RequestVerificationHeader verify_header = 3; -} - -// Tuple of a full object header and signature of an `ObjectID`. \ -// Signed `ObjectID` is present to verify full header's authenticity through the -// following steps: -// -// 1. Calculate `SHA-256` of the marshalled `Header` structure -// 2. Check if the resulting hash matches `ObjectID` -// 3. Check if `ObjectID` signature in `signature` field is correct -message HeaderWithSignature { - // Full object header - Header header = 1 [ json_name = "header" ]; - - // Signed `ObjectID` to verify full header's authenticity - neo.fs.v2.refs.Signature signature = 2 [ json_name = "signature" ]; -} - -// Object HEAD response -message HeadResponse { - // Object HEAD response body - message Body { - // Requested object header, it's part or meta information about split - // object. - oneof head { - // Full object's `Header` with `ObjectID` signature - HeaderWithSignature header = 1; - - // Short object header - ShortHeader short_header = 2; - - // Meta information of split hierarchy. - SplitInfo split_info = 3; - - // Meta information for EC object assembly. - ECInfo ec_info = 4; - } - } - // Body of head object response message. - Body body = 1; - - // Carries response meta information. Header data is used only to regulate - // message transport and does not affect request execution. - neo.fs.v2.session.ResponseMetaHeader meta_header = 2; - - // Carries response verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.ResponseVerificationHeader verify_header = 3; -} - -// Object Search request -message SearchRequest { - // Object Search request body - message Body { - // Container identifier were to search - neo.fs.v2.refs.ContainerID container_id = 1; - - // Version of the Query Language used - uint32 version = 2; - // Filter structure checks if the object header field or the attribute - // content matches a value. - // - // If no filters are set, search request will return all objects of the - // container, including Regular object and Tombstone - // objects. Most human users expect to get only object they can directly - // work with. In that case, `$Object:ROOT` filter should be used. - // - // By default `key` field refers to the corresponding object's `Attribute`. - // Some Object's header fields can also be accessed by adding `$Object:` - // prefix to the name. Here is the list of fields available via this prefix: - // - // * $Object:version \ - // version - // * $Object:objectID \ - // object_id - // * $Object:containerID \ - // container_id - // * $Object:ownerID \ - // owner_id - // * $Object:creationEpoch \ - // creation_epoch - // * $Object:payloadLength \ - // payload_length - // * $Object:payloadHash \ - // payload_hash - // * $Object:objectType \ - // object_type - // * $Object:homomorphicHash \ - // homomorphic_hash - // * $Object:split.parent \ - // object_id of parent - // * $Object:split.splitID \ - // 16 byte UUIDv4 used to identify the split object hierarchy parts - // * $Object:ec.parent \ - // If the object is stored according to EC policy, then ec_parent - // attribute is set to return an id list of all related EC chunks. - // - // There are some well-known filter aliases to match objects by certain - // properties: - // - // * $Object:ROOT \ - // Returns only `REGULAR` type objects that are not split or that are the - // top level root objects in a split hierarchy. This includes objects not - // present physically, like large objects split into smaller objects - // without a separate top-level root object. Objects of other types like - // Locks and Tombstones will not be shown. This filter may be - // useful for listing objects like `ls` command of some virtual file - // system. This filter is activated if the `key` exists, disregarding the - // value and matcher type. - // * $Object:PHY \ - // Returns only objects physically stored in the system. This filter is - // activated if the `key` exists, disregarding the value and matcher type. - // - // Note: using filters with a key with prefix `$Object:` and match type - // `NOT_PRESENT `is not recommended since this is not a cross-version - // approach. Behavior when processing this kind of filters is undefined. - message Filter { - // Match type to use - MatchType match_type = 1 [ json_name = "matchType" ]; - - // Attribute or Header fields to match - string key = 2 [ json_name = "key" ]; - - // Value to match - string value = 3 [ json_name = "value" ]; - } - // List of search expressions - repeated Filter filters = 3; - } - // Body of search object request message. - Body body = 1; - - // Carries request meta information. Header data is used only to regulate - // message transport and does not affect request execution. - neo.fs.v2.session.RequestMetaHeader meta_header = 2; - - // Carries request verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.RequestVerificationHeader verify_header = 3; -} - -// Search response -message SearchResponse { - // Object Search response body - message Body { - // List of `ObjectID`s that match the search query - repeated neo.fs.v2.refs.ObjectID id_list = 1; - } - // Body of search object response message. - Body body = 1; - - // Carries response meta information. Header data is used only to regulate - // message transport and does not affect request execution. - neo.fs.v2.session.ResponseMetaHeader meta_header = 2; - - // Carries response verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.ResponseVerificationHeader verify_header = 3; -} - -// Object payload range.Ranges of zero length SHOULD be considered as invalid. -message Range { - // Offset of the range from the object payload start - uint64 offset = 1; - - // Length in bytes of the object payload range - uint64 length = 2; -} - -// Request part of object's payload -message GetRangeRequest { - // Byte range of object's payload request body - message Body { - // Address of the object containing the requested payload range - neo.fs.v2.refs.Address address = 1; - - // Requested payload range - Range range = 2; - - // If `raw` flag is set, request will work only with objects that are - // physically stored on the peer node. - bool raw = 3; - } - - // Body of get range object request message. - Body body = 1; - - // Carries request meta information. Header data is used only to regulate - // message transport and does not affect request execution. - neo.fs.v2.session.RequestMetaHeader meta_header = 2; - - // Carries request verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.RequestVerificationHeader verify_header = 3; -} - -// Get part of object's payload -message GetRangeResponse { - // Get Range response body uses streams to transfer the response. Because - // object payload considered a byte sequence, there is no need to have some - // initial preamble message. The requested byte range is sent as a series - // chunks. - message Body { - // Requested object range or meta information about split object. - oneof range_part { - // Chunked object payload's range. - bytes chunk = 1; - - // Meta information of split hierarchy. - SplitInfo split_info = 2; - - // Meta information for EC object assembly. - ECInfo ec_info = 3; - } - } - - // Body of get range object response message. - Body body = 1; - - // Carries response meta information. Header data is used only to regulate - // message transport and does not affect request execution. - neo.fs.v2.session.ResponseMetaHeader meta_header = 2; - - // Carries response verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.ResponseVerificationHeader verify_header = 3; -} - -// Get hash of object's payload part -message GetRangeHashRequest { - // Get hash of object's payload part request body. - message Body { - // Address of the object that containing the requested payload range - neo.fs.v2.refs.Address address = 1; - - // List of object's payload ranges to calculate homomorphic hash - repeated Range ranges = 2; - - // Binary salt to XOR object's payload ranges before hash calculation - bytes salt = 3; - - // Checksum algorithm type - neo.fs.v2.refs.ChecksumType type = 4; - } - // Body of get range hash object request message. - Body body = 1; - - // Carries request meta information. Header data is used only to regulate - // message transport and does not affect request execution. - neo.fs.v2.session.RequestMetaHeader meta_header = 2; - - // Carries request verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.RequestVerificationHeader verify_header = 3; -} - -// Get hash of object's payload part -message GetRangeHashResponse { - // Get hash of object's payload part response body. - message Body { - // Checksum algorithm type - neo.fs.v2.refs.ChecksumType type = 1; - - // List of range hashes in a binary format - repeated bytes hash_list = 2; - } - // Body of get range hash object response message. - Body body = 1; - - // Carries response meta information. Header data is used only to regulate - // message transport and does not affect request execution. - neo.fs.v2.session.ResponseMetaHeader meta_header = 2; - - // Carries response verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.ResponseVerificationHeader verify_header = 3; -} - -// Object PUT Single request -message PutSingleRequest { - // PUT Single request body - message Body { - // Prepared object with payload. - Object object = 1; - // Number of copies of the object to store within the RPC call. By default, - // object is processed according to the container's placement policy. - // Every number is treated as a minimal number of - // nodes in a corresponding placement vector that must store an object - // to complete the request successfully. The length MUST equal the placement - // vectors number, otherwise request is considered malformed. - repeated uint32 copies_number = 2; - } - // Body of put single object request message. - Body body = 1; - - // Carries request meta information. Header data is used only to regulate - // message transport and does not affect request execution. - neo.fs.v2.session.RequestMetaHeader meta_header = 2; - - // Carries request verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.RequestVerificationHeader verify_header = 3; -} - -// Object PUT Single response -message PutSingleResponse { - // PUT Single Object response body - message Body {} - // Body of put single object response message. - Body body = 1; - - // Carries response meta information. Header data is used only to regulate - // message transport and does not affect request execution. - neo.fs.v2.session.ResponseMetaHeader meta_header = 2; - - // Carries response verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.ResponseVerificationHeader verify_header = 3; -} - -// Object PATCH request -message PatchRequest { - // PATCH request body - message Body { - // The address of the object that is requested to get patched. - neo.fs.v2.refs.Address address = 1; - - // New attributes for the object. See `replace_attributes` flag usage to - // define how new attributes should be set. - repeated neo.fs.v2.object.Header.Attribute new_attributes = 2; - - // If this flag is set, then the object's attributes will be entirely - // replaced by `new_attributes` list. The empty `new_attributes` list with - // `replace_attributes = true` just resets attributes list for the object. - // - // Default `false` value for this flag means the attributes will be just - // merged. If the incoming `new_attributes` list contains already existing - // key, then it just replaces it while merging the lists. - bool replace_attributes = 3; - - // The patch for the object's payload. - message Patch { - // The range of the source object for which the payload is replaced by the - // patch's chunk. If the range's `length = 0`, then the patch's chunk is - // just appended to the original payload starting from the `offest` - // without any replace. - Range source_range = 1; - - // The chunk that is being appended to or that replaces the original - // payload on the given range. - bytes chunk = 2; - } - - // The patch that is applied for the object. - Patch patch = 4; - } - - // Body for patch request message. - Body body = 1; - - // Carries request meta information. Header data is used only to regulate - // message transport and does not affect request execution. - neo.fs.v2.session.RequestMetaHeader meta_header = 2; - - // Carries request verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.RequestVerificationHeader verify_header = 3; -} - -// Object PATCH response -message PatchResponse { - // PATCH response body - message Body { - // The object ID of the saved patched object. - neo.fs.v2.refs.ObjectID object_id = 1; - } - - // Body for patch response message. - Body body = 1; - - // Carries response meta information. Header data is used only to regulate - // message transport and does not affect request execution. - neo.fs.v2.session.ResponseMetaHeader meta_header = 2; - - // Carries response verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.ResponseVerificationHeader verify_header = 3; -} diff --git a/protos/src/main/proto/object/types.proto b/protos/src/main/proto/object/types.proto deleted file mode 100644 index 736e49b..0000000 --- a/protos/src/main/proto/object/types.proto +++ /dev/null @@ -1,277 +0,0 @@ -syntax = "proto3"; - -package neo.fs.v2.object; - -option java_package = "frostfs.object"; - -import "refs/types.proto"; -import "session/types.proto"; - -// Type of the object payload content. Only `REGULAR` type objects can be split, -// hence `TOMBSTONE` and `LOCK` payload is limited by the -// maximum object size. -// -// String presentation of object type is the same as definition: -// * REGULAR -// * TOMBSTONE -// * LOCK -enum ObjectType { - // Just a normal object - REGULAR = 0; - - // Used internally to identify deleted objects - TOMBSTONE = 1; - - // Unused (previously storageGroup information) - // _ = 2; - - // Object lock - LOCK = 3; -} - -// Type of match expression -enum MatchType { - // Unknown. Not used - MATCH_TYPE_UNSPECIFIED = 0; - - // Full string match - STRING_EQUAL = 1; - - // Full string mismatch - STRING_NOT_EQUAL = 2; - - // Lack of key - NOT_PRESENT = 3; - - // String prefix match - COMMON_PREFIX = 4; -} - -// Short header fields -message ShortHeader { - // Object format version. Effectively, the version of API library used to - // create particular object. - neo.fs.v2.refs.Version version = 1 [ json_name = "version" ]; - - // Epoch when the object was created - uint64 creation_epoch = 2 [ json_name = "creationEpoch" ]; - - // Object's owner - neo.fs.v2.refs.OwnerID owner_id = 3 [ json_name = "ownerID" ]; - - // Type of the object payload content - ObjectType object_type = 4 [ json_name = "objectType" ]; - - // Size of payload in bytes. - // `0xFFFFFFFFFFFFFFFF` means `payload_length` is unknown - uint64 payload_length = 5 [ json_name = "payloadLength" ]; - - // Hash of payload bytes - neo.fs.v2.refs.Checksum payload_hash = 6 [ json_name = "payloadHash" ]; - - // Homomorphic hash of the object payload - neo.fs.v2.refs.Checksum homomorphic_hash = 7 - [ json_name = "homomorphicHash" ]; -} - -// Object Header -message Header { - // Object format version. Effectively, the version of API library used to - // create particular object - neo.fs.v2.refs.Version version = 1 [ json_name = "version" ]; - - // Object's container - neo.fs.v2.refs.ContainerID container_id = 2 [ json_name = "containerID" ]; - - // Object's owner - neo.fs.v2.refs.OwnerID owner_id = 3 [ json_name = "ownerID" ]; - - // Object creation Epoch - uint64 creation_epoch = 4 [ json_name = "creationEpoch" ]; - - // Size of payload in bytes. - // `0xFFFFFFFFFFFFFFFF` means `payload_length` is unknown. - uint64 payload_length = 5 [ json_name = "payloadLength" ]; - - // Hash of payload bytes - neo.fs.v2.refs.Checksum payload_hash = 6 [ json_name = "payloadHash" ]; - - // Type of the object payload content - ObjectType object_type = 7 [ json_name = "objectType" ]; - - // Homomorphic hash of the object payload - neo.fs.v2.refs.Checksum homomorphic_hash = 8 - [ json_name = "homomorphicHash" ]; - - // Session token, if it was used during Object creation. Need it to verify - // integrity and authenticity out of Request scope. - neo.fs.v2.session.SessionToken session_token = 9 - [ json_name = "sessionToken" ]; - - // `Attribute` is a user-defined Key-Value metadata pair attached to an - // object. - // - // Key name must be an object-unique valid UTF-8 string. Value can't be empty. - // Objects with duplicated attribute names or attributes with empty values - // will be considered invalid. - // - // There are some "well-known" attributes starting with `__SYSTEM__` - // (`__NEOFS__` is deprecated) prefix that affect system behaviour: - // - // * [ __SYSTEM__UPLOAD_ID ] \ - // (`__NEOFS__UPLOAD_ID` is deprecated) \ - // Marks smaller parts of a split bigger object - // * [ __SYSTEM__EXPIRATION_EPOCH ] \ - // (`__NEOFS__EXPIRATION_EPOCH` is deprecated) \ - // The epoch after which object with no LOCKs on it becomes unavailable. - // Locked object continues to be available until each of the LOCKs expire. - // * [ __SYSTEM__TICK_EPOCH ] \ - // (`__NEOFS__TICK_EPOCH` is deprecated) \ - // Decimal number that defines what epoch must produce - // object notification with UTF-8 object address in a - // body (`0` value produces notification right after - // object put) - // * [ __SYSTEM__TICK_TOPIC ] \ - // (`__NEOFS__TICK_TOPIC` is deprecated) \ - // UTF-8 string topic ID that is used for object notification - // - // And some well-known attributes used by applications only: - // - // * Name \ - // Human-friendly name - // * FileName \ - // File name to be associated with the object on saving - // * FilePath \ - // Full path to be associated with the object on saving. Should start with a - // '/' and use '/' as a delimiting symbol. Trailing '/' should be - // interpreted as a virtual directory marker. If an object has conflicting - // FilePath and FileName, FilePath should have higher priority, because it - // is used to construct the directory tree. FilePath with trailing '/' and - // non-empty FileName attribute should not be used together. - // * Timestamp \ - // User-defined local time of object creation in Unix Timestamp format - // * Content-Type \ - // MIME Content Type of object's payload - // - // For detailed description of each well-known attribute please see the - // corresponding section in FrostFS Technical Specification. - message Attribute { - // string key to the object attribute - string key = 1 [ json_name = "key" ]; - // string value of the object attribute - string value = 2 [ json_name = "value" ]; - } - // User-defined object attributes - repeated Attribute attributes = 10 [ json_name = "attributes" ]; - - // Bigger objects can be split into a chain of smaller objects. Information - // about inter-dependencies between spawned objects and how to re-construct - // the original one is in the `Split` headers. Parent and children objects - // must be within the same container. - message Split { - // Identifier of the origin object. Known only to the minor child. - neo.fs.v2.refs.ObjectID parent = 1 [ json_name = "parent" ]; - - // Identifier of the left split neighbor - neo.fs.v2.refs.ObjectID previous = 2 [ json_name = "previous" ]; - - // `signature` field of the parent object. Used to reconstruct parent. - neo.fs.v2.refs.Signature parent_signature = 3 - [ json_name = "parentSignature" ]; - - // `header` field of the parent object. Used to reconstruct parent. - Header parent_header = 4 [ json_name = "parentHeader" ]; - - // List of identifiers of the objects generated by splitting current one. - repeated neo.fs.v2.refs.ObjectID children = 5 [ json_name = "children" ]; - - // 16 byte UUIDv4 used to identify the split object hierarchy parts. Must be - // unique inside container. All objects participating in the split must have - // the same `split_id` value. - bytes split_id = 6 [ json_name = "splitID" ]; - } - // Position of the object in the split hierarchy - Split split = 11 [ json_name = "split" ]; - - // Erasure code can be applied to any object. - // Information about encoded object structure is stored in `EC` header. - // All objects belonging to a single EC group have the same `parent` field. - message EC { - // Identifier of the origin object. Known to all chunks. - neo.fs.v2.refs.ObjectID parent = 1 [ json_name = "parent" ]; - // Index of this chunk. - uint32 index = 2 [ json_name = "index" ]; - // Total number of chunks in this split. - uint32 total = 3 [ json_name = "total" ]; - // Total length of a parent header. Used to trim padding zeroes. - uint32 header_length = 4 [ json_name = "headerLength" ]; - // Chunk of a parent header. - bytes header = 5 [ json_name = "header" ]; - // As the origin object is EC-splitted its identifier is known to all - // chunks as parent. But parent itself can be a part of Split (does not - // relate to EC-split). In this case parent_split_id should be set. - bytes parent_split_id = 6 [ json_name = "parentSplitID" ]; - // EC-parent's parent ID. parent_split_parent_id is set if EC-parent, - // itself, is a part of Split and if an object ID of its parent is - // presented. The field allows to determine how EC-chunk is placed in Split - // hierarchy. - neo.fs.v2.refs.ObjectID parent_split_parent_id = 7 - [ json_name = "parentSplitParentID" ]; - // EC parent's attributes. - repeated Attribute parent_attributes = 8 [ json_name = "parentAttributes" ]; - } - // Erasure code chunk information. - EC ec = 12 [ json_name = "ec" ]; -} - -// Object structure. Object is immutable and content-addressed. It means -// `ObjectID` will change if the header or the payload changes. It's calculated -// as a hash of header field which contains hash of the object's payload. -// -// For non-regular object types payload format depends on object type specified -// in the header. -message Object { - // Object's unique identifier. - neo.fs.v2.refs.ObjectID object_id = 1 [ json_name = "objectID" ]; - - // Signed object_id - neo.fs.v2.refs.Signature signature = 2 [ json_name = "signature" ]; - - // Object metadata headers - Header header = 3 [ json_name = "header" ]; - - // Payload bytes - bytes payload = 4 [ json_name = "payload" ]; -} - -// Meta information of split hierarchy for object assembly. With the last part -// one can traverse linked list of split hierarchy back to the first part and -// assemble the original object. With a linking object one can assemble an -// object right from the object parts. -message SplitInfo { - // 16 byte UUID used to identify the split object hierarchy parts. - bytes split_id = 1; - - // The identifier of the last object in split hierarchy parts. It contains - // split header with the original object header. - neo.fs.v2.refs.ObjectID last_part = 2; - - // The identifier of a linking object for split hierarchy parts. It contains - // split header with the original object header and a sorted list of - // object parts. - neo.fs.v2.refs.ObjectID link = 3; -} - -// Meta information for the erasure-encoded object. -message ECInfo { - message Chunk { - // Object ID of the chunk. - neo.fs.v2.refs.ObjectID id = 1; - // Index of the chunk. - uint32 index = 2; - // Total number of chunks in this split. - uint32 total = 3; - } - // Chunk stored on the node. - repeated Chunk chunks = 1; -} diff --git a/protos/src/main/proto/refs/types.proto b/protos/src/main/proto/refs/types.proto deleted file mode 100644 index 9c74edc..0000000 --- a/protos/src/main/proto/refs/types.proto +++ /dev/null @@ -1,150 +0,0 @@ -syntax = "proto3"; - -package neo.fs.v2.refs; - -option java_package = "frostfs.refs"; - -// Objects in FrostFS are addressed by their ContainerID and ObjectID. -// -// String presentation of `Address` is a concatenation of string encoded -// `ContainerID` and `ObjectID` delimited by '/' character. -message Address { - // Container identifier - ContainerID container_id = 1 [ json_name = "containerID" ]; - // Object identifier - ObjectID object_id = 2 [ json_name = "objectID" ]; -} - -// FrostFS Object unique identifier. Objects are immutable and -// content-addressed. It means `ObjectID` will change if the `header` or the -// `payload` changes. -// -// `ObjectID` is a 32 byte long -// [SHA256](https://csrc.nist.gov/publications/detail/fips/180/4/final) hash of -// the object's `header` field, which, in it's turn, contains the hash of the -// object's payload. -// -// String presentation is a -// [base58](https://tools.ietf.org/html/draft-msporny-base58-02) encoded string. -// -// JSON value will be data encoded as a string using standard base64 -// encoding with paddings. Either -// [standard](https://tools.ietf.org/html/rfc4648#section-4) or -// [URL-safe](https://tools.ietf.org/html/rfc4648#section-5) base64 encoding -// with/without paddings are accepted. -message ObjectID { - // Object identifier in a binary format - bytes value = 1 [ json_name = "value" ]; -} - -// FrostFS container identifier. Container structures are immutable and -// content-addressed. -// -// `ContainerID` is a 32 byte long -// [SHA256](https://csrc.nist.gov/publications/detail/fips/180/4/final) hash of -// stable-marshalled container message. -// -// String presentation is a -// [base58](https://tools.ietf.org/html/draft-msporny-base58-02) encoded string. -// -// JSON value will be data encoded as a string using standard base64 -// encoding with paddings. Either -// [standard](https://tools.ietf.org/html/rfc4648#section-4) or -// [URL-safe](https://tools.ietf.org/html/rfc4648#section-5) base64 encoding -// with/without paddings are accepted. -message ContainerID { - // Container identifier in a binary format. - bytes value = 1 [ json_name = "value" ]; -} - -// `OwnerID` is a derivative of a user's main public key. The transformation -// algorithm is the same as for Neo3 wallet addresses. Neo3 wallet address can -// be directly used as `OwnerID`. -// -// `OwnerID` is a 25 bytes sequence starting with Neo version prefix byte -// followed by 20 bytes of ScrptHash and 4 bytes of checksum. -// -// String presentation is a [Base58 -// Check](https://en.bitcoin.it/wiki/Base58Check_encoding) Encoded string. -// -// JSON value will be data encoded as a string using standard base64 -// encoding with paddings. Either -// [standard](https://tools.ietf.org/html/rfc4648#section-4) or -// [URL-safe](https://tools.ietf.org/html/rfc4648#section-5) base64 encoding -// with/without paddings are accepted. -message OwnerID { - // Identifier of the container owner in a binary format - bytes value = 1 [ json_name = "value" ]; -} - -// API version used by a node. -// -// String presentation is a Semantic Versioning 2.0.0 compatible version string -// with 'v' prefix. i.e. `vX.Y`, where `X` is the major number, `Y` is the minor -// number. -message Version { - // Major API version - uint32 major = 1 [ json_name = "major" ]; - - // Minor API version - uint32 minor = 2 [ json_name = "minor" ]; -} - -// Signature of something in FrostFS. -message Signature { - // Public key used for signing - bytes key = 1 [ json_name = "key" ]; - // Signature - bytes sign = 2 [ json_name = "signature" ]; - // Scheme contains digital signature scheme identifier - SignatureScheme scheme = 3 [ json_name = "scheme" ]; -} - -// Signature scheme describes digital signing scheme used for (key, signature) -// pair. -enum SignatureScheme { - // ECDSA with SHA-512 hashing (FIPS 186-3) - ECDSA_SHA512 = 0; - - // Deterministic ECDSA with SHA-256 hashing (RFC 6979) - ECDSA_RFC6979_SHA256 = 1; - - // Deterministic ECDSA with SHA-256 hashing using WalletConnect API. - // Here the algorithm is the same, but the message format differs. - ECDSA_RFC6979_SHA256_WALLET_CONNECT = 2; -} - -// RFC 6979 signature. -message SignatureRFC6979 { - // Public key used for signing - bytes key = 1 [ json_name = "key" ]; - // Deterministic ECDSA with SHA-256 hashing - bytes sign = 2 [ json_name = "signature" ]; -} - -// Checksum algorithm type. -enum ChecksumType { - // Unknown. Not used - CHECKSUM_TYPE_UNSPECIFIED = 0; - - // Tillich-Zemor homomorphic hash function - TZ = 1; - - // SHA-256 - SHA256 = 2; -} - -// Checksum message. -// Depending on checksum algorithm type, the string presentation may vary: -// -// * TZ \ -// Hex encoded string without `0x` prefix -// * SHA256 \ -// Hex encoded string without `0x` prefix -message Checksum { - // Checksum algorithm type - ChecksumType type = 1 [ json_name = "type" ]; - - // Checksum itself - bytes sum = 2 [ json_name = "sum" ]; -} diff --git a/protos/src/main/proto/session/service.proto b/protos/src/main/proto/session/service.proto deleted file mode 100644 index 17fd756..0000000 --- a/protos/src/main/proto/session/service.proto +++ /dev/null @@ -1,68 +0,0 @@ -syntax = "proto3"; - -package neo.fs.v2.session; - -option java_package = "frostfs.session"; - -import "refs/types.proto"; -import "session/types.proto"; - -// `SessionService` allows to establish a temporary trust relationship between -// two peer nodes and generate a `SessionToken` as the proof of trust to be -// attached in requests for further verification. Please see corresponding -// section of FrostFS Technical Specification for details. -service SessionService { - // Open a new session between two peers. - // - // Statuses: - // - **OK** (0, SECTION_SUCCESS): - // session has been successfully opened; - // - Common failures (SECTION_FAILURE_COMMON). - rpc Create(CreateRequest) returns (CreateResponse); -} - -// Information necessary for opening a session. -message CreateRequest { - // Session creation request body - message Body { - // Session initiating user's or node's key derived `OwnerID` - neo.fs.v2.refs.OwnerID owner_id = 1; - // Session expiration `Epoch` - uint64 expiration = 2; - } - // Body of a create session token request message. - Body body = 1; - - // Carries request meta information. Header data is used only to regulate - // message transport and does not affect request execution. - neo.fs.v2.session.RequestMetaHeader meta_header = 2; - - // Carries request verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.RequestVerificationHeader verify_header = 3; -} - -// Information about the opened session. -message CreateResponse { - // Session creation response body - message Body { - // Identifier of a newly created session - bytes id = 1; - - // Public key used for session - bytes session_key = 2; - } - - // Body of create session token response message. - Body body = 1; - - // Carries response meta information. Header data is used only to regulate - // message transport and does not affect request execution. - neo.fs.v2.session.ResponseMetaHeader meta_header = 2; - - // Carries response verification information. This header is used to - // authenticate the nodes of the message route and check the correctness of - // transmission. - neo.fs.v2.session.ResponseVerificationHeader verify_header = 3; -} diff --git a/protos/src/main/proto/session/types.proto b/protos/src/main/proto/session/types.proto deleted file mode 100644 index 7e356de..0000000 --- a/protos/src/main/proto/session/types.proto +++ /dev/null @@ -1,240 +0,0 @@ -syntax = "proto3"; - -package neo.fs.v2.session; - -option java_package = "frostfs.session"; - -import "refs/types.proto"; -import "acl/types.proto"; -import "status/types.proto"; - -// Context information for Session Tokens related to ObjectService requests -message ObjectSessionContext { - // Object request verbs - enum Verb { - // Unknown verb - VERB_UNSPECIFIED = 0; - - // Refers to object.Put RPC call - PUT = 1; - - // Refers to object.Get RPC call - GET = 2; - - // Refers to object.Head RPC call - HEAD = 3; - - // Refers to object.Search RPC call - SEARCH = 4; - - // Refers to object.Delete RPC call - DELETE = 5; - - // Refers to object.GetRange RPC call - RANGE = 6; - - // Refers to object.GetRangeHash RPC call - RANGEHASH = 7; - - // Refers to object.Patch RPC call - PATCH = 8; - } - // Type of request for which the token is issued - Verb verb = 1 [ json_name = "verb" ]; - - // Carries objects involved in the object session. - message Target { - // Indicates which container the session is spread to. Field MUST be set - // and correct. - refs.ContainerID container = 1 [ json_name = "container" ]; - - // Indicates which objects the session is spread to. Objects are expected - // to be stored in the FrostFS container referenced by `container` field. - // Each element MUST have correct format. - repeated refs.ObjectID objects = 2 [ json_name = "objects" ]; - } - // Object session target. MUST be correctly formed and set. If `objects` - // field is not empty, then the session applies only to these elements, - // otherwise, to all objects from the specified container. - Target target = 2 [ json_name = "target" ]; -} - -// Context information for Session Tokens related to ContainerService requests. -message ContainerSessionContext { - // Container request verbs - enum Verb { - // Unknown verb - VERB_UNSPECIFIED = 0; - - // Refers to container.Put RPC call - PUT = 1; - - // Refers to container.Delete RPC call - DELETE = 2; - - // Refers to container.SetExtendedACL RPC call - SETEACL = 3; - } - // Type of request for which the token is issued - Verb verb = 1 [ json_name = "verb" ]; - - // Spreads the action to all owner containers. - // If set, container_id field is ignored. - bool wildcard = 2 [ json_name = "wildcard" ]; - - // Particular container to which the action applies. - // Ignored if wildcard flag is set. - refs.ContainerID container_id = 3 [ json_name = "containerID" ]; -} - -// FrostFS Session Token. -message SessionToken { - // Session Token body - message Body { - // Token identifier is a valid UUIDv4 in binary form - bytes id = 1 [ json_name = "id" ]; - - // Identifier of the session initiator - neo.fs.v2.refs.OwnerID owner_id = 2 [ json_name = "ownerID" ]; - - // Lifetime parameters of the token. Field names taken from rfc7519. - message TokenLifetime { - // Expiration Epoch - uint64 exp = 1 [ json_name = "exp" ]; - - // Not valid before Epoch - uint64 nbf = 2 [ json_name = "nbf" ]; - - // Issued at Epoch - uint64 iat = 3 [ json_name = "iat" ]; - } - // Lifetime of the session - TokenLifetime lifetime = 3 [ json_name = "lifetime" ]; - - // Public key used in session - bytes session_key = 4 [ json_name = "sessionKey" ]; - - // Session Context information - oneof context { - // ObjectService session context - ObjectSessionContext object = 5 [ json_name = "object" ]; - - // ContainerService session context - ContainerSessionContext container = 6 [ json_name = "container" ]; - } - } - // Session Token contains the proof of trust between peers to be attached in - // requests for further verification. Please see corresponding section of - // FrostFS Technical Specification for details. - Body body = 1 [ json_name = "body" ]; - - // Signature of `SessionToken` information - neo.fs.v2.refs.Signature signature = 2 [ json_name = "signature" ]; -} - -// Extended headers for Request/Response. They may contain any user-defined -// headers to be interpreted on application level. -// -// Key name must be a unique valid UTF-8 string. Value can't be empty. Requests -// or Responses with duplicated header names or headers with empty values will -// be considered invalid. -// -// There are some "well-known" headers starting with `__SYSTEM__` (`__NEOFS__` -// is deprecated) prefix that affect system behaviour: -// -// * [ __SYSTEM__NETMAP_EPOCH ] \ -// (`__NEOFS__NETMAP_EPOCH` is deprecated) \ -// Netmap epoch to use for object placement calculation. The `value` is string -// encoded `uint64` in decimal presentation. If set to '0' or not set, the -// current epoch only will be used. -// * [ __SYSTEM__NETMAP_LOOKUP_DEPTH ] \ -// (`__NEOFS__NETMAP_LOOKUP_DEPTH` is deprecated) \ -// If object can't be found using current epoch's netmap, this header limits -// how many past epochs the node can look up through. The `value` is string -// encoded `uint64` in decimal presentation. If set to '0' or not set, only -// the current epoch will be used. -message XHeader { - // Key of the X-Header - string key = 1 [ json_name = "key" ]; - - // Value of the X-Header - string value = 2 [ json_name = "value" ]; -} - -// Meta information attached to the request. When forwarded between peers, -// request meta headers are folded in matryoshka style. -message RequestMetaHeader { - // Peer's API version used - neo.fs.v2.refs.Version version = 1 [ json_name = "version" ]; - - // Peer's local epoch number. Set to 0 if unknown. - uint64 epoch = 2 [ json_name = "epoch" ]; - - // Maximum number of intermediate nodes in the request route - uint32 ttl = 3 [ json_name = "ttl" ]; - - // Request X-Headers - repeated XHeader x_headers = 4 [ json_name = "xHeaders" ]; - - // Session token within which the request is sent - SessionToken session_token = 5 [ json_name = "sessionToken" ]; - - // `BearerToken` with eACL overrides for the request - neo.fs.v2.acl.BearerToken bearer_token = 6 [ json_name = "bearerToken" ]; - - // `RequestMetaHeader` of the origin request - RequestMetaHeader origin = 7 [ json_name = "origin" ]; - - // FrostFS network magic. Must match the value for the network - // that the server belongs to. - uint64 magic_number = 8 [ json_name = "magicNumber" ]; -} - -// Information about the response -message ResponseMetaHeader { - // Peer's API version used - neo.fs.v2.refs.Version version = 1 [ json_name = "version" ]; - - // Peer's local epoch number - uint64 epoch = 2 [ json_name = "epoch" ]; - - // Maximum number of intermediate nodes in the request route - uint32 ttl = 3 [ json_name = "ttl" ]; - - // Response X-Headers - repeated XHeader x_headers = 4 [ json_name = "xHeaders" ]; - - // `ResponseMetaHeader` of the origin request - ResponseMetaHeader origin = 5 [ json_name = "origin" ]; - - // Status return - neo.fs.v2.status.Status status = 6 [ json_name = "status" ]; -} - -// Verification info for the request signed by all intermediate nodes. -message RequestVerificationHeader { - // Request Body signature. Should be generated once by the request initiator. - neo.fs.v2.refs.Signature body_signature = 1 [ json_name = "bodySignature" ]; - // Request Meta signature is added and signed by each intermediate node - neo.fs.v2.refs.Signature meta_signature = 2 [ json_name = "metaSignature" ]; - // Signature of previous hops - neo.fs.v2.refs.Signature origin_signature = 3 - [ json_name = "originSignature" ]; - - // Chain of previous hops signatures - RequestVerificationHeader origin = 4 [ json_name = "origin" ]; -} - -// Verification info for the response signed by all intermediate nodes -message ResponseVerificationHeader { - // Response Body signature. Should be generated once by an answering node. - neo.fs.v2.refs.Signature body_signature = 1 [ json_name = "bodySignature" ]; - // Response Meta signature is added and signed by each intermediate node - neo.fs.v2.refs.Signature meta_signature = 2 [ json_name = "metaSignature" ]; - // Signature of previous hops - neo.fs.v2.refs.Signature origin_signature = 3 - [ json_name = "originSignature" ]; - - // Chain of previous hops signatures - ResponseVerificationHeader origin = 4 [ json_name = "origin" ]; -} diff --git a/protos/src/main/proto/status/types.proto b/protos/src/main/proto/status/types.proto deleted file mode 100644 index 8e61ae5..0000000 --- a/protos/src/main/proto/status/types.proto +++ /dev/null @@ -1,161 +0,0 @@ -syntax = "proto3"; - -package neo.fs.v2.status; - -option java_package = "frostfs.status"; - -// Declares the general format of the status returns of the FrostFS RPC -// protocol. Status is present in all response messages. Each RPC of FrostFS -// protocol describes the possible outcomes and details of the operation. -// -// Each status is assigned a one-to-one numeric code. Any unique result of an -// operation in FrostFS is unambiguously associated with the code value. -// -// Numerical set of codes is split into 1024-element sections. An enumeration -// is defined for each section. Values can be referred to in the following ways: -// -// * numerical value ranging from 0 to 4,294,967,295 (global code); -// -// * values from enumeration (local code). The formula for the ratio of the -// local code (`L`) of a defined section (`S`) to the global one (`G`): -// `G = 1024 * S + L`. -// -// All outcomes are divided into successful and failed, which corresponds -// to the success or failure of the operation. The definition of success -// follows the semantics of RPC and the description of its purpose. -// The server must not attach code that is the opposite of the outcome type. -// -// See the set of return codes in the description for calls. -// -// Each status can carry a developer-facing error message. It should be a human -// readable text in English. The server should not transmit (and the client -// should not expect) useful information in the message. Field `details` -// should make the return more detailed. -message Status { - // The status code - uint32 code = 1; - - // Developer-facing error message - string message = 2; - - // Return detail. It contains additional information that can be used to - // analyze the response. Each code defines a set of details that can be - // attached to a status. Client should not handle details that are not - // covered by the code. - message Detail { - // Detail ID. The identifier is required to determine the binary format - // of the detail and how to decode it. - uint32 id = 1; - - // Binary status detail. Must follow the format associated with ID. - // The possibility of missing a value must be explicitly allowed. - bytes value = 2; - } - - // Data detailing the outcome of the operation. Must be unique by ID. - repeated Detail details = 3; -} - -// Section identifiers. -enum Section { - // Successful return codes. - SECTION_SUCCESS = 0; - - // Failure codes regardless of the operation. - SECTION_FAILURE_COMMON = 1; - - // Object service-specific errors. - SECTION_OBJECT = 2; - - // Container service-specific errors. - SECTION_CONTAINER = 3; - - // Session service-specific errors. - SECTION_SESSION = 4; - - // Session service-specific errors. - SECTION_APE_MANAGER = 5; -} - -// Section of FrostFS successful return codes. -enum Success { - // [**0**] Default success. Not detailed. - // If the server cannot match successful outcome to the code, it should - // use this code. - OK = 0; -} - -// Section of failed statuses independent of the operation. -enum CommonFail { - // [**1024**] Internal server error, default failure. Not detailed. - // If the server cannot match failed outcome to the code, it should - // use this code. - INTERNAL = 0; - - // [**1025**] Wrong magic of the FrostFS network. - // Details: - // - [**0**] Magic number of the served FrostFS network (big-endian 64-bit - // unsigned integer). - WRONG_MAGIC_NUMBER = 1; - - // [**1026**] Signature verification failure. - SIGNATURE_VERIFICATION_FAIL = 2; - - // [**1027**] Node is under maintenance. - NODE_UNDER_MAINTENANCE = 3; - - // [**1028**] Invalid argument error. If the server fails on validation of a - // request parameter as the client sent it incorrectly, then this code should - // be used. - INVALID_ARGUMENT = 4; -} - -// Section of statuses for object-related operations. -enum Object { - // [**2048**] Access denied by ACL. - // Details: - // - [**0**] Human-readable description (UTF-8 encoded string). - ACCESS_DENIED = 0; - - // [**2049**] Object not found. - OBJECT_NOT_FOUND = 1; - - // [**2050**] Operation rejected by the object lock. - LOCKED = 2; - - // [**2051**] Locking an object with a non-REGULAR type rejected. - LOCK_NON_REGULAR_OBJECT = 3; - - // [**2052**] Object has been marked deleted. - OBJECT_ALREADY_REMOVED = 4; - - // [**2053**] Invalid range has been requested for an object. - OUT_OF_RANGE = 5; -} - -// Section of statuses for container-related operations. -enum Container { - // [**3072**] Container not found. - CONTAINER_NOT_FOUND = 0; - - // [**3073**] eACL table not found. - EACL_NOT_FOUND = 1; - - // [**3074**] Container access denied. - CONTAINER_ACCESS_DENIED = 2; -} - -// Section of statuses for session-related operations. -enum Session { - // [**4096**] Token not found. - TOKEN_NOT_FOUND = 0; - - // [**4097**] Token has expired. - TOKEN_EXPIRED = 1; -} - -// Section of status for APE manager related operations. -enum APEManager { - // [**5120**] The operation is denied by APE manager. - APE_MANAGER_ACCESS_DENIED = 0; -} diff --git a/protos/src/main/proto/tombstone/types.proto b/protos/src/main/proto/tombstone/types.proto deleted file mode 100644 index e7164b5..0000000 --- a/protos/src/main/proto/tombstone/types.proto +++ /dev/null @@ -1,26 +0,0 @@ -syntax = "proto3"; - -package neo.fs.v2.tombstone; - -option java_package = "frostfs.tombstone"; - -import "refs/types.proto"; - -// Tombstone keeps record of deleted objects for a few epochs until they are -// purged from the FrostFS network. -message Tombstone { - // Last FrostFS epoch number of the tombstone lifetime. It's set by the - // tombstone creator depending on the current FrostFS network settings. A - // tombstone object must have the same expiration epoch value in - // `__SYSTEM__EXPIRATION_EPOCH` (`__NEOFS__EXPIRATION_EPOCH` is deprecated) - // attribute. Otherwise, the tombstone will be rejected by a storage node. - uint64 expiration_epoch = 1 [ json_name = "expirationEpoch" ]; - - // 16 byte UUID used to identify the split object hierarchy parts. Must be - // unique inside a container. All objects participating in the split must - // have the same `split_id` value. - bytes split_id = 2 [ json_name = "splitID" ]; - - // List of objects to be deleted. - repeated neo.fs.v2.refs.ObjectID members = 3 [ json_name = "members" ]; -}