Search in sources :

Example 1 with Instruction

use of net.solarnetwork.node.reactor.Instruction in project solarnetwork-node by SolarNetwork.

the class SimpleReactorService method processInstruction.

@Override
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public InstructionStatus processInstruction(Instruction instruction) {
    // look for an existing status...
    Instruction instr = instructionDao.getInstruction(instruction.getId(), instruction.getInstructorId());
    if (instr == null) {
        // persist new status
        instructionDao.storeInstruction(instruction);
        instr = instructionDao.getInstruction(instruction.getId(), instruction.getInstructorId());
    }
    return instr.getStatus();
}
Also used : Instruction(net.solarnetwork.node.reactor.Instruction) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with Instruction

use of net.solarnetwork.node.reactor.Instruction in project solarnetwork-node by SolarNetwork.

the class CASettingsServiceTests method processUpdateSetting.

@Test
public void processUpdateSetting() throws IOException {
    // GIVEN
    dao.storeSetting(new Setting("foo", "bar", "bam", null));
    Configuration config = EasyMock.createMock(Configuration.class);
    mocks.add(config);
    Hashtable<String, Object> configProps = new Hashtable<>();
    expect(ca.getConfiguration("foo", null)).andReturn(config);
    expect(config.getProperties()).andReturn(configProps).anyTimes();
    Capture<Dictionary<String, ?>> configPropsCaptor = Capture.newInstance();
    config.update(capture(configPropsCaptor));
    // WHEN
    replayAll();
    Map<String, String> params = new LinkedHashMap<>(2);
    params.put("key", "foo");
    params.put("type", "bar");
    params.put("value", "bam");
    Instruction instr = createLocalInstruction(SettingsService.TOPIC_UPDATE_SETTING, params);
    InstructionStatus result = service.processInstruction(instr);
    // THEN
    assertThat("Result provided", result, is(notNullValue()));
    Map<String, ?> props = CollectionUtils.mapForDictionary(configPropsCaptor.getValue());
    assertThat("Config updated", props, hasEntry("bar", "bam"));
    assertThat("Config updated props", props.keySet(), hasSize(1));
}
Also used : Dictionary(java.util.Dictionary) InstructionStatus(net.solarnetwork.node.reactor.InstructionStatus) Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable) Setting(net.solarnetwork.node.domain.Setting) Instruction(net.solarnetwork.node.reactor.Instruction) InstructionUtils.createLocalInstruction(net.solarnetwork.node.reactor.InstructionUtils.createLocalInstruction) LinkedHashMap(java.util.LinkedHashMap) EasyMock.anyObject(org.easymock.EasyMock.anyObject) Test(org.junit.Test)

Example 3 with Instruction

use of net.solarnetwork.node.reactor.Instruction in project solarnetwork-node by SolarNetwork.

the class CASettingsServiceTests method processUpdateSetting_noValue.

@Test
public void processUpdateSetting_noValue() throws IOException {
    // GIVEN
    expect(dao.deleteSetting("foo", "bar")).andReturn(true);
    Configuration config = EasyMock.createMock(Configuration.class);
    mocks.add(config);
    Hashtable<String, Object> configProps = new Hashtable<>();
    expect(ca.getConfiguration("foo", null)).andReturn(config);
    expect(config.getProperties()).andReturn(configProps).anyTimes();
    // WHEN
    replayAll();
    Map<String, String> params = new LinkedHashMap<>(2);
    params.put("key", "foo");
    params.put("type", "bar");
    Instruction instr = createLocalInstruction(SettingsService.TOPIC_UPDATE_SETTING, params);
    InstructionStatus result = service.processInstruction(instr);
    // THEN
    assertThat("Result provided", result, is(notNullValue()));
}
Also used : InstructionStatus(net.solarnetwork.node.reactor.InstructionStatus) Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable) EasyMock.anyObject(org.easymock.EasyMock.anyObject) Instruction(net.solarnetwork.node.reactor.Instruction) InstructionUtils.createLocalInstruction(net.solarnetwork.node.reactor.InstructionUtils.createLocalInstruction) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 4 with Instruction

use of net.solarnetwork.node.reactor.Instruction in project solarnetwork-node by SolarNetwork.

the class JdbcInstructionDaoTests method findForAck.

@Test
public void findForAck() {
    storeNew();
    List<Instruction> results = dao.findInstructionsForAcknowledgement();
    assertThat("Result provided", results, hasSize(1));
    assertEquals(lastDatum.getId(), results.get(0).getId());
    // update ack now for second search
    InstructionStatus newStatus = lastDatum.getStatus().newCopyWithAcknowledgedState(lastDatum.getStatus().getInstructionState());
    dao.storeInstructionStatus(lastDatum.getId(), lastDatum.getInstructorId(), newStatus);
    results = dao.findInstructionsForAcknowledgement();
    assertThat("Result not found", results, hasSize(0));
}
Also used : InstructionStatus(net.solarnetwork.node.reactor.InstructionStatus) Instruction(net.solarnetwork.node.reactor.Instruction) BasicInstruction(net.solarnetwork.node.reactor.BasicInstruction) AbstractNodeTransactionalTest(net.solarnetwork.node.test.AbstractNodeTransactionalTest) Test(org.junit.Test)

Example 5 with Instruction

use of net.solarnetwork.node.reactor.Instruction in project solarnetwork-node by SolarNetwork.

the class JdbcInstructionDaoTests method compareAndSetStatus.

@Test
public void compareAndSetStatus() {
    storeNew();
    InstructionStatus execStatus = lastDatum.getStatus().newCopyWithState(InstructionState.Executing);
    boolean updated = dao.compareAndStoreInstructionStatus(lastDatum.getId(), lastDatum.getInstructorId(), InstructionState.Received, execStatus);
    assertThat("Status updated", updated, equalTo(true));
    Instruction instr = dao.getInstruction(lastDatum.getId(), lastDatum.getInstructorId());
    assertThat("State", instr.getStatus().getInstructionState(), equalTo(InstructionState.Executing));
    assertThat("Acknoledged state", instr.getStatus().getAcknowledgedInstructionState(), is(nullValue()));
}
Also used : InstructionStatus(net.solarnetwork.node.reactor.InstructionStatus) Instruction(net.solarnetwork.node.reactor.Instruction) BasicInstruction(net.solarnetwork.node.reactor.BasicInstruction) AbstractNodeTransactionalTest(net.solarnetwork.node.test.AbstractNodeTransactionalTest) Test(org.junit.Test)

Aggregations

Instruction (net.solarnetwork.node.reactor.Instruction)66 InstructionStatus (net.solarnetwork.node.reactor.InstructionStatus)53 Test (org.junit.Test)50 BasicInstruction (net.solarnetwork.node.reactor.BasicInstruction)22 LinkedHashMap (java.util.LinkedHashMap)9 AbstractNodeTransactionalTest (net.solarnetwork.node.test.AbstractNodeTransactionalTest)8 InstructionExecutionService (net.solarnetwork.node.reactor.InstructionExecutionService)7 CommandStatus (com.automatak.dnp3.enums.CommandStatus)5 DefaultChannelPromise (io.netty.channel.DefaultChannelPromise)5 DefaultStompFrame (io.netty.handler.codec.stomp.DefaultStompFrame)5 StompFrame (io.netty.handler.codec.stomp.StompFrame)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 HttpRequesterJob (net.solarnetwork.node.control.ping.HttpRequesterJob)5 ControlConfig (net.solarnetwork.node.io.dnp3.domain.ControlConfig)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 Instant (java.time.Instant)4 MqttConnection (net.solarnetwork.common.mqtt.MqttConnection)4 InstructionStatus (net.solarnetwork.domain.InstructionStatus)4 DatumSamples (net.solarnetwork.domain.datum.DatumSamples)4