goutamadwant commented on code in PR #12297:
URL: https://github.com/apache/seatunnel/pull/12297#discussion_r4000362612


##########
seatunnel-connectors-v2/connector-file/connector-file-smb/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/smb/system/SmbInputStream.java:
##########
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.seatunnel.connectors.seatunnel.file.smb.system;
+
+import org.apache.hadoop.fs.FSInputStream;
+import org.apache.hadoop.fs.FileSystem;
+
+import com.hierynomus.smbj.share.DiskShare;
+import com.hierynomus.smbj.share.File;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class SmbInputStream extends FSInputStream {
+
+    private InputStream wrappedStream;
+    private File smbFile;
+    private DiskShare diskShare;
+    private FileSystem.Statistics stats;
+    private boolean closed;
+    private long pos;
+
+    SmbInputStream(
+            InputStream stream, File smbFile, DiskShare diskShare, 
FileSystem.Statistics stats) {
+        if (stream == null) {
+            throw new IllegalArgumentException("Null InputStream");
+        }
+        this.wrappedStream = stream;
+        this.smbFile = smbFile;
+        this.diskShare = diskShare;
+        this.stats = stats;
+        this.pos = 0;
+        this.closed = false;
+    }
+
+    @Override
+    public void seek(long position) throws IOException {
+        throw new IOException("Seek not supported");

Review Comment:
   This makes the advertised Parquet and ORC source paths unusable. Both 
`ParquetReadStrategy` and `OrcReadStrategy` call `FSDataInputStream.seek` 
before reading, and the optional split strategy also seeks to split boundaries. 
I reproduced it against Samba by reading one byte and seeking to offset 5; this 
line throws immediately. Please implement random access here (`SMBJ File.read` 
supports an explicit file offset) and add a connector-level regression that 
seeks backward and reads a Parquet/ORC file.



##########
seatunnel-connectors-v2/connector-file/connector-file-smb/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/smb/system/SmbFileSystem.java:
##########
@@ -0,0 +1,550 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.seatunnel.connectors.seatunnel.file.smb.system;
+
+import 
org.apache.seatunnel.connectors.seatunnel.file.hadoop.FileStatusListingSession;
+import 
org.apache.seatunnel.connectors.seatunnel.file.hadoop.StreamingFileSystem;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FSDataOutputStream;
+import org.apache.hadoop.fs.FileStatus;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.fs.permission.FsPermission;
+import org.apache.hadoop.util.Progressable;
+
+import com.hierynomus.msdtyp.AccessMask;
+import com.hierynomus.msfscc.FileAttributes;
+import com.hierynomus.msfscc.fileinformation.FileAllInformation;
+import com.hierynomus.msfscc.fileinformation.FileIdBothDirectoryInformation;
+import com.hierynomus.mssmb2.SMB2CreateDisposition;
+import com.hierynomus.mssmb2.SMB2ShareAccess;
+import com.hierynomus.smbj.SMBClient;
+import com.hierynomus.smbj.SmbConfig;
+import com.hierynomus.smbj.auth.AuthenticationContext;
+import com.hierynomus.smbj.connection.Connection;
+import com.hierynomus.smbj.session.Session;
+import com.hierynomus.smbj.share.DiskShare;
+import com.hierynomus.smbj.share.File;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.EnumSet;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+public class SmbFileSystem extends FileSystem implements StreamingFileSystem {
+
+    public static final String FS_SMB_HOST = "fs.smb.host";
+    public static final String FS_SMB_PORT = "fs.smb.port";
+    public static final String FS_SMB_USER = "fs.smb.user";
+    public static final String FS_SMB_PASSWORD = "fs.smb.password";
+    public static final String FS_SMB_DOMAIN = "fs.smb.domain";
+    public static final String FS_SMB_SHARE = "fs.smb.share";
+
+    private static final int DEFAULT_SMB_PORT = 445;
+    private static final int DEFAULT_BLOCK_SIZE = 4 * 1024;
+
+    private URI uri;
+    private SMBClient client;
+    private String host;
+    private int port;
+    private String user;
+    private String password;
+    private String domain;
+    private String share;
+
+    @Override
+    public void initialize(URI uri, Configuration conf) throws IOException {
+        super.initialize(uri, conf);
+        this.uri = uri;
+
+        this.host = conf.get(FS_SMB_HOST, uri.getHost());
+        this.port =
+                conf.getInt(FS_SMB_PORT, uri.getPort() == -1 ? 
DEFAULT_SMB_PORT : uri.getPort());
+        this.user = conf.get(FS_SMB_USER);
+        this.password = conf.get(FS_SMB_PASSWORD, "");
+        this.domain = conf.get(FS_SMB_DOMAIN, "");
+        this.share = conf.get(FS_SMB_SHARE, "");
+
+        if (host == null || host.isEmpty()) {
+            throw new IOException("SMB host is not specified");
+        }
+        if (user == null || user.isEmpty()) {
+            throw new IOException("SMB user is not specified");
+        }
+        if (share == null || share.isEmpty()) {
+            throw new IOException("SMB share is not specified");
+        }
+
+        SmbConfig smbConfig = SmbConfig.builder().build();
+        this.client = new SMBClient(smbConfig);
+        setConf(conf);
+    }
+
+    @Override
+    public String getScheme() {
+        return "smb";
+    }
+
+    @Override
+    public URI getUri() {
+        return uri;
+    }
+
+    private DiskShare connectShare() throws IOException {
+        try {
+            Connection connection = client.connect(host, port);
+            AuthenticationContext ac =
+                    new AuthenticationContext(user, password.toCharArray(), 
domain);
+            Session session = connection.authenticate(ac);
+            return (DiskShare) session.connectShare(share);

Review Comment:
   Returning only the `DiskShare` loses ownership of the authenticated 
`Session` and leased `Connection`. In SMBJ 0.13, `DiskShare.close()` only 
disconnects the tree; it does not log off the session or release the connection 
lease. I reproduced this against Samba: after two `getFileStatus` calls, 
`SmbFileSystem.close()` left the cached `Connection` connected. Please retain 
all three resources and close the share, session, and connection on every 
success/failure path, including stream and listing-session wrappers, and add a 
multiple-operation lifecycle regression.



##########
seatunnel-connectors-v2/connector-file/connector-file-smb/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/smb/source/SmbFileSourceFactory.java:
##########
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.seatunnel.connectors.seatunnel.file.smb.source;
+
+import org.apache.seatunnel.api.configuration.util.OptionRule;
+import org.apache.seatunnel.api.options.ConnectorCommonOptions;
+import org.apache.seatunnel.api.source.SeaTunnelSource;
+import org.apache.seatunnel.api.source.SourceSplit;
+import org.apache.seatunnel.api.table.connector.TableSource;
+import org.apache.seatunnel.api.table.factory.Factory;
+import org.apache.seatunnel.api.table.factory.TableSourceFactory;
+import org.apache.seatunnel.api.table.factory.TableSourceFactoryContext;
+import 
org.apache.seatunnel.connectors.seatunnel.file.config.FileBaseSourceOptions;
+import org.apache.seatunnel.connectors.seatunnel.file.config.FileFormat;
+import 
org.apache.seatunnel.connectors.seatunnel.file.config.FilePostSyncAction;
+import org.apache.seatunnel.connectors.seatunnel.file.config.FileSyncMode;
+import org.apache.seatunnel.connectors.seatunnel.file.config.FileSystemType;
+import 
org.apache.seatunnel.connectors.seatunnel.file.smb.config.SmbFileSourceOptions;
+
+import com.google.auto.service.AutoService;
+
+import java.io.Serializable;
+import java.util.Arrays;
+
+@AutoService(Factory.class)
+public class SmbFileSourceFactory implements TableSourceFactory {
+    @Override
+    public String factoryIdentifier() {
+        return FileSystemType.SMB.getFileSystemPluginName();
+    }
+
+    @Override
+    public OptionRule optionRule() {
+        return OptionRule.builder()
+                .exclusive(SmbFileSourceOptions.TABLE_CONFIGS, 
SmbFileSourceOptions.FILE_PATH)
+                .required(SmbFileSourceOptions.SMB_HOST)

Review Comment:
   The documented `tables_configs` form cannot pass this `OptionRule`. I 
reproduced it with `ConfigValidator` using the documented shape (`host`, 
`user`, and `share` inside each table entry): validation fails with API-02 
because all three are required at the root. `BaseMultipleTableFileSourceConfig` 
later constructs each source config from the nested map, so requiring these 
only at the root is also incompatible with per-table SMB settings. Please make 
the root connection options optional for `tables_configs` (as SFTP does) and 
add validation/regression coverage for each nested table config.



##########
seatunnel-connectors-v2/connector-file/connector-file-smb/pom.xml:
##########
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You 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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.seatunnel</groupId>
+        <artifactId>connector-file</artifactId>
+        <version>${revision}</version>
+    </parent>
+
+    <artifactId>connector-file-smb</artifactId>
+    <name>SeaTunnel : Connectors V2 : File : Smb</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.seatunnel</groupId>
+            <artifactId>connector-file-base</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.seatunnel</groupId>
+            <artifactId>seatunnel-shade-hadoop3-uber</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.hierynomus</groupId>
+            <artifactId>smbj</artifactId>
+            <version>0.13.0</version>

Review Comment:
   This new runtime dependency is not registered in SeaTunnel's release-license 
inventory. The resolved runtime tree adds `smbj-0.13.0`, `asn-one-0.6.0`, 
`mbassador-1.3.0`, and `bcprov-jdk18on-1.75`, but none is present in 
`known-dependencies.txt` and this PR adds no corresponding LICENSE/NOTICE 
material under `seatunnel-dist/release-docs`. Please add the complete 
dependency and license metadata required by `docs/en/developer/new-license.md`; 
otherwise the dependency-license check and Apache release audit will fail.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to