Search in sources :

Example 1 with PhoneHomeRequestBodyBuilder

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();
    }
}
Also used : PhoneHomeRequestBody(com.synopsys.integration.phonehome.request.PhoneHomeRequestBody) PhoneHomeRequestBodyBuilder(com.synopsys.integration.phonehome.request.PhoneHomeRequestBodyBuilder) PhoneHomeResponse(com.synopsys.integration.phonehome.PhoneHomeResponse) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) NameVersion(com.synopsys.integration.util.NameVersion) ProviderPhoneHomeHandler(com.synopsys.integration.alert.api.provider.ProviderPhoneHomeHandler) PhoneHomeService(com.synopsys.integration.phonehome.PhoneHomeService) ExecutorService(java.util.concurrent.ExecutorService)

Example 2 with PhoneHomeRequestBodyBuilder

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;
}
Also used : PhoneHomeRequestBodyBuilder(com.synopsys.integration.phonehome.request.PhoneHomeRequestBodyBuilder) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) IntegrationException(com.synopsys.integration.exception.IntegrationException) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) BlackDuckServerData(com.synopsys.integration.blackduck.service.model.BlackDuckServerData) StatefulProvider(com.synopsys.integration.alert.api.provider.state.StatefulProvider) BlackDuckRegistrationService(com.synopsys.integration.blackduck.service.dataservice.BlackDuckRegistrationService)

Aggregations

PhoneHomeRequestBodyBuilder (com.synopsys.integration.phonehome.request.PhoneHomeRequestBodyBuilder)2 ProviderPhoneHomeHandler (com.synopsys.integration.alert.api.provider.ProviderPhoneHomeHandler)1 StatefulProvider (com.synopsys.integration.alert.api.provider.state.StatefulProvider)1 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)1 BlackDuckHttpClient (com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient)1 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)1 BlackDuckRegistrationService (com.synopsys.integration.blackduck.service.dataservice.BlackDuckRegistrationService)1 BlackDuckServerData (com.synopsys.integration.blackduck.service.model.BlackDuckServerData)1 IntegrationException (com.synopsys.integration.exception.IntegrationException)1 Slf4jIntLogger (com.synopsys.integration.log.Slf4jIntLogger)1 PhoneHomeResponse (com.synopsys.integration.phonehome.PhoneHomeResponse)1 PhoneHomeService (com.synopsys.integration.phonehome.PhoneHomeService)1 PhoneHomeRequestBody (com.synopsys.integration.phonehome.request.PhoneHomeRequestBody)1 NameVersion (com.synopsys.integration.util.NameVersion)1 ExecutorService (java.util.concurrent.ExecutorService)1