Search in sources :

Example 1 with UploadBatchRunner

use of com.synopsys.integration.blackduck.codelocation.bdiolegacy.UploadBatchRunner in project blackduck-common by blackducksoftware.

the class BdioUploadRecipeTest method testBdioUploadAndMapToVersion.

@Test
public void testBdioUploadAndMapToVersion() throws InterruptedException, IntegrationException {
    assertCodeLocationDoesNotExist();
    File file = BasicRecipe.restConnectionTestHelper.getFile("bdio/hub_common_bdio_without_project_section.jsonld");
    // in this case we upload the bdio but we have to map it to a project and version ourselves since the Project information is missing in the bdio file
    IntLogger logger = new BufferedIntLogger();
    UploadBatchRunner uploadBatchRunner = new UploadBatchRunner(logger, blackDuckApiClient, apiDiscovery, BlackDuckServicesFactory.NO_THREAD_EXECUTOR_SERVICE);
    UploadBatch uploadBatch = new UploadBatch();
    uploadBatch.addUploadTarget(UploadTarget.createDefault(projectAndVersion, codeLocationName, file));
    BdioUploadCodeLocationCreationRequest scanRequest = new BdioUploadCodeLocationCreationRequest(uploadBatchRunner, uploadBatch);
    codeLocationCreationService.createCodeLocations(scanRequest);
    // now that the file is uploaded, we want to lookup the code location that was created by the upload. in this case we know the name of the code location that was specified in the bdio file
    Optional<CodeLocationView> optionalCodeLocationView = codeLocationService.getCodeLocationByName(codeLocationName);
    int maxAttempts = 6;
    int attempt = 0;
    while (!optionalCodeLocationView.isPresent() && attempt < maxAttempts) {
        // creating the code location can take a few seconds
        attempt++;
        Thread.sleep(5000);
        optionalCodeLocationView = codeLocationService.getCodeLocationByName(codeLocationName);
    }
    CodeLocationView codeLocationView = optionalCodeLocationView.get();
    // then we map the code location to a version
    String versionName = "27.0.0-SNAPSHOT";
    ProjectSyncModel projectSyncModel = ProjectSyncModel.createWithDefaults(projectAndVersion);
    projectService.createProject(projectSyncModel.createProjectRequest());
    projectVersionWrapper = projectService.getProjectVersion(projectAndVersion);
    List<CodeLocationView> versionCodeLocations = blackDuckApiClient.getAllResponses(projectVersionWrapper.get().getProjectVersionView().metaCodelocationsLink());
    assertTrue(versionCodeLocations.isEmpty());
    NotificationTaskRange notificationTaskRange = codeLocationCreationService.calculateCodeLocationRange();
    System.out.println(RestConstants.formatDate(notificationTaskRange.getStartDate()));
    System.out.println(RestConstants.formatDate(notificationTaskRange.getEndDate()));
    codeLocationService.mapCodeLocation(codeLocationView, projectVersionWrapper.get().getProjectVersionView());
    CodeLocationWaitResult waitResult = codeLocationCreationService.waitForCodeLocations(notificationTaskRange, projectAndVersion, new HashSet<>(Arrays.asList(codeLocationView.getName())), 1, 3 * 60);
    System.out.println("wait status: " + waitResult.getStatus());
    if (waitResult.getErrorMessage().isPresent()) {
        System.out.println(waitResult.getErrorMessage().get());
    }
    waitResult.getCodeLocationNames().stream().forEach(System.out::println);
    assertEquals(CodeLocationWaitResult.Status.COMPLETE, waitResult.getStatus());
    assertEquals(1, waitResult.getCodeLocationNames().size());
    assertTrue(waitResult.getCodeLocationNames().contains(codeLocationName));
    versionCodeLocations = blackDuckApiClient.getAllResponses(projectVersionWrapper.get().getProjectVersionView().metaCodelocationsLink());
    CodeLocationView versionCodeLocation = versionCodeLocations.get(0);
    assertEquals(codeLocationName, versionCodeLocation.getName());
}
Also used : ProjectSyncModel(com.synopsys.integration.blackduck.service.model.ProjectSyncModel) CodeLocationWaitResult(com.synopsys.integration.blackduck.codelocation.CodeLocationWaitResult) BdioUploadCodeLocationCreationRequest(com.synopsys.integration.blackduck.codelocation.bdiolegacy.BdioUploadCodeLocationCreationRequest) NotificationTaskRange(com.synopsys.integration.blackduck.service.model.NotificationTaskRange) IntLogger(com.synopsys.integration.log.IntLogger) BufferedIntLogger(com.synopsys.integration.log.BufferedIntLogger) BufferedIntLogger(com.synopsys.integration.log.BufferedIntLogger) CodeLocationView(com.synopsys.integration.blackduck.api.generated.view.CodeLocationView) UploadBatch(com.synopsys.integration.blackduck.codelocation.upload.UploadBatch) File(java.io.File) UploadBatchRunner(com.synopsys.integration.blackduck.codelocation.bdiolegacy.UploadBatchRunner) Test(org.junit.jupiter.api.Test)

Example 2 with UploadBatchRunner

use of com.synopsys.integration.blackduck.codelocation.bdiolegacy.UploadBatchRunner in project blackduck-common by blackducksoftware.

the class BdioUploadRecipeTest method testBdioUpload.

@Test
public void testBdioUpload() throws IntegrationException, InterruptedException {
    assertCodeLocationDoesNotExist();
    File file = BasicRecipe.restConnectionTestHelper.getFile("bdio/hub_common_bdio_with_project_section.jsonld");
    // in this case we can upload the bdio and it will be mapped to a project and version because it has the Project information within the bdio file
    IntLogger logger = new BufferedIntLogger();
    UploadBatchRunner uploadBatchRunner = new UploadBatchRunner(logger, blackDuckApiClient, apiDiscovery, BlackDuckServicesFactory.NO_THREAD_EXECUTOR_SERVICE);
    UploadBatch uploadBatch = new UploadBatch();
    uploadBatch.addUploadTarget(UploadTarget.createDefault(projectAndVersion, codeLocationName, file));
    BdioUploadCodeLocationCreationRequest scanRequest = new BdioUploadCodeLocationCreationRequest(uploadBatchRunner, uploadBatch);
    codeLocationCreationService.createCodeLocationsAndWait(scanRequest, 15 * 60);
    projectVersionWrapper = projectService.getProjectVersion(projectAndVersion);
    assertTrue(projectVersionWrapper.isPresent());
    List<CodeLocationView> versionCodeLocations = blackDuckApiClient.getAllResponses(projectVersionWrapper.get().getProjectVersionView().metaCodelocationsLink());
    assertEquals(1, versionCodeLocations.size());
    CodeLocationView versionCodeLocation = versionCodeLocations.get(0);
    assertEquals(codeLocationName, versionCodeLocation.getName());
}
Also used : CodeLocationView(com.synopsys.integration.blackduck.api.generated.view.CodeLocationView) BdioUploadCodeLocationCreationRequest(com.synopsys.integration.blackduck.codelocation.bdiolegacy.BdioUploadCodeLocationCreationRequest) UploadBatch(com.synopsys.integration.blackduck.codelocation.upload.UploadBatch) IntLogger(com.synopsys.integration.log.IntLogger) BufferedIntLogger(com.synopsys.integration.log.BufferedIntLogger) BufferedIntLogger(com.synopsys.integration.log.BufferedIntLogger) File(java.io.File) UploadBatchRunner(com.synopsys.integration.blackduck.codelocation.bdiolegacy.UploadBatchRunner) Test(org.junit.jupiter.api.Test)

Example 3 with UploadBatchRunner

use of com.synopsys.integration.blackduck.codelocation.bdiolegacy.UploadBatchRunner in project blackduck-common by blackducksoftware.

the class BasicRecipe method startRecipe.

@BeforeEach
public void startRecipe() throws IntegrationException {
    /*
         * the integration logger used to display log messages from our code
         * within a 3rd party integration environment
         */
    logger = new BufferedIntLogger();
    /*
         * any usage of Black Duck API's has to begin with a url for the Black Duck
         * server and either:
         *   an API key
         * --or--
         *   a username and a password (this is what we're using here)
         */
    BlackDuckServerConfig blackDuckServerConfig = restConnectionTestHelper.getBlackDuckServerConfig();
    /*
         * next, we need to create the pieces needed for the
         * BlackDuckServicesFactory, the wrapper to get/use all Black Duck API's
         */
    BlackDuckHttpClient blackDuckHttpClient;
    if (blackDuckServerConfig.getApiToken().isPresent()) {
        blackDuckHttpClient = blackDuckServerConfig.createApiTokenBlackDuckHttpClient(logger);
    } else {
        blackDuckHttpClient = blackDuckServerConfig.createCredentialsBlackDuckHttpClient(logger);
    }
    IntEnvironmentVariables intEnvironmentVariables = IntEnvironmentVariables.includeSystemEnv();
    blackDuckServicesFactory = new BlackDuckServicesFactory(intEnvironmentVariables, executorService, logger, blackDuckHttpClient);
    blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
    apiDiscovery = blackDuckServicesFactory.getApiDiscovery();
    projectService = blackDuckServicesFactory.createProjectService();
    projectUsersService = blackDuckServicesFactory.createProjectUsersService();
    projectBomService = blackDuckServicesFactory.createProjectBomService();
    codeLocationService = blackDuckServicesFactory.createCodeLocationService();
    notificationService = blackDuckServicesFactory.createNotificationService();
    codeLocationCreationService = blackDuckServicesFactory.createCodeLocationCreationService();
    policyRuleService = blackDuckServicesFactory.createPolicyRuleService();
    bdio2UploadService = blackDuckServicesFactory.createBdio2UploadService();
    uploadRunner = new UploadBatchRunner(logger, blackDuckApiClient, apiDiscovery, executorService);
}
Also used : IntEnvironmentVariables(com.synopsys.integration.util.IntEnvironmentVariables) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) BufferedIntLogger(com.synopsys.integration.log.BufferedIntLogger) UploadBatchRunner(com.synopsys.integration.blackduck.codelocation.bdiolegacy.UploadBatchRunner) BlackDuckServerConfig(com.synopsys.integration.blackduck.configuration.BlackDuckServerConfig) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

UploadBatchRunner (com.synopsys.integration.blackduck.codelocation.bdiolegacy.UploadBatchRunner)3 BufferedIntLogger (com.synopsys.integration.log.BufferedIntLogger)3 CodeLocationView (com.synopsys.integration.blackduck.api.generated.view.CodeLocationView)2 BdioUploadCodeLocationCreationRequest (com.synopsys.integration.blackduck.codelocation.bdiolegacy.BdioUploadCodeLocationCreationRequest)2 UploadBatch (com.synopsys.integration.blackduck.codelocation.upload.UploadBatch)2 IntLogger (com.synopsys.integration.log.IntLogger)2 File (java.io.File)2 Test (org.junit.jupiter.api.Test)2 CodeLocationWaitResult (com.synopsys.integration.blackduck.codelocation.CodeLocationWaitResult)1 BlackDuckServerConfig (com.synopsys.integration.blackduck.configuration.BlackDuckServerConfig)1 BlackDuckHttpClient (com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient)1 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)1 NotificationTaskRange (com.synopsys.integration.blackduck.service.model.NotificationTaskRange)1 ProjectSyncModel (com.synopsys.integration.blackduck.service.model.ProjectSyncModel)1 IntEnvironmentVariables (com.synopsys.integration.util.IntEnvironmentVariables)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1