Search in sources :

Example 6 with NodeReadException

use of org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeReadException in project open-smart-grid-platform by OSGP.

the class Iec61850RtuDeviceReportingService method resyncBufferedReport.

private void resyncBufferedReport(final DeviceConnection connection, final String deviceIdentification, final Brcb brcb) {
    final NodeContainer node = new NodeContainer(connection, brcb);
    try {
        this.client.readNodeDataValues(connection.getConnection().getClientAssociation(), node.getFcmodelNode());
    } catch (final NodeReadException e) {
        LOGGER.debug("NodeReadException", e);
        LOGGER.error("Resync reporting failed, could not read report id from device {}, exception: {}", deviceIdentification, e.getMessage());
        return;
    }
    final String reportId = node.getString(SubDataAttribute.REPORT_ID);
    LOGGER.debug("Resync reporting for report {} on device {}", reportId, deviceIdentification);
    final Iec61850ReportEntry reportEntry = this.iec61850ReportEntryRepository.findByDeviceIdentificationAndReportId(deviceIdentification, reportId);
    if (reportEntry == null) {
        LOGGER.info("Resync reporting for report {} on device {} not possible, no last report entry found", reportId, deviceIdentification);
    } else {
        LOGGER.info("Resync reporting for report {} on device {} with last report entry: {}", reportId, deviceIdentification, reportEntry);
        try {
            node.writeOctetString(SubDataAttribute.ENTRY_ID, reportEntry.getEntryId());
        } catch (final NodeWriteException e) {
            LOGGER.debug("NodeWriteException", e);
            LOGGER.error("Resync reporting for report {} on device {} failed with exception: {}", reportId, deviceIdentification, e.getMessage());
        }
    }
}
Also used : NodeWriteException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeWriteException) NodeReadException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeReadException) NodeContainer(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.NodeContainer) Iec61850ReportEntry(org.opensmartgridplatform.adapter.protocol.iec61850.domain.entities.Iec61850ReportEntry)

Example 7 with NodeReadException

use of org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeReadException in project open-smart-grid-platform by OSGP.

the class Iec61850DeviceConnectionService method testIfConnectionIsCachedAndAlive.

private boolean testIfConnectionIsCachedAndAlive(final String deviceIdentification, final IED ied, final String serverName, final String logicalDevice) throws ProtocolAdapterException {
    try {
        LOGGER.info("Trying to find connection in cache for deviceIdentification: {}", deviceIdentification);
        final Iec61850Connection iec61850Connection = this.fetchIec61850Connection(deviceIdentification);
        if (iec61850Connection != null) {
            // Already connected, check if connection is still usable.
            LOGGER.info("Connection found for deviceIdentification: {}", deviceIdentification);
            // requires manual reads of remote data.
            if (ied != null && logicalDevice != null) {
                final String description = this.getActualServerName(ied, serverName);
                LOGGER.info("Testing if connection is alive using {}{}/{}.{} for deviceIdentification: {}", description, logicalDevice, LogicalNode.LOGICAL_NODE_ZERO.getDescription(), DataAttribute.NAME_PLATE.getDescription(), deviceIdentification);
                final FcModelNode modelNode = this.getModelNode(logicalDevice, iec61850Connection, description);
                this.iec61850Client.readNodeDataValues(iec61850Connection.getClientAssociation(), modelNode);
            } else {
                // Read all data values, which is much slower, but requires
                // no manual reads of remote data.
                LOGGER.info("Testing if connection is alive using readAllDataValues() for deviceIdentification: {}", deviceIdentification);
                this.iec61850Client.readAllDataValues(iec61850Connection.getClientAssociation());
            }
            LOGGER.info("Connection is still active for deviceIdentification: {}", deviceIdentification);
            return true;
        }
    } catch (final NodeReadException e) {
        LOGGER.error("Connection is no longer active, removing connection from cache for deviceIdentification: " + deviceIdentification, e);
        this.disconnect(deviceIdentification);
    }
    return false;
}
Also used : Iec61850Connection(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.Iec61850Connection) NodeReadException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeReadException) FcModelNode(com.beanit.openiec61850.FcModelNode)

Example 8 with NodeReadException

use of org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeReadException in project open-smart-grid-platform by OSGP.

the class Iec61850DeviceConnectionService method readAllValues.

public void readAllValues(final String deviceIdentification) throws NodeReadException {
    final Iec61850Connection iec61850Connection = this.fetchIec61850Connection(deviceIdentification);
    if (iec61850Connection == null) {
        return;
    }
    final ClientAssociation clientAssociation = iec61850Connection.getClientAssociation();
    this.iec61850Client.readAllDataValues(clientAssociation);
}
Also used : Iec61850Connection(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.Iec61850Connection) Iec61850ClientAssociation(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.Iec61850ClientAssociation) ClientAssociation(com.beanit.openiec61850.ClientAssociation)

Example 9 with NodeReadException

use of org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeReadException in project open-smart-grid-platform by OSGP.

the class Iec61850DeviceConnectionService method readNodeDataValues.

public void readNodeDataValues(final String deviceIdentification, final FcModelNode fcModelNode) throws NodeReadException {
    final Iec61850Connection iec61850Connection = this.fetchIec61850Connection(deviceIdentification);
    if (iec61850Connection == null) {
        return;
    }
    final ClientAssociation clientAssociation = iec61850Connection.getClientAssociation();
    this.iec61850Client.readNodeDataValues(clientAssociation, fcModelNode);
}
Also used : Iec61850Connection(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.Iec61850Connection) Iec61850ClientAssociation(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.Iec61850ClientAssociation) ClientAssociation(com.beanit.openiec61850.ClientAssociation)

Example 10 with NodeReadException

use of org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeReadException in project open-smart-grid-platform by OSGP.

the class Iec61850Client method sendCommandWithRetry.

/**
 * Executes the apply method of the given {@link Function} with retries and message logging.
 *
 * @return The given T.
 */
public <T> T sendCommandWithRetry(final Function<T> function, final String functionName, final String deviceIdentification) throws ProtocolAdapterException {
    T output = null;
    final DeviceMessageLog deviceMessageLog = new DeviceMessageLog(IED.FLEX_OVL, LogicalDevice.LIGHTING, functionName);
    try {
        output = function.apply(deviceMessageLog);
    } catch (final NodeWriteException | NodeReadException e) {
        if (ConnectionState.OK.equals(e.getConnectionState())) {
            // ServiceError means we have to retry.
            LOGGER.error("Caught ServiceError, retrying", e);
            this.sendCommandWithRetry(function, deviceIdentification, 1, deviceMessageLog);
        } else {
            LOGGER.error("Caught IOException, connection with device is broken.", e);
        }
    } catch (final ProtocolAdapterException e) {
        throw e;
    } catch (final Exception e) {
        throw new ProtocolAdapterException(e.getMessage() == null ? COULD_NOT_EXECUTE_COMMAND : e.getMessage(), e);
    }
    return output;
}
Also used : DeviceMessageLog(org.opensmartgridplatform.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog) NodeWriteException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeWriteException) NodeReadException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeReadException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) NodeReadException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeReadException) ConnectionFailureException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) IOException(java.io.IOException) SclParseException(com.beanit.openiec61850.SclParseException) NodeWriteException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeWriteException)

Aggregations

IOException (java.io.IOException)4 NodeReadException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeReadException)4 NodeReadException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.NodeReadException)3 Iec61850Connection (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.Iec61850Connection)3 ClientAssociation (com.beanit.openiec61850.ClientAssociation)2 NodeWriteException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeWriteException)2 Iec61850ClientAssociation (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.Iec61850ClientAssociation)2 DeviceMessageLog (com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog)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 Iec61850Connection (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.Iec61850Connection)1 FcModelNode (com.beanit.openiec61850.FcModelNode)1 SclParseException (com.beanit.openiec61850.SclParseException)1 ServiceError (com.beanit.openiec61850.ServiceError)1 DateTime (org.joda.time.DateTime)1 FcModelNode (org.openmuc.openiec61850.FcModelNode)1 SclParseException (org.openmuc.openiec61850.SclParseException)1 ServiceError (org.openmuc.openiec61850.ServiceError)1 Iec61850ReportEntry (org.opensmartgridplatform.adapter.protocol.iec61850.domain.entities.Iec61850ReportEntry)1