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 if (resourceName.equals(RestConstants.ADMIN_STATUS_RESOURCE)) { 093 boolean safeMode = Boolean.parseBoolean(request.getParameter(modeTag)); 094 //Services.get().setSafeMode(safeMode); 095 SYSTEM_MODE sysMode = safeMode == true ? SYSTEM_MODE.NOWEBSERVICE : SYSTEM_MODE.NORMAL; 096 System.out.println(modeTag + " DDDD " + sysMode); 097 Services.get().setSystemMode(sysMode); 098 response.setStatus(HttpServletResponse.SC_OK); 099 } 100 else { 101 throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, 102 ErrorCode.E0301, resourceName); 103 } 104 } 105 106 /* 107 * (non-Javadoc) 108 * 109 * @see 110 * org.apache.oozie.servlet.BaseAdminServlet#getQueueDump(org.json.simple 111 * .JSONObject) 112 */ 113 @Override 114 protected void getQueueDump(JSONObject json) throws XServletException { 115 throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0301, "cannot get queue dump"); 116 } 117 118 @Override 119 protected JsonBean getJMSConnectionInfo(HttpServletRequest request, HttpServletResponse response) throws XServletException, 120 IOException { 121 throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0302, "Not supported in v0"); 122 } 123 124 @Override 125 protected Map<String, String> getOozieURLs() throws XServletException { 126 throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0302, "Not supported in v0"); 127 } 128 129 @Override 130 protected void sendMetricsResponse(HttpServletResponse response) throws IOException, XServletException { 131 throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0302, "Not supported in v0"); 132 } 133}