Skip to content

Commit

Permalink
FIX unable to update route at restart in Actility Thingpark
Browse files Browse the repository at this point in the history
  • Loading branch information
cpoder committed Jun 9, 2024
1 parent a0b0789 commit b252434
Show file tree
Hide file tree
Showing 32 changed files with 162 additions and 69 deletions.
2 changes: 1 addition & 1 deletion java/github-proxy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.softwareag</groupId>
<artifactId>lora</artifactId>
<version>1.0.1</version>
<version>1.1.0-SNAPSHOT</version>
</parent>

<artifactId>github-proxy</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion java/lora-codec-acs-switch/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.softwareag</groupId>
<artifactId>lora</artifactId>
<version>1.0.1</version>
<version>1.1.0-SNAPSHOT</version>
</parent>

<artifactId>lora-codec-acs-switch</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion java/lora-codec-atim-th/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.softwareag</groupId>
<artifactId>lora</artifactId>
<version>1.0.1</version>
<version>1.1.0-SNAPSHOT</version>
</parent>

<artifactId>lora-codec-atim-th</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion java/lora-codec-atim-tm2d/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.softwareag</groupId>
<artifactId>lora</artifactId>
<version>1.0.1</version>
<version>1.1.0-SNAPSHOT</version>
</parent>

<artifactId>lora-codec-atim-tm2d</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion java/lora-codec-atim-tmxd/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.softwareag</groupId>
<artifactId>lora</artifactId>
<version>1.0.1</version>
<version>1.1.0-SNAPSHOT</version>
</parent>

<artifactId>lora-codec-atim-tmxd</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion java/lora-codec-axioma/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.softwareag</groupId>
<artifactId>lora</artifactId>
<version>1.0.1</version>
<version>1.1.0-SNAPSHOT</version>
</parent>

<artifactId>lora-codec-axioma</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion java/lora-codec-c8y/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>com.softwareag</groupId>
<artifactId>lora</artifactId>
<version>1.0.1</version>
<version>1.1.0-SNAPSHOT</version>
</parent>

<artifactId>lora-codec-c8y</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion java/lora-codec-cayennelpp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.softwareag</groupId>
<artifactId>lora</artifactId>
<version>1.0.1</version>
<version>1.1.0-SNAPSHOT</version>
</parent>

<artifactId>lora-codec-cayennelpp</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion java/lora-codec-elsys/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.softwareag</groupId>
<artifactId>lora</artifactId>
<version>1.0.1</version>
<version>1.1.0-SNAPSHOT</version>
</parent>

<artifactId>lora-codec-elsys</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion java/lora-codec-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.softwareag</groupId>
<artifactId>lora</artifactId>
<version>1.0.1</version>
<version>1.1.0-SNAPSHOT</version>
</parent>

<artifactId>lora-codec-example</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion java/lora-codec-lansitec/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.softwareag</groupId>
<artifactId>lora</artifactId>
<version>1.0.1</version>
<version>1.1.0-SNAPSHOT</version>
</parent>

<artifactId>lora-codec-lansitec</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion java/lora-codec-ms/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.softwareag</groupId>
<artifactId>lora</artifactId>
<version>1.0.1</version>
<version>1.1.0-SNAPSHOT</version>
</parent>

<artifactId>lora-codec-ms</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion java/lora-codec-nke/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.softwareag</groupId>
<artifactId>lora</artifactId>
<version>1.0.1</version>
<version>1.1.0-SNAPSHOT</version>
</parent>

<artifactId>lora-codec-nke</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion java/lora-codec-pyrescom-classair/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.softwareag</groupId>
<artifactId>lora</artifactId>
<version>1.0.1</version>
<version>1.1.0-SNAPSHOT</version>
</parent>

<artifactId>lora-codec-pyrescom</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion java/lora-codec-semtech/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.softwareag</groupId>
<artifactId>lora</artifactId>
<version>1.0.1</version>
<version>1.1.0-SNAPSHOT</version>
</parent>

<artifactId>lora-codec-semtech</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion java/lora-codec-senlab/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.softwareag</groupId>
<artifactId>lora</artifactId>
<version>1.0.1</version>
<version>1.1.0-SNAPSHOT</version>
</parent>

<artifactId>lora-codec-senlab</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion java/lora-interface/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.softwareag</groupId>
<artifactId>lora</artifactId>
<version>1.0.1</version>
<version>1.1.0-SNAPSHOT</version>
</parent>

<artifactId>lora-interface</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion java/lora-ns-actility/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.softwareag</groupId>
<artifactId>lora</artifactId>
<version>1.0.1</version>
<version>1.1.0-SNAPSHOT</version>
</parent>

<artifactId>lora-ns-actility</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import lora.ns.actility.api.model.appserver.AppServerCustomHttpHeadersInner;
import lora.ns.actility.api.model.appserver.AppServerHttpLorawanDestination;
import lora.ns.actility.api.model.appserver.AppServerStrategy;
import lora.ns.actility.api.model.appserver.AppServerUpdate;
import lora.ns.actility.api.model.appserver.DownlinkSecurity;
import lora.ns.actility.api.model.basestation.Bs;
import lora.ns.actility.api.model.basestation.BsAppServersInner;
Expand All @@ -65,7 +66,6 @@
import lora.ns.actility.api.model.device.DeviceProfiles;
import lora.ns.actility.api.model.device.DeviceProfilesBriefsInner;
import lora.ns.actility.common.RandomUtils;
import lora.ns.actility.rest.ActilityAdminService;
import lora.ns.actility.rest.ActilityServiceAccountService;
import lora.ns.actility.rest.JwtInterceptor;
import lora.ns.connector.LNSAbstractConnector;
Expand All @@ -78,13 +78,13 @@
@Slf4j
public class ActilityConnector extends LNSAbstractConnector {

private static final String THINGPARK_WIRELESS_REST = "/thingpark/wireless/rest";
private static final String AS_ID_PROPERTY = "asId";
private static final String AS_KEY_PROPERTY = "asKey";
private static final String AS_ID_PREFIX = "cumulocity-";
private static final String DEFAULT_AS_ID = "cumulocity";
private static final String DEFAULT_AS_KEY = "4e0ff46472fa1840f25368c066e94769";

private ActilityAdminService actilityAdminService;
private ActilityServiceAccountService actilityServiceAccountService;

private DeviceApi deviceApi;
Expand All @@ -108,12 +108,7 @@ public DXAdminJWTInterceptor(String clientId, String clientSecret) {
protected String getToken() {
Token token = null;
try {
if (this.clientId.contains("/")) {
token = actilityServiceAccountService.getToken("client_credentials", this.clientId,
this.clientSecret);
} else {
token = actilityAdminService.getToken("client_credentials", this.clientId, this.clientSecret);
}
token = actilityServiceAccountService.getToken("client_credentials", this.clientId, this.clientSecret);
} catch (Exception e) {
throw new LoraException("Couldn't get JWT", e);
}
Expand Down Expand Up @@ -176,14 +171,8 @@ protected void init() {
final ch.qos.logback.classic.Logger serviceLogger = (ch.qos.logback.classic.Logger) LoggerFactory
.getLogger("lora.ns.actility");
serviceLogger.setLevel(ch.qos.logback.classic.Level.DEBUG);
var feignBuilder = Feign.builder().client(new Client.Default(getSSLSocketFactory(), getHostnameVerifier()))
.decoder(new JacksonDecoder(objectMapper)).encoder(new FormEncoder())
.logger(new Slf4jLogger("lora.ns.actility")).logLevel(Level.FULL)
.requestInterceptor(template -> template.header("Content-Type",
"application/x-www-form-urlencoded"));
String url = properties.getProperty("url");
actilityAdminService = feignBuilder.target(ActilityAdminService.class, url + "/thingpark/dx/admin/latest/api/");
feignBuilder = Feign.builder().client(new Client.Default(getSSLSocketFactory(), getHostnameVerifier()))
var feignBuilder = Feign.builder().client(new Client.Default(getSSLSocketFactory(), getHostnameVerifier()))
.decoder(new JacksonDecoder(objectMapper)).encoder(new FormEncoder())
.logger(new Slf4jLogger("lora.ns.actility")).logLevel(Level.FULL)
.requestInterceptor(template -> template.header("Content-Type",
Expand All @@ -199,9 +188,9 @@ protected void init() {
feignBuilder = feignBuilder.requestInterceptor(new DXAdminJWTInterceptor(properties.getProperty("username"),
properties.getProperty("password")));

deviceApi = feignBuilder.target(DeviceApi.class, url + "/thingpark/wireless/rest");
appServerApi = feignBuilder.target(AppServerApi.class, url + "/thingpark/wireless/rest");
baseStationApi = feignBuilder.target(BaseStationApi.class, url + "/thingpark/wireless/rest");
deviceApi = feignBuilder.target(DeviceApi.class, url + THINGPARK_WIRELESS_REST);
appServerApi = feignBuilder.target(AppServerApi.class, url + THINGPARK_WIRELESS_REST);
baseStationApi = feignBuilder.target(BaseStationApi.class, url + THINGPARK_WIRELESS_REST);
downlinkV2Api = feignBuilder.target(DownlinkApi.class, url + "/thingpark/lrc/rest");
}

Expand Down Expand Up @@ -244,25 +233,30 @@ public void provisionDevice(DeviceProvisioning deviceProvisioning) {

@Override
public void configureRoutings(String url, String tenant, String login, String password) {
log.info("Configuring routings to: {} with credentials: {}:{}", url, login, password);
String domain = properties.getProperty("domain");
String group = properties.getProperty("group");
log.info("Configuring routings to: {} with credentials: {}:{} and domain {}:{}", url, login, password, domain,
group);

var appServers = appServerApi.getAppServersByName(tenant + "-" + getId());
if (!appServers.getBriefs().isEmpty()) {
// Update appserver
this.appServerId = appServers.getBriefs().iterator().next().getID();
String uid = appServers.getBriefs().iterator().next().getID().split("\\.")[1];
var appServer = new AppServer();
appServer.setType(null);
appServer.setContentType(ContentTypeEnum.JSON);
var currentAppServer = appServers.getBriefs().iterator().next();
this.appServerId = currentAppServer.getID();
String uid = currentAppServer.getID().split("\\.")[1];
var appServer = new AppServerUpdate();
appServer.setCustomHttpHeaders(new ArrayList<>());
appServer.addCustomHttpHeadersItem(new AppServerCustomHttpHeadersInner().name("Authentication")
.value("Basic " + Base64.getEncoder()
.encodeToString((tenant + "/" + login + ":" + password).getBytes())));
appServer.setDestinations(new ArrayList<>());
appServer.addDestinationsItem(new AppServerHttpLorawanDestination().addAddressesItem(url + "/uplink")
.strategy(AppServerStrategy.SEQUENTIAL).ports("*"));
appServer.downlinkSecurity(new DownlinkSecurity(getAsId(), getAsKey()));
// appServerApi.updateAppServer(uid, appServer); <- doesn't work, 403
if (properties.containsKey("domain")) {
appServer.addDomainsItem(new Domain().name(properties.getProperty("domain"))
.group(new DomainGroup().name(properties.getProperty("group"))));
}
appServerApi.updateAppServer(uid, appServer);
} else {
// Create appserver
var appServer = new AppServer().contentType(ContentTypeEnum.JSON)
Expand All @@ -287,7 +281,7 @@ public void removeRoutings() {

@Override
public void deprovisionDevice(String deveui) {
deviceApi.deleteDevice("e" + deveui);
deviceApi.deleteDevice("e" + deveui.toUpperCase());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import feign.Param;
import feign.RequestLine;
import lora.ns.actility.api.model.appserver.AppServer;
import lora.ns.actility.api.model.appserver.AppServerUpdate;
import lora.ns.actility.api.model.appserver.AppServers;

public interface AppServerApi {
Expand All @@ -16,5 +17,5 @@ public interface AppServerApi {
AppServer createAppServer(AppServer appServer);

@RequestLine("PUT /subscriptions/mine/appServers/{appServerUID}")
AppServer updateAppServer(@Param("appServerUID") String appServerUID, AppServer appServer);
AppServer updateAppServer(@Param("appServerUID") String appServerUID, AppServerUpdate appServer);
}
Loading

0 comments on commit b252434

Please sign in to comment.