2 * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may
5 * not use this file except in compliance with the License. You may obtain
6 * a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 * implied. See the License for the specific language governing
14 * permissions and limitations under the License.
17 package org.akraino.validation.ui.service;
19 import java.io.IOException;
20 import java.util.ArrayList;
21 import java.util.HashSet;
22 import java.util.List;
25 import javax.annotation.Nonnull;
27 import org.akraino.validation.ui.dao.BlueprintDAO;
28 import org.akraino.validation.ui.dao.BlueprintInstanceDAO;
29 import org.akraino.validation.ui.dao.BlueprintLayerDAO;
30 import org.akraino.validation.ui.dao.LabDAO;
31 import org.akraino.validation.ui.dao.TimeslotDAO;
32 import org.akraino.validation.ui.dao.ValidationTestResultDAO;
33 import org.akraino.validation.ui.dao.WRobotTestResultDAO;
34 import org.akraino.validation.ui.data.JnksJobNotify;
35 import org.akraino.validation.ui.entity.Blueprint;
36 import org.akraino.validation.ui.entity.BlueprintInstance;
37 import org.akraino.validation.ui.entity.BlueprintLayer;
38 import org.akraino.validation.ui.entity.LabInfo;
39 import org.akraino.validation.ui.entity.Submission;
40 import org.akraino.validation.ui.entity.Timeslot;
41 import org.akraino.validation.ui.entity.ValidationDbTestResult;
42 import org.akraino.validation.ui.entity.WRobotDbTestResult;
43 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
44 import org.springframework.beans.factory.annotation.Autowired;
45 import org.springframework.stereotype.Service;
46 import org.springframework.transaction.annotation.Transactional;
48 import com.fasterxml.jackson.core.JsonParseException;
49 import com.fasterxml.jackson.databind.JsonMappingException;
53 public class DbAdapter {
55 private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(DbAdapter.class);
56 private static final Object LOCK = new Object();
59 private ValidationTestResultDAO vTestResultDAO;
62 private WRobotTestResultDAO wRobotDAO;
65 private LabDAO labDAO;
68 private BlueprintLayerDAO layerDAO;
71 private BlueprintInstanceDAO bluInstDao;
74 private BlueprintDAO blueprintDAO;
77 private TimeslotDAO timeslotDAO;
80 DbSubmissionAdapter subService;
82 public void associateSubmissionWithValidationResult(Submission submission)
83 throws JsonParseException, JsonMappingException, IOException {
85 if (!compareBluInstances(submission.getValidationDbTestResult().getBlueprintInstance(),
86 bluInstDao.getBlueprintInstance(
87 submission.getValidationDbTestResult().getBlueprintInstance().getBlueprintInstanceId()))) {
88 throw new RuntimeException("Blueprint instance data changed.");
90 if (!compareTimeslots(submission.getTimeslot(),
91 timeslotDAO.getTimeslot(submission.getTimeslot().getTimeslotId()))) {
92 throw new RuntimeException("Timeslot data changed.");
95 boolean canContinue = false;
96 for (Timeslot timeslot : bluInstDao
97 .getBlueprintInstance(
98 submission.getValidationDbTestResult().getBlueprintInstance().getBlueprintInstanceId())
100 if (compareTimeslots(timeslot, submission.getTimeslot())) {
106 throw new RuntimeException("Configured timeslot is no longer assigned to the blueprint instance.");
108 submission.getValidationDbTestResult().setSubmission(submission);
109 vTestResultDAO.saveOrUpdate(submission.getValidationDbTestResult());
110 if (submission.getValidationDbTestResult().getWRobotDbTestResults() != null) {
111 for (WRobotDbTestResult vRobotDbResult : submission.getValidationDbTestResult()
112 .getWRobotDbTestResults()) {
113 vRobotDbResult.setValidationDbTestResult(submission.getValidationDbTestResult());
114 wRobotDAO.saveOrUpdate(vRobotDbResult);
120 public void storeResultsInDb(List<ValidationDbTestResult> vNexusResults) {
121 synchronized (LOCK) {
122 if (vNexusResults == null || vNexusResults.size() < 1) {
125 for (ValidationDbTestResult vNexusResult : vNexusResults) {
126 if (vNexusResult.getWRobotDbTestResults() == null) {
129 if (!checkValidityOfNexusResult(vNexusResult)) {
132 LabInfo labInfo = labDAO.getLabBasedOnSilo(vNexusResult.getLab().getSilo());
133 ValidationDbTestResult vDbResult = vTestResultDAO.getValidationTestResult(labInfo,
134 vNexusResult.getTimestamp());
135 if (vDbResult == null) {
136 vDbResult = vNexusResult;
137 vDbResult.setLab(labInfo);
138 Blueprint blueprint = blueprintDAO
139 .getBlueprint(vNexusResult.getBlueprintInstance().getBlueprint().getBlueprintName());
140 if (blueprint == null) {
141 blueprint = vNexusResult.getBlueprintInstance().getBlueprint();
142 blueprintDAO.saveOrUpdate(blueprint);
144 BlueprintInstance blueprintInst = bluInstDao.getBlueprintInstance(blueprint,
145 (vNexusResult.getBlueprintInstance().getVersion()));
146 if (blueprintInst == null) {
147 blueprintInst = vNexusResult.getBlueprintInstance();
148 blueprintInst.setBlueprint(blueprint);
149 bluInstDao.saveOrUpdate(blueprintInst);
151 vDbResult.setBlueprintInstance(blueprintInst);
153 updateBlueInstLayers(vNexusResult);
154 vDbResult.setResult(vNexusResult.getResult());
155 vDbResult.setDateStorage(vNexusResult.getDateStorage());
156 LOGGER.debug(EELFLoggerDelegate.debugLogger,
157 "Storing validation test result with keys: blueprint name: "
158 + vNexusResult.getBlueprintInstance().getBlueprint().getBlueprintName() + ", version: "
159 + vNexusResult.getBlueprintInstance().getVersion() + ", lab: "
160 + vNexusResult.getLab().getSilo() + ", timestamp: " + vNexusResult.getTimestamp());
161 vTestResultDAO.saveOrUpdate(vDbResult);
162 List<org.akraino.validation.ui.entity.WRobotDbTestResult> wRobotDbResults = wRobotDAO
163 .getWRobotTestResult(vDbResult);
164 if (wRobotDbResults == null) {
165 // Store the new wrapper robot rest results in db
166 for (WRobotDbTestResult wNexusResult : vNexusResult.getWRobotDbTestResults()) {
167 wNexusResult.setValidationDbTestResult(vDbResult);
168 wRobotDAO.saveOrUpdate(wNexusResult);
170 } else if (vDbResult.getSubmission() != null) {
171 // update validation result related to submission
172 for (WRobotDbTestResult wNexusResult : vNexusResult.getWRobotDbTestResults()) {
173 WRobotDbTestResult wRobotDbResult = wRobotDAO.getWRobotTestResult(wNexusResult.getLayer(),
175 wRobotDbResult.setRobotTestResults(wNexusResult.getRobotTestResults());
176 wRobotDAO.saveOrUpdate(wRobotDbResult);
183 public void updateTimestamp(JnksJobNotify jnksJobNotify) {
184 synchronized (LOCK) {
185 if (!checkValidityOfJenkinsNotification(jnksJobNotify)) {
188 ValidationDbTestResult vDbSubmission = vTestResultDAO
189 .getValidationTestResult(subService.getSubmission(String.valueOf(jnksJobNotify.getSubmissionId())));
190 ValidationDbTestResult vDbTimestamp = vTestResultDAO.getValidationTestResult(vDbSubmission.getLab(),
191 jnksJobNotify.getTimestamp());
192 if (vDbTimestamp == null) {
193 vDbSubmission.setTimestamp(jnksJobNotify.getTimestamp());
194 vTestResultDAO.saveOrUpdate(vDbSubmission);
197 // Delete the wrobot results associated with submission validation result
198 List<WRobotDbTestResult> wRobotResults = wRobotDAO.getWRobotTestResult(vDbSubmission);
199 if (wRobotResults != null && wRobotResults.size() > 0) {
200 for (WRobotDbTestResult wRobotResult : wRobotResults) {
201 wRobotDAO.deleteWRobotTestResult(wRobotResult.getWRobotResultId());
204 // Change the timestamp wrobot results to point to submission validation result
205 wRobotResults = wRobotDAO.getWRobotTestResult(vDbTimestamp);
206 if (wRobotResults != null && wRobotResults.size() > 0) {
207 for (WRobotDbTestResult wRobotResult : wRobotResults) {
208 wRobotResult.setValidationDbTestResult(vDbSubmission);
209 wRobotDAO.saveOrUpdate(wRobotResult);
212 vTestResultDAO.deleteValidationTestResult(vDbTimestamp);
213 // Now vDbSubmission can be updated
214 vDbSubmission.setDateStorage(vDbTimestamp.getDateStorage());
215 vDbSubmission.setResult(vDbTimestamp.getResult());
216 vDbSubmission.setTimestamp(vDbTimestamp.getTimestamp());
217 vTestResultDAO.saveOrUpdate(vDbSubmission);
221 public List<ValidationDbTestResult> readResultFromDb(String blueprintName, String version, String lab,
222 List<String> layers, Boolean allLayers, Boolean optional, Boolean outcome)
223 throws JsonParseException, JsonMappingException, IOException {
224 synchronized (LOCK) {
225 LabInfo actualLabInfo = null;
227 actualLabInfo = labDAO.getLab(lab);
228 if (actualLabInfo == null) {
232 Blueprint blueprint = null;
233 if (blueprintName != null) {
234 blueprint = blueprintDAO.getBlueprint(blueprintName);
235 if (blueprint == null) {
239 BlueprintInstance blueprintInst = bluInstDao.getBlueprintInstance(blueprint, version);
240 if (blueprintInst == null) {
243 List<ValidationDbTestResult> vDbResults = vTestResultDAO.getValidationTestResults(blueprintInst,
244 actualLabInfo, allLayers, optional, outcome);
245 if (vDbResults == null || vDbResults.size() < 1) {
248 List<ValidationDbTestResult> actualResults = new ArrayList<ValidationDbTestResult>();
249 for (ValidationDbTestResult vDbResult : vDbResults) {
250 if (layers != null && layers.size() > 0) {
251 List<String> storedLayers = new ArrayList<String>();
252 List<WRobotDbTestResult> wDbResults = wRobotDAO.getWRobotTestResult(vDbResult);
253 if (wDbResults == null || wDbResults.size() < 1) {
256 for (WRobotDbTestResult wRobot : wDbResults) {
257 storedLayers.add(wRobot.getLayer());
259 if (!new HashSet<>(storedLayers).equals(new HashSet<>(layers))) {
263 actualResults.add(vDbResult);
265 return actualResults;
269 public ValidationDbTestResult readResultFromDb(@Nonnull String lab, @Nonnull String timestamp)
270 throws JsonParseException, JsonMappingException, IOException {
271 synchronized (LOCK) {
272 LabInfo actualLabInfo = labDAO.getLab(lab);
273 ValidationDbTestResult vDbResult = vTestResultDAO.getValidationTestResult(actualLabInfo, timestamp);
274 if (vDbResult == null) {
281 public ValidationDbTestResult readResultFromDb(@Nonnull String submissionId)
282 throws JsonParseException, JsonMappingException, IOException {
283 synchronized (LOCK) {
284 return vTestResultDAO.getValidationTestResult(subService.getSubmission(submissionId));
288 public void deleteUnreferencedEntries(List<ValidationDbTestResult> vNexusResults) {
289 synchronized (LOCK) {
290 if (vNexusResults == null || vNexusResults.size() < 1) {
293 LabInfo labInfo = labDAO.getLabBasedOnSilo(vNexusResults.get(0).getLab().getSilo());
294 if (labInfo == null) {
297 Blueprint blueprint = blueprintDAO
298 .getBlueprint(vNexusResults.get(0).getBlueprintInstance().getBlueprint().getBlueprintName());
299 if (blueprint == null) {
302 BlueprintInstance blueInst = bluInstDao.getBlueprintInstance(blueprint,
303 vNexusResults.get(0).getBlueprintInstance().getVersion());
304 if (blueInst == null) {
307 List<ValidationDbTestResult> vDbResults = vTestResultDAO.getValidationTestResults(blueInst, labInfo, null,
309 if (vDbResults == null || vDbResults.size() < 1) {
312 for (ValidationDbTestResult vDbResult : vDbResults) {
313 if (vDbResult.getSubmission() != null) {
316 boolean deletion = true;
317 String dbTimestamp = vDbResult.getTimestamp();
318 LabInfo dbLabInfo = vDbResult.getLab();
319 for (ValidationDbTestResult vNexusResult : vNexusResults) {
320 LabInfo nexusLabInfo = labDAO.getLabBasedOnSilo(vNexusResult.getLab().getSilo());
321 if (nexusLabInfo == null) {
324 if (vNexusResult.getTimestamp().equals(dbTimestamp) && nexusLabInfo.equals(dbLabInfo)) {
330 LOGGER.debug(EELFLoggerDelegate.debugLogger,
331 "Deleting unreferenced validation result with id: " + vDbResult.getResultId());
332 // Delete old associated wrapper robot rest results from db
333 for (WRobotDbTestResult wRobotDbResult : wRobotDAO.getWRobotTestResult(vDbResult)) {
334 wRobotDAO.deleteWRobotTestResult(wRobotDbResult.getWRobotResultId());
336 vTestResultDAO.deleteValidationTestResult(vDbResult);
342 public List<ValidationDbTestResult> getValidationTestResults() {
343 synchronized (LOCK) {
344 return vTestResultDAO.getValidationTestResults();
348 public ValidationDbTestResult getValidationTestResult(Integer resultId) {
349 synchronized (LOCK) {
350 return vTestResultDAO.getValidationTestResult(resultId);
354 public List<ValidationDbTestResult> getValidationTestResults(String blueprintName, @Nonnull String version,
355 LabInfo labInfo, Boolean allLayers, Boolean optional, Boolean outcome) {
356 synchronized (LOCK) {
357 Blueprint blueprint = null;
358 if (blueprintName != null) {
359 blueprint = blueprintDAO.getBlueprint(blueprintName);
360 if (blueprint == null) {
364 BlueprintInstance bluInst = bluInstDao.getBlueprintInstance(blueprint, version);
365 if (bluInst == null) {
368 return vTestResultDAO.getValidationTestResults(bluInst, labInfo, allLayers, optional, outcome);
372 public ValidationDbTestResult getValidationTestResult(LabInfo labInfo, String timestamp) {
373 synchronized (LOCK) {
374 return vTestResultDAO.getValidationTestResult(labInfo, timestamp);
378 public ValidationDbTestResult getValidationTestResult(String labSilo, String timestamp) {
379 synchronized (LOCK) {
380 return vTestResultDAO.getValidationTestResult(labDAO.getLabBasedOnSilo(labSilo), timestamp);
384 public ValidationDbTestResult getValidationTestResult(@Nonnull Submission submission) {
385 synchronized (LOCK) {
386 return vTestResultDAO.getValidationTestResult(submission);
390 public List<WRobotDbTestResult> getWRobotTestResults() {
391 synchronized (LOCK) {
392 return wRobotDAO.getWRobotTestResults();
396 public WRobotDbTestResult getWRobotTestResult(Integer wRobotResultId) {
397 synchronized (LOCK) {
398 return wRobotDAO.getWRobotTestResult(wRobotResultId);
402 public List<WRobotDbTestResult> getWRobotTestResult(ValidationDbTestResult vResult) {
403 synchronized (LOCK) {
404 return wRobotDAO.getWRobotTestResult(vResult);
408 public void saveLab(LabInfo lab) {
409 synchronized (LOCK) {
410 labDAO.saveOrUpdate(lab);
414 public void deleteLab(LabInfo lab) {
415 synchronized (LOCK) {
416 labDAO.deleteLab(lab);
420 public LabInfo getLab(String lab) {
421 synchronized (LOCK) {
422 return labDAO.getLab(lab);
426 public LabInfo getLabBasedOnSilo(String silo) {
427 synchronized (LOCK) {
428 return labDAO.getLabBasedOnSilo(silo);
432 public List<LabInfo> getLabs() {
433 synchronized (LOCK) {
434 return labDAO.getLabs();
438 public void deleteLabAll() {
439 synchronized (LOCK) {
444 public void saveBlueprintInstance(BlueprintInstance blueprintIns) {
445 synchronized (LOCK) {
446 Set<Timeslot> timeslots = blueprintIns.getTimeslots();
447 if (timeslots != null && timeslots.size() > 1) {
448 for (Timeslot timeslot : timeslots) {
449 if (!compareTimeslots(timeslot, timeslotDAO.getTimeslot(timeslot.getTimeslotId()))) {
450 throw new RuntimeException("Timeslot instance data changed.");
453 bluInstDao.merge(blueprintIns);
456 bluInstDao.saveOrUpdate(blueprintIns);
460 public List<BlueprintInstance> getBlueprintInstances() {
461 synchronized (LOCK) {
462 return bluInstDao.getBlueprintInstances();
466 public BlueprintInstance getBlueprintInstance(int instId) {
467 synchronized (LOCK) {
468 return bluInstDao.getBlueprintInstance(instId);
472 public BlueprintInstance getBlueprintInstance(Blueprint blueprint, String version) {
473 synchronized (LOCK) {
474 return bluInstDao.getBlueprintInstance(blueprint, version);
478 public void deleteBlueprintInstance(BlueprintInstance blueprintIns) {
479 synchronized (LOCK) {
480 bluInstDao.deleteBlueprintInstance(blueprintIns);
484 public void deleteBluInstAll() {
485 synchronized (LOCK) {
486 bluInstDao.deleteAll();
490 public void saveBlueprintLayer(BlueprintLayer layer) {
491 synchronized (LOCK) {
492 layerDAO.saveOrUpdate(layer);
496 public BlueprintLayer getBlueprintLayer(Integer layerId) {
497 synchronized (LOCK) {
498 return layerDAO.getBlueprintLayer(layerId);
502 public BlueprintLayer getBlueprintLayer(String layerData) {
503 synchronized (LOCK) {
504 return layerDAO.getBlueprintLayer(layerData);
508 public List<BlueprintLayer> getBlueprintLayers() {
509 synchronized (LOCK) {
510 return layerDAO.getBlueprintLayers();
514 public void deleteBlueprintLayer(BlueprintLayer layer) {
515 synchronized (LOCK) {
516 layerDAO.deleteBlueprintLayer(layer);
520 public void deleteBluLayersAll() {
521 synchronized (LOCK) {
522 layerDAO.deleteAll();
526 public void saveBlueprint(Blueprint blueprint) {
527 synchronized (LOCK) {
528 blueprintDAO.saveOrUpdate(blueprint);
532 public Blueprint getBlueprint(String name) {
533 synchronized (LOCK) {
534 return blueprintDAO.getBlueprint(name);
538 public List<Blueprint> getBlueprints() {
539 synchronized (LOCK) {
540 return blueprintDAO.getBlueprints();
544 public void deleteBlueprint(Blueprint blueprint) {
545 synchronized (LOCK) {
546 blueprintDAO.deleteBlueprint(blueprint);
550 public void deleteBluAll() {
551 synchronized (LOCK) {
552 blueprintDAO.deleteAll();
556 public void saveTimeslot(Timeslot timeslot) {
557 synchronized (LOCK) {
558 LabInfo labInfo = timeslot.getLabInfo();
559 if (labInfo != null) {
560 if (!compareLabInfos(labInfo, labDAO.getLab(labInfo.getLabId()))) {
561 throw new RuntimeException("Lab data changed.");
564 timeslotDAO.saveOrUpdate(timeslot);
568 public List<Timeslot> getTimeslots() {
569 synchronized (LOCK) {
570 return timeslotDAO.getTimeslots();
574 public void deleteTimeslot(Timeslot timeslot) {
575 synchronized (LOCK) {
576 timeslotDAO.deleteTimeslot(timeslot);
580 public void deleteTimeslotAll() {
581 synchronized (LOCK) {
582 timeslotDAO.deleteAll();
586 public boolean checkValidityOfNexusResult(ValidationDbTestResult vNexusResult) {
587 if (vNexusResult == null) {
590 LabInfo labInfo = labDAO.getLabBasedOnSilo(vNexusResult.getLab().getSilo());
591 if (labInfo == null) {
592 throw new RuntimeException("Lab silo : " + vNexusResult.getLab().getSilo() + " not found");
594 ValidationDbTestResult vDbResult = vTestResultDAO.getValidationTestResult(
595 labDAO.getLabBasedOnSilo(vNexusResult.getLab().getSilo()), vNexusResult.getTimestamp());
596 Blueprint blueprint = null;
597 BlueprintInstance bluInst = null;
598 List<WRobotDbTestResult> wRobotDbResults = null;
599 if (vDbResult != null) {
600 blueprint = vDbResult.getBlueprintInstance().getBlueprint();
601 labInfo = vDbResult.getLab();
602 wRobotDbResults = wRobotDAO.getWRobotTestResult(vDbResult);
604 blueprint = blueprintDAO
605 .getBlueprint(vNexusResult.getBlueprintInstance().getBlueprint().getBlueprintName());
607 if (blueprint != null) {
608 if (vDbResult != null) {
609 bluInst = vDbResult.getBlueprintInstance();
611 bluInst = bluInstDao.getBlueprintInstance(blueprint, vNexusResult.getBlueprintInstance().getVersion());
614 // Start comparison, be elastic with allLayers and optional
615 if (!labInfo.getSilo().equals(vNexusResult.getLab().getSilo())) {
616 LOGGER.error(EELFLoggerDelegate.errorLogger,
617 "Nexus has different data for blueprint : "
618 + vDbResult.getBlueprintInstance().getBlueprint().getBlueprintName() + ", version: "
619 + vDbResult.getBlueprintInstance().getVersion() + " and lab: " + vDbResult.getLab().getLab()
620 + ". Lab inconsistency : " + vDbResult.getLab() + " " + labInfo);
623 if (blueprint != null) {
624 if (!blueprint.getBlueprintName()
625 .equals(vNexusResult.getBlueprintInstance().getBlueprint().getBlueprintName())) {
626 LOGGER.error(EELFLoggerDelegate.errorLogger,
627 "Nexus has different data for blueprint : " + blueprint.getBlueprintName()
628 + ". Name inconsistency : " + blueprint.getBlueprintName() + " "
629 + vNexusResult.getBlueprintInstance().getBlueprint().getBlueprintName());
633 if (bluInst != null) {
634 if (!bluInst.getVersion().equals(vNexusResult.getBlueprintInstance().getVersion())) {
635 LOGGER.error(EELFLoggerDelegate.errorLogger,
636 "Nexus has different data for blueprint : " + bluInst.getBlueprint().getBlueprintName()
637 + ", version: " + bluInst.getVersion() + ". Version inconsistency : "
638 + bluInst.getVersion() + " " + vNexusResult.getBlueprintInstance().getVersion());
642 if (wRobotDbResults != null) {
643 List<String> storedLayers1 = new ArrayList<String>();
644 for (WRobotDbTestResult wNexusResult : vNexusResult.getWRobotDbTestResults()) {
645 storedLayers1.add(wNexusResult.getLayer());
647 List<String> storedLayers2 = new ArrayList<String>();
648 for (WRobotDbTestResult wDbResult : wRobotDbResults) {
649 storedLayers2.add(wDbResult.getLayer());
651 if (!new HashSet<>(storedLayers1).equals(new HashSet<>(storedLayers2))) {
652 LOGGER.error(EELFLoggerDelegate.errorLogger,
653 "Nexus has different layer results for validation result id: " + vDbResult.getResultId());
660 private boolean checkValidityOfJenkinsNotification(JnksJobNotify jnksJobNotify) {
661 ValidationDbTestResult vDbSubmission = vTestResultDAO
662 .getValidationTestResult(subService.getSubmission(String.valueOf(jnksJobNotify.getSubmissionId())));
663 if (vDbSubmission == null) {
664 LOGGER.error(EELFLoggerDelegate.errorLogger, "Received timestamp for submission id : "
665 + jnksJobNotify.getSubmissionId() + " which has not validation result associated with it");
668 if (!vDbSubmission.getAllLayers() && (vDbSubmission.getWRobotDbTestResults() == null
669 || vDbSubmission.getWRobotDbTestResults().size() < 1)) {
670 LOGGER.error(EELFLoggerDelegate.errorLogger, "Received timestamp for submission id : "
671 + jnksJobNotify.getSubmissionId() + " which is not stored correctly");
674 ValidationDbTestResult vDbTimestamp = vTestResultDAO.getValidationTestResult(vDbSubmission.getLab(),
675 jnksJobNotify.getTimestamp());
676 if (vDbTimestamp == null) {
679 if (vDbTimestamp.equals(vDbSubmission) || (vDbTimestamp.getSubmission() != null
680 && !jnksJobNotify.getSubmissionId().equals(vDbTimestamp.getSubmission().getSubmissionId()))) {
681 LOGGER.error(EELFLoggerDelegate.errorLogger, "Received same timestamp: " + jnksJobNotify.getTimestamp()
682 + " from nexus for submission id: " + jnksJobNotify.getSubmissionId());
685 if (!vDbSubmission.getAllLayers()) {
686 if (wRobotDAO.getWRobotTestResult(vDbSubmission).size() != wRobotDAO.getWRobotTestResult(vDbTimestamp)
688 LOGGER.error(EELFLoggerDelegate.errorLogger, "No consistency exists in stored layers records.");
691 List<String> storedLayers1 = new ArrayList<String>();
692 List<String> storedLayers2 = new ArrayList<String>();
693 List<WRobotDbTestResult> wDbResults = wRobotDAO.getWRobotTestResult(vDbSubmission);
694 for (WRobotDbTestResult wRobot : wDbResults) {
695 storedLayers1.add(wRobot.getLayer());
697 wDbResults = wRobotDAO.getWRobotTestResult(vDbTimestamp);
698 for (WRobotDbTestResult wRobot : wDbResults) {
699 storedLayers2.add(wRobot.getLayer());
701 if (!new HashSet<>(storedLayers1).equals(new HashSet<>(storedLayers2))) {
702 LOGGER.error(EELFLoggerDelegate.errorLogger, "No consistency exists in stored layers records.");
706 // Be elastic with allLayers and optional
707 if (!vDbSubmission.getBlueprintInstance().getBlueprint().getBlueprintName()
708 .equals(vDbTimestamp.getBlueprintInstance().getBlueprint().getBlueprintName())
709 || !vDbSubmission.getBlueprintInstance().getVersion()
710 .equals(vDbTimestamp.getBlueprintInstance().getVersion())
711 || !compareLabInfos(vDbSubmission.getLab(), vDbTimestamp.getLab())) {
712 LOGGER.error(EELFLoggerDelegate.errorLogger, "No consistency exists in database records.");
718 private void updateBlueInstLayers(ValidationDbTestResult vNexusResult) {
719 for (BlueprintInstance blueprintInst : bluInstDao.getBlueprintInstances()) {
720 if (!blueprintInst.getBlueprint().getBlueprintName()
721 .equals(vNexusResult.getBlueprintInstance().getBlueprint().getBlueprintName())) {
724 Set<BlueprintLayer> blueprintLayers = blueprintInst.getBlueprintLayers();
725 if (blueprintLayers == null) {
726 blueprintLayers = new HashSet<BlueprintLayer>();
728 for (WRobotDbTestResult nexusResult : vNexusResult.getWRobotDbTestResults()) {
729 BlueprintLayer layer = layerDAO.getBlueprintLayer(nexusResult.getLayer());
731 layer = new BlueprintLayer();
732 layer.setLayer(nexusResult.getLayer());
733 layerDAO.saveOrUpdate(layer);
735 if (!blueprintLayers.contains(layer)) {
736 blueprintLayers.add(layer);
739 blueprintInst.setBlueprintLayers(blueprintLayers);
740 bluInstDao.saveOrUpdate(blueprintInst);
744 private boolean compareBluInstances(BlueprintInstance inst1, BlueprintInstance inst2) {
745 if (!inst1.getVersion().equals(inst2.getVersion())) {
748 if (inst1.getBlueprintInstanceId() != inst2.getBlueprintInstanceId()) {
751 Set<BlueprintLayer> layers1 = inst1.getBlueprintLayers();
752 Set<BlueprintLayer> layers2 = inst2.getBlueprintLayers();
753 if (!(layers1 == null && layers2 == null)) {
754 if (layers1 != null && layers2 == null) {
757 if (layers1 == null && layers2 != null) {
760 if (!(layers1.size() == layers2.size())) {
763 boolean overallLayerEquality = true;
764 for (BlueprintLayer blulayer1 : layers1) {
765 boolean layerEquality = false;
766 for (BlueprintLayer blulayer2 : layers2) {
767 if (blulayer1.getLayer().equals(blulayer2.getLayer())) {
768 layerEquality = true;
771 if (!layerEquality) {
772 overallLayerEquality = false;
776 if (!overallLayerEquality) {
780 if (!compareBlueprints(inst1.getBlueprint(), inst2.getBlueprint())) {
786 private boolean compareTimeslots(Timeslot timeslot1, Timeslot timeslot2) {
787 if (!timeslot1.getStartDateTime().equals(timeslot2.getStartDateTime())
788 || timeslot1.getTimeslotId() != timeslot2.getTimeslotId()) {
791 if (!compareLabInfos(timeslot1.getLabInfo(), timeslot2.getLabInfo())) {
797 private boolean compareBlueprints(Blueprint blueprint1, Blueprint blueprint2) {
798 if (blueprint1 != null || blueprint2 != null) {
799 if (blueprint1 != null && blueprint2 == null) {
802 if (blueprint1 == null && blueprint2 != null) {
805 if (blueprint1.getBlueprintId() != blueprint2.getBlueprintId()) {
808 if (!blueprint1.getBlueprintName().equals(blueprint2.getBlueprintName())) {
815 private boolean compareLabInfos(LabInfo labInfo1, LabInfo labInfo2) {
816 if (labInfo1 != null || labInfo2 != null) {
817 if (labInfo1 != null && labInfo2 == null) {
820 if (labInfo1 == null && labInfo2 != null) {
823 if (labInfo1.getLabId() != labInfo2.getLabId()) {
826 if (!labInfo1.getSilo().equals(labInfo2.getSilo())) {
829 if (!labInfo1.getLab().equals(labInfo2.getLab())) {