Search in sources :

Example 1 with DuplicateKeyException

use of org.pentaho.di.www.exception.DuplicateKeyException in project pentaho-kettle by pentaho.

the class GetJobStatusServletTest method doGetConflictingJobNamesUseHTMLTest.

@Test
public void doGetConflictingJobNamesUseHTMLTest() throws Exception {
    KettleLogStore.init();
    CarteStatusCache cacheMock = mock(CarteStatusCache.class);
    getJobStatusServlet.cache = cacheMock;
    HttpServletRequest mockHttpServletRequest = mock(HttpServletRequest.class);
    HttpServletResponse mockHttpServletResponse = mock(HttpServletResponse.class);
    StringWriter out = new StringWriter();
    PrintWriter printWriter = new PrintWriter(out);
    when(mockHttpServletRequest.getContextPath()).thenReturn(GetJobStatusServlet.CONTEXT_PATH);
    when(mockHttpServletRequest.getParameter("id")).thenReturn(null);
    when(mockHttpServletRequest.getParameter("name")).thenReturn("dummy_job");
    when(mockHttpServletResponse.getWriter()).thenReturn(printWriter);
    when(mockJobMap.getUniqueCarteObjectEntry(any())).thenThrow(new DuplicateKeyException());
    getJobStatusServlet.doGet(mockHttpServletRequest, mockHttpServletResponse);
    verify(mockHttpServletResponse).setStatus(HttpServletResponse.SC_OK);
    verify(mockHttpServletResponse).setStatus(HttpServletResponse.SC_CONFLICT);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) StringWriter(java.io.StringWriter) HttpServletResponse(javax.servlet.http.HttpServletResponse) CarteStatusCache(org.pentaho.di.www.cache.CarteStatusCache) DuplicateKeyException(org.pentaho.di.www.exception.DuplicateKeyException) PrintWriter(java.io.PrintWriter) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with DuplicateKeyException

use of org.pentaho.di.www.exception.DuplicateKeyException in project pentaho-kettle by pentaho.

the class GetJobStatusServletTest method doGetConflictingJobNamesUseXMLTest.

@Test
public void doGetConflictingJobNamesUseXMLTest() throws Exception {
    KettleLogStore.init();
    CarteStatusCache cacheMock = mock(CarteStatusCache.class);
    getJobStatusServlet.cache = cacheMock;
    HttpServletRequest mockHttpServletRequest = mock(HttpServletRequest.class);
    HttpServletResponse mockHttpServletResponse = mock(HttpServletResponse.class);
    StringWriter out = new StringWriter();
    PrintWriter printWriter = new PrintWriter(out);
    when(mockHttpServletRequest.getContextPath()).thenReturn(GetJobStatusServlet.CONTEXT_PATH);
    when(mockHttpServletRequest.getParameter("id")).thenReturn(null);
    when(mockHttpServletRequest.getParameter("name")).thenReturn("dummy_job");
    when(mockHttpServletRequest.getParameter("xml")).thenReturn("Y");
    when(mockHttpServletResponse.getWriter()).thenReturn(printWriter);
    when(mockJobMap.getUniqueCarteObjectEntry(any())).thenThrow(new DuplicateKeyException());
    getJobStatusServlet.doGet(mockHttpServletRequest, mockHttpServletResponse);
    verify(mockHttpServletResponse).setStatus(HttpServletResponse.SC_OK);
    verify(mockHttpServletResponse).setStatus(HttpServletResponse.SC_CONFLICT);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) StringWriter(java.io.StringWriter) HttpServletResponse(javax.servlet.http.HttpServletResponse) CarteStatusCache(org.pentaho.di.www.cache.CarteStatusCache) DuplicateKeyException(org.pentaho.di.www.exception.DuplicateKeyException) PrintWriter(java.io.PrintWriter) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with DuplicateKeyException

use of org.pentaho.di.www.exception.DuplicateKeyException in project pentaho-kettle by pentaho.

the class GetJobImageServlet method doGet.

/**
 *<div id="mindtouch">
 *    <h1>/kettle/jobImage</h1>
 *    <a name="GET"></a>
 *    <h2>GET</h2>
 *    <p>Generates and returns image of the specified job.
 *  Generates PNG image of the specified job currently present on Carte server. Job name and Carte job ID (optional)
 *  is used for specifying job to get information for. Response is binary of the PNG image.</p>
 *
 *    <p><b>Example Request:</b><br />
 *    <pre function="syntax.xml">
 *    GET /kettle/jobImage?name=dummy_job
 *    </pre>
 *
 *    </p>
 *    <h3>Parameters</h3>
 *    <table class="pentaho-table">
 *    <tbody>
 *    <tr>
 *      <th>name</th>
 *      <th>description</th>
 *      <th>type</th>
 *    </tr>
 *    <tr>
 *    <td>name</td>
 *    <td>Name of the job to be used for image generation.</td>
 *    <td>query</td>
 *    </tr>
 *    <tr>
 *    <td>id</td>
 *    <td>Carte id of the job to be used for image generation.</td>
 *    <td>query, optional</td>
 *    </tr>
 *    </tbody>
 *    </table>
 *
 *  <h3>Response Body</h3>
 *
 *  <table class="pentaho-table">
 *    <tbody>
 *      <tr>
 *        <td align="right">binary streak:</td>
 *        <td>image</td>
 *      </tr>
 *      <tr>
 *        <td align="right">media types:</td>
 *        <td>image/png</td>
 *      </tr>
 *    </tbody>
 *  </table>
 *    <p>A binary PNG image or empty response if no job is found.</p>
 *
 *    <h3>Status Codes</h3>
 *    <table class="pentaho-table">
 *  <tbody>
 *    <tr>
 *      <th>code</th>
 *      <th>description</th>
 *    </tr>
 *    <tr>
 *      <td>200</td>
 *      <td>Request was processed.</td>
 *    </tr>
 *    <tr>
 *      <td>500</td>
 *      <td>Internal server error occurs during request processing.</td>
 *    </tr>
 *  </tbody>
 *</table>
 *</div>
 */
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, "GetJobImageServlet.Log.JobImageRequested"));
    }
    String jobName = request.getParameter("name");
    String id = request.getParameter("id");
    boolean useXML = "Y".equalsIgnoreCase(request.getParameter("xml"));
    // ID is optional...
    // 
    Job job;
    CarteObjectEntry entry;
    if (Utils.isEmpty(id)) {
        try {
            entry = getJobMap().getUniqueCarteObjectEntry(jobName);
        } catch (DuplicateKeyException e) {
            buildDuplicateResponse(response, jobName, useXML);
            return;
        }
        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);
    }
    try {
        if (job != null) {
            buildOkResponse(response, job);
        } else {
            buildNotFoundResponse(response, jobName, id, useXML);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Job(org.pentaho.di.job.Job) DuplicateKeyException(org.pentaho.di.www.exception.DuplicateKeyException) DuplicateKeyException(org.pentaho.di.www.exception.DuplicateKeyException) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 4 with DuplicateKeyException

use of org.pentaho.di.www.exception.DuplicateKeyException in project pentaho-kettle by pentaho.

the class JobMap method getUniqueCarteObjectEntry.

public synchronized CarteObjectEntry getUniqueCarteObjectEntry(String jobName) throws DuplicateKeyException {
    CarteObjectEntry entry = null;
    boolean unique = true;
    for (CarteObjectEntry key : jobMap.keySet()) {
        if (unique && key.getName().equals(jobName)) {
            unique = false;
            entry = key;
        } else if (!unique && key.getName().equals(jobName)) {
            throw new DuplicateKeyException();
        }
    }
    return entry;
}
Also used : DuplicateKeyException(org.pentaho.di.www.exception.DuplicateKeyException)

Aggregations

DuplicateKeyException (org.pentaho.di.www.exception.DuplicateKeyException)4 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 Test (org.junit.Test)2 CarteStatusCache (org.pentaho.di.www.cache.CarteStatusCache)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1 Job (org.pentaho.di.job.Job)1