Search in sources :

Example 1 with DetectRunInfo

use of com.synopsys.detect.doctor.diagnosticparser.DetectRunInfo in project hub-detect by blackducksoftware.

the class DoctorApplication method run.

@Override
public void run(final ApplicationArguments applicationArguments) throws Exception {
    PropertyMap<DoctorProperty> doctorPropertyPropertyMap = new PropertyMap<>();
    SpringPropertySource springPropertySource = new SpringPropertySource(configurableEnvironment);
    DoctorConfiguration doctorConfiguration = new DoctorConfiguration(springPropertySource, doctorPropertyPropertyMap);
    DoctorArgumentStateParser argumentStateParser = new DoctorArgumentStateParser();
    DoctorArgumentState state = argumentStateParser.parseArgs(applicationArguments.getSourceArgs());
    doctorConfiguration.init();
    DoctorRun doctorRun = DoctorRun.createDefault();
    logger.info("Doctor begin: " + doctorRun.getRunId());
    DoctorDirectoryManager doctorDirectoryManager = new DoctorDirectoryManager(doctorRun);
    logger.info("Doctor ready.");
    Optional<DetectRunInfo> detectRunInfo = Optional.empty();
    File diagnosticZip = new File(doctorConfiguration.getProperty(DoctorProperty.DETECT_DIAGNOSTIC_FILE));
    if (diagnosticZip.exists()) {
        logger.info("A diagnostic zip was found: " + diagnosticZip.getAbsolutePath());
        DiagnosticParser diagnosticParser = new DiagnosticParser();
        detectRunInfo = Optional.of(diagnosticParser.processDiagnosticZip(doctorDirectoryManager, diagnosticZip));
    } else {
        logger.info("No diagnostic zip provided, looking for the pieces.");
        File log = new File(doctorConfiguration.getProperty(DoctorProperty.DETECT_LOG_FILE));
        logger.info("Looking for log file at: " + log.getAbsolutePath());
        if (log.exists()) {
            logger.info("Found log file.");
        // detectRunInfo = Optional.of(new DetectRunInfo(log));
        } else {
            logger.info("No log file found.");
        }
    }
    if (detectRunInfo.isPresent()) {
        DetectLogParser logParser = new DetectLogParser();
        logger.info("Doctor can proceed, necessary pieces located.");
        File log = detectRunInfo.get().getLogFile();
        DetectLogParseResult result = logParser.parse(log);
        logger.info("Detect log parsed.");
        String extractionId = doctorConfiguration.getProperty(DoctorProperty.DETECT_EXTRACTION_ID);
        Set<String> extractions = new HashSet<>();
        LoggedDetectExtraction extraction = null;
        for (LoggedDetectExtraction possibleExtraction : result.loggedConfiguration.extractions) {
            extractions.add(possibleExtraction.extractionIdentifier);
            if (possibleExtraction.extractionIdentifier.equals(extractionId)) {
                extraction = possibleExtraction;
            }
        }
        if (StringUtils.isBlank(extractionId)) {
            quit("Doctor needs an extraction to work with, options are: " + extractions.stream().collect(Collectors.joining(",")));
        }
        if (extraction == null) {
            quit("No extraction found for given id: " + extractionId);
        }
        logger.info("Found extraction with id: " + extractionId);
        logger.info("Doctor will attempt to diagnose!");
        logger.info("We begin by rebuilding the configuration.");
        Map<String, String> propertyMap = new HashMap<>();
        result.loggedConfiguration.loggedPropertyList.stream().forEach(it -> propertyMap.put(it.key, it.value));
        RehydratedPropertySource rehydratedPropertySource = new RehydratedPropertySource(propertyMap);
        DetectConfiguration detectConfiguration = new DetectConfiguration(new DetectPropertySource(rehydratedPropertySource), new DetectPropertyMap());
        ExtractionHandler extractionHandler = new ExtractionHandler();
        extractionHandler.processExtraction(extraction, detectRunInfo.get(), detectConfiguration);
    } else {
        quit("Neccessary pieces not found for doctor to proceed.");
    }
}
Also used : DetectRunInfo(com.synopsys.detect.doctor.diagnosticparser.DetectRunInfo) HashMap(java.util.HashMap) SpringPropertySource(com.blackducksoftware.integration.hub.detect.property.SpringPropertySource) DoctorDirectoryManager(com.synopsys.detect.doctor.run.DoctorDirectoryManager) DoctorRun(com.synopsys.detect.doctor.run.DoctorRun) DetectLogParseResult(com.synopsys.detect.doctor.logparser.DetectLogParseResult) DetectPropertyMap(com.blackducksoftware.integration.hub.detect.configuration.DetectPropertyMap) DetectPropertySource(com.blackducksoftware.integration.hub.detect.configuration.DetectPropertySource) DetectLogParser(com.synopsys.detect.doctor.logparser.DetectLogParser) DoctorArgumentState(com.synopsys.detect.doctor.configuration.DoctorArgumentState) HashSet(java.util.HashSet) ExtractionHandler(com.synopsys.detect.doctor.extraction.ExtractionHandler) LoggedDetectExtraction(com.synopsys.detect.doctor.logparser.LoggedDetectExtraction) DoctorConfiguration(com.synopsys.detect.doctor.configuration.DoctorConfiguration) DetectConfiguration(com.blackducksoftware.integration.hub.detect.configuration.DetectConfiguration) DoctorProperty(com.synopsys.detect.doctor.configuration.DoctorProperty) PropertyMap(com.blackducksoftware.integration.hub.detect.property.PropertyMap) DetectPropertyMap(com.blackducksoftware.integration.hub.detect.configuration.DetectPropertyMap) DiagnosticParser(com.synopsys.detect.doctor.diagnosticparser.DiagnosticParser) File(java.io.File) DoctorArgumentStateParser(com.synopsys.detect.doctor.configuration.DoctorArgumentStateParser)

Aggregations

DetectConfiguration (com.blackducksoftware.integration.hub.detect.configuration.DetectConfiguration)1 DetectPropertyMap (com.blackducksoftware.integration.hub.detect.configuration.DetectPropertyMap)1 DetectPropertySource (com.blackducksoftware.integration.hub.detect.configuration.DetectPropertySource)1 PropertyMap (com.blackducksoftware.integration.hub.detect.property.PropertyMap)1 SpringPropertySource (com.blackducksoftware.integration.hub.detect.property.SpringPropertySource)1 DoctorArgumentState (com.synopsys.detect.doctor.configuration.DoctorArgumentState)1 DoctorArgumentStateParser (com.synopsys.detect.doctor.configuration.DoctorArgumentStateParser)1 DoctorConfiguration (com.synopsys.detect.doctor.configuration.DoctorConfiguration)1 DoctorProperty (com.synopsys.detect.doctor.configuration.DoctorProperty)1 DetectRunInfo (com.synopsys.detect.doctor.diagnosticparser.DetectRunInfo)1 DiagnosticParser (com.synopsys.detect.doctor.diagnosticparser.DiagnosticParser)1 ExtractionHandler (com.synopsys.detect.doctor.extraction.ExtractionHandler)1 DetectLogParseResult (com.synopsys.detect.doctor.logparser.DetectLogParseResult)1 DetectLogParser (com.synopsys.detect.doctor.logparser.DetectLogParser)1 LoggedDetectExtraction (com.synopsys.detect.doctor.logparser.LoggedDetectExtraction)1 DoctorDirectoryManager (com.synopsys.detect.doctor.run.DoctorDirectoryManager)1 DoctorRun (com.synopsys.detect.doctor.run.DoctorRun)1 File (java.io.File)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1