Skip to content
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

Merged
merged 8 commits into from
Jan 9, 2024

Conversation

elbert3
Copy link
Contributor

@elbert3 elbert3 commented Dec 20, 2023

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

List<Class<?>> candidateParamTypes = Arrays.asList(method.getParameterTypes());

if (candidateParamTypes.size() != methodParamTypes.size() || !candidateParamTypes.containsAll(methodParamTypes)) {
if(!Arrays.equals(method.getParameterTypes(), candidate.getParameterTypes())) {
Copy link
Contributor

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?

Copy link
Contributor Author

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);
Copy link
Contributor

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)

Copy link
Contributor Author

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);
Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

Copy link

codecov bot commented Jan 6, 2024

Codecov Report

Attention: 67 lines in your changes are missing coverage. Please review.

Comparison is base (09d0dd2) 20.63% compared to head (7850853) 20.73%.
Report is 12 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@              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     
Files Coverage Δ
.../eclipse/kapua/commons/event/ServiceInspector.java 71.42% <100.00%> (+59.12%) ⬆️
.../internal/DeviceConnectionEventListenerModule.java 100.00% <100.00%> (ø)
...al/DeviceConnectionEventListenerServiceModule.java 100.00% <100.00%> (ø)
...ry/DeviceConnectionServiceConfigurationModule.java 100.00% <ø> (ø)
.../service/device/registry/DeviceRegistryModule.java 83.33% <100.00%> (+4.76%) ⬆️
...a/service/device/registry/DeviceServiceModule.java 100.00% <100.00%> (ø)
...e/registry/internal/DeviceRegistryServiceImpl.java 7.44% <ø> (ø)
...commons/event/ServiceEventTransactionalModule.java 23.52% <91.66%> (+11.46%) ⬆️
...thentication/AuthenticationServiceBackEndCall.java 0.00% <0.00%> (ø)
...emis/plugin/security/event/BrokerEventHandler.java 0.00% <0.00%> (ø)
... and 6 more

... and 6 files with indirect coverage changes

…ed the docker environment to be setup

Signed-off-by: Elbert Evangelista <[email protected]>
@elbert3 elbert3 force-pushed the feature-disconnectDevice branch from 4ab0af6 to 7850853 Compare January 9, 2024 20:36
@elbert3 elbert3 merged commit c7159d4 into eclipse-kapua:develop Jan 9, 2024
31 of 32 checks passed
@Coduz Coduz added the Enhancement This PR/Issue improves an part of Kapua label Jan 11, 2024
Coduz added a commit to Coduz/kapua that referenced this pull request Jan 11, 2024
…opeId,deviceConnectionid) - errata for eclipse-kapua#3924

Signed-off-by: Alberto Codutti <[email protected]>
Coduz added a commit that referenced this pull request Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement This PR/Issue improves an part of Kapua
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants