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 DbAdapter dbAdapter;
51 private IntegratedResultService iService;
54 private ValidationTestResultDAO vTestResultDAO;
56 public void handle(JnksJobNotify jnksJobNotify) throws Exception {
57 String jenkinsJobName = System.getenv("JENKINS_JOB_NAME");
58 if (!jenkinsJobName.equals(jnksJobNotify.getName())) {
61 Submission submission = submissionService.getSubmission(Integer.toString(jnksJobNotify.getSubmissionId()));
62 if (submission == null) {
63 LOGGER.debug(EELFLoggerDelegate.debugLogger, "No related submission was found");
66 LabInfo labInfo = dbAdapter.getLab(submission.getTimeslot().getLabInfo().getLab());
67 if (labInfo == null) {
68 throw new IllegalArgumentException(
69 "Could not retrieve lab : " + submission.getTimeslot().getLabInfo().getLab().toString());
71 LOGGER.info(EELFLoggerDelegate.applicationLogger,
72 "Updating submission with id: " + submission.getSubmissionId());
73 submission.setSubmissionStatus(SubmissionStatus.Completed);
74 submissionHelper.saveSubmission(submission);
75 ValidationDbTestResult vDbResult = vTestResultDAO.getValidationTestResult(submission);
77 if (vDbResult != null) {
78 // Fetch submission result from nexus
79 ValidationDbTestResult vNexusResult = iService.getResult(
80 vDbResult.getBlueprintInstance().getBlueprint().getBlueprintName(),
81 vDbResult.getBlueprintInstance().getVersion(), vDbResult.getLab().getLab(),
82 jnksJobNotify.getTimestamp());
83 if (vNexusResult != null) {
84 List<ValidationDbTestResult> vNexusResults = new ArrayList<ValidationDbTestResult>();
85 vNexusResults.add(vNexusResult);
86 dbAdapter.storeResultsInDb(vNexusResults);
89 } catch (HttpException ex) {
90 LOGGER.error(EELFLoggerDelegate.errorLogger,
91 "Error when retrieving Nexus results. " + UserUtils.getStackTrace(ex));
93 dbAdapter.updateTimestamp(jnksJobNotify);