Search in sources :

Example 6 with Files

use of org.apache.flink.shaded.guava30.com.google.common.io.Files in project flink by apache.

the class UnalignedCheckpointStressITCase method discoverRetainedCheckpoint.

private File discoverRetainedCheckpoint() throws Exception {
    // structure: root/attempt/checkpoint/_metadata
    File rootDir = temporaryFolder.getRoot();
    Path checkpointDir = null;
    for (int i = 0; i <= 1000 && checkpointDir == null; i++) {
        Thread.sleep(5);
        try (Stream<Path> files = Files.walk(Paths.get(rootDir.getPath()))) {
            checkpointDir = files.filter(Files::isRegularFile).filter(path -> path.endsWith("_metadata")).map(path -> path.getParent()).sorted(Comparator.comparingInt(UnalignedCheckpointStressITCase::getCheckpointNumberFromPath)).reduce((first, second) -> second).orElse(null);
        }
    }
    if (checkpointDir == null) {
        List<Path> files = Files.walk(Paths.get(rootDir.getPath())).collect(Collectors.toList());
        throw new IllegalStateException("Failed to find _metadata file among " + files);
    }
    return checkpointDir.toFile();
}
Also used : Path(java.nio.file.Path) Deadline(org.apache.flink.api.common.time.Deadline) TumblingProcessingTimeWindows(org.apache.flink.streaming.api.windowing.assigners.TumblingProcessingTimeWindows) FileUtils(org.apache.flink.util.FileUtils) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) KeyedCoProcessFunction(org.apache.flink.streaming.api.functions.co.KeyedCoProcessFunction) ExceptionUtils(org.apache.flink.util.ExceptionUtils) CHECKPOINTS_DIRECTORY(org.apache.flink.configuration.CheckpointingOptions.CHECKPOINTS_DIRECTORY) FunctionSnapshotContext(org.apache.flink.runtime.state.FunctionSnapshotContext) MapFunction(org.apache.flink.api.common.functions.MapFunction) MiniClusterResourceConfiguration(org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration) ListState(org.apache.flink.api.common.state.ListState) Matcher(java.util.regex.Matcher) TestUtils.submitJobAndWaitForResult(org.apache.flink.test.util.TestUtils.submitJobAndWaitForResult) CheckpointListener(org.apache.flink.api.common.state.CheckpointListener) After(org.junit.After) Level(org.slf4j.event.Level) Duration(java.time.Duration) StreamGraph(org.apache.flink.streaming.api.graph.StreamGraph) TestLogger(org.apache.flink.util.TestLogger) ListStateDescriptor(org.apache.flink.api.common.state.ListStateDescriptor) FsStateChangelogStorageFactory(org.apache.flink.changelog.fs.FsStateChangelogStorageFactory) ClassRule(org.junit.ClassRule) Path(java.nio.file.Path) NetworkActionsLogger(org.apache.flink.runtime.io.network.logger.NetworkActionsLogger) CheckpointedFunction(org.apache.flink.streaming.api.checkpoint.CheckpointedFunction) ExpectedTestException(org.apache.flink.runtime.operators.testutils.ExpectedTestException) FunctionInitializationContext(org.apache.flink.runtime.state.FunctionInitializationContext) DataStreamUtils(org.apache.flink.streaming.api.datastream.DataStreamUtils) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) List(java.util.List) Stream(java.util.stream.Stream) Optional(java.util.Optional) ParallelSourceFunction(org.apache.flink.streaming.api.functions.source.ParallelSourceFunction) Pattern(java.util.regex.Pattern) Iterables.getOnlyElement(org.apache.flink.shaded.guava30.com.google.common.collect.Iterables.getOnlyElement) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) RestartStrategies(org.apache.flink.api.common.restartstrategy.RestartStrategies) DataStreamSource(org.apache.flink.streaming.api.datastream.DataStreamSource) Collector(org.apache.flink.util.Collector) TimeWindow(org.apache.flink.streaming.api.windowing.windows.TimeWindow) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Nullable(javax.annotation.Nullable) Before(org.junit.Before) MAX_RETAINED_CHECKPOINTS(org.apache.flink.configuration.CheckpointingOptions.MAX_RETAINED_CHECKPOINTS) MiniClusterWithClientResource(org.apache.flink.test.util.MiniClusterWithClientResource) Time(org.apache.flink.streaming.api.windowing.time.Time) LogLevelRule(org.apache.flink.util.LogLevelRule) ExternalizedCheckpointCleanup(org.apache.flink.streaming.api.environment.CheckpointConfig.ExternalizedCheckpointCleanup) Files(java.nio.file.Files) Configuration(org.apache.flink.configuration.Configuration) SingleOutputStreamOperator(org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator) Test(org.junit.Test) IOException(java.io.IOException) ProcessWindowFunction(org.apache.flink.streaming.api.functions.windowing.ProcessWindowFunction) File(java.io.File) DataStream(org.apache.flink.streaming.api.datastream.DataStream) Rule(org.junit.Rule) Paths(java.nio.file.Paths) Comparator(java.util.Comparator) SavepointRestoreSettings(org.apache.flink.runtime.jobgraph.SavepointRestoreSettings) TemporaryFolder(org.junit.rules.TemporaryFolder) Preconditions.checkState(org.apache.flink.shaded.curator5.org.apache.curator.shaded.com.google.common.base.Preconditions.checkState) AbstractRichFunction(org.apache.flink.api.common.functions.AbstractRichFunction) Files(java.nio.file.Files) File(java.io.File)

Example 7 with Files

use of org.apache.flink.shaded.guava30.com.google.common.io.Files in project alluxio by Alluxio.

the class PinCommandMultipleMediaIntegrationTest method pinToMediumForceEviction.

@Test
public void pinToMediumForceEviction() throws Exception {
    FileSystem fileSystem = sLocalAlluxioClusterResource.get().getClient();
    FileSystemShell fsShell = new FileSystemShell(ServerConfiguration.global());
    AlluxioURI filePathA = new AlluxioURI("/testFileA");
    AlluxioURI dirPath = new AlluxioURI("/testDirA");
    AlluxioURI filePathB = new AlluxioURI(dirPath.getPath() + "/testFileB");
    AlluxioURI filePathC = new AlluxioURI("/testFileC");
    int fileSize = SIZE_BYTES / 2;
    FileSystemTestUtils.createByteFile(fileSystem, filePathA, WritePType.CACHE_THROUGH, fileSize);
    assertTrue(fileExists(fileSystem, filePathA));
    assertEquals(0, fsShell.run("pin", filePathA.toString(), "MEM"));
    URIStatus status = fileSystem.getStatus(filePathA);
    assertTrue(status.isPinned());
    assertTrue(status.getPinnedMediumTypes().contains("MEM"));
    fileSystem.createDirectory(dirPath);
    assertEquals(0, fsShell.run("pin", dirPath.toString(), "MEM"));
    FileSystemTestUtils.createByteFile(fileSystem, filePathB, WritePType.CACHE_THROUGH, fileSize);
    assertTrue(fileExists(fileSystem, filePathB));
    URIStatus statusB = fileSystem.getStatus(filePathB);
    assertTrue(statusB.isPinned());
    assertTrue(statusB.getPinnedMediumTypes().contains("MEM"));
    FileSystemTestUtils.createByteFile(fileSystem, filePathC, WritePType.THROUGH, fileSize);
    assertEquals(100, fileSystem.getStatus(filePathA).getInAlluxioPercentage());
    assertEquals(100, fileSystem.getStatus(filePathB).getInAlluxioPercentage());
    assertEquals(0, fileSystem.getStatus(filePathC).getInAlluxioPercentage());
    assertEquals(0, fsShell.run("pin", filePathC.toString(), "SSD"));
    // Verify files are replicated into the correct tier through job service
    CommonUtils.waitFor("File being loaded", () -> sJobCluster.getMaster().getJobMaster().listDetailed().stream().anyMatch(x -> x.getStatus().equals(Status.COMPLETED) && x.getName().equals("Replicate") && x.getAffectedPaths().contains(filePathC.getPath())), sWaitOptions);
    assertEquals(100, fileSystem.getStatus(filePathC).getInAlluxioPercentage());
    assertEquals(Constants.MEDIUM_MEM, fileSystem.getStatus(filePathA).getFileBlockInfos().get(0).getBlockInfo().getLocations().get(0).getMediumType());
    assertEquals(Constants.MEDIUM_MEM, fileSystem.getStatus(filePathB).getFileBlockInfos().get(0).getBlockInfo().getLocations().get(0).getMediumType());
    assertEquals(Constants.MEDIUM_SSD, fileSystem.getStatus(filePathC).getFileBlockInfos().get(0).getBlockInfo().getLocations().get(0).getMediumType());
    assertEquals(0, fsShell.run("unpin", filePathA.toString()));
    assertEquals(0, fsShell.run("pin", filePathC.toString(), "MEM"));
    status = fileSystem.getStatus(filePathA);
    assertFalse(status.isPinned());
    assertTrue(status.getPinnedMediumTypes().isEmpty());
    // Verify files are migrated from another tier into the correct tier through job service
    // Also verify that eviction works
    CommonUtils.waitFor("File being moved", () -> sJobCluster.getMaster().getJobMaster().listDetailed().stream().anyMatch(x -> x.getStatus().equals(Status.COMPLETED) && x.getName().equals("Move") && x.getAffectedPaths().contains(filePathC.getPath())), sWaitOptions);
    assertEquals(0, fileSystem.getStatus(filePathA).getInAlluxioPercentage());
    assertEquals(Constants.MEDIUM_MEM, fileSystem.getStatus(filePathC).getFileBlockInfos().get(0).getBlockInfo().getLocations().get(0).getMediumType());
}
Also used : BeforeClass(org.junit.BeforeClass) TestRule(org.junit.rules.TestRule) FileSystemTestUtils(alluxio.client.file.FileSystemTestUtils) Status(alluxio.job.wire.Status) PropertyKey(alluxio.conf.PropertyKey) WaitForOptions(alluxio.util.WaitForOptions) FileSystem(alluxio.client.file.FileSystem) Constants(alluxio.Constants) Files(com.google.common.io.Files) AlluxioURI(alluxio.AlluxioURI) ClassRule(org.junit.ClassRule) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Before(org.junit.Before) WritePType(alluxio.grpc.WritePType) FileSystemShell(alluxio.cli.fs.FileSystemShell) ServerConfiguration(alluxio.conf.ServerConfiguration) LocalAlluxioClusterResource(alluxio.testutils.LocalAlluxioClusterResource) LocalAlluxioJobCluster(alluxio.master.LocalAlluxioJobCluster) Assert.assertTrue(org.junit.Assert.assertTrue) AlluxioException(alluxio.exception.AlluxioException) Test(org.junit.Test) IOException(java.io.IOException) URIStatus(alluxio.client.file.URIStatus) Rule(org.junit.Rule) Assert.assertFalse(org.junit.Assert.assertFalse) Assert.assertEquals(org.junit.Assert.assertEquals) CommonUtils(alluxio.util.CommonUtils) FileSystem(alluxio.client.file.FileSystem) FileSystemShell(alluxio.cli.fs.FileSystemShell) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 8 with Files

use of org.apache.flink.shaded.guava30.com.google.common.io.Files in project java by wavefrontHQ.

the class QueueExporterTest method testQueueExporter.

@Test
public void testQueueExporter() throws Exception {
    File file = new File(File.createTempFile("proxyTestConverter", null).getPath() + ".queue");
    file.deleteOnExit();
    String bufferFile = file.getAbsolutePath();
    TaskQueueFactory taskQueueFactory = new TaskQueueFactoryImpl(bufferFile, false, false, 128);
    EntityPropertiesFactory entityPropFactory = new DefaultEntityPropertiesFactoryForTesting();
    QueueExporter qe = new QueueExporter(bufferFile, "2878", bufferFile + "-output", false, taskQueueFactory, entityPropFactory);
    BufferedWriter mockedWriter = EasyMock.createMock(BufferedWriter.class);
    reset(mockedWriter);
    HandlerKey key = HandlerKey.of(ReportableEntityType.POINT, "2878");
    TaskQueue<LineDelimitedDataSubmissionTask> queue = taskQueueFactory.getTaskQueue(key, 0);
    queue.clear();
    UUID proxyId = UUID.randomUUID();
    LineDelimitedDataSubmissionTask task = new LineDelimitedDataSubmissionTask(null, proxyId, new DefaultEntityPropertiesForTesting(), queue, "wavefront", ReportableEntityType.POINT, "2878", ImmutableList.of("item1", "item2", "item3"), () -> 12345L);
    task.enqueue(QueueingReason.RETRY);
    LineDelimitedDataSubmissionTask task2 = new LineDelimitedDataSubmissionTask(null, proxyId, new DefaultEntityPropertiesForTesting(), queue, "wavefront", ReportableEntityType.POINT, "2878", ImmutableList.of("item4", "item5"), () -> 12345L);
    task2.enqueue(QueueingReason.RETRY);
    mockedWriter.write("item1");
    mockedWriter.newLine();
    mockedWriter.write("item2");
    mockedWriter.newLine();
    mockedWriter.write("item3");
    mockedWriter.newLine();
    mockedWriter.write("item4");
    mockedWriter.newLine();
    mockedWriter.write("item5");
    mockedWriter.newLine();
    TaskQueue<EventDataSubmissionTask> queue2 = taskQueueFactory.getTaskQueue(HandlerKey.of(ReportableEntityType.EVENT, "2888"), 0);
    queue2.clear();
    EventDataSubmissionTask eventTask = new EventDataSubmissionTask(null, proxyId, new DefaultEntityPropertiesForTesting(), queue2, "2888", ImmutableList.of(new Event(ReportEvent.newBuilder().setStartTime(123456789L * 1000).setEndTime(123456789L * 1000 + 1).setName("Event name for testing").setHosts(ImmutableList.of("host1", "host2")).setDimensions(ImmutableMap.of("multi", ImmutableList.of("bar", "baz"))).setAnnotations(ImmutableMap.of("severity", "INFO")).setTags(ImmutableList.of("tag1")).build()), new Event(ReportEvent.newBuilder().setStartTime(123456789L * 1000).setEndTime(123456789L * 1000 + 1).setName("Event name for testing").setHosts(ImmutableList.of("host1", "host2")).setAnnotations(ImmutableMap.of("severity", "INFO")).build())), () -> 12345L);
    eventTask.enqueue(QueueingReason.RETRY);
    mockedWriter.write("@Event 123456789000 123456789001 \"Event name for testing\" " + "\"host\"=\"host1\" \"host\"=\"host2\" \"severity\"=\"INFO\" \"multi\"=\"bar\" " + "\"multi\"=\"baz\" \"tag\"=\"tag1\"");
    mockedWriter.newLine();
    mockedWriter.write("@Event 123456789000 123456789001 \"Event name for testing\" " + "\"host\"=\"host1\" \"host\"=\"host2\" \"severity\"=\"INFO\"");
    mockedWriter.newLine();
    TaskQueue<SourceTagSubmissionTask> queue3 = taskQueueFactory.getTaskQueue(HandlerKey.of(ReportableEntityType.SOURCE_TAG, "2898"), 0);
    queue3.clear();
    SourceTagSubmissionTask sourceTagTask = new SourceTagSubmissionTask(null, new DefaultEntityPropertiesForTesting(), queue3, "2898", new SourceTag(ReportSourceTag.newBuilder().setOperation(SourceOperationType.SOURCE_TAG).setAction(SourceTagAction.SAVE).setSource("testSource").setAnnotations(ImmutableList.of("newtag1", "newtag2")).build()), () -> 12345L);
    sourceTagTask.enqueue(QueueingReason.RETRY);
    mockedWriter.write("@SourceTag action=save source=\"testSource\" \"newtag1\" \"newtag2\"");
    mockedWriter.newLine();
    expectLastCall().once();
    replay(mockedWriter);
    assertEquals(2, queue.size());
    qe.processQueue(queue, mockedWriter);
    assertEquals(0, queue.size());
    assertEquals(1, queue2.size());
    qe.processQueue(queue2, mockedWriter);
    assertEquals(0, queue2.size());
    assertEquals(1, queue3.size());
    qe.processQueue(queue3, mockedWriter);
    assertEquals(0, queue3.size());
    verify(mockedWriter);
    List<String> files = ConcurrentShardedQueueFile.listFiles(bufferFile, ".spool").stream().map(x -> x.replace(bufferFile + ".", "")).collect(Collectors.toList());
    assertEquals(3, files.size());
    assertTrue(files.contains("points.2878.0.spool_0000"));
    assertTrue(files.contains("events.2888.0.spool_0000"));
    assertTrue(files.contains("sourceTags.2898.0.spool_0000"));
    HandlerKey k1 = HandlerKey.of(ReportableEntityType.POINT, "2878");
    HandlerKey k2 = HandlerKey.of(ReportableEntityType.EVENT, "2888");
    HandlerKey k3 = HandlerKey.of(ReportableEntityType.SOURCE_TAG, "2898");
    files = ConcurrentShardedQueueFile.listFiles(bufferFile, ".spool");
    Set<HandlerKey> hk = QueueExporter.getValidHandlerKeys(files, "all");
    assertEquals(3, hk.size());
    assertTrue(hk.contains(k1));
    assertTrue(hk.contains(k2));
    assertTrue(hk.contains(k3));
    hk = QueueExporter.getValidHandlerKeys(files, "2878, 2898");
    assertEquals(2, hk.size());
    assertTrue(hk.contains(k1));
    assertTrue(hk.contains(k3));
    hk = QueueExporter.getValidHandlerKeys(files, "2888");
    assertEquals(1, hk.size());
    assertTrue(hk.contains(k2));
}
Also used : HandlerKey(com.wavefront.agent.handlers.HandlerKey) QueueingReason(com.wavefront.agent.data.QueueingReason) ReportSourceTag(wavefront.report.ReportSourceTag) ReportEvent(wavefront.report.ReportEvent) SourceOperationType(wavefront.report.SourceOperationType) ImmutableList(com.google.common.collect.ImmutableList) Event(com.wavefront.dto.Event) EasyMock.reset(org.easymock.EasyMock.reset) Files(com.google.common.io.Files) DefaultEntityPropertiesFactoryForTesting(com.wavefront.agent.data.DefaultEntityPropertiesFactoryForTesting) SourceTagSubmissionTask(com.wavefront.agent.data.SourceTagSubmissionTask) HandlerKey(com.wavefront.agent.handlers.HandlerKey) EasyMock.replay(org.easymock.EasyMock.replay) Charsets(com.google.common.base.Charsets) DefaultEntityPropertiesForTesting(com.wavefront.agent.data.DefaultEntityPropertiesForTesting) ImmutableMap(com.google.common.collect.ImmutableMap) EventDataSubmissionTask(com.wavefront.agent.data.EventDataSubmissionTask) BufferedWriter(java.io.BufferedWriter) EntityPropertiesFactory(com.wavefront.agent.data.EntityPropertiesFactory) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) EasyMock(org.easymock.EasyMock) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) File(java.io.File) SourceTag(com.wavefront.dto.SourceTag) EasyMock.expectLastCall(org.easymock.EasyMock.expectLastCall) ReportableEntityType(com.wavefront.data.ReportableEntityType) List(java.util.List) LineDelimitedDataSubmissionTask(com.wavefront.agent.data.LineDelimitedDataSubmissionTask) EasyMock.verify(org.easymock.EasyMock.verify) Assert.assertEquals(org.junit.Assert.assertEquals) SourceTagAction(wavefront.report.SourceTagAction) EventDataSubmissionTask(com.wavefront.agent.data.EventDataSubmissionTask) ReportSourceTag(wavefront.report.ReportSourceTag) SourceTag(com.wavefront.dto.SourceTag) LineDelimitedDataSubmissionTask(com.wavefront.agent.data.LineDelimitedDataSubmissionTask) DefaultEntityPropertiesFactoryForTesting(com.wavefront.agent.data.DefaultEntityPropertiesFactoryForTesting) EntityPropertiesFactory(com.wavefront.agent.data.EntityPropertiesFactory) BufferedWriter(java.io.BufferedWriter) SourceTagSubmissionTask(com.wavefront.agent.data.SourceTagSubmissionTask) ReportEvent(wavefront.report.ReportEvent) Event(com.wavefront.dto.Event) DefaultEntityPropertiesForTesting(com.wavefront.agent.data.DefaultEntityPropertiesForTesting) UUID(java.util.UUID) File(java.io.File) Test(org.junit.Test)

Example 9 with Files

use of org.apache.flink.shaded.guava30.com.google.common.io.Files in project mzmine2 by mzmine.

the class KovatsIndexExtractionDialog method addDialogComponents.

@Override
protected void addDialogComponents() {
    super.addDialogComponents();
    mainPanel.removeAll();
    mainPanel.getParent().remove(mainPanel);
    ddlKovats = new DelayedDocumentListener(e -> updateKovatsList());
    DelayedDocumentListener ddlUpdateChart = new DelayedDocumentListener(e -> updateChart());
    newMainPanel = new JPanel(new MigLayout("fill", "[right][grow,fill]", ""));
    getContentPane().add(newMainPanel, BorderLayout.SOUTH);
    JPanel pnCenter = new JPanel(new BorderLayout());
    getContentPane().add(pnCenter, BorderLayout.CENTER);
    pnChart = new JPanel(new BorderLayout());
    pnCenter.add(pnChart, BorderLayout.CENTER);
    Box sizedummy = new Box(BoxLayout.X_AXIS);
    sizedummy.setMinimumSize(new Dimension(200, 450));
    sizedummy.setPreferredSize(new Dimension(200, 450));
    pnChart.add(sizedummy, BorderLayout.CENTER);
    // left: Kovats: min max and list
    JPanel west = new JPanel(new BorderLayout());
    newMainPanel.add(west);
    // add min max
    JPanel pnKovatsParam = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 5));
    west.add(pnKovatsParam, BorderLayout.NORTH);
    minc = (IntegerComponent) getComponentForParameter(KovatsIndexExtractionParameters.minKovats);
    maxc = (IntegerComponent) getComponentForParameter(KovatsIndexExtractionParameters.maxKovats);
    minc.addDocumentListener(ddlKovats);
    maxc.addDocumentListener(ddlKovats);
    pnKovatsParam.add(new JLabel("Min carbon:"));
    pnKovatsParam.add(minc);
    pnKovatsParam.add(new JLabel("Max carbon:"));
    pnKovatsParam.add(maxc);
    // kovats list
    JPanel pnKovatsSelect = new JPanel(new BorderLayout());
    west.add(pnKovatsSelect, BorderLayout.CENTER);
    comboKovats = (MultiChoiceComponent) getComponentForParameter(KovatsIndexExtractionParameters.kovats);
    comboKovats.addValueChangeListener(() -> handleKovatsSelectionChange());
    pnKovatsSelect.add(comboKovats, BorderLayout.CENTER);
    // center: Chart and parameters
    JPanel center = new JPanel(new BorderLayout());
    newMainPanel.add(center);
    // all parameters on peak pick panel
    JPanel pnSouth = new JPanel(new BorderLayout());
    center.add(pnSouth, BorderLayout.SOUTH);
    JPanel pnPeakPick = new JPanel(new MigLayout("", "[right][]", ""));
    pnSouth.add(pnPeakPick, BorderLayout.CENTER);
    valuesComponent = (StringComponent) getComponentForParameter(KovatsIndexExtractionParameters.pickedKovatsValues);
    MZRangeComponent mzc = (MZRangeComponent) getComponentForParameter(KovatsIndexExtractionParameters.mzRange);
    RTRangeComponent rtc = (RTRangeComponent) getComponentForParameter(KovatsIndexExtractionParameters.rtRange);
    DoubleComponent noisec = (DoubleComponent) getComponentForParameter(KovatsIndexExtractionParameters.noiseLevel);
    DoubleComponent edgeRatioC = (DoubleComponent) getComponentForParameter(KovatsIndexExtractionParameters.ratioTopEdge);
    valuesComponent.addDocumentListener(new DelayedDocumentListener(e -> kovatsValuesChanged()));
    valuesComponent.setLayout(new GridLayout(1, 1));
    pnCenter.add(valuesComponent, BorderLayout.SOUTH);
    JPanel pnButtonFlow = new JPanel();
    pnPeakPick.add(pnButtonFlow, "cell 0 0 2 1");
    JButton btnUpdateChart = new JButton("Update chart");
    btnUpdateChart.addActionListener(e -> updateChart());
    pnButtonFlow.add(btnUpdateChart);
    JButton btnPickRT = new JButton("Pick peaks");
    btnPickRT.addActionListener(e -> pickRetentionTimes());
    pnButtonFlow.add(btnPickRT);
    JButton btnSaveFile = new JButton("Save to file");
    btnSaveFile.setToolTipText("Save Kovats index file");
    btnSaveFile.addActionListener(e -> saveToFile());
    pnButtonFlow.add(btnSaveFile);
    JButton btnLoad = new JButton("Load");
    btnLoad.setToolTipText("Load Kovats index file");
    btnLoad.addActionListener(e -> loadFile());
    pnButtonFlow.add(btnLoad);
    JButton btnCombineFiles = new JButton("Combine files");
    btnCombineFiles.setToolTipText("Select multiple Kovats index files to be combined into one");
    btnCombineFiles.addActionListener(e -> combineFiles());
    pnButtonFlow.add(btnCombineFiles);
    // add combo for raw data file
    dataFiles = MZmineCore.getProjectManager().getCurrentProject().getDataFiles();
    comboDataFileName = new JComboBox<RawDataFile>(dataFiles);
    comboDataFileName2 = new JComboBox<RawDataFile>(dataFiles);
    cbSecondRaw = new JCheckBox();
    initRawDataFileSelection();
    pnPeakPick.add(new JLabel("Raw data file(s)"), "cell 0 1");
    pnPeakPick.add(comboDataFileName);
    cbSecondRaw.addItemListener(e -> useSecondDataFile(cbSecondRaw.isSelected()));
    pnPeakPick.add(cbSecondRaw, "cell 0 2");
    pnPeakPick.add(comboDataFileName2);
    // direct alkane selection < CxH2x+1 >
    JPanel pnAlkaneSelect = new JPanel();
    Dimension dim = new Dimension(SIZE, SIZE);
    JButton btnPrevAlkane = new JButton(iconPrev);
    btnPrevAlkane.addActionListener(e -> setMzRangeByAlkane(-1));
    btnPrevAlkane.setPreferredSize(dim);
    btnPrevAlkane.setMaximumSize(dim);
    JButton btnNextAlkane = new JButton(iconNext);
    btnNextAlkane.addActionListener(e -> setMzRangeByAlkane(1));
    btnNextAlkane.setPreferredSize(dim);
    btnNextAlkane.setMaximumSize(dim);
    lbCurrentAlkane = new JLabel("");
    cbCurrentAlkaneSubH = new JCheckBox("-H");
    cbCurrentAlkaneSubH.setSelected(true);
    cbCurrentAlkaneSubH.addItemListener(e -> setMzRangeByAlkane(0));
    pnAlkaneSelect.add(btnPrevAlkane);
    pnAlkaneSelect.add(lbCurrentAlkane);
    pnAlkaneSelect.add(btnNextAlkane);
    pnAlkaneSelect.add(cbCurrentAlkaneSubH);
    pnPeakPick.add(pnAlkaneSelect, "cell 1 3");
    pnPeakPick.add(new JLabel("m/z range"), "cell 0 4");
    pnPeakPick.add(mzc);
    pnPeakPick.add(new JLabel(KovatsIndexExtractionParameters.rtRange.getName()), "cell 0 5");
    pnPeakPick.add(rtc);
    pnPeakPick.add(new JLabel(KovatsIndexExtractionParameters.noiseLevel.getName()), "cell 0 6");
    pnPeakPick.add(noisec);
    pnPeakPick.add(new JLabel(KovatsIndexExtractionParameters.ratioTopEdge.getName()), "cell 0 7");
    pnPeakPick.add(edgeRatioC);
    // add listeners
    comboDataFileName.addItemListener(e -> updateChart());
    mzc.addDocumentListener(ddlUpdateChart);
    rtc.addDocumentListener(ddlUpdateChart);
    // show
    revalidate();
    updateMinimumSize();
    pack();
    updateChart();
}
Also used : Color(java.awt.Color) StringComponent(net.sf.mzmine.parameters.parametertypes.StringComponent) Arrays(java.util.Arrays) FileAndPathUtil(net.sf.mzmine.util.files.FileAndPathUtil) ChartGestureHandler(net.sf.mzmine.chartbasics.gestures.ChartGestureHandler) ValueMarker(org.jfree.chart.plot.ValueMarker) MultiChoiceComponent(net.sf.mzmine.parameters.parametertypes.MultiChoiceComponent) ParameterSet(net.sf.mzmine.parameters.ParameterSet) Event(net.sf.mzmine.chartbasics.gestures.ChartGesture.Event) JFileChooser(javax.swing.JFileChooser) BorderLayout(java.awt.BorderLayout) JComboBox(javax.swing.JComboBox) Image(java.awt.Image) Key(net.sf.mzmine.chartbasics.gestures.ChartGesture.Key) Font(java.awt.Font) Range(com.google.common.collect.Range) MZRangeComponent(net.sf.mzmine.parameters.parametertypes.ranges.MZRangeComponent) Icon(javax.swing.Icon) Logger(java.util.logging.Logger) StandardCharsets(java.nio.charset.StandardCharsets) Box(javax.swing.Box) ChartGestureDragDiffEvent(net.sf.mzmine.chartbasics.gestures.ChartGestureDragDiffEvent) Dimension(java.awt.Dimension) List(java.util.List) Stream(java.util.stream.Stream) XYDataset(org.jfree.data.xy.XYDataset) Entry(java.util.Map.Entry) JCheckBox(javax.swing.JCheckBox) Entity(net.sf.mzmine.chartbasics.gestures.ChartGesture.Entity) RTRangeComponent(net.sf.mzmine.parameters.parametertypes.ranges.RTRangeComponent) BasicStroke(java.awt.BasicStroke) JPanel(javax.swing.JPanel) MZmineCore(net.sf.mzmine.main.MZmineCore) ColorPalettes(net.sf.mzmine.util.ColorPalettes) JTextField(javax.swing.JTextField) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) MzRangeFormulaCalculatorModule(net.sf.mzmine.modules.tools.mzrangecalculator.MzRangeFormulaCalculatorModule) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) ArrayUtils(org.apache.commons.lang3.ArrayUtils) NumberFormat(java.text.NumberFormat) Button(net.sf.mzmine.chartbasics.gestures.ChartGesture.Button) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) GridLayout(java.awt.GridLayout) IntegerComponent(net.sf.mzmine.parameters.parametertypes.IntegerComponent) FileNameComponent(net.sf.mzmine.parameters.parametertypes.filenames.FileNameComponent) DelayedDocumentListener(net.sf.mzmine.framework.listener.DelayedDocumentListener) Files(com.google.common.io.Files) ChartGesture(net.sf.mzmine.chartbasics.gestures.ChartGesture) TxtWriter(net.sf.mzmine.util.io.TxtWriter) ImageIcon(javax.swing.ImageIcon) TICPlot(net.sf.mzmine.modules.visualization.tic.TICPlot) ParameterSetupDialog(net.sf.mzmine.parameters.dialogs.ParameterSetupDialog) BoxLayout(javax.swing.BoxLayout) Stroke(java.awt.Stroke) FlowLayout(java.awt.FlowLayout) MZTolerance(net.sf.mzmine.parameters.parametertypes.tolerances.MZTolerance) JButton(javax.swing.JButton) KovatsIndex(net.sf.mzmine.modules.tools.kovats.KovatsValues.KovatsIndex) TICPlotType(net.sf.mzmine.modules.visualization.tic.TICPlotType) MigLayout(net.miginfocom.swing.MigLayout) Window(java.awt.Window) DecimalFormat(java.text.DecimalFormat) RawDataFilesSelection(net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesSelection) TICSumDataSet(net.sf.mzmine.modules.visualization.tic.TICSumDataSet) IOException(java.io.IOException) IonizationType(net.sf.mzmine.datamodel.IonizationType) File(java.io.File) Consumer(java.util.function.Consumer) RectangleInsets(org.jfree.chart.ui.RectangleInsets) TreeMap(java.util.TreeMap) ChartGestureDragDiffHandler(net.sf.mzmine.chartbasics.gestures.ChartGestureDragDiffHandler) JLabel(javax.swing.JLabel) RawDataFilesSelectionType(net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesSelectionType) DialogLoggerUtil(net.sf.mzmine.util.DialogLoggerUtil) DoubleComponent(net.sf.mzmine.parameters.parametertypes.DoubleComponent) DoubleComponent(net.sf.mzmine.parameters.parametertypes.DoubleComponent) JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) MigLayout(net.miginfocom.swing.MigLayout) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) JComboBox(javax.swing.JComboBox) Box(javax.swing.Box) JCheckBox(javax.swing.JCheckBox) Dimension(java.awt.Dimension) MZRangeComponent(net.sf.mzmine.parameters.parametertypes.ranges.MZRangeComponent) JCheckBox(javax.swing.JCheckBox) GridLayout(java.awt.GridLayout) BorderLayout(java.awt.BorderLayout) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) DelayedDocumentListener(net.sf.mzmine.framework.listener.DelayedDocumentListener) RTRangeComponent(net.sf.mzmine.parameters.parametertypes.ranges.RTRangeComponent)

Example 10 with Files

use of org.apache.flink.shaded.guava30.com.google.common.io.Files in project mzmine2 by mzmine.

the class KovatsIndexExtractionDialog method initRawDataFileSelection.

/**
 * Init raw data selection to last used raw data file or "kovats" or "dro"
 */
private void initRawDataFileSelection() {
    if (dataFiles != null && dataFiles.length <= 0)
        return;
    RawDataFilesSelection select = parameterSet.getParameter(KovatsIndexExtractionParameters.dataFiles).getValue();
    RawDataFile[] raw = null;
    // set to parameters files - if they exist in this project
    if (select != null && select.getMatchingRawDataFiles().length > 0) {
        RawDataFile[] exists = Arrays.stream(select.getMatchingRawDataFiles()).filter(r -> Arrays.stream(dataFiles).anyMatch(d -> r.getName().equals(d.getName()))).toArray(RawDataFile[]::new);
        if (exists.length > 0)
            raw = exists;
    }
    if (raw == null) {
        // find kovats or dro file
        // first use all kovats named files and then dro (max 2)
        RawDataFile[] kovats = Arrays.stream(dataFiles).filter(d -> d.getName().toLowerCase().contains("kovats")).toArray(RawDataFile[]::new);
        RawDataFile[] dro = Arrays.stream(dataFiles).filter(d -> d.getName().toLowerCase().contains("dro")).toArray(RawDataFile[]::new);
        // maximum of two files are chosen (0,1,2)
        int size = Math.min(2, kovats.length + dro.length);
        raw = new RawDataFile[size];
        for (int i = 0; i < raw.length; i++) {
            if (i < kovats.length)
                raw[i] = kovats[i];
            else
                raw[i] = dro[i - kovats.length];
        }
    }
    if (raw.length > 0) {
        selectedDataFile = raw;
        comboDataFileName.setSelectedItem(selectedDataFile[0]);
        if (raw.length > 1) {
            comboDataFileName2.setSelectedItem(selectedDataFile[1]);
        }
    }
}
Also used : Color(java.awt.Color) StringComponent(net.sf.mzmine.parameters.parametertypes.StringComponent) Arrays(java.util.Arrays) FileAndPathUtil(net.sf.mzmine.util.files.FileAndPathUtil) ChartGestureHandler(net.sf.mzmine.chartbasics.gestures.ChartGestureHandler) ValueMarker(org.jfree.chart.plot.ValueMarker) MultiChoiceComponent(net.sf.mzmine.parameters.parametertypes.MultiChoiceComponent) ParameterSet(net.sf.mzmine.parameters.ParameterSet) Event(net.sf.mzmine.chartbasics.gestures.ChartGesture.Event) JFileChooser(javax.swing.JFileChooser) BorderLayout(java.awt.BorderLayout) JComboBox(javax.swing.JComboBox) Image(java.awt.Image) Key(net.sf.mzmine.chartbasics.gestures.ChartGesture.Key) Font(java.awt.Font) Range(com.google.common.collect.Range) MZRangeComponent(net.sf.mzmine.parameters.parametertypes.ranges.MZRangeComponent) Icon(javax.swing.Icon) Logger(java.util.logging.Logger) StandardCharsets(java.nio.charset.StandardCharsets) Box(javax.swing.Box) ChartGestureDragDiffEvent(net.sf.mzmine.chartbasics.gestures.ChartGestureDragDiffEvent) Dimension(java.awt.Dimension) List(java.util.List) Stream(java.util.stream.Stream) XYDataset(org.jfree.data.xy.XYDataset) Entry(java.util.Map.Entry) JCheckBox(javax.swing.JCheckBox) Entity(net.sf.mzmine.chartbasics.gestures.ChartGesture.Entity) RTRangeComponent(net.sf.mzmine.parameters.parametertypes.ranges.RTRangeComponent) BasicStroke(java.awt.BasicStroke) JPanel(javax.swing.JPanel) MZmineCore(net.sf.mzmine.main.MZmineCore) ColorPalettes(net.sf.mzmine.util.ColorPalettes) JTextField(javax.swing.JTextField) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) MzRangeFormulaCalculatorModule(net.sf.mzmine.modules.tools.mzrangecalculator.MzRangeFormulaCalculatorModule) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) ArrayUtils(org.apache.commons.lang3.ArrayUtils) NumberFormat(java.text.NumberFormat) Button(net.sf.mzmine.chartbasics.gestures.ChartGesture.Button) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) GridLayout(java.awt.GridLayout) IntegerComponent(net.sf.mzmine.parameters.parametertypes.IntegerComponent) FileNameComponent(net.sf.mzmine.parameters.parametertypes.filenames.FileNameComponent) DelayedDocumentListener(net.sf.mzmine.framework.listener.DelayedDocumentListener) Files(com.google.common.io.Files) ChartGesture(net.sf.mzmine.chartbasics.gestures.ChartGesture) TxtWriter(net.sf.mzmine.util.io.TxtWriter) ImageIcon(javax.swing.ImageIcon) TICPlot(net.sf.mzmine.modules.visualization.tic.TICPlot) ParameterSetupDialog(net.sf.mzmine.parameters.dialogs.ParameterSetupDialog) BoxLayout(javax.swing.BoxLayout) Stroke(java.awt.Stroke) FlowLayout(java.awt.FlowLayout) MZTolerance(net.sf.mzmine.parameters.parametertypes.tolerances.MZTolerance) JButton(javax.swing.JButton) KovatsIndex(net.sf.mzmine.modules.tools.kovats.KovatsValues.KovatsIndex) TICPlotType(net.sf.mzmine.modules.visualization.tic.TICPlotType) MigLayout(net.miginfocom.swing.MigLayout) Window(java.awt.Window) DecimalFormat(java.text.DecimalFormat) RawDataFilesSelection(net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesSelection) TICSumDataSet(net.sf.mzmine.modules.visualization.tic.TICSumDataSet) IOException(java.io.IOException) IonizationType(net.sf.mzmine.datamodel.IonizationType) File(java.io.File) Consumer(java.util.function.Consumer) RectangleInsets(org.jfree.chart.ui.RectangleInsets) TreeMap(java.util.TreeMap) ChartGestureDragDiffHandler(net.sf.mzmine.chartbasics.gestures.ChartGestureDragDiffHandler) JLabel(javax.swing.JLabel) RawDataFilesSelectionType(net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesSelectionType) DialogLoggerUtil(net.sf.mzmine.util.DialogLoggerUtil) DoubleComponent(net.sf.mzmine.parameters.parametertypes.DoubleComponent) RawDataFilesSelection(net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesSelection) RawDataFile(net.sf.mzmine.datamodel.RawDataFile)

Aggregations

Files (com.google.common.io.Files)16 File (java.io.File)14 IOException (java.io.IOException)12 List (java.util.List)10 StandardCharsets (java.nio.charset.StandardCharsets)8 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 Stream (java.util.stream.Stream)6 Before (org.junit.Before)6 ImmutableList (com.google.common.collect.ImmutableList)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 Joiner (com.google.common.base.Joiner)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 Path (java.nio.file.Path)3 Optional (java.util.Optional)3 Compiler (com.facebook.buck.cxx.Compiler)2 CxxPreprocessorInput (com.facebook.buck.cxx.CxxPreprocessorInput)2 BuildTarget (com.facebook.buck.model.BuildTarget)2 Flavor (com.facebook.buck.model.Flavor)2 InternalFlavor (com.facebook.buck.model.InternalFlavor)2