Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.pentaho.di.www.GetStatusServlet Maven / Gradle / Ivy
/*! ******************************************************************************
*
* 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( "" );
// 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" + htmlClass + ">" );
out.println( "
" );
out.println( "" );
out.println( "" );
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( "" + name + " " );
out.print( "" + id + " " );
out.print( "" + status + " " );
String dateStr = XMLHandler.date2string( trans.getLogDate() );
out.print( ""
+ ( trans.getLogDate() == null ? "-" : dateStr.substring( 0, dateStr.indexOf( ' ' ) ) ) + " " );
out.print( "" + dateStr.substring( dateStr.indexOf( ' ' ), dateStr.length() ) + " " );
out.print( " " );
}
out.print( "
" );
out.print( "
" ); // end div
out.println( "
" );
out.println( "<" + htmlClass + " class=\"workspaceHeading\" style=\"padding: 0px 0px 0px 0px;\">Jobs" + htmlClass + ">" );
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( "" + name + " " );
out.print( "" + id + " " );
out.print( "" + status + " " );
String dateStr = XMLHandler.date2string( job.getLogDate() );
out.print( ""
+ ( job.getLogDate() == null ? "-" : dateStr.substring( 0, dateStr.indexOf( ' ' ) ) ) + " " );
out.print( "" + dateStr.substring( dateStr.indexOf( ' ' ), dateStr.length() ) + " " );
out.print( " " );
}
out.print( "
" );
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" ) + "" + htmlClass + ">
" );
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( " "
+ BaseMessages.getString( PKG, "GetStatusServlet.Parameter.MaxLogLines" ) + " " + maxLines
+ " " );
// 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( " "
+ BaseMessages.getString( PKG, "GetStatusServlet.Parameter.MaxLogLinesAge" ) + " " + maxAge
+ " " );
// 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( " "
+ BaseMessages.getString( PKG, "GetStatusServlet.Parameter.MaxObjectsAge" ) + " " + maxObjAge
+ " " );
// 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( " "
+ BaseMessages.getString( PKG, "GetStatusServlet.Parameter.RepositoryName" ) + " "
+ repositoryName + " " );
out.print( "
" );
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( "