Skip to content

Commit

Permalink
Using and saving app server ID instead of looking for app server by name
Browse files Browse the repository at this point in the history
  • Loading branch information
cpoder committed Jul 8, 2024
1 parent fe69951 commit 85c4834
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package lora.ns.actility;

import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.apache.commons.lang3.StringUtils.*;

import java.math.BigDecimal;
import java.security.SecureRandom;
Expand Down Expand Up @@ -238,14 +238,13 @@ public void provisionDevice(DeviceProvisioning deviceProvisioning) {
public void configureRoutings(String url, String tenant, String login, String password) {
String domain = properties.getProperty("domain");
String group = properties.getProperty("group");
var routeId = getProperty("routeId");
log.info("Configuring routings to: {} with credentials: {}:{} and domain {}:{}", url, login, password, domain,
group);

var appServers = appServerApi.getAppServersByName(tenant + "-" + getId());
if (!appServers.getBriefs().isEmpty()) {
if (routeId.isPresent()) {
// Update appserver
var currentAppServer = appServers.getBriefs().iterator().next();
this.appServerId = currentAppServer.getID();
this.appServerId = routeId.get().toString();
var currentAppServer = appServerApi.getAppServer(appServerId);
String uid = currentAppServer.getID().split("\\.")[1];
var appServer = new AppServerUpdate();
appServer.setCustomHttpHeaders(new ArrayList<>());
Expand All @@ -268,20 +267,21 @@ public void configureRoutings(String url, String tenant, String login, String pa
(tenant + "/" + login + ":" + password).getBytes())))
.addDestinationsItem(new AppServerHttpLorawanDestination().addAddressesItem(url + "/uplink")
.strategy(AppServerStrategy.SEQUENTIAL).ports("*"))
.name(tenant + "-" + getId()).downlinkSecurity(new DownlinkSecurity(getAsId(), getAsKey()));
.name(getName() + "-" + tenant + "-" + getId())
.downlinkSecurity(new DownlinkSecurity(getAsId(), getAsKey()));
if (properties.containsKey("domain")) {
appServer.addDomainsItem(new Domain().name(properties.getProperty("domain"))
.group(new DomainGroup().name(properties.getProperty("group"))));
}
this.appServerId = appServerApi.createAppServer(appServer).getID();
setProperty("routeId", appServerId);
}
}

@Override
public Optional<String> getCustomRoutingBaseUrl() {
return isNotBlank(properties.getProperty("webhook-url")) ?
Optional.of(properties.getProperty("webhook-url")) :
super.getCustomRoutingBaseUrl();
return isNotBlank(properties.getProperty("webhook-url")) ? Optional.of(properties.getProperty("webhook-url"))
: super.getCustomRoutingBaseUrl();
}

@Override
Expand Down

0 comments on commit 85c4834

Please sign in to comment.