001    /*
002     * Copyright (c) 2007-2014 Concurrent, Inc. All Rights Reserved.
003     *
004     * Project and contact information: http://www.cascading.org/
005     *
006     * This file is part of the Cascading project.
007     *
008     * Licensed under the Apache License, Version 2.0 (the "License");
009     * you may not use this file except in compliance with the License.
010     * You may obtain a copy of the License at
011     *
012     *     http://www.apache.org/licenses/LICENSE-2.0
013     *
014     * Unless required by applicable law or agreed to in writing, software
015     * distributed under the License is distributed on an "AS IS" BASIS,
016     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017     * See the License for the specific language governing permissions and
018     * limitations under the License.
019     */
020    
021    package cascading.flow.planner;
022    
023    import cascading.flow.FlowElement;
024    import cascading.flow.FlowException;
025    import cascading.pipe.Pipe;
026    import cascading.util.Util;
027    import org.jgrapht.graph.SimpleDirectedGraph;
028    
029    /**
030     * Class PlannerException is thrown when a job planner fails.
031     * <p/>
032     * For debugging purposes, the PlannerException holds a copy of the internal job representation which can be
033     * written out to disk and visualized with tools that support the
034     * <a href="http://en.wikipedia.org/wiki/DOT_language">DOT file format</a> using the {@link #writeDOT(String)}
035     * method.
036     */
037    public class PlannerException extends FlowException
038      {
039      /** Field pipeGraph */
040      ElementGraph elementGraph;
041    
042      /** Constructor PlannerException creates a new PlannerException instance. */
043      public PlannerException()
044        {
045        }
046    
047      /**
048       * Constructor PlannerException creates a new PlannerException instance.
049       *
050       * @param pipe    of type Pipe
051       * @param message of type String
052       */
053      public PlannerException( Pipe pipe, String message )
054        {
055        super( Util.formatTrace( pipe, message ) );
056        }
057    
058      /**
059       * Constructor PlannerException creates a new PlannerException instance.
060       *
061       * @param pipe      of type Pipe
062       * @param message   of type String
063       * @param throwable of type Throwable
064       */
065      public PlannerException( Pipe pipe, String message, Throwable throwable )
066        {
067        super( Util.formatTrace( pipe, message ), throwable );
068        }
069    
070      /**
071       * Constructor PlannerException creates a new PlannerException instance.
072       *
073       * @param pipe         of type Pipe
074       * @param message      of type String
075       * @param throwable    of type Throwable
076       * @param elementGraph of type ElementGraph
077       */
078      public PlannerException( Pipe pipe, String message, Throwable throwable, ElementGraph elementGraph )
079        {
080        super( Util.formatTrace( pipe, message ), throwable );
081        this.elementGraph = elementGraph;
082        }
083    
084      /**
085       * Constructor PlannerException creates a new PlannerException instance.
086       *
087       * @param string of type String
088       */
089      public PlannerException( String string )
090        {
091        super( string );
092        }
093    
094      /**
095       * Constructor PlannerException creates a new PlannerException instance.
096       *
097       * @param string    of type String
098       * @param throwable of type Throwable
099       */
100      public PlannerException( String string, Throwable throwable )
101        {
102        super( string, throwable );
103        }
104    
105      /**
106       * Constructor PlannerException creates a new PlannerException instance.
107       *
108       * @param throwable of type Throwable
109       */
110      public PlannerException( Throwable throwable )
111        {
112        super( throwable );
113        }
114    
115      /**
116       * Constructor PlannerException creates a new PlannerException instance.
117       *
118       * @param string       of type String
119       * @param throwable    of type Throwable
120       * @param elementGraph of type SimpleDirectedGraph<FlowElement, Scope>
121       */
122      public PlannerException( String string, Throwable throwable, ElementGraph elementGraph )
123        {
124        super( string, throwable );
125        this.elementGraph = elementGraph;
126        }
127    
128      /**
129       * Method getPipeGraph returns the pipeGraph of this PlannerException object.
130       *
131       * @return the pipeGraph (type SimpleDirectedGraph<FlowElement, Scope>) of this PlannerException object.
132       */
133      SimpleDirectedGraph<FlowElement, Scope> getElementGraph()
134        {
135        return elementGraph;
136        }
137    
138      /**
139       * Method writeDOT writes the failed Flow instance to the given filename as a DOT file for import into a graphics package.
140       *
141       * @param filename of type String
142       */
143      public void writeDOT( String filename )
144        {
145        if( elementGraph == null )
146          return;
147    
148        elementGraph.writeDOT( filename );
149        }
150      }