X-Git-Url: https://gerrit.akraino.org/r/gitweb?p=validation.git;a=blobdiff_plain;f=ui%2Fsrc%2Fmain%2Fjava%2Forg%2Fakraino%2Fvalidation%2Fui%2Fconf%2FValidationNexusTestResultsGetter.java;fp=ui%2Fsrc%2Fmain%2Fjava%2Forg%2Fakraino%2Fvalidation%2Fui%2Fconf%2FValidationNexusTestResultsGetter.java;h=769549a17711891a09686291948b8ecf3f3ab488;hp=0000000000000000000000000000000000000000;hb=2eba847ebb6acb2686be08eb1cdafc1b12071e7d;hpb=f86b9715d156238532fcb0bf464bd72e9cf7ce96 diff --git a/ui/src/main/java/org/akraino/validation/ui/conf/ValidationNexusTestResultsGetter.java b/ui/src/main/java/org/akraino/validation/ui/conf/ValidationNexusTestResultsGetter.java new file mode 100644 index 0000000..769549a --- /dev/null +++ b/ui/src/main/java/org/akraino/validation/ui/conf/ValidationNexusTestResultsGetter.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ +package org.akraino.validation.ui.conf; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutorService; + +import org.akraino.validation.ui.client.nexus.resources.ValidationNexusTestResult; +import org.akraino.validation.ui.data.Lab; +import org.akraino.validation.ui.service.DbResultAdapter; +import org.akraino.validation.ui.service.IntegratedResultService; +import org.akraino.validation.ui.service.utils.PrioritySupplier; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.portalsdk.core.onboarding.util.PortalApiProperties; +import org.onap.portalsdk.core.web.support.UserUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationListener; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.event.ContextRefreshedEvent; +import org.springframework.stereotype.Component; + +@Component +public class ValidationNexusTestResultsGetter implements ApplicationListener { + + private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate + .getLogger(ValidationNexusTestResultsGetter.class); + + @Autowired + IntegratedResultService integratedService; + + @Autowired + DbResultAdapter dbAdapter; + + @Override + public void onApplicationEvent(final ContextRefreshedEvent event) { + ApplicationContext context = new AnnotationConfigApplicationContext(ExecutorServiceInitializer.class); + ExecutorService service = (ExecutorService) context.getBean("executorService"); + ValidationNexusTestResultsGetterExecution task = new ValidationNexusTestResultsGetterExecution(); + CompletableFuture>> completableFuture = CompletableFuture + .supplyAsync(new PrioritySupplier<>(1, task::execute), service); + completableFuture.thenAcceptAsync(results -> this.callbackNotify(results)); + } + + private void callbackNotify(List> results) { + try { + for (List result : results) { + + LOGGER.debug(EELFLoggerDelegate.debugLogger, + "Validation test results retrieved from nexus with size : " + result.size()); + dbAdapter.deleteUnreferencedEntries(result); + dbAdapter.storeResultInDb(result); + } + Thread.sleep(Integer.valueOf(PortalApiProperties.getProperty("thread_sleep"))); + } catch (Exception e) { + LOGGER.error(EELFLoggerDelegate.errorLogger, + "Error in callback notification. " + UserUtils.getStackTrace(e)); + } + // Trigger the next retrieval of results + ApplicationContext context = new AnnotationConfigApplicationContext(ExecutorServiceInitializer.class); + ExecutorService service = (ExecutorService) context.getBean("executorService"); + ValidationNexusTestResultsGetterExecution task = new ValidationNexusTestResultsGetterExecution(); + CompletableFuture>> completableFuture = CompletableFuture + .supplyAsync(new PrioritySupplier<>(1, task::execute), service); + completableFuture.thenAcceptAsync(newResults -> this.callbackNotify(newResults)); + } + + private class ValidationNexusTestResultsGetterExecution { + + public ValidationNexusTestResultsGetterExecution() { + } + + public List> execute() { + List> results = new ArrayList>(); + try { + for (Lab lab : integratedService.getLabsFromNexus()) { + for (String blueprintName : integratedService.getBlueprintNamesOfLabFromNexus(lab)) { + for (String version : integratedService.getBlueprintVersionsFromNexus(blueprintName, lab)) { + LOGGER.debug(EELFLoggerDelegate.debugLogger, + "Trying to retrieve validation test result from nexus for: blueprint name: " + + blueprintName + ", version: " + version + " and lab: " + lab.name()); + results.add(integratedService.getResultsFromNexus(blueprintName, version, lab, + Integer.valueOf(PortalApiProperties.getProperty("no_last_timestamps")))); + } + } + } + } catch (Exception e) { + LOGGER.error(EELFLoggerDelegate.errorLogger, + "Error when retrieving Nexus results. " + UserUtils.getStackTrace(e)); + } + return results; + } + } + +}