1 package org.akraino.validation.ui.service;
3 import java.io.IOException;
4 import java.util.ArrayList;
5 import java.util.HashSet;
9 import javax.annotation.Nonnull;
11 import org.akraino.validation.ui.dao.BlueprintDAO;
12 import org.akraino.validation.ui.dao.BlueprintInstanceDAO;
13 import org.akraino.validation.ui.dao.BlueprintLayerDAO;
14 import org.akraino.validation.ui.dao.LabDAO;
15 import org.akraino.validation.ui.dao.TimeslotDAO;
16 import org.akraino.validation.ui.dao.ValidationTestResultDAO;
17 import org.akraino.validation.ui.dao.WRobotTestResultDAO;
18 import org.akraino.validation.ui.data.JnksJobNotify;
19 import org.akraino.validation.ui.entity.Blueprint;
20 import org.akraino.validation.ui.entity.BlueprintInstance;
21 import org.akraino.validation.ui.entity.BlueprintLayer;
22 import org.akraino.validation.ui.entity.LabInfo;
23 import org.akraino.validation.ui.entity.Submission;
24 import org.akraino.validation.ui.entity.Timeslot;
25 import org.akraino.validation.ui.entity.ValidationDbTestResult;
26 import org.akraino.validation.ui.entity.WRobotDbTestResult;
27 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
28 import org.springframework.beans.factory.annotation.Autowired;
29 import org.springframework.stereotype.Service;
30 import org.springframework.transaction.annotation.Transactional;
32 import com.fasterxml.jackson.core.JsonParseException;
33 import com.fasterxml.jackson.databind.JsonMappingException;
37 public class DbAdapter {
39 private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(DbAdapter.class);
40 private static final Object LOCK = new Object();
43 private ValidationTestResultDAO vTestResultDAO;
46 private WRobotTestResultDAO wRobotDAO;
49 private LabDAO labDAO;
52 private BlueprintLayerDAO layerDAO;
55 private BlueprintInstanceDAO bluInstDao;
58 private BlueprintDAO blueprintDAO;
61 private TimeslotDAO timeslotDAO;
64 DbSubmissionAdapter subService;
66 public void associateSubmissionWithValidationResult(Submission submission)
67 throws JsonParseException, JsonMappingException, IOException {
69 if (!compareBluInstances(submission.getValidationDbTestResult().getBlueprintInstance(),
70 bluInstDao.getBlueprintInstance(
71 submission.getValidationDbTestResult().getBlueprintInstance().getBlueprintInstanceId()))) {
72 throw new RuntimeException("Blueprint instance data changed.");
74 if (!compareTimeslots(submission.getTimeslot(),
75 timeslotDAO.getTimeslot(submission.getTimeslot().getTimeslotId()))) {
76 throw new RuntimeException("Timeslot data changed.");
79 boolean canContinue = false;
80 for (Timeslot timeslot : bluInstDao
81 .getBlueprintInstance(
82 submission.getValidationDbTestResult().getBlueprintInstance().getBlueprintInstanceId())
84 if (compareTimeslots(timeslot, submission.getTimeslot())) {
90 throw new RuntimeException("Configured timeslot is no longer assigned to the blueprint instance.");
92 submission.getValidationDbTestResult().setSubmission(submission);
93 vTestResultDAO.saveOrUpdate(submission.getValidationDbTestResult());
94 if (submission.getValidationDbTestResult().getWRobotDbTestResults() != null) {
95 for (WRobotDbTestResult vRobotDbResult : submission.getValidationDbTestResult()
96 .getWRobotDbTestResults()) {
97 vRobotDbResult.setValidationDbTestResult(submission.getValidationDbTestResult());
98 wRobotDAO.saveOrUpdate(vRobotDbResult);
104 public void storeResultsInDb(List<ValidationDbTestResult> vNexusResults) {
105 synchronized (LOCK) {
106 if (vNexusResults == null || vNexusResults.size() < 1) {
109 for (ValidationDbTestResult vNexusResult : vNexusResults) {
110 if (vNexusResult.getWRobotDbTestResults() == null) {
113 if (!checkValidityOfNexusResult(vNexusResult)) {
116 LabInfo labInfo = labDAO.getLabBasedOnSilo(vNexusResult.getLab().getSilo());
117 ValidationDbTestResult vDbResult = vTestResultDAO.getValidationTestResult(labInfo,
118 vNexusResult.getTimestamp());
119 if (vDbResult == null) {
120 vDbResult = vNexusResult;
121 vDbResult.setLab(labInfo);
122 Blueprint blueprint = blueprintDAO
123 .getBlueprint(vNexusResult.getBlueprintInstance().getBlueprint().getBlueprintName());
124 if (blueprint == null) {
125 blueprint = vNexusResult.getBlueprintInstance().getBlueprint();
126 blueprintDAO.saveOrUpdate(blueprint);
128 BlueprintInstance blueprintInst = bluInstDao.getBlueprintInstance(blueprint,
129 (vNexusResult.getBlueprintInstance().getVersion()));
130 if (blueprintInst == null) {
131 blueprintInst = vNexusResult.getBlueprintInstance();
132 blueprintInst.setBlueprint(blueprint);
133 bluInstDao.saveOrUpdate(blueprintInst);
135 vDbResult.setBlueprintInstance(blueprintInst);
137 updateBlueInstLayers(vNexusResult);
138 vDbResult.setResult(vNexusResult.getResult());
139 vDbResult.setDateStorage(vNexusResult.getDateStorage());
140 LOGGER.debug(EELFLoggerDelegate.debugLogger,
141 "Storing validation test result with keys: blueprint name: "
142 + vNexusResult.getBlueprintInstance().getBlueprint().getBlueprintName() + ", version: "
143 + vNexusResult.getBlueprintInstance().getVersion() + ", lab: "
144 + vNexusResult.getLab().getSilo() + ", timestamp: " + vNexusResult.getTimestamp());
145 vTestResultDAO.saveOrUpdate(vDbResult);
146 List<org.akraino.validation.ui.entity.WRobotDbTestResult> wRobotDbResults = wRobotDAO
147 .getWRobotTestResult(vDbResult);
148 if (wRobotDbResults == null) {
149 // Store the new wrapper robot rest results in db
150 for (WRobotDbTestResult wNexusResult : vNexusResult.getWRobotDbTestResults()) {
151 wNexusResult.setValidationDbTestResult(vDbResult);
152 wRobotDAO.saveOrUpdate(wNexusResult);
154 } else if (vDbResult.getSubmission() != null) {
155 // update validation result related to submission
156 for (WRobotDbTestResult wNexusResult : vNexusResult.getWRobotDbTestResults()) {
157 WRobotDbTestResult wRobotDbResult = wRobotDAO.getWRobotTestResult(wNexusResult.getLayer(),
159 wRobotDbResult.setRobotTestResults(wNexusResult.getRobotTestResults());
160 wRobotDAO.saveOrUpdate(wRobotDbResult);
167 public void updateTimestamp(JnksJobNotify jnksJobNotify) {
168 synchronized (LOCK) {
169 if (!checkValidityOfJenkinsNotification(jnksJobNotify)) {
172 ValidationDbTestResult vDbSubmission = vTestResultDAO
173 .getValidationTestResult(subService.getSubmission(String.valueOf(jnksJobNotify.getSubmissionId())));
174 ValidationDbTestResult vDbTimestamp = vTestResultDAO.getValidationTestResult(vDbSubmission.getLab(),
175 jnksJobNotify.getTimestamp());
176 if (vDbTimestamp == null) {
177 vDbSubmission.setTimestamp(jnksJobNotify.getTimestamp());
178 vTestResultDAO.saveOrUpdate(vDbSubmission);
181 // Delete the wrobot results associated with submission validation result
182 List<WRobotDbTestResult> wRobotResults = wRobotDAO.getWRobotTestResult(vDbSubmission);
183 if (wRobotResults != null && wRobotResults.size() > 0) {
184 for (WRobotDbTestResult wRobotResult : wRobotResults) {
185 wRobotDAO.deleteWRobotTestResult(wRobotResult.getWRobotResultId());
188 // Change the timestamp wrobot results to point to submission validation result
189 wRobotResults = wRobotDAO.getWRobotTestResult(vDbTimestamp);
190 if (wRobotResults != null && wRobotResults.size() > 0) {
191 for (WRobotDbTestResult wRobotResult : wRobotResults) {
192 wRobotResult.setValidationDbTestResult(vDbSubmission);
193 wRobotDAO.saveOrUpdate(wRobotResult);
196 vTestResultDAO.deleteValidationTestResult(vDbTimestamp);
197 // Now vDbSubmission can be updated
198 vDbSubmission.setDateStorage(vDbTimestamp.getDateStorage());
199 vDbSubmission.setResult(vDbTimestamp.getResult());
200 vDbSubmission.setTimestamp(vDbTimestamp.getTimestamp());
201 vTestResultDAO.saveOrUpdate(vDbSubmission);
205 public List<ValidationDbTestResult> readResultFromDb(String blueprintName, String version, String lab,
206 List<String> layers, Boolean allLayers, Boolean optional, Boolean outcome)
207 throws JsonParseException, JsonMappingException, IOException {
208 synchronized (LOCK) {
209 LabInfo actualLabInfo = null;
211 actualLabInfo = labDAO.getLab(lab);
212 if (actualLabInfo == null) {
216 Blueprint blueprint = null;
217 if (blueprintName != null) {
218 blueprint = blueprintDAO.getBlueprint(blueprintName);
219 if (blueprint == null) {
223 BlueprintInstance blueprintInst = bluInstDao.getBlueprintInstance(blueprint, version);
224 if (blueprintInst == null) {
227 List<ValidationDbTestResult> vDbResults = vTestResultDAO.getValidationTestResults(blueprintInst,
228 actualLabInfo, allLayers, optional, outcome);
229 if (vDbResults == null || vDbResults.size() < 1) {
232 List<ValidationDbTestResult> actualResults = new ArrayList<ValidationDbTestResult>();
233 for (ValidationDbTestResult vDbResult : vDbResults) {
234 if (layers != null && layers.size() > 0) {
235 List<String> storedLayers = new ArrayList<String>();
236 List<WRobotDbTestResult> wDbResults = wRobotDAO.getWRobotTestResult(vDbResult);
237 if (wDbResults == null || wDbResults.size() < 1) {
240 for (WRobotDbTestResult wRobot : wDbResults) {
241 storedLayers.add(wRobot.getLayer());
243 if (!new HashSet<>(storedLayers).equals(new HashSet<>(layers))) {
247 actualResults.add(vDbResult);
249 return actualResults;
253 public ValidationDbTestResult readResultFromDb(@Nonnull String lab, @Nonnull String timestamp)
254 throws JsonParseException, JsonMappingException, IOException {
255 synchronized (LOCK) {
256 LabInfo actualLabInfo = labDAO.getLab(lab);
257 ValidationDbTestResult vDbResult = vTestResultDAO.getValidationTestResult(actualLabInfo, timestamp);
258 if (vDbResult == null) {
265 public ValidationDbTestResult readResultFromDb(@Nonnull String submissionId)
266 throws JsonParseException, JsonMappingException, IOException {
267 synchronized (LOCK) {
268 return vTestResultDAO.getValidationTestResult(subService.getSubmission(submissionId));
272 public void deleteUnreferencedEntries(List<ValidationDbTestResult> vNexusResults) {
273 synchronized (LOCK) {
274 if (vNexusResults == null || vNexusResults.size() < 1) {
277 LabInfo labInfo = labDAO.getLabBasedOnSilo(vNexusResults.get(0).getLab().getSilo());
278 if (labInfo == null) {
281 Blueprint blueprint = blueprintDAO
282 .getBlueprint(vNexusResults.get(0).getBlueprintInstance().getBlueprint().getBlueprintName());
283 if (blueprint == null) {
286 BlueprintInstance blueInst = bluInstDao.getBlueprintInstance(blueprint,
287 vNexusResults.get(0).getBlueprintInstance().getVersion());
288 if (blueInst == null) {
291 List<ValidationDbTestResult> vDbResults = vTestResultDAO.getValidationTestResults(blueInst, labInfo, null,
293 if (vDbResults == null || vDbResults.size() < 1) {
296 for (ValidationDbTestResult vDbResult : vDbResults) {
297 if (vDbResult.getSubmission() != null) {
300 boolean deletion = true;
301 String dbTimestamp = vDbResult.getTimestamp();
302 LabInfo dbLabInfo = vDbResult.getLab();
303 for (ValidationDbTestResult vNexusResult : vNexusResults) {
304 LabInfo nexusLabInfo = labDAO.getLabBasedOnSilo(vNexusResult.getLab().getSilo());
305 if (nexusLabInfo == null) {
308 if (vNexusResult.getTimestamp().equals(dbTimestamp) && nexusLabInfo.equals(dbLabInfo)) {
314 LOGGER.debug(EELFLoggerDelegate.debugLogger,
315 "Deleting unreferenced validation result with id: " + vDbResult.getResultId());
316 // Delete old associated wrapper robot rest results from db
317 for (WRobotDbTestResult wRobotDbResult : wRobotDAO.getWRobotTestResult(vDbResult)) {
318 wRobotDAO.deleteWRobotTestResult(wRobotDbResult.getWRobotResultId());
320 vTestResultDAO.deleteValidationTestResult(vDbResult);
326 public List<ValidationDbTestResult> getValidationTestResults() {
327 synchronized (LOCK) {
328 return vTestResultDAO.getValidationTestResults();
332 public ValidationDbTestResult getValidationTestResult(Integer resultId) {
333 synchronized (LOCK) {
334 return vTestResultDAO.getValidationTestResult(resultId);
338 public List<ValidationDbTestResult> getValidationTestResults(String blueprintName, @Nonnull String version,
339 LabInfo labInfo, Boolean allLayers, Boolean optional, Boolean outcome) {
340 synchronized (LOCK) {
341 Blueprint blueprint = null;
342 if (blueprintName != null) {
343 blueprint = blueprintDAO.getBlueprint(blueprintName);
344 if (blueprint == null) {
348 BlueprintInstance bluInst = bluInstDao.getBlueprintInstance(blueprint, version);
349 if (bluInst == null) {
352 return vTestResultDAO.getValidationTestResults(bluInst, labInfo, allLayers, optional, outcome);
356 public ValidationDbTestResult getValidationTestResult(LabInfo labInfo, String timestamp) {
357 synchronized (LOCK) {
358 return vTestResultDAO.getValidationTestResult(labInfo, timestamp);
362 public ValidationDbTestResult getValidationTestResult(String labSilo, String timestamp) {
363 synchronized (LOCK) {
364 return vTestResultDAO.getValidationTestResult(labDAO.getLabBasedOnSilo(labSilo), timestamp);
368 public ValidationDbTestResult getValidationTestResult(@Nonnull Submission submission) {
369 synchronized (LOCK) {
370 return vTestResultDAO.getValidationTestResult(submission);
374 public List<WRobotDbTestResult> getWRobotTestResults() {
375 synchronized (LOCK) {
376 return wRobotDAO.getWRobotTestResults();
380 public WRobotDbTestResult getWRobotTestResult(Integer wRobotResultId) {
381 synchronized (LOCK) {
382 return wRobotDAO.getWRobotTestResult(wRobotResultId);
386 public List<WRobotDbTestResult> getWRobotTestResult(ValidationDbTestResult vResult) {
387 synchronized (LOCK) {
388 return wRobotDAO.getWRobotTestResult(vResult);
392 public void saveLab(LabInfo lab) {
393 synchronized (LOCK) {
394 labDAO.saveOrUpdate(lab);
398 public void deleteLab(LabInfo lab) {
399 synchronized (LOCK) {
400 labDAO.deleteLab(lab);
404 public LabInfo getLab(String lab) {
405 synchronized (LOCK) {
406 return labDAO.getLab(lab);
410 public LabInfo getLabBasedOnSilo(String silo) {
411 synchronized (LOCK) {
412 return labDAO.getLabBasedOnSilo(silo);
416 public List<LabInfo> getLabs() {
417 synchronized (LOCK) {
418 return labDAO.getLabs();
422 public void deleteLabAll() {
423 synchronized (LOCK) {
428 public void saveBlueprintInstance(BlueprintInstance blueprintIns) {
429 synchronized (LOCK) {
430 Set<Timeslot> timeslots = blueprintIns.getTimeslots();
431 if (timeslots != null && timeslots.size() > 1) {
432 for (Timeslot timeslot : timeslots) {
433 if (!compareTimeslots(timeslot, timeslotDAO.getTimeslot(timeslot.getTimeslotId()))) {
434 throw new RuntimeException("Timeslot instance data changed.");
437 bluInstDao.merge(blueprintIns);
440 bluInstDao.saveOrUpdate(blueprintIns);
444 public List<BlueprintInstance> getBlueprintInstances() {
445 synchronized (LOCK) {
446 return bluInstDao.getBlueprintInstances();
450 public BlueprintInstance getBlueprintInstance(int instId) {
451 synchronized (LOCK) {
452 return bluInstDao.getBlueprintInstance(instId);
456 public BlueprintInstance getBlueprintInstance(Blueprint blueprint, String version) {
457 synchronized (LOCK) {
458 return bluInstDao.getBlueprintInstance(blueprint, version);
462 public void deleteBlueprintInstance(BlueprintInstance blueprintIns) {
463 synchronized (LOCK) {
464 bluInstDao.deleteBlueprintInstance(blueprintIns);
468 public void deleteBluInstAll() {
469 synchronized (LOCK) {
470 bluInstDao.deleteAll();
474 public void saveBlueprintLayer(BlueprintLayer layer) {
475 synchronized (LOCK) {
476 layerDAO.saveOrUpdate(layer);
480 public BlueprintLayer getBlueprintLayer(Integer layerId) {
481 synchronized (LOCK) {
482 return layerDAO.getBlueprintLayer(layerId);
486 public BlueprintLayer getBlueprintLayer(String layerData) {
487 synchronized (LOCK) {
488 return layerDAO.getBlueprintLayer(layerData);
492 public List<BlueprintLayer> getBlueprintLayers() {
493 synchronized (LOCK) {
494 return layerDAO.getBlueprintLayers();
498 public void deleteBlueprintLayer(BlueprintLayer layer) {
499 synchronized (LOCK) {
500 layerDAO.deleteBlueprintLayer(layer);
504 public void deleteBluLayersAll() {
505 synchronized (LOCK) {
506 layerDAO.deleteAll();
510 public void saveBlueprint(Blueprint blueprint) {
511 synchronized (LOCK) {
512 blueprintDAO.saveOrUpdate(blueprint);
516 public Blueprint getBlueprint(String name) {
517 synchronized (LOCK) {
518 return blueprintDAO.getBlueprint(name);
522 public List<Blueprint> getBlueprints() {
523 synchronized (LOCK) {
524 return blueprintDAO.getBlueprints();
528 public void deleteBlueprint(Blueprint blueprint) {
529 synchronized (LOCK) {
530 blueprintDAO.deleteBlueprint(blueprint);
534 public void deleteBluAll() {
535 synchronized (LOCK) {
536 blueprintDAO.deleteAll();
540 public void saveTimeslot(Timeslot timeslot) {
541 synchronized (LOCK) {
542 LabInfo labInfo = timeslot.getLabInfo();
543 if (labInfo != null) {
544 if (!compareLabInfos(labInfo, labDAO.getLab(labInfo.getLabId()))) {
545 throw new RuntimeException("Lab data changed.");
548 timeslotDAO.saveOrUpdate(timeslot);
552 public List<Timeslot> getTimeslots() {
553 synchronized (LOCK) {
554 return timeslotDAO.getTimeslots();
558 public void deleteTimeslot(Timeslot timeslot) {
559 synchronized (LOCK) {
560 timeslotDAO.deleteTimeslot(timeslot);
564 public void deleteTimeslotAll() {
565 synchronized (LOCK) {
566 timeslotDAO.deleteAll();
570 public boolean checkValidityOfNexusResult(ValidationDbTestResult vNexusResult) {
571 if (vNexusResult == null) {
574 LabInfo labInfo = labDAO.getLabBasedOnSilo(vNexusResult.getLab().getSilo());
575 if (labInfo == null) {
576 throw new RuntimeException("Lab silo : " + vNexusResult.getLab().getSilo() + " not found");
578 ValidationDbTestResult vDbResult = vTestResultDAO.getValidationTestResult(
579 labDAO.getLabBasedOnSilo(vNexusResult.getLab().getSilo()), vNexusResult.getTimestamp());
580 Blueprint blueprint = null;
581 BlueprintInstance bluInst = null;
582 List<WRobotDbTestResult> wRobotDbResults = null;
583 if (vDbResult != null) {
584 blueprint = vDbResult.getBlueprintInstance().getBlueprint();
585 labInfo = vDbResult.getLab();
586 wRobotDbResults = wRobotDAO.getWRobotTestResult(vDbResult);
588 blueprint = blueprintDAO
589 .getBlueprint(vNexusResult.getBlueprintInstance().getBlueprint().getBlueprintName());
591 if (blueprint != null) {
592 if (vDbResult != null) {
593 bluInst = vDbResult.getBlueprintInstance();
595 bluInst = bluInstDao.getBlueprintInstance(blueprint, vNexusResult.getBlueprintInstance().getVersion());
598 // Start comparison, be elastic with allLayers and optional
599 if (!labInfo.getSilo().equals(vNexusResult.getLab().getSilo())) {
600 LOGGER.error(EELFLoggerDelegate.errorLogger,
601 "Nexus has different data for blueprint : "
602 + vDbResult.getBlueprintInstance().getBlueprint().getBlueprintName() + ", version: "
603 + vDbResult.getBlueprintInstance().getVersion() + " and lab: " + vDbResult.getLab().getLab()
604 + ". Lab inconsistency : " + vDbResult.getLab() + " " + labInfo);
607 if (blueprint != null) {
608 if (!blueprint.getBlueprintName()
609 .equals(vNexusResult.getBlueprintInstance().getBlueprint().getBlueprintName())) {
610 LOGGER.error(EELFLoggerDelegate.errorLogger,
611 "Nexus has different data for blueprint : " + blueprint.getBlueprintName()
612 + ". Name inconsistency : " + blueprint.getBlueprintName() + " "
613 + vNexusResult.getBlueprintInstance().getBlueprint().getBlueprintName());
617 if (bluInst != null) {
618 if (!bluInst.getVersion().equals(vNexusResult.getBlueprintInstance().getVersion())) {
619 LOGGER.error(EELFLoggerDelegate.errorLogger,
620 "Nexus has different data for blueprint : " + bluInst.getBlueprint().getBlueprintName()
621 + ", version: " + bluInst.getVersion() + ". Version inconsistency : "
622 + bluInst.getVersion() + " " + vNexusResult.getBlueprintInstance().getVersion());
626 if (wRobotDbResults != null) {
627 List<String> storedLayers1 = new ArrayList<String>();
628 for (WRobotDbTestResult wNexusResult : vNexusResult.getWRobotDbTestResults()) {
629 storedLayers1.add(wNexusResult.getLayer());
631 List<String> storedLayers2 = new ArrayList<String>();
632 for (WRobotDbTestResult wDbResult : wRobotDbResults) {
633 storedLayers2.add(wDbResult.getLayer());
635 if (!new HashSet<>(storedLayers1).equals(new HashSet<>(storedLayers2))) {
636 LOGGER.error(EELFLoggerDelegate.errorLogger,
637 "Nexus has different layer results for validation result id: " + vDbResult.getResultId());
644 private boolean checkValidityOfJenkinsNotification(JnksJobNotify jnksJobNotify) {
645 ValidationDbTestResult vDbSubmission = vTestResultDAO
646 .getValidationTestResult(subService.getSubmission(String.valueOf(jnksJobNotify.getSubmissionId())));
647 if (vDbSubmission == null) {
648 LOGGER.error(EELFLoggerDelegate.errorLogger, "Received timestamp for submission id : "
649 + jnksJobNotify.getSubmissionId() + " which has not validation result associated with it");
652 if (!vDbSubmission.getAllLayers() && (vDbSubmission.getWRobotDbTestResults() == null
653 || vDbSubmission.getWRobotDbTestResults().size() < 1)) {
654 LOGGER.error(EELFLoggerDelegate.errorLogger, "Received timestamp for submission id : "
655 + jnksJobNotify.getSubmissionId() + " which is not stored correctly");
658 ValidationDbTestResult vDbTimestamp = vTestResultDAO.getValidationTestResult(vDbSubmission.getLab(),
659 jnksJobNotify.getTimestamp());
660 if (vDbTimestamp == null) {
663 if (vDbTimestamp.equals(vDbSubmission) || (vDbTimestamp.getSubmission() != null
664 && !jnksJobNotify.getSubmissionId().equals(vDbTimestamp.getSubmission().getSubmissionId()))) {
665 LOGGER.error(EELFLoggerDelegate.errorLogger, "Received same timestamp: " + jnksJobNotify.getTimestamp()
666 + " from nexus for submission id: " + jnksJobNotify.getSubmissionId());
669 if (!vDbSubmission.getAllLayers()) {
670 if (wRobotDAO.getWRobotTestResult(vDbSubmission).size() != wRobotDAO.getWRobotTestResult(vDbTimestamp)
672 LOGGER.error(EELFLoggerDelegate.errorLogger, "No consistency exists in stored layers records.");
675 List<String> storedLayers1 = new ArrayList<String>();
676 List<String> storedLayers2 = new ArrayList<String>();
677 List<WRobotDbTestResult> wDbResults = wRobotDAO.getWRobotTestResult(vDbSubmission);
678 for (WRobotDbTestResult wRobot : wDbResults) {
679 storedLayers1.add(wRobot.getLayer());
681 wDbResults = wRobotDAO.getWRobotTestResult(vDbTimestamp);
682 for (WRobotDbTestResult wRobot : wDbResults) {
683 storedLayers2.add(wRobot.getLayer());
685 if (!new HashSet<>(storedLayers1).equals(new HashSet<>(storedLayers2))) {
686 LOGGER.error(EELFLoggerDelegate.errorLogger, "No consistency exists in stored layers records.");
690 // Be elastic with allLayers and optional
691 if (!vDbSubmission.getBlueprintInstance().getBlueprint().getBlueprintName()
692 .equals(vDbTimestamp.getBlueprintInstance().getBlueprint().getBlueprintName())
693 || !vDbSubmission.getBlueprintInstance().getVersion()
694 .equals(vDbTimestamp.getBlueprintInstance().getVersion())
695 || !compareLabInfos(vDbSubmission.getLab(), vDbTimestamp.getLab())) {
696 LOGGER.error(EELFLoggerDelegate.errorLogger, "No consistency exists in database records.");
702 private void updateBlueInstLayers(ValidationDbTestResult vNexusResult) {
703 for (BlueprintInstance blueprintInst : bluInstDao.getBlueprintInstances()) {
704 if (!blueprintInst.getBlueprint().getBlueprintName()
705 .equals(vNexusResult.getBlueprintInstance().getBlueprint().getBlueprintName())) {
708 Set<BlueprintLayer> blueprintLayers = blueprintInst.getBlueprintLayers();
709 if (blueprintLayers == null) {
710 blueprintLayers = new HashSet<BlueprintLayer>();
712 for (WRobotDbTestResult nexusResult : vNexusResult.getWRobotDbTestResults()) {
713 BlueprintLayer layer = layerDAO.getBlueprintLayer(nexusResult.getLayer());
715 layer = new BlueprintLayer();
716 layer.setLayer(nexusResult.getLayer());
717 layerDAO.saveOrUpdate(layer);
719 if (!blueprintLayers.contains(layer)) {
720 blueprintLayers.add(layer);
723 blueprintInst.setBlueprintLayers(blueprintLayers);
724 bluInstDao.saveOrUpdate(blueprintInst);
728 private boolean compareBluInstances(BlueprintInstance inst1, BlueprintInstance inst2) {
729 if (!inst1.getVersion().equals(inst2.getVersion())) {
732 if (inst1.getBlueprintInstanceId() != inst2.getBlueprintInstanceId()) {
735 Set<BlueprintLayer> layers1 = inst1.getBlueprintLayers();
736 Set<BlueprintLayer> layers2 = inst2.getBlueprintLayers();
737 if (!(layers1 == null && layers2 == null)) {
738 if (layers1 != null && layers2 == null) {
741 if (layers1 == null && layers2 != null) {
744 if (!(layers1.size() == layers2.size())) {
747 boolean overallLayerEquality = true;
748 for (BlueprintLayer blulayer1 : layers1) {
749 boolean layerEquality = false;
750 for (BlueprintLayer blulayer2 : layers2) {
751 if (blulayer1.getLayer().equals(blulayer2.getLayer())) {
752 layerEquality = true;
755 if (!layerEquality) {
756 overallLayerEquality = false;
760 if (!overallLayerEquality) {
764 if (!compareBlueprints(inst1.getBlueprint(), inst2.getBlueprint())) {
770 private boolean compareTimeslots(Timeslot timeslot1, Timeslot timeslot2) {
771 if (!timeslot1.getStartDateTime().equals(timeslot2.getStartDateTime())
772 || timeslot1.getTimeslotId() != timeslot2.getTimeslotId()) {
775 if (!compareLabInfos(timeslot1.getLabInfo(), timeslot2.getLabInfo())) {
781 private boolean compareBlueprints(Blueprint blueprint1, Blueprint blueprint2) {
782 if (blueprint1 != null || blueprint2 != null) {
783 if (blueprint1 != null && blueprint2 == null) {
786 if (blueprint1 == null && blueprint2 != null) {
789 if (blueprint1.getBlueprintId() != blueprint2.getBlueprintId()) {
792 if (!blueprint1.getBlueprintName().equals(blueprint2.getBlueprintName())) {
799 private boolean compareLabInfos(LabInfo labInfo1, LabInfo labInfo2) {
800 if (labInfo1 != null || labInfo2 != null) {
801 if (labInfo1 != null && labInfo2 == null) {
804 if (labInfo1 == null && labInfo2 != null) {
807 if (labInfo1.getLabId() != labInfo2.getLabId()) {
810 if (!labInfo1.getSilo().equals(labInfo2.getSilo())) {
813 if (!labInfo1.getLab().equals(labInfo2.getLab())) {