use of com.synopsys.integration.phonehome.request.PhoneHomeRequestBodyBuilder in project hub-alert by blackducksoftware.
the class PhoneHomeTask method runTask.
@Override
public void runTask() {
String productVersion = aboutReader.getProductVersion();
if (AboutReader.PRODUCT_VERSION_UNKNOWN.equals(productVersion)) {
return;
}
ExecutorService phoneHomeExecutor = Executors.newSingleThreadExecutor();
try {
String[] channelMetaData = retrieveChannelMetadataForAllJobs();
for (ProviderPhoneHomeHandler handler : providerHandlers) {
List<ConfigurationModel> configurations = configurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(handler.getProviderKey(), ConfigContextEnum.GLOBAL);
for (ConfigurationModel configuration : configurations) {
PhoneHomeService phoneHomeService = createPhoneHomeService(phoneHomeExecutor);
NameVersion alertArtifactInfo = new NameVersion(ARTIFACT_ID, productVersion);
PhoneHomeRequestBodyBuilder requestBodyBuilder = handler.populatePhoneHomeData(configuration, alertArtifactInfo);
requestBodyBuilder.addArtifactModules(channelMetaData);
PhoneHomeRequestBody requestBody = requestBodyBuilder.build();
PhoneHomeResponse phoneHomeResponse = phoneHomeService.phoneHome(requestBody, System.getenv());
boolean taskSucceeded = BooleanUtils.isTrue(phoneHomeResponse.awaitResult(DEFAULT_TIMEOUT));
if (!taskSucceeded) {
logger.debug("Phone home task timed out and did not send any results.");
}
}
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
} finally {
phoneHomeExecutor.shutdownNow();
}
}
use of com.synopsys.integration.phonehome.request.PhoneHomeRequestBodyBuilder in project hub-alert by blackducksoftware.
the class BlackDuckPhoneHomeHandler method populatePhoneHomeData.
@Override
public PhoneHomeRequestBodyBuilder populatePhoneHomeData(ConfigurationModel configurationModel, NameVersion alertArtifactInfo) {
String registrationId = null;
String blackDuckUrl = PhoneHomeRequestBody.UNKNOWN_FIELD_VALUE;
String blackDuckVersion = PhoneHomeRequestBody.UNKNOWN_FIELD_VALUE;
try {
descriptorAccessor.getRegisteredDescriptorById(configurationModel.getDescriptorId());
StatefulProvider statefulProvider = provider.createStatefulProvider(configurationModel);
BlackDuckProperties blackDuckProperties = (BlackDuckProperties) statefulProvider.getProperties();
BlackDuckHttpClient blackDuckHttpClient = blackDuckProperties.createBlackDuckHttpClient(logger);
BlackDuckServicesFactory blackDuckServicesFactory = blackDuckProperties.createBlackDuckServicesFactory(blackDuckHttpClient, new Slf4jIntLogger(logger));
BlackDuckRegistrationService blackDuckRegistrationService = blackDuckServicesFactory.createBlackDuckRegistrationService();
BlackDuckServerData blackDuckServerData = blackDuckRegistrationService.getBlackDuckServerData();
blackDuckVersion = blackDuckServerData.getVersion();
registrationId = blackDuckServerData.getRegistrationKey().orElse(null);
blackDuckUrl = blackDuckProperties.getBlackDuckUrl().orElse(PhoneHomeRequestBody.UNKNOWN_FIELD_VALUE);
} catch (IntegrationException ignored) {
// ignoring this exception
}
// We must check if the reg id is blank because of an edge case in which Black Duck can authenticate (while the webserver is coming up) without registration
if (StringUtils.isBlank(registrationId)) {
registrationId = PhoneHomeRequestBody.UNKNOWN_FIELD_VALUE;
}
PhoneHomeRequestBodyBuilder phoneHomeBuilder = new PhoneHomeRequestBodyBuilder(registrationId, blackDuckUrl, alertArtifactInfo, UniquePhoneHomeProduct.BLACK_DUCK, blackDuckVersion);
return phoneHomeBuilder;
}
Aggregations