Search in sources :

Example 1 with TechnicalException

use of com.alliander.osgp.shared.exceptionhandling.TechnicalException in project Protocol-Adapter-IEC61850 by OSGP.

the class PublicLightingGetPowerUsageHistoryRequestMessageProcessor method handleGetPowerUsageHistoryDeviceResponse.

private void handleGetPowerUsageHistoryDeviceResponse(final DeviceResponse deviceResponse, final ResponseMessageSender responseMessageSender, final String domain, final String domainVersion, final String messageType, final int retryCount, final int messagePriority, final Long scheduleTime) {
    final GetPowerUsageHistoryDeviceResponse getPowerUsageHistoryDeviceResponse = (GetPowerUsageHistoryDeviceResponse) deviceResponse;
    ResponseMessageResultType result = ResponseMessageResultType.OK;
    OsgpException osgpException = null;
    PowerUsageHistoryResponseMessageDataContainerDto powerUsageHistoryResponseMessageDataContainer = null;
    try {
        powerUsageHistoryResponseMessageDataContainer = new PowerUsageHistoryResponseMessageDataContainerDto(getPowerUsageHistoryDeviceResponse.getPowerUsageHistoryData());
    } catch (final Exception e) {
        LOGGER.error("Device Response Exception", e);
        result = ResponseMessageResultType.NOT_OK;
        osgpException = new TechnicalException(ComponentType.PROTOCOL_IEC61850, "Unexpected exception while retrieving response message", e);
    }
    final DeviceMessageMetadata deviceMessageMetadata = new DeviceMessageMetadata(deviceResponse.getDeviceIdentification(), deviceResponse.getOrganisationIdentification(), deviceResponse.getCorrelationUid(), messageType, messagePriority, scheduleTime);
    final ProtocolResponseMessage.Builder builder = new ProtocolResponseMessage.Builder();
    final ProtocolResponseMessage responseMessage = builder.domain(domain).domainVersion(domainVersion).deviceMessageMetadata(deviceMessageMetadata).result(result).osgpException(osgpException).dataObject(powerUsageHistoryResponseMessageDataContainer).retryCount(retryCount).build();
    responseMessageSender.send(responseMessage);
}
Also used : OsgpException(com.alliander.osgp.shared.exceptionhandling.OsgpException) PowerUsageHistoryResponseMessageDataContainerDto(com.alliander.osgp.dto.valueobjects.PowerUsageHistoryResponseMessageDataContainerDto) TechnicalException(com.alliander.osgp.shared.exceptionhandling.TechnicalException) ProtocolResponseMessage(com.alliander.osgp.shared.infra.jms.ProtocolResponseMessage) GetPowerUsageHistoryDeviceResponse(com.alliander.osgp.adapter.protocol.iec61850.device.ssld.responses.GetPowerUsageHistoryDeviceResponse) DeviceMessageMetadata(com.alliander.osgp.shared.infra.jms.DeviceMessageMetadata) ResponseMessageResultType(com.alliander.osgp.shared.infra.jms.ResponseMessageResultType) OsgpException(com.alliander.osgp.shared.exceptionhandling.OsgpException) JMSException(javax.jms.JMSException) TechnicalException(com.alliander.osgp.shared.exceptionhandling.TechnicalException)

Example 2 with TechnicalException

use of com.alliander.osgp.shared.exceptionhandling.TechnicalException in project Protocol-Adapter-IEC61850 by OSGP.

the class CommonGetConfigurationRequestMessageProcessor method handleGetConfigurationDeviceResponse.

private void handleGetConfigurationDeviceResponse(final DeviceResponse deviceResponse, final ResponseMessageSender responseMessageSender, final String domain, final String domainVersion, final String messageType, final int retryCount) {
    ResponseMessageResultType result = ResponseMessageResultType.OK;
    OsgpException osgpException = null;
    ConfigurationDto configuration = null;
    try {
        final GetConfigurationDeviceResponse response = (GetConfigurationDeviceResponse) deviceResponse;
        configuration = response.getConfiguration();
    } catch (final Exception e) {
        LOGGER.error("Device Response Exception", e);
        result = ResponseMessageResultType.NOT_OK;
        osgpException = new TechnicalException(ComponentType.PROTOCOL_IEC61850, "Unexpected exception while retrieving response message", e);
    }
    final DeviceMessageMetadata deviceMessageMetaData = new DeviceMessageMetadata(deviceResponse.getDeviceIdentification(), deviceResponse.getOrganisationIdentification(), deviceResponse.getCorrelationUid(), messageType, 0);
    final ProtocolResponseMessage responseMessage = new ProtocolResponseMessage.Builder().domain(domain).domainVersion(domainVersion).deviceMessageMetadata(deviceMessageMetaData).result(result).osgpException(osgpException).dataObject(configuration).retryCount(retryCount).build();
    responseMessageSender.send(responseMessage);
}
Also used : OsgpException(com.alliander.osgp.shared.exceptionhandling.OsgpException) TechnicalException(com.alliander.osgp.shared.exceptionhandling.TechnicalException) ProtocolResponseMessage(com.alliander.osgp.shared.infra.jms.ProtocolResponseMessage) ConfigurationDto(com.alliander.osgp.dto.valueobjects.ConfigurationDto) GetConfigurationDeviceResponse(com.alliander.osgp.adapter.protocol.iec61850.device.ssld.responses.GetConfigurationDeviceResponse) DeviceMessageMetadata(com.alliander.osgp.shared.infra.jms.DeviceMessageMetadata) ResponseMessageResultType(com.alliander.osgp.shared.infra.jms.ResponseMessageResultType) OsgpException(com.alliander.osgp.shared.exceptionhandling.OsgpException) JMSException(javax.jms.JMSException) TechnicalException(com.alliander.osgp.shared.exceptionhandling.TechnicalException)

Example 3 with TechnicalException

use of com.alliander.osgp.shared.exceptionhandling.TechnicalException in project Protocol-Adapter-IEC61850 by OSGP.

the class CommonGetFirmwareRequestMessageProcessor method handleGetFirmwareVersionDeviceResponse.

private void handleGetFirmwareVersionDeviceResponse(final DeviceResponse deviceResponse, final ResponseMessageSender responseMessageSender, final String domain, final String domainVersion, final String messageType, final int retryCount) {
    ResponseMessageResultType result = ResponseMessageResultType.OK;
    OsgpException osgpException = null;
    List<FirmwareVersionDto> firmwareVersions = null;
    try {
        firmwareVersions = ((GetFirmwareVersionDeviceResponse) deviceResponse).getFirmwareVersions();
    } catch (final Exception e) {
        LOGGER.error("Device Response Exception", e);
        result = ResponseMessageResultType.NOT_OK;
        osgpException = new TechnicalException(ComponentType.UNKNOWN, "Unexpected exception while retrieving response message", e);
    }
    final DeviceMessageMetadata deviceMessageMetaData = new DeviceMessageMetadata(deviceResponse.getDeviceIdentification(), deviceResponse.getOrganisationIdentification(), deviceResponse.getCorrelationUid(), messageType, 0);
    final ProtocolResponseMessage responseMessage = new ProtocolResponseMessage.Builder().domain(domain).domainVersion(domainVersion).deviceMessageMetadata(deviceMessageMetaData).result(result).osgpException(osgpException).dataObject((Serializable) firmwareVersions).retryCount(retryCount).build();
    responseMessageSender.send(responseMessage);
}
Also used : OsgpException(com.alliander.osgp.shared.exceptionhandling.OsgpException) TechnicalException(com.alliander.osgp.shared.exceptionhandling.TechnicalException) ProtocolResponseMessage(com.alliander.osgp.shared.infra.jms.ProtocolResponseMessage) DeviceMessageMetadata(com.alliander.osgp.shared.infra.jms.DeviceMessageMetadata) ResponseMessageResultType(com.alliander.osgp.shared.infra.jms.ResponseMessageResultType) FirmwareVersionDto(com.alliander.osgp.dto.valueobjects.FirmwareVersionDto) OsgpException(com.alliander.osgp.shared.exceptionhandling.OsgpException) JMSException(javax.jms.JMSException) TechnicalException(com.alliander.osgp.shared.exceptionhandling.TechnicalException)

Example 4 with TechnicalException

use of com.alliander.osgp.shared.exceptionhandling.TechnicalException in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850SsldDeviceService method runSelfTest.

@Override
public void runSelfTest(final DeviceRequest deviceRequest, final DeviceResponseHandler deviceResponseHandler, final boolean startOfTest) throws JMSException {
    // Assuming all goes well.
    final DeviceMessageStatus status = DeviceMessageStatus.OK;
    DeviceConnection deviceConnection = null;
    try {
        deviceConnection = this.connectToDevice(deviceRequest);
        // Getting the SSLD for the device output-settings.
        final Ssld ssld = this.ssldDataService.findDevice(deviceRequest.getDeviceIdentification());
        // This list will contain the external indexes of all light relays.
        // It's used to interpret the deviceStatus data later on.
        final List<Integer> lightRelays = new ArrayList<>();
        LOGGER.info("Turning all lights relays {}", startOfTest ? "on" : "off");
        final Iec61850SetLightCommand iec61850SetLightCommand = new Iec61850SetLightCommand();
        // startOfTest.
        for (final DeviceOutputSetting deviceOutputSetting : this.ssldDataService.findByRelayType(ssld, RelayType.LIGHT)) {
            lightRelays.add(deviceOutputSetting.getExternalId());
            if (!iec61850SetLightCommand.switchLightRelay(this.iec61850Client, deviceConnection, deviceOutputSetting.getInternalId(), startOfTest)) {
                throw new ProtocolAdapterException(String.format("Failed to switch light relay during self-test with internal index: %d for device: %s", deviceOutputSetting.getInternalId(), deviceRequest.getDeviceIdentification()));
            }
        }
        // Sleep and wait.
        this.selfTestSleep();
        // Getting the status.
        final DeviceStatusDto deviceStatus = new Iec61850GetStatusCommand().getStatusFromDevice(this.iec61850Client, deviceConnection, ssld);
        LOGGER.info("Fetching and checking the devicestatus");
        // Checking to see if all light relays have the correct state.
        for (final LightValueDto lightValue : deviceStatus.getLightValues()) {
            if (lightRelays.contains(lightValue.getIndex()) && lightValue.isOn() != startOfTest) {
                // request failed.
                throw new ProtocolAdapterException("not all relays are ".concat(startOfTest ? "on" : "off"));
            }
        }
        LOGGER.info("All lights relays are {}, returning OK", startOfTest ? "on" : "off");
        this.createSuccessfulDefaultResponse(deviceRequest, deviceResponseHandler, status);
    } catch (final ConnectionFailureException se) {
        LOGGER.info("Original ConnectionFailureException message: {}", se.getMessage());
        final ConnectionFailureException seGeneric = new ConnectionFailureException("Connection failure", se);
        this.handleConnectionFailureException(deviceRequest, deviceResponseHandler, seGeneric);
    } catch (final Exception e) {
        LOGGER.info("Selftest failure", e);
        final TechnicalException te = new TechnicalException(ComponentType.PROTOCOL_IEC61850, "Selftest failure - " + e.getMessage());
        this.handleException(deviceRequest, deviceResponseHandler, te);
    }
    this.iec61850DeviceConnectionService.disconnect(deviceConnection, deviceRequest);
}
Also used : TechnicalException(com.alliander.osgp.shared.exceptionhandling.TechnicalException) ArrayList(java.util.ArrayList) DeviceOutputSetting(com.alliander.osgp.core.db.api.iec61850.entities.DeviceOutputSetting) NodeWriteException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.NodeWriteException) FunctionalException(com.alliander.osgp.shared.exceptionhandling.FunctionalException) JMSException(javax.jms.JMSException) ProtocolAdapterException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) ConnectionFailureException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ConnectionFailureException) TechnicalException(com.alliander.osgp.shared.exceptionhandling.TechnicalException) Iec61850SetLightCommand(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.services.commands.Iec61850SetLightCommand) LightValueDto(com.alliander.osgp.dto.valueobjects.LightValueDto) DeviceMessageStatus(com.alliander.osgp.adapter.protocol.iec61850.device.DeviceMessageStatus) Iec61850GetStatusCommand(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.services.commands.Iec61850GetStatusCommand) DeviceStatusDto(com.alliander.osgp.dto.valueobjects.DeviceStatusDto) ConnectionFailureException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ConnectionFailureException) DeviceConnection(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection) ProtocolAdapterException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) Ssld(com.alliander.osgp.core.db.api.iec61850.entities.Ssld)

Example 5 with TechnicalException

use of com.alliander.osgp.shared.exceptionhandling.TechnicalException in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850SsldDeviceService method selfTestSleep.

private void selfTestSleep() throws TechnicalException {
    try {
        LOGGER.info("Waiting {} milliseconds before getting the device status", this.selftestTimeout);
        Thread.sleep(this.selftestTimeout);
    } catch (final InterruptedException e) {
        LOGGER.error("An InterruptedException occurred during the device selftest timeout.", e);
        throw new TechnicalException(ComponentType.PROTOCOL_IEC61850, "An error occurred during the device selftest timeout.");
    }
}
Also used : TechnicalException(com.alliander.osgp.shared.exceptionhandling.TechnicalException)

Aggregations

TechnicalException (com.alliander.osgp.shared.exceptionhandling.TechnicalException)6 JMSException (javax.jms.JMSException)5 OsgpException (com.alliander.osgp.shared.exceptionhandling.OsgpException)4 DeviceMessageMetadata (com.alliander.osgp.shared.infra.jms.DeviceMessageMetadata)4 ProtocolResponseMessage (com.alliander.osgp.shared.infra.jms.ProtocolResponseMessage)4 ResponseMessageResultType (com.alliander.osgp.shared.infra.jms.ResponseMessageResultType)4 DeviceMessageStatus (com.alliander.osgp.adapter.protocol.iec61850.device.DeviceMessageStatus)1 GetConfigurationDeviceResponse (com.alliander.osgp.adapter.protocol.iec61850.device.ssld.responses.GetConfigurationDeviceResponse)1 GetDataDeviceResponse (com.alliander.osgp.adapter.protocol.iec61850.device.ssld.responses.GetDataDeviceResponse)1 GetPowerUsageHistoryDeviceResponse (com.alliander.osgp.adapter.protocol.iec61850.device.ssld.responses.GetPowerUsageHistoryDeviceResponse)1 ConnectionFailureException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ConnectionFailureException)1 NodeWriteException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.NodeWriteException)1 ProtocolAdapterException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)1 DeviceConnection (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection)1 Iec61850GetStatusCommand (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.services.commands.Iec61850GetStatusCommand)1 Iec61850SetLightCommand (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.services.commands.Iec61850SetLightCommand)1 DeviceOutputSetting (com.alliander.osgp.core.db.api.iec61850.entities.DeviceOutputSetting)1 Ssld (com.alliander.osgp.core.db.api.iec61850.entities.Ssld)1 ConfigurationDto (com.alliander.osgp.dto.valueobjects.ConfigurationDto)1 DeviceStatusDto (com.alliander.osgp.dto.valueobjects.DeviceStatusDto)1