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 package org.apache.hadoop.hdfs.web.resources;
019
020 import java.net.HttpURLConnection;
021
022 /** Http POST operation parameter. */
023 public class PutOpParam extends HttpOpParam<PutOpParam.Op> {
024 /** Put operations. */
025 public static enum Op implements HttpOpParam.Op {
026 CREATE(true, HttpURLConnection.HTTP_CREATED),
027
028 MKDIRS(false, HttpURLConnection.HTTP_OK),
029 CREATESYMLINK(false, HttpURLConnection.HTTP_OK),
030 RENAME(false, HttpURLConnection.HTTP_OK),
031 SETREPLICATION(false, HttpURLConnection.HTTP_OK),
032
033 SETOWNER(false, HttpURLConnection.HTTP_OK),
034 SETPERMISSION(false, HttpURLConnection.HTTP_OK),
035 SETTIMES(false, HttpURLConnection.HTTP_OK),
036
037 RENEWDELEGATIONTOKEN(false, HttpURLConnection.HTTP_OK, true),
038 CANCELDELEGATIONTOKEN(false, HttpURLConnection.HTTP_OK, true),
039
040 MODIFYACLENTRIES(false, HttpURLConnection.HTTP_OK),
041 REMOVEACLENTRIES(false, HttpURLConnection.HTTP_OK),
042 REMOVEDEFAULTACL(false, HttpURLConnection.HTTP_OK),
043 REMOVEACL(false, HttpURLConnection.HTTP_OK),
044 SETACL(false, HttpURLConnection.HTTP_OK),
045
046 NULL(false, HttpURLConnection.HTTP_NOT_IMPLEMENTED);
047
048 final boolean doOutputAndRedirect;
049 final int expectedHttpResponseCode;
050 final boolean requireAuth;
051
052 Op(final boolean doOutputAndRedirect, final int expectedHttpResponseCode) {
053 this(doOutputAndRedirect, expectedHttpResponseCode, false);
054 }
055
056 Op(final boolean doOutputAndRedirect, final int expectedHttpResponseCode,
057 final boolean requireAuth) {
058 this.doOutputAndRedirect = doOutputAndRedirect;
059 this.expectedHttpResponseCode = expectedHttpResponseCode;
060 this.requireAuth = requireAuth;
061 }
062
063 @Override
064 public HttpOpParam.Type getType() {
065 return HttpOpParam.Type.PUT;
066 }
067
068 @Override
069 public boolean getRequireAuth() {
070 return requireAuth;
071 }
072
073 @Override
074 public boolean getDoOutput() {
075 return doOutputAndRedirect;
076 }
077
078 @Override
079 public boolean getRedirect() {
080 return doOutputAndRedirect;
081 }
082
083 @Override
084 public int getExpectedHttpResponseCode() {
085 return expectedHttpResponseCode;
086 }
087
088 @Override
089 public String toQueryString() {
090 return NAME + "=" + this;
091 }
092 }
093
094 private static final Domain<Op> DOMAIN = new Domain<Op>(NAME, Op.class);
095
096 /**
097 * Constructor.
098 * @param str a string representation of the parameter value.
099 */
100 public PutOpParam(final String str) {
101 super(DOMAIN, DOMAIN.parse(str));
102 }
103
104 @Override
105 public String getName() {
106 return NAME;
107 }
108 }