Skip to content

Commit

Permalink
Fixed behavior of create* methods in file system and directory clients (
Browse files Browse the repository at this point in the history
  • Loading branch information
gapra-msft authored Apr 3, 2020
1 parent 8fc1c30 commit 07d4533
Show file tree
Hide file tree
Showing 19 changed files with 1,302 additions and 46 deletions.
2 changes: 2 additions & 0 deletions sdk/storage/azure-storage-file-datalake/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## 12.1.0-beta.1 (Unreleased)
- Fixed a NPE caused due to deserializing a non existent lastModifiedTime.
- Added an isDirectory property to PathProperties.
- Fixed DataLakeFileSystemClient.createFile/createDirectory, DataLakeDirectoryClient.createFile/createSubdirectory to not overwrite by default
- Added overloads to DataLakeFileSystemClient.createFile/createDirectory, DataLakeDirectoryClient.createFile/createSubdirectory to allow overwrite behavior.
- Fixed a bug where the Date header wouldn't be updated with a new value on request retry.

## 12.0.1 (2020-03-11)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.azure.storage.blob.specialized.BlockBlobAsyncClient;
import com.azure.storage.blob.specialized.SpecializedBlobClientBuilder;
import com.azure.storage.common.Utility;
import com.azure.storage.common.implementation.Constants;
import com.azure.storage.common.implementation.StorageImplUtils;
import com.azure.storage.file.datalake.implementation.models.PathResourceType;
import com.azure.storage.file.datalake.implementation.util.DataLakeImplUtils;
Expand Down Expand Up @@ -167,8 +168,8 @@ public DataLakeFileAsyncClient getFileAsyncClient(String fileName) {
}

/**
* Creates a new file within a directory. If a file with the same name already exists, the file will be
* overwritten. For more information, see the
* Creates a new file within a directory. By default this method will not overwrite an existing file.
* For more information, see the
* <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path/create">Azure
* Docs</a>.
*
Expand All @@ -180,8 +181,30 @@ public DataLakeFileAsyncClient getFileAsyncClient(String fileName) {
* @return A {@link Mono} containing a {@link DataLakeFileAsyncClient} used to interact with the file created.
*/
public Mono<DataLakeFileAsyncClient> createFile(String fileName) {
return createFile(fileName, false);
}

/**
* Creates a new file within a directory. For more information, see the
* <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path/create">Azure
* Docs</a>.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.file.datalake.DataLakeDirectoryAsyncClient.createFile#String-boolean}
*
* @param fileName Name of the file to create.
* @param overwrite Whether or not to overwrite, should the file exist.
* @return A {@link Mono} containing a {@link DataLakeFileAsyncClient} used to interact with the file created.
*/
public Mono<DataLakeFileAsyncClient> createFile(String fileName, boolean overwrite) {
DataLakeRequestConditions requestConditions = new DataLakeRequestConditions();
if (!overwrite) {
requestConditions.setIfNoneMatch(Constants.HeaderConstants.ETAG_WILDCARD);
}
try {
return createFileWithResponse(fileName, null, null, null, null, null).flatMap(FluxUtil::toMono);
return createFileWithResponse(fileName, null, null, null, null, requestConditions)
.flatMap(FluxUtil::toMono);
} catch (RuntimeException ex) {
return monoError(logger, ex);
}
Expand Down Expand Up @@ -286,8 +309,8 @@ public DataLakeDirectoryAsyncClient getSubdirectoryAsyncClient(String subdirecto
}

/**
* Creates a new sub-directory within a directory. If a sub-directory with the same name already exists, the
* sub-directory will be overwritten. For more information, see the
* Creates a new sub-directory within a directory. By default this method will not overwrite an existing
* sub-directory. For more information, see the
* <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path/create">Azure Docs</a>.
*
* <p><strong>Code Samples</strong></p>
Expand All @@ -299,8 +322,29 @@ public DataLakeDirectoryAsyncClient getSubdirectoryAsyncClient(String subdirecto
* created.
*/
public Mono<DataLakeDirectoryAsyncClient> createSubdirectory(String subdirectoryName) {
return createSubdirectory(subdirectoryName, false);
}

/**
* Creates a new sub-directory within a directory. For more information, see the
* <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path/create">Azure Docs</a>.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.file.datalake.DataLakeDirectoryAsyncClient.createSubdirectory#String-boolean}
*
* @param subdirectoryName Name of the sub-directory to create.
* @param overwrite Whether or not to overwrite, should the sub directory exist.
* @return A {@link Mono} containing a {@link DataLakeDirectoryAsyncClient} used to interact with the directory
* created.
*/
public Mono<DataLakeDirectoryAsyncClient> createSubdirectory(String subdirectoryName, boolean overwrite) {
DataLakeRequestConditions requestConditions = new DataLakeRequestConditions();
if (!overwrite) {
requestConditions.setIfNoneMatch(Constants.HeaderConstants.ETAG_WILDCARD);
}
try {
return createSubdirectoryWithResponse(subdirectoryName, null, null, null, null, null)
return createSubdirectoryWithResponse(subdirectoryName, null, null, null, null, requestConditions)
.flatMap(FluxUtil::toMono);
} catch (RuntimeException ex) {
return monoError(logger, ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.azure.core.util.Context;
import com.azure.core.util.logging.ClientLogger;
import com.azure.storage.blob.specialized.BlockBlobClient;
import com.azure.storage.common.implementation.Constants;
import com.azure.storage.common.implementation.StorageImplUtils;
import com.azure.storage.file.datalake.models.DataLakeRequestConditions;
import com.azure.storage.file.datalake.models.PathHttpHeaders;
Expand Down Expand Up @@ -140,8 +141,8 @@ public DataLakeFileClient getFileClient(String fileName) {
}

/**
* Creates a new file within a directory. If a file with the same name already exists, the file will be
* overwritten. For more information, see the
* Creates a new file within a directory. By default this method will not overwrite an existing file.
* For more information, see the
* <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path/create">Azure Docs</a>.
*
* <p><strong>Code Samples</strong></p>
Expand All @@ -152,7 +153,27 @@ public DataLakeFileClient getFileClient(String fileName) {
* @return A {@link DataLakeFileClient} used to interact with the file created.
*/
public DataLakeFileClient createFile(String fileName) {
return createFileWithResponse(fileName, null, null, null, null, null, null, Context.NONE).getValue();
return createFile(fileName, false);
}

/**
* Creates a new file within a directory. For more information, see the
* <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path/create">Azure Docs</a>.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.file.datalake.DataLakeDirectoryClient.createFile#String-boolean}
*
* @param fileName Name of the file to create.
* @param overwrite Whether or not to overwrite, should a file exist.
* @return A {@link DataLakeFileClient} used to interact with the file created.
*/
public DataLakeFileClient createFile(String fileName, boolean overwrite) {
DataLakeRequestConditions requestConditions = new DataLakeRequestConditions();
if (!overwrite) {
requestConditions.setIfNoneMatch(Constants.HeaderConstants.ETAG_WILDCARD);
}
return createFileWithResponse(fileName, null, null, null, null, requestConditions, null, null).getValue();
}

/**
Expand Down Expand Up @@ -242,8 +263,8 @@ public DataLakeDirectoryClient getSubdirectoryClient(String subdirectoryName) {
}

/**
* Creates a new sub-directory within a directory. If a sub-directory with the same name already exists, the
* sub-directory will be overwritten. For more information, see the
* Creates a new sub-directory within a directory. By default this method will not overwrite an existing
* sub-directory. For more information, see the
* <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path/create">Azure Docs</a>.
*
* <p><strong>Code Samples</strong></p>
Expand All @@ -254,8 +275,28 @@ public DataLakeDirectoryClient getSubdirectoryClient(String subdirectoryName) {
* @return A {@link DataLakeDirectoryClient} used to interact with the sub-directory created.
*/
public DataLakeDirectoryClient createSubdirectory(String subdirectoryName) {
return createSubdirectoryWithResponse(subdirectoryName, null, null, null,
null, null, null, Context.NONE).getValue();
return createSubdirectory(subdirectoryName, false);
}

/**
* Creates a new sub-directory within a directory. For more information, see the
* <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path/create">Azure Docs</a>.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.file.datalake.DataLakeDirectoryClient.createSubdirectory#String-boolean}
*
* @param subdirectoryName Name of the sub-directory to create.
* @param overwrite Whether or not to overwrite, should the sub-directory exist.
* @return A {@link DataLakeDirectoryClient} used to interact with the sub-directory created.
*/
public DataLakeDirectoryClient createSubdirectory(String subdirectoryName, boolean overwrite) {
DataLakeRequestConditions requestConditions = new DataLakeRequestConditions();
if (!overwrite) {
requestConditions.setIfNoneMatch(Constants.HeaderConstants.ETAG_WILDCARD);
}
return createSubdirectoryWithResponse(subdirectoryName, null, null, null, null, requestConditions, null, null)
.getValue();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.azure.storage.blob.specialized.BlockBlobAsyncClient;
import com.azure.storage.common.StorageSharedKeyCredential;
import com.azure.storage.common.Utility;
import com.azure.storage.common.implementation.Constants;
import com.azure.storage.common.implementation.StorageImplUtils;
import com.azure.storage.file.datalake.implementation.DataLakeStorageClientBuilder;
import com.azure.storage.file.datalake.implementation.DataLakeStorageClientImpl;
Expand Down Expand Up @@ -453,9 +454,8 @@ private Mono<FileSystemsListPathsResponse> listPathsSegment(String marker,
}

/**
* Creates a new file within a file system. If a file with the same name already exists, the file will be
* overwritten. For more information, see the
* <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path/create">Azure Docs</a>.
* Creates a new file within a file system. By default this method will not overwrite an existing file. For more
* information, see the <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path/create">Azure Docs</a>.
*
* <p><strong>Code Samples</strong></p>
*
Expand All @@ -465,8 +465,29 @@ private Mono<FileSystemsListPathsResponse> listPathsSegment(String marker,
* @return A {@link Mono} containing a {@link DataLakeFileAsyncClient} used to interact with the file created.
*/
public Mono<DataLakeFileAsyncClient> createFile(String fileName) {
return createFile(fileName, false);
}

/**
* Creates a new file within a file system. For more information, see the
* <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path/create">Azure Docs</a>.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.file.datalake.DataLakeFileSystemAsyncClient.createFile#String-boolean}
*
* @param fileName Name of the file to create.
* @param overwrite Whether or not to overwrite, should a file exist.
* @return A {@link Mono} containing a {@link DataLakeFileAsyncClient} used to interact with the file created.
*/
public Mono<DataLakeFileAsyncClient> createFile(String fileName, boolean overwrite) {
DataLakeRequestConditions requestConditions = new DataLakeRequestConditions();
if (!overwrite) {
requestConditions.setIfNoneMatch(Constants.HeaderConstants.ETAG_WILDCARD);
}
try {
return createFileWithResponse(fileName, null, null, null, null, null).flatMap(FluxUtil::toMono);
return createFileWithResponse(fileName, null, null, null, null, requestConditions)
.flatMap(FluxUtil::toMono);
} catch (RuntimeException ex) {
return monoError(logger, ex);
}
Expand Down Expand Up @@ -545,9 +566,8 @@ public Mono<Response<Void>> deleteFileWithResponse(String fileName, DataLakeRequ
}

/**
* Creates a new directory within a file system. If a directory with the same name already exists, the directory
* will be overwritten. For more information, see the
* <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path/create">Azure Docs</a>.
* Creates a new directory within a file system. By default this method will not overwrite an existing directory.
* For more information, see the <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path/create">Azure Docs</a>.
*
* <p><strong>Code Samples</strong></p>
*
Expand All @@ -558,8 +578,30 @@ public Mono<Response<Void>> deleteFileWithResponse(String fileName, DataLakeRequ
* created.
*/
public Mono<DataLakeDirectoryAsyncClient> createDirectory(String directoryName) {
return createDirectory(directoryName, false);
}

/**
* Creates a new directory within a file system. For more information, see the
* <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path/create">Azure Docs</a>.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.file.datalake.DataLakeFileSystemAsyncClient.createDirectory#String-boolean}
*
* @param directoryName Name of the directory to create.
* @param overwrite Whether or not to overwrite, should a directory exist.
* @return A {@link Mono} containing a {@link DataLakeDirectoryAsyncClient} used to interact with the directory
* created.
*/
public Mono<DataLakeDirectoryAsyncClient> createDirectory(String directoryName, boolean overwrite) {
DataLakeRequestConditions requestConditions = new DataLakeRequestConditions();
if (!overwrite) {
requestConditions.setIfNoneMatch(Constants.HeaderConstants.ETAG_WILDCARD);
}
try {
return createDirectoryWithResponse(directoryName, null, null, null, null, null).flatMap(FluxUtil::toMono);
return createDirectoryWithResponse(directoryName, null, null, null, null, requestConditions)
.flatMap(FluxUtil::toMono);
} catch (RuntimeException ex) {
return monoError(logger, ex);
}
Expand Down
Loading

0 comments on commit 07d4533

Please sign in to comment.