Search in sources :

Example 21 with ConnectionException

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

the class DlmsConnectionHelperTest method initializesInvocationCounterWhenInvocationCounterIsOutOfSyncForLAndGDevice.

@Test
void initializesInvocationCounterWhenInvocationCounterIsOutOfSyncForLAndGDevice() throws Exception {
    final DlmsDevice device = new DlmsDeviceBuilder().withHls5Active(true).withProtocol("SMR").withInvocationCounter(123L).build();
    final DlmsMessageListener listener = new InvocationCountingDlmsMessageListener();
    final ConnectionException exception = new ConnectionException("Error creating connection for device E0051004228715518 with Ip address:62.133.88.34 Port:null " + "UseHdlc:false UseSn:false Message:Socket was closed by remote host.");
    doThrow(exception).when(this.connectionFactory).createAndHandleConnection(this.messageMetadata, device, listener, null, this.task);
    assertThrows(ConnectionException.class, () -> this.helper.createAndHandleConnectionForDevice(this.messageMetadata, device, listener, null, this.task));
    verify(this.invocationCounterManager).initializeInvocationCounter(this.messageMetadata, device);
    verify(this.connectionFactory, times(2)).createAndHandleConnection(this.messageMetadata, device, listener, null, this.task);
}
Also used : DlmsMessageListener(org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.DlmsMessageListener) InvocationCountingDlmsMessageListener(org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener) InvocationCountingDlmsMessageListener(org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) DlmsDeviceBuilder(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder) ConnectionException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException) Test(org.junit.jupiter.api.Test)

Example 22 with ConnectionException

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

the class DlmsConnectionHelperTest method doesNotResetInvocationCounterWhenInvocationCounterIsOutOfSyncForDeviceThatNeedsNoInvocationCounter.

@Test
void doesNotResetInvocationCounterWhenInvocationCounterIsOutOfSyncForDeviceThatNeedsNoInvocationCounter() throws Exception {
    final DlmsDevice device = new DlmsDeviceBuilder().withHls5Active(true).withProtocol("DSMR").withInvocationCounter(123L).build();
    final DlmsMessageListener listener = new InvocationCountingDlmsMessageListener();
    final ConnectionException exception = new ConnectionException("Error creating connection for device E0051004228715518 with Ip address:62.133.88.34 Port:null " + "UseHdlc:false UseSn:false Message:Socket was closed by remote host.");
    doThrow(exception).when(this.connectionFactory).createAndHandleConnection(this.messageMetadata, device, listener, null, this.task);
    assertThrows(ConnectionException.class, () -> this.helper.createAndHandleConnectionForDevice(this.messageMetadata, device, listener, this.task));
    verifyNoMoreInteractions(this.invocationCounterManager);
}
Also used : DlmsMessageListener(org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.DlmsMessageListener) InvocationCountingDlmsMessageListener(org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener) InvocationCountingDlmsMessageListener(org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) DlmsDeviceBuilder(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder) ConnectionException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException) Test(org.junit.jupiter.api.Test)

Example 23 with ConnectionException

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

the class DlmsHelper method getWithList.

public List<GetResult> getWithList(final DlmsConnectionManager conn, final DlmsDevice device, final AttributeAddress... params) throws ProtocolAdapterException {
    try {
        if (device.isWithListSupported()) {
            // Getting a too large list of attribute addresses in one get
            // from the DlmsConnection
            // might result in a SCOPE_OF_ACCESS_VIOLATED error
            final List<GetResult> getResults = new ArrayList<>();
            final List<AttributeAddress[]> maximizedSubsetsOfParams = this.getMaximizedSubsetsOfParams(params);
            for (final AttributeAddress[] maximizedSubsetOfParams : maximizedSubsetsOfParams) {
                getResults.addAll(conn.getConnection().get(Arrays.asList(maximizedSubsetOfParams)));
            }
            return getResults;
        } else {
            return this.getWithListWorkaround(conn, params);
        }
    } catch (final IOException | NullPointerException e) {
        // JDlmsException).
        throw new ConnectionException("Connection error retrieving values with-list for device: " + device.getDeviceIdentification(), e);
    } catch (final Exception e) {
        throw new ProtocolAdapterException("Error retrieving values with-list for device: " + device.getDeviceIdentification() + ", with-list: " + (device.isWithListSupported() ? "supported" : "not supported"), e);
    }
}
Also used : GetResult(org.openmuc.jdlms.GetResult) ArrayList(java.util.ArrayList) AttributeAddress(org.openmuc.jdlms.AttributeAddress) IOException(java.io.IOException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) ConnectionException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException) BufferedDateTimeValidationException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.BufferedDateTimeValidationException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ConnectionException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) IOException(java.io.IOException)

Example 24 with ConnectionException

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

the class DlmsHelper method getAttributeValue.

/**
 * Gets a single result from a meter, and returns the result data if retrieval was successful
 * (resultCode of the GetResult equals AccessResultCode.SUCCESS).
 *
 * @return a result from trying to retrieve the value for the attribute identified by {@code
 *     attributeAddress}.
 */
public DataObject getAttributeValue(final DlmsConnectionManager conn, final AttributeAddress attributeAddress) throws FunctionalException {
    Objects.requireNonNull(conn, "conn must not be null");
    Objects.requireNonNull(attributeAddress, "attributeAddress must not be null");
    try {
        final GetResult getResult = conn.getConnection().get(attributeAddress);
        final AccessResultCode resultCode = getResult.getResultCode();
        if (AccessResultCode.SUCCESS == resultCode) {
            return getResult.getResultData();
        }
        final String errorMessage = String.format("Retrieving attribute value for { %d, %s, %d }. Result: resultCode(%d), with data: %s", attributeAddress.getClassId(), attributeAddress.getInstanceId().asShortObisCodeString(), attributeAddress.getId(), resultCode.getCode(), this.getDebugInfo(getResult.getResultData()));
        LOGGER.error(errorMessage);
        throw new FunctionalException(FunctionalExceptionType.ERROR_RETRIEVING_ATTRIBUTE_VALUE, ComponentType.PROTOCOL_DLMS, new OsgpException(ComponentType.PROTOCOL_DLMS, errorMessage));
    } catch (final IOException e) {
        throw new ConnectionException(e);
    }
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) GetResult(org.openmuc.jdlms.GetResult) AccessResultCode(org.openmuc.jdlms.AccessResultCode) BitString(org.openmuc.jdlms.datatypes.BitString) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) IOException(java.io.IOException) ConnectionException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)

Example 25 with ConnectionException

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

the class Lls1Connector method connect.

@Override
public DlmsConnection connect(final MessageMetadata messageMetadata, final DlmsDevice device, final DlmsMessageListener dlmsMessageListener) throws OsgpException {
    // Make sure neither device or device.getIpAddress() is null.
    this.checkDevice(device);
    this.checkIpAddress(device);
    try {
        return this.createConnection(messageMetadata, device, dlmsMessageListener, this.secretManagementService::getKeys);
    } catch (final UnknownHostException e) {
        LOGGER.warn("The IP address is not found: {}", device.getIpAddress(), e);
        // Unknown IP, unrecoverable.
        throw new TechnicalException(ComponentType.PROTOCOL_DLMS, "The IP address is not found: " + device.getIpAddress());
    } catch (final IOException e) {
        throw new ConnectionException(e);
    } catch (final EncrypterException e) {
        LOGGER.error("decryption of security keys failed for device: {}", device.getDeviceIdentification(), e);
        throw new TechnicalException(ComponentType.PROTOCOL_DLMS, "decryption of security keys failed for device: " + device.getDeviceIdentification());
    }
}
Also used : TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) UnknownHostException(java.net.UnknownHostException) EncrypterException(org.opensmartgridplatform.shared.exceptionhandling.EncrypterException) IOException(java.io.IOException) ConnectionException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)

Aggregations

ConnectionException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)25 IOException (java.io.IOException)18 DataObject (org.openmuc.jdlms.datatypes.DataObject)9 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)8 AttributeAddress (org.openmuc.jdlms.AttributeAddress)7 GetResult (org.openmuc.jdlms.GetResult)6 Test (org.junit.jupiter.api.Test)5 SetParameter (org.openmuc.jdlms.SetParameter)5 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)5 DlmsDeviceBuilder (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder)4 DlmsMessageListener (org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.DlmsMessageListener)4 InvocationCountingDlmsMessageListener (org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener)4 EncrypterException (org.opensmartgridplatform.shared.exceptionhandling.EncrypterException)4 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)4 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)4 UnknownHostException (java.net.UnknownHostException)3 AccessResultCode (org.openmuc.jdlms.AccessResultCode)3 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)3 ArrayList (java.util.ArrayList)2 MethodParameter (org.openmuc.jdlms.MethodParameter)2