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