Search in sources :

Example 1 with PhoneHomeResponse

use of com.synopsys.integration.phonehome.PhoneHomeResponse 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)

Aggregations

ProviderPhoneHomeHandler (com.synopsys.integration.alert.api.provider.ProviderPhoneHomeHandler)1 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)1 PhoneHomeResponse (com.synopsys.integration.phonehome.PhoneHomeResponse)1 PhoneHomeService (com.synopsys.integration.phonehome.PhoneHomeService)1 PhoneHomeRequestBody (com.synopsys.integration.phonehome.request.PhoneHomeRequestBody)1 PhoneHomeRequestBodyBuilder (com.synopsys.integration.phonehome.request.PhoneHomeRequestBodyBuilder)1 NameVersion (com.synopsys.integration.util.NameVersion)1 ExecutorService (java.util.concurrent.ExecutorService)1