All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.pentaho.di.www.GetStatusServlet Maven / Gradle / Ivy

The newest version!
/*! ******************************************************************************
 *
 * Pentaho Data Integration
 *
 * Copyright (C) 2002-2019 by Hitachi Vantara : http://www.pentaho.com
 *
 *******************************************************************************
 *
 * Licensed 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.
 *
 ******************************************************************************/

package org.pentaho.di.www;

import java.io.IOException;
import java.io.PrintWriter;
import java.lang.management.OperatingSystemMXBean;
import java.lang.management.RuntimeMXBean;
import java.lang.management.ThreadMXBean;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.pentaho.di.core.Const;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.xml.XMLHandler;
import org.pentaho.di.i18n.BaseMessages;
import org.pentaho.di.job.Job;
import org.pentaho.di.trans.Trans;

public class GetStatusServlet extends BaseHttpServlet implements CartePluginInterface {
  private static Class PKG = GetStatusServlet.class; // for i18n purposes, needed by Translator2!!

  private static final long serialVersionUID = 3634806745372015720L;

  public static final String CONTEXT_PATH = "/kettle/status";

  public GetStatusServlet() {
  }

  public GetStatusServlet( TransformationMap transformationMap, JobMap jobMap ) {
    super( transformationMap, jobMap );
  }

  /**
   

/kettle/status

GET

Retrieve server status. The status contains information about the server itself (OS, memory, etc) and information about jobs and transformations present on the server.

Example Request:

   GET /kettle/status/?xml=Y
   

Parameters

name description type
xml Boolean flag which defines output format Y forces XML output to be generated. HTML is returned otherwise. boolean, optional

Response Body

element: (custom)
media types: text/xml, text/html

Response XML or HTML response containing details about the transformation specified. If an error occurs during method invocation result field of the response will contain ERROR status.

Example Response:

   
   
   Online
   229093440
   285736960
   4
   7534848300
   68818403
   45
   -1.0
   Windows 7
   6.1
   amd64
   
   
   Row generator test
   56c93d4e-96c1-4fae-92d9-d864b0779845
   Waiting
   
   N
   
   
   0
   0
   <![CDATA[]]>
   
   
   dummy-trans
   c56961b2-c848-49b8-abde-76c8015e29b0
   Stopped
   
   N
   
   
   0
   0
   <![CDATA[]]>
   
   
   
   
   dummy_job
   abd61143-8174-4f27-9037-6b22fbd3e229
   Stopped
   
   <![CDATA[]]>
   0
   0
   
   
   
   

Status Codes

code description
200 Request was processed.
500 Internal server error occurs during request processing.
*/ public void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException { if ( isJettyMode() && !request.getContextPath().startsWith( CONTEXT_PATH ) ) { return; } if ( log.isDebug() ) { logDebug( BaseMessages.getString( PKG, "GetStatusServlet.StatusRequested" ) ); } response.setStatus( HttpServletResponse.SC_OK ); String root = request.getRequestURI() == null ? StatusServletUtils.PENTAHO_ROOT : request.getRequestURI().substring( 0, request.getRequestURI().indexOf( CONTEXT_PATH ) ); String prefix = isJettyMode() ? StatusServletUtils.STATIC_PATH : root + StatusServletUtils.RESOURCES_PATH; boolean useXML = "Y".equalsIgnoreCase( request.getParameter( "xml" ) ); boolean useLightTheme = "Y".equalsIgnoreCase( request.getParameter( "useLightTheme" ) ); if ( useXML ) { response.setContentType( "text/xml" ); response.setCharacterEncoding( Const.XML_ENCODING ); } else { response.setContentType( "text/html;charset=UTF-8" ); } PrintWriter out = response.getWriter(); List transEntries = getTransformationMap().getTransformationObjects(); List jobEntries = getJobMap().getJobObjects(); if ( useXML ) { out.print( XMLHandler.getXMLHeader( Const.XML_ENCODING ) ); SlaveServerStatus serverStatus = new SlaveServerStatus(); serverStatus.setStatusDescription( "Online" ); getSystemInfo( serverStatus ); for ( CarteObjectEntry entry : transEntries ) { Trans trans = getTransformationMap().getTransformation( entry ); String status = trans.getStatus(); SlaveServerTransStatus sstatus = new SlaveServerTransStatus( entry.getName(), entry.getId(), status ); sstatus.setLogDate( trans.getLogDate() ); sstatus.setPaused( trans.isPaused() ); serverStatus.getTransStatusList().add( sstatus ); } for ( CarteObjectEntry entry : jobEntries ) { Job job = getJobMap().getJob( entry ); String status = job.getStatus(); SlaveServerJobStatus jobStatus = new SlaveServerJobStatus( entry.getName(), entry.getId(), status ); jobStatus.setLogDate( job.getLogDate() ); serverStatus.getJobStatusList().add( jobStatus ); } try { out.println( serverStatus.getXML() ); } catch ( KettleException e ) { throw new ServletException( "Unable to get the server status in XML format", e ); } } else { out.println( "" ); out.println( "" + BaseMessages.getString( PKG, "GetStatusServlet.KettleSlaveServerStatus" ) + "" ); out.println( "" ); int tableBorder = 1; if ( !useLightTheme ) { if ( isJettyMode() ) { out.println( "" ); } else { out.print( StatusServletUtils.getPentahoStyles( root ) ); out.println( "" ); } tableBorder = 0; } out.println( "" ); out.println( "" ); // Empty div for containing currently selected item out.println( "
" ); out.println( "" ); //initialize to none out.println( "
" ); out.println( "
" ); String htmlClass = useLightTheme ? "h1" : "div"; out.println( "<" + htmlClass + " class=\"workspaceHeading\" style=\"padding: 0px 0px 0px 10px;\">" + BaseMessages.getString( PKG, "GetStatusServlet.TopStatus" ) + "" ); out.println( "
" ); // Tooltips String run = BaseMessages.getString( PKG, "CarteStatusServlet.Run" ); String stop = BaseMessages.getString( PKG, "CarteStatusServlet.StopTrans" ); String view = BaseMessages.getString( PKG, "CarteStatusServlet.ViewTransDetails" ); String remove = BaseMessages.getString( PKG, "CarteStatusServlet.RemoveTrans" ); String runJ = BaseMessages.getString( PKG, "CarteStatusServlet.Run" ); String stopJ = BaseMessages.getString( PKG, "CarteStatusServlet.StopJob" ); String viewJ = BaseMessages.getString( PKG, "CarteStatusServlet.ViewJobDetails" ); String removeJ = BaseMessages.getString( PKG, "CarteStatusServlet.RemoveJob" ); try { out.println( "
" ); htmlClass = useLightTheme ? "h2" : "div"; out.println( "
" ); out.println( "<" + htmlClass + " class=\"workspaceHeading\" style=\"padding: 0px 0px 0px 0px;\">Transformations" ); out.println( "
" ); out.println( "" ); out.println( "" ); out.println( "" ); out.println( "" ); out.println( "" ); out.println( "" ); out.println( "" ); out.println( "
" ); out.println( "
Stop transformation
Stop input processing
" ); out.println( messageDialog() ); out.println( "" ); out.print( "" ); Comparator transComparator = new Comparator() { @Override public int compare( CarteObjectEntry o1, CarteObjectEntry o2 ) { Trans t1 = getTransformationMap().getTransformation( o1 ); Trans t2 = getTransformationMap().getTransformation( o2 ); Date d1 = t1.getLogDate(); Date d2 = t2.getLogDate(); // if both transformations have last log date, desc sort by log date if ( d1 != null && d2 != null ) { int logDateCompare = d2.compareTo( d1 ); if ( logDateCompare != 0 ) { return logDateCompare; } } return o1.compareTo( o2 ); } }; Collections.sort( transEntries, transComparator ); boolean evenRow = true; for ( int i = 0; i < transEntries.size(); i++ ) { String name = transEntries.get( i ).getName(); String id = transEntries.get( i ).getId(); Trans trans = getTransformationMap().getTransformation( transEntries.get( i ) ); String status = trans.getStatus(); String trClass = evenRow ? "cellTableEvenRow" : "cellTableOddRow"; // alternating row color String tdClass = evenRow ? "cellTableEvenRowCell" : "cellTableOddRowCell"; evenRow = !evenRow; // flip String firstColumn = i == 0 ? "cellTableFirstColumn" : ""; String lastColumn = i == transEntries.size() - 1 ? "cellTableLastColumn" : ""; out.print( "" ); out.print( "" ); out.print( "" ); out.print( "" ); String dateStr = XMLHandler.date2string( trans.getLogDate() ); out.print( "" ); out.print( "" ); out.print( "" ); } out.print( "
" + BaseMessages.getString( PKG, "GetStatusServlet.TransName" ) + " " + BaseMessages.getString( PKG, "GetStatusServlet.CarteId" ) + " " + BaseMessages.getString( PKG, "GetStatusServlet.Status" ) + " " + BaseMessages.getString( PKG, "GetStatusServlet.LastLogDate" ) + " " + BaseMessages.getString( PKG, "GetStatusServlet.LastLogTime" ) + "
" + name + "" + id + "" + status + "" + ( trans.getLogDate() == null ? "-" : dateStr.substring( 0, dateStr.indexOf( ' ' ) ) ) + "" + dateStr.substring( dateStr.indexOf( ' ' ), dateStr.length() ) + "
" ); out.print( "
" ); // end div out.println( "
" ); out.println( "<" + htmlClass + " class=\"workspaceHeading\" style=\"padding: 0px 0px 0px 0px;\">Jobs" ); out.println( "
" ); out.println( "" ); out.println( "" ); out.println( "" ); out.println( "" ); out.println( "" ); out.println( "" ); out.println( "" ); out.println( "
" ); out.println( "" ); out.print( "" ); Comparator jobComparator = new Comparator() { @Override public int compare( CarteObjectEntry o1, CarteObjectEntry o2 ) { Job t1 = getJobMap().getJob( o1 ); Job t2 = getJobMap().getJob( o2 ); Date d1 = t1.getLogDate(); Date d2 = t2.getLogDate(); // if both jobs have last log date, desc sort by log date if ( d1 != null && d2 != null ) { int logDateCompare = d2.compareTo( d1 ); if ( logDateCompare != 0 ) { return logDateCompare; } } return o1.compareTo( o2 ); } }; Collections.sort( jobEntries, jobComparator ); evenRow = true; for ( int i = 0; i < jobEntries.size(); i++ ) { String name = jobEntries.get( i ).getName(); String id = jobEntries.get( i ).getId(); Job job = getJobMap().getJob( jobEntries.get( i ) ); String status = job.getStatus(); String trClass = evenRow ? "cellTableEvenRow" : "cellTableOddRow"; // alternating row color String tdClass = evenRow ? "cellTableEvenRowCell" : "cellTableOddRowCell"; evenRow = !evenRow; // flip out.print( "" ); out.print( "" ); out.print( "" ); out.print( "" ); String dateStr = XMLHandler.date2string( job.getLogDate() ); out.print( "" ); out.print( "" ); out.print( "" ); } out.print( "
" + BaseMessages.getString( PKG, "GetStatusServlet.JobName" ) + " " + BaseMessages.getString( PKG, "GetStatusServlet.CarteId" ) + " " + BaseMessages.getString( PKG, "GetStatusServlet.Status" ) + " " + BaseMessages.getString( PKG, "GetStatusServlet.LastLogDate" ) + " " + BaseMessages.getString( PKG, "GetStatusServlet.LastLogTime" ) + "
" + name + "" + id + "" + status + "" + ( job.getLogDate() == null ? "-" : dateStr.substring( 0, dateStr.indexOf( ' ' ) ) ) + "" + dateStr.substring( dateStr.indexOf( ' ' ), dateStr.length() ) + "
" ); out.print( "
" ); // end div } catch ( Exception ex ) { out.println( "
" );
        ex.printStackTrace( out );
        out.println( "
" ); } out.println( "
" ); htmlClass = useLightTheme ? "h3" : "div"; out.println( "
<" + htmlClass + " class=\"workspaceHeading\">" + BaseMessages.getString( PKG, "GetStatusServlet.ConfigurationDetails.Title" ) + "
" ); out.println( "" ); // out.print( "" ); // The max number of log lines in the back-end // SlaveServerConfig serverConfig = getTransformationMap().getSlaveServerConfig(); if ( serverConfig != null ) { String maxLines = ""; if ( serverConfig.getMaxLogLines() == 0 ) { maxLines = BaseMessages.getString( PKG, "GetStatusServlet.NoLimit" ); } else { maxLines = serverConfig.getMaxLogLines() + BaseMessages.getString( PKG, "GetStatusServlet.Lines" ); } out.print( "" ); // The max age of log lines // String maxAge = ""; if ( serverConfig.getMaxLogTimeoutMinutes() == 0 ) { maxAge = BaseMessages.getString( PKG, "GetStatusServlet.NoLimit" ); } else { maxAge = serverConfig.getMaxLogTimeoutMinutes() + BaseMessages.getString( PKG, "GetStatusServlet.Minutes" ); } out.print( "" ); // The max age of stale objects // String maxObjAge = ""; if ( serverConfig.getObjectTimeoutMinutes() == 0 ) { maxObjAge = BaseMessages.getString( PKG, "GetStatusServlet.NoLimit" ); } else { maxObjAge = serverConfig.getObjectTimeoutMinutes() + BaseMessages.getString( PKG, "GetStatusServlet.Minutes" ); } out.print( "" ); // The name of the specified repository // String repositoryName; try { repositoryName = serverConfig.getRepository() != null ? serverConfig.getRepository().getName() : ""; } catch ( Exception e ) { logError( BaseMessages.getString( PKG, "GetStatusServlet.Parameter.RepositoryName.UnableToConnect", serverConfig.getRepositoryId() ), e ); repositoryName = BaseMessages.getString( PKG, "GetStatusServlet.Parameter.RepositoryName.UnableToConnect", serverConfig.getRepositoryId() ); } out.print( "" ); out.print( "
" // + BaseMessages.getString( PKG, "GetStatusServlet.Parameter.Title" ) + " " // + BaseMessages.getString( PKG, "GetStatusServlet.Value.Title" ) + "
" + BaseMessages.getString( PKG, "GetStatusServlet.Parameter.MaxLogLines" ) + " " + maxLines + "
" + BaseMessages.getString( PKG, "GetStatusServlet.Parameter.MaxLogLinesAge" ) + " " + maxAge + "
" + BaseMessages.getString( PKG, "GetStatusServlet.Parameter.MaxObjectsAge" ) + " " + maxObjAge + "
" + BaseMessages.getString( PKG, "GetStatusServlet.Parameter.RepositoryName" ) + " " + repositoryName + "
" ); String filename = serverConfig.getFilename(); if ( filename == null ) { filename = BaseMessages.getString( PKG, "GetStatusServlet.ConfigurationDetails.UsingDefaults" ); } out.println( "
" ); // end div out.print( "
" ); out .println( "" + BaseMessages.getString( PKG, "GetStatusServlet.ConfigurationDetails.Advice", filename ) + "" ); out.print( "
" ); out.print( "
" ); out.print( "
" ); } out.println( "" ); out.println( "" ); out.println( "" ); } } private static void getSystemInfo( SlaveServerStatus serverStatus ) { OperatingSystemMXBean operatingSystemMXBean = java.lang.management.ManagementFactory.getOperatingSystemMXBean(); ThreadMXBean threadMXBean = java.lang.management.ManagementFactory.getThreadMXBean(); RuntimeMXBean runtimeMXBean = java.lang.management.ManagementFactory.getRuntimeMXBean(); int cores = Runtime.getRuntime().availableProcessors(); long freeMemory = Runtime.getRuntime().freeMemory(); long totalMemory = Runtime.getRuntime().totalMemory(); String osArch = operatingSystemMXBean.getArch(); String osName = operatingSystemMXBean.getName(); String osVersion = operatingSystemMXBean.getVersion(); double loadAvg = operatingSystemMXBean.getSystemLoadAverage(); int threadCount = threadMXBean.getThreadCount(); long allThreadsCpuTime = 0L; long[] threadIds = threadMXBean.getAllThreadIds(); for ( int i = 0; i < threadIds.length; i++ ) { allThreadsCpuTime += threadMXBean.getThreadCpuTime( threadIds[i] ); } long uptime = runtimeMXBean.getUptime(); serverStatus.setCpuCores( cores ); serverStatus.setCpuProcessTime( allThreadsCpuTime ); serverStatus.setUptime( uptime ); serverStatus.setThreadCount( threadCount ); serverStatus.setLoadAvg( loadAvg ); serverStatus.setOsName( osName ); serverStatus.setOsVersion( osVersion ); serverStatus.setOsArchitecture( osArch ); serverStatus.setMemoryFree( freeMemory ); serverStatus.setMemoryTotal( totalMemory ); } public String toString() { return "Status Handler"; } public String getService() { return CONTEXT_PATH + " (" + toString() + ")"; } public String getContextPath() { return CONTEXT_PATH; } private String setupIconEnterLeaveJavascript( String id ) { return "onMouseEnter=\"if( !document.getElementById('" + id + "').classList.contains('toolbar-button-disabled') ) { document.getElementById('" + id + "').classList.add('toolbar-button-hovering') }\" onMouseLeave=\"document.getElementById('" + id + "').classList.remove('toolbar-button-hovering')\""; } private String messageDialog() { String retVal = "
\n"; retVal += "
\n"; retVal += "
\n"; retVal += "
\n"; retVal += "
\n\n
\n"; retVal += "
\n\n\n
\n"; retVal += "
\n"; return retVal; } private String setupAjaxCall( String uri, String title, String success, String failure ) { String retVal = ""; retVal += "var xhttp = new XMLHttpRequest();\n"; retVal += "xhttp.onreadystatechange = function() {\n"; retVal += " if ( this.readyState === 4 ) {\n"; retVal += " if ( this.status === 200 ) {\n"; retVal += " openMessageDialog( '" + title + "', " + success + ", true );\n"; retVal += " } else {\n"; retVal += " openMessageDialog( '" + BaseMessages.getString( PKG, "GetStatusServlet.UnableTo.Label" ) + " " + title + "', " + failure + ", true );\n"; retVal += " }\n"; retVal += " }\n"; retVal += "};\n"; retVal += "xhttp.open( \"GET\", " + uri + ", true );\n"; retVal += "xhttp.send();\n"; return retVal; } private String setupTransURI( String context ) { return "'" + context + "'" + " + '?name=' + document.getElementById( 'cellTableFirstCell_' + selectedTransRowIndex ).innerHTML" + " + '&id=' + document.getElementById( 'cellTableCell_' + selectedTransRowIndex ).innerHTML"; } private String setupJobURI( String context ) { return "'" + context + "'" + " + '?name=' + document.getElementById( 'j-cellTableFirstCell_' + selectedJobRowIndex ).innerHTML" + " + '&id=' + document.getElementById( 'j-cellTableCell_' + selectedJobRowIndex ).innerHTML"; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy