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 org.akraino.validation.ui.conf.UiUtils;
19 import org.akraino.validation.ui.data.BlueprintLayer;
20 import org.akraino.validation.ui.data.JnksJobNotify;
21 import org.akraino.validation.ui.data.SubmissionStatus;
22 import org.akraino.validation.ui.entity.LabSilo;
23 import org.akraino.validation.ui.entity.Submission;
24 import org.akraino.validation.ui.service.utils.SubmissionHelper;
25 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
26 import org.springframework.beans.factory.annotation.Autowired;
27 import org.springframework.stereotype.Service;
28 import org.springframework.transaction.annotation.Transactional;
32 public class JenkinsJobNotificationService {
34 private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(JenkinsJobNotificationService.class);
37 private SubmissionHelper submissionHelper;
40 private SubmissionService submissionService;
43 private SiloService siloService;
45 public void handle(JnksJobNotify jnksJobNotify) throws Exception {
46 String jenkinsJobName = System.getenv("JENKINS_JOB_NAME");
47 if (!jenkinsJobName.equals(jnksJobNotify.getName())) {
50 Submission submission = submissionService.getSubmission(Integer.toString(jnksJobNotify.getSubmissionId()));
51 if (submission == null) {
52 LOGGER.debug(EELFLoggerDelegate.debugLogger, "No related submission was found");
55 String siloText = null;
56 for (LabSilo silo : siloService.getSilos()) {
57 if (silo.getLab().getLab().equals(submission.getTimeslot().getLab().getLab())) {
58 siloText = silo.getSilo();
61 if (siloText == null) {
62 throw new Exception("Could not retrieve silo of the selected lab : "
63 + submission.getTimeslot().getLab().getLab().toString());
66 String nexusUrl = UiUtils.NEXUS_URL + "/" + siloText + "/job/" + System.getenv("JENKINS_JOB_NAME") + "/"
67 + String.valueOf(jnksJobNotify.getbuildNumber() + "/results");
68 if (!submission.getBlueprintInstanceForValidation().getLayer().equals(BlueprintLayer.All)) {
69 nexusUrl = nexusUrl + "/" + submission.getBlueprintInstanceForValidation().getLayer().name().toLowerCase();
71 submission.setNexusResultUrl(nexusUrl);
72 LOGGER.info(EELFLoggerDelegate.applicationLogger,
73 "Updating submission with id: " + submission.getSubmissionId());
74 submission.setSubmissionStatus(SubmissionStatus.Completed);
75 submissionHelper.saveSubmission(submission);