Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* 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.nifi.services.smb;

import org.apache.nifi.logging.ComponentLog;

import java.io.IOException;
import java.net.URI;
import java.util.Map;

public interface SmbClientProvider {

/**
* Returns the identifier of the service location.
*
* @return the remote location
*/
default URI getServiceLocation() {
return getServiceLocation(Map.of());
}

/**
* Returns the identifier of the service location.
*
* @param attributes FlowFile attributes to evaluate connection properties
* @return the remote location
*/
URI getServiceLocation(Map<String, String> attributes);

/**
* Returns the smb client to use.
*
* @return the client.
*/
default SmbClientService getClient(ComponentLog logger) throws IOException {
return getClient(logger, Map.of());
}

/**
* Returns the smb client to use.
*
* @param attributes FlowFile attributes to evaluate connection properties
* @return the client.
*/
SmbClientService getClient(ComponentLog logger, Map<String, String> attributes) throws IOException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,6 @@
package org.apache.nifi.services.smb;

import org.apache.nifi.controller.ControllerService;
import org.apache.nifi.logging.ComponentLog;

import java.io.IOException;
import java.net.URI;

public interface SmbClientProviderService extends ControllerService {

/**
* Returns the identifier of the service location.
*
* @return the remote location
*/
URI getServiceLocation();

/**
* Returns the smb client to use.
*
* @return the client.
*/
SmbClientService getClient(ComponentLog logger) throws IOException;

public interface SmbClientProviderService extends SmbClientProvider, ControllerService {
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,29 @@
*/
package org.apache.nifi.services.smb;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Set;
import java.util.stream.Stream;

/**
* Service abstraction for Server Message Block protocol operations.
*/
public interface SmbClientService extends AutoCloseable {

Stream<SmbListableEntity> listFiles(String directoryPath);
boolean folderExists(String path);

boolean fileExists(String path);

Stream<SmbListableEntity> listFiles(String directoryPath, boolean recursive);

void ensureDirectory(String directoryPath);

void readFile(String filePath, OutputStream outputStream) throws IOException;
void readFile(String filePath, OutputStream outputStream, Set<SmbShareAccess> shareAccesses);

void writeFile(String filePath, InputStream inputStream, Set<SmbShareAccess> shareAccesses);

void renameFile(String oldFilePath, String newFilePath, boolean override);

void moveFile(String filePath, String directoryPath);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ public class SmbListableEntity implements ListableEntity {
private final long lastAccessTime;
private final long changeTime;
private final boolean directory;
private final boolean hidden;
private final long size;
private final long allocationSize;
private final URI serviceLocation;

private SmbListableEntity(String name, String shortName, String path, long lastModifiedTime, long creationTime,
long lastAccessTime, long changeTime, boolean directory,
long lastAccessTime, long changeTime, boolean directory, boolean hidden,
long size, long allocationSize, URI serviceLocation) {
this.name = name;
this.shortName = shortName;
Expand All @@ -64,6 +65,7 @@ private SmbListableEntity(String name, String shortName, String path, long lastM
this.lastAccessTime = lastAccessTime;
this.changeTime = changeTime;
this.directory = directory;
this.hidden = hidden;
this.size = size;
this.allocationSize = allocationSize;
this.serviceLocation = serviceLocation;
Expand Down Expand Up @@ -144,6 +146,10 @@ public boolean isDirectory() {
return directory;
}

public boolean isHidden() {
return hidden;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down Expand Up @@ -196,6 +202,7 @@ public static class SmbListableEntityBuilder {
private long lastAccessTime;
private long changeTime;
private boolean directory = false;
private boolean hidden = false;
private long size = 0;
private long allocationSize = 0;
private URI serviceLocation;
Expand Down Expand Up @@ -240,6 +247,11 @@ public SmbListableEntityBuilder setDirectory(boolean directory) {
return this;
}

public SmbListableEntityBuilder setHidden(boolean hidden) {
this.hidden = hidden;
return this;
}

public SmbListableEntityBuilder setSize(long size) {
this.size = size;
return this;
Expand All @@ -257,7 +269,7 @@ public SmbListableEntityBuilder setServiceLocation(URI serviceLocation) {

public SmbListableEntity build() {
return new SmbListableEntity(name, shortName, path, lastModifiedTime, creationTime, lastAccessTime, changeTime,
directory, size, allocationSize, serviceLocation);
directory, hidden, size, allocationSize, serviceLocation);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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.nifi.services.smb;

import java.util.Set;

public enum SmbShareAccess {
READ_ALLOWED,
WRITE_ALLOWED,
DELETE_ALLOWED;

public static final Set<SmbShareAccess> NONE = Set.of();
public static final Set<SmbShareAccess> READ = Set.of(READ_ALLOWED);
public static final Set<SmbShareAccess> READ_DELETE = Set.of(READ_ALLOWED, DELETE_ALLOWED);
public static final Set<SmbShareAccess> READ_WRITE_DELETE = Set.of(READ_ALLOWED, WRITE_ALLOWED, DELETE_ALLOWED);
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,11 @@
<artifactId>nifi-smb-smbj-common</artifactId>
<version>2.12.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.hierynomus</groupId>
<artifactId>smbj</artifactId>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.nifi.services.smb.SmbClientProviderService;
import org.apache.nifi.services.smb.SmbClientService;
import org.apache.nifi.services.smb.SmbException;
import org.apache.nifi.services.smb.SmbShareAccess;

import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -149,8 +150,8 @@ public void onTrigger(final ProcessContext context, final ProcessSession session

final SmbClientProviderService clientProviderService = context.getProperty(SMB_CLIENT_PROVIDER_SERVICE).asControllerService(SmbClientProviderService.class);

try (SmbClientService client = clientProviderService.getClient(getLogger())) {
flowFile = session.write(flowFile, outputStream -> client.readFile(filePath, outputStream));
try (SmbClientService client = clientProviderService.getClient(getLogger(), attributes)) {
flowFile = session.write(flowFile, outputStream -> client.readFile(filePath, outputStream, SmbShareAccess.READ));

session.transfer(flowFile, REL_SUCCESS);
} catch (Exception e) {
Expand Down Expand Up @@ -188,7 +189,7 @@ private void performCompletionStrategy(final ProcessContext context, final Map<S

final SmbClientProviderService clientProviderService = context.getProperty(SMB_CLIENT_PROVIDER_SERVICE).asControllerService(SmbClientProviderService.class);

try (SmbClientService client = clientProviderService.getClient(getLogger())) {
try (SmbClientService client = clientProviderService.getClient(getLogger(), attributes)) {
if (completionStrategy == CompletionStrategy.MOVE) {
final String destinationDirectory = context.getProperty(DESTINATION_DIRECTORY).evaluateAttributeExpressions(attributes).getValue();
final boolean createDestinationDirectory = context.getProperty(CREATE_DESTINATION_DIRECTORY).asBoolean();
Expand Down
Loading
Loading