Search in sources :

Example 1 with PhoneHomeManager

use of com.synopsys.integration.detect.workflow.phonehome.PhoneHomeManager in project synopsys-detect by blackducksoftware.

the class Application method run.

@Override
public void run(ApplicationArguments applicationArguments) {
    long startTime = System.currentTimeMillis();
    // Events, Status and Exit Codes are required even if boot fails.
    EventSystem eventSystem = new EventSystem();
    DetectStatusManager statusManager = new DetectStatusManager(eventSystem);
    ExceptionUtility exceptionUtility = new ExceptionUtility();
    ExitCodeManager exitCodeManager = new ExitCodeManager(eventSystem, exceptionUtility);
    ExitManager exitManager = new ExitManager(eventSystem, exitCodeManager, statusManager);
    ReportListener.createDefault(eventSystem);
    FormattedOutputManager formattedOutputManager = new FormattedOutputManager(eventSystem);
    InstalledToolManager installedToolManager = new InstalledToolManager();
    // Before boot even begins, we create a new Spring context for Detect to work within.
    logger.debug("Initializing detect.");
    DetectRunId detectRunId = DetectRunId.createDefault();
    Gson gson = BlackDuckServicesFactory.createDefaultGsonBuilder().setPrettyPrinting().create();
    DetectInfo detectInfo = DetectInfoUtility.createDefaultDetectInfo();
    FileFinder fileFinder = new SimpleFileFinder();
    boolean shouldForceSuccess = false;
    Optional<DetectBootResult> detectBootResultOptional = bootApplication(detectRunId, applicationArguments.getSourceArgs(), eventSystem, exitCodeManager, gson, detectInfo, fileFinder, installedToolManager, exceptionUtility);
    if (detectBootResultOptional.isPresent()) {
        DetectBootResult detectBootResult = detectBootResultOptional.get();
        shouldForceSuccess = detectBootResult.shouldForceSuccess();
        runApplication(eventSystem, exitCodeManager, detectBootResult, exceptionUtility);
        detectBootResult.getProductRunData().filter(ProductRunData::shouldUseBlackDuckProduct).map(ProductRunData::getBlackDuckRunData).flatMap(BlackDuckRunData::getPhoneHomeManager).ifPresent(PhoneHomeManager::phoneHomeOperations);
        // Create status output file.
        logger.info("");
        detectBootResult.getDirectoryManager().ifPresent(directoryManager -> createStatusOutputFile(formattedOutputManager, detectInfo, directoryManager));
        // Create installed tool data file.
        detectBootResult.getDirectoryManager().ifPresent(directoryManager -> createOrUpdateInstalledToolsFile(installedToolManager, directoryManager.getPermanentDirectory()));
        shutdownApplication(detectBootResult, exitCodeManager);
    } else {
        logger.info("Will not create status file, detect did not boot.");
    }
    logger.debug("All Detect actions completed.");
    exitApplication(exitManager, startTime, shouldForceSuccess);
}
Also used : ExitManager(com.synopsys.integration.detect.lifecycle.exit.ExitManager) DetectRunId(com.synopsys.integration.detect.workflow.DetectRunId) DetectInfo(com.synopsys.integration.detect.configuration.DetectInfo) Gson(com.google.gson.Gson) DetectBootResult(com.synopsys.integration.detect.lifecycle.boot.DetectBootResult) SimpleFileFinder(com.synopsys.integration.common.util.finder.SimpleFileFinder) FileFinder(com.synopsys.integration.common.util.finder.FileFinder) PhoneHomeManager(com.synopsys.integration.detect.workflow.phonehome.PhoneHomeManager) FormattedOutputManager(com.synopsys.integration.detect.workflow.report.output.FormattedOutputManager) ProductRunData(com.synopsys.integration.detect.lifecycle.run.data.ProductRunData) InstalledToolManager(com.synopsys.integration.detect.tool.cache.InstalledToolManager) SimpleFileFinder(com.synopsys.integration.common.util.finder.SimpleFileFinder) ExceptionUtility(com.synopsys.integration.detect.lifecycle.shutdown.ExceptionUtility) EventSystem(com.synopsys.integration.detect.workflow.event.EventSystem) DetectStatusManager(com.synopsys.integration.detect.workflow.status.DetectStatusManager) ExitCodeManager(com.synopsys.integration.detect.lifecycle.shutdown.ExitCodeManager)

Example 2 with PhoneHomeManager

use of com.synopsys.integration.detect.workflow.phonehome.PhoneHomeManager in project synopsys-detect by blackducksoftware.

the class ProductBoot method getBlackDuckRunData.

@Nullable
private BlackDuckRunData getBlackDuckRunData(BlackDuckDecision blackDuckDecision, ProductBootFactory productBootFactory, BlackDuckConnectivityChecker blackDuckConnectivityChecker, ProductBootOptions productBootOptions, AnalyticsConfigurationService analyticsConfigurationService) throws DetectUserFriendlyException {
    if (!blackDuckDecision.shouldRun()) {
        return null;
    }
    if (blackDuckDecision.isOffline()) {
        return BlackDuckRunData.offline();
    }
    logger.debug("Will boot Black Duck product.");
    BlackDuckServerConfig blackDuckServerConfig = productBootFactory.createBlackDuckServerConfig();
    BlackDuckConnectivityResult blackDuckConnectivityResult = blackDuckConnectivityChecker.determineConnectivity(blackDuckServerConfig);
    if (blackDuckConnectivityResult.isSuccessfullyConnected()) {
        BlackDuckServicesFactory blackDuckServicesFactory = blackDuckConnectivityResult.getBlackDuckServicesFactory();
        if (shouldUsePhoneHome(analyticsConfigurationService, blackDuckServicesFactory.getApiDiscovery(), blackDuckServicesFactory.getBlackDuckApiClient())) {
            PhoneHomeManager phoneHomeManager = productBootFactory.createPhoneHomeManager(blackDuckServicesFactory);
            return BlackDuckRunData.online(blackDuckDecision.scanMode(), blackDuckServicesFactory, phoneHomeManager, blackDuckConnectivityResult.getBlackDuckServerConfig());
        } else {
            logger.debug("Skipping phone home due to Black Duck global settings.");
            return BlackDuckRunData.onlineNoPhoneHome(blackDuckDecision.scanMode(), blackDuckServicesFactory, blackDuckConnectivityResult.getBlackDuckServerConfig());
        }
    } else {
        if (productBootOptions.isIgnoreConnectionFailures()) {
            logger.info(String.format("Failed to connect to Black Duck: %s", blackDuckConnectivityResult.getFailureReason()));
            logger.info(String.format("%s is set to 'true' so Detect will simply disable the Black Duck product.", DetectProperties.DETECT_IGNORE_CONNECTION_FAILURES.getName()));
            return null;
        } else {
            throw new DetectUserFriendlyException("Could not communicate with Black Duck: " + blackDuckConnectivityResult.getFailureReason(), ExitCodeType.FAILURE_BLACKDUCK_CONNECTIVITY);
        }
    }
}
Also used : DetectUserFriendlyException(com.synopsys.integration.detect.configuration.DetectUserFriendlyException) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) PhoneHomeManager(com.synopsys.integration.detect.workflow.phonehome.PhoneHomeManager) BlackDuckServerConfig(com.synopsys.integration.blackduck.configuration.BlackDuckServerConfig) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with PhoneHomeManager

use of com.synopsys.integration.detect.workflow.phonehome.PhoneHomeManager in project synopsys-detect by blackducksoftware.

the class ProductBootFactory method createPhoneHomeManager.

public PhoneHomeManager createPhoneHomeManager(BlackDuckServicesFactory blackDuckServicesFactory) {
    ExecutorService executorService = Executors.newSingleThreadExecutor();
    BlackDuckPhoneHomeHelper blackDuckPhoneHomeHelper = BlackDuckPhoneHomeHelper.createAsynchronousPhoneHomeHelper(blackDuckServicesFactory, executorService);
    PhoneHomeManager phoneHomeManager = new OnlinePhoneHomeManager(detectConfigurationFactory.createPhoneHomeOptions().getPassthrough(), detectInfo, eventSystem, blackDuckPhoneHomeHelper);
    return phoneHomeManager;
}
Also used : OnlinePhoneHomeManager(com.synopsys.integration.detect.workflow.phonehome.OnlinePhoneHomeManager) BlackDuckPhoneHomeHelper(com.synopsys.integration.blackduck.phonehome.BlackDuckPhoneHomeHelper) ExecutorService(java.util.concurrent.ExecutorService) PhoneHomeManager(com.synopsys.integration.detect.workflow.phonehome.PhoneHomeManager) OnlinePhoneHomeManager(com.synopsys.integration.detect.workflow.phonehome.OnlinePhoneHomeManager)

Example 4 with PhoneHomeManager

use of com.synopsys.integration.detect.workflow.phonehome.PhoneHomeManager in project synopsys-detect by blackducksoftware.

the class ShutdownDecider method decideShutdown.

public ShutdownDecision decideShutdown(DetectBootResult detectBootResult) {
    DiagnosticSystem diagnosticSystem = detectBootResult.getDiagnosticSystem().orElse(null);
    PhoneHomeManager phoneHomeManager = detectBootResult.getProductRunData().filter(ProductRunData::shouldUseBlackDuckProduct).map(ProductRunData::getBlackDuckRunData).flatMap(BlackDuckRunData::getPhoneHomeManager).orElse(null);
    CleanupDecision cleanupDecision = decideCleanup(detectBootResult.getDetectConfiguration().orElse(null), detectBootResult.getProductRunData().orElse(null), detectBootResult.getAirGapZip().orElse(null));
    return new ShutdownDecision(phoneHomeManager, diagnosticSystem, cleanupDecision);
}
Also used : DiagnosticSystem(com.synopsys.integration.detect.workflow.diagnostic.DiagnosticSystem) PhoneHomeManager(com.synopsys.integration.detect.workflow.phonehome.PhoneHomeManager) ProductRunData(com.synopsys.integration.detect.lifecycle.run.data.ProductRunData)

Aggregations

PhoneHomeManager (com.synopsys.integration.detect.workflow.phonehome.PhoneHomeManager)4 ProductRunData (com.synopsys.integration.detect.lifecycle.run.data.ProductRunData)2 Gson (com.google.gson.Gson)1 BlackDuckServerConfig (com.synopsys.integration.blackduck.configuration.BlackDuckServerConfig)1 BlackDuckPhoneHomeHelper (com.synopsys.integration.blackduck.phonehome.BlackDuckPhoneHomeHelper)1 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)1 FileFinder (com.synopsys.integration.common.util.finder.FileFinder)1 SimpleFileFinder (com.synopsys.integration.common.util.finder.SimpleFileFinder)1 DetectInfo (com.synopsys.integration.detect.configuration.DetectInfo)1 DetectUserFriendlyException (com.synopsys.integration.detect.configuration.DetectUserFriendlyException)1 DetectBootResult (com.synopsys.integration.detect.lifecycle.boot.DetectBootResult)1 ExitManager (com.synopsys.integration.detect.lifecycle.exit.ExitManager)1 ExceptionUtility (com.synopsys.integration.detect.lifecycle.shutdown.ExceptionUtility)1 ExitCodeManager (com.synopsys.integration.detect.lifecycle.shutdown.ExitCodeManager)1 InstalledToolManager (com.synopsys.integration.detect.tool.cache.InstalledToolManager)1 DetectRunId (com.synopsys.integration.detect.workflow.DetectRunId)1 DiagnosticSystem (com.synopsys.integration.detect.workflow.diagnostic.DiagnosticSystem)1 EventSystem (com.synopsys.integration.detect.workflow.event.EventSystem)1 OnlinePhoneHomeManager (com.synopsys.integration.detect.workflow.phonehome.OnlinePhoneHomeManager)1 FormattedOutputManager (com.synopsys.integration.detect.workflow.report.output.FormattedOutputManager)1