-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DOP-22337] Add logic for handling Samba transfers
- Loading branch information
Ilyas Gasanov
committed
Jan 31, 2025
1 parent
cc69298
commit 16a7f6c
Showing
20 changed files
with
729 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
name: FTP tests | ||
on: | ||
workflow_call: | ||
|
||
env: | ||
DEFAULT_PYTHON: '3.12' | ||
|
||
jobs: | ||
test: | ||
name: Run FTP tests | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Cache jars | ||
uses: actions/cache@v4 | ||
with: | ||
path: ./cached_jars | ||
key: ${{ runner.os }}-python-${{ env.DEFAULT_PYTHON }}-test-samba | ||
restore-keys: | | ||
${{ runner.os }}-python-${{ env.DEFAULT_PYTHON }}-test-samba | ||
${{ runner.os }}-python- | ||
- name: Build Worker Image | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: . | ||
tags: mtsrus/syncmaster-worker:${{ github.sha }} | ||
target: test | ||
file: docker/Dockerfile.worker | ||
load: true | ||
cache-from: mtsrus/syncmaster-worker:develop | ||
|
||
- name: Docker compose up | ||
run: | | ||
docker compose -f docker-compose.test.yml --profile all down -v --remove-orphans | ||
docker compose -f docker-compose.test.yml --profile samba up -d --wait --wait-timeout 200 | ||
env: | ||
WORKER_IMAGE_TAG: ${{ github.sha }} | ||
|
||
- name: Run FTP Tests | ||
run: | | ||
docker compose -f ./docker-compose.test.yml --profile samba exec -T worker coverage run -m pytest -vvv -s -m "worker and samba" | ||
- name: Dump worker logs on failure | ||
if: failure() | ||
uses: jwalton/gh-docker-logs@v2 | ||
with: | ||
images: mtsrus/syncmaster-worker | ||
dest: ./logs | ||
|
||
# This is important, as coverage is exported after receiving SIGTERM | ||
- name: Shutdown | ||
if: always() | ||
run: | | ||
docker compose -f docker-compose.test.yml --profile all down -v --remove-orphans | ||
- name: Upload worker logs | ||
uses: actions/upload-artifact@v4 | ||
if: failure() | ||
with: | ||
name: worker-logs-samba | ||
path: logs/* | ||
|
||
- name: Upload coverage results | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: coverage-samba | ||
path: reports/* | ||
# https://github.com/actions/upload-artifact/issues/602 | ||
include-hidden-files: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env bash | ||
|
||
# allow create files and directories | ||
mkdir -p /share/folder | ||
chmod 0777 /share/folder | ||
/entrypoint.sh -u "1000:1000:syncmaster:syncmaster:test_only" -s "SmbShare:/share/folder:rw:syncmaster" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add logic for handling Samba transfers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# SPDX-FileCopyrightText: 2023-2024 MTS PJSC | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from __future__ import annotations | ||
|
||
import os | ||
from typing import TYPE_CHECKING | ||
|
||
from onetl.connection import Samba, SparkLocalFS | ||
from onetl.file import FileDFReader, FileDFWriter, FileDownloader, FileUploader | ||
|
||
from syncmaster.dto.connections import SambaConnectionDTO | ||
from syncmaster.worker.handlers.file.base import FileHandler | ||
|
||
if TYPE_CHECKING: | ||
from pyspark.sql import DataFrame, SparkSession | ||
|
||
|
||
class SambaHandler(FileHandler): | ||
connection_dto: SambaConnectionDTO | ||
|
||
def connect(self, spark: SparkSession) -> None: | ||
self.connection = Samba( | ||
host=self.connection_dto.host, | ||
port=self.connection_dto.port, | ||
share=self.connection_dto.share, | ||
protocol=self.connection_dto.protocol, | ||
domain=self.connection_dto.domain, | ||
user=self.connection_dto.user, | ||
password=self.connection_dto.password, | ||
auth_type=self.connection_dto.auth_type, | ||
).check() | ||
self.local_connection = SparkLocalFS( | ||
spark=spark, | ||
).check() | ||
|
||
def read(self) -> DataFrame: | ||
from pyspark.sql.types import StructType | ||
|
||
downloader = FileDownloader( | ||
connection=self.connection, | ||
source_path=self.transfer_dto.directory_path, | ||
local_path=self.temp_dir.name, | ||
) | ||
downloader.run() | ||
|
||
reader = FileDFReader( | ||
connection=self.local_connection, | ||
format=self.transfer_dto.file_format, | ||
source_path=self.temp_dir.name, | ||
df_schema=StructType.fromJson(self.transfer_dto.df_schema) if self.transfer_dto.df_schema else None, | ||
) | ||
df = reader.run() | ||
|
||
rows_filter_expression = self._get_rows_filter_expression() | ||
if rows_filter_expression: | ||
df = df.where(rows_filter_expression) | ||
|
||
columns_filter_expressions = self._get_columns_filter_expressions() | ||
if columns_filter_expressions: | ||
df = df.selectExpr(*columns_filter_expressions) | ||
|
||
return df | ||
|
||
def write(self, df: DataFrame) -> None: | ||
writer = FileDFWriter( | ||
connection=self.local_connection, | ||
format=self.transfer_dto.file_format, | ||
target_path=self.temp_dir.name, | ||
options={"if_exists": "replace_entire_directory"}, | ||
) | ||
writer.run(df=df) | ||
|
||
crc_files = [f for f in os.listdir(self.temp_dir.name) if f.endswith(".crc")] | ||
for file in crc_files: | ||
os.remove(os.path.join(self.temp_dir.name, file)) | ||
|
||
uploader = FileUploader( | ||
connection=self.connection, | ||
local_path=self.temp_dir.name, | ||
target_path=self.transfer_dto.directory_path, | ||
options=self.transfer_dto.options, | ||
) | ||
uploader.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.