Skip to content

Commit

Permalink
finalized upgrade to 10.14
Browse files Browse the repository at this point in the history
  • Loading branch information
cpoder committed Dec 15, 2022
1 parent 396b08e commit 2c28bda
Show file tree
Hide file tree
Showing 82 changed files with 27,487 additions and 6,061 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
done
- name: Build webapp
run: |
cd web/1011.0.12/devicemanagement-lora
cd web/1014.0.172/devicemanagement-lora
npm install --force
npm run build
cd dist/apps/devicemanagement-lora
Expand Down Expand Up @@ -80,7 +80,7 @@ jobs:
owner, repo,
release_id: release.data.id,
name: 'devicemanagement-lora.zip',
data: await fs.readFile('web/1011.0.12/devicemanagement-lora/dist/apps/devicemanagement-lora/devicemanagement-lora.zip')
data: await fs.readFile('web/1014.0.172/devicemanagement-lora/dist/apps/devicemanagement-lora/devicemanagement-lora.zip')
});
for (let dir of await fs.readdir('.', {withFileTypes: true})) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import java.util.Optional;
import java.util.Properties;
import java.util.Random;

import com.cumulocity.rest.representation.inventory.ManagedObjectRepresentation;

import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;

import com.cumulocity.microservice.subscription.service.MicroserviceSubscriptionsService;
import com.cumulocity.rest.representation.inventory.ManagedObjectRepresentation;

import c8y.ConnectionState;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -115,7 +116,8 @@ protected void init() {

@Override
public LNSResponse<List<EndDevice>> getDevices() {
LNSResponse<List<EndDevice>> result = new LNSResponse<List<EndDevice>>().withOk(true).withResult(new ArrayList<EndDevice>());
LNSResponse<List<EndDevice>> result = new LNSResponse<List<EndDevice>>().withOk(true)
.withResult(new ArrayList<EndDevice>());

return result;
}
Expand Down Expand Up @@ -151,7 +153,8 @@ public LNSResponse<String> sendDownlink(DownlinkData operation) {
securityParams.setAsId("cumulocity");
securityParams.setAsKey(downlinkAsKey);
message.setSecurityParams(securityParams);
Response<DownlinkMessage> response = actilityCoreService.sendDownlink(operation.getDevEui(), message).execute();
Response<DownlinkMessage> response = actilityCoreService.sendDownlink(operation.getDevEui(), message)
.execute();
log.info("Response from Thingpark was {}", response.code());
result.withOk(true).withResult(String.valueOf(downlinkCounter));
} catch (Exception e) {
Expand Down Expand Up @@ -191,8 +194,8 @@ public LNSResponse<Void> provisionDevice(DeviceProvisioning deviceProvisioning)
}

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

Expand Down Expand Up @@ -268,8 +271,11 @@ public LNSResponse<List<String>> configureRoutings(String url, String tenant, St
return result;
}

@Autowired
private MicroserviceSubscriptionsService subscriptionsService;

@Override
public LNSResponse<Void> removeRoutings(String tenant, List<String> routeIds) {
public LNSResponse<Void> removeRoutings() {
LNSResponse<Void> result = new LNSResponse<Void>().withOk(true);
try {
Response<List<DeviceCreate>> response = actilityCoreService.getDevices().execute();
Expand All @@ -294,7 +300,7 @@ public LNSResponse<Void> removeRoutings(String tenant, List<String> routeIds) {
if (response.isSuccessful()) {
response.body().forEach(connection -> {
log.info("Found Connection {}", connection.getName());
if (connection.getName().equals(tenant + "-" + this.getId())) {
if (connection.getName().equals(subscriptionsService.getTenant() + "-" + this.getId())) {
try {
actilityCoreService.deleteConnection(connection.getId()).execute();
} catch (Exception e) {
Expand Down Expand Up @@ -335,7 +341,7 @@ public LNSResponse<List<Gateway>> getGateways() {
try {
Response<List<BaseStation>> response = actilityCoreService.getBaseStations().execute();
if (response.isSuccessful()) {
for (BaseStation baseStation: response.body()) {
for (BaseStation baseStation : response.body()) {
Response<BaseStation> r = actilityCoreService.getBaseStation(baseStation.getRef()).execute();
if (r.isSuccessful()) {
baseStation = r.body();
Expand All @@ -353,22 +359,29 @@ public LNSResponse<List<Gateway>> getGateways() {
}
if (baseStation.getStatistics() != null) {
C8YData data = new C8YData();
if (baseStation.getStatistics().getConnectionState() == ConnectionStateEnum.CNX && baseStation.getStatistics().getHealthState() == HealthStateEnum.ACTIVE) {
if (baseStation.getStatistics().getConnectionState() == ConnectionStateEnum.CNX
&& baseStation.getStatistics().getHealthState() == HealthStateEnum.ACTIVE) {
g.setStatus(ConnectionState.AVAILABLE);
} else {
g.setStatus(ConnectionState.UNAVAILABLE);
}
if (baseStation.getStatistics().getTemperature() != null) {
data.addMeasurement(null, "Temperature", "T", "°C", BigDecimal.valueOf(baseStation.getStatistics().getTemperature()), new DateTime());
data.addMeasurement(null, "Temperature", "T", "°C",
BigDecimal.valueOf(baseStation.getStatistics().getTemperature()),
new DateTime());
}
if (baseStation.getStatistics().getCpUUsage() != null) {
data.addMeasurement(null, "CPU", "Usage", "%", BigDecimal.valueOf(baseStation.getStatistics().getCpUUsage()), new DateTime());
data.addMeasurement(null, "CPU", "Usage", "%",
BigDecimal.valueOf(baseStation.getStatistics().getCpUUsage()), new DateTime());
}
if (baseStation.getStatistics().getRaMUsage() != null) {
data.addMeasurement(null, "RAM", "Usage", "%", BigDecimal.valueOf(baseStation.getStatistics().getRaMUsage()), new DateTime());
data.addMeasurement(null, "RAM", "Usage", "%",
BigDecimal.valueOf(baseStation.getStatistics().getRaMUsage()), new DateTime());
}
if (baseStation.getStatistics().getBatteryLevel() != null) {
data.addMeasurement(null, "Battery", "level", "%", BigDecimal.valueOf(baseStation.getStatistics().getBatteryLevel()), new DateTime());
data.addMeasurement(null, "Battery", "level", "%",
BigDecimal.valueOf(baseStation.getStatistics().getBatteryLevel()),
new DateTime());
}
g.setData(data);
}
Expand Down Expand Up @@ -416,7 +429,8 @@ public LNSResponse<Void> provisionGateway(GatewayProvisioning gatewayProvisionin
if (gatewayProvisioning.getLng() != null) {
baseStation.setGeoLongitude(gatewayProvisioning.getLng().floatValue());
}
baseStation.setBaseStationProfileId(gatewayProvisioning.getAdditionalProperties().getProperty("gatewayProfile"));
baseStation.setBaseStationProfileId(
gatewayProvisioning.getAdditionalProperties().getProperty("gatewayProfile"));
baseStation.setRfRegionId(gatewayProvisioning.getAdditionalProperties().getProperty("rfRegion"));
Response<BaseStation> response = actilityCoreService.createBaseStation(baseStation).execute();
if (!response.isSuccessful()) {
Expand Down Expand Up @@ -453,7 +467,8 @@ public List<BaseStationProfile> getBaseStationProfiles() {
if (response.isSuccessful()) {
result = response.body();
} else {
log.error("Error while retrieving the list of base station profiles: {}", response.errorBody().string());
log.error("Error while retrieving the list of base station profiles: {}",
response.errorBody().string());
}
} catch (Exception e) {
e.printStackTrace();
Expand All @@ -475,4 +490,8 @@ public List<RFRegion> getRFRegions() {
}
return result;
}

public boolean hasGatewayManagementCapability() {
return true;
}
}
37 changes: 21 additions & 16 deletions lora-ns-generic/src/main/java/lora/ns/generic/GenericConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,21 @@ public GenericConnector(Properties properties) {
public GenericConnector(ManagedObjectRepresentation instance) {
super(instance);
}
@Override

@Override
protected void init() {
// Configure LNS API access here
}
// Configure LNS API access here
}

@Override
@Override
public LNSResponse<List<EndDevice>> getDevices() {
return new LNSResponse<List<EndDevice>>().withOk(false).withMessage("Not implemented.");
}

@Override
public LNSResponse<EndDevice> getDevice(String devEui) {
return new LNSResponse<EndDevice>().withOk(false).withMessage("Not implemented.");
}
}

@Override
public LNSResponse<String> sendDownlink(DownlinkData operation) {
Expand All @@ -46,36 +47,40 @@ public LNSResponse<String> sendDownlink(DownlinkData operation) {

@Override
public LNSResponse<Void> provisionDevice(DeviceProvisioning deviceProvisioning) {
return new LNSResponse<Void>().withOk(false).withMessage("Not implemented.");
return new LNSResponse<Void>().withOk(false).withMessage("Not implemented.");
}

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

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

@Override
public LNSResponse<Void> deprovisionDevice(String deveui) {
return new LNSResponse<Void>().withOk(false).withMessage("Not implemented.");
return new LNSResponse<Void>().withOk(false).withMessage("Not implemented.");
}

@Override
public LNSResponse<List<Gateway>> getGateways() {
return new LNSResponse<List<Gateway>>().withOk(false).withMessage("Not implemented.");
return new LNSResponse<List<Gateway>>().withOk(false).withMessage("Not implemented.");
}

@Override
@Override
public LNSResponse<Void> provisionGateway(GatewayProvisioning gatewayProvisioning) {
return new LNSResponse<Void>().withOk(false).withMessage("Not implemented.");
return new LNSResponse<Void>().withOk(false).withMessage("Not implemented.");
}

@Override
@Override
public LNSResponse<Void> deprovisionGateway(String id) {
return new LNSResponse<Void>().withOk(false).withMessage("Not implemented.");
return new LNSResponse<Void>().withOk(false).withMessage("Not implemented.");
}

public boolean hasGatewayManagementCapability() {
return false;
}
}
65 changes: 35 additions & 30 deletions lora-ns-kerlink/src/main/java/lora/ns/kerlink/KerlinkConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,24 +103,27 @@ private void login() {
}

public LNSResponse<List<EndDevice>> getDevices() {
LNSResponse<List<EndDevice>> result = new LNSResponse<List<EndDevice>>().withOk(true).withResult(new ArrayList<>());
LNSResponse<List<EndDevice>> result = new LNSResponse<List<EndDevice>>().withOk(true)
.withResult(new ArrayList<>());
if (jwt == null || jwt.isExpired()) {
login();
}
HttpHeaders headers = new HttpHeaders();
headers.set("Authorization", jwt.getTokenType() + " " + jwt.getToken());
RestTemplate restTemplate = new RestTemplate();
try {
ResponseEntity<PaginatedDto<EndDeviceDto>> response = restTemplate.exchange(baseUrl + "/endDevices", HttpMethod.GET,
ResponseEntity<PaginatedDto<EndDeviceDto>> response = restTemplate.exchange(baseUrl + "/endDevices",
HttpMethod.GET,
new HttpEntity<String>("", headers), new ParameterizedTypeReference<PaginatedDto<EndDeviceDto>>() {
});
if (response.hasBody()) {
for (EndDeviceDto endDeviceDto : response.getBody().getList()) {
result.getResult()
.add(new EndDevice(endDeviceDto.getDevEui(), endDeviceDto.getName(), endDeviceDto.getClassType()));
.add(new EndDevice(endDeviceDto.getDevEui(), endDeviceDto.getName(),
endDeviceDto.getClassType()));
}
}
} catch(Exception e) {
} catch (Exception e) {
e.printStackTrace();
result.withOk(false).withMessage(e.getMessage());
}
Expand Down Expand Up @@ -194,12 +197,13 @@ public LNSResponse<Void> provisionDevice(DeviceProvisioning deviceProvisioning)
dto.setAppEui(deviceProvisioning.getAppEUI());
dto.setAppKey(deviceProvisioning.getAppKey());
try {
ResponseEntity<String> res = restTemplate.exchange(baseUrl + "/endDevices/" + deviceProvisioning.getDevEUI(),
ResponseEntity<String> res = restTemplate.exchange(
baseUrl + "/endDevices/" + deviceProvisioning.getDevEUI(),
HttpMethod.PUT, new HttpEntity<EndDeviceDto>(dto, headers), String.class);
if (res.getStatusCodeValue() != 201) {
result.withOk(false).withMessage(res.getBody());
}
} catch(HttpClientErrorException e) {
} catch (HttpClientErrorException e) {
e.printStackTrace();
logger.error(e.getResponseBodyAsString());
result.withOk(false).withMessage(e.getResponseBodyAsString());
Expand All @@ -216,8 +220,8 @@ protected void init() {
}

@Override
public LNSResponse<List<String>> configureRoutings(String url, String tenant, String login, String password) {
LNSResponse<List<String>> result = new LNSResponse<List<String>>().withOk(true);
public LNSResponse<Void> configureRoutings(String url, String tenant, String login, String password) {
LNSResponse<Void> result = new LNSResponse<Void>().withOk(true);
if (jwt == null || jwt.isExpired()) {
login();
}
Expand Down Expand Up @@ -279,7 +283,7 @@ public LNSResponse<List<String>> configureRoutings(String url, String tenant, St
"/downlink", "/uplink", url, tenant + "/" + login, password);
logger.info("Will create a new push configuration: {}", currentPushConfigurationDto.toString());
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
List<MediaType> mediaTypes = new ArrayList<MediaType>();
List<MediaType> mediaTypes = new ArrayList<>();
mediaTypes.add(MediaType.APPLICATION_JSON);
headers.setAccept(mediaTypes);
ObjectMapper mapper = new ObjectMapper();
Expand All @@ -298,11 +302,13 @@ public LNSResponse<List<String>> configureRoutings(String url, String tenant, St
String[] tokens = response.getHeaders().getLocation().getPath().split("/");
configId = Integer.parseInt(tokens[tokens.length - 1]);
} else {
result.withOk(false).withMessage("Something was wrong while creating the push config: " + response.getBody());
result.withOk(false)
.withMessage("Something was wrong while creating the push config: " + response.getBody());
logger.error("Something was wrong while creating the push config: {}", response.getBody());
}
}
if (configId != null) {
this.setProperty("configId", configId);
headers = new HttpHeaders();
headers.set("Authorization", jwt.getTokenType() + " " + jwt.getToken());
ClusterDto cluster = restTemplate.exchange(baseUrl + "/clusters/" + clusterId, HttpMethod.GET,
Expand All @@ -315,33 +321,27 @@ public LNSResponse<List<String>> configureRoutings(String url, String tenant, St
ResponseEntity<String> response = restTemplate.exchange(baseUrl + "/clusters/" + clusterId,
HttpMethod.PATCH, new HttpEntity<ClusterDto>(cluster, headers), String.class);
if (response.getStatusCode() != HttpStatus.NO_CONTENT) {
result.withOk(false).withMessage("Something was wrong while updating the cluster: " + response.getBody());
result.withOk(false)
.withMessage("Something was wrong while updating the cluster: " + response.getBody());
logger.error("Something was wrong while updating the cluster: {}", response.getBody());
}
}
return result;
}

@Override
public LNSResponse<Void> removeRoutings(String tenant, List<String> routeIds) {
LNSResponse<Void> result = new LNSResponse<Void>().withOk(true);
if (jwt == null || jwt.isExpired()) {
login();
}
HttpHeaders headers = new HttpHeaders();
headers.set("Authorization", jwt.getTokenType() + " " + jwt.getToken());
RestTemplate restTemplate = new RestTemplate();
PaginatedDto<PushConfigurationDto> pushConfigurationDtos = restTemplate
.exchange(baseUrl + "/pushConfigurations", HttpMethod.GET, new HttpEntity<String>("", headers),
new ParameterizedTypeReference<PaginatedDto<PushConfigurationDto>>() {
})
.getBody();
for (PushConfigurationDto pushConfigurationDto : pushConfigurationDtos.getList()) {
if (pushConfigurationDto.getName().equals(tenant + "-" + this.getId())) {
restTemplate.exchange(baseUrl + "/pushConfigurations/" + pushConfigurationDto.getId(),
HttpMethod.DELETE, new HttpEntity<String>("", headers), String.class);
public LNSResponse<Void> removeRoutings() {
final LNSResponse<Void> result = new LNSResponse<Void>().withOk(true);
this.getProperty("configId").ifPresent(configId -> {
if (jwt == null || jwt.isExpired()) {
login();
}
}
HttpHeaders headers = new HttpHeaders();
headers.set("Authorization", jwt.getTokenType() + " " + jwt.getToken());
RestTemplate restTemplate = new RestTemplate();
restTemplate.exchange(baseUrl + "/pushConfigurations/" + configId,
HttpMethod.DELETE, new HttpEntity<String>("", headers), String.class);
});
return result;
}

Expand Down Expand Up @@ -395,7 +395,8 @@ public LNSResponse<List<Gateway>> getGateways() {
}).getBody();
C8YData c8yData = new C8YData();
for (GatewayDto gatewayDto : gatewaysDto.getList()) {
result.getResult().add(new Gateway(gatewayDto.getEui(), gatewayDto.getEui(), gatewayDto.getName(), gatewayDto.getLatitude(),
result.getResult().add(new Gateway(gatewayDto.getEui(), gatewayDto.getEui(), gatewayDto.getName(),
gatewayDto.getLatitude(),
gatewayDto.getLongitude(), gatewayDto.getDescription(), ConnectionState.AVAILABLE, c8yData));
}
return result;
Expand All @@ -408,4 +409,8 @@ public LNSResponse<Void> provisionGateway(lora.ns.gateway.GatewayProvisioning ga
public LNSResponse<Void> deprovisionGateway(String id) {
return new LNSResponse<Void>().withOk(false).withMessage("Not implemented");
}

public boolean hasGatewayManagementCapability() {
return false;
}
}
Loading

0 comments on commit 2c28bda

Please sign in to comment.