4343import org .apache .hadoop .fs .Path ;
4444import org .apache .hadoop .fs .PathIsNotEmptyDirectoryException ;
4545import org .apache .hadoop .fs .permission .FsPermission ;
46+ import org .apache .hadoop .hdds .conf .OzoneConfiguration ;
4647import org .apache .hadoop .ozone .OmUtils ;
4748import org .apache .hadoop .ozone .om .exceptions .OMException ;
4849import org .apache .hadoop .security .UserGroupInformation ;
@@ -87,11 +88,20 @@ public class BasicOzoneFileSystem extends FileSystem {
8788 private static final Pattern URL_SCHEMA_PATTERN =
8889 Pattern .compile ("([^\\ .]+)\\ .([^\\ .]+)\\ .{0,1}(.*)" );
8990
90- private static final String URI_EXCEPTION_TEXT = "Ozone file system URL " +
91- "should be one of the following formats: " +
92- "o3fs://bucket.volume/key OR " +
93- "o3fs://bucket.volume.om-host.example.com/key OR " +
94- "o3fs://bucket.volume.om-host.example.com:5678/key" ;
91+ private OzoneConfiguration getOzoneConf (Configuration conf ) {
92+
93+ return (conf instanceof OzoneConfiguration ) ?
94+ (OzoneConfiguration ) conf : new OzoneConfiguration (conf );
95+ }
96+
97+ private String getUriExceptionText (Configuration conf ) {
98+
99+ return "Ozone file system URL should be one of the following formats: "
100+ + "o3fs://bucket.volume/key OR "
101+ + "o3fs://bucket.volume.om-host.example.com/key OR "
102+ + "o3fs://bucket.volume.om-host.example.com:"
103+ + OmUtils .getOmRpcPort (getOzoneConf (conf )) + "/key" ;
104+ }
95105
96106 @ Override
97107 public void initialize (URI name , Configuration conf ) throws IOException {
@@ -106,7 +116,7 @@ public void initialize(URI name, Configuration conf) throws IOException {
106116 Matcher matcher = URL_SCHEMA_PATTERN .matcher (authority );
107117
108118 if (!matcher .matches ()) {
109- throw new IllegalArgumentException (URI_EXCEPTION_TEXT );
119+ throw new IllegalArgumentException (getUriExceptionText ( conf ) );
110120 }
111121 String bucketStr = matcher .group (1 );
112122 String volumeStr = matcher .group (2 );
@@ -118,14 +128,14 @@ public void initialize(URI name, Configuration conf) throws IOException {
118128 String [] parts = remaining .split (":" );
119129 // Array length should be either 1(host) or 2(host:port)
120130 if (parts .length > 2 ) {
121- throw new IllegalArgumentException (URI_EXCEPTION_TEXT );
131+ throw new IllegalArgumentException (getUriExceptionText ( conf ) );
122132 }
123133 omHost = parts [0 ];
124134 if (parts .length == 2 ) {
125135 try {
126136 omPort = Integer .parseInt (parts [1 ]);
127137 } catch (NumberFormatException e ) {
128- throw new IllegalArgumentException (URI_EXCEPTION_TEXT );
138+ throw new IllegalArgumentException (getUriExceptionText ( conf ) );
129139 }
130140 } else {
131141 // If port number is not specified, read it from config
0 commit comments