Search in sources :

Example 1 with DeviceStatusDto

use of com.alliander.osgp.dto.valueobjects.DeviceStatusDto 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 2 with DeviceStatusDto

use of com.alliander.osgp.dto.valueobjects.DeviceStatusDto in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850SsldDeviceService method getStatus.

@Override
public void getStatus(final DeviceRequest deviceRequest, final DeviceResponseHandler deviceResponseHandler) throws JMSException {
    DeviceConnection devCon = null;
    try {
        final DeviceConnection deviceConnection = this.connectToDevice(deviceRequest);
        devCon = deviceConnection;
        // Getting the SSLD for the device output-settings.
        final Ssld ssld = this.ssldDataService.findDevice(deviceRequest.getDeviceIdentification());
        final DeviceStatusDto deviceStatus = new Iec61850GetStatusCommand().getStatusFromDevice(this.iec61850Client, deviceConnection, ssld);
        final GetStatusDeviceResponse deviceResponse = new GetStatusDeviceResponse(deviceRequest.getOrganisationIdentification(), deviceRequest.getDeviceIdentification(), deviceRequest.getCorrelationUid(), deviceStatus);
        deviceResponseHandler.handleResponse(deviceResponse);
        this.enableReporting(deviceConnection, deviceRequest);
    } catch (final ConnectionFailureException se) {
        this.handleConnectionFailureException(deviceRequest, deviceResponseHandler, se);
        this.iec61850DeviceConnectionService.disconnect(devCon, deviceRequest);
    } catch (final Exception e) {
        this.handleException(deviceRequest, deviceResponseHandler, e);
        this.iec61850DeviceConnectionService.disconnect(devCon, deviceRequest);
    }
}
Also used : Iec61850GetStatusCommand(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.services.commands.Iec61850GetStatusCommand) GetStatusDeviceResponse(com.alliander.osgp.adapter.protocol.iec61850.device.ssld.responses.GetStatusDeviceResponse) 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) 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) Ssld(com.alliander.osgp.core.db.api.iec61850.entities.Ssld)

Example 3 with DeviceStatusDto

use of com.alliander.osgp.dto.valueobjects.DeviceStatusDto in project Protocol-Adapter-OSLP by OSGP.

the class OslpDeviceService method handleOslpResponseGetStatus.

private void handleOslpResponseGetStatus(final DeviceRequest deviceRequest, final OslpEnvelope oslpResponse, final DeviceResponseHandler deviceResponseHandler) {
    this.saveOslpResponseLogEntry(deviceRequest, oslpResponse);
    this.updateSequenceNumber(deviceRequest.getDeviceIdentification(), oslpResponse);
    DeviceStatusDto deviceStatus = null;
    if (oslpResponse.getPayloadMessage().hasGetStatusResponse()) {
        final Oslp.GetStatusResponse getStatusResponse = oslpResponse.getPayloadMessage().getGetStatusResponse();
        final Oslp.Status oslpStatus = getStatusResponse.getStatus();
        if (oslpStatus == Oslp.Status.OK) {
            // Required properties.
            final List<LightValueDto> lightValues = this.mapper.mapAsList(getStatusResponse.getValueList(), LightValueDto.class);
            final LinkTypeDto preferredType = getStatusResponse.getPreferredLinktype().equals(Oslp.LinkType.LINK_NOT_SET) ? null : this.mapper.map(getStatusResponse.getPreferredLinktype(), LinkTypeDto.class);
            final LinkTypeDto actualLinkType = getStatusResponse.getActualLinktype().equals(Oslp.LinkType.LINK_NOT_SET) ? null : this.mapper.map(getStatusResponse.getActualLinktype(), LinkTypeDto.class);
            final LightTypeDto lightType = getStatusResponse.getLightType().equals(Oslp.LightType.LT_NOT_SET) ? null : this.mapper.map(getStatusResponse.getLightType(), LightTypeDto.class);
            final int eventNotificationMask = getStatusResponse.getEventNotificationMask();
            deviceStatus = new DeviceStatusDto(lightValues, preferredType, actualLinkType, lightType, eventNotificationMask);
            // Optional properties.
            if (getStatusResponse.hasBootLoaderVersion()) {
                deviceStatus.setBootLoaderVersion(getStatusResponse.getBootLoaderVersion());
            }
            if (getStatusResponse.getCurrentConfigurationBackUsed() != null && getStatusResponse.getCurrentConfigurationBackUsed().toByteArray().length == 1) {
                deviceStatus.setCurrentConfigurationBackUsed(this.convertCurrentConfigurationBankUsed(getStatusResponse.getCurrentConfigurationBackUsed()));
            }
            if (getStatusResponse.hasCurrentIp()) {
                deviceStatus.setCurrentIp(getStatusResponse.getCurrentIp());
            }
            if (getStatusResponse.hasCurrentTime()) {
                deviceStatus.setCurrentTime(getStatusResponse.getCurrentTime());
            }
            if (getStatusResponse.hasDcOutputVoltageCurrent()) {
                deviceStatus.setDcOutputVoltageCurrent(getStatusResponse.getDcOutputVoltageCurrent());
            }
            if (getStatusResponse.hasDcOutputVoltageMaximum()) {
                deviceStatus.setDcOutputVoltageMaximum(getStatusResponse.getDcOutputVoltageMaximum());
            }
            if (getStatusResponse.hasEventNotificationMask()) {
                deviceStatus.setEventNotificationsMask(getStatusResponse.getEventNotificationMask());
            }
            if (getStatusResponse.hasExternalFlashMemSize()) {
                deviceStatus.setExternalFlashMemSize(getStatusResponse.getExternalFlashMemSize());
            }
            if (getStatusResponse.hasFirmwareVersion()) {
                deviceStatus.setFirmwareVersion(getStatusResponse.getFirmwareVersion());
            }
            if (getStatusResponse.hasHardwareId()) {
                deviceStatus.setHardwareId(getStatusResponse.getHardwareId());
            }
            if (getStatusResponse.hasInternalFlashMemSize()) {
                deviceStatus.setInternalFlashMemSize(getStatusResponse.getInternalFlashMemSize());
            }
            if (getStatusResponse.hasLastInternalTestResultCode()) {
                deviceStatus.setLastInternalTestResultCode(getStatusResponse.getLastInternalTestResultCode());
            }
            if (getStatusResponse.getMacAddress() != null && !getStatusResponse.getMacAddress().isEmpty()) {
                deviceStatus.setMacAddress(this.convertMacAddress(getStatusResponse.getMacAddress()));
            }
            if (getStatusResponse.hasMaximumOutputPowerOnDcOutput()) {
                deviceStatus.setMaximumOutputPowerOnDcOutput(getStatusResponse.getMaximumOutputPowerOnDcOutput());
            }
            if (getStatusResponse.hasName()) {
                deviceStatus.setName(getStatusResponse.getName());
            }
            if (getStatusResponse.hasNumberOfOutputs()) {
                deviceStatus.setNumberOfOutputs(getStatusResponse.getNumberOfOutputs());
            }
            if (getStatusResponse.hasSerialNumber()) {
                deviceStatus.setSerialNumber(this.convertSerialNumber(getStatusResponse.getSerialNumber()));
            }
            if (getStatusResponse.hasStartupCounter()) {
                deviceStatus.setStartupCounter(getStatusResponse.getStartupCounter());
            }
        } else {
            // handle failure by throwing exceptions if needed
            LOGGER.error("Unable to convert Oslp.GetStatusResponse");
        }
    }
    final DeviceResponse deviceResponse = new GetStatusDeviceResponse(deviceRequest.getOrganisationIdentification(), deviceRequest.getDeviceIdentification(), deviceRequest.getCorrelationUid(), deviceStatus);
    deviceResponseHandler.handleResponse(deviceResponse);
}
Also used : GetStatusDeviceResponse(com.alliander.osgp.adapter.protocol.oslp.elster.device.responses.GetStatusDeviceResponse) LinkTypeDto(com.alliander.osgp.dto.valueobjects.LinkTypeDto) LightTypeDto(com.alliander.osgp.dto.valueobjects.LightTypeDto) DeviceStatusDto(com.alliander.osgp.dto.valueobjects.DeviceStatusDto) EmptyDeviceResponse(com.alliander.osgp.adapter.protocol.oslp.elster.device.responses.EmptyDeviceResponse) GetConfigurationDeviceResponse(com.alliander.osgp.adapter.protocol.oslp.elster.device.responses.GetConfigurationDeviceResponse) GetStatusDeviceResponse(com.alliander.osgp.adapter.protocol.oslp.elster.device.responses.GetStatusDeviceResponse) GetFirmwareVersionDeviceResponse(com.alliander.osgp.adapter.protocol.oslp.elster.device.responses.GetFirmwareVersionDeviceResponse) GetPowerUsageHistoryDeviceResponse(com.alliander.osgp.adapter.protocol.oslp.elster.device.responses.GetPowerUsageHistoryDeviceResponse) GetActualPowerUsageDeviceResponse(com.alliander.osgp.adapter.protocol.oslp.elster.device.responses.GetActualPowerUsageDeviceResponse) DeviceResponse(com.alliander.osgp.adapter.protocol.oslp.elster.device.DeviceResponse) Oslp(com.alliander.osgp.oslp.Oslp) LightValueDto(com.alliander.osgp.dto.valueobjects.LightValueDto)

Example 4 with DeviceStatusDto

use of com.alliander.osgp.dto.valueobjects.DeviceStatusDto in project Protocol-Adapter-OSLP by OSGP.

the class CommonGetStatusRequestMessageProcessor method handleGetStatusDeviceResponse.

private void handleGetStatusDeviceResponse(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;
    DeviceStatusDto status = null;
    try {
        final GetStatusDeviceResponse response = (GetStatusDeviceResponse) deviceResponse;
        status = response.getDeviceStatus();
    } catch (final Exception e) {
        LOGGER.error("Device Response Exception", e);
        result = ResponseMessageResultType.NOT_OK;
        osgpException = new TechnicalException(ComponentType.UNKNOWN, "Exception occurred while getting device status", e);
    }
    final DeviceMessageMetadata deviceMessageMetadata = new DeviceMessageMetadata(deviceResponse.getDeviceIdentification(), deviceResponse.getOrganisationIdentification(), deviceResponse.getCorrelationUid(), messageType, MessagePriorityEnum.DEFAULT.getPriority());
    final ProtocolResponseMessage responseMessage = ProtocolResponseMessage.newBuilder().domain(domain).domainVersion(domainVersion).deviceMessageMetadata(deviceMessageMetadata).result(result).osgpException(osgpException).dataObject(status).retryCount(retryCount).build();
    responseMessageSender.send(responseMessage);
}
Also used : OsgpException(com.alliander.osgp.shared.exceptionhandling.OsgpException) GetStatusDeviceResponse(com.alliander.osgp.adapter.protocol.oslp.elster.device.responses.GetStatusDeviceResponse) TechnicalException(com.alliander.osgp.shared.exceptionhandling.TechnicalException) ProtocolResponseMessage(com.alliander.osgp.shared.infra.jms.ProtocolResponseMessage) DeviceStatusDto(com.alliander.osgp.dto.valueobjects.DeviceStatusDto) DeviceMessageMetadata(com.alliander.osgp.shared.infra.jms.DeviceMessageMetadata) ResponseMessageResultType(com.alliander.osgp.shared.infra.jms.ResponseMessageResultType) OsgpException(com.alliander.osgp.shared.exceptionhandling.OsgpException) IOException(java.io.IOException) JMSException(javax.jms.JMSException) TechnicalException(com.alliander.osgp.shared.exceptionhandling.TechnicalException)

Example 5 with DeviceStatusDto

use of com.alliander.osgp.dto.valueobjects.DeviceStatusDto in project Protocol-Adapter-OSLP by OSGP.

the class PublicLightingGetStatusRequestMessageProcessor method handleGetStatusDeviceResponse.

private void handleGetStatusDeviceResponse(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;
    DeviceStatusDto status = null;
    try {
        final GetStatusDeviceResponse response = (GetStatusDeviceResponse) deviceResponse;
        status = response.getDeviceStatus();
    } catch (final Exception e) {
        LOGGER.error("Device Response Exception", e);
        result = ResponseMessageResultType.NOT_OK;
        osgpException = new TechnicalException(ComponentType.UNKNOWN, "Exception occurred while getting device status", e);
    }
    final DeviceMessageMetadata deviceMessageMetadata = new DeviceMessageMetadata(deviceResponse.getDeviceIdentification(), deviceResponse.getOrganisationIdentification(), deviceResponse.getCorrelationUid(), messageType, MessagePriorityEnum.DEFAULT.getPriority());
    final ProtocolResponseMessage responseMessage = ProtocolResponseMessage.newBuilder().domain(domain).domainVersion(domainVersion).deviceMessageMetadata(deviceMessageMetadata).result(result).osgpException(osgpException).dataObject(status).retryCount(retryCount).build();
    responseMessageSender.send(responseMessage);
}
Also used : OsgpException(com.alliander.osgp.shared.exceptionhandling.OsgpException) GetStatusDeviceResponse(com.alliander.osgp.adapter.protocol.oslp.elster.device.responses.GetStatusDeviceResponse) TechnicalException(com.alliander.osgp.shared.exceptionhandling.TechnicalException) ProtocolResponseMessage(com.alliander.osgp.shared.infra.jms.ProtocolResponseMessage) DeviceStatusDto(com.alliander.osgp.dto.valueobjects.DeviceStatusDto) DeviceMessageMetadata(com.alliander.osgp.shared.infra.jms.DeviceMessageMetadata) ResponseMessageResultType(com.alliander.osgp.shared.infra.jms.ResponseMessageResultType) OsgpException(com.alliander.osgp.shared.exceptionhandling.OsgpException) IOException(java.io.IOException) JMSException(javax.jms.JMSException) TechnicalException(com.alliander.osgp.shared.exceptionhandling.TechnicalException)

Aggregations

DeviceStatusDto (com.alliander.osgp.dto.valueobjects.DeviceStatusDto)8 TechnicalException (com.alliander.osgp.shared.exceptionhandling.TechnicalException)5 JMSException (javax.jms.JMSException)5 GetStatusDeviceResponse (com.alliander.osgp.adapter.protocol.oslp.elster.device.responses.GetStatusDeviceResponse)4 DeviceMessageMetadata (com.alliander.osgp.shared.infra.jms.DeviceMessageMetadata)4 ProtocolResponseMessage (com.alliander.osgp.shared.infra.jms.ProtocolResponseMessage)4 LightValueDto (com.alliander.osgp.dto.valueobjects.LightValueDto)3 OsgpException (com.alliander.osgp.shared.exceptionhandling.OsgpException)3 ResponseMessageResultType (com.alliander.osgp.shared.infra.jms.ResponseMessageResultType)3 IOException (java.io.IOException)3 GetStatusDeviceResponse (com.alliander.osgp.adapter.protocol.iec61850.device.ssld.responses.GetStatusDeviceResponse)2 ConnectionFailureException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ConnectionFailureException)2 NodeWriteException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.NodeWriteException)2 ProtocolAdapterException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)2 DeviceConnection (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection)2 Iec61850GetStatusCommand (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.services.commands.Iec61850GetStatusCommand)2 DeviceOutputSetting (com.alliander.osgp.core.db.api.iec61850.entities.DeviceOutputSetting)2 Ssld (com.alliander.osgp.core.db.api.iec61850.entities.Ssld)2 LightTypeDto (com.alliander.osgp.dto.valueobjects.LightTypeDto)2 FunctionalException (com.alliander.osgp.shared.exceptionhandling.FunctionalException)2