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.List; 025import java.util.Map; 026import java.util.Properties; 027 028import javax.servlet.http.HttpServletRequest; 029import javax.servlet.http.HttpServletResponse; 030 031import org.apache.hadoop.conf.Configuration; 032import org.apache.oozie.ErrorCode; 033import org.apache.oozie.client.OozieClient.SYSTEM_MODE; 034import org.apache.oozie.client.rest.JMSConnectionInfoBean; 035import org.apache.oozie.client.rest.JsonBean; 036import org.apache.oozie.client.rest.JsonTags; 037import org.apache.oozie.client.rest.RestConstants; 038import org.apache.oozie.jms.JMSConnectionInfo; 039import org.apache.oozie.jms.JMSJobEventListener; 040import org.apache.oozie.service.CallableQueueService; 041import org.apache.oozie.service.JMSTopicService; 042import org.apache.oozie.service.Services; 043import org.json.simple.JSONArray; 044import org.json.simple.JSONObject; 045 046public class V1AdminServlet extends BaseAdminServlet { 047 048 private static final long serialVersionUID = 1L; 049 private static final String INSTRUMENTATION_NAME = "v1admin"; 050 private static final ResourceInfo RESOURCES_INFO[] = new ResourceInfo[13]; 051 052 static { 053 RESOURCES_INFO[0] = new ResourceInfo(RestConstants.ADMIN_STATUS_RESOURCE, Arrays.asList("PUT", "GET"), 054 Arrays.asList(new ParameterInfo(RestConstants.ADMIN_SYSTEM_MODE_PARAM, String.class, true, 055 Arrays.asList("PUT")))); 056 RESOURCES_INFO[1] = new ResourceInfo(RestConstants.ADMIN_OS_ENV_RESOURCE, Arrays.asList("GET"), 057 Collections.EMPTY_LIST); 058 RESOURCES_INFO[2] = new ResourceInfo(RestConstants.ADMIN_JAVA_SYS_PROPS_RESOURCE, Arrays.asList("GET"), 059 Collections.EMPTY_LIST); 060 RESOURCES_INFO[3] = new ResourceInfo(RestConstants.ADMIN_CONFIG_RESOURCE, Arrays.asList("GET"), 061 Collections.EMPTY_LIST); 062 RESOURCES_INFO[4] = new ResourceInfo(RestConstants.ADMIN_INSTRUMENTATION_RESOURCE, Arrays.asList("GET"), 063 Collections.EMPTY_LIST); 064 RESOURCES_INFO[5] = new ResourceInfo(RestConstants.ADMIN_BUILD_VERSION_RESOURCE, Arrays.asList("GET"), 065 Collections.EMPTY_LIST); 066 RESOURCES_INFO[6] = new ResourceInfo(RestConstants.ADMIN_QUEUE_DUMP_RESOURCE, Arrays.asList("GET"), 067 Collections.EMPTY_LIST); 068 RESOURCES_INFO[7] = new ResourceInfo((RestConstants.ADMIN_TIME_ZONES_RESOURCE), Arrays.asList("GET"), 069 Collections.EMPTY_LIST); 070 RESOURCES_INFO[8] = new ResourceInfo((RestConstants.ADMIN_JMS_INFO), Arrays.asList("GET"), 071 Collections.EMPTY_LIST); 072 RESOURCES_INFO[9] = new ResourceInfo(RestConstants.ADMIN_AVAILABLE_OOZIE_SERVERS_RESOURCE, Arrays.asList("GET"), 073 Collections.EMPTY_LIST); 074 RESOURCES_INFO[10] = new ResourceInfo(RestConstants.ADMIN_UPDATE_SHARELIB, Arrays.asList("GET"), 075 Collections.EMPTY_LIST); 076 RESOURCES_INFO[11] = new ResourceInfo(RestConstants.ADMIN_LIST_SHARELIB, Arrays.asList("GET"), 077 Collections.EMPTY_LIST); 078 RESOURCES_INFO[12] = new ResourceInfo(RestConstants.ADMIN_METRICS_RESOURCE, Arrays.asList("GET"), 079 Collections.EMPTY_LIST); 080 081 } 082 083 protected V1AdminServlet(String name) { 084 super(name, RESOURCES_INFO); 085 modeTag = RestConstants.ADMIN_SYSTEM_MODE_PARAM; 086 } 087 088 public V1AdminServlet() { 089 this(INSTRUMENTATION_NAME); 090 } 091 092 /* 093 * (non-Javadoc) 094 * 095 * @see 096 * org.apache.oozie.servlet.BaseAdminServlet#populateOozieMode(org.json. 097 * simple.JSONObject) 098 */ 099 @SuppressWarnings("unchecked") 100 @Override 101 protected void populateOozieMode(JSONObject json) { 102 json.put(JsonTags.OOZIE_SYSTEM_MODE, Services.get().getSystemMode().toString()); 103 } 104 105 /* 106 * (non-Javadoc) 107 * 108 * @see 109 * org.apache.oozie.servlet.BaseAdminServlet#setOozieMode(javax.servlet. 110 * http.HttpServletRequest, javax.servlet.http.HttpServletResponse, 111 * java.lang.String) 112 */ 113 @Override 114 protected void setOozieMode(HttpServletRequest request, 115 HttpServletResponse response, String resourceName) 116 throws XServletException { 117 if (resourceName.equals(RestConstants.ADMIN_STATUS_RESOURCE)) { 118 SYSTEM_MODE sysMode = SYSTEM_MODE.valueOf(request.getParameter(modeTag)); 119 Services.get().setSystemMode(sysMode); 120 response.setStatus(HttpServletResponse.SC_OK); 121 } 122 else { 123 throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, 124 ErrorCode.E0301, resourceName); 125 } 126 } 127 128 /** 129 * Get a json array of queue dump and a json array of unique map dump 130 * 131 * @param JSONObject the result json object that contains a JSONArray for the callable dump 132 * 133 * @see 134 * org.apache.oozie.servlet.BaseAdminServlet#getQueueDump(org.json.simple 135 * .JSONObject) 136 */ 137 @SuppressWarnings("unchecked") 138 @Override 139 protected void getQueueDump(JSONObject json) throws XServletException { 140 List<String> queueDumpList = Services.get().get(CallableQueueService.class).getQueueDump(); 141 JSONArray queueDumpArray = new JSONArray(); 142 for (String str: queueDumpList) { 143 JSONObject jObject = new JSONObject(); 144 jObject.put(JsonTags.CALLABLE_DUMP, str); 145 queueDumpArray.add(jObject); 146 } 147 json.put(JsonTags.QUEUE_DUMP, queueDumpArray); 148 149 List<String> uniqueDumpList = Services.get().get(CallableQueueService.class).getUniqueDump(); 150 JSONArray uniqueDumpArray = new JSONArray(); 151 for (String str: uniqueDumpList) { 152 JSONObject jObject = new JSONObject(); 153 jObject.put(JsonTags.UNIQUE_ENTRY_DUMP, str); 154 uniqueDumpArray.add(jObject); 155 } 156 json.put(JsonTags.UNIQUE_MAP_DUMP, uniqueDumpArray); 157 } 158 159 @Override 160 protected JsonBean getJMSConnectionInfo(HttpServletRequest request, HttpServletResponse response) throws XServletException, 161 IOException { 162 throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0302, "Not supported in v1"); 163 } 164 165 @Override 166 protected Map<String, String> getOozieURLs() throws XServletException { 167 throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0302, "Not supported in v1"); 168 } 169 170 @Override 171 protected void sendMetricsResponse(HttpServletResponse response) throws IOException, XServletException { 172 throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0302, "Not supported in v1"); 173 } 174}