Skip to content

Commit

Permalink
refactor: remove birth.cert.policy from standard cloud service implem…
Browse files Browse the repository at this point in the history
…entations (#4859)

* refactor(core.cloud): removed birth.cert.policy option

Signed-off-by: Marcello Martina <[email protected]>

* refactor: updated snapshots to remove birth.cert.policy option from cloud connections

Signed-off-by: Marcello Martina <[email protected]>

* test: adjusted tests for missing property

Signed-off-by: Marcello Martina <[email protected]>

* refactor: remove unused class

Signed-off-by: Marcello Martina <[email protected]>

* refactor: removed lefovers in tests

Signed-off-by: Marcello Martina <[email protected]>

---------

Signed-off-by: Marcello Martina <[email protected]>
  • Loading branch information
marcellorinaldo authored Sep 15, 2023
1 parent a9ed3b3 commit 613779f
Show file tree
Hide file tree
Showing 22 changed files with 6 additions and 336 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,6 @@
<esf:property array="false" encrypted="false" name="topic.control-prefix" type="String">
<esf:value>$EDC</esf:value>
</esf:property>
<esf:property array="false" encrypted="false" name="birth.cert.policy" type="String">
<esf:value>birth-connect-reconnect</esf:value>
</esf:property>
<esf:property array="false" encrypted="false" name="device.custom-name" type="String">
<esf:value>Unknown Generic Device</esf:value>
</esf:property>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,6 @@
<esf:property array="false" encrypted="false" name="topic.control-prefix" type="String">
<esf:value>$EDC</esf:value>
</esf:property>
<esf:property array="false" encrypted="false" name="birth.cert.policy" type="String">
<esf:value>birth-connect-reconnect</esf:value>
</esf:property>
<esf:property array="false" encrypted="false" name="device.custom-name" type="String">
<esf:value>Intel UP²</esf:value>
</esf:property>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,6 @@
<esf:property array="false" encrypted="false" name="topic.control-prefix" type="String">
<esf:value>$EDC</esf:value>
</esf:property>
<esf:property array="false" encrypted="false" name="birth.cert.policy" type="String">
<esf:value>birth-connect-reconnect</esf:value>
</esf:property>
<esf:property array="false" encrypted="false" name="device.custom-name" type="String">
<esf:value>Nvidia Jetson Nano</esf:value>
</esf:property>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,6 @@
<esf:property array="false" encrypted="false" name="topic.control-prefix" type="String">
<esf:value>$EDC</esf:value>
</esf:property>
<esf:property array="false" encrypted="false" name="birth.cert.policy" type="String">
<esf:value>birth-connect-reconnect</esf:value>
</esf:property>
<esf:property array="false" encrypted="false" name="device.custom-name" type="String">
<esf:value>Raspberry Pi</esf:value>
</esf:property>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,6 @@
<esf:property array="false" encrypted="false" name="topic.control-prefix" type="String">
<esf:value>$EDC</esf:value>
</esf:property>
<esf:property array="false" encrypted="false" name="birth.cert.policy" type="String">
<esf:value>birth-connect-reconnect</esf:value>
</esf:property>
<esf:property array="false" encrypted="false" name="device.custom-name" type="String">
<esf:value>Intel UP²</esf:value>
</esf:property>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,6 @@
<esf:property array="false" encrypted="false" name="topic.control-prefix" type="String">
<esf:value>$EDC</esf:value>
</esf:property>
<esf:property array="false" encrypted="false" name="birth.cert.policy" type="String">
<esf:value>birth-connect-reconnect</esf:value>
</esf:property>
<esf:property array="false" encrypted="false" name="device.custom-name" type="String">
<esf:value>Intel UP²</esf:value>
</esf:property>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,6 @@
<esf:property array="false" encrypted="false" name="topic.control-prefix" type="String">
<esf:value>$EDC</esf:value>
</esf:property>
<esf:property array="false" encrypted="false" name="birth.cert.policy" type="String">
<esf:value>birth-connect-reconnect</esf:value>
</esf:property>
<esf:property array="false" encrypted="false" name="device.custom-name" type="String">
<esf:value>Intel UP²</esf:value>
</esf:property>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,6 @@
<esf:property array="false" encrypted="false" name="topic.control-prefix" type="String">
<esf:value>$EDC</esf:value>
</esf:property>
<esf:property array="false" encrypted="false" name="birth.cert.policy" type="String">
<esf:value>birth-connect-reconnect</esf:value>
</esf:property>
<esf:property array="false" encrypted="false" name="device.custom-name" type="String">
<esf:value>Nvidia Jetson Nano</esf:value>
</esf:property>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,6 @@
<esf:property array="false" encrypted="false" name="topic.control-prefix" type="String">
<esf:value>$EDC</esf:value>
</esf:property>
<esf:property array="false" encrypted="false" name="birth.cert.policy" type="String">
<esf:value>birth-connect-reconnect</esf:value>
</esf:property>
<esf:property array="false" encrypted="false" name="device.custom-name" type="String">
<esf:value>Nvidia Jetson Nano</esf:value>
</esf:property>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,6 @@
<esf:property array="false" encrypted="false" name="topic.control-prefix" type="String">
<esf:value>$EDC</esf:value>
</esf:property>
<esf:property array="false" encrypted="false" name="birth.cert.policy" type="String">
<esf:value>birth-connect-reconnect</esf:value>
</esf:property>
<esf:property array="false" encrypted="false" name="device.custom-name" type="String">
<esf:value>Raspberry Pi 3/4</esf:value>
</esf:property>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,6 @@
<esf:property array="false" encrypted="false" name="topic.control-prefix" type="String">
<esf:value>$EDC</esf:value>
</esf:property>
<esf:property array="false" encrypted="false" name="birth.cert.policy" type="String">
<esf:value>birth-connect-reconnect</esf:value>
</esf:property>
<esf:property array="false" encrypted="false" name="device.custom-name" type="String">
<esf:value>Raspberry Pi 3/4</esf:value>
</esf:property>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,6 @@
<esf:property array="false" encrypted="false" name="topic.control-prefix" type="String">
<esf:value>$EDC</esf:value>
</esf:property>
<esf:property array="false" encrypted="false" name="birth.cert.policy" type="String">
<esf:value>birth-connect-reconnect</esf:value>
</esf:property>
<esf:property array="false" encrypted="false" name="device.custom-name" type="String">
<esf:value>Raspberry Pi 2</esf:value>
</esf:property>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,6 @@
<esf:property array="false" encrypted="false" name="topic.control-prefix" type="String">
<esf:value>$EDC</esf:value>
</esf:property>
<esf:property array="false" encrypted="false" name="birth.cert.policy" type="String">
<esf:value>birth-connect-reconnect</esf:value>
</esf:property>
<esf:property array="false" encrypted="false" name="device.custom-name" type="String">
<esf:value>Raspberry Pi 2</esf:value>
</esf:property>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,6 @@
required="true"
default="false"
description="Whether or not to republish the MQTT Birth Certificate on modem detection event"/>

<AD id="birth.cert.policy"
name="Birth Cert Policy"
type="String"
cardinality="0"
required="true"
default="birth-connect-reconnect"
description="Specify the birth certificate policy.">
<Option label="Disable publishing" value="disable" />
<Option label="Publish birth on connect" value="birth-connect" />
<Option label="Publish birth on connect and reconnect" value="birth-connect-reconnect" />
</AD>

<AD id="payload.encoding"
name="Payload Encoding"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ public class CloudConnectionManagerImpl
String rssi;
String modemFwVer;

private boolean birthPublished;
private String ownPid;

private final AtomicInteger messageId;
Expand Down Expand Up @@ -443,8 +442,6 @@ public void onDisconnecting() {
} catch (KuraException e) {
logger.warn("Cannot publish disconnect certificate");
}

this.birthPublished = false;
}

@Override
Expand Down Expand Up @@ -602,20 +599,7 @@ public KuraPayload buildFromByteArray(byte[] payload) throws KuraException {
// ----------------------------------------------------------------

private void setupCloudConnection(boolean isNewConnection) throws KuraException {
// publish birth certificate unless it has already been published
// and republish is disabled
boolean publishBirth = true;
if (this.birthPublished && !this.options.getRepubBirthCertOnReconnect()) {
publishBirth = false;
logger.info("Birth certificate republish is disabled in configuration");
}

// publish birth certificate
if (publishBirth) {
publishBirthCertificate(isNewConnection);
this.birthPublished = true;
}

publishBirthCertificate(isNewConnection);
setupDeviceSubscriptions();
}

Expand All @@ -630,10 +614,6 @@ private void setupDeviceSubscriptions() throws KuraException {
}

private void publishBirthCertificate(boolean isNewConnection) throws KuraException {
if (this.options.isLifecycleCertsDisabled()) {
return;
}

LifecycleMessage birthToPublish = new LifecycleMessage(this.options, this).asBirthCertificateMessage();

if (isNewConnection) {
Expand All @@ -644,10 +624,6 @@ private void publishBirthCertificate(boolean isNewConnection) throws KuraExcepti
}

private void publishDisconnectCertificate() throws KuraException {
if (this.options.isLifecycleCertsDisabled()) {
return;
}

publishLifeCycleMessage(new LifecycleMessage(this.options, this).asDisconnectCertificateMessage());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011, 2020 Eurotech and/or its affiliates and others
* Copyright (c) 2011, 2023 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -12,9 +12,6 @@
*******************************************************************************/
package org.eclipse.kura.internal.cloudconnection.eclipseiot.mqtt.cloud;

import static org.eclipse.kura.internal.cloudconnection.eclipseiot.mqtt.cloud.CloudServiceLifecycleCertsPolicy.DISABLE_PUBLISHING;
import static org.eclipse.kura.internal.cloudconnection.eclipseiot.mqtt.cloud.CloudServiceLifecycleCertsPolicy.PUBLISH_BIRTH_CONNECT_RECONNECT;

import java.util.Map;

import org.eclipse.kura.cloud.CloudPayloadEncoding;
Expand All @@ -37,7 +34,6 @@ public class CloudConnectionManagerOptions {
private static final String ENCODE_GZIP = "encode.gzip";
private static final String REPUB_BIRTH_ON_GPS_LOCK = "republish.mqtt.birth.cert.on.gps.lock";
private static final String REPUB_BIRTH_ON_MODEM_DETECT = "republish.mqtt.birth.cert.on.modem.detect";
private static final String BIRTH_CERT_POLICY = "birth.cert.policy";
private static final String PAYLOAD_ENCODING = "payload.encoding";

private static final int LIFECYCLE_QOS = 1;
Expand Down Expand Up @@ -133,45 +129,6 @@ public boolean getRepubBirthCertOnModemDetection() {
return repubBirth;
}

/**
* This method parses the Cloud Service configuration and returns true if the Cloud Service instance should
* not publish lifecycle messages.
*
* @return a boolean value.
*/
public boolean isLifecycleCertsDisabled() {
boolean birthPubDisabled = false;
String birthPubPolicy = "";
if (this.properties != null && this.properties.get(BIRTH_CERT_POLICY) != null
&& this.properties.get(BIRTH_CERT_POLICY) instanceof String) {
birthPubPolicy = (String) this.properties.get(BIRTH_CERT_POLICY);
}
if (DISABLE_PUBLISHING.getValue().equals(birthPubPolicy)) {
birthPubDisabled = true;
}
return birthPubDisabled;
}

/**
* This method parses the Cloud Service configuration and returns true if the Cloud Service instance should
* republish the birth message on a reconnection.
* By default, this method returns true.
*
* @return a boolean value.
*/
public boolean getRepubBirthCertOnReconnect() {
boolean republishBirt = true;
String birthPubPolicy = "";
if (this.properties != null && this.properties.get(BIRTH_CERT_POLICY) != null
&& this.properties.get(BIRTH_CERT_POLICY) instanceof String) {
birthPubPolicy = (String) this.properties.get(BIRTH_CERT_POLICY);
}
if (!PUBLISH_BIRTH_CONNECT_RECONNECT.getValue().equals(birthPubPolicy)) {
republishBirt = false;
}
return republishBirt;
}

/**
* This method parses the Cloud Service configuration and returns the selected cloud payload encoding.
* By default, this method returns {@link CloudPayloadEncoding} {@code KURA_PROTOBUF}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,7 @@
required="true"
default="true"
description="Manages the default subscriptions to the gateway management MQTT topics. When disabled, the gateway will not be remotely manageable."/>

<AD id="birth.cert.policy"
name="Birth Cert Policy"
type="String"
cardinality="0"
required="true"
default="birth-connect-reconnect"
description="Specify the birth certificate policy.">
<Option label="Disable publishing" value="disable" />
<Option label="Publish birth on connect" value="birth-connect" />
<Option label="Publish birth on connect and reconnect" value="birth-connect-reconnect" />
</AD>


<AD id="payload.encoding"
name="Payload Encoding"
type="String"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ public class CloudServiceImpl
String modemFwVer;

private boolean subscribed;
private boolean birthPublished;

private final AtomicInteger messageId;

Expand Down Expand Up @@ -572,8 +571,6 @@ public void onDisconnecting() {
} catch (KuraException e) {
logger.warn("Cannot publish disconnect certificate");
}

this.birthPublished = false;
}

@Override
Expand Down Expand Up @@ -808,19 +805,7 @@ private void setupCloudConnection(boolean isNewConnection) throws KuraException
this.subscribed = false;
}

// publish birth certificate unless it has already been published
// and republish is disabled
boolean publishBirth = true;
if (this.birthPublished && !this.options.getRepubBirthCertOnReconnect()) {
publishBirth = false;
logger.info("Birth certificate republish is disabled in configuration");
}

// publish birth certificate
if (publishBirth) {
publishBirthCertificate(isNewConnection);
this.birthPublished = true;
}
publishBirthCertificate(isNewConnection);

// restore or remove default subscriptions
if (this.options.getEnableDefaultSubscriptions()) {
Expand All @@ -838,10 +823,6 @@ private void setupCloudConnection(boolean isNewConnection) throws KuraException
}

private void publishBirthCertificate(boolean isNewConnection) throws KuraException {
if (this.options.isLifecycleCertsDisabled()) {
return;
}

LifecycleMessage birthToPublish = new LifecycleMessage(this.options, this).asBirthCertificateMessage();

if (isNewConnection) {
Expand All @@ -852,18 +833,10 @@ private void publishBirthCertificate(boolean isNewConnection) throws KuraExcepti
}

private void publishDisconnectCertificate() throws KuraException {
if (this.options.isLifecycleCertsDisabled()) {
return;
}

publishLifeCycleMessage(new LifecycleMessage(this.options, this).asDisconnectCertificateMessage());
}

private void publishAppCertificate() {
if (this.options.isLifecycleCertsDisabled()) {
return;
}

publishWithDelay(new LifecycleMessage(this.options, this).asAppCertificateMessage());
}

Expand Down
Loading

0 comments on commit 613779f

Please sign in to comment.