Skip to content

Commit

Permalink
updated to 10.14.0.172
Browse files Browse the repository at this point in the history
  • Loading branch information
cpoder committed Nov 30, 2022
1 parent ec28db6 commit fff35c1
Show file tree
Hide file tree
Showing 61 changed files with 42,878 additions and 256 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ web/1010.0.12/devicemanagement-lora/dist
web/1010.0.12/devicemanagement-lora/node_modules
web/1011.0.12/devicemanagement-lora/dist
web/1011.0.12/devicemanagement-lora/node_modules
web/1014.0.172/devicemanagement-lora/dist
web/1014.0.172/devicemanagement-lora/node_modules
c8y_credentials
34 changes: 18 additions & 16 deletions lora-interface/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
module lora_interface {
requires rest.representation;
requires joda.time;
requires core.model;
requires device.capability.model;
requires org.slf4j;
requires svenson;
requires java.client;
requires com.fasterxml.jackson.core;
requires com.fasterxml.jackson.databind;
requires microservice.subscription;
requires microservice.context;
requires spring.beans;
requires spring.web;
requires spring.core;
requires spring.context;
requires com.google.common;
// both modules will be replaced in 10.15 by requires transitive java.client.model;
requires transitive rest.representation;
requires transitive core.model;

requires transitive org.joda.time;
requires transitive device.capability.model;
requires transitive org.slf4j;
requires transitive svenson;
requires transitive java.client;
requires transitive com.fasterxml.jackson.core;
requires transitive com.fasterxml.jackson.databind;
requires transitive microservice.subscription;
requires transitive microservice.context;
requires transitive spring.beans;
requires transitive spring.web;
requires transitive spring.core;
requires transitive spring.context;
requires transitive com.google.common;
requires transitive lombok;

exports lora.codec;
Expand Down
5 changes: 0 additions & 5 deletions lora-ns-actility/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@
</execution>
</executions>
</plugin>
<!-- <plugin> <groupId>com.google.cloud.tools</groupId> <artifactId>jib-maven-plugin</artifactId>
<version>2.4.0</version> <configuration> <outputPaths> <tar>target/image.tar</tar>
</outputPaths> </configuration> <executions> <execution> <phase>package</phase>
<goals> <goal>buildTar</goal> </goals> </execution> </executions> </plugin> -->

<plugin>
<groupId>com.nsn.cumulocity.clients-java</groupId>
<artifactId>microservice-package-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ public LNSResponse<Void> provisionDevice(DeviceProvisioning deviceProvisioning)
}

@Override
public LNSResponse<Void> configureRoutings(String url, String tenant, String login, String password) {
LNSResponse<Void> result = new LNSResponse<Void>().withOk(true);
public LNSResponse<List<String>> configureRoutings(String url, String tenant, String login, String password) {
LNSResponse<List<String>> result = new LNSResponse<List<String>>().withOk(true);
log.info("Configuring routings to: {} with credentials: {}:{}", url, login, password);
String connectionId = null;

Expand Down Expand Up @@ -269,7 +269,7 @@ public LNSResponse<Void> configureRoutings(String url, String tenant, String log
}

@Override
public LNSResponse<Void> removeRoutings(String tenant) {
public LNSResponse<Void> removeRoutings(String tenant, List<String> routeIds) {
LNSResponse<Void> result = new LNSResponse<Void>().withOk(true);
try {
Response<List<DeviceCreate>> response = actilityCoreService.getDevices().execute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ public LNSResponse<Void> provisionDevice(DeviceProvisioning deviceProvisioning)
}

@Override
public LNSResponse<Void> configureRoutings(String url, String tenant, String login, String password) {
return new LNSResponse<Void>().withOk(false).withMessage("Not implemented.");
public LNSResponse<List<String>> configureRoutings(String url, String tenant, String login, String password) {
return new LNSResponse<List<String>>().withOk(false).withMessage("Not implemented.");
}

@Override
public LNSResponse<Void> removeRoutings(String tenant) {
public LNSResponse<Void> removeRoutings(String tenant, List<String> routeIds) {
return new LNSResponse<Void>().withOk(false).withMessage("Not implemented.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ protected void init() {
}

@Override
public LNSResponse<Void> configureRoutings(String url, String tenant, String login, String password) {
LNSResponse<Void> result = new LNSResponse<Void>().withOk(true);
public LNSResponse<List<String>> configureRoutings(String url, String tenant, String login, String password) {
LNSResponse<List<String>> result = new LNSResponse<List<String>>().withOk(true);
if (jwt == null || jwt.isExpired()) {
login();
}
Expand Down Expand Up @@ -323,7 +323,7 @@ public LNSResponse<Void> configureRoutings(String url, String tenant, String log
}

@Override
public LNSResponse<Void> removeRoutings(String tenant) {
public LNSResponse<Void> removeRoutings(String tenant, List<String> routeIds) {
LNSResponse<Void> result = new LNSResponse<Void>().withOk(true);
if (jwt == null || jwt.isExpired()) {
login();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ private LNSResponse<Void> provisionDeviceAbp(DeviceProvisioning deviceProvisioni
}

@Override
public LNSResponse<Void> configureRoutings(String url, String tenant, String login, String password) {
LNSResponse<Void> result = new LNSResponse<Void>().withOk(true);
public LNSResponse<List<String>> configureRoutings(String url, String tenant, String login, String password) {
LNSResponse<List<String>> result = new LNSResponse<List<String>>().withOk(true);
logger.info("Configuring routings to: {} with credentials: {}:{}", url, login, password);
try {
retrofit2.Response<List<Output>> outputs = loriotService.getOutputs(getProperties().getProperty("appid"))
Expand Down Expand Up @@ -307,7 +307,7 @@ public LNSResponse<Void> configureRoutings(String url, String tenant, String log
}

@Override
public LNSResponse<Void> removeRoutings(String tenant) {
public LNSResponse<Void> removeRoutings(String tenant, List<String> routeIds) {
// TODO
return new LNSResponse<Void>().withOk(false).withMessage("Not implemented");
}
Expand Down
32 changes: 27 additions & 5 deletions lora-ns-ms/src/main/java/lora/codec/ms/CodecProxy.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package lora.codec.ms;

import java.util.HashMap;
import java.util.Map;

import org.springframework.core.ParameterizedTypeReference;
Expand All @@ -8,8 +9,10 @@
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.ResourceAccessException;
import org.springframework.web.client.RestClientResponseException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.client.UnknownContentTypeException;

import lombok.extern.slf4j.Slf4j;
import lora.codec.Result;
Expand Down Expand Up @@ -71,10 +74,17 @@ public Result<DownlinkData> encode(Encode data) {
ResponseEntity<Result<DownlinkData>> response = restTemplate.exchange(System.getenv(C8Y_BASEURL) + SERVICE_LORA_CODEC + id + "/encode", HttpMethod.POST, new HttpEntity<Encode>(data, headers), new ParameterizedTypeReference<Result<DownlinkData>>(){});
log.info("Answer of encoder is {} with content {}", response.getStatusCode(), response.getBody());
result = response.getBody();
} catch(HttpClientErrorException e) {
} catch(RestClientResponseException e) {
e.printStackTrace();
log.error(e.getResponseBodyAsString());
result = new Result<>(false, e.getResponseBodyAsString(), null);
} catch(UnknownContentTypeException e) {
e.printStackTrace();
log.error(e.getResponseBodyAsString());
result = new Result<>(false, e.getResponseBodyAsString(), null);
} catch(ResourceAccessException e) {
e.printStackTrace();
result = new Result<>(false, e.getMessage(), null);
}
return result;
}
Expand All @@ -93,16 +103,23 @@ public Result<String> decode(Decode data) {
ResponseEntity<Result<String>> response = restTemplate.exchange(System.getenv(C8Y_BASEURL) + SERVICE_LORA_CODEC + id + "/decode", HttpMethod.POST, new HttpEntity<Decode>(data, headers), new ParameterizedTypeReference<Result<String>>(){});
result = response.getBody();
log.info("Answer of decoder is {} with content {}", response.getStatusCode(), result != null ? result.getResponse() : "");
} catch(HttpClientErrorException e) {
} catch(RestClientResponseException e) {
e.printStackTrace();
log.error(e.getResponseBodyAsString());
result = new Result<>(false, e.getResponseBodyAsString(), null);
} catch(UnknownContentTypeException e) {
e.printStackTrace();
log.error(e.getResponseBodyAsString());
result = new Result<>(false, e.getResponseBodyAsString(), null);
} catch(ResourceAccessException e) {
e.printStackTrace();
result = new Result<>(false, e.getMessage(), null);
}
return result;
}

public Map<String, DeviceOperationElement> getAvailableOperations(String model) {
Map<String, DeviceOperationElement> result = null;
Map<String, DeviceOperationElement> result = new HashMap<>();
RestTemplate restTemplate = new RestTemplate();
try {
HttpHeaders headers = new HttpHeaders();
Expand All @@ -113,9 +130,14 @@ public Map<String, DeviceOperationElement> getAvailableOperations(String model)
ResponseEntity<Map<String, DeviceOperationElement>> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<String>("", headers), new ParameterizedTypeReference<Map<String, DeviceOperationElement>>(){});
log.info("Answer of decoder is {} with content {}", response.getStatusCode(), response.getBody());
result = response.getBody();
} catch(HttpClientErrorException e) {
} catch(RestClientResponseException e) {
e.printStackTrace();
log.error(e.getResponseBodyAsString());
} catch(UnknownContentTypeException e) {
e.printStackTrace();
log.error(e.getResponseBodyAsString());
} catch(ResourceAccessException e) {
e.printStackTrace();
}
return result;
}
Expand Down
5 changes: 2 additions & 3 deletions lora-ns-ms/src/main/java/lora/ns/connector/LNSConnector.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package lora.ns.connector;

import java.util.List;
import java.util.Optional;
import java.util.Properties;

import lora.codec.downlink.DownlinkData;
Expand All @@ -20,8 +19,8 @@ public interface LNSConnector {
LNSResponse<EndDevice> getDevice(String devEui);
LNSResponse<String> sendDownlink(DownlinkData downlinkData);
LNSResponse<Void> provisionDevice(DeviceProvisioning deviceProvisioning);
LNSResponse<Void> configureRoutings(String url, String tenant, String login, String password);
LNSResponse<Void> removeRoutings(String tenant);
LNSResponse<List<String>> configureRoutings(String url, String tenant, String login, String password);
LNSResponse<Void> removeRoutings(String tenant, List<String> routeIds);
LNSResponse<Void> deprovisionDevice(String deveui);
LNSResponse<List<Gateway>> getGateways();
Properties mergeProperties(Properties properties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.lang.reflect.ParameterizedType;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
Expand All @@ -14,6 +15,20 @@
import java.util.Optional;
import java.util.Properties;

import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.Trigger;
import org.springframework.scheduling.TriggerContext;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.thymeleaf.context.Context;
import org.thymeleaf.spring5.SpringTemplateEngine;

import com.cumulocity.microservice.context.credentials.MicroserviceCredentials;
import com.cumulocity.microservice.subscription.model.MicroserviceSubscriptionAddedEvent;
import com.cumulocity.microservice.subscription.service.MicroserviceSubscriptionsService;
Expand All @@ -36,20 +51,6 @@
import com.cumulocity.sdk.client.measurement.MeasurementApi;
import com.cumulocity.sdk.client.option.TenantOptionApi;

import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.Trigger;
import org.springframework.scheduling.TriggerContext;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.thymeleaf.context.Context;
import org.thymeleaf.spring5.SpringTemplateEngine;

import c8y.IsDevice;
import lora.codec.uplink.C8YData;
import lora.common.C8YUtils;
Expand Down Expand Up @@ -184,6 +185,9 @@ private void init(MicroserviceSubscriptionAddedEvent event) {
properties.setProperty(option.getKey(), option.getValue());
}
instance.setProperties(properties);
if (mor.hasProperty("routeIds")) {
instance.getProperties().put("routeIds", mor.getProperty("routeIds"));
}
lnsConnectorManager.addConnector(instance);
lnsGatewayManager.upsertGateways(instance);
configureRoutings(instance.getId(), event.getCredentials());
Expand Down Expand Up @@ -252,8 +256,12 @@ private void configureRoutings(String lnsInstanceId, MicroserviceCredentials cre
logger.info("Connector URL is {}", url);
Optional<LNSConnector> connector = lnsConnectorManager.getConnector(lnsInstanceId);
if (connector.isPresent()) {
connector.get().configureRoutings(url, subscriptionsService.getTenant(), credentials.getUsername(),
var response = connector.get().configureRoutings(url, subscriptionsService.getTenant(), credentials.getUsername(),
credentials.getPassword());
ManagedObjectRepresentation mor = new ManagedObjectRepresentation();
mor.setId(GId.asGId(connector.get().getId()));
mor.setProperty("routeIds", response.getResult());
inventoryApi.update(mor);
}
}

Expand Down Expand Up @@ -297,10 +305,23 @@ public ManagedObjectRepresentation addLnsConnector(LNSConnectorRepresentation co
return mor;
}

private List<String> getRouteIds(LNSConnector connector) {
List<String> result = new ArrayList<>();
ManagedObjectRepresentation mor = inventoryApi.get(GId.asGId(connector.getId()));
if (mor.hasProperty("routeIds")) {
Object p = mor.getProperty("routeIds");
if (p instanceof List) {
result = (List<String>)p;
}
}

return result;
}

public void removeLnsConnector(String lnsConnectorId) {
Optional<LNSConnector> connector = lnsConnectorManager.getConnector(lnsConnectorId);
if (connector.isPresent()) {
connector.get().removeRoutings(subscriptionsService.getTenant());
connector.get().removeRoutings(subscriptionsService.getTenant(), getRouteIds(connector.get()));
inventoryApi.delete(new GId(lnsConnectorId));
lnsConnectorManager.removeConnector(lnsConnectorId);
}
Expand Down
23 changes: 3 additions & 20 deletions lora-ns-ms/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,9 @@
module lora.ns.ms {
requires transitive lora_interface;
requires org.apache.commons.codec;
requires transitive rest.representation;
requires joda.time;
requires core.model;
requires device.capability.model;
requires org.slf4j;
requires svenson;
requires java.client;
requires com.fasterxml.jackson.core;
requires com.fasterxml.jackson.databind;
requires microservice.subscription;
requires microservice.context;
requires spring.beans;
requires spring.web;
requires spring.core;
requires transitive spring.context;
requires spring.security.core;
requires spring.security.config;
requires spring.security.web;
requires com.google.common;
requires transitive lombok;
requires transitive spring.security.core;
requires transitive spring.security.config;
requires transitive spring.security.web;
requires transitive thymeleaf;
requires transitive thymeleaf.spring5;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,9 @@ public LNSResponse<Void> configureRouting(String url, String tenant, String logi
}

@Override
public LNSResponse<Void> configureRoutings(String url, String tenant, String login, String password) {
public LNSResponse<List<String>> configureRoutings(String url, String tenant, String login, String password) {
logger.info("Configuring routings to: {} with credentials: {}:{}", url, login, password);
LNSResponse<Void> result = new LNSResponse<Void>();
LNSResponse<List<String>> result = new LNSResponse<>();
LNSResponse<Void> resultDownlink = configureRouting(url + "/downlink", tenant, login, password, tenant + "-" + this.getId() + "-downlink",
MessageTypeEnum.DOWNLINK);
LNSResponse<Void> resultUplink = configureRouting(url + "/uplink", tenant, login, password, tenant + "-" + this.getId() + "-uplink",
Expand Down Expand Up @@ -322,7 +322,7 @@ private LNSResponse<Void> removeRouting(String name) {
}

@Override
public LNSResponse<Void> removeRoutings(String tenant) {
public LNSResponse<Void> removeRoutings(String tenant, List<String> routeIds) {
LNSResponse<Void> result = new LNSResponse<Void>().withOk(true);
var resultUplink = removeRouting(tenant + "-" + this.getId() + "-uplink");
var resultDownlink = removeRouting(tenant + "-" + this.getId() + "-downlink");
Expand Down
Loading

0 comments on commit fff35c1

Please sign in to comment.