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