import javax.annotation.Nonnull;
+import org.akraino.validation.ui.dao.BlueprintDAO;
+import org.akraino.validation.ui.dao.BlueprintInstanceDAO;
+import org.akraino.validation.ui.dao.BlueprintLayerDAO;
+import org.akraino.validation.ui.dao.LabDAO;
+import org.akraino.validation.ui.dao.TimeslotDAO;
import org.akraino.validation.ui.dao.ValidationTestResultDAO;
import org.akraino.validation.ui.dao.WRobotTestResultDAO;
import org.akraino.validation.ui.data.JnksJobNotify;
import org.akraino.validation.ui.entity.BlueprintLayer;
import org.akraino.validation.ui.entity.LabInfo;
import org.akraino.validation.ui.entity.Submission;
+import org.akraino.validation.ui.entity.Timeslot;
import org.akraino.validation.ui.entity.ValidationDbTestResult;
import org.akraino.validation.ui.entity.WRobotDbTestResult;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
@Service
@Transactional
-public class DbResultAdapter {
+public class DbAdapter {
- private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(DbResultAdapter.class);
+ private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(DbAdapter.class);
private static final Object LOCK = new Object();
- @Autowired
- LabService labService;
-
@Autowired
private ValidationTestResultDAO vTestResultDAO;
private WRobotTestResultDAO wRobotDAO;
@Autowired
- DbSubmissionAdapter subService;
+ private LabDAO labDAO;
+
+ @Autowired
+ private BlueprintLayerDAO layerDAO;
@Autowired
- BlueprintService blueprintService;
+ private BlueprintInstanceDAO bluInstDao;
@Autowired
- BlueprintInstanceService blueprintInstService;
+ private BlueprintDAO blueprintDAO;
@Autowired
- BlueprintLayerService layerService;
+ private TimeslotDAO timeslotDAO;
+
+ @Autowired
+ DbSubmissionAdapter subService;
public void associateSubmissionWithValidationResult(Submission submission)
throws JsonParseException, JsonMappingException, IOException {
synchronized (LOCK) {
if (!compareBluInstances(submission.getValidationDbTestResult().getBlueprintInstance(),
- blueprintInstService.getBlueprintInstance(
+ bluInstDao.getBlueprintInstance(
submission.getValidationDbTestResult().getBlueprintInstance().getBlueprintInstanceId()))) {
throw new RuntimeException("Blueprint instance data changed.");
}
+ if (!compareTimeslots(submission.getTimeslot(),
+ timeslotDAO.getTimeslot(submission.getTimeslot().getTimeslotId()))) {
+ throw new RuntimeException("Timeslot data changed.");
+ }
+
+ boolean canContinue = false;
+ for (Timeslot timeslot : bluInstDao
+ .getBlueprintInstance(
+ submission.getValidationDbTestResult().getBlueprintInstance().getBlueprintInstanceId())
+ .getTimeslots()) {
+ if (compareTimeslots(timeslot, submission.getTimeslot())) {
+ canContinue = true;
+ break;
+ }
+ }
+ if (!canContinue) {
+ throw new RuntimeException("Configured timeslot is no longer assigned to the blueprint instance.");
+ }
submission.getValidationDbTestResult().setSubmission(submission);
vTestResultDAO.saveOrUpdate(submission.getValidationDbTestResult());
if (submission.getValidationDbTestResult().getWRobotDbTestResults() != null) {
if (!checkValidityOfNexusResult(vNexusResult)) {
continue;
}
- LabInfo labInfo = labService.getLabBasedOnSilo(vNexusResult.getLab().getSilo());
+ LabInfo labInfo = labDAO.getLabBasedOnSilo(vNexusResult.getLab().getSilo());
ValidationDbTestResult vDbResult = vTestResultDAO.getValidationTestResult(labInfo,
vNexusResult.getTimestamp());
if (vDbResult == null) {
vDbResult = vNexusResult;
vDbResult.setLab(labInfo);
- Blueprint blueprint = blueprintService
+ Blueprint blueprint = blueprintDAO
.getBlueprint(vNexusResult.getBlueprintInstance().getBlueprint().getBlueprintName());
if (blueprint == null) {
blueprint = vNexusResult.getBlueprintInstance().getBlueprint();
- blueprintService.saveBlueprint(blueprint);
+ blueprintDAO.saveOrUpdate(blueprint);
}
- BlueprintInstance blueprintInst = blueprintInstService.getBlueprintInstance(blueprint,
+ BlueprintInstance blueprintInst = bluInstDao.getBlueprintInstance(blueprint,
(vNexusResult.getBlueprintInstance().getVersion()));
if (blueprintInst == null) {
blueprintInst = vNexusResult.getBlueprintInstance();
blueprintInst.setBlueprint(blueprint);
- blueprintInstService.saveBlueprintInstance(blueprintInst);
+ bluInstDao.saveOrUpdate(blueprintInst);
}
vDbResult.setBlueprintInstance(blueprintInst);
}
synchronized (LOCK) {
LabInfo actualLabInfo = null;
if (lab != null) {
- actualLabInfo = labService.getLab(lab);
+ actualLabInfo = labDAO.getLab(lab);
if (actualLabInfo == null) {
return null;
}
}
Blueprint blueprint = null;
if (blueprintName != null) {
- blueprint = blueprintService.getBlueprint(blueprintName);
+ blueprint = blueprintDAO.getBlueprint(blueprintName);
if (blueprint == null) {
return null;
}
}
- BlueprintInstance blueprintInst = blueprintInstService.getBlueprintInstance(blueprint, version);
+ BlueprintInstance blueprintInst = bluInstDao.getBlueprintInstance(blueprint, version);
if (blueprintInst == null) {
return null;
}
public ValidationDbTestResult readResultFromDb(@Nonnull String lab, @Nonnull String timestamp)
throws JsonParseException, JsonMappingException, IOException {
synchronized (LOCK) {
- LabInfo actualLabInfo = labService.getLab(lab);
+ LabInfo actualLabInfo = labDAO.getLab(lab);
ValidationDbTestResult vDbResult = vTestResultDAO.getValidationTestResult(actualLabInfo, timestamp);
if (vDbResult == null) {
return null;
if (vNexusResults == null || vNexusResults.size() < 1) {
return;
}
- LabInfo labInfo = labService.getLabBasedOnSilo(vNexusResults.get(0).getLab().getSilo());
+ LabInfo labInfo = labDAO.getLabBasedOnSilo(vNexusResults.get(0).getLab().getSilo());
if (labInfo == null) {
return;
}
- Blueprint blueprint = blueprintService
+ Blueprint blueprint = blueprintDAO
.getBlueprint(vNexusResults.get(0).getBlueprintInstance().getBlueprint().getBlueprintName());
if (blueprint == null) {
return;
}
- BlueprintInstance blueInst = blueprintInstService.getBlueprintInstance(blueprint,
+ BlueprintInstance blueInst = bluInstDao.getBlueprintInstance(blueprint,
vNexusResults.get(0).getBlueprintInstance().getVersion());
if (blueInst == null) {
return;
String dbTimestamp = vDbResult.getTimestamp();
LabInfo dbLabInfo = vDbResult.getLab();
for (ValidationDbTestResult vNexusResult : vNexusResults) {
- LabInfo nexusLabInfo = labService.getLabBasedOnSilo(vNexusResult.getLab().getSilo());
+ LabInfo nexusLabInfo = labDAO.getLabBasedOnSilo(vNexusResult.getLab().getSilo());
if (nexusLabInfo == null) {
continue;
}
synchronized (LOCK) {
Blueprint blueprint = null;
if (blueprintName != null) {
- blueprint = blueprintService.getBlueprint(blueprintName);
+ blueprint = blueprintDAO.getBlueprint(blueprintName);
if (blueprint == null) {
return null;
}
}
- BlueprintInstance bluInst = blueprintInstService.getBlueprintInstance(blueprint, version);
+ BlueprintInstance bluInst = bluInstDao.getBlueprintInstance(blueprint, version);
if (bluInst == null) {
return null;
}
public ValidationDbTestResult getValidationTestResult(String labSilo, String timestamp) {
synchronized (LOCK) {
- return vTestResultDAO.getValidationTestResult(labService.getLabBasedOnSilo(labSilo), timestamp);
+ return vTestResultDAO.getValidationTestResult(labDAO.getLabBasedOnSilo(labSilo), timestamp);
}
}
}
}
+ public void saveLab(LabInfo lab) {
+ synchronized (LOCK) {
+ labDAO.saveOrUpdate(lab);
+ }
+ }
+
+ public void deleteLab(LabInfo lab) {
+ synchronized (LOCK) {
+ labDAO.deleteLab(lab);
+ }
+ }
+
+ public LabInfo getLab(String lab) {
+ synchronized (LOCK) {
+ return labDAO.getLab(lab);
+ }
+ }
+
+ public LabInfo getLabBasedOnSilo(String silo) {
+ synchronized (LOCK) {
+ return labDAO.getLabBasedOnSilo(silo);
+ }
+ }
+
+ public List<LabInfo> getLabs() {
+ synchronized (LOCK) {
+ return labDAO.getLabs();
+ }
+ }
+
+ public void deleteLabAll() {
+ synchronized (LOCK) {
+ labDAO.deleteAll();
+ }
+ }
+
+ public void saveBlueprintInstance(BlueprintInstance blueprintIns) {
+ synchronized (LOCK) {
+ Set<Timeslot> timeslots = blueprintIns.getTimeslots();
+ if (timeslots != null && timeslots.size() > 1) {
+ for (Timeslot timeslot : timeslots) {
+ if (!compareTimeslots(timeslot, timeslotDAO.getTimeslot(timeslot.getTimeslotId()))) {
+ throw new RuntimeException("Timeslot instance data changed.");
+ }
+ }
+ bluInstDao.merge(blueprintIns);
+ return;
+ }
+ bluInstDao.saveOrUpdate(blueprintIns);
+ }
+ }
+
+ public List<BlueprintInstance> getBlueprintInstances() {
+ synchronized (LOCK) {
+ return bluInstDao.getBlueprintInstances();
+ }
+ }
+
+ public BlueprintInstance getBlueprintInstance(int instId) {
+ synchronized (LOCK) {
+ return bluInstDao.getBlueprintInstance(instId);
+ }
+ }
+
+ public BlueprintInstance getBlueprintInstance(Blueprint blueprint, String version) {
+ synchronized (LOCK) {
+ return bluInstDao.getBlueprintInstance(blueprint, version);
+ }
+ }
+
+ public void deleteBlueprintInstance(BlueprintInstance blueprintIns) {
+ synchronized (LOCK) {
+ bluInstDao.deleteBlueprintInstance(blueprintIns);
+ }
+ }
+
+ public void deleteBluInstAll() {
+ synchronized (LOCK) {
+ bluInstDao.deleteAll();
+ }
+ }
+
+ public void saveBlueprintLayer(BlueprintLayer layer) {
+ synchronized (LOCK) {
+ layerDAO.saveOrUpdate(layer);
+ }
+ }
+
+ public BlueprintLayer getBlueprintLayer(Integer layerId) {
+ synchronized (LOCK) {
+ return layerDAO.getBlueprintLayer(layerId);
+ }
+ }
+
+ public BlueprintLayer getBlueprintLayer(String layerData) {
+ synchronized (LOCK) {
+ return layerDAO.getBlueprintLayer(layerData);
+ }
+ }
+
+ public List<BlueprintLayer> getBlueprintLayers() {
+ synchronized (LOCK) {
+ return layerDAO.getBlueprintLayers();
+ }
+ }
+
+ public void deleteBlueprintLayer(BlueprintLayer layer) {
+ synchronized (LOCK) {
+ layerDAO.deleteBlueprintLayer(layer);
+ }
+ }
+
+ public void deleteBluLayersAll() {
+ synchronized (LOCK) {
+ layerDAO.deleteAll();
+ }
+ }
+
+ public void saveBlueprint(Blueprint blueprint) {
+ synchronized (LOCK) {
+ blueprintDAO.saveOrUpdate(blueprint);
+ }
+ }
+
+ public Blueprint getBlueprint(String name) {
+ synchronized (LOCK) {
+ return blueprintDAO.getBlueprint(name);
+ }
+ }
+
+ public List<Blueprint> getBlueprints() {
+ synchronized (LOCK) {
+ return blueprintDAO.getBlueprints();
+ }
+ }
+
+ public void deleteBlueprint(Blueprint blueprint) {
+ synchronized (LOCK) {
+ blueprintDAO.deleteBlueprint(blueprint);
+ }
+ }
+
+ public void deleteBluAll() {
+ synchronized (LOCK) {
+ blueprintDAO.deleteAll();
+ }
+ }
+
+ public void saveTimeslot(Timeslot timeslot) {
+ synchronized (LOCK) {
+ LabInfo labInfo = timeslot.getLabInfo();
+ if (labInfo != null) {
+ if (!compareLabInfos(labInfo, labDAO.getLab(labInfo.getLabId()))) {
+ throw new RuntimeException("Lab data changed.");
+ }
+ }
+ timeslotDAO.saveOrUpdate(timeslot);
+ }
+ }
+
+ public List<Timeslot> getTimeslots() {
+ synchronized (LOCK) {
+ return timeslotDAO.getTimeslots();
+ }
+ }
+
+ public void deleteTimeslot(Timeslot timeslot) {
+ synchronized (LOCK) {
+ timeslotDAO.deleteTimeslot(timeslot);
+ }
+ }
+
+ public void deleteTimeslotAll() {
+ synchronized (LOCK) {
+ timeslotDAO.deleteAll();
+ }
+ }
+
public boolean checkValidityOfNexusResult(ValidationDbTestResult vNexusResult) {
if (vNexusResult == null) {
return true;
}
- LabInfo labInfo = labService.getLabBasedOnSilo(vNexusResult.getLab().getSilo());
+ LabInfo labInfo = labDAO.getLabBasedOnSilo(vNexusResult.getLab().getSilo());
if (labInfo == null) {
throw new RuntimeException("Lab silo : " + vNexusResult.getLab().getSilo() + " not found");
}
ValidationDbTestResult vDbResult = vTestResultDAO.getValidationTestResult(
- labService.getLabBasedOnSilo(vNexusResult.getLab().getSilo()), vNexusResult.getTimestamp());
+ labDAO.getLabBasedOnSilo(vNexusResult.getLab().getSilo()), vNexusResult.getTimestamp());
Blueprint blueprint = null;
BlueprintInstance bluInst = null;
List<WRobotDbTestResult> wRobotDbResults = null;
labInfo = vDbResult.getLab();
wRobotDbResults = wRobotDAO.getWRobotTestResult(vDbResult);
} else {
- blueprint = blueprintService
+ blueprint = blueprintDAO
.getBlueprint(vNexusResult.getBlueprintInstance().getBlueprint().getBlueprintName());
}
if (blueprint != null) {
if (vDbResult != null) {
bluInst = vDbResult.getBlueprintInstance();
} else {
- bluInst = blueprintInstService.getBlueprintInstance(blueprint,
- vNexusResult.getBlueprintInstance().getVersion());
+ bluInst = bluInstDao.getBlueprintInstance(blueprint, vNexusResult.getBlueprintInstance().getVersion());
}
}
// Start comparison, be elastic with allLayers and optional
.equals(vDbTimestamp.getBlueprintInstance().getBlueprint().getBlueprintName())
|| !vDbSubmission.getBlueprintInstance().getVersion()
.equals(vDbTimestamp.getBlueprintInstance().getVersion())
- || !vDbSubmission.getLab().equals(vDbTimestamp.getLab())) {
+ || !compareLabInfos(vDbSubmission.getLab(), vDbTimestamp.getLab())) {
LOGGER.error(EELFLoggerDelegate.errorLogger, "No consistency exists in database records.");
return false;
}
}
private void updateBlueInstLayers(ValidationDbTestResult vNexusResult) {
- for (BlueprintInstance blueprintInst : blueprintInstService.getBlueprintInstances()) {
+ for (BlueprintInstance blueprintInst : bluInstDao.getBlueprintInstances()) {
if (!blueprintInst.getBlueprint().getBlueprintName()
.equals(vNexusResult.getBlueprintInstance().getBlueprint().getBlueprintName())) {
continue;
blueprintLayers = new HashSet<BlueprintLayer>();
}
for (WRobotDbTestResult nexusResult : vNexusResult.getWRobotDbTestResults()) {
- BlueprintLayer layer = layerService.getBlueprintLayer(nexusResult.getLayer());
+ BlueprintLayer layer = layerDAO.getBlueprintLayer(nexusResult.getLayer());
if (layer == null) {
layer = new BlueprintLayer();
layer.setLayer(nexusResult.getLayer());
- layerService.saveBlueprintLayer(layer);
+ layerDAO.saveOrUpdate(layer);
}
if (!blueprintLayers.contains(layer)) {
blueprintLayers.add(layer);
}
}
blueprintInst.setBlueprintLayers(blueprintLayers);
- blueprintInstService.saveBlueprintInstance(blueprintInst);
+ bluInstDao.saveOrUpdate(blueprintInst);
}
}
return false;
}
}
- Blueprint blueprint1 = inst1.getBlueprint();
- Blueprint blueprint2 = inst2.getBlueprint();
- if (blueprint1.getBlueprintId() != blueprint2.getBlueprintId()) {
+ if (!compareBlueprints(inst1.getBlueprint(), inst2.getBlueprint())) {
+ return false;
+ }
+ return true;
+ }
+
+ private boolean compareTimeslots(Timeslot timeslot1, Timeslot timeslot2) {
+ if (!timeslot1.getStartDateTime().equals(timeslot2.getStartDateTime())
+ || timeslot1.getTimeslotId() != timeslot2.getTimeslotId()) {
return false;
}
- if (!blueprint1.getBlueprintName().equals(blueprint2.getBlueprintName())) {
+ if (!compareLabInfos(timeslot1.getLabInfo(), timeslot2.getLabInfo())) {
return false;
}
return true;
}
+ private boolean compareBlueprints(Blueprint blueprint1, Blueprint blueprint2) {
+ if (blueprint1 != null || blueprint2 != null) {
+ if (blueprint1 != null && blueprint2 == null) {
+ return false;
+ }
+ if (blueprint1 == null && blueprint2 != null) {
+ return false;
+ }
+ if (blueprint1.getBlueprintId() != blueprint2.getBlueprintId()) {
+ return false;
+ }
+ if (!blueprint1.getBlueprintName().equals(blueprint2.getBlueprintName())) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private boolean compareLabInfos(LabInfo labInfo1, LabInfo labInfo2) {
+ if (labInfo1 != null || labInfo2 != null) {
+ if (labInfo1 != null && labInfo2 == null) {
+ return false;
+ }
+ if (labInfo1 == null && labInfo2 != null) {
+ return false;
+ }
+ if (labInfo1.getLabId() != labInfo2.getLabId()) {
+ return false;
+ }
+ if (!labInfo1.getSilo().equals(labInfo2.getSilo())) {
+ return false;
+ }
+ if (!labInfo1.getLab().equals(labInfo2.getLab())) {
+ return false;
+ }
+ }
+ return true;
+ }
+
}