Search in sources :

Example 1 with Slf4jIntLogger

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

the class NotificationExtractorBlackDuckServicesFactoryCache method createBlackDuckServicesFactory.

private BlackDuckServicesFactory createBlackDuckServicesFactory(Long blackDuckConfigId) throws AlertConfigurationException {
    Optional<BlackDuckProperties> optionalProperties = blackDuckPropertiesFactory.createProperties(blackDuckConfigId);
    if (optionalProperties.isPresent()) {
        BlackDuckProperties blackDuckProperties = optionalProperties.get();
        Slf4jIntLogger intLogger = new Slf4jIntLogger(logger);
        try {
            BlackDuckHttpClient blackDuckHttpClient = blackDuckProperties.createBlackDuckCacheClient(intLogger);
            return blackDuckProperties.createBlackDuckServicesFactory(blackDuckHttpClient, intLogger);
        } catch (AlertException e) {
            throw new AlertConfigurationException("The BlackDuck configuration is invalid", e);
        }
    }
    throw new AlertConfigurationException(String.format("No BlackDuck configuration with id '%s' existed", blackDuckConfigId));
}
Also used : BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)

Example 2 with Slf4jIntLogger

use of com.synopsys.integration.log.Slf4jIntLogger 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 Slf4jIntLogger

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

the class BlackDuckSSOConfigRetriever method fromProperties.

public static BlackDuckSSOConfigRetriever fromProperties(BlackDuckProperties blackDuckProperties) throws AlertException {
    Logger logger = LoggerFactory.getLogger(BlackDuckSSOConfigRetriever.class);
    Slf4jIntLogger intLogger = new Slf4jIntLogger(logger);
    BlackDuckHttpClient blackDuckHttpClient = blackDuckProperties.createBlackDuckHttpClient(intLogger);
    BlackDuckServicesFactory blackDuckServicesFactory = blackDuckProperties.createBlackDuckServicesFactory(blackDuckHttpClient, intLogger);
    return new BlackDuckSSOConfigRetriever(blackDuckServicesFactory.getApiDiscovery(), blackDuckServicesFactory.getBlackDuckApiClient());
}
Also used : Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) Logger(org.slf4j.Logger)

Example 4 with Slf4jIntLogger

use of com.synopsys.integration.log.Slf4jIntLogger 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 5 with Slf4jIntLogger

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

the class JiraServerProperties method createJiraServicesServerFactory.

public JiraServerServiceFactory createJiraServicesServerFactory(Logger logger, Gson gson) throws IssueTrackerException {
    JiraServerRestConfig jiraServerConfig = createJiraServerConfig();
    Slf4jIntLogger intLogger = new Slf4jIntLogger(logger);
    JiraHttpClient jiraHttpClient = jiraServerConfig.createJiraHttpClient(intLogger);
    return new JiraServerServiceFactory(intLogger, jiraHttpClient, gson);
}
Also used : JiraHttpClient(com.synopsys.integration.jira.common.rest.JiraHttpClient) JiraServerServiceFactory(com.synopsys.integration.jira.common.server.service.JiraServerServiceFactory) JiraServerRestConfig(com.synopsys.integration.jira.common.server.configuration.JiraServerRestConfig) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger)

Aggregations

Slf4jIntLogger (com.synopsys.integration.log.Slf4jIntLogger)13 BlackDuckHttpClient (com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient)8 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)6 IntegrationException (com.synopsys.integration.exception.IntegrationException)4 IntLogger (com.synopsys.integration.log.IntLogger)4 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)3 BlackDuckProperties (com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties)3 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)2 AlertRuntimeException (com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException)2 StatefulProvider (com.synopsys.integration.alert.api.provider.state.StatefulProvider)2 BlackDuckServerConfig (com.synopsys.integration.blackduck.configuration.BlackDuckServerConfig)2 JiraHttpClient (com.synopsys.integration.jira.common.rest.JiraHttpClient)2 AlertFieldException (com.synopsys.integration.alert.common.exception.AlertFieldException)1 MessageResult (com.synopsys.integration.alert.common.message.model.MessageResult)1 ProviderProject (com.synopsys.integration.alert.common.persistence.model.ProviderProject)1 BlackDuckApiTokenValidator (com.synopsys.integration.alert.provider.blackduck.validator.BlackDuckApiTokenValidator)1 ApiDiscovery (com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery)1 ProjectView (com.synopsys.integration.blackduck.api.generated.view.ProjectView)1 BlackDuckServerConfigBuilder (com.synopsys.integration.blackduck.configuration.BlackDuckServerConfigBuilder)1 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)1