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 */ 018 019package org.apache.hadoop.fs.http.server; 020 021import org.apache.hadoop.classification.InterfaceAudience; 022import org.apache.hadoop.conf.Configuration; 023import org.apache.hadoop.fs.FileSystem; 024import org.apache.hadoop.fs.XAttrCodec; 025import org.apache.hadoop.fs.XAttrSetFlag; 026import org.apache.hadoop.fs.http.client.HttpFSFileSystem; 027import org.apache.hadoop.fs.http.server.HttpFSParametersProvider.AccessTimeParam; 028import org.apache.hadoop.fs.http.server.HttpFSParametersProvider.AclPermissionParam; 029import org.apache.hadoop.fs.http.server.HttpFSParametersProvider.BlockSizeParam; 030import org.apache.hadoop.fs.http.server.HttpFSParametersProvider.DataParam; 031import org.apache.hadoop.fs.http.server.HttpFSParametersProvider.DestinationParam; 032import org.apache.hadoop.fs.http.server.HttpFSParametersProvider.FilterParam; 033import org.apache.hadoop.fs.http.server.HttpFSParametersProvider.GroupParam; 034import org.apache.hadoop.fs.http.server.HttpFSParametersProvider.LenParam; 035import org.apache.hadoop.fs.http.server.HttpFSParametersProvider.ModifiedTimeParam; 036import org.apache.hadoop.fs.http.server.HttpFSParametersProvider.NewLengthParam; 037import org.apache.hadoop.fs.http.server.HttpFSParametersProvider.OffsetParam; 038import org.apache.hadoop.fs.http.server.HttpFSParametersProvider.OperationParam; 039import org.apache.hadoop.fs.http.server.HttpFSParametersProvider.OverwriteParam; 040import org.apache.hadoop.fs.http.server.HttpFSParametersProvider.OwnerParam; 041import org.apache.hadoop.fs.http.server.HttpFSParametersProvider.PermissionParam; 042import org.apache.hadoop.fs.http.server.HttpFSParametersProvider.PolicyNameParam; 043import org.apache.hadoop.fs.http.server.HttpFSParametersProvider.RecursiveParam; 044import org.apache.hadoop.fs.http.server.HttpFSParametersProvider.ReplicationParam; 045import org.apache.hadoop.fs.http.server.HttpFSParametersProvider.SourcesParam; 046import org.apache.hadoop.fs.http.server.HttpFSParametersProvider.XAttrEncodingParam; 047import org.apache.hadoop.fs.http.server.HttpFSParametersProvider.XAttrNameParam; 048import org.apache.hadoop.fs.http.server.HttpFSParametersProvider.XAttrSetFlagParam; 049import org.apache.hadoop.fs.http.server.HttpFSParametersProvider.XAttrValueParam; 050import org.apache.hadoop.lib.service.FileSystemAccess; 051import org.apache.hadoop.lib.service.FileSystemAccessException; 052import org.apache.hadoop.lib.service.Groups; 053import org.apache.hadoop.lib.service.Instrumentation; 054import org.apache.hadoop.lib.servlet.FileSystemReleaseFilter; 055import org.apache.hadoop.lib.wsrs.InputStreamEntity; 056import org.apache.hadoop.lib.wsrs.Parameters; 057import org.apache.hadoop.security.UserGroupInformation; 058import org.apache.hadoop.security.token.delegation.web.HttpUserGroupInformation; 059import org.json.simple.JSONObject; 060import org.slf4j.Logger; 061import org.slf4j.LoggerFactory; 062import org.slf4j.MDC; 063 064import javax.servlet.http.HttpServletRequest; 065import javax.ws.rs.Consumes; 066import javax.ws.rs.DELETE; 067import javax.ws.rs.GET; 068import javax.ws.rs.POST; 069import javax.ws.rs.PUT; 070import javax.ws.rs.Path; 071import javax.ws.rs.PathParam; 072import javax.ws.rs.Produces; 073import javax.ws.rs.QueryParam; 074import javax.ws.rs.core.Context; 075import javax.ws.rs.core.MediaType; 076import javax.ws.rs.core.Response; 077import javax.ws.rs.core.UriBuilder; 078import javax.ws.rs.core.UriInfo; 079 080import java.io.IOException; 081import java.io.InputStream; 082import java.net.URI; 083import java.security.AccessControlException; 084import java.security.PrivilegedExceptionAction; 085import java.text.MessageFormat; 086import java.util.EnumSet; 087import java.util.List; 088import java.util.Map; 089 090/** 091 * Main class of HttpFSServer server. 092 * <p> 093 * The <code>HttpFSServer</code> class uses Jersey JAX-RS to binds HTTP requests to the 094 * different operations. 095 */ 096@Path(HttpFSFileSystem.SERVICE_VERSION) 097@InterfaceAudience.Private 098public class HttpFSServer { 099 private static Logger AUDIT_LOG = LoggerFactory.getLogger("httpfsaudit"); 100 private static final Logger LOG = LoggerFactory.getLogger(HttpFSServer.class); 101 102 /** 103 * Executes a {@link FileSystemAccess.FileSystemExecutor} using a filesystem for the effective 104 * user. 105 * 106 * @param ugi user making the request. 107 * @param executor FileSystemExecutor to execute. 108 * 109 * @return FileSystemExecutor response 110 * 111 * @throws IOException thrown if an IO error occurs. 112 * @throws FileSystemAccessException thrown if a FileSystemAccess releated error occurred. Thrown 113 * exceptions are handled by {@link HttpFSExceptionProvider}. 114 */ 115 private <T> T fsExecute(UserGroupInformation ugi, FileSystemAccess.FileSystemExecutor<T> executor) 116 throws IOException, FileSystemAccessException { 117 FileSystemAccess fsAccess = HttpFSServerWebApp.get().get(FileSystemAccess.class); 118 Configuration conf = HttpFSServerWebApp.get().get(FileSystemAccess.class).getFileSystemConfiguration(); 119 return fsAccess.execute(ugi.getShortUserName(), conf, executor); 120 } 121 122 /** 123 * Returns a filesystem instance. The fileystem instance is wired for release at the completion of 124 * the current Servlet request via the {@link FileSystemReleaseFilter}. 125 * <p> 126 * If a do-as user is specified, the current user must be a valid proxyuser, otherwise an 127 * <code>AccessControlException</code> will be thrown. 128 * 129 * @param ugi principal for whom the filesystem instance is. 130 * 131 * @return a filesystem for the specified user or do-as user. 132 * 133 * @throws IOException thrown if an IO error occurred. Thrown exceptions are 134 * handled by {@link HttpFSExceptionProvider}. 135 * @throws FileSystemAccessException thrown if a FileSystemAccess releated error occurred. Thrown 136 * exceptions are handled by {@link HttpFSExceptionProvider}. 137 */ 138 private FileSystem createFileSystem(UserGroupInformation ugi) 139 throws IOException, FileSystemAccessException { 140 String hadoopUser = ugi.getShortUserName(); 141 FileSystemAccess fsAccess = HttpFSServerWebApp.get().get(FileSystemAccess.class); 142 Configuration conf = HttpFSServerWebApp.get().get(FileSystemAccess.class).getFileSystemConfiguration(); 143 FileSystem fs = fsAccess.createFileSystem(hadoopUser, conf); 144 FileSystemReleaseFilter.setFileSystem(fs); 145 return fs; 146 } 147 148 private void enforceRootPath(HttpFSFileSystem.Operation op, String path) { 149 if (!path.equals("/")) { 150 throw new UnsupportedOperationException( 151 MessageFormat.format("Operation [{0}], invalid path [{1}], must be '/'", 152 op, path)); 153 } 154 } 155 156 /** 157 * Special binding for '/' as it is not handled by the wildcard binding. 158 * 159 * @param op the HttpFS operation of the request. 160 * @param params the HttpFS parameters of the request. 161 * 162 * @return the request response. 163 * 164 * @throws IOException thrown if an IO error occurred. Thrown exceptions are 165 * handled by {@link HttpFSExceptionProvider}. 166 * @throws FileSystemAccessException thrown if a FileSystemAccess releated 167 * error occurred. Thrown exceptions are handled by 168 * {@link HttpFSExceptionProvider}. 169 */ 170 @GET 171 @Produces(MediaType.APPLICATION_JSON) 172 public Response getRoot(@QueryParam(OperationParam.NAME) OperationParam op, 173 @Context Parameters params, 174 @Context HttpServletRequest request) 175 throws IOException, FileSystemAccessException { 176 return get("", op, params, request); 177 } 178 179 private String makeAbsolute(String path) { 180 return "/" + ((path != null) ? path : ""); 181 } 182 183 /** 184 * Binding to handle GET requests, supported operations are 185 * 186 * @param path the path for operation. 187 * @param op the HttpFS operation of the request. 188 * @param params the HttpFS parameters of the request. 189 * 190 * @return the request response. 191 * 192 * @throws IOException thrown if an IO error occurred. Thrown exceptions are 193 * handled by {@link HttpFSExceptionProvider}. 194 * @throws FileSystemAccessException thrown if a FileSystemAccess releated 195 * error occurred. Thrown exceptions are handled by 196 * {@link HttpFSExceptionProvider}. 197 */ 198 @GET 199 @Path("{path:.*}") 200 @Produces({MediaType.APPLICATION_OCTET_STREAM, MediaType.APPLICATION_JSON}) 201 public Response get(@PathParam("path") String path, 202 @QueryParam(OperationParam.NAME) OperationParam op, 203 @Context Parameters params, 204 @Context HttpServletRequest request) 205 throws IOException, FileSystemAccessException { 206 UserGroupInformation user = HttpUserGroupInformation.get(); 207 Response response; 208 path = makeAbsolute(path); 209 MDC.put(HttpFSFileSystem.OP_PARAM, op.value().name()); 210 MDC.put("hostname", request.getRemoteAddr()); 211 switch (op.value()) { 212 case OPEN: { 213 //Invoking the command directly using an unmanaged FileSystem that is 214 // released by the FileSystemReleaseFilter 215 final FSOperations.FSOpen command = new FSOperations.FSOpen(path); 216 final FileSystem fs = createFileSystem(user); 217 InputStream is = null; 218 UserGroupInformation ugi = UserGroupInformation 219 .createProxyUser(user.getShortUserName(), 220 UserGroupInformation.getLoginUser()); 221 try { 222 is = ugi.doAs(new PrivilegedExceptionAction<InputStream>() { 223 @Override 224 public InputStream run() throws Exception { 225 return command.execute(fs); 226 } 227 }); 228 } catch (InterruptedException ie) { 229 LOG.info("Open interrupted.", ie); 230 Thread.currentThread().interrupt(); 231 } 232 Long offset = params.get(OffsetParam.NAME, OffsetParam.class); 233 Long len = params.get(LenParam.NAME, LenParam.class); 234 AUDIT_LOG.info("[{}] offset [{}] len [{}]", 235 new Object[] { path, offset, len }); 236 InputStreamEntity entity = new InputStreamEntity(is, offset, len); 237 response = 238 Response.ok(entity).type(MediaType.APPLICATION_OCTET_STREAM).build(); 239 break; 240 } 241 case GETFILESTATUS: { 242 FSOperations.FSFileStatus command = new FSOperations.FSFileStatus(path); 243 Map json = fsExecute(user, command); 244 AUDIT_LOG.info("[{}]", path); 245 response = Response.ok(json).type(MediaType.APPLICATION_JSON).build(); 246 break; 247 } 248 case LISTSTATUS: { 249 String filter = params.get(FilterParam.NAME, FilterParam.class); 250 FSOperations.FSListStatus command = 251 new FSOperations.FSListStatus(path, filter); 252 Map json = fsExecute(user, command); 253 AUDIT_LOG.info("[{}] filter [{}]", path, (filter != null) ? filter : "-"); 254 response = Response.ok(json).type(MediaType.APPLICATION_JSON).build(); 255 break; 256 } 257 case GETHOMEDIRECTORY: { 258 enforceRootPath(op.value(), path); 259 FSOperations.FSHomeDir command = new FSOperations.FSHomeDir(); 260 JSONObject json = fsExecute(user, command); 261 AUDIT_LOG.info(""); 262 response = Response.ok(json).type(MediaType.APPLICATION_JSON).build(); 263 break; 264 } 265 case INSTRUMENTATION: { 266 enforceRootPath(op.value(), path); 267 Groups groups = HttpFSServerWebApp.get().get(Groups.class); 268 List<String> userGroups = groups.getGroups(user.getShortUserName()); 269 if (!userGroups.contains(HttpFSServerWebApp.get().getAdminGroup())) { 270 throw new AccessControlException( 271 "User not in HttpFSServer admin group"); 272 } 273 Instrumentation instrumentation = 274 HttpFSServerWebApp.get().get(Instrumentation.class); 275 Map snapshot = instrumentation.getSnapshot(); 276 response = Response.ok(snapshot).build(); 277 break; 278 } 279 case GETCONTENTSUMMARY: { 280 FSOperations.FSContentSummary command = 281 new FSOperations.FSContentSummary(path); 282 Map json = fsExecute(user, command); 283 AUDIT_LOG.info("[{}]", path); 284 response = Response.ok(json).type(MediaType.APPLICATION_JSON).build(); 285 break; 286 } 287 case GETFILECHECKSUM: { 288 FSOperations.FSFileChecksum command = 289 new FSOperations.FSFileChecksum(path); 290 Map json = fsExecute(user, command); 291 AUDIT_LOG.info("[{}]", path); 292 response = Response.ok(json).type(MediaType.APPLICATION_JSON).build(); 293 break; 294 } 295 case GETFILEBLOCKLOCATIONS: { 296 response = Response.status(Response.Status.BAD_REQUEST).build(); 297 break; 298 } 299 case GETACLSTATUS: { 300 FSOperations.FSAclStatus command = new FSOperations.FSAclStatus(path); 301 Map json = fsExecute(user, command); 302 AUDIT_LOG.info("ACL status for [{}]", path); 303 response = Response.ok(json).type(MediaType.APPLICATION_JSON).build(); 304 break; 305 } 306 case GETXATTRS: { 307 List<String> xattrNames = 308 params.getValues(XAttrNameParam.NAME, XAttrNameParam.class); 309 XAttrCodec encoding = 310 params.get(XAttrEncodingParam.NAME, XAttrEncodingParam.class); 311 FSOperations.FSGetXAttrs command = 312 new FSOperations.FSGetXAttrs(path, xattrNames, encoding); 313 @SuppressWarnings("rawtypes") Map json = fsExecute(user, command); 314 AUDIT_LOG.info("XAttrs for [{}]", path); 315 response = Response.ok(json).type(MediaType.APPLICATION_JSON).build(); 316 break; 317 } 318 case LISTXATTRS: { 319 FSOperations.FSListXAttrs command = new FSOperations.FSListXAttrs(path); 320 @SuppressWarnings("rawtypes") Map json = fsExecute(user, command); 321 AUDIT_LOG.info("XAttr names for [{}]", path); 322 response = Response.ok(json).type(MediaType.APPLICATION_JSON).build(); 323 break; 324 } 325 case GETALLSTORAGEPOLICY: { 326 FSOperations.FSGetAllStoragePolicies command = 327 new FSOperations.FSGetAllStoragePolicies(); 328 JSONObject json = fsExecute(user, command); 329 AUDIT_LOG.info("[{}]", path); 330 response = Response.ok(json).type(MediaType.APPLICATION_JSON).build(); 331 break; 332 } 333 case GETSTORAGEPOLICY: { 334 FSOperations.FSGetStoragePolicy command = 335 new FSOperations.FSGetStoragePolicy(path); 336 JSONObject json = fsExecute(user, command); 337 AUDIT_LOG.info("[{}]", path); 338 response = Response.ok(json).type(MediaType.APPLICATION_JSON).build(); 339 break; 340 } 341 default: { 342 throw new IOException( 343 MessageFormat.format("Invalid HTTP GET operation [{0}]", op.value())); 344 } 345 } 346 return response; 347 } 348 349 350 /** 351 * Binding to handle DELETE requests. 352 * 353 * @param path the path for operation. 354 * @param op the HttpFS operation of the request. 355 * @param params the HttpFS parameters of the request. 356 * 357 * @return the request response. 358 * 359 * @throws IOException thrown if an IO error occurred. Thrown exceptions are 360 * handled by {@link HttpFSExceptionProvider}. 361 * @throws FileSystemAccessException thrown if a FileSystemAccess releated 362 * error occurred. Thrown exceptions are handled by 363 * {@link HttpFSExceptionProvider}. 364 */ 365 @DELETE 366 @Path("{path:.*}") 367 @Produces(MediaType.APPLICATION_JSON) 368 public Response delete(@PathParam("path") String path, 369 @QueryParam(OperationParam.NAME) OperationParam op, 370 @Context Parameters params, 371 @Context HttpServletRequest request) 372 throws IOException, FileSystemAccessException { 373 UserGroupInformation user = HttpUserGroupInformation.get(); 374 Response response; 375 path = makeAbsolute(path); 376 MDC.put(HttpFSFileSystem.OP_PARAM, op.value().name()); 377 MDC.put("hostname", request.getRemoteAddr()); 378 switch (op.value()) { 379 case DELETE: { 380 Boolean recursive = 381 params.get(RecursiveParam.NAME, RecursiveParam.class); 382 AUDIT_LOG.info("[{}] recursive [{}]", path, recursive); 383 FSOperations.FSDelete command = 384 new FSOperations.FSDelete(path, recursive); 385 JSONObject json = fsExecute(user, command); 386 response = Response.ok(json).type(MediaType.APPLICATION_JSON).build(); 387 break; 388 } 389 default: { 390 throw new IOException( 391 MessageFormat.format("Invalid HTTP DELETE operation [{0}]", 392 op.value())); 393 } 394 } 395 return response; 396 } 397 398 /** 399 * Binding to handle POST requests. 400 * 401 * @param is the inputstream for the request payload. 402 * @param uriInfo the of the request. 403 * @param path the path for operation. 404 * @param op the HttpFS operation of the request. 405 * @param params the HttpFS parameters of the request. 406 * 407 * @return the request response. 408 * 409 * @throws IOException thrown if an IO error occurred. Thrown exceptions are 410 * handled by {@link HttpFSExceptionProvider}. 411 * @throws FileSystemAccessException thrown if a FileSystemAccess releated 412 * error occurred. Thrown exceptions are handled by 413 * {@link HttpFSExceptionProvider}. 414 */ 415 @POST 416 @Path("{path:.*}") 417 @Consumes({"*/*"}) 418 @Produces({MediaType.APPLICATION_JSON}) 419 public Response post(InputStream is, 420 @Context UriInfo uriInfo, 421 @PathParam("path") String path, 422 @QueryParam(OperationParam.NAME) OperationParam op, 423 @Context Parameters params, 424 @Context HttpServletRequest request) 425 throws IOException, FileSystemAccessException { 426 UserGroupInformation user = HttpUserGroupInformation.get(); 427 Response response; 428 path = makeAbsolute(path); 429 MDC.put(HttpFSFileSystem.OP_PARAM, op.value().name()); 430 MDC.put("hostname", request.getRemoteAddr()); 431 switch (op.value()) { 432 case APPEND: { 433 Boolean hasData = params.get(DataParam.NAME, DataParam.class); 434 if (!hasData) { 435 response = Response.temporaryRedirect( 436 createUploadRedirectionURL(uriInfo, 437 HttpFSFileSystem.Operation.APPEND)).build(); 438 } else { 439 FSOperations.FSAppend command = 440 new FSOperations.FSAppend(is, path); 441 fsExecute(user, command); 442 AUDIT_LOG.info("[{}]", path); 443 response = Response.ok().type(MediaType.APPLICATION_JSON).build(); 444 } 445 break; 446 } 447 case CONCAT: { 448 System.out.println("HTTPFS SERVER CONCAT"); 449 String sources = params.get(SourcesParam.NAME, SourcesParam.class); 450 451 FSOperations.FSConcat command = 452 new FSOperations.FSConcat(path, sources.split(",")); 453 fsExecute(user, command); 454 AUDIT_LOG.info("[{}]", path); 455 System.out.println("SENT RESPONSE"); 456 response = Response.ok().build(); 457 break; 458 } 459 case TRUNCATE: { 460 Long newLength = params.get(NewLengthParam.NAME, NewLengthParam.class); 461 FSOperations.FSTruncate command = 462 new FSOperations.FSTruncate(path, newLength); 463 JSONObject json = fsExecute(user, command); 464 AUDIT_LOG.info("Truncate [{}] to length [{}]", path, newLength); 465 response = Response.ok(json).type(MediaType.APPLICATION_JSON).build(); 466 break; 467 } 468 case UNSETSTORAGEPOLICY: { 469 FSOperations.FSUnsetStoragePolicy command = 470 new FSOperations.FSUnsetStoragePolicy(path); 471 fsExecute(user, command); 472 AUDIT_LOG.info("Unset storage policy [{}]", path); 473 response = Response.ok().build(); 474 break; 475 } 476 default: { 477 throw new IOException( 478 MessageFormat.format("Invalid HTTP POST operation [{0}]", 479 op.value())); 480 } 481 } 482 return response; 483 } 484 485 /** 486 * Creates the URL for an upload operation (create or append). 487 * 488 * @param uriInfo uri info of the request. 489 * @param uploadOperation operation for the upload URL. 490 * 491 * @return the URI for uploading data. 492 */ 493 protected URI createUploadRedirectionURL(UriInfo uriInfo, Enum<?> uploadOperation) { 494 UriBuilder uriBuilder = uriInfo.getRequestUriBuilder(); 495 uriBuilder = uriBuilder.replaceQueryParam(OperationParam.NAME, uploadOperation). 496 queryParam(DataParam.NAME, Boolean.TRUE); 497 return uriBuilder.build(null); 498 } 499 500 501 /** 502 * Binding to handle PUT requests. 503 * 504 * @param is the inputstream for the request payload. 505 * @param uriInfo the of the request. 506 * @param path the path for operation. 507 * @param op the HttpFS operation of the request. 508 * @param params the HttpFS parameters of the request. 509 * 510 * @return the request response. 511 * 512 * @throws IOException thrown if an IO error occurred. Thrown exceptions are 513 * handled by {@link HttpFSExceptionProvider}. 514 * @throws FileSystemAccessException thrown if a FileSystemAccess releated 515 * error occurred. Thrown exceptions are handled by 516 * {@link HttpFSExceptionProvider}. 517 */ 518 @PUT 519 @Path("{path:.*}") 520 @Consumes({"*/*"}) 521 @Produces({MediaType.APPLICATION_JSON}) 522 public Response put(InputStream is, 523 @Context UriInfo uriInfo, 524 @PathParam("path") String path, 525 @QueryParam(OperationParam.NAME) OperationParam op, 526 @Context Parameters params, 527 @Context HttpServletRequest request) 528 throws IOException, FileSystemAccessException { 529 UserGroupInformation user = HttpUserGroupInformation.get(); 530 Response response; 531 path = makeAbsolute(path); 532 MDC.put(HttpFSFileSystem.OP_PARAM, op.value().name()); 533 MDC.put("hostname", request.getRemoteAddr()); 534 switch (op.value()) { 535 case CREATE: { 536 Boolean hasData = params.get(DataParam.NAME, DataParam.class); 537 if (!hasData) { 538 response = Response.temporaryRedirect( 539 createUploadRedirectionURL(uriInfo, 540 HttpFSFileSystem.Operation.CREATE)).build(); 541 } else { 542 Short permission = params.get(PermissionParam.NAME, 543 PermissionParam.class); 544 Boolean override = params.get(OverwriteParam.NAME, 545 OverwriteParam.class); 546 Short replication = params.get(ReplicationParam.NAME, 547 ReplicationParam.class); 548 Long blockSize = params.get(BlockSizeParam.NAME, 549 BlockSizeParam.class); 550 FSOperations.FSCreate command = 551 new FSOperations.FSCreate(is, path, permission, override, 552 replication, blockSize); 553 fsExecute(user, command); 554 AUDIT_LOG.info( 555 "[{}] permission [{}] override [{}] replication [{}] blockSize [{}]", 556 new Object[]{path, permission, override, replication, blockSize}); 557 response = Response.status(Response.Status.CREATED).build(); 558 } 559 break; 560 } 561 case SETXATTR: { 562 String xattrName = params.get(XAttrNameParam.NAME, 563 XAttrNameParam.class); 564 String xattrValue = params.get(XAttrValueParam.NAME, 565 XAttrValueParam.class); 566 EnumSet<XAttrSetFlag> flag = params.get(XAttrSetFlagParam.NAME, 567 XAttrSetFlagParam.class); 568 569 FSOperations.FSSetXAttr command = new FSOperations.FSSetXAttr( 570 path, xattrName, xattrValue, flag); 571 fsExecute(user, command); 572 AUDIT_LOG.info("[{}] to xAttr [{}]", path, xattrName); 573 response = Response.ok().build(); 574 break; 575 } 576 case REMOVEXATTR: { 577 String xattrName = params.get(XAttrNameParam.NAME, XAttrNameParam.class); 578 FSOperations.FSRemoveXAttr command = new FSOperations.FSRemoveXAttr( 579 path, xattrName); 580 fsExecute(user, command); 581 AUDIT_LOG.info("[{}] removed xAttr [{}]", path, xattrName); 582 response = Response.ok().build(); 583 break; 584 } 585 case MKDIRS: { 586 Short permission = params.get(PermissionParam.NAME, 587 PermissionParam.class); 588 FSOperations.FSMkdirs command = 589 new FSOperations.FSMkdirs(path, permission); 590 JSONObject json = fsExecute(user, command); 591 AUDIT_LOG.info("[{}] permission [{}]", path, permission); 592 response = Response.ok(json).type(MediaType.APPLICATION_JSON).build(); 593 break; 594 } 595 case RENAME: { 596 String toPath = params.get(DestinationParam.NAME, DestinationParam.class); 597 FSOperations.FSRename command = 598 new FSOperations.FSRename(path, toPath); 599 JSONObject json = fsExecute(user, command); 600 AUDIT_LOG.info("[{}] to [{}]", path, toPath); 601 response = Response.ok(json).type(MediaType.APPLICATION_JSON).build(); 602 break; 603 } 604 case SETOWNER: { 605 String owner = params.get(OwnerParam.NAME, OwnerParam.class); 606 String group = params.get(GroupParam.NAME, GroupParam.class); 607 FSOperations.FSSetOwner command = 608 new FSOperations.FSSetOwner(path, owner, group); 609 fsExecute(user, command); 610 AUDIT_LOG.info("[{}] to (O/G)[{}]", path, owner + ":" + group); 611 response = Response.ok().build(); 612 break; 613 } 614 case SETPERMISSION: { 615 Short permission = params.get(PermissionParam.NAME, 616 PermissionParam.class); 617 FSOperations.FSSetPermission command = 618 new FSOperations.FSSetPermission(path, permission); 619 fsExecute(user, command); 620 AUDIT_LOG.info("[{}] to [{}]", path, permission); 621 response = Response.ok().build(); 622 break; 623 } 624 case SETREPLICATION: { 625 Short replication = params.get(ReplicationParam.NAME, 626 ReplicationParam.class); 627 FSOperations.FSSetReplication command = 628 new FSOperations.FSSetReplication(path, replication); 629 JSONObject json = fsExecute(user, command); 630 AUDIT_LOG.info("[{}] to [{}]", path, replication); 631 response = Response.ok(json).build(); 632 break; 633 } 634 case SETTIMES: { 635 Long modifiedTime = params.get(ModifiedTimeParam.NAME, 636 ModifiedTimeParam.class); 637 Long accessTime = params.get(AccessTimeParam.NAME, 638 AccessTimeParam.class); 639 FSOperations.FSSetTimes command = 640 new FSOperations.FSSetTimes(path, modifiedTime, accessTime); 641 fsExecute(user, command); 642 AUDIT_LOG.info("[{}] to (M/A)[{}]", path, 643 modifiedTime + ":" + accessTime); 644 response = Response.ok().build(); 645 break; 646 } 647 case SETACL: { 648 String aclSpec = params.get(AclPermissionParam.NAME, 649 AclPermissionParam.class); 650 FSOperations.FSSetAcl command = 651 new FSOperations.FSSetAcl(path, aclSpec); 652 fsExecute(user, command); 653 AUDIT_LOG.info("[{}] to acl [{}]", path, aclSpec); 654 response = Response.ok().build(); 655 break; 656 } 657 case REMOVEACL: { 658 FSOperations.FSRemoveAcl command = 659 new FSOperations.FSRemoveAcl(path); 660 fsExecute(user, command); 661 AUDIT_LOG.info("[{}] removed acl", path); 662 response = Response.ok().build(); 663 break; 664 } 665 case MODIFYACLENTRIES: { 666 String aclSpec = params.get(AclPermissionParam.NAME, 667 AclPermissionParam.class); 668 FSOperations.FSModifyAclEntries command = 669 new FSOperations.FSModifyAclEntries(path, aclSpec); 670 fsExecute(user, command); 671 AUDIT_LOG.info("[{}] modify acl entry with [{}]", path, aclSpec); 672 response = Response.ok().build(); 673 break; 674 } 675 case REMOVEACLENTRIES: { 676 String aclSpec = params.get(AclPermissionParam.NAME, 677 AclPermissionParam.class); 678 FSOperations.FSRemoveAclEntries command = 679 new FSOperations.FSRemoveAclEntries(path, aclSpec); 680 fsExecute(user, command); 681 AUDIT_LOG.info("[{}] remove acl entry [{}]", path, aclSpec); 682 response = Response.ok().build(); 683 break; 684 } 685 case REMOVEDEFAULTACL: { 686 FSOperations.FSRemoveDefaultAcl command = 687 new FSOperations.FSRemoveDefaultAcl(path); 688 fsExecute(user, command); 689 AUDIT_LOG.info("[{}] remove default acl", path); 690 response = Response.ok().build(); 691 break; 692 } 693 case SETSTORAGEPOLICY: { 694 String policyName = params.get(PolicyNameParam.NAME, 695 PolicyNameParam.class); 696 FSOperations.FSSetStoragePolicy command = 697 new FSOperations.FSSetStoragePolicy(path, policyName); 698 fsExecute(user, command); 699 AUDIT_LOG.info("[{}] to policy [{}]", path, policyName); 700 response = Response.ok().build(); 701 break; 702 } 703 default: { 704 throw new IOException( 705 MessageFormat.format("Invalid HTTP PUT operation [{0}]", 706 op.value())); 707 } 708 } 709 return response; 710 } 711 712}