From 85c4834968224a3e6bc0e44b68f8fd7e5d44f9a7 Mon Sep 17 00:00:00 2001 From: cpoder Date: Mon, 8 Jul 2024 17:23:48 +0200 Subject: [PATCH] Using and saving app server ID instead of looking for app server by name --- .../lora/ns/actility/ActilityConnector.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/java/lora-ns-actility/src/main/java/lora/ns/actility/ActilityConnector.java b/java/lora-ns-actility/src/main/java/lora/ns/actility/ActilityConnector.java index 5b13d3398..ec3418c92 100644 --- a/java/lora-ns-actility/src/main/java/lora/ns/actility/ActilityConnector.java +++ b/java/lora-ns-actility/src/main/java/lora/ns/actility/ActilityConnector.java @@ -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; @@ -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<>()); @@ -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 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