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.
}
}
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;
}
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();
}
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");
}
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();
}
}
Aggregations