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.conf;
18 import java.util.ArrayList;
19 import java.util.List;
20 import java.util.concurrent.CompletableFuture;
21 import java.util.concurrent.ExecutorService;
23 import org.akraino.validation.ui.client.nexus.resources.ValidationNexusTestResult;
24 import org.akraino.validation.ui.data.Lab;
25 import org.akraino.validation.ui.service.DbResultAdapter;
26 import org.akraino.validation.ui.service.IntegratedResultService;
27 import org.akraino.validation.ui.service.utils.PrioritySupplier;
28 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
29 import org.onap.portalsdk.core.onboarding.util.PortalApiProperties;
30 import org.onap.portalsdk.core.web.support.UserUtils;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.context.ApplicationContext;
33 import org.springframework.context.ApplicationListener;
34 import org.springframework.context.annotation.AnnotationConfigApplicationContext;
35 import org.springframework.context.event.ContextRefreshedEvent;
36 import org.springframework.stereotype.Component;
39 public class ValidationNexusTestResultsGetter implements ApplicationListener<ContextRefreshedEvent> {
41 private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate
42 .getLogger(ValidationNexusTestResultsGetter.class);
45 IntegratedResultService integratedService;
48 DbResultAdapter dbAdapter;
51 public void onApplicationEvent(final ContextRefreshedEvent event) {
52 ApplicationContext context = new AnnotationConfigApplicationContext(ExecutorServiceInitializer.class);
53 ExecutorService service = (ExecutorService) context.getBean("executorService");
54 ValidationNexusTestResultsGetterExecution task = new ValidationNexusTestResultsGetterExecution();
55 CompletableFuture<List<List<ValidationNexusTestResult>>> completableFuture = CompletableFuture
56 .supplyAsync(new PrioritySupplier<>(1, task::execute), service);
57 completableFuture.thenAcceptAsync(results -> this.callbackNotify(results));
60 private void callbackNotify(List<List<ValidationNexusTestResult>> results) {
62 for (List<ValidationNexusTestResult> result : results) {
64 LOGGER.debug(EELFLoggerDelegate.debugLogger,
65 "Validation test results retrieved from nexus with size : " + result.size());
66 dbAdapter.deleteUnreferencedEntries(result);
67 dbAdapter.storeResultInDb(result);
69 Thread.sleep(Integer.valueOf(PortalApiProperties.getProperty("thread_sleep")));
70 } catch (Exception e) {
71 LOGGER.error(EELFLoggerDelegate.errorLogger,
72 "Error in callback notification. " + UserUtils.getStackTrace(e));
74 // Trigger the next retrieval of results
75 ApplicationContext context = new AnnotationConfigApplicationContext(ExecutorServiceInitializer.class);
76 ExecutorService service = (ExecutorService) context.getBean("executorService");
77 ValidationNexusTestResultsGetterExecution task = new ValidationNexusTestResultsGetterExecution();
78 CompletableFuture<List<List<ValidationNexusTestResult>>> completableFuture = CompletableFuture
79 .supplyAsync(new PrioritySupplier<>(1, task::execute), service);
80 completableFuture.thenAcceptAsync(newResults -> this.callbackNotify(newResults));
83 private class ValidationNexusTestResultsGetterExecution {
85 public ValidationNexusTestResultsGetterExecution() {
88 public List<List<ValidationNexusTestResult>> execute() {
89 List<List<ValidationNexusTestResult>> results = new ArrayList<List<ValidationNexusTestResult>>();
91 for (Lab lab : integratedService.getLabsFromNexus()) {
92 for (String blueprintName : integratedService.getBlueprintNamesOfLabFromNexus(lab)) {
93 for (String version : integratedService.getBlueprintVersionsFromNexus(blueprintName, lab)) {
94 LOGGER.debug(EELFLoggerDelegate.debugLogger,
95 "Trying to retrieve validation test result from nexus for: blueprint name: "
96 + blueprintName + ", version: " + version + " and lab: " + lab.name());
97 results.add(integratedService.getResultsFromNexus(blueprintName, version, lab,
98 Integer.valueOf(PortalApiProperties.getProperty("no_last_timestamps"))));
102 } catch (Exception e) {
103 LOGGER.error(EELFLoggerDelegate.errorLogger,
104 "Error when retrieving Nexus results. " + UserUtils.getStackTrace(e));