This project has retired. For details please refer to its
Attic page.
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.oozie.servlet;
019
020 import java.io.IOException;
021 import java.util.Arrays;
022 import java.util.Collections;
023
024 import javax.servlet.http.HttpServletRequest;
025 import javax.servlet.http.HttpServletResponse;
026
027 import org.apache.oozie.ErrorCode;
028 import org.apache.oozie.client.OozieClient.SYSTEM_MODE;
029 import org.apache.oozie.client.rest.JsonBean;
030 import org.apache.oozie.client.rest.JsonTags;
031 import org.apache.oozie.client.rest.RestConstants;
032 import org.apache.oozie.service.Services;
033 import org.json.simple.JSONObject;
034
035 @SuppressWarnings("unchecked")
036 public class V0AdminServlet extends BaseAdminServlet {
037 private static final long serialVersionUID = 1L;
038 private static final String INSTRUMENTATION_NAME = "v0admin";
039 private static final ResourceInfo RESOURCES_INFO[] = new ResourceInfo[6];
040
041 static {
042 RESOURCES_INFO[0] = new ResourceInfo(RestConstants.ADMIN_STATUS_RESOURCE, Arrays.asList("PUT", "GET"),
043 Arrays.asList(new ParameterInfo(RestConstants.ADMIN_SAFE_MODE_PARAM, Boolean.class, true,
044 Arrays.asList("PUT"))));
045 RESOURCES_INFO[1] = new ResourceInfo(RestConstants.ADMIN_OS_ENV_RESOURCE, Arrays.asList("GET"),
046 Collections.EMPTY_LIST);
047 RESOURCES_INFO[2] = new ResourceInfo(RestConstants.ADMIN_JAVA_SYS_PROPS_RESOURCE, Arrays.asList("GET"),
048 Collections.EMPTY_LIST);
049 RESOURCES_INFO[3] = new ResourceInfo(RestConstants.ADMIN_CONFIG_RESOURCE, Arrays.asList("GET"),
050 Collections.EMPTY_LIST);
051 RESOURCES_INFO[4] = new ResourceInfo(RestConstants.ADMIN_INSTRUMENTATION_RESOURCE, Arrays.asList("GET"),
052 Collections.EMPTY_LIST);
053 RESOURCES_INFO[5] = new ResourceInfo(RestConstants.ADMIN_BUILD_VERSION_RESOURCE, Arrays.asList("GET"),
054 Collections.EMPTY_LIST);
055 }
056
057 public V0AdminServlet() {
058 super(INSTRUMENTATION_NAME, RESOURCES_INFO);
059 modeTag = RestConstants.ADMIN_SAFE_MODE_PARAM;
060 }
061
062 /*
063 * (non-Javadoc)
064 *
065 * @see
066 * org.apache.oozie.servlet.BaseAdminServlet#populateOozieMode(org.json.
067 * simple.JSONObject)
068 */
069 @Override
070 protected void populateOozieMode(JSONObject json) {
071 if (Services.get().getSystemMode() != SYSTEM_MODE.NORMAL) {
072 json.put(JsonTags.OOZIE_SAFE_MODE, true);
073 }
074 else {
075 json.put(JsonTags.OOZIE_SAFE_MODE, false);
076 }
077 }
078
079 /*
080 * (non-Javadoc)
081 *
082 * @see
083 * org.apache.oozie.servlet.BaseAdminServlet#setOozieMode(javax.servlet.
084 * http.HttpServletRequest, javax.servlet.http.HttpServletResponse,
085 * java.lang.String)
086 */
087 @Override
088 protected void setOozieMode(HttpServletRequest request, HttpServletResponse response, String resourceName)
089 throws XServletException {
090 if (resourceName.equals(RestConstants.ADMIN_STATUS_RESOURCE)) {
091 boolean safeMode = Boolean.parseBoolean(request.getParameter(modeTag));
092 //Services.get().setSafeMode(safeMode);
093 SYSTEM_MODE sysMode = safeMode == true ? SYSTEM_MODE.NOWEBSERVICE : SYSTEM_MODE.NORMAL;
094 System.out.println(modeTag + " DDDD " + sysMode);
095 Services.get().setSystemMode(sysMode);
096 response.setStatus(HttpServletResponse.SC_OK);
097 }
098 else {
099 throw new XServletException(HttpServletResponse.SC_BAD_REQUEST,
100 ErrorCode.E0301, resourceName);
101 }
102 }
103
104 /*
105 * (non-Javadoc)
106 *
107 * @see
108 * org.apache.oozie.servlet.BaseAdminServlet#getQueueDump(org.json.simple
109 * .JSONObject)
110 */
111 @Override
112 protected void getQueueDump(JSONObject json) throws XServletException {
113 throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0301, "cannot get queue dump");
114 }
115
116 @Override
117 protected JsonBean getJMSConnectionInfo(HttpServletRequest request, HttpServletResponse response) throws XServletException,
118 IOException {
119 throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0302, "Not supported in v0");
120 }
121 }