Search in sources :

Example 1 with ProviderPhoneHomeHandler

use of com.synopsys.integration.alert.api.provider.ProviderPhoneHomeHandler in project hub-alert by blackducksoftware.

the class PhoneHomeTest method runTest.

@Test
public void runTest() {
    RestApiAuditAccessor auditAccessor = Mockito.mock(RestApiAuditAccessor.class);
    Mockito.when(auditAccessor.findFirstByJobId(Mockito.any())).thenReturn(Optional.empty());
    TaskScheduler taskScheduler = Mockito.mock(TaskScheduler.class);
    ProxyManager proxyManager = Mockito.mock(ProxyManager.class);
    Mockito.when(proxyManager.createProxyInfoForHost(Mockito.anyString())).thenReturn(ProxyInfo.NO_PROXY_INFO);
    AboutReader aboutReader = Mockito.mock(AboutReader.class);
    Mockito.when(aboutReader.getProductVersion()).thenReturn(TEST_VERSION);
    JobAccessor jobAccessor = Mockito.mock(JobAccessor.class);
    // FIXME implement mocks
    DefaultConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(DefaultConfigurationModelConfigurationAccessor.class);
    ConfigurationModel config = Mockito.mock(ConfigurationModel.class);
    Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorKey(Mockito.any(DescriptorKey.class))).thenReturn(List.of(config));
    DescriptorMap descriptorMap = Mockito.mock(DescriptorMap.class);
    Descriptor descriptor = Mockito.mock(Descriptor.class);
    DescriptorKey descriptorKey = Mockito.mock(DescriptorKey.class);
    Mockito.when(descriptorKey.getUniversalKey()).thenReturn(TEST_DESCRIPTOR_NAME);
    Mockito.when(descriptorMap.getDescriptorMap()).thenReturn(Collections.singletonMap(descriptorKey, descriptor));
    List<ProviderPhoneHomeHandler> providerHandlers = List.of();
    ProviderKey providerKey = new BlackDuckProviderKey();
    PhoneHomeTask phoneHomeTask = new PhoneHomeTask(taskScheduler, aboutReader, jobAccessor, configurationModelConfigurationAccessor, null, proxyManager, new Gson(), auditAccessor, providerHandlers, providerKey);
    try {
        phoneHomeTask.run();
    } catch (Exception e) {
        fail("Unexpected exception");
    }
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) BlackDuckProviderKey(com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey) PhoneHomeTask(com.synopsys.integration.alert.task.PhoneHomeTask) ProxyManager(com.synopsys.integration.alert.common.rest.proxy.ProxyManager) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) Gson(com.google.gson.Gson) TaskScheduler(org.springframework.scheduling.TaskScheduler) ProviderPhoneHomeHandler(com.synopsys.integration.alert.api.provider.ProviderPhoneHomeHandler) AboutReader(com.synopsys.integration.alert.web.api.about.AboutReader) JobAccessor(com.synopsys.integration.alert.common.persistence.accessor.JobAccessor) DescriptorMap(com.synopsys.integration.alert.common.descriptor.DescriptorMap) ProviderKey(com.synopsys.integration.alert.descriptor.api.model.ProviderKey) BlackDuckProviderKey(com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey) Descriptor(com.synopsys.integration.alert.common.descriptor.Descriptor) RestApiAuditAccessor(com.synopsys.integration.alert.common.persistence.accessor.RestApiAuditAccessor) DefaultConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.database.api.DefaultConfigurationModelConfigurationAccessor) Test(org.junit.jupiter.api.Test)

Example 2 with ProviderPhoneHomeHandler

use of com.synopsys.integration.alert.api.provider.ProviderPhoneHomeHandler 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)2 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)2 Gson (com.google.gson.Gson)1 Descriptor (com.synopsys.integration.alert.common.descriptor.Descriptor)1 DescriptorMap (com.synopsys.integration.alert.common.descriptor.DescriptorMap)1 JobAccessor (com.synopsys.integration.alert.common.persistence.accessor.JobAccessor)1 RestApiAuditAccessor (com.synopsys.integration.alert.common.persistence.accessor.RestApiAuditAccessor)1 ProxyManager (com.synopsys.integration.alert.common.rest.proxy.ProxyManager)1 DefaultConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.database.api.DefaultConfigurationModelConfigurationAccessor)1 BlackDuckProviderKey (com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey)1 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)1 ProviderKey (com.synopsys.integration.alert.descriptor.api.model.ProviderKey)1 PhoneHomeTask (com.synopsys.integration.alert.task.PhoneHomeTask)1 AboutReader (com.synopsys.integration.alert.web.api.about.AboutReader)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