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

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

The newest version!
/*! ******************************************************************************
 *
 * Pentaho Data Integration
 *
 * Copyright (C) 2002-2017 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 org.owasp.encoder.Encode;

import java.io.IOException;
import java.io.PrintStream;
import java.util.Iterator;
import java.util.List;

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


public class ListServerSocketServlet extends BaseHttpServlet implements CartePluginInterface {
  private static final long serialVersionUID = 3634806745372015720L;

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

  public static final String PARAM_HOSTNAME = "host";
  public static final String PARAM_ONLY_OPEN = "onlyOpen";

  public ListServerSocketServlet() {
  }

  public ListServerSocketServlet( TransformationMap transformationMap ) {
    super( transformationMap );
  }

  /**

/kettle/listSocket

GET

Gets list of ports for specified host. Method is used for listing all or just open ports for specified host. Response contains port number, which transformation it is (was) used for, current status of the port and last date time used.

Example Request:

    GET /kettle/listSocket/?host=127.0.0.1
    

Parameters

name description type
host Host to get ports for. query
onlyOpen Boolean flag that indicates whether all or only open ports should be returned. Set it to Y to get the list of only currently open ports. boolean, optional

Response Body

text: HTML
media types: text/html

Response is HTML document listing the ports requested.

Example Response:

  
  List of server sockets on server '127.0.0.1'
  
  

Ports for host '127.0.0.1'

Found 5 ports for host '127.0.0.1'

8088 : Transformation=dummy-trans, crt/Dummy (do nothing) 2.0 --> sll/Dummy (do nothing).0 id=b20bcd03-9682-4327-8c42-b129faabbfe1, allocated=false time=Mon Nov 17 09:31:15 BRT 2014
8089 : Transformation=dummy-trans, crt/Dummy (do nothing) 2.0 --> sll/Dummy (do nothing).1 id=b20bcd03-9682-4327-8c42-b129faabbfe1, allocated=false time=Mon Nov 17 09:31:15 BRT 2014
8090 : Transformation=dummy-trans, crt/Dummy (do nothing) 2.0 --> sll/Dummy (do nothing).2 id=b20bcd03-9682-4327-8c42-b129faabbfe1, allocated=false time=Mon Nov 17 09:31:15 BRT 2014
8091 : Transformation=dummy-trans, crt/Dummy (do nothing) 2.0 --> sll/Dummy (do nothing).3 id=b20bcd03-9682-4327-8c42-b129faabbfe1, allocated=false time=Mon Nov 17 09:31:15 BRT 2014
8092 : Transformation=dummy-trans, crt/Dummy (do nothing) 2.0 --> sll/Dummy (do nothing).4 id=b20bcd03-9682-4327-8c42-b129faabbfe1, allocated=false time=Mon Nov 17 09:31:15 BRT 2014

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( "List of ports for a server requested" ); } response.setStatus( HttpServletResponse.SC_OK ); String hostname = request.getParameter( PARAM_HOSTNAME ); boolean onlyOpen = "Y".equalsIgnoreCase( request.getParameter( PARAM_ONLY_OPEN ) ); response.setContentType( "text/html" ); PrintStream out = new PrintStream( response.getOutputStream() ); out.println( "" ); out.println( "List of server sockets on server " + Encode.forHtml( "\'" + hostname + "\'" ) + "" ); out.println( "" ); out.println( "

Ports for host " + Encode.forHtml( "\'" + hostname + "\'" ) + "

" ); List allocations = getTransformationMap().getHostServerSocketPorts( hostname ); if ( allocations == null ) { out.println( "No port allocations found for host " + Encode.forHtml( "\'" + hostname + "\'" ) ); return; } out.println( "Found " + allocations.size() + " ports for host " + Encode.forHtml( "\'" + hostname + "\'" ) + "

" ); Iterator iterator = allocations.iterator(); while ( iterator.hasNext() ) { SocketPortAllocation allocation = iterator.next(); if ( !onlyOpen || ( onlyOpen && allocation.isAllocated() ) ) { out.println( allocation.getPort() + " : Transformation=" + allocation.getTransformationName() + ", " + allocation.getSourceSlaveName() + "/" + allocation.getSourceStepName() + "." + allocation.getSourceStepCopy() ); out.println( " --> " + allocation.getTargetSlaveName() + "/" + allocation.getTargetStepName() + "." + allocation.getTargetStepCopy() ); out.println( " id=" + allocation.getClusterRunId() + ", allocated=" + allocation.isAllocated() ); out.println( " time=" + allocation.getLastRequested() ); out.println( "
" ); } } out.println( "

" ); out.println( "" ); out.println( "" ); } public String toString() { return "Server socket port information request"; } public String getService() { return CONTEXT_PATH + " (" + toString() + ")"; } public String getContextPath() { return CONTEXT_PATH; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy