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.
16 package org.akraino.validation.ui.service;
18 import java.util.ArrayList;
19 import java.util.List;
21 import org.akraino.validation.ui.dao.ValidationTestResultDAO;
22 import org.akraino.validation.ui.data.JnksJobNotify;
23 import org.akraino.validation.ui.data.SubmissionStatus;
24 import org.akraino.validation.ui.entity.LabInfo;
25 import org.akraino.validation.ui.entity.Submission;
26 import org.akraino.validation.ui.entity.ValidationDbTestResult;
27 import org.akraino.validation.ui.service.utils.SubmissionHelper;
28 import org.apache.commons.httpclient.HttpException;
29 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
30 import org.onap.portalsdk.core.web.support.UserUtils;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.stereotype.Service;
33 import org.springframework.transaction.annotation.Transactional;
37 public class JenkinsJobNotificationService {
39 private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(JenkinsJobNotificationService.class);
42 private SubmissionHelper submissionHelper;
45 private DbSubmissionAdapter submissionService;
48 private DbResultAdapter dbAdapter;
51 private IntegratedResultService iService;
54 private LabService labService;
57 private ValidationTestResultDAO vTestResultDAO;
59 public void handle(JnksJobNotify jnksJobNotify) throws Exception {
60 String jenkinsJobName = System.getenv("JENKINS_JOB_NAME");
61 if (!jenkinsJobName.equals(jnksJobNotify.getName())) {
64 Submission submission = submissionService.getSubmission(Integer.toString(jnksJobNotify.getSubmissionId()));
65 if (submission == null) {
66 LOGGER.debug(EELFLoggerDelegate.debugLogger, "No related submission was found");
69 LabInfo labInfo = labService.getLab(submission.getTimeslot().getLabInfo().getLab());
70 if (labInfo == null) {
71 throw new IllegalArgumentException(
72 "Could not retrieve lab : " + submission.getTimeslot().getLabInfo().getLab().toString());
74 LOGGER.info(EELFLoggerDelegate.applicationLogger,
75 "Updating submission with id: " + submission.getSubmissionId());
76 submission.setSubmissionStatus(SubmissionStatus.Completed);
77 submissionHelper.saveSubmission(submission);
78 ValidationDbTestResult vDbResult = vTestResultDAO.getValidationTestResult(submission);
80 if (vDbResult != null) {
81 // Fetch submission result from nexus
82 ValidationDbTestResult vNexusResult = iService.getResult(
83 vDbResult.getBlueprintInstance().getBlueprint().getBlueprintName(),
84 vDbResult.getBlueprintInstance().getVersion(), vDbResult.getLab().getLab(),
85 jnksJobNotify.getTimestamp());
86 if (vNexusResult != null) {
87 List<ValidationDbTestResult> vNexusResults = new ArrayList<ValidationDbTestResult>();
88 vNexusResults.add(vNexusResult);
89 dbAdapter.storeResultsInDb(vNexusResults);
92 } catch (HttpException ex) {
93 LOGGER.error(EELFLoggerDelegate.errorLogger,
94 "Error when retrieving Nexus results. " + UserUtils.getStackTrace(ex));
96 dbAdapter.updateTimestamp(jnksJobNotify);