-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature - Add option to disconnect a device from the broker #3924
Feature - Add option to disconnect a device from the broker #3924
Conversation
Signed-off-by: Elbert Evangelista <[email protected]>
Signed-off-by: Elbert Evangelista <[email protected]>
Signed-off-by: Elbert Evangelista <[email protected]>
…vice events Signed-off-by: Elbert Evangelista <[email protected]>
Signed-off-by: Elbert Evangelista <[email protected]>
Signed-off-by: Elbert Evangelista <[email protected]>
…ion; check if a matching connection was found when processing the event Signed-off-by: Elbert Evangelista <[email protected]>
List<Class<?>> candidateParamTypes = Arrays.asList(method.getParameterTypes()); | ||
|
||
if (candidateParamTypes.size() != methodParamTypes.size() || !candidateParamTypes.containsAll(methodParamTypes)) { | ||
if(!Arrays.equals(method.getParameterTypes(), candidate.getParameterTypes())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you move this code to avoid NPE?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This actually fixes a bug I found with the previous implementation where it was not always finding the correct method since it just uses the containsAll
check instead of comparing the parameter type at each position. For example, if the candidateParamTypes list is (String, KapuaId), containsAll
would return true
when comparing another list with (String, String) or (KapuaId, String) or (KapuaId, KapuaId).
I updated it to instead use the Arrays.equals comparison which checks that they have the same number of elements, compares for equality at each position of the array, and it removes the need to first convert to a List.
@@ -515,6 +527,34 @@ public void disconnectClient(String clientName) throws Exception { | |||
} | |||
} | |||
|
|||
@When("I Force Disconnect connection with client id {string}") | |||
public void disconnectConnectionWithClientId(String clientId) throws Exception { | |||
DeviceConnection deviceConnection = deviceConnectionService.findByClientId(SYS_SCOPE_ID, clientId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could I suggest to use a parameter to provide the scopeId? (so the test can be invoked also for children accounts)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it's generated, would it be possible to specify a scopeId from a cucumber test? I agree that it would be a good idea to extend this (and other tests) to also check child accounts. But I think it would require a lot of other changes (i.e. setting up the accounts, connecting with those credentials, etc.) and might be better to do as a separate item.
Thread.sleep(1000); | ||
|
||
logger.info("Device(s) status countdown check: {}", timeout); | ||
DeviceConnection deviceConnection = deviceConnectionService.findByClientId(SYS_SCOPE_ID, clientId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could I suggest to use a parameter to provide the scopeId? (so the test can be invoked also for children accounts)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above.
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## develop #3924 +/- ##
=============================================
+ Coverage 20.63% 20.73% +0.09%
Complexity 6 6
=============================================
Files 1946 1951 +5
Lines 41665 41767 +102
Branches 3952 3959 +7
=============================================
+ Hits 8599 8661 +62
- Misses 32667 32703 +36
- Partials 399 403 +4
|
…ed the docker environment to be setup Signed-off-by: Elbert Evangelista <[email protected]>
4ab0af6
to
7850853
Compare
…opeId,deviceConnectionid) - errata for eclipse-kapua#3924 Signed-off-by: Alberto Codutti <[email protected]>
fix(javadoc): fixed javadoc after #3924
This adds the option to request that a DeviceConnection be disconnected from the broker via the REST API.
Related Issue
None
Description of the solution adopted
There was an existing "disconnect" method in the DeviceConnectionService API that had never been implemented and had been marked as deprecated. This adds an implementation for the disconnect request, but using the KapuaId of the connection instead of the clientId string. It works by raising a service event which the broker is listening for.
To implement this I added a new DeviceConnectionEventListenerService to setup the event listening, and the ServerPlugin registers itself with this service as a receiver of those messages. When it receives a disconnect event, it makes use of the existing BrokerEventHandler to perform the disconnection.
In order for this to work I also had to have the ServerPlugin setup the KapuaLocator, startup the ServiceModuleBundle, and add a JAXBContextProvider.
Screenshots
None
Any side note on the changes made
None