Search in sources :

Example 1 with UploadBatch

use of com.synopsys.integration.blackduck.codelocation.upload.UploadBatch in project blackduck-common by blackducksoftware.

the class BdioUploadService method uploadBdioAndWait.

public UploadBatchOutput uploadBdioAndWait(UploadTarget uploadTarget, long timeoutInSeconds) throws IntegrationException, InterruptedException {
    UploadBatch uploadBatch = new UploadBatch();
    uploadBatch.addUploadTarget(uploadTarget);
    BdioUploadCodeLocationCreationRequest uploadRequest = new BdioUploadCodeLocationCreationRequest(uploadBatchRunner, uploadBatch);
    return uploadBdioAndWait(uploadRequest, timeoutInSeconds);
}
Also used : UploadBatch(com.synopsys.integration.blackduck.codelocation.upload.UploadBatch)

Example 2 with UploadBatch

use of com.synopsys.integration.blackduck.codelocation.upload.UploadBatch in project blackduck-common by blackducksoftware.

the class CreateProjectWithBdioAndVerifyBOMTest method testCreatingProject.

@Test
public void testCreatingProject() throws IntegrationException, InterruptedException {
    UploadBatch uploadBatch = new UploadBatch();
    uploadBatch.addUploadTarget(createUploadTarget(CODE_LOCATION_NAMES.get(0), BDIO_FILE_NAMES[0]));
    uploadBatch.addUploadTarget(createUploadTarget(CODE_LOCATION_NAMES.get(1), BDIO_FILE_NAMES[1]));
    Set<String> expectedCodeLocationNames = getCodeLocationNames(uploadBatch);
    uploadAndVerifyBdio(uploadBatch, expectedCodeLocationNames);
    uploadBatch.addUploadTarget(createUploadTarget(CODE_LOCATION_NAMES.get(2), BDIO_FILE_NAMES[2]));
    expectedCodeLocationNames = getCodeLocationNames(uploadBatch);
    uploadAndVerifyBdio(uploadBatch, expectedCodeLocationNames);
}
Also used : UploadBatch(com.synopsys.integration.blackduck.codelocation.upload.UploadBatch) Test(org.junit.jupiter.api.Test)

Example 3 with UploadBatch

use of com.synopsys.integration.blackduck.codelocation.upload.UploadBatch in project blackduck-common by blackducksoftware.

the class IntelligentPersistenceRecipeTest method uploadBdio2.

@Test
void uploadBdio2() throws IOException, IntegrationException, InterruptedException {
    Bdio2Factory bdio2Factory = new Bdio2Factory();
    // create the bdio2 metadata
    ZonedDateTime now = Instant.now().atZone(ZoneId.of("EST5EDT"));
    ProjectInfo projectInfo = ProjectInfo.nameVersion(PROJECT);
    BdioMetadata bdio2Metadata = bdio2Factory.createBdioMetadata(CODE_LOCATION_NAME, projectInfo, now);
    // create the bdio2 project
    Dependency projectDependency = Dependency.FACTORY.createMavenDependency("com.synopsys.integration", PROJECT.getName(), PROJECT.getVersion());
    // create a graph of one dependency
    Dependency dependency = Dependency.FACTORY.createMavenDependency("org.apache.commons", "commons-lang3", "3.11");
    ProjectDependencyGraph dependencyGraph = new ProjectDependencyGraph(projectDependency);
    dependencyGraph.addDirectDependency(dependency);
    // now, with metadata, a project, and a graph, we can create a bdio2 document and write out the file
    Bdio2Document bdio2Document = bdio2Factory.createBdio2Document(bdio2Metadata, dependencyGraph);
    File bdio2File = File.createTempFile("test_bdio2", ".bdio");
    bdio2File.createNewFile();
    bdio2File.deleteOnExit();
    Bdio2Writer bdio2Writer = new Bdio2Writer();
    bdio2Writer.writeBdioDocument(new FileOutputStream(bdio2File), bdio2Document);
    // using the file and the previously set values, we create the UploadBatch for uploading to Black Duck
    UploadBatch uploadBatch = new UploadBatch();
    uploadBatch.addUploadTarget(UploadTarget.createDefault(PROJECT, CODE_LOCATION_NAME, bdio2File));
    // now all the setup is done, we can upload the bdio2 file
    IntelligentPersistenceService intelligentPersistenceService = blackDuckServicesFactory.createIntelligentPersistenceService();
    UploadBatchOutput uploadBatchOutput = intelligentPersistenceService.uploadBdioAndWait(uploadBatch, 120);
    assertFalse(uploadBatchOutput.hasAnyFailures());
    // verify that we now have a bom with 1 component
    Optional<ProjectVersionWrapper> projectVersionWrapper = projectService.getProjectVersion(PROJECT);
    assertTrue(projectVersionWrapper.isPresent());
    List<ProjectVersionComponentVersionView> bomComponents = projectBomService.getComponentsForProjectVersion(projectVersionWrapper.get().getProjectVersionView());
    assertEquals(1, bomComponents.size());
}
Also used : UploadBatchOutput(com.synopsys.integration.blackduck.codelocation.upload.UploadBatchOutput) BdioMetadata(com.blackducksoftware.bdio2.BdioMetadata) Bdio2Writer(com.synopsys.integration.blackduck.bdio2.util.Bdio2Writer) Bdio2Document(com.synopsys.integration.blackduck.bdio2.model.Bdio2Document) ProjectDependencyGraph(com.synopsys.integration.bdio.graph.ProjectDependencyGraph) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) Bdio2Factory(com.synopsys.integration.blackduck.bdio2.util.Bdio2Factory) IntelligentPersistenceService(com.synopsys.integration.blackduck.codelocation.intelligentpersistence.IntelligentPersistenceService) ZonedDateTime(java.time.ZonedDateTime) FileOutputStream(java.io.FileOutputStream) ProjectInfo(com.synopsys.integration.blackduck.bdio2.model.ProjectInfo) UploadBatch(com.synopsys.integration.blackduck.codelocation.upload.UploadBatch) File(java.io.File) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView) Test(org.junit.jupiter.api.Test)

Example 4 with UploadBatch

use of com.synopsys.integration.blackduck.codelocation.upload.UploadBatch 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 5 with UploadBatch

use of com.synopsys.integration.blackduck.codelocation.upload.UploadBatch 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)

Aggregations

UploadBatch (com.synopsys.integration.blackduck.codelocation.upload.UploadBatch)13 UploadBatchOutput (com.synopsys.integration.blackduck.codelocation.upload.UploadBatchOutput)6 File (java.io.File)6 Test (org.junit.jupiter.api.Test)6 BdioUploadCodeLocationCreationRequest (com.synopsys.integration.blackduck.codelocation.bdiolegacy.BdioUploadCodeLocationCreationRequest)4 ProjectDependencyGraph (com.synopsys.integration.bdio.graph.ProjectDependencyGraph)3 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)3 BdioUploadService (com.synopsys.integration.blackduck.codelocation.bdiolegacy.BdioUploadService)3 UploadTarget (com.synopsys.integration.blackduck.codelocation.upload.UploadTarget)3 NameVersion (com.synopsys.integration.util.NameVersion)3 BdioMetadata (com.blackducksoftware.bdio2.BdioMetadata)2 CodeLocationView (com.synopsys.integration.blackduck.api.generated.view.CodeLocationView)2 ProjectVersionComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)2 Bdio2Document (com.synopsys.integration.blackduck.bdio2.model.Bdio2Document)2 ProjectInfo (com.synopsys.integration.blackduck.bdio2.model.ProjectInfo)2 Bdio2Factory (com.synopsys.integration.blackduck.bdio2.util.Bdio2Factory)2 Bdio2Writer (com.synopsys.integration.blackduck.bdio2.util.Bdio2Writer)2 UploadBatchRunner (com.synopsys.integration.blackduck.codelocation.bdiolegacy.UploadBatchRunner)2 UploadOutput (com.synopsys.integration.blackduck.codelocation.upload.UploadOutput)2 ProjectVersionWrapper (com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper)2