Search in sources :

Example 1 with CurrentVersionView

use of com.synopsys.integration.blackduck.api.generated.response.CurrentVersionView in project hub-detect by blackducksoftware.

the class ConnectivityChecker method determineConnectivity.

public ConnectivityResult determineConnectivity(DetectConfiguration detectConfiguration, DetectOptionManager detectOptionManager, DetectInfo detectInfo, Gson gson, ObjectMapper objectMapper, EventSystem eventSystem) throws DetectUserFriendlyException {
    logger.info("Detect will check if it can communicate with the Black Duck Server.");
    Slf4jIntLogger blackduckLogger = new Slf4jIntLogger(logger);
    BlackDuckServerConfig blackDuckServerConfig = detectOptionManager.createBlackduckServerConfig();
    logger.info("Attempting connection to the Black Duck server");
    ConnectionResult connectionResult = blackDuckServerConfig.attemptConnection(blackduckLogger);
    if (connectionResult.isFailure()) {
        logger.error("Failed to connect to the Black Duck server");
        logger.debug(String.format("The Black Duck server responded with a status code of %d", connectionResult.getHttpStatusCode()));
        return ConnectivityResult.failure(connectionResult.getErrorMessage().orElse("Could not reach the Black Duck server or the credentials were invalid."));
    }
    // TODO: Get a detailed reason of why canConnect failed.
    logger.info("Connection to the Black Duck server was successful");
    BlackDuckServicesFactory blackDuckServicesFactory = blackDuckServerConfig.createBlackDuckServicesFactory(gson, objectMapper, blackduckLogger);
    try {
        final BlackDuckService blackDuckService = blackDuckServicesFactory.createBlackDuckService();
        final CurrentVersionView currentVersion = blackDuckService.getResponse(ApiDiscovery.CURRENT_VERSION_LINK_RESPONSE);
        logger.info(String.format("Successfully connected to BlackDuck (version %s)!", currentVersion.getVersion()));
    } catch (IntegrationException e) {
        throw new DetectUserFriendlyException("Could not determine which version of Black Duck detect connected to.", e, ExitCodeType.FAILURE_HUB_CONNECTIVITY);
    }
    Map<String, String> additionalMetaData = detectConfiguration.getPhoneHomeProperties();
    ExecutorService executorService = Executors.newSingleThreadExecutor();
    BlackDuckPhoneHomeHelper blackDuckPhoneHomeHelper = BlackDuckPhoneHomeHelper.createAsynchronousPhoneHomeHelper(blackDuckServicesFactory, executorService);
    PhoneHomeManager phoneHomeManager = new OnlinePhoneHomeManager(additionalMetaData, detectInfo, gson, eventSystem, blackDuckPhoneHomeHelper);
    return ConnectivityResult.success(blackDuckServicesFactory, phoneHomeManager, blackDuckServerConfig);
}
Also used : CurrentVersionView(com.synopsys.integration.blackduck.api.generated.response.CurrentVersionView) IntegrationException(com.synopsys.integration.exception.IntegrationException) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) OnlinePhoneHomeManager(com.blackducksoftware.integration.hub.detect.workflow.phonehome.OnlinePhoneHomeManager) PhoneHomeManager(com.blackducksoftware.integration.hub.detect.workflow.phonehome.PhoneHomeManager) BlackDuckServerConfig(com.synopsys.integration.blackduck.configuration.BlackDuckServerConfig) DetectUserFriendlyException(com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) OnlinePhoneHomeManager(com.blackducksoftware.integration.hub.detect.workflow.phonehome.OnlinePhoneHomeManager) ConnectionResult(com.synopsys.integration.blackduck.configuration.ConnectionResult) BlackDuckPhoneHomeHelper(com.synopsys.integration.blackduck.phonehome.BlackDuckPhoneHomeHelper) ExecutorService(java.util.concurrent.ExecutorService) BlackDuckService(com.synopsys.integration.blackduck.service.BlackDuckService)

Aggregations

DetectUserFriendlyException (com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException)1 OnlinePhoneHomeManager (com.blackducksoftware.integration.hub.detect.workflow.phonehome.OnlinePhoneHomeManager)1 PhoneHomeManager (com.blackducksoftware.integration.hub.detect.workflow.phonehome.PhoneHomeManager)1 CurrentVersionView (com.synopsys.integration.blackduck.api.generated.response.CurrentVersionView)1 BlackDuckServerConfig (com.synopsys.integration.blackduck.configuration.BlackDuckServerConfig)1 ConnectionResult (com.synopsys.integration.blackduck.configuration.ConnectionResult)1 BlackDuckPhoneHomeHelper (com.synopsys.integration.blackduck.phonehome.BlackDuckPhoneHomeHelper)1 BlackDuckService (com.synopsys.integration.blackduck.service.BlackDuckService)1 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)1 IntegrationException (com.synopsys.integration.exception.IntegrationException)1 Slf4jIntLogger (com.synopsys.integration.log.Slf4jIntLogger)1 ExecutorService (java.util.concurrent.ExecutorService)1