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

feat(web2): Replace NetAdmin with ConfigurationService in GwtNetworkConfigurationService #3964

Merged
merged 17 commits into from
May 14, 2022

Conversation

pierantoniomerlino
Copy link
Contributor

@pierantoniomerlino pierantoniomerlino commented Apr 27, 2022

This PR replaces the NetAdminService with the ConfigurationService for updating the network and firewall configuration from the webUI.

@pierantoniomerlino pierantoniomerlino self-assigned this Apr 27, 2022
@MMaiero MMaiero requested a review from nicolatimeus April 27, 2022 16:24
@pierantoniomerlino pierantoniomerlino changed the title Replace NetAdmin with ConfigurationService in GwtNetworkConfigurationService feat(web): Replace NetAdmin with ConfigurationService in GwtNetworkConfigurationService Apr 29, 2022
@pierantoniomerlino pierantoniomerlino changed the title feat(web): Replace NetAdmin with ConfigurationService in GwtNetworkConfigurationService feat(web2): Replace NetAdmin with ConfigurationService in GwtNetworkConfigurationService Apr 29, 2022
@@ -66,7 +66,10 @@ public List<? extends NetInterfaceConfig<? extends NetInterfaceAddressConfig>> g
* @param mtu
* - required MTU for the interface, -1 to keep the automatic default
* @throws KuraException
*
* @deprecated Since 2.4
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we suggest the use of other APIs in replacement of these?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't exist a 1-to-1 replacement of this API. We can suggest to use directly the ConfigurationService.

nat.append(entry.getInInterface()).append(",");
nat.append(entry.getOutInterface()).append(",");
nat.append(entry.getProtocol()).append(",");
if (entry.getSourceNetwork() == null || entry.getSourceNetwork().equals(UNKNOWN_NETWORK)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe better using Objects.isNull()?

Copy link
Contributor

Choose a reason for hiding this comment

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

Or comparing using UNKNOWN_NETWORK.equals(entry.getSourceNetwork())?

firewallPortForwardConfigIP.setPermittedNetwork(new NetworkPair<>(
(IP4Address) IPAddress.parseHostAddress(network), Short.parseShort(prefix)));
nat.append(",");
if (entry.getDestinationNetwork() == null || entry.getDestinationNetwork().equals(UNKNOWN_NETWORK)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

@MMaiero
Copy link
Contributor

MMaiero commented May 2, 2022

I have tested in a device with ppp connection and even if the device was able to set the IP, no dns servers are set living an empty value and preventing from connecting to the cloud.

@MMaiero
Copy link
Contributor

MMaiero commented May 2, 2022

2022-05-02T13:51:20,616 [pool-34-thread-1] INFO  o.e.k.n.a.m.ModemMonitorServiceImpl - monitor() :: previous PppState=CONNECTED
2022-05-02T13:51:20,618 [pool-34-thread-1] INFO  o.e.k.n.a.m.ModemMonitorServiceImpl - monitor() :: current PppState=IN_PROGRESS
2022-05-02T13:51:20,619 [pool-34-thread-1] INFO  o.e.k.n.a.m.ModemMonitorServiceImpl - monitor() :: Modem will be reset in 299 sec if not connected
2022-05-02T13:51:20,637 [pool-34-thread-1] WARN  o.e.k.l.n.u.LinuxNetworkUtil - error reading /sys/class/net/ppp1/carrier_changes, error message /sys/class/net/ppp1/carrier_changes (No such file or directory)
2022-05-02T13:51:20,673 [EventAdmin Async Event Dispatcher Thread] INFO  o.e.k.n.a.m.DnsMonitorServiceImpl - Current DNS servers are null - setting dns servers: []
2022-05-02T13:51:27,359 [DataServiceImpl:ReconnectTask:org.eclipse.kura.data.DataService] INFO  o.e.k.c.d.DataServiceImpl - Connecting...
2022-05-02T13:51:27,360 [DataServiceImpl:ReconnectTask:org.eclipse.kura.data.DataService] INFO  o.e.k.c.d.t.m.MqttDataTransport - Creating a new client instance
2022-05-02T13:51:27,362 [DataServiceImpl:ReconnectTask:org.eclipse.kura.data.DataService] INFO  o.e.k.c.d.t.m.MqttDataTransport - Using memory persistence for in-flight messages
2022-05-02T13:51:27,366 [DataServiceImpl:ReconnectTask:org.eclipse.kura.data.DataService] INFO  o.e.k.c.d.t.m.MqttDataTransport - # ------------------------------------------------------------
2022-05-02T13:51:27,367 [DataServiceImpl:ReconnectTask:org.eclipse.kura.data.DataService] INFO  o.e.k.c.d.t.m.MqttDataTransport - #  Connection Properties
2022-05-02T13:51:27,369 [DataServiceImpl:ReconnectTask:org.eclipse.kura.data.DataService] INFO  o.e.k.c.d.t.m.MqttDataTransport - #  broker    = ssl://<endpoint>:8883
2022-05-02T13:51:27,370 [DataServiceImpl:ReconnectTask:org.eclipse.kura.data.DataService] INFO  o.e.k.c.d.t.m.MqttDataTransport - #  clientId  = clientid
2022-05-02T13:51:27,371 [DataServiceImpl:ReconnectTask:org.eclipse.kura.data.DataService] INFO  o.e.k.c.d.t.m.MqttDataTransport - #  username  = username
2022-05-02T13:51:27,372 [DataServiceImpl:ReconnectTask:org.eclipse.kura.data.DataService] INFO  o.e.k.c.d.t.m.MqttDataTransport - #  password  = XXXXXXXXXXXXXX
2022-05-02T13:51:27,372 [DataServiceImpl:ReconnectTask:org.eclipse.kura.data.DataService] INFO  o.e.k.c.d.t.m.MqttDataTransport - #  keepAlive = 30
2022-05-02T13:51:27,373 [DataServiceImpl:ReconnectTask:org.eclipse.kura.data.DataService] INFO  o.e.k.c.d.t.m.MqttDataTransport - #  timeout   = 20
2022-05-02T13:51:27,374 [DataServiceImpl:ReconnectTask:org.eclipse.kura.data.DataService] INFO  o.e.k.c.d.t.m.MqttDataTransport - #  cleanSession    = true
2022-05-02T13:51:27,375 [DataServiceImpl:ReconnectTask:org.eclipse.kura.data.DataService] INFO  o.e.k.c.d.t.m.MqttDataTransport - #  MQTT version    = 3.1.1
2022-05-02T13:51:27,375 [DataServiceImpl:ReconnectTask:org.eclipse.kura.data.DataService] INFO  o.e.k.c.d.t.m.MqttDataTransport - #  willDestination = $EDC/ec-provisioning/00E0C709917D/MQTT/LWT
2022-05-02T13:51:27,376 [DataServiceImpl:ReconnectTask:org.eclipse.kura.data.DataService] INFO  o.e.k.c.d.t.m.MqttDataTransport - #  willMessage     =
2022-05-02T13:51:27,377 [DataServiceImpl:ReconnectTask:org.eclipse.kura.data.DataService] INFO  o.e.k.c.d.t.m.MqttDataTransport - #
2022-05-02T13:51:27,378 [DataServiceImpl:ReconnectTask:org.eclipse.kura.data.DataService] INFO  o.e.k.c.d.t.m.MqttDataTransport - #  Connecting...
2022-05-02T13:51:27,382 [MQTT Con: 00E0C709917D] INFO  o.e.k.c.s.SSLSocketFactoryWrapper - SSL Endpoint Identification enabled.
2022-05-02T13:51:27,386 [DataServiceImpl:ReconnectTask:org.eclipse.kura.data.DataService] WARN  o.e.k.c.d.t.m.MqttDataTransport - xxxxx  Connect failed. Forcing disconnect. xxxxx
2022-05-02T13:51:27,387 [DataServiceImpl:ReconnectTask:org.eclipse.kura.data.DataService] INFO  o.e.k.c.d.t.m.MqttDataTransport - Forcing client disconnect...
2022-05-02T13:51:52,014 [pool-34-thread-1] INFO  o.e.k.n.a.m.ModemMonitorServiceImpl - monitor() :: previous PppState=IN_PROGRESS
2022-05-02T13:51:52,015 [pool-34-thread-1] INFO  o.e.k.n.a.m.ModemMonitorServiceImpl - monitor() :: current PppState=CONNECTED
2022-05-02T13:51:52,066 [EventAdmin Async Event Dispatcher Thread] INFO  o.e.k.n.a.m.DnsMonitorServiceImpl - Current DNS servers are null - setting dns servers: []
2022-05-02T13:51:57,398 [DataServiceImpl:ReconnectTask:org.eclipse.kura.data.DataService] INFO  o.e.k.c.d.t.m.MqttDataTransport - Closing client...
2022-05-02T13:51:57,399 [DataServiceImpl:ReconnectTask:org.eclipse.kura.data.DataService] INFO  o.e.k.c.d.t.m.MqttDataTransport - Closed
2022-05-02T13:51:57,400 [DataServiceImpl:ReconnectTask:org.eclipse.kura.data.DataService] WARN  o.e.k.c.d.DataServiceImpl - Connect failed
org.eclipse.kura.KuraConnectException: "Connection failed. Cannot connect"
	at org.eclipse.kura.core.data.transport.mqtt.MqttDataTransport.connect(MqttDataTransport.java:359)
	at org.eclipse.kura.core.data.DataServiceImpl$2.run(DataServiceImpl.java:606)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: MqttException (0) - java.net.UnknownHostException: broker-sbx.everyware.io
	at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:38)
	at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:736)
	... 1 more
Caused by: java.net.UnknownHostException: broker-sbx.everyware.io
	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
	at java.net.Socket.connect(Socket.java:607)
	at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:284)
	at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start(TCPNetworkModule.java:74)
	at org.eclipse.paho.client.mqttv3.internal.SSLNetworkModule.start(SSLNetworkModule.java:130)
	at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:722)
	... 1 more

@pierantoniomerlino pierantoniomerlino force-pushed the web_configuration_service branch from 25685e7 to 258d267 Compare May 5, 2022 13:55
@MMaiero
Copy link
Contributor

MMaiero commented May 9, 2022

@pierantoniomerlino is the PR ready for review? Please also give a check on sonar

@pierantoniomerlino
Copy link
Contributor Author

I'm running some tests for the dhcp feature. I'll take a look at sonar too.

private void fillDhcpServerProperties(GwtNetInterfaceConfig config, Map<String, Object> properties,
String basePropName) throws UnknownHostException {
StringBuilder dhcpServer4PropName = new StringBuilder(basePropName).append("dhcpServer4.");
properties.put(dhcpServer4PropName.toString() + ENABLED, true);
Copy link
Contributor

Choose a reason for hiding this comment

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

StringBuilder.toString() allocates a new string at each invocation. As an enhancement we could refactor the code to avoid calling this method multiple times to produce the same string.

}
try {
for (GwtFirewallOpenPortEntry entry : entries) {
openPorts.append(entry.getPortRange()).append(",");
Copy link
Contributor

@nicolatimeus nicolatimeus May 10, 2022

Choose a reason for hiding this comment

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

If entry.getPortRange() returns null, this will probably add the null string in the configuration. Is this ok? This probably applies also to other fields.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mhh... the null value is not allowed here. I mean, the web UI forces to set a value in the port range property.

@pierantoniomerlino pierantoniomerlino force-pushed the web_configuration_service branch from 0c1aced to 489a2fe Compare May 10, 2022 13:49
@MMaiero MMaiero merged commit ec6e97e into develop May 14, 2022
@MMaiero MMaiero deleted the web_configuration_service branch May 14, 2022 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants