Search in sources :

Example 1 with ResilientJobConfig

use of com.synopsys.integration.wait.ResilientJobConfig in project blackduck-common by blackducksoftware.

the class CodeLocationWaiter method checkCodeLocationsAddedToBom.

public CodeLocationWaitResult checkCodeLocationsAddedToBom(UserView userView, NotificationTaskRange notificationTaskRange, NameVersion projectAndVersion, Set<String> codeLocationNames, int expectedNotificationCount, long timeoutInSeconds, int waitIntervalInSeconds) throws IntegrationException, InterruptedException {
    logger.debug("Expected notification count " + expectedNotificationCount);
    logger.debug("Expected code locations:");
    codeLocationNames.forEach(codeLocation -> logger.debug(String.format("  Code Location -> %s", codeLocation)));
    logger.debug("");
    ResilientJobConfig jobConfig = new ResilientJobConfig(logger, timeoutInSeconds, notificationTaskRange.getTaskStartTime(), waitIntervalInSeconds);
    CodeLocationWaitJob codeLocationWaitJob = new CodeLocationWaitJob(logger, projectService, notificationService, userView, notificationTaskRange, projectAndVersion, codeLocationNames, expectedNotificationCount, blackDuckApiClient);
    ResilientJobExecutor resilientJobExecutor = new ResilientJobExecutor(jobConfig);
    return resilientJobExecutor.executeJob(codeLocationWaitJob);
}
Also used : ResilientJobExecutor(com.synopsys.integration.wait.ResilientJobExecutor) ResilientJobConfig(com.synopsys.integration.wait.ResilientJobConfig)

Example 2 with ResilientJobConfig

use of com.synopsys.integration.wait.ResilientJobConfig in project blackduck-common by blackducksoftware.

the class InstallAndRunSignatureScannerTestIT method testInstallingAndRunningSignatureScanner.

@Test
void testInstallingAndRunningSignatureScanner() throws IOException, InterruptedException, IntegrationException {
    // here, we do not want to automatically trust the server's certificate
    BlackDuckServerConfigBuilder blackDuckServerConfigBuilder = intHttpClientTestHelper.getBlackDuckServerConfigBuilder();
    blackDuckServerConfigBuilder.setTrustCert(false);
    BlackDuckServerConfig blackDuckServerConfig = blackDuckServerConfigBuilder.build();
    File installDirectory = new File(scannerDirectoryPath, "scanner_install");
    File outputDirectory = new File(scannerDirectoryPath, "scanner_output");
    ScanBatch scanBatch = createScanBatch(blackDuckServerConfig, outputDirectory);
    BufferedIntLogger logger = new BufferedIntLogger();
    BlackDuckServicesFactory blackDuckServicesFactory = blackDuckServerConfig.createBlackDuckServicesFactory(logger);
    IntEnvironmentVariables environmentVariables = blackDuckServicesFactory.getEnvironmentVariables();
    OperatingSystemType operatingSystemType = OperatingSystemType.determineFromSystem();
    ExecutorService executorService = BlackDuckServicesFactory.NO_THREAD_EXECUTOR_SERVICE;
    BlackDuckHttpClient blackDuckHttpClient = blackDuckServicesFactory.getBlackDuckHttpClient();
    BlackDuckRegistrationService blackDuckRegistrationService = blackDuckServicesFactory.createBlackDuckRegistrationService();
    CleanupZipExpander cleanupZipExpander = new CleanupZipExpander(logger);
    HttpUrl blackDuckServerUrl = blackDuckHttpClient.getBlackDuckUrl();
    ScanPathsUtility scanPathsUtility = new ScanPathsUtility(logger, environmentVariables, operatingSystemType);
    ScanCommandRunner scanCommandRunner = new ScanCommandRunner(logger, environmentVariables, scanPathsUtility, executorService);
    // first, run a scan with an install that will NOT update the embedded keystore, which should fail
    KeyStoreHelper noOpKeyStoreHelper = new NoOpKeyStoreHelper();
    ScannerZipInstaller installerWithoutKeyStoreManagement = new ScannerZipInstaller(logger, new SignatureScannerClient(blackDuckHttpClient), blackDuckRegistrationService, cleanupZipExpander, scanPathsUtility, noOpKeyStoreHelper, blackDuckServerUrl, operatingSystemType, installDirectory);
    ScanBatchRunner scanBatchRunnerWithout = ScanBatchRunner.createComplete(environmentVariables, scanPathsUtility, scanCommandRunner, installerWithoutKeyStoreManagement);
    SignatureScannerService signatureScannerServiceWithout = blackDuckServicesFactory.createSignatureScannerService(scanBatchRunnerWithout);
    assertScanFailure(logger, blackDuckRegistrationService, signatureScannerServiceWithout, scanBatch);
    // now, delete the failed installation
    FileUtils.deleteDirectory(installDirectory);
    // second, run a scan with an install that DOES update the embedded keystore, which should succeed
    logger.resetAllLogs();
    KeyStoreHelper keyStoreHelper = new KeyStoreHelper(logger);
    ScannerZipInstaller installerWithKeyStoreManagement = new ScannerZipInstaller(logger, new SignatureScannerClient(blackDuckHttpClient), blackDuckRegistrationService, cleanupZipExpander, scanPathsUtility, keyStoreHelper, blackDuckServerUrl, operatingSystemType, installDirectory);
    ScanBatchRunner scanBatchRunnerWith = ScanBatchRunner.createComplete(environmentVariables, scanPathsUtility, scanCommandRunner, installerWithKeyStoreManagement);
    SignatureScannerService signatureScannerServiceWith = blackDuckServicesFactory.createSignatureScannerService(scanBatchRunnerWith);
    assertScanSuccess(logger, signatureScannerServiceWith, scanBatch);
    // finally, verify the code location exists and then delete it to clean up
    CodeLocationService codeLocationService = blackDuckServicesFactory.createCodeLocationService();
    BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
    ResilientJobConfig jobConfig = new ResilientJobConfig(logger, 120, System.currentTimeMillis(), 10);
    WaitJob.waitFor(jobConfig, () -> codeLocationService.getCodeLocationByName(CODE_LOCATION_NAME).isPresent(), "codeLocationTest");
    Optional<CodeLocationView> codeLocationViewOptional = codeLocationService.getCodeLocationByName(CODE_LOCATION_NAME);
    assertTrue(codeLocationViewOptional.isPresent());
    blackDuckApiClient.delete(codeLocationViewOptional.get());
}
Also used : CodeLocationService(com.synopsys.integration.blackduck.service.dataservice.CodeLocationService) BlackDuckServerConfigBuilder(com.synopsys.integration.blackduck.configuration.BlackDuckServerConfigBuilder) SignatureScannerService(com.synopsys.integration.blackduck.codelocation.signaturescanner.SignatureScannerService) KeyStoreHelper(com.synopsys.integration.blackduck.keystore.KeyStoreHelper) ScannerZipInstaller(com.synopsys.integration.blackduck.codelocation.signaturescanner.command.ScannerZipInstaller) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) CleanupZipExpander(com.synopsys.integration.util.CleanupZipExpander) CodeLocationView(com.synopsys.integration.blackduck.api.generated.view.CodeLocationView) IntEnvironmentVariables(com.synopsys.integration.util.IntEnvironmentVariables) ScanBatch(com.synopsys.integration.blackduck.codelocation.signaturescanner.ScanBatch) ScanPathsUtility(com.synopsys.integration.blackduck.codelocation.signaturescanner.command.ScanPathsUtility) SignatureScannerClient(com.synopsys.integration.blackduck.http.client.SignatureScannerClient) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) BufferedIntLogger(com.synopsys.integration.log.BufferedIntLogger) ScanCommandRunner(com.synopsys.integration.blackduck.codelocation.signaturescanner.command.ScanCommandRunner) HttpUrl(com.synopsys.integration.rest.HttpUrl) BlackDuckServerConfig(com.synopsys.integration.blackduck.configuration.BlackDuckServerConfig) BlackDuckRegistrationService(com.synopsys.integration.blackduck.service.dataservice.BlackDuckRegistrationService) ScanBatchRunner(com.synopsys.integration.blackduck.codelocation.signaturescanner.ScanBatchRunner) OperatingSystemType(com.synopsys.integration.util.OperatingSystemType) ExecutorService(java.util.concurrent.ExecutorService) ResilientJobConfig(com.synopsys.integration.wait.ResilientJobConfig) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 3 with ResilientJobConfig

use of com.synopsys.integration.wait.ResilientJobConfig in project blackduck-common by blackducksoftware.

the class BdioUploadRecipeTest method assertCodeLocationDoesNotExist.

private void assertCodeLocationDoesNotExist() throws IntegrationException, InterruptedException {
    Optional<CodeLocationView> optionalCodeLocationView = codeLocationService.getCodeLocationByName(codeLocationName);
    if (optionalCodeLocationView.isPresent()) {
        deleteCodeLocation(codeLocationName);
    }
    ResilientJobConfig waitJobConfig = new ResilientJobConfig(logger, 30, ResilientJobConfig.CURRENT_TIME_SUPPLIER, 5);
    WaitJob.waitFor(waitJobConfig, () -> !codeLocationService.getCodeLocationByName(codeLocationName).isPresent(), "code location not found");
}
Also used : CodeLocationView(com.synopsys.integration.blackduck.api.generated.view.CodeLocationView) ResilientJobConfig(com.synopsys.integration.wait.ResilientJobConfig)

Example 4 with ResilientJobConfig

use of com.synopsys.integration.wait.ResilientJobConfig in project hub-alert by blackducksoftware.

the class NotificationRemovalTest method testDeletion.

@Test
// performance test
@Ignore
@Disabled
void testDeletion() throws IntegrationException, InterruptedException {
    providerConfig = createBlackDuckConfiguration();
    OffsetDateTime testStartTime = OffsetDateTime.now();
    OffsetDateTime notificationCreatedAtTime = OffsetDateTime.now();
    // create 1000 processed notifications not for removal
    createABatchOfNotifications(providerConfig, testStartTime, true);
    // create 9000 for removal with varying dates and processed flags
    for (int index = 0; index < 9; index++) {
        boolean processed = index % 2 == 0 ? true : false;
        // update the createdAt time to be 1 month older
        notificationCreatedAtTime = notificationCreatedAtTime.minusMonths(1);
        createABatchOfNotifications(providerConfig, notificationCreatedAtTime, processed);
    }
    OffsetDateTime oldestNotificationCreationTime = notificationCreatedAtTime;
    purgeTask = new PurgeTask(schedulingDescriptorKey, taskScheduler, notificationAccessor, systemMessageAccessor, taskManager, configurationModelConfigurationAccessor);
    LocalDateTime startTime = LocalDateTime.now();
    purgeTask.runTask();
    WaitJobCondition waitJobCondition = () -> {
        List<AlertNotificationModel> notificationsInDatabase = getAllNotificationsInDatabase(oldestNotificationCreationTime, testStartTime);
        return notificationsInDatabase.size() == BATCH_SIZE && notificationsInDatabase.stream().allMatch(AlertNotificationModel::getProcessed);
    };
    ResilientJobConfig resilientJobConfig = new ResilientJobConfig(LOGGER, 600, startTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(), 1);
    boolean isComplete = WaitJob.waitFor(resilientJobConfig, waitJobCondition, "int performance test runner notification wait");
    logTimeElapsedWithMessage("Purge of notifications duration: %s", startTime, LocalDateTime.now());
    List<AlertNotificationModel> remainingNotifications = getAllNotificationsInDatabase(oldestNotificationCreationTime, testStartTime);
    assertTrue(isComplete);
    assertEquals(BATCH_SIZE, remainingNotifications.size());
}
Also used : LocalDateTime(java.time.LocalDateTime) AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) OffsetDateTime(java.time.OffsetDateTime) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) WaitJobCondition(com.synopsys.integration.wait.WaitJobCondition) PurgeTask(com.synopsys.integration.alert.component.scheduling.workflow.PurgeTask) ResilientJobConfig(com.synopsys.integration.wait.ResilientJobConfig) Ignore(org.junit.Ignore) Test(org.junit.jupiter.api.Test) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Disabled(org.junit.jupiter.api.Disabled)

Example 5 with ResilientJobConfig

use of com.synopsys.integration.wait.ResilientJobConfig in project hub-alert by blackducksoftware.

the class IntegrationPerformanceTestRunnerV2 method waitForJobToFinish.

private void waitForJobToFinish(Set<String> jobIds, LocalDateTime startingNotificationTime, int numberOfExpectedAuditEntries, NotificationType notificationType) throws IntegrationException, InterruptedException {
    ResilientJobConfig resilientJobConfig = new ResilientJobConfig(intLogger, 14400, startingNotificationTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(), 2);
    NotificationWaitJobTaskV2 notificationWaitJobTask = new NotificationWaitJobTaskV2(intLogger, dateTimeFormatter, gson, alertRequestUtility, startingNotificationTime, numberOfExpectedAuditEntries, notificationType, jobIds);
    boolean isComplete = WaitJob.waitFor(resilientJobConfig, notificationWaitJobTask, "int performance test runner notification wait");
    intLogger.info("Finished waiting for the notification to be processed: " + isComplete);
    assertTrue(isComplete);
}
Also used : ResilientJobConfig(com.synopsys.integration.wait.ResilientJobConfig)

Aggregations

ResilientJobConfig (com.synopsys.integration.wait.ResilientJobConfig)18 LocalDateTime (java.time.LocalDateTime)10 List (java.util.List)5 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)4 HttpUrl (com.synopsys.integration.rest.HttpUrl)4 Test (org.junit.jupiter.api.Test)4 Ignore (org.junit.Ignore)3 Disabled (org.junit.jupiter.api.Disabled)3 Gson (com.google.gson.Gson)2 Application (com.synopsys.integration.alert.Application)2 SlackDescriptor (com.synopsys.integration.alert.channel.slack.descriptor.SlackDescriptor)2 ChannelDescriptor (com.synopsys.integration.alert.common.descriptor.ChannelDescriptor)2 FrequencyType (com.synopsys.integration.alert.common.enumeration.FrequencyType)2 NotificationAccessor (com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor)2 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)2 FieldValueModel (com.synopsys.integration.alert.common.rest.model.FieldValueModel)2 PurgeTask (com.synopsys.integration.alert.component.scheduling.workflow.PurgeTask)2 ApplicationConfiguration (com.synopsys.integration.alert.configuration.ApplicationConfiguration)2 DatabaseDataSource (com.synopsys.integration.alert.database.DatabaseDataSource)2 ChannelKeys (com.synopsys.integration.alert.descriptor.api.model.ChannelKeys)2