webapps.admin.query.jsp Maven / Gradle / Ivy
<%
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="org.apache.tajo.master.TajoMaster" %>
<%@ page import="org.apache.tajo.master.QueryInProgress" %>
<%@ page import="org.apache.tajo.master.rm.Worker" %>
<%@ page import="org.apache.tajo.util.JSPUtil" %>
<%@ page import="org.apache.tajo.util.StringUtils" %>
<%@ page import="org.apache.tajo.webapp.StaticHttpServer" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.*" %>
<%@ page import="org.apache.tajo.util.history.HistoryReader" %>
<%@ page import="org.apache.tajo.master.QueryInfo" %>
<%@ page import="java.net.InetSocketAddress" %>
<%
TajoMaster master = (TajoMaster) StaticHttpServer.getInstance().getAttribute("tajo.info.server.object");
String[] masterName = master.getMasterName().split(":");
InetSocketAddress socketAddress = new InetSocketAddress(masterName[0], Integer.parseInt(masterName[1]));
String masterLabel = socketAddress.getAddress().getHostName()+ ":" + socketAddress.getPort();
List runningQueries =
new ArrayList(master.getContext().getQueryJobManager().getSubmittedQueries());
runningQueries.addAll(master.getContext().getQueryJobManager().getRunningQueries());
JSPUtil.sortQueryInProgress(runningQueries, true);
int currentPage = 1;
if (request.getParameter("page") != null && !request.getParameter("page").isEmpty()) {
currentPage = Integer.parseInt(request.getParameter("page"));
}
int pageSize = HistoryReader.DEFAULT_PAGE_SIZE;
if (request.getParameter("pageSize") != null && !request.getParameter("pageSize").isEmpty()) {
try {
pageSize = Integer.parseInt(request.getParameter("pageSize"));
} catch (NumberFormatException e) {
pageSize = HistoryReader.DEFAULT_PAGE_SIZE;
}
}
String keyword = request.getParameter("keyword");
HistoryReader historyReader = master.getContext().getHistoryReader();
List allFinishedQueries = historyReader.getQueries(keyword);
int numOfFinishedQueries = allFinishedQueries.size();
int totalPage = numOfFinishedQueries % pageSize == 0 ?
numOfFinishedQueries / pageSize : numOfFinishedQueries / pageSize + 1;
List finishedQueries = JSPUtil.getPageNavigationList(allFinishedQueries, currentPage, pageSize);
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Map workers = master.getContext().getResourceManager().getWorkers();
Map portMap = new HashMap();
Collection queryMasters = master.getContext().getResourceManager().getQueryMasters();
if (queryMasters == null || queryMasters.isEmpty()) {
queryMasters = master.getContext().getResourceManager().getWorkers().keySet();
}
for(int eachQueryMasterKey: queryMasters) {
Worker queryMaster = workers.get(eachQueryMasterKey);
if(queryMaster != null) {
portMap.put(queryMaster.getConnectionInfo().getHost(), queryMaster.getConnectionInfo().getHttpInfoPort());
}
}
%>
Tajo
<%@ include file="header.jsp"%>
Tajo Master: <%=masterLabel%> <%=JSPUtil.getMasterActiveLabel(master.getContext())%>
Running Queries
<%
if(runningQueries.isEmpty()) {
out.write("No running queries");
} else {
%>
QueryId Query Master Started Progress Time Status sql Kill Query
<%
for(QueryInProgress eachQuery: runningQueries) {
long time = System.currentTimeMillis() - eachQuery.getQueryInfo().getStartTime();
String detailView = "http://" + eachQuery.getQueryInfo().getQueryMasterHost() + ":" + portMap.get(eachQuery.getQueryInfo().getQueryMasterHost()) +
"/querydetail.jsp?queryId=" + eachQuery.getQueryId() + "&startTime=" + eachQuery.getQueryInfo().getStartTime();
%>
<%=eachQuery.getQueryId()%>
<%=eachQuery.getQueryInfo().getQueryMasterHost()%>
<%=df.format(eachQuery.getQueryInfo().getStartTime())%>
<%=(int)(eachQuery.getQueryInfo().getProgress() * 100.0f)%>%
<%=StringUtils.formatTime(time)%>
<%=eachQuery.getQueryInfo().getQueryState()%>
<%=eachQuery.getQueryInfo().getSql()%>
<%
}
%>
<%
}
%>
Finished Queries
<%
if(finishedQueries.isEmpty()) {
out.write("No finished queries");
} else {
%>
QueryId Query Master Started Finished Time Status sql
<%
for(QueryInfo eachQuery: finishedQueries) {
long runTime = eachQuery.getFinishTime() > 0 ?
eachQuery.getFinishTime() - eachQuery.getStartTime() : -1;
String detailView = "querydetail.jsp?queryId=" + eachQuery.getQueryIdStr() + "&startTime=" + eachQuery.getStartTime();
%>
<%=eachQuery.getQueryIdStr()%>
<%=eachQuery.getQueryMasterHost()%>
<%=df.format(eachQuery.getStartTime())%>
<%=eachQuery.getFinishTime() > 0 ? df.format(eachQuery.getFinishTime()) : "-"%>
<%=runTime == -1 ? "-" : StringUtils.formatTime(runTime) %>
<%=eachQuery.getQueryState()%>
<%=eachQuery.getSql()%>
<%
}
%>
<%=JSPUtil.getPageNavigation(currentPage, totalPage, "query.jsp?pageSize=" + pageSize)%>
<%
}
%>
© 2015 - 2025 Weber Informatics LLC | Privacy Policy