Search in sources :

Example 6 with UploadBatchOutput

use of com.synopsys.integration.blackduck.codelocation.upload.UploadBatchOutput in project synopsys-detect by blackducksoftware.

the class BdioUploadOperation method uploadBdioFiles.

public BdioUploadResult uploadBdioFiles(BdioResult bdioResult) throws DetectUserFriendlyException {
    UploadBatch uploadBatch = createBatch(bdioResult);
    CodeLocationCreationData<UploadBatchOutput> response;
    try {
        response = executeUpload(uploadBatch);
    } catch (IntegrationException ex) {
        logger.error("Error uploading bdio files", ex);
        throw new DetectUserFriendlyException("Error uploading bdio files", ex, ExitCodeType.FAILURE_BLACKDUCK_FEATURE_ERROR);
    }
    checkForUploadFailure(response);
    return new BdioUploadResult(response);
}
Also used : UploadBatchOutput(com.synopsys.integration.blackduck.codelocation.upload.UploadBatchOutput) DetectUserFriendlyException(com.synopsys.integration.detect.configuration.DetectUserFriendlyException) IntegrationException(com.synopsys.integration.exception.IntegrationException) BdioUploadResult(com.synopsys.integration.detect.lifecycle.run.operation.blackduck.BdioUploadResult) UploadBatch(com.synopsys.integration.blackduck.codelocation.upload.UploadBatch)

Example 7 with UploadBatchOutput

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

the class UploadBatchRunner method executeUploads.

public UploadBatchOutput executeUploads(UploadBatch uploadBatch) throws BlackDuckIntegrationException {
    logger.info("Starting the codelocation file uploads.");
    UploadBatchOutput uploadBatchOutput = uploadTargets(uploadBatch);
    logger.info("Completed the codelocation file uploads.");
    return uploadBatchOutput;
}
Also used : UploadBatchOutput(com.synopsys.integration.blackduck.codelocation.upload.UploadBatchOutput)

Example 8 with UploadBatchOutput

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

the class IntelligentPersistenceBatchRunner method uploadTargets.

private UploadBatchOutput uploadTargets(UploadBatch uploadBatch, long timeout) throws BlackDuckIntegrationException {
    List<UploadOutput> uploadOutputs = new ArrayList<>();
    try {
        List<IntelligentPersistenceCallable> callables = createCallables(uploadBatch, timeout);
        List<Future<UploadOutput>> submitted = new ArrayList<>();
        for (IntelligentPersistenceCallable callable : callables) {
            submitted.add(executorService.submit(callable));
        }
        for (Future<UploadOutput> future : submitted) {
            UploadOutput uploadOutput = future.get();
            uploadOutputs.add(uploadOutput);
        }
    } catch (Exception e) {
        throw new BlackDuckIntegrationException(String.format("Encountered a problem uploading a file: %s", e.getMessage()), e);
    }
    return new UploadBatchOutput(uploadOutputs);
}
Also used : UploadBatchOutput(com.synopsys.integration.blackduck.codelocation.upload.UploadBatchOutput) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) UploadOutput(com.synopsys.integration.blackduck.codelocation.upload.UploadOutput) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException)

Example 9 with UploadBatchOutput

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

the class UploadBdio2BatchRunner method uploadTargets.

private UploadBatchOutput uploadTargets(UploadBatch uploadBatch) throws BlackDuckIntegrationException {
    List<UploadOutput> uploadOutputs = new ArrayList<>();
    try {
        List<UploadBdio2Callable> callables = createCallables(uploadBatch);
        List<Future<UploadOutput>> submitted = new ArrayList<>();
        for (UploadBdio2Callable callable : callables) {
            submitted.add(executorService.submit(callable));
        }
        for (Future<UploadOutput> future : submitted) {
            UploadOutput uploadOutput = future.get();
            uploadOutputs.add(uploadOutput);
        }
    } catch (Exception e) {
        throw new BlackDuckIntegrationException(String.format("Encountered a problem uploading a file: %s", e.getMessage()), e);
    }
    return new UploadBatchOutput(uploadOutputs);
}
Also used : UploadBatchOutput(com.synopsys.integration.blackduck.codelocation.upload.UploadBatchOutput) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) UploadOutput(com.synopsys.integration.blackduck.codelocation.upload.UploadOutput) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException)

Example 10 with UploadBatchOutput

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

the class Bdio2UploadRecipeTest 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 = new ProjectInfo(PROJECT, GROUP_NAME, // TODO: What is this supposed to look like? Only used for chunking? JM-04/2022
    null, new GitInfo(new URL("https://github.com/blackducksoftware/blackduck-common"), "4a1f431d7aa4ac15f755edd5de004f07d36ae89a", "master"));
    BdioMetadata bdio2Metadata = bdio2Factory.createBdioMetadata(CODE_LOCATION_NAME, projectInfo, now);
    // create a graph of one dependency
    Dependency projectDependency = Dependency.FACTORY.createMavenDependency(GROUP_NAME, PROJECT.getName(), PROJECT.getVersion());
    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
    UploadBatchOutput uploadBatchOutput = bdio2UploadService.uploadBdioAndWait(uploadBatch, 120);
    assertFalse(uploadBatchOutput.hasAnyFailures());
    Optional<ProjectVersionWrapper> projectVersionWrapper = projectService.getProjectVersion(PROJECT);
    assertTrue(projectVersionWrapper.isPresent());
    // Verify project headers are being set correctly
    String projectName = projectVersionWrapper.get().getProjectView().getName();
    String projectVersionName = projectVersionWrapper.get().getProjectVersionView().getVersionName();
    assertEquals(PROJECT, new NameVersion(projectName, projectVersionName));
    assertEquals(PROJECT.getName(), bdio2Document.getBdioMetadata().get(Bdio.DataProperty.project.toString()));
    assertEquals(PROJECT.getVersion(), bdio2Document.getBdioMetadata().get(Bdio.DataProperty.projectVersion.toString()));
    assertEquals(GROUP_NAME, bdio2Document.getBdioMetadata().get(Bdio.DataProperty.projectGroup.toString()));
    // verify that we now have a bom with 1 component
    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) NameVersion(com.synopsys.integration.util.NameVersion) ProjectDependencyGraph(com.synopsys.integration.bdio.graph.ProjectDependencyGraph) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) Bdio2Factory(com.synopsys.integration.blackduck.bdio2.util.Bdio2Factory) GitInfo(com.synopsys.integration.blackduck.bdio2.model.GitInfo) URL(java.net.URL) 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)

Aggregations

UploadBatchOutput (com.synopsys.integration.blackduck.codelocation.upload.UploadBatchOutput)13 UploadBatch (com.synopsys.integration.blackduck.codelocation.upload.UploadBatch)6 UploadOutput (com.synopsys.integration.blackduck.codelocation.upload.UploadOutput)5 BdioUploadService (com.synopsys.integration.blackduck.codelocation.bdiolegacy.BdioUploadService)4 File (java.io.File)4 ProjectDependencyGraph (com.synopsys.integration.bdio.graph.ProjectDependencyGraph)3 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)3 BlackDuckIntegrationException (com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException)3 NameVersion (com.synopsys.integration.util.NameVersion)3 ArrayList (java.util.ArrayList)3 Future (java.util.concurrent.Future)3 Test (org.junit.jupiter.api.Test)3 BdioMetadata (com.blackducksoftware.bdio2.BdioMetadata)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 BdioUploadCodeLocationCreationRequest (com.synopsys.integration.blackduck.codelocation.bdiolegacy.BdioUploadCodeLocationCreationRequest)2 ProjectVersionWrapper (com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper)2