Search in sources :

Example 11 with ScanBean

use of org.eclipse.scanning.api.event.scan.ScanBean in project gda-core by openGDA.

the class MScanSubmitterTest method willNotAllowStaticScanWithoutDetectors.

@Test
public void willNotAllowStaticScanWithoutDetectors() throws Exception {
    // No Size, so default size=1
    Object[] arr = { Scanpath.STATIC };
    when(resolver.resolveScanClauses()).thenReturn(Arrays.asList(Arrays.asList(new ScanpathElementProcessor(Scanpath.STATIC))));
    builder.buildAndSubmitBlockingScanRequest(arr);
    verify(submitter).blockingSubmit(beanCaptor.capture());
    verify(eventSubscriber).addListener(any(IScanListener.class));
    ScanBean bean = beanCaptor.getValue();
    assertThat(bean.getScanRequest().getCompoundModel(), is(equalTo(new CompoundModel(new StaticModel()))));
}
Also used : IScanListener(org.eclipse.scanning.api.event.scan.IScanListener) ScanBean(org.eclipse.scanning.api.event.scan.ScanBean) ScanpathElementProcessor(gda.mscan.processor.ScanpathElementProcessor) CompoundModel(org.eclipse.scanning.api.points.models.CompoundModel) StaticModel(org.eclipse.scanning.api.points.models.StaticModel) Test(org.junit.Test)

Example 12 with ScanBean

use of org.eclipse.scanning.api.event.scan.ScanBean in project gda-core by openGDA.

the class MScanSubmitterTest method createsCorrectProcessorListForPointScanWithShorthandSyntax.

@Test
public void createsCorrectProcessorListForPointScanWithShorthandSyntax() throws Exception {
    Object[] arr = { scannable, anotherScannable, RegionShape.POINT, point.getX(), point.getY(), detectorRunnableDevice };
    when(resolver.resolveScanClauses()).thenReturn(Arrays.asList(Arrays.asList(new ScannableElementProcessor(scannable), new ScannableElementProcessor(anotherScannable), new RegionShapeElementProcessor(RegionShape.POINT), new NumberElementProcessor(point.getX()), new NumberElementProcessor(point.getY()), new ScanpathElementProcessor(Scanpath.SINGLE_POINT), new NumberElementProcessor(point.getX()), new NumberElementProcessor(point.getY())), Arrays.asList(new IRunnableDeviceDetectorElementProcessor(detectorRunnableDevice))));
    builder.buildAndSubmitBlockingScanRequest(arr);
    List<IClauseElementProcessor> processors = captor.getValue();
    assertThat(processors.size(), is(9));
    assertThat(processors.get(0), instanceOf(ScannableElementProcessor.class));
    assertThat(processors.get(0).getElement(), is(scannable));
    assertThat(processors.get(1), instanceOf(ScannableElementProcessor.class));
    assertThat(processors.get(1).getElement(), is(anotherScannable));
    assertThat(processors.get(2), instanceOf(RegionShapeElementProcessor.class));
    assertThat(processors.get(2).getElement(), is(RegionShape.POINT));
    assertThat(processors.get(3), instanceOf(NumberElementProcessor.class));
    assertThat(processors.get(3).getElement(), is(point.getX()));
    assertThat(processors.get(4), instanceOf(NumberElementProcessor.class));
    assertThat(processors.get(4).getElement(), is(point.getY()));
    assertThat(processors.get(5), instanceOf(ScanpathElementProcessor.class));
    assertThat(processors.get(5).getElement(), is(Scanpath.SINGLE_POINT));
    assertThat(processors.get(6), instanceOf(NumberElementProcessor.class));
    assertThat(processors.get(6).getElement(), is(point.getX()));
    assertThat(processors.get(7), instanceOf(NumberElementProcessor.class));
    assertThat(processors.get(7).getElement(), is(point.getY()));
    assertThat(processors.get(8), instanceOf(IRunnableDeviceDetectorElementProcessor.class));
    assertThat(processors.get(8).getElement(), is(detectorRunnableDevice));
    verify(eventSubscriber).addListener(any(IScanListener.class));
    verify(submitter).blockingSubmit(beanCaptor.capture());
    ScanBean bean = beanCaptor.getValue();
    assertThat(bean.getScanRequest().getCompoundModel(), is(equalTo(getCompoundModel(point, pointRoi))));
    assertThat(bean.getScanRequest().getDetectors().values(), contains(detectorRunnableDevice.getModel()));
}
Also used : IScanListener(org.eclipse.scanning.api.event.scan.IScanListener) ScanBean(org.eclipse.scanning.api.event.scan.ScanBean) NumberElementProcessor(gda.mscan.processor.NumberElementProcessor) ScanpathElementProcessor(gda.mscan.processor.ScanpathElementProcessor) IClauseElementProcessor(gda.mscan.processor.IClauseElementProcessor) ScannableElementProcessor(gda.mscan.processor.ScannableElementProcessor) IRunnableDeviceDetectorElementProcessor(gda.mscan.processor.IRunnableDeviceDetectorElementProcessor) RegionShapeElementProcessor(gda.mscan.processor.RegionShapeElementProcessor) Test(org.junit.Test)

Example 13 with ScanBean

use of org.eclipse.scanning.api.event.scan.ScanBean in project gda-core by openGDA.

the class MScanSubmitter method submit.

/**
 * Handle submission of the supplied ScanRequest and monitoring and reporting of the progress of the associated scan
 *
 * @param scanRequest	The ScanRequest to be submitted
 * @param block			Whether the request should be submitted in blocking or non-blocking mode
 * @throws Exception	Any Exception arising from the submission operation
 */
public void submit(final ScanRequest scanRequest, final boolean block, final String name) throws Exception {
    // validate the scan bean properly here or you get a nullpointer exception
    final ScanBean bean = new ScanBean(scanRequest);
    eventService.getEventConnectorService().marshal(bean);
    final URI uri = new URI(LocalProperties.getActiveMQBrokerURI());
    if (name != null && !name.isBlank()) {
        bean.setName(name);
    }
    try (final ISubmitter<ScanBean> submitter = eventService.createSubmitter(uri, EventConstants.SUBMISSION_QUEUE);
        final ISubscriber<IScanListener> subscriber = eventService.createSubscriber(uri, EventConstants.STATUS_TOPIC);
        var queue = eventService.createJobQueueProxy(uri, EventConstants.SUBMISSION_QUEUE)) {
        subscriber.addListener(new IScanListener() {

            @Override
            public void scanEventPerformed(ScanEvent evt) {
                String message = evt.getBean().getMessage();
                if (message != null) {
                    printToJython(Map.of(EMPTYSTRING, message));
                }
            }

            @Override
            public void scanStateChanged(ScanEvent evt) {
                ScanBean bean = evt.getBean();
                if ((bean.getStatus().equals(Status.PREPARING) || bean.getStatus().equals(Status.COMPLETE)) && bean.getFilePath() != null) {
                    printToJython(Map.of("Output file: ", bean.getFilePath()));
                } else if (bean.getStatus().equals(Status.FAILED)) {
                    facade.print(bean.getMessage());
                }
            }
        });
        if (block) {
            try {
                submitter.blockingSubmit(bean);
            } catch (InterruptedException e) {
                queue.terminateJob(bean);
                facade.print("Scan terminated");
                Thread.currentThread().interrupt();
            }
        } else {
            submitter.submit(bean);
        }
    }
}
Also used : ScanBean(org.eclipse.scanning.api.event.scan.ScanBean) IScanListener(org.eclipse.scanning.api.event.scan.IScanListener) ScanEvent(org.eclipse.scanning.api.event.scan.ScanEvent) URI(java.net.URI)

Example 14 with ScanBean

use of org.eclipse.scanning.api.event.scan.ScanBean in project gda-core by openGDA.

the class QueuePreventingScanSubmitterTest method canSubmitImportantScanToEmptyQueue.

@Test
public void canSubmitImportantScanToEmptyQueue() throws Exception {
    ScanBean scan = getTestScanBean();
    scanSubmitter.submitImportantScan(scan);
    verify(submitter).submit(scan);
}
Also used : ScanBean(org.eclipse.scanning.api.event.scan.ScanBean) Test(org.junit.Test)

Example 15 with ScanBean

use of org.eclipse.scanning.api.event.scan.ScanBean in project gda-core by openGDA.

the class QueuePreventingScanSubmitterTest method importantSubmissionAbortsRunningScan.

@Test
public void importantSubmissionAbortsRunningScan() throws Exception {
    ScanBean runningScan = getTestScanBean();
    runningScan.setStatus(Status.RUNNING);
    runningAndCompleted.add(runningScan);
    scanSubmitter.submitImportantScan(getTestScanBean());
    verify(consumer).terminateJob(runningScan);
}
Also used : ScanBean(org.eclipse.scanning.api.event.scan.ScanBean) Test(org.junit.Test)

Aggregations

ScanBean (org.eclipse.scanning.api.event.scan.ScanBean)35 Test (org.junit.Test)23 IScanListener (org.eclipse.scanning.api.event.scan.IScanListener)20 ScanpathElementProcessor (gda.mscan.processor.ScanpathElementProcessor)18 IRunnableDeviceDetectorElementProcessor (gda.mscan.processor.IRunnableDeviceDetectorElementProcessor)16 NumberElementProcessor (gda.mscan.processor.NumberElementProcessor)15 IClauseElementProcessor (gda.mscan.processor.IClauseElementProcessor)13 RegionShapeElementProcessor (gda.mscan.processor.RegionShapeElementProcessor)12 ScannableElementProcessor (gda.mscan.processor.ScannableElementProcessor)12 CompoundModel (org.eclipse.scanning.api.points.models.CompoundModel)8 ScanRequest (org.eclipse.scanning.api.event.scan.ScanRequest)7 StaticModel (org.eclipse.scanning.api.points.models.StaticModel)7 EventException (org.eclipse.scanning.api.event.EventException)4 IMappingExperimentBean (uk.ac.diamond.daq.mapping.api.IMappingExperimentBean)3 ScannableDetectorElementProcessor (gda.mscan.processor.ScannableDetectorElementProcessor)2 URISyntaxException (java.net.URISyntaxException)2 IScanPointGeneratorModel (org.eclipse.scanning.api.points.models.IScanPointGeneratorModel)2 ReRunFromFileElementProcessor (gda.mscan.processor.ReRunFromFileElementProcessor)1 ScanDataConsumerElementProcessor (gda.mscan.processor.ScanDataConsumerElementProcessor)1 ScannableMonitorElementProcessor (gda.mscan.processor.ScannableMonitorElementProcessor)1