use of com.synopsys.integration.blackduck.service.BlackDuckService 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);
}
use of com.synopsys.integration.blackduck.service.BlackDuckService in project hub-detect by blackducksoftware.
the class DetectProjectService method createOrUpdateHubProject.
public ProjectVersionWrapper createOrUpdateHubProject(final NameVersion projectNameVersion, final String applicationId) throws IntegrationException, DetectUserFriendlyException, InterruptedException {
final ProjectService projectService = blackDuckServicesFactory.createProjectService();
final BlackDuckService hubService = blackDuckServicesFactory.createBlackDuckService();
final ProjectRequest projectRequest = createProjectRequest(projectNameVersion, projectService, hubService);
final boolean forceUpdate = detectProjectServiceOptions.isForceProjectVersionUpdate();
final ProjectVersionWrapper projectVersionWrapper = projectService.syncProjectAndVersion(projectRequest, forceUpdate);
setApplicationId(projectVersionWrapper.getProjectView(), applicationId);
return projectVersionWrapper;
}
Aggregations