@Override public int hashCode() { int result = getId() != null ? getId().hashCode() : 0; result = 31 * result + (getTopologyId() != null ? getTopologyId().hashCode() : 0); result = 31 * result + (getVersionId() != null ? getVersionId().hashCode() : 0); result = 31 * result + (getTestCaseId() != null ? getTestCaseId().hashCode() : 0); result = 31 * result + (getFinished() != null ? getFinished().hashCode() : 0); result = 31 * result + (getSuccess() != null ? getSuccess().hashCode() : 0); result = 31 * result + (getExpectedOutputRecords() != null ? getExpectedOutputRecords().hashCode() : 0); result = 31 * result + (getActualOutputRecords() != null ? getActualOutputRecords().hashCode() : 0); result = 31 * result + (getMatched() != null ? getMatched().hashCode() : 0); result = 31 * result + (getEventLogFilePath() != null ? getEventLogFilePath().hashCode() : 0); result = 31 * result + (getStartTime() != null ? getStartTime().hashCode() : 0); result = 31 * result + (getFinishTime() != null ? getFinishTime().hashCode() : 0); result = 31 * result + (getTimestamp() != null ? getTimestamp().hashCode() : 0); return result; }
private TopologyTestRunHistory initializeTopologyTestRunHistory(Topology topology, TopologyTestRunCase testRunCase, Map<String, List<Map<String, Object>>> expectedOutputRecords, String eventLogFilePath) throws JsonProcessingException { Long topologyVersionId = catalogService.getCurrentVersionId(topology.getId()); TopologyTestRunHistory history = new TopologyTestRunHistory(); history.setTopologyId(topology.getId()); history.setVersionId(topologyVersionId); history.setTestCaseId(testRunCase.getId()); if (expectedOutputRecords != null) { String expectedOutputRecordsJson = objectMapper.writeValueAsString(expectedOutputRecords); history.setExpectedOutputRecords(expectedOutputRecordsJson); } history.setFinished(false); history.setStartTime(System.currentTimeMillis()); history.setEventLogFilePath(eventLogFilePath); return history; }
SimplifiedTopologyTestRunHistory(TopologyTestRunHistory history) { id = history.getId(); topologyId = history.getTopologyId(); versionId = history.getVersionId(); finished = history.getFinished(); success = history.getSuccess(); matched = history.getMatched(); startTime = history.getStartTime(); finishTime = history.getFinishTime(); timestamp = history.getTimestamp(); }
public TopologyTestRunHistory getTopologyTestRunHistory(Long id) { TopologyTestRunHistory history = new TopologyTestRunHistory(); history.setId(id); return dao.get(new StorableKey(TopologyTestRunHistory.NAMESPACE, history.getPrimaryKey())); }
private Void runTestInBackground(TopologyActions topologyActions, Topology topology, TopologyTestRunHistory history, Map<String, TestRunSource> testRunSourceMap, Map<String, TestRunProcessor> testRunProcessorMap, Map<String, TestRunRulesProcessor> testRunRulesProcessorMap, Map<String, TestRunSink> testRunSinkMap, Map<String, List<Map<String, Object>>> expectedOutputRecordsMap, Optional<Long> durationSecs) throws IOException { TopologyLayout topologyLayout = CatalogToLayoutConverter.getTopologyLayout(topology, topology.getTopologyDag()); try { topologyActionsService.setUpClusterArtifacts(topology, topologyActions); String mavenArtifacts = topologyActionsService.setUpExtraJars(topology, topologyActions); topologyActions.runTest(topologyLayout, history, mavenArtifacts, testRunSourceMap, testRunProcessorMap, testRunRulesProcessorMap, testRunSinkMap, durationSecs); history.finishSuccessfully(); Map<String, List<Map<String, Object>>> actualOutputRecordsMap = parseTestRunOutputFiles(testRunSinkMap); history.setActualOutputRecords(objectMapper.writeValueAsString(actualOutputRecordsMap)); if (expectedOutputRecordsMap != null) { boolean matched = equalsOutputRecords(expectedOutputRecordsMap, actualOutputRecordsMap); history.setMatched(matched); } } catch (Throwable e) { LOG.warn("Exception thrown while running Topology as test mode. Marking as 'failed'. topology id: {}", topology.getId(), e); history.finishWithFailures(); } catalogService.addOrUpdateTopologyTestRunHistory(history.getId(), history); return null; }
@Override public boolean killTest(TopologyTestRunHistory testRunHistory) { // just turn on the flag only if it exists LOG.info("Turning on force kill flag on test run history {}", testRunHistory.getId()); Boolean newValue = forceKillRequests.computeIfPresent(testRunHistory.getId(), (id, flag) -> true); return newValue != null; }
public TopologyTestRunHistory addTopologyTestRunHistory(TopologyTestRunHistory history) { if (history.getId() == null) { history.setId(dao.nextId(TopologyTestRunHistory.NAMESPACE)); } history.setTimestamp(System.currentTimeMillis()); dao.add(history); return history; }
private File getEventLogFile(Long topologyId, Long historyId) { TopologyTestRunHistory history = catalogService.getTopologyTestRunHistory(historyId); if (history == null) { throw EntityNotFoundException.byId(String.valueOf(historyId)); } if (!history.getTopologyId().equals(topologyId)) { throw BadRequestException.message("Test history " + historyId + " is not belong to topology " + topologyId); } String eventLogFilePath = history.getEventLogFilePath(); File eventLogFile = new File(eventLogFilePath); if (!eventLogFile.exists() || eventLogFile.isDirectory() || !eventLogFile.canRead()) { throw BadRequestException.message("Event log file of history " + historyId + " does not exist or is not readable."); } return eventLogFile; }
@GET @Path("/topologies/{topologyId}/testhistories/{historyId}") @Timed public Response getHistoryOfTestRunTopology (@Context UriInfo urlInfo, @PathParam("topologyId") Long topologyId, @PathParam("historyId") Long historyId, @QueryParam("simplify") Boolean simplify, @Context SecurityContext securityContext) throws Exception { SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_USER, Topology.NAMESPACE, topologyId, READ); TopologyTestRunHistory history = catalogService.getTopologyTestRunHistory(historyId); if (history == null) { throw EntityNotFoundException.byId(String.valueOf(historyId)); } if (!history.getTopologyId().equals(topologyId)) { throw BadRequestException.message("Test history " + historyId + " is not belong to topology " + topologyId); } if (BooleanUtils.isTrue(simplify)) { return WSUtils.respondEntity(new SimplifiedTopologyTestRunHistory(history), OK); } else { return WSUtils.respondEntity(history, OK); } }
private List<TopologyTestRunHistory> filterHistories(Integer limit, Collection<TopologyTestRunHistory> histories) { if (limit == null) { limit = DEFAULT_LIST_ENTITIES_COUNT; } return histories.stream() // reverse order .sorted((h1, h2) -> (int) (h2.getId() - h1.getId())) .limit(limit) .collect(toList()); }
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof TopologyTestRunHistory)) return false; TopologyTestRunHistory that = (TopologyTestRunHistory) o; if (getId() != null ? !getId().equals(that.getId()) : that.getId() != null) return false; if (getTopologyId() != null ? !getTopologyId().equals(that.getTopologyId()) : that.getTopologyId() != null) return false; if (getVersionId() != null ? !getVersionId().equals(that.getVersionId()) : that.getVersionId() != null) return false; if (getTestCaseId() != null ? !getTestCaseId().equals(that.getTestCaseId()) : that.getTestCaseId() != null) return false; if (getFinished() != null ? !getFinished().equals(that.getFinished()) : that.getFinished() != null) return false; if (getSuccess() != null ? !getSuccess().equals(that.getSuccess()) : that.getSuccess() != null) return false; if (getExpectedOutputRecords() != null ? !getExpectedOutputRecords().equals(that.getExpectedOutputRecords()) : that.getExpectedOutputRecords() != null) return false; if (getActualOutputRecords() != null ? !getActualOutputRecords().equals(that.getActualOutputRecords()) : that.getActualOutputRecords() != null) return false; if (getMatched() != null ? !getMatched().equals(that.getMatched()) : that.getMatched() != null) return false; if (getEventLogFilePath() != null ? !getEventLogFilePath().equals(that.getEventLogFilePath()) : that.getEventLogFilePath() != null) return false; if (getStartTime() != null ? !getStartTime().equals(that.getStartTime()) : that.getStartTime() != null) return false; if (getFinishTime() != null ? !getFinishTime().equals(that.getFinishTime()) : that.getFinishTime() != null) return false; return getTimestamp() != null ? getTimestamp().equals(that.getTimestamp()) : that.getTimestamp() == null; }
ShellProcessResult shellProcessResult = waitTestRunProcess(process, testRunHistory.getId()); int exitValue = shellProcessResult.exitValue; if (exitValue != 0) {
runHistories.forEach(history -> removeTopologyTestRunHistory(history.getId()));