Search in sources :

Example 6 with ExecutionContext

use of org.springframework.batch.item.ExecutionContext in project jvarkit by lindenb.

the class VariantContextBatchWriter method open.

@Override
public void open(final ExecutionContext executionContext) throws ItemStreamException {
    if (this.filenameFactory == null)
        throw new ItemStreamException("resource is not defined");
    try {
        final String filename = this.filenameFactory.apply(executionContext);
        if (StringUtil.isBlank(filename))
            throw new ItemStreamException("No output file defined.");
        if (LOG.isInfoEnabled())
            LOG.info("Opening " + filename + " for writing");
        if (!Arrays.stream(IOUtil.VCF_EXTENSIONS).anyMatch(SUFF -> filename.endsWith(SUFF))) {
            throw new ItemStreamException("Bad extension for a VCF file:" + filename);
        }
        final File vcfFile = new File(filename);
        VCFHeader header = SpringBatchUtils.getVcfHeader(executionContext);
        final VariantContextWriterBuilder vcwb = new VariantContextWriterBuilder();
        vcwb.setOutputFile(vcfFile);
        if (this.reference != null) {
            final SAMSequenceDictionary dic = SAMSequenceDictionaryExtractor.extractDictionary(this.reference);
            vcwb.setReferenceDictionary(dic);
            if (header.getSequenceDictionary() == null) {
                header = new VCFHeader(header);
                header.setSequenceDictionary(dic);
            }
        } else {
            vcwb.setReferenceDictionary(header.getSequenceDictionary());
        }
        vcwb.setCreateMD5(this.createMD5);
        this.vcw = vcwb.build();
        this.vcw.writeHeader(header);
    } catch (final Exception err) {
        priv_close();
        throw new ItemStreamException(err);
    }
}
Also used : Arrays(java.util.Arrays) ItemStreamException(org.springframework.batch.item.ItemStreamException) IOUtil(htsjdk.samtools.util.IOUtil) VCFHeader(htsjdk.variant.vcf.VCFHeader) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary) VariantContextWriterBuilder(htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder) Function(java.util.function.Function) File(java.io.File) ExecutionContext(org.springframework.batch.item.ExecutionContext) ResourceAwareItemWriterItemStream(org.springframework.batch.item.file.ResourceAwareItemWriterItemStream) List(java.util.List) StringUtil(htsjdk.samtools.util.StringUtil) VariantContextWriter(htsjdk.variant.variantcontext.writer.VariantContextWriter) VariantContext(htsjdk.variant.variantcontext.VariantContext) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) SAMSequenceDictionaryExtractor(htsjdk.variant.utils.SAMSequenceDictionaryExtractor) Resource(org.springframework.core.io.Resource) CloserUtil(htsjdk.samtools.util.CloserUtil) VariantContextWriterBuilder(htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder) VCFHeader(htsjdk.variant.vcf.VCFHeader) ItemStreamException(org.springframework.batch.item.ItemStreamException) File(java.io.File) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary) ItemStreamException(org.springframework.batch.item.ItemStreamException)

Example 7 with ExecutionContext

use of org.springframework.batch.item.ExecutionContext in project pinpoint by naver.

the class DefaultDividerTest method devide.

@Test
public void devide() {
    DefaultDivider defaultDivider = new DefaultDivider();
    Map<String, ExecutionContext> map = defaultDivider.divide("test_partition", "test");
    assertEquals(1, map.size());
}
Also used : ExecutionContext(org.springframework.batch.item.ExecutionContext) DefaultDivider(com.navercorp.pinpoint.batch.common.DefaultDivider) Test(org.junit.Test)

Example 8 with ExecutionContext

use of org.springframework.batch.item.ExecutionContext in project pinpoint by naver.

the class AlarmReaderTest method readTest3.

@Test
public void readTest3() {
    StepExecution stepExecution = new StepExecution("alarmStep", null);
    ExecutionContext executionContext = new ExecutionContext();
    stepExecution.setExecutionContext(executionContext);
    AlarmServiceImpl alarmService = new AlarmServiceImpl(mock(AlarmDao.class), mock(WebhookSendInfoDao.class)) {

        @Override
        public List<Rule> selectRuleByApplicationId(String applicationId) {
            return new LinkedList<>();
        }
    };
    AlarmReader reader = new AlarmReader(dataCollectorFactory, applicationIndexDao, alarmService);
    reader.beforeStep(stepExecution);
    assertNull(reader.read());
}
Also used : ExecutionContext(org.springframework.batch.item.ExecutionContext) WebhookSendInfoDao(com.navercorp.pinpoint.web.dao.WebhookSendInfoDao) AlarmServiceImpl(com.navercorp.pinpoint.web.service.AlarmServiceImpl) Rule(com.navercorp.pinpoint.web.alarm.vo.Rule) StepExecution(org.springframework.batch.core.StepExecution) AlarmDao(com.navercorp.pinpoint.web.dao.AlarmDao) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 9 with ExecutionContext

use of org.springframework.batch.item.ExecutionContext in project pinpoint by naver.

the class ReaderTest method readTest2.

@Test
public void readTest2() {
    StepExecution stepExecution = new StepExecution("alarmStep", null);
    ExecutionContext executionContext = new ExecutionContext();
    executionContext.put(AlarmPartitioner.PARTITION_NUMBER, 2);
    stepExecution.setExecutionContext(executionContext);
    AlarmReader reader = new AlarmReader(dataCollectorFactory, applicationIndexDao, alarmService);
    reader.beforeStep(stepExecution);
    for (int i = 0; i < 2; i++) {
        assertNotNull(reader.read());
    }
    assertNull(reader.read());
}
Also used : ExecutionContext(org.springframework.batch.item.ExecutionContext) StepExecution(org.springframework.batch.core.StepExecution) Test(org.junit.Test)

Example 10 with ExecutionContext

use of org.springframework.batch.item.ExecutionContext in project pinpoint by naver.

the class ReaderTest method readTest.

@Test
public void readTest() {
    StepExecution stepExecution = new StepExecution("alarmStep", null);
    ExecutionContext executionContext = new ExecutionContext();
    executionContext.put(AlarmPartitioner.PARTITION_NUMBER, 1);
    stepExecution.setExecutionContext(executionContext);
    AlarmReader reader = new AlarmReader(dataCollectorFactory, applicationIndexDao, alarmService);
    reader.beforeStep(stepExecution);
    for (int i = 0; i < 5; i++) {
        assertNotNull(reader.read());
    }
    assertNull(reader.read());
}
Also used : ExecutionContext(org.springframework.batch.item.ExecutionContext) StepExecution(org.springframework.batch.core.StepExecution) Test(org.junit.Test)

Aggregations

ExecutionContext (org.springframework.batch.item.ExecutionContext)17 Test (org.junit.Test)6 StepExecution (org.springframework.batch.core.StepExecution)5 HashMap (java.util.HashMap)4 Rule (com.navercorp.pinpoint.web.alarm.vo.Rule)2 AlarmServiceImpl (com.navercorp.pinpoint.web.service.AlarmServiceImpl)2 LinkedList (java.util.LinkedList)2 Line (org.baeldung.taskletsvschunks.model.Line)2 Resource (org.springframework.core.io.Resource)2 DefaultDivider (com.navercorp.pinpoint.batch.common.DefaultDivider)1 AlarmDao (com.navercorp.pinpoint.web.dao.AlarmDao)1 WebhookSendInfoDao (com.navercorp.pinpoint.web.dao.WebhookSendInfoDao)1 AbstractTest (cz.mzk.recordmanager.server.AbstractTest)1 LongValueRowMapper (cz.mzk.recordmanager.server.jdbc.LongValueRowMapper)1 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)1 CloserUtil (htsjdk.samtools.util.CloserUtil)1 IOUtil (htsjdk.samtools.util.IOUtil)1 StringUtil (htsjdk.samtools.util.StringUtil)1 SAMSequenceDictionaryExtractor (htsjdk.variant.utils.SAMSequenceDictionaryExtractor)1 VariantContext (htsjdk.variant.variantcontext.VariantContext)1