diff --git a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/extensions/SASTokenProvider.java b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/extensions/SASTokenProvider.java index 2cd44f1b90..a2cd292b0b 100644 --- a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/extensions/SASTokenProvider.java +++ b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/extensions/SASTokenProvider.java @@ -33,6 +33,7 @@ public interface SASTokenProvider { String CHECK_ACCESS_OPERATION = "check-access"; + String CREATE_DIRECTORY_OPERATION = "create-directory"; String CREATE_FILE_OPERATION = "create-file"; String DELETE_OPERATION = "delete"; String DELETE_RECURSIVE_OPERATION = "delete-recursive"; @@ -40,7 +41,6 @@ public interface SASTokenProvider { String GET_STATUS_OPERATION = "get-status"; String GET_PROPERTIES_OPERATION = "get-properties"; String LIST_OPERATION = "list"; - String CREATE_DIRECTORY_OPERATION = "create-directory"; String READ_OPERATION = "read"; String RENAME_SOURCE_OPERATION = "rename-source"; String RENAME_DESTINATION_OPERATION = "rename-destination"; diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemDelegationSAS.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemDelegationSAS.java index 07b5804d11..c2c691e2f6 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemDelegationSAS.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemDelegationSAS.java @@ -25,6 +25,7 @@ import java.util.List; import java.util.UUID; +import org.junit.Assert; import org.junit.Assume; import org.junit.Test; import org.slf4j.Logger; @@ -365,4 +366,19 @@ public void testRootPath() throws Exception { } assertEquals(0, count); } + + @Test + // Test filesystem operations getXAttr and setXAttr + public void testProperties() throws Exception { + final AzureBlobFileSystem fs = getFileSystem(); + Path reqPath = new Path(UUID.randomUUID().toString()); + + fs.create(reqPath).close(); + + final String propertyName = "user.mime_type"; + final byte[] propertyValue = "text/plain".getBytes("utf-8"); + fs.setXAttr(reqPath, propertyName, propertyValue); + + assertArrayEquals(propertyValue, fs.getXAttr(reqPath, propertyName)); + } } diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/extensions/MockDelegationSASTokenProvider.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/extensions/MockDelegationSASTokenProvider.java index fa50bef454..121256c4db 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/extensions/MockDelegationSASTokenProvider.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/extensions/MockDelegationSASTokenProvider.java @@ -55,8 +55,8 @@ public void initialize(Configuration configuration, String accountName) throws I String appSecret = configuration.get(TestConfigurationKeys.FS_AZURE_TEST_APP_SECRET); String sktid = configuration.get(TestConfigurationKeys.FS_AZURE_TEST_APP_SERVICE_PRINCIPAL_TENANT_ID); String skoid = configuration.get(TestConfigurationKeys.FS_AZURE_TEST_APP_SERVICE_PRINCIPAL_OBJECT_ID); - String skt = SASGenerator.ISO_8601_FORMATTER.format(Instant.now().minusSeconds(SASGenerator.FIVE_MINUTES)); - String ske = SASGenerator.ISO_8601_FORMATTER.format(Instant.now().plusSeconds(SASGenerator.ONE_DAY)); + String skt = SASGenerator.ISO_8601_FORMATTER.format(Instant.now().minus(SASGenerator.FIVE_MINUTES)); + String ske = SASGenerator.ISO_8601_FORMATTER.format(Instant.now().plus(SASGenerator.ONE_DAY)); String skv = SASGenerator.AuthenticationVersion.Dec19.toString(); byte[] key = getUserDelegationKey(accountName, appID, appSecret, sktid, skt, ske, skv); diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/utils/DelegationSASGenerator.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/utils/DelegationSASGenerator.java index f84ed6ab4c..6f2209a6e8 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/utils/DelegationSASGenerator.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/utils/DelegationSASGenerator.java @@ -29,12 +29,12 @@ * Test Delegation SAS generator. */ public class DelegationSASGenerator extends SASGenerator { - private String skoid; - private String sktid; - private String skt; - private String ske; + private final String skoid; + private final String sktid; + private final String skt; + private final String ske; private final String sks = "b"; - private String skv; + private final String skv; public DelegationSASGenerator(byte[] userDelegationKey, String skoid, String sktid, String skt, String ske, String skv) { super(userDelegationKey); @@ -48,20 +48,18 @@ public DelegationSASGenerator(byte[] userDelegationKey, String skoid, String skt public String getDelegationSAS(String accountName, String containerName, String path, String operation, String saoid, String suoid, String scid) { - final String sv = AuthenticationVersion.Dec19.toString(); - final String st = ISO_8601_FORMATTER.format(Instant.now().minusSeconds(FIVE_MINUTES)); - final String se = ISO_8601_FORMATTER.format(Instant.now().plusSeconds(ONE_DAY)); + final String sv = AuthenticationVersion.Feb20.toString(); + final String st = ISO_8601_FORMATTER.format(Instant.now().minus(FIVE_MINUTES)); + final String se = ISO_8601_FORMATTER.format(Instant.now().plus(ONE_DAY)); String sr = "b"; String sdd = null; - String sp = null; + String sp; switch (operation) { - case SASTokenProvider.CHECK_ACCESS_OPERATION: - sp = "e"; - break; - case SASTokenProvider.WRITE_OPERATION: case SASTokenProvider.CREATE_FILE_OPERATION: case SASTokenProvider.CREATE_DIRECTORY_OPERATION: + case SASTokenProvider.WRITE_OPERATION: + case SASTokenProvider.SET_PROPERTIES_OPERATION: sp = "w"; break; case SASTokenProvider.DELETE_OPERATION: @@ -72,6 +70,7 @@ public String getDelegationSAS(String accountName, String containerName, String sr = "d"; sdd = Integer.toString(StringUtils.countMatches(path, "/")); break; + case SASTokenProvider.CHECK_ACCESS_OPERATION: case SASTokenProvider.GET_ACL_OPERATION: case SASTokenProvider.GET_STATUS_OPERATION: sp = "e"; @@ -79,6 +78,7 @@ public String getDelegationSAS(String accountName, String containerName, String case SASTokenProvider.LIST_OPERATION: sp = "l"; break; + case SASTokenProvider.GET_PROPERTIES_OPERATION: case SASTokenProvider.READ_OPERATION: sp = "r"; break; @@ -87,14 +87,12 @@ public String getDelegationSAS(String accountName, String containerName, String sp = "m"; break; case SASTokenProvider.SET_ACL_OPERATION: + case SASTokenProvider.SET_PERMISSION_OPERATION: sp = "p"; break; case SASTokenProvider.SET_OWNER_OPERATION: sp = "o"; break; - case SASTokenProvider.SET_PERMISSION_OPERATION: - sp = "p"; - break; default: throw new IllegalArgumentException(operation); } @@ -146,7 +144,7 @@ private String computeSignatureForSAS(String sp, String st, String se, String sv sb.append(accountName); sb.append("/"); sb.append(containerName); - if (path != null && sr != "c") { + if (path != null && !sr.equals("c")) { sb.append(path); } sb.append("\n"); diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/utils/SASGenerator.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/utils/SASGenerator.java index 34d504a9a0..2e9289d8d4 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/utils/SASGenerator.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/utils/SASGenerator.java @@ -20,6 +20,7 @@ import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets; +import java.time.Duration; import java.time.format.DateTimeFormatter; import java.time.ZoneId; import java.util.Locale; @@ -35,7 +36,8 @@ public abstract class SASGenerator { public enum AuthenticationVersion { Nov18("2018-11-09"), - Dec19("2019-12-12"); + Dec19("2019-12-12"), + Feb20("2020-02-10"); private final String ver; @@ -50,8 +52,8 @@ public String toString() { } protected static final Logger LOG = LoggerFactory.getLogger(SASGenerator.class); - public static final int FIVE_MINUTES = 5 * 60; - public static final int ONE_DAY = 24 * 60 * 60; + public static final Duration FIVE_MINUTES = Duration.ofMinutes(5); + public static final Duration ONE_DAY = Duration.ofDays(1); public static final DateTimeFormatter ISO_8601_FORMATTER = DateTimeFormatter .ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ROOT) diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/utils/ServiceSASGenerator.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/utils/ServiceSASGenerator.java index a76681b599..3d8496eff8 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/utils/ServiceSASGenerator.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/utils/ServiceSASGenerator.java @@ -40,8 +40,8 @@ public String getContainerSASWithFullControl(String accountName, String containe String sp = "rcwdl"; String sv = AuthenticationVersion.Nov18.toString(); String sr = "c"; - String st = ISO_8601_FORMATTER.format(Instant.now().minusSeconds(FIVE_MINUTES)); - String se = ISO_8601_FORMATTER.format(Instant.now().plusSeconds(ONE_DAY)); + String st = ISO_8601_FORMATTER.format(Instant.now().minus(FIVE_MINUTES)); + String se = ISO_8601_FORMATTER.format(Instant.now().plus(ONE_DAY)); String signature = computeSignatureForSAS(sp, st, se, sv, "c", accountName, containerName, null); @@ -71,7 +71,7 @@ private String computeSignatureForSAS(String sp, String st, String se, String sv sb.append(accountName); sb.append("/"); sb.append(containerName); - if (path != null && sr != "c") { + if (path != null && !sr.equals("c")) { //sb.append("/"); sb.append(path); }