org.pentaho.di.www.RemoveJobServlet Maven / Gradle / Ivy
Show all versions of kettle-engine Show documentation
/*! ******************************************************************************
*
* Pentaho Data Integration
*
* Copyright (C) 2002-2018 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 javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.google.common.annotations.VisibleForTesting;
import org.owasp.encoder.Encode;
import org.pentaho.di.core.Const;
import org.pentaho.di.core.util.Utils;
import org.pentaho.di.core.logging.KettleLogStore;
import org.pentaho.di.core.xml.XMLHandler;
import org.pentaho.di.i18n.BaseMessages;
import org.pentaho.di.job.Job;
import org.pentaho.di.www.cache.CarteStatusCache;
public class RemoveJobServlet extends BaseHttpServlet implements CartePluginInterface {
private static Class> PKG = RemoveJobServlet.class; // for i18n purposes, needed by Translator2!!
private static final long serialVersionUID = -2051906998698124039L;
public static final String CONTEXT_PATH = "/kettle/removeJob";
@VisibleForTesting
private CarteStatusCache cache = CarteStatusCache.getInstance();
public RemoveJobServlet() {
}
public RemoveJobServlet( JobMap jobMap ) {
super( jobMap );
}
/**
/kettle/removeJob
GET
Remove specified job from Carte server.
Example Request:
GET /kettle/removeJob/?name=dummy_job&xml=Y
Parameters
name
description
type
name
Name of the job to be removed.
query
xml
Boolean flag which sets the output format required. Use Y
to receive XML response.
boolean, optional
id
Carte job ID of the job to be removed. This parameter is optional when xml=Y is used.
query, optional
Response Body
text:
HTML
media types:
text/xml, text/html
Response XML or HTML containing operation result. When using xml=Y result
field indicates whether
operation was successful (OK
) or not (ERROR
).
Example Response:
OK
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, "RemoveJobServlet.Log.RemoveJobRequested" ) );
}
String jobName = request.getParameter( "name" );
String id = request.getParameter( "id" );
boolean useXML = "Y".equalsIgnoreCase( request.getParameter( "xml" ) );
response.setStatus( HttpServletResponse.SC_OK );
if ( useXML ) {
response.setContentType( "text/xml" );
response.setCharacterEncoding( Const.XML_ENCODING );
} else {
response.setContentType( "text/html;charset=UTF-8" );
}
PrintWriter out = response.getWriter();
// ID is optional...
//
Job job;
CarteObjectEntry entry;
if ( Utils.isEmpty( id ) ) {
// get the first transformation that matches...
//
entry = getJobMap().getFirstCarteObjectEntry( jobName );
if ( entry == null ) {
job = null;
} else {
id = entry.getId();
job = getJobMap().getJob( entry );
}
} else {
// Take the ID into account!
//
entry = new CarteObjectEntry( jobName, id );
job = getJobMap().getJob( entry );
}
if ( job != null ) {
cache.remove( job.getLogChannelId() );
KettleLogStore.discardLines( job.getLogChannelId(), true );
getJobMap().removeJob( entry );
if ( useXML ) {
response.setContentType( "text/xml" );
response.setCharacterEncoding( Const.XML_ENCODING );
out.print( XMLHandler.getXMLHeader( Const.XML_ENCODING ) );
out.print( WebResult.OK.getXML() );
} else {
response.setContentType( "text/html;charset=UTF-8" );
out.println( "" );
out.println( "" );
out.println( "" + BaseMessages.getString( PKG, "RemoveJobServlet.JobRemoved" ) + " " );
out.println( "" );
out.println( "" );
out.println( "" );
out.println( ""
+ Encode.forHtml( BaseMessages
.getString( PKG, "RemoveJobServlet.TheJobWasRemoved", jobName, id ) ) + "
" );
out.print( ""
+ BaseMessages.getString( PKG, "TransStatusServlet.BackToStatusPage" ) + "
" );
out.println( "" );
out.println( "" );
out.println( "" );
}
} else {
if ( useXML ) {
out.println( new WebResult( WebResult.STRING_ERROR, BaseMessages.getString(
PKG, "RemoveJobServlet.Log.CoundNotFindSpecJob", jobName ) ) );
} else {
out.println( "
"
+ Encode.forHtml( BaseMessages.getString(
PKG, "RemoveJobServlet.JobRemoved.Log.CoundNotFindJob", jobName, id ) ) + "
" );
out.println( ""
+ BaseMessages.getString( PKG, "TransStatusServlet.BackToStatusPage" ) + "" );
response.setStatus( HttpServletResponse.SC_BAD_REQUEST );
}
}
}
public String toString() {
return "Remove job servlet";
}
public String getService() {
return CONTEXT_PATH + " (" + toString() + ")";
}
public String getContextPath() {
return CONTEXT_PATH;
}
}