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.io.IOException;
19 import java.net.MalformedURLException;
21 import java.security.KeyManagementException;
22 import java.security.NoSuchAlgorithmException;
23 import java.util.List;
25 import org.akraino.validation.ui.client.jenkins.JenkinsExecutorClient;
26 import org.akraino.validation.ui.client.jenkins.resources.QueueJobItem;
27 import org.akraino.validation.ui.client.jenkins.resources.QueueJobItem.Executable;
28 import org.akraino.validation.ui.client.nexus.NexusExecutorClient;
29 import org.akraino.validation.ui.client.nexus.resources.RobotTestResult;
30 import org.akraino.validation.ui.entity.Submission;
31 import org.apache.commons.httpclient.HttpException;
32 import org.apache.log4j.Logger;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.stereotype.Service;
36 import com.fasterxml.jackson.core.JsonParseException;
37 import com.fasterxml.jackson.databind.JsonMappingException;
38 import com.sun.jersey.api.client.ClientHandlerException;
39 import com.sun.jersey.api.client.UniformInterfaceException;
42 public class ResultService {
44 private static final Logger LOGGER = Logger.getLogger(ResultService.class);
47 private SubmissionService submissionService;
50 public URL getNexusResultUrl(Submission submission)
51 throws MalformedURLException, KeyManagementException, HttpException, ClientHandlerException,
52 UniformInterfaceException, NoSuchAlgorithmException, InterruptedException {
54 String url = System.getenv("jenkins_url");
55 String userName = System.getenv("jenkins_user_name");
56 String password = System.getenv("jenkins_user_pwd");
58 Executable executable = null;
59 while (executable == null) {
60 JenkinsExecutorClient client;
61 client = JenkinsExecutorClient.getInstance(userName, password, url);
62 QueueJobItem queueJobItem = client.getQueueJobItem(new URL(submission.getJenkinsQueueJobItemUrl()));
63 executable = queueJobItem.getExecutable();
66 return new URL(System.getenv("nexus_results_url") + "/"
67 + submission.getBlueprintInstance().getTimeslot().getLab().name().toLowerCase() + "-blu-val"
68 + "/job/validation/" + String.valueOf(executable.getNumber()));
71 public List<RobotTestResult> getRobotTestResults(String submissionId)
72 throws JsonParseException, JsonMappingException, KeyManagementException, ClientHandlerException,
73 UniformInterfaceException, NoSuchAlgorithmException, IOException {
74 Submission submission = submissionService.getSubmission(submissionId);
75 if (submission == null) {
76 LOGGER.info("Requested submission does not exist");
79 String nexusUrl = submission.getNexusResultUrl();
80 NexusExecutorClient client = new NexusExecutorClient(nexusUrl + "/results");
81 return client.getRobotTestResults();