Search in sources :

Example 1 with IntLogger

use of com.synopsys.integration.log.IntLogger in project hub-alert by blackducksoftware.

the class ComponentUnknownVersionNotificationSerializationTest method testNotificationSerialization.

@Test
@Ignore
@Disabled
public void testNotificationSerialization() throws IntegrationException, InterruptedException {
    LocalDateTime searchStartTime = LocalDateTime.now().minusMinutes(1);
    AlertRequestUtility alertRequestUtility = IntegrationPerformanceTestRunner.createAlertRequestUtility(webApplicationContext);
    BlackDuckProviderService blackDuckProviderService = new BlackDuckProviderService(alertRequestUtility, gson);
    configureJob(alertRequestUtility, blackDuckProviderService);
    ExternalId externalId = new ExternalId(Forge.MAVEN);
    externalId.setGroup("commons-fileupload");
    externalId.setName("commons-fileupload");
    Predicate<ProjectVersionComponentVersionView> componentFilter = (component) -> component.getComponentName().equals("Apache Commons FileUpload");
    blackDuckProviderService.triggerBlackDuckNotification(() -> externalId, componentFilter);
    try {
        WaitJobConfig waitJobConfig = new WaitJobConfig(intLogger, "notification serialization test notification wait", 300, searchStartTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(), 20);
        NotificationReceivedWaitJobTask notificationWaitJobTask = new NotificationReceivedWaitJobTask(notificationAccessor, searchStartTime, "Apache Commons FileUpload", null, NotificationType.COMPONENT_UNKNOWN_VERSION);
        WaitJob<Boolean> waitForNotificationToBeProcessed = WaitJob.createSimpleWait(waitJobConfig, notificationWaitJobTask);
        boolean isComplete = waitForNotificationToBeProcessed.waitFor();
        if (isComplete) {
            String notificationContent = notificationWaitJobTask.getNotificationContent().orElseThrow(() -> new IllegalStateException("Expected notification is missing."));
            BlackDuckResponseResolver resolver = blackDuckProviderService.getBlackDuckServicesFactory().getBlackDuckResponseResolver();
            ComponentUnknownVersionNotificationView notificationView = resolver.resolve(notificationContent, ComponentUnknownVersionNotificationView.class);
            assertNotNull(notificationView.getContent());
            assertTrue(StringUtils.isNotBlank(notificationView.getContent().getComponentName()));
            BlackDuckApiClient apiClient = blackDuckProviderService.getBlackDuckServicesFactory().getBlackDuckApiClient();
            Optional<HttpUrl> componentUrl = HttpUrl.createSafely(notificationView.getContent().getBomComponent());
            if (componentUrl.isPresent()) {
                apiClient.delete(componentUrl.get());
            }
        }
    } catch (InterruptedException ex) {
    // if a timeout happens that's ok we are trying to ensure deserialization is correct.
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) IntegrationException(com.synopsys.integration.exception.IntegrationException) DescriptorMocker(com.synopsys.integration.alert.util.DescriptorMocker) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) FrequencyType(com.synopsys.integration.alert.common.enumeration.FrequencyType) BlackDuckResponseResolver(com.synopsys.integration.blackduck.http.transform.subclass.BlackDuckResponseResolver) Disabled(org.junit.jupiter.api.Disabled) StringUtils(org.apache.commons.lang3.StringUtils) TestTags(com.synopsys.integration.alert.test.common.TestTags) HttpUrl(com.synopsys.integration.rest.HttpUrl) BeforeAll(org.junit.jupiter.api.BeforeAll) Gson(com.google.gson.Gson) Map(java.util.Map) Tag(org.junit.jupiter.api.Tag) TestPropertyKey(com.synopsys.integration.alert.test.common.TestPropertyKey) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) WebAppConfiguration(org.springframework.test.context.web.WebAppConfiguration) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) Predicate(java.util.function.Predicate) WebApplicationContext(org.springframework.web.context.WebApplicationContext) TestPropertySource(org.springframework.test.context.TestPropertySource) IntegrationPerformanceTestRunner(com.synopsys.integration.alert.performance.utility.IntegrationPerformanceTestRunner) ApplicationConfiguration(com.synopsys.integration.alert.configuration.ApplicationConfiguration) NotificationType(com.synopsys.integration.blackduck.api.manual.enumeration.NotificationType) ZoneId(java.time.ZoneId) WaitJob(com.synopsys.integration.wait.WaitJob) Test(org.junit.jupiter.api.Test) SlackDescriptor(com.synopsys.integration.alert.channel.slack.descriptor.SlackDescriptor) List(java.util.List) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) DatabaseDataSource(com.synopsys.integration.alert.database.DatabaseDataSource) ChannelKeys(com.synopsys.integration.alert.descriptor.api.model.ChannelKeys) TestProperties(com.synopsys.integration.alert.test.common.TestProperties) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) WaitJobConfig(com.synopsys.integration.wait.WaitJobConfig) Forge(com.synopsys.integration.bdio.model.Forge) LocalDateTime(java.time.LocalDateTime) HashMap(java.util.HashMap) IntLogger(com.synopsys.integration.log.IntLogger) AlertRequestUtility(com.synopsys.integration.alert.performance.utility.AlertRequestUtility) BlackDuckProviderService(com.synopsys.integration.alert.performance.utility.BlackDuckProviderService) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) ConfigurationManager(com.synopsys.integration.alert.performance.utility.ConfigurationManager) ChannelDescriptor(com.synopsys.integration.alert.common.descriptor.ChannelDescriptor) NotificationAccessor(com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor) Application(com.synopsys.integration.alert.Application) ComponentUnknownVersionNotificationView(com.synopsys.integration.blackduck.api.manual.view.ComponentUnknownVersionNotificationView) Ignore(org.junit.Ignore) ContextConfiguration(org.springframework.test.context.ContextConfiguration) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel) BlackDuckResponseResolver(com.synopsys.integration.blackduck.http.transform.subclass.BlackDuckResponseResolver) AlertRequestUtility(com.synopsys.integration.alert.performance.utility.AlertRequestUtility) BlackDuckProviderService(com.synopsys.integration.alert.performance.utility.BlackDuckProviderService) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) HttpUrl(com.synopsys.integration.rest.HttpUrl) WaitJobConfig(com.synopsys.integration.wait.WaitJobConfig) ComponentUnknownVersionNotificationView(com.synopsys.integration.blackduck.api.manual.view.ComponentUnknownVersionNotificationView) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView) Ignore(org.junit.Ignore) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Disabled(org.junit.jupiter.api.Disabled)

Example 2 with IntLogger

use of com.synopsys.integration.log.IntLogger in project hub-alert by blackducksoftware.

the class BlackDuckSystemValidator method validate.

public boolean validate(BlackDuckProperties blackDuckProperties) {
    boolean valid = true;
    String configName = blackDuckProperties.getConfigName();
    logger.info("Validating Black Duck configuration '{}'...", configName);
    try {
        Optional<String> blackDuckUrlOptional = blackDuckProperties.getBlackDuckUrl();
        removeOldConfigMessages(blackDuckProperties, SystemMessageType.BLACKDUCK_PROVIDER_CONNECTIVITY, SystemMessageType.BLACKDUCK_PROVIDER_LOCALHOST, SystemMessageType.BLACKDUCK_PROVIDER_URL_MISSING);
        String errorMessage = String.format(MISSING_BLACKDUCK_URL_ERROR_W_CONFIG_FORMAT, configName);
        String urlMissingType = createProviderSystemMessageType(blackDuckProperties, SystemMessageType.BLACKDUCK_PROVIDER_URL_MISSING);
        boolean missingUrl = addSystemMessageForError(errorMessage, SystemMessageSeverity.WARNING, urlMissingType, blackDuckUrlOptional.isEmpty());
        if (missingUrl) {
            logger.error("  -> {}", String.format(MISSING_BLACKDUCK_CONFIG_ERROR_FORMAT, configName));
            valid = false;
        }
        if (blackDuckUrlOptional.isPresent()) {
            String blackDuckUrlString = blackDuckUrlOptional.get();
            Integer timeout = blackDuckProperties.getBlackDuckTimeout();
            logger.debug("  -> Black Duck configuration '{}' URL found validating: {}", configName, blackDuckUrlString);
            logger.debug("  -> Black Duck configuration '{}' Timeout: {}", configName, timeout);
            URL blackDuckUrl = new URL(blackDuckUrlString);
            String localhostMissingType = createProviderSystemMessageType(blackDuckProperties, SystemMessageType.BLACKDUCK_PROVIDER_LOCALHOST);
            boolean localHostError = addSystemMessageForError(String.format(BLACKDUCK_LOCALHOST_ERROR_FORMAT, configName), SystemMessageSeverity.WARNING, localhostMissingType, "localhost".equals(blackDuckUrl.getHost()));
            if (localHostError) {
                logger.warn("  -> {}", String.format(BLACKDUCK_LOCALHOST_ERROR_FORMAT, configName));
            }
            IntLogger intLogger = new Slf4jIntLogger(logger);
            BlackDuckServerConfig blackDuckServerConfig = blackDuckProperties.createBlackDuckServerConfig(intLogger);
            boolean canConnect = blackDuckServerConfig.canConnect(intLogger);
            if (canConnect) {
                logger.info("  -> Black Duck configuration '{}' is Valid!", configName);
            } else {
                String message = String.format("Can not connect to the Black Duck server with the configuration '%s'.", configName);
                connectivityWarning(blackDuckProperties, message);
                valid = false;
            }
        } else {
            String message = String.format("The Black Duck configuration '%s' is not valid.", configName);
            connectivityWarning(blackDuckProperties, message);
            valid = false;
        }
        BlackDuckApiTokenValidator blackDuckAPITokenValidator = new BlackDuckApiTokenValidator(blackDuckProperties);
        if (!blackDuckAPITokenValidator.isApiTokenValid()) {
            connectivityWarning(blackDuckProperties, BLACKDUCK_API_PERMISSION_FORMAT);
            valid = false;
        }
    } catch (MalformedURLException | IntegrationException | AlertRuntimeException ex) {
        logger.error("  -> Black Duck configuration '{}' is invalid; cause: {}", configName, ex.getMessage());
        logger.debug(String.format("  -> Black Duck configuration '%s' Stack Trace: ", configName), ex);
        valid = false;
    }
    return valid;
}
Also used : MalformedURLException(java.net.MalformedURLException) IntegrationException(com.synopsys.integration.exception.IntegrationException) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) IntLogger(com.synopsys.integration.log.IntLogger) URL(java.net.URL) BlackDuckServerConfig(com.synopsys.integration.blackduck.configuration.BlackDuckServerConfig) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException)

Example 3 with IntLogger

use of com.synopsys.integration.log.IntLogger in project hub-alert by blackducksoftware.

the class BlackDuckProjectExistencePopulator method createBlackDuckApiClient.

private BlackDuckApiClient createBlackDuckApiClient(ConfigurationModel providerGlobalConfig) throws AlertException {
    StatefulProvider statefulProvider = blackDuckProvider.createStatefulProvider(providerGlobalConfig);
    BlackDuckProperties blackDuckProperties = (BlackDuckProperties) statefulProvider.getProperties();
    IntLogger intLogger = new Slf4jIntLogger(logger);
    BlackDuckHttpClient blackDuckHttpClient = blackDuckProperties.createBlackDuckHttpClient(intLogger);
    BlackDuckServicesFactory blackDuckServicesFactory = blackDuckProperties.createBlackDuckServicesFactory(blackDuckHttpClient, intLogger);
    return blackDuckServicesFactory.getBlackDuckApiClient();
}
Also used : Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) IntLogger(com.synopsys.integration.log.IntLogger) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) StatefulProvider(com.synopsys.integration.alert.api.provider.state.StatefulProvider)

Example 4 with IntLogger

use of com.synopsys.integration.log.IntLogger in project hub-alert by blackducksoftware.

the class DockerTagRetrieverTest method getTagsModelTestIT.

@Test
@Tags({ @Tag(TestTags.DEFAULT_INTEGRATION), @Tag(TestTags.CUSTOM_EXTERNAL_CONNECTION) })
public void getTagsModelTestIT() throws IntegrationException {
    IntLogger intLogger = new PrintStreamIntLogger(System.out, LogLevel.INFO);
    IntHttpClient intHttpClient = new IntHttpClient(intLogger, gson, 10, true, ProxyInfo.NO_PROXY_INFO);
    HttpUrl httpUrl = new HttpUrl("https://google.com");
    Request testRequest = new Request.Builder(httpUrl).build();
    try (Response googleResponse = intHttpClient.execute(testRequest)) {
        googleResponse.throwExceptionForError();
    } catch (IntegrationException | IOException e) {
        assumeTrue(null == e, "Could not connect. Skipping this test...");
    }
    DockerTagRetriever dockerTagRetriever = new DockerTagRetriever(gson, intHttpClient);
    DockerTagsResponseModel tagsModel = dockerTagRetriever.getTagsModel();
    assertFalse(tagsModel.isEmpty(), "Expected tags from the docker repo to exist");
}
Also used : Response(com.synopsys.integration.rest.response.Response) DockerTagsResponseModel(com.synopsys.integration.alert.update.model.DockerTagsResponseModel) PrintStreamIntLogger(com.synopsys.integration.log.PrintStreamIntLogger) IntegrationException(com.synopsys.integration.exception.IntegrationException) IntHttpClient(com.synopsys.integration.rest.client.IntHttpClient) Request(com.synopsys.integration.rest.request.Request) IntLogger(com.synopsys.integration.log.IntLogger) PrintStreamIntLogger(com.synopsys.integration.log.PrintStreamIntLogger) IOException(java.io.IOException) HttpUrl(com.synopsys.integration.rest.HttpUrl) Test(org.junit.jupiter.api.Test) TestTags(com.synopsys.integration.alert.test.common.TestTags) Tags(org.junit.jupiter.api.Tags)

Example 5 with IntLogger

use of com.synopsys.integration.log.IntLogger in project hub-alert by blackducksoftware.

the class BlackDuckIssueTrackerCallbackEventHandler method createBlackDuckServicesFactory.

private Optional<BlackDuckServicesFactory> createBlackDuckServicesFactory(BlackDuckProperties blackDuckProperties) {
    IntLogger intLogger = new Slf4jIntLogger(logger);
    try {
        BlackDuckHttpClient blackDuckHttpClient = blackDuckProperties.createBlackDuckHttpClient(intLogger);
        BlackDuckServicesFactory blackDuckServicesFactory = blackDuckProperties.createBlackDuckServicesFactory(blackDuckHttpClient, intLogger);
        return Optional.of(blackDuckServicesFactory);
    } catch (AlertException e) {
        logger.error("Failed to create a BlackDuck http client", e);
        return Optional.empty();
    }
}
Also used : Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) IntLogger(com.synopsys.integration.log.IntLogger) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Aggregations

IntLogger (com.synopsys.integration.log.IntLogger)6 Slf4jIntLogger (com.synopsys.integration.log.Slf4jIntLogger)5 IntegrationException (com.synopsys.integration.exception.IntegrationException)3 TestTags (com.synopsys.integration.alert.test.common.TestTags)2 BlackDuckHttpClient (com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient)2 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)2 HttpUrl (com.synopsys.integration.rest.HttpUrl)2 IntHttpClient (com.synopsys.integration.rest.client.IntHttpClient)2 Test (org.junit.jupiter.api.Test)2 Gson (com.google.gson.Gson)1 Application (com.synopsys.integration.alert.Application)1 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)1 AlertRuntimeException (com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException)1 StatefulProvider (com.synopsys.integration.alert.api.provider.state.StatefulProvider)1 SlackDescriptor (com.synopsys.integration.alert.channel.slack.descriptor.SlackDescriptor)1 ChannelDescriptor (com.synopsys.integration.alert.common.descriptor.ChannelDescriptor)1 FrequencyType (com.synopsys.integration.alert.common.enumeration.FrequencyType)1 NotificationAccessor (com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor)1 FieldValueModel (com.synopsys.integration.alert.common.rest.model.FieldValueModel)1 ApplicationConfiguration (com.synopsys.integration.alert.configuration.ApplicationConfiguration)1