Search in sources :

Example 1 with Checkpoint

use of nl.nn.testtool.Checkpoint in project iaf by ibissource.

the class Debugger method rerun.

@Override
public String rerun(String correlationId, Report originalReport, SecurityContext securityContext, ReportRunner reportRunner) {
    String errorMessage = null;
    if (securityContext.isUserInRoles(rerunRoles)) {
        int i = 0;
        List<Checkpoint> checkpoints = originalReport.getCheckpoints();
        Checkpoint checkpoint = checkpoints.get(i);
        String checkpointName = checkpoint.getName();
        if (checkpointName.startsWith("Pipeline ")) {
            String pipelineName = checkpointName.substring("Pipeline ".length());
            Message inputMessage = new Message(checkpoint.getMessageWithResolvedVariables(reportRunner));
            IAdapter adapter = ibisManager.getRegisteredAdapter(pipelineName);
            if (adapter != null) {
                synchronized (inRerun) {
                    inRerun.add(correlationId);
                }
                try {
                    // are also closed and the generated report will not remain in progress
                    try (PipeLineSession pipeLineSession = new PipeLineSession()) {
                        while (checkpoints.size() > i + 1) {
                            i++;
                            checkpoint = checkpoints.get(i);
                            checkpointName = checkpoint.getName();
                            if (checkpointName.startsWith("SessionKey ")) {
                                String sessionKey = checkpointName.substring("SessionKey ".length());
                                if (!sessionKey.equals("messageId") && !sessionKey.equals("originalMessage")) {
                                    pipeLineSession.put(sessionKey, checkpoint.getMessage());
                                }
                            } else {
                                i = checkpoints.size();
                            }
                        }
                        adapter.processMessage(correlationId, inputMessage, pipeLineSession);
                    }
                } finally {
                    synchronized (inRerun) {
                        inRerun.remove(correlationId);
                    }
                }
            } else {
                errorMessage = "Adapter '" + pipelineName + "' not found";
            }
        } else {
            errorMessage = "First checkpoint isn't a pipeline";
        }
    } else {
        errorMessage = "Not allowed";
    }
    return errorMessage;
}
Also used : Checkpoint(nl.nn.testtool.Checkpoint) Message(nl.nn.adapterframework.stream.Message) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) IAdapter(nl.nn.adapterframework.core.IAdapter) Checkpoint(nl.nn.testtool.Checkpoint)

Example 2 with Checkpoint

use of nl.nn.testtool.Checkpoint in project iaf by ibissource.

the class Storage method delete.

@Override
public void delete(Report report) throws StorageException {
    String errorMessage = null;
    if ("Table EXCEPTIONLOG".equals(report.getName())) {
        List checkpoints = report.getCheckpoints();
        Checkpoint checkpoint = (Checkpoint) checkpoints.get(0);
        Message message = Message.asMessage(checkpoint.getMessage());
        IAdapter adapter = ibisManager.getRegisteredAdapter(DELETE_ADAPTER);
        if (adapter != null) {
            PipeLineSession pipeLineSession = new PipeLineSession();
            if (securityContext.getUserPrincipal() != null)
                pipeLineSession.put("principal", securityContext.getUserPrincipal().getName());
            PipeLineResult processResult = adapter.processMessage(TestTool.getCorrelationId(), message, pipeLineSession);
            if (!processResult.isSuccessful()) {
                errorMessage = "Delete failed (see logging for more details)";
            } else {
                try {
                    String result = processResult.getResult().asString();
                    if (!result.equalsIgnoreCase("<ok/>")) {
                        errorMessage = "Delete failed: " + result;
                    }
                } catch (IOException e) {
                    throw new StorageException("Delete failed", e);
                }
            }
        } else {
            errorMessage = "Adapter '" + DELETE_ADAPTER + "' not found";
        }
    } else {
        errorMessage = "Delete method is not implemented for '" + report.getName() + "'";
    }
    if (errorMessage != null) {
        throw new StorageException(errorMessage);
    }
}
Also used : Checkpoint(nl.nn.testtool.Checkpoint) Message(nl.nn.adapterframework.stream.Message) PipeLineResult(nl.nn.adapterframework.core.PipeLineResult) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException) IAdapter(nl.nn.adapterframework.core.IAdapter) StorageException(nl.nn.testtool.storage.StorageException)

Example 3 with Checkpoint

use of nl.nn.testtool.Checkpoint in project iaf by ibissource.

the class Storage method getReport.

@Override
public Report getReport(Integer storageId) throws StorageException {
    final Report report = new Report();
    report.setTestTool(testTool);
    report.setStorage(this);
    report.setStorageId(storageId);
    report.setName("Table " + table);
    report.setStubStrategy("Never");
    final List<Checkpoint> checkpoints = new ArrayList<Checkpoint>();
    report.setCheckpoints(checkpoints);
    StringBuilder query = new StringBuilder("select " + reportColumnNames.get(0));
    for (int i = 1; i < reportColumnNames.size(); i++) {
        query.append(", " + reportColumnNames.get(i));
    }
    query.append(" from " + table + " where LOGID = ?");
    try {
        jdbcTemplate.query(query.toString(), new Object[] { storageId }, new RowMapper() {

            public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
                for (int i = 0; i < reportColumnNames.size(); i++) {
                    String value = getValue(rs, i + 1);
                    Checkpoint checkpoint = new Checkpoint(report, Thread.currentThread().getName(), Storage.class.getName(), "Column " + reportColumnNames.get(i), Checkpoint.TYPE_INPUTPOINT, 0);
                    checkpoint.setMessage(value);
                    checkpoints.add(checkpoint);
                }
                return null;
            }
        });
    } catch (DataAccessException e) {
        throw new StorageException("Could not read report", e);
    }
    return report;
}
Also used : Report(nl.nn.testtool.Report) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Checkpoint(nl.nn.testtool.Checkpoint) Checkpoint(nl.nn.testtool.Checkpoint) ResultSet(java.sql.ResultSet) StorageException(nl.nn.testtool.storage.StorageException) DataAccessException(org.springframework.dao.DataAccessException) RowMapper(org.springframework.jdbc.core.RowMapper)

Example 4 with Checkpoint

use of nl.nn.testtool.Checkpoint in project iaf by ibissource.

the class Debugger method rerun.

@Override
public String rerun(String correlationId, Report originalReport, SecurityContext securityContext, ReportRunner reportRunner) {
    String errorMessage = null;
    if ("Table EXCEPTIONLOG".equals(originalReport.getName())) {
        List<Checkpoint> checkpoints = originalReport.getCheckpoints();
        Checkpoint checkpoint = checkpoints.get(0);
        String inputMessage = checkpoint.getMessageWithResolvedVariables(reportRunner);
        IAdapter adapter = ibisManager.getRegisteredAdapter(RESEND_ADAPTER);
        if (adapter != null) {
            PipeLineSession pipeLineSession = new PipeLineSession();
            synchronized (inRerun) {
                inRerun.add(correlationId);
            }
            try {
                if (securityContext.getUserPrincipal() != null)
                    pipeLineSession.put("principal", securityContext.getUserPrincipal().getName());
                PipeLineResult processResult = adapter.processMessage(correlationId, new Message(inputMessage), pipeLineSession);
                if (!(processResult.isSuccessful() && processResult.getResult().asString().equalsIgnoreCase("<ok/>"))) {
                    errorMessage = "Rerun failed. Result of adapter " + RESEND_ADAPTER + ": " + processResult.getResult().asString();
                }
            } catch (IOException e) {
                errorMessage = "Rerun failed. Exception in adapter " + RESEND_ADAPTER + ": (" + e.getClass().getName() + ") " + e.getMessage();
            } finally {
                synchronized (inRerun) {
                    inRerun.remove(correlationId);
                }
            }
        } else {
            errorMessage = "Adapter '" + RESEND_ADAPTER + "' not found";
        }
    } else {
        errorMessage = super.rerun(correlationId, originalReport, securityContext, reportRunner);
    }
    return errorMessage;
}
Also used : Checkpoint(nl.nn.testtool.Checkpoint) Message(nl.nn.adapterframework.stream.Message) PipeLineResult(nl.nn.adapterframework.core.PipeLineResult) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) IOException(java.io.IOException) IAdapter(nl.nn.adapterframework.core.IAdapter)

Example 5 with Checkpoint

use of nl.nn.testtool.Checkpoint in project iaf by ibissource.

the class StatusExtractor method extractMetadata.

public Object extractMetadata(Report report) {
    String status = "Success";
    List checkpoints = report.getCheckpoints();
    if (checkpoints.size() > 0) {
        Checkpoint lastCheckpoint = (Checkpoint) checkpoints.get(checkpoints.size() - 1);
        if (lastCheckpoint.getType() == Checkpoint.TYPE_ABORTPOINT) {
            status = "Error";
        }
    }
    return status;
}
Also used : Checkpoint(nl.nn.testtool.Checkpoint) List(java.util.List)

Aggregations

Checkpoint (nl.nn.testtool.Checkpoint)6 IAdapter (nl.nn.adapterframework.core.IAdapter)3 PipeLineSession (nl.nn.adapterframework.core.PipeLineSession)3 Message (nl.nn.adapterframework.stream.Message)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 PipeLineResult (nl.nn.adapterframework.core.PipeLineResult)2 Report (nl.nn.testtool.Report)2 StorageException (nl.nn.testtool.storage.StorageException)2 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 DataAccessException (org.springframework.dao.DataAccessException)1 RowMapper (org.springframework.jdbc.core.RowMapper)1