001/** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.fs.http.server; 019 020import org.apache.hadoop.classification.InterfaceAudience; 021import org.apache.hadoop.fs.XAttrCodec; 022import org.apache.hadoop.fs.XAttrSetFlag; 023import org.apache.hadoop.fs.http.client.HttpFSFileSystem; 024import org.apache.hadoop.fs.http.client.HttpFSFileSystem.Operation; 025import org.apache.hadoop.lib.wsrs.BooleanParam; 026import org.apache.hadoop.lib.wsrs.EnumParam; 027import org.apache.hadoop.lib.wsrs.EnumSetParam; 028import org.apache.hadoop.lib.wsrs.LongParam; 029import org.apache.hadoop.lib.wsrs.Param; 030import org.apache.hadoop.lib.wsrs.ParametersProvider; 031import org.apache.hadoop.lib.wsrs.ShortParam; 032import org.apache.hadoop.lib.wsrs.StringParam; 033 034import javax.ws.rs.ext.Provider; 035import java.util.HashMap; 036import java.util.Map; 037import java.util.regex.Pattern; 038 039import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_WEBHDFS_ACL_PERMISSION_PATTERN_DEFAULT; 040 041/** 042 * HttpFS ParametersProvider. 043 */ 044@Provider 045@InterfaceAudience.Private 046@SuppressWarnings("unchecked") 047public class HttpFSParametersProvider extends ParametersProvider { 048 049 private static final Map<Enum, Class<Param<?>>[]> PARAMS_DEF = 050 new HashMap<Enum, Class<Param<?>>[]>(); 051 052 static { 053 PARAMS_DEF.put(Operation.OPEN, 054 new Class[]{OffsetParam.class, LenParam.class}); 055 PARAMS_DEF.put(Operation.GETFILESTATUS, new Class[]{}); 056 PARAMS_DEF.put(Operation.LISTSTATUS, new Class[]{FilterParam.class}); 057 PARAMS_DEF.put(Operation.GETHOMEDIRECTORY, new Class[]{}); 058 PARAMS_DEF.put(Operation.GETCONTENTSUMMARY, new Class[]{}); 059 PARAMS_DEF.put(Operation.GETFILECHECKSUM, new Class[]{}); 060 PARAMS_DEF.put(Operation.GETFILEBLOCKLOCATIONS, new Class[]{}); 061 PARAMS_DEF.put(Operation.GETACLSTATUS, new Class[]{}); 062 PARAMS_DEF.put(Operation.GETTRASHROOT, new Class[]{}); 063 PARAMS_DEF.put(Operation.INSTRUMENTATION, new Class[]{}); 064 PARAMS_DEF.put(Operation.APPEND, new Class[]{DataParam.class}); 065 PARAMS_DEF.put(Operation.CONCAT, new Class[]{SourcesParam.class}); 066 PARAMS_DEF.put(Operation.CREATE, 067 new Class[]{PermissionParam.class, OverwriteParam.class, 068 ReplicationParam.class, BlockSizeParam.class, DataParam.class}); 069 PARAMS_DEF.put(Operation.MKDIRS, new Class[]{PermissionParam.class}); 070 PARAMS_DEF.put(Operation.RENAME, new Class[]{DestinationParam.class}); 071 PARAMS_DEF.put(Operation.SETOWNER, 072 new Class[]{OwnerParam.class, GroupParam.class}); 073 PARAMS_DEF.put(Operation.SETPERMISSION, new Class[]{PermissionParam.class}); 074 PARAMS_DEF.put(Operation.SETREPLICATION, 075 new Class[]{ReplicationParam.class}); 076 PARAMS_DEF.put(Operation.SETTIMES, 077 new Class[]{ModifiedTimeParam.class, AccessTimeParam.class}); 078 PARAMS_DEF.put(Operation.DELETE, new Class[]{RecursiveParam.class}); 079 PARAMS_DEF.put(Operation.SETACL, new Class[]{AclPermissionParam.class}); 080 PARAMS_DEF.put(Operation.REMOVEACL, new Class[]{}); 081 PARAMS_DEF.put(Operation.MODIFYACLENTRIES, 082 new Class[]{AclPermissionParam.class}); 083 PARAMS_DEF.put(Operation.REMOVEACLENTRIES, 084 new Class[]{AclPermissionParam.class}); 085 PARAMS_DEF.put(Operation.REMOVEDEFAULTACL, new Class[]{}); 086 PARAMS_DEF.put(Operation.SETXATTR, 087 new Class[]{XAttrNameParam.class, XAttrValueParam.class, 088 XAttrSetFlagParam.class}); 089 PARAMS_DEF.put(Operation.REMOVEXATTR, new Class[]{XAttrNameParam.class}); 090 PARAMS_DEF.put(Operation.GETXATTRS, 091 new Class[]{XAttrNameParam.class, XAttrEncodingParam.class}); 092 PARAMS_DEF.put(Operation.LISTXATTRS, new Class[]{}); 093 PARAMS_DEF.put(Operation.LISTSTATUS_BATCH, 094 new Class[]{StartAfterParam.class}); 095 } 096 097 public HttpFSParametersProvider() { 098 super(HttpFSFileSystem.OP_PARAM, HttpFSFileSystem.Operation.class, 099 PARAMS_DEF); 100 } 101 102 /** 103 * Class for access-time parameter. 104 */ 105 @InterfaceAudience.Private 106 public static class AccessTimeParam extends LongParam { 107 108 /** 109 * Parameter name. 110 */ 111 public static final String NAME = HttpFSFileSystem.ACCESS_TIME_PARAM; 112 /** 113 * Constructor. 114 */ 115 public AccessTimeParam() { 116 super(NAME, -1l); 117 } 118 } 119 120 /** 121 * Class for block-size parameter. 122 */ 123 @InterfaceAudience.Private 124 public static class BlockSizeParam extends LongParam { 125 126 /** 127 * Parameter name. 128 */ 129 public static final String NAME = HttpFSFileSystem.BLOCKSIZE_PARAM; 130 131 /** 132 * Constructor. 133 */ 134 public BlockSizeParam() { 135 super(NAME, -1l); 136 } 137 } 138 139 /** 140 * Class for data parameter. 141 */ 142 @InterfaceAudience.Private 143 public static class DataParam extends BooleanParam { 144 145 /** 146 * Parameter name. 147 */ 148 public static final String NAME = "data"; 149 150 /** 151 * Constructor. 152 */ 153 public DataParam() { 154 super(NAME, false); 155 } 156 } 157 158 /** 159 * Class for operation parameter. 160 */ 161 @InterfaceAudience.Private 162 public static class OperationParam extends EnumParam<HttpFSFileSystem.Operation> { 163 164 /** 165 * Parameter name. 166 */ 167 public static final String NAME = HttpFSFileSystem.OP_PARAM; 168 /** 169 * Constructor. 170 */ 171 public OperationParam(String operation) { 172 super(NAME, HttpFSFileSystem.Operation.class, 173 HttpFSFileSystem.Operation.valueOf(operation.toUpperCase())); 174 } 175 } 176 177 /** 178 * Class for delete's recursive parameter. 179 */ 180 @InterfaceAudience.Private 181 public static class RecursiveParam extends BooleanParam { 182 183 /** 184 * Parameter name. 185 */ 186 public static final String NAME = HttpFSFileSystem.RECURSIVE_PARAM; 187 188 /** 189 * Constructor. 190 */ 191 public RecursiveParam() { 192 super(NAME, false); 193 } 194 } 195 196 /** 197 * Class for filter parameter. 198 */ 199 @InterfaceAudience.Private 200 public static class FilterParam extends StringParam { 201 202 /** 203 * Parameter name. 204 */ 205 public static final String NAME = "filter"; 206 207 /** 208 * Constructor. 209 */ 210 public FilterParam() { 211 super(NAME, null); 212 } 213 214 } 215 216 /** 217 * Class for group parameter. 218 */ 219 @InterfaceAudience.Private 220 public static class GroupParam extends StringParam { 221 222 /** 223 * Parameter name. 224 */ 225 public static final String NAME = HttpFSFileSystem.GROUP_PARAM; 226 227 /** 228 * Constructor. 229 */ 230 public GroupParam() { 231 super(NAME, null); 232 } 233 234 } 235 236 /** 237 * Class for len parameter. 238 */ 239 @InterfaceAudience.Private 240 public static class LenParam extends LongParam { 241 242 /** 243 * Parameter name. 244 */ 245 public static final String NAME = "length"; 246 247 /** 248 * Constructor. 249 */ 250 public LenParam() { 251 super(NAME, -1l); 252 } 253 } 254 255 /** 256 * Class for modified-time parameter. 257 */ 258 @InterfaceAudience.Private 259 public static class ModifiedTimeParam extends LongParam { 260 261 /** 262 * Parameter name. 263 */ 264 public static final String NAME = HttpFSFileSystem.MODIFICATION_TIME_PARAM; 265 266 /** 267 * Constructor. 268 */ 269 public ModifiedTimeParam() { 270 super(NAME, -1l); 271 } 272 } 273 274 /** 275 * Class for offset parameter. 276 */ 277 @InterfaceAudience.Private 278 public static class OffsetParam extends LongParam { 279 280 /** 281 * Parameter name. 282 */ 283 public static final String NAME = "offset"; 284 285 /** 286 * Constructor. 287 */ 288 public OffsetParam() { 289 super(NAME, 0l); 290 } 291 } 292 293 /** 294 * Class for overwrite parameter. 295 */ 296 @InterfaceAudience.Private 297 public static class OverwriteParam extends BooleanParam { 298 299 /** 300 * Parameter name. 301 */ 302 public static final String NAME = HttpFSFileSystem.OVERWRITE_PARAM; 303 304 /** 305 * Constructor. 306 */ 307 public OverwriteParam() { 308 super(NAME, true); 309 } 310 } 311 312 /** 313 * Class for owner parameter. 314 */ 315 @InterfaceAudience.Private 316 public static class OwnerParam extends StringParam { 317 318 /** 319 * Parameter name. 320 */ 321 public static final String NAME = HttpFSFileSystem.OWNER_PARAM; 322 323 /** 324 * Constructor. 325 */ 326 public OwnerParam() { 327 super(NAME, null); 328 } 329 330 } 331 332 /** 333 * Class for permission parameter. 334 */ 335 @InterfaceAudience.Private 336 public static class PermissionParam extends ShortParam { 337 338 /** 339 * Parameter name. 340 */ 341 public static final String NAME = HttpFSFileSystem.PERMISSION_PARAM; 342 343 344 /** 345 * Constructor. 346 */ 347 public PermissionParam() { 348 super(NAME, HttpFSFileSystem.DEFAULT_PERMISSION, 8); 349 } 350 351 } 352 353 /** 354 * Class for AclPermission parameter. 355 */ 356 @InterfaceAudience.Private 357 public static class AclPermissionParam extends StringParam { 358 359 /** 360 * Parameter name. 361 */ 362 public static final String NAME = HttpFSFileSystem.ACLSPEC_PARAM; 363 364 /** 365 * Constructor. 366 */ 367 public AclPermissionParam() { 368 super(NAME, HttpFSFileSystem.ACLSPEC_DEFAULT, 369 Pattern.compile(DFS_WEBHDFS_ACL_PERMISSION_PATTERN_DEFAULT)); 370 } 371 } 372 373 /** 374 * Class for replication parameter. 375 */ 376 @InterfaceAudience.Private 377 public static class ReplicationParam extends ShortParam { 378 379 /** 380 * Parameter name. 381 */ 382 public static final String NAME = HttpFSFileSystem.REPLICATION_PARAM; 383 384 /** 385 * Constructor. 386 */ 387 public ReplicationParam() { 388 super(NAME, (short) -1); 389 } 390 } 391 392 /** 393 * Class for concat sources parameter. 394 */ 395 @InterfaceAudience.Private 396 public static class SourcesParam extends StringParam { 397 398 /** 399 * Parameter name. 400 */ 401 public static final String NAME = HttpFSFileSystem.SOURCES_PARAM; 402 403 /** 404 * Constructor. 405 */ 406 public SourcesParam() { 407 super(NAME, null); 408 } 409 } 410 411 /** 412 * Class for to-path parameter. 413 */ 414 @InterfaceAudience.Private 415 public static class DestinationParam extends StringParam { 416 417 /** 418 * Parameter name. 419 */ 420 public static final String NAME = HttpFSFileSystem.DESTINATION_PARAM; 421 422 /** 423 * Constructor. 424 */ 425 public DestinationParam() { 426 super(NAME, null); 427 } 428 } 429 430 /** 431 * Class for xattr parameter. 432 */ 433 @InterfaceAudience.Private 434 public static class XAttrNameParam extends StringParam { 435 public static final String XATTR_NAME_REGX = 436 "^(user\\.|trusted\\.|system\\.|security\\.).+"; 437 /** 438 * Parameter name. 439 */ 440 public static final String NAME = HttpFSFileSystem.XATTR_NAME_PARAM; 441 private static final Pattern pattern = Pattern.compile(XATTR_NAME_REGX); 442 443 /** 444 * Constructor. 445 */ 446 public XAttrNameParam() { 447 super(NAME, null, pattern); 448 } 449 } 450 451 /** 452 * Class for xattr parameter. 453 */ 454 @InterfaceAudience.Private 455 public static class XAttrValueParam extends StringParam { 456 /** 457 * Parameter name. 458 */ 459 public static final String NAME = HttpFSFileSystem.XATTR_VALUE_PARAM; 460 461 /** 462 * Constructor. 463 */ 464 public XAttrValueParam() { 465 super(NAME, null); 466 } 467 } 468 469 /** 470 * Class for xattr parameter. 471 */ 472 @InterfaceAudience.Private 473 public static class XAttrSetFlagParam extends EnumSetParam<XAttrSetFlag> { 474 /** 475 * Parameter name. 476 */ 477 public static final String NAME = HttpFSFileSystem.XATTR_SET_FLAG_PARAM; 478 479 /** 480 * Constructor. 481 */ 482 public XAttrSetFlagParam() { 483 super(NAME, XAttrSetFlag.class, null); 484 } 485 } 486 487 /** 488 * Class for xattr parameter. 489 */ 490 @InterfaceAudience.Private 491 public static class XAttrEncodingParam extends EnumParam<XAttrCodec> { 492 /** 493 * Parameter name. 494 */ 495 public static final String NAME = HttpFSFileSystem.XATTR_ENCODING_PARAM; 496 497 /** 498 * Constructor. 499 */ 500 public XAttrEncodingParam() { 501 super(NAME, XAttrCodec.class, null); 502 } 503 } 504 505 /** 506 * Class for startafter parameter. 507 */ 508 @InterfaceAudience.Private 509 public static class StartAfterParam extends StringParam { 510 /** 511 * Parameter name. 512 */ 513 public static final String NAME = HttpFSFileSystem.START_AFTER_PARAM; 514 515 /** 516 * Constructor. 517 */ 518 public StartAfterParam() { 519 super(NAME, null); 520 } 521 } 522}