Skip to content

Commit

Permalink
Merge pull request #63 from disk91/roaming_feature
Browse files Browse the repository at this point in the history
Roaming feature
  • Loading branch information
disk91 authored Jun 22, 2023
2 parents 4c7edbd + 9027a12 commit e6111fd
Show file tree
Hide file tree
Showing 176 changed files with 71,635 additions and 636 deletions.
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
- Manage Invoice generation
- Manage device migration from console
- Manage device live migration from console
- Manage device live Region change
- Manage Helium integration with forwarder


#### MVP1 - terminated
Expand Down Expand Up @@ -94,4 +96,22 @@ be publicly published, even when small pieces of code or architecture are reused
--grpc-java_out=...same... --proto_path=.../proto/src/ service/iot_config.proto
./protoc/bin/protoc --java_out=... --proto_path=.../proto/src/ region.proto
./protoc/bin/protoc --java_out=... --proto_path=.../proto/src/ blockchain_region_param_v1.proto
```
```

- Chirpstack-api grpc api found on - https://github.com/brocaar/chirpstack-api/tree/master
- gooogleapi found on - https://fuchsia.googlesource.com/third_party/googleapis
- Chirpstack grpc api found on - https://github.com/chirpstack/chirpstack.git
```bash
# for chirpstack grpc api
~ git checkout v4.3.2
```

````
./protoc/bin/protoc -I ./chirpstack/api/proto -I ./googleapis/ --java_out ./out ./chirpstack/api/proto/common/common.proto
./protoc/bin/protoc -I ./chirpstack/api/proto -I ./googleapis/ --java_out ./out ./chirpstack/api/proto/api/user.proto
./protoc/bin/protoc -I ./chirpstack/api/proto -I ./googleapis/ --java_out ./out ./chirpstack/api/proto/api/device.proto
./protoc/bin/protoc -I ./chirpstack/api/proto --java_out ./out ./chirpstack/api/proto/api/frame_log.proto
./protoc/bin/protoc -I ./chirpstack/api/proto -I ./googleapis/ --java_out ./out ./chirpstack/api/proto/api/internal.proto
./protoc/bin/protoc -I ./chirpstack-api/protobuf --java_out ./out ./chirpstack-api//protobuf/as/as.proto
````
15 changes: 11 additions & 4 deletions nuxt/console/components/DataCreditPurchase.vue
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ interface data {
card : any,
secret : string,
transaction : string,
}
Vue.filter('currency', function (value:number) {
Expand Down Expand Up @@ -322,7 +324,7 @@ export default Vue.extend({
stripe : undefined,
card : undefined,
secret : '',
transaction : '',
};
},
async fetch() {
Expand Down Expand Up @@ -368,6 +370,7 @@ export default Vue.extend({
this.stripe = undefined;
this.card = undefined;
this.secret = '';
this.transaction = '';
},
updateTenantConfiguration() {
this.isBusy = true;
Expand Down Expand Up @@ -417,6 +420,7 @@ export default Vue.extend({
if (response.status == 200 ) {
this.isBusy = false;
let r : TransactionStripeRespItf = response.data;
this.transaction = r.transactionUUID; // here is the key for update later
var stripe = Stripe(r.stripePublicKey);
var elements = stripe.elements();
var style = {
Expand Down Expand Up @@ -491,9 +495,12 @@ export default Vue.extend({
'Authorization': 'Bearer '+self.$store.state.consoleBearer,
}
};
self.$axios.put(self.$config.transactionStripeUpdate+'/'+result.paymentIntent.id+'/',null,config)
.then((response) =>{})
.catch((err) => {})
//self.$axios.put(self.$config.transactionStripeUpdate+'/'+result.paymentIntent.id+'/',null,config)
if ( self.transaction != '' ) {
self.$axios.put(self.$config.transactionStripeUpdate+'/'+self.transaction+'/',null,config)
.then((response) =>{})
.catch((err) => {})
}
// display success and quit
setTimeout(function() {
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/eu/heliumiot/console/jpa/db/Device.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,20 @@ public String getVariables() {
public void setVariables(String variables) {
this.variables = variables;
}

public UUID getDeviceProfileId() {
return deviceProfileId;
}

public void setDeviceProfileId(UUID deviceProfileId) {
this.deviceProfileId = deviceProfileId;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}
}
108 changes: 108 additions & 0 deletions src/main/java/eu/heliumiot/console/jpa/db/DeviceProfile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* Copyright (c) - Paul Pinault (aka disk91) - 2020.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
* OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package eu.heliumiot.console.jpa.db;

import fr.ingeniousthings.tools.HexaConverters;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Immutable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.sql.Timestamp;
import java.util.UUID;

@Entity
@Immutable
@Table(name = "device_profile")
public class DeviceProfile {

@Id
@GenericGenerator(name = "UUIDGenerator", strategy = "uuid2")
@Column(name = "id", updatable = false, nullable = false)
private UUID id;

@GenericGenerator(name = "UUIDGenerator", strategy = "uuid2")
@Column(name = "tenant_id", updatable = false, nullable = false)
private UUID tenantId;

@Column(name = "created_at")
private Timestamp createdAt;
@Column(name = "updated_at")
private Timestamp updatedAt;

@Column(name = "region")
private String region;
@Column(name = "name")
private String name;


// ---


public UUID getId() {
return id;
}

public void setId(UUID id) {
this.id = id;
}

public UUID getTenantId() {
return tenantId;
}

public void setTenantId(UUID tenantId) {
this.tenantId = tenantId;
}

public Timestamp getCreatedAt() {
return createdAt;
}

public void setCreatedAt(Timestamp createdAt) {
this.createdAt = createdAt;
}

public Timestamp getUpdatedAt() {
return updatedAt;
}

public void setUpdatedAt(Timestamp updatedAt) {
this.updatedAt = updatedAt;
}

public String getRegion() {
return region;
}

public void setRegion(String region) {
this.region = region;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) - Paul Pinault (aka disk91) - 2020.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
* OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package eu.heliumiot.console.jpa.repository;

import eu.heliumiot.console.jpa.db.DeviceProfile;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.sql.Timestamp;
import java.util.List;
import java.util.UUID;

@Repository
public interface DeviceProfileRepository extends CrudRepository<DeviceProfile, UUID> {

public DeviceProfile findOneDeviceProfileById(UUID id);

public List<DeviceProfile> findDeviceProfileByTenantId(
UUID tenantId
);

}
14 changes: 10 additions & 4 deletions src/main/java/eu/heliumiot/console/mqtt/MqttListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@
import eu.heliumiot.console.mqtt.api.HeliumDeviceStatItf;
import eu.heliumiot.console.jpa.repository.TenantRepository;
import eu.heliumiot.console.mqtt.api.HeliumTenantActDeactItf;
import eu.heliumiot.console.service.HeliumDeviceService;
import eu.heliumiot.console.service.HeliumDeviceStatService;
import eu.heliumiot.console.service.HeliumTenantService;
import eu.heliumiot.console.service.PrometeusService;
import eu.heliumiot.console.service.*;
import fr.ingeniousthings.tools.DateConverters;
import fr.ingeniousthings.tools.HexaConverters;
import fr.ingeniousthings.tools.Now;
Expand All @@ -49,6 +46,7 @@
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;

import javax.annotation.PostConstruct;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Set;

Expand Down Expand Up @@ -145,6 +143,9 @@ public void deliveryComplete(IMqttDeliveryToken arg0) {
@Autowired
protected HeliumDeviceService heliumDeviceService;

@Autowired
protected RoamingService roamingService;

protected class DeviceDedup {
public String devEui;
public long lastSeen;
Expand Down Expand Up @@ -258,6 +259,11 @@ public void messageArrived(String topicName, MqttMessage message) throws Excepti

// ... push to process
log.info("Found a join request for "+d.devEui+" for region "+region);
byte [] _dev = new byte[8]; // reverse the bytes of the address
for ( int i = 0 ; i < 8 ; i++ ) {
_dev[i] = payload[(9+8-1)-i];
}
roamingService.processJoinMessage(_dev, HexaConverters.byteToHexString(_dev),region);
}
// clean the dedup storage
if ( dedupHashMap.size() > 500 ) {
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/eu/heliumiot/console/service/PrometeusService.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,24 @@ public void addQueryDb(long duration) {

public void setDcAmount(long dcAmount) { this.dcAmount = dcAmount; }


// ============================================================
// Roaming Service metrix

private long roamingTotalDurationMs = 0; // total time spend in processing roaming
private long roamingCount = 0; // number of time we roam a device

public void roamingAddDuration(long duration) {
this.roamingTotalDurationMs += duration;
}

public void roamingAddOne() {
this.roamingCount++;
}

protected Supplier<Number> getRoamingTotalDuration() { return ()->roamingTotalDurationMs; }
protected Supplier<Number> getRoamingCount() { return ()->roamingCount; }

// =============================================================
// Prometheus interface

Expand Down Expand Up @@ -395,6 +413,13 @@ public PrometeusService(MeterRegistry registry) {
Gauge.builder("cons.router.dcbalance", getDcAmount())
.description("current router wallet DCs")
.register(registry);

Gauge.builder("cons.roaming.duration", getRoamingTotalDuration())
.description("Time passed in processing roaming management")
.register(registry);
Gauge.builder("cons.roaming.changes", getRoamingCount())
.description("Number of devices updated to another region")
.register(registry);
}

@Autowired
Expand Down
Loading

0 comments on commit e6111fd

Please sign in to comment.