Search in sources :

Example 1 with BlackDuckFortifyMapperGroup

use of com.blackducksoftware.integration.fortify.batch.model.BlackDuckFortifyMapperGroup in project hub-fortify-ssc-integration-service by blackducksoftware.

the class Initializer method execute.

@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
    logger.info("Started MappingParserTask");
    // Delete the files that are error out in previous run
    Arrays.stream(new File(propertyConstants.getReportDir()).listFiles()).forEach(File::delete);
    logger.debug("Found Mapping file:: " + propertyConstants.getMappingJsonPath());
    // Create the mapping between Hub and Fortify
    final List<BlackDuckFortifyMapperGroup> groupMap = mappingParser.createMapping(propertyConstants.getMappingJsonPath());
    logger.info("blackDuckFortifyMappers :" + groupMap.toString());
    // Create the threads for parallel processing
    ExecutorService exec = Executors.newFixedThreadPool(propertyConstants.getMaximumThreadSize());
    List<Future<?>> futures = new ArrayList<>(groupMap.size());
    for (BlackDuckFortifyMapperGroup blackDuckFortifyMapperGroup : groupMap) {
        futures.add(exec.submit(new BlackDuckFortifyPushThread(blackDuckFortifyMapperGroup, hubServices, fortifyFileTokenApi, fortifyUploadApi, propertyConstants)));
    }
    for (Future<?> f : futures) {
        // wait for a processor to complete
        f.get();
    }
    jobStatus = true;
    logger.info("After all threads processing");
    return RepeatStatus.FINISHED;
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) BlackDuckFortifyMapperGroup(com.blackducksoftware.integration.fortify.batch.model.BlackDuckFortifyMapperGroup) File(java.io.File)

Example 2 with BlackDuckFortifyMapperGroup

use of com.blackducksoftware.integration.fortify.batch.model.BlackDuckFortifyMapperGroup in project hub-fortify-ssc-integration-service by blackducksoftware.

the class MappingParser method buildGroupedMappings.

/**
 * This method, groups multiple Hub projects mapped to the same Fortify application.
 *
 * @param blackDuckFortifyMappers
 * @return
 * @throws IOException
 * @throws IntegrationException
 */
private List<BlackDuckFortifyMapperGroup> buildGroupedMappings(List<BlackDuckFortifyMapper> blackDuckFortifyMappers) throws IOException, IntegrationException {
    Map<String, BlackDuckFortifyMapperGroup> mappings = new HashMap<>();
    try {
        for (BlackDuckFortifyMapper blackDuckFortifyMapper : blackDuckFortifyMappers) {
            int applicationId;
            List<HubProjectVersion> hubProjectVersions = new ArrayList<>();
            BlackDuckFortifyMapperGroup blackDuckFortifyMapperGroup;
            HubProjectVersion hubProjectVersion = new HubProjectVersion(blackDuckFortifyMapper.getHubProject(), blackDuckFortifyMapper.getHubProjectVersion());
            String key = blackDuckFortifyMapper.getFortifyApplication() + '_' + blackDuckFortifyMapper.getFortifyApplicationVersion();
            if (mappings.containsKey(key)) {
                blackDuckFortifyMapperGroup = mappings.get(key);
                hubProjectVersions = blackDuckFortifyMapperGroup.getHubProjectVersion();
                applicationId = blackDuckFortifyMapperGroup.getFortifyApplicationId();
            } else {
                applicationId = getFortifyApplicationId(blackDuckFortifyMapper);
            }
            hubProjectVersions.add(hubProjectVersion);
            blackDuckFortifyMapperGroup = new BlackDuckFortifyMapperGroup(blackDuckFortifyMapper.getFortifyApplication(), blackDuckFortifyMapper.getFortifyApplicationVersion(), hubProjectVersions, applicationId);
            mappings.put(key, blackDuckFortifyMapperGroup);
        }
    } catch (IOException ioe) {
        logger.error(ioe.getMessage(), ioe);
        throw new IOException(ioe);
    }
    return new ArrayList<>(mappings.values());
}
Also used : HubProjectVersion(com.blackducksoftware.integration.fortify.batch.model.HubProjectVersion) HashMap(java.util.HashMap) BlackDuckFortifyMapper(com.blackducksoftware.integration.fortify.batch.model.BlackDuckFortifyMapper) ArrayList(java.util.ArrayList) BlackDuckFortifyMapperGroup(com.blackducksoftware.integration.fortify.batch.model.BlackDuckFortifyMapperGroup) IOException(java.io.IOException) JsonIOException(com.google.gson.JsonIOException)

Aggregations

BlackDuckFortifyMapperGroup (com.blackducksoftware.integration.fortify.batch.model.BlackDuckFortifyMapperGroup)2 ArrayList (java.util.ArrayList)2 BlackDuckFortifyMapper (com.blackducksoftware.integration.fortify.batch.model.BlackDuckFortifyMapper)1 HubProjectVersion (com.blackducksoftware.integration.fortify.batch.model.HubProjectVersion)1 JsonIOException (com.google.gson.JsonIOException)1 File (java.io.File)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1