Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Device Manager #767

Merged
merged 116 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
4c88c9a
Updating device summaries
grafnu Nov 7, 2023
06f709b
Refacotring and adding base
grafnu Nov 7, 2023
204e9b9
Basic event proxy
grafnu Nov 7, 2023
bcea0ec
Adding proxyID
grafnu Nov 7, 2023
2725e26
Refactoring to envelope
grafnu Nov 7, 2023
c8ff2d7
Linty and NPE
grafnu Nov 7, 2023
7f99358
Minor refactoring
grafnu Nov 7, 2023
ec2eee4
Cleanup
grafnu Nov 7, 2023
be5a77b
Fix suffix calculation
grafnu Nov 7, 2023
0f6acbd
Cleanup
grafnu Nov 7, 2023
cb9cd95
Adding itemized test stuff
grafnu Nov 7, 2023
0cef5c5
Updating sequence cache
grafnu Nov 7, 2023
818017f
Adding sequencer.out
grafnu Nov 7, 2023
5d4d620
Fixing itemized debugging
grafnu Nov 7, 2023
10d6b83
Generalize not-a-gateway check
grafnu Nov 7, 2023
6daa3f1
Increasing shart count to 10
grafnu Nov 7, 2023
0e9439c
Adding combined itemized validation
grafnu Nov 7, 2023
a53f6d9
PASSING TESTS
grafnu Nov 7, 2023
9f52336
Fix generated.md
grafnu Nov 7, 2023
a6355ca
Fix sequcheck
grafnu Nov 8, 2023
81a2a1c
out
grafnu Nov 8, 2023
428dadf
Fix test run archiving
grafnu Nov 8, 2023
2e10789
Fix out merge
grafnu Nov 8, 2023
77af4ff
Fix combinatorics
grafnu Nov 8, 2023
a4defe3
Shard output cleanup
grafnu Nov 8, 2023
e4833ae
Don't error on missing combined
grafnu Nov 8, 2023
e647a6e
Clean-up out logging
grafnu Nov 8, 2023
0e513b1
Fix out/ combined
grafnu Nov 8, 2023
0c70d89
Cleanup itemized out
grafnu Nov 8, 2023
36519af
Remember to invoke super
grafnu Nov 8, 2023
5945434
Cleanup test_itemized out
grafnu Nov 8, 2023
f92c521
Fix itemized cleaniup
grafnu Nov 8, 2023
f673921
Don't agressively clean out/
grafnu Nov 8, 2023
60349ea
Increase node version
grafnu Nov 8, 2023
2319461
Fix some combination stuff
grafnu Nov 9, 2023
0968a91
Fix some out gathering
grafnu Nov 9, 2023
d9438ea
Add rsync suffixz
grafnu Nov 9, 2023
ee2fad7
Fix test combinations
grafnu Nov 9, 2023
2ef6589
Increse timeout for config ack check
grafnu Nov 9, 2023
0c411a5
Sort expected out
grafnu Nov 9, 2023
b8ae163
Adding more tests
grafnu Nov 9, 2023
bbe4088
Tweaking output
grafnu Nov 9, 2023
2554067
Rename test out files
grafnu Nov 9, 2023
205f2d9
Updatin gto latest test results
grafnu Nov 9, 2023
e9d4540
Fix pointset
grafnu Nov 9, 2023
c3aff25
Pubber code
grafnu Nov 9, 2023
c7600a5
Updating generated.md with new sequences
grafnu Nov 9, 2023
cdde4af
Updating itemized out
grafnu Nov 9, 2023
2b83ce0
Adding missing itemized out
grafnu Nov 9, 2023
665b7a8
Fixing schema capture
grafnu Nov 9, 2023
c72fa56
Fix schema out generation
grafnu Nov 9, 2023
1215ad5
Fix schema combination
grafnu Nov 9, 2023
e52baf4
Only sequence cache changes
grafnu Nov 9, 2023
c2f4e67
Merge branch 'master' into gatewaytest
grafnu Nov 9, 2023
12116c7
Merge branch 'master' into gatewaytest
grafnu Nov 9, 2023
0984a24
Minor cleanup
grafnu Nov 9, 2023
1a5db33
Merge branch 'master' into gatewaytest
grafnu Nov 9, 2023
933a2f8
Merge branch 'master' into gatewaytest
grafnu Nov 10, 2023
2f8273b
Updated expected out
grafnu Nov 10, 2023
e02aa06
Fix local checking of test results
grafnu Nov 10, 2023
1c1b82f
Add missing source
grafnu Nov 10, 2023
ee18926
Increase jitter threshold
grafnu Nov 10, 2023
5040799
Fix error capture
grafnu Nov 10, 2023
839c182
Capture message upgrade errors
grafnu Nov 10, 2023
086937d
Add auto-update udmis
grafnu Nov 10, 2023
502bf7f
Fix required return
grafnu Nov 10, 2023
71edaa1
Allow expliciti upgrade_to
grafnu Nov 10, 2023
8bb6835
Be more flexible in legacy upgrading
grafnu Nov 10, 2023
516f7e7
Refactor pointset manager
grafnu Nov 13, 2023
46f37ae
Change hash algorithm
grafnu Nov 13, 2023
310d2d7
Fix algo typos
grafnu Nov 13, 2023
10741fa
Use proper tag
grafnu Nov 13, 2023
7a7cf03
Use complete push tag
grafnu Nov 13, 2023
012bf80
Use different image tag
grafnu Nov 13, 2023
3d6651f
Fix command help
grafnu Nov 13, 2023
cff5cbb
Fix periodic sender timing
grafnu Nov 13, 2023
6e2b86d
Minor tweaks
grafnu Nov 13, 2023
7e6055d
Fix pointset handling
grafnu Nov 13, 2023
541b460
FIx some pointset management
grafnu Nov 13, 2023
0643def
Linty
grafnu Nov 13, 2023
5e9127b
Fix startup pointset state stuff
grafnu Nov 13, 2023
ae5fcad
Fix mosquitto check
grafnu Nov 13, 2023
9392128
Restore itemized test out
grafnu Nov 13, 2023
afac211
Diagnostics
grafnu Nov 13, 2023
c054aa1
Change order of output processing
grafnu Nov 14, 2023
885131c
Fixing writeback
grafnu Nov 14, 2023
a89a267
Fix no pointset state setup
grafnu Nov 14, 2023
aa5f550
Fix output sequence cache
grafnu Nov 14, 2023
d74da5a
Fix generated
grafnu Nov 14, 2023
eb1eab7
Fix set_project for determining kcontext
grafnu Nov 14, 2023
e8c076c
Fix auto subscription model
grafnu Nov 14, 2023
e48adb3
Merge branch 'master' into gatewaytest
grafnu Nov 14, 2023
1b4b5a5
Refacotring of SystemManager
grafnu Nov 14, 2023
acfdae7
Stoopid
grafnu Nov 14, 2023
93be5f3
SystemManager refactoring
grafnu Nov 15, 2023
61b7440
Refactoring options
grafnu Nov 15, 2023
a062315
Fix system event send
grafnu Nov 15, 2023
9a883f3
Fix sending timeunit
grafnu Nov 15, 2023
e8f8fad
Fix undefined handling
grafnu Nov 15, 2023
8b250ce
Revert feed change
grafnu Nov 15, 2023
0dea569
Cleanup logic
grafnu Nov 15, 2023
7a99a4c
Add default system logging interval
grafnu Nov 15, 2023
38b6e76
Reduce default system metric update time
grafnu Nov 15, 2023
a3c59eb
Fix some expected out
grafnu Nov 15, 2023
695272a
Merge remote-tracking branch 'faucet/master' into gatewaytest
grafnu Nov 15, 2023
85c0c07
Add DeviceManager
grafnu Nov 15, 2023
4d35860
Fix NPE
grafnu Nov 15, 2023
0b23e1c
Fixings
grafnu Nov 15, 2023
933e4fe
Don't shutdown on reconnect
grafnu Nov 15, 2023
8d550b7
Fix persistence handling
grafnu Nov 15, 2023
f780ef8
Restore missing restart
grafnu Nov 15, 2023
690e607
Fix state locking
grafnu Nov 15, 2023
37bfe31
Logging tweaks
grafnu Nov 15, 2023
c84a0ff
Fix reflector shutdown-on-error
grafnu Nov 16, 2023
4866d16
Cleanup pubber shutdown logic
grafnu Nov 16, 2023
4c4951a
Refactoring cleanup
grafnu Nov 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ jobs:
- name: registrar clean
run: bin/test_regclean $TARGET_PROJECT
- name: sequence tests clean
run: bin/test_sequencer nocheck $TARGET_PROJECT
run: bin/test_sequencer clean nocheck $TARGET_PROJECT
- name: sequence tests alpha
run: bin/test_sequencer noclean alpha nocheck $TARGET_PROJECT
run: bin/test_sequencer alpha nocheck $TARGET_PROJECT
- name: sequence test post-process
if: ${{ always() }}
run: egrep ' test .* after .*s ' out/sequencer.log > out/timing_sequencer.out
Expand Down
11 changes: 4 additions & 7 deletions bin/test_sequencer
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ source etc/shell_common.sh

debug_opts=-v
seq_opts=
clean_cache=y
clean_cache=
pubber_opts=
suffix=
out_check=y

if [[ $1 == 'noclean' ]]; then
if [[ $1 == 'clean' ]]; then
shift
clean_cache=
clean_cache=y
fi

if [[ $1 == 'alpha' ]]; then
Expand All @@ -42,16 +42,13 @@ if [[ $1 == 'full' ]]; then
fi

if [[ $# -lt 1 ]]; then
echo Usage: $0 [noclean] [alpha] [nostate] [full] PROJECT_ID [tests...]
echo Usage: $0 [clean] [alpha] [nostate] [full] PROJECT_ID [tests...]
false
fi

project_id=$1
shift
targets=$*
if [[ -n $targets ]]; then
clean_cache=
fi

[[ -n $GITHUB_RUN_NUMBER ]] && echo "Workflow run number $GITHUB_RUN_NUMBER" || true
echo "export TARGET_PROJECT=$project_id"
Expand Down
86 changes: 86 additions & 0 deletions pubber/src/main/java/daq/pubber/DeviceManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package daq.pubber;

import udmi.schema.Config;
import udmi.schema.DevicePersistent;
import udmi.schema.Entry;
import udmi.schema.Level;
import udmi.schema.Metadata;
import udmi.schema.Operation.SystemMode;
import udmi.schema.PubberOptions;

/**
* Uber-manager for a complete device.
*/
public class DeviceManager extends ManagerBase {

private PointsetManager pointsetManager;
private SystemManager systemManager;

/**
* Create a new instance.
*/
public DeviceManager(ManagerHost host, PubberOptions options, String serialNo) {
super(host, options);
systemManager = new SystemManager(host, options, serialNo);
pointsetManager = new PointsetManager(host, options);
}

@Override
protected void periodicUpdate() {

}

public void setPersistentData(DevicePersistent persistentData) {
systemManager.setPersistentData(persistentData);
}

public void setMetadata(Metadata metadata) {
pointsetManager.setPointsetModel(metadata.pointset);
systemManager.setMetadata(metadata);
}

@Override
public void cancelPeriodicSend() {
super.cancelPeriodicSend();
pointsetManager.cancelPeriodicSend();
systemManager.cancelPeriodicSend();
}

public void systemLifecycle(SystemMode mode) {
systemManager.systemLifecycle(mode);
}

public void maybeRestartSystem() {
systemManager.maybeRestartSystem();
}

public void localLog(Entry report) {
systemManager.localLog(report);
}

public void localLog(String message, Level trace, String timestamp, String detail) {
systemManager.localLog(message, trace, timestamp, detail);
}

public String getTestingTag() {
return systemManager.getTestingTag();
}

public void updateConfig(Config config) {
pointsetManager.updateConfig(config.pointset);
systemManager.updateConfig(config.system, config.timestamp);
}

public void publishLogMessage(Entry logEntry) {
systemManager.publishLogMessage(logEntry);
}

public void cloudLog(String message, Level level, String detail) {
systemManager.cloudLog(message, level, detail);
}

public void shutdown() {
systemManager.shutdown();
pointsetManager.shutdown();
}
}
35 changes: 32 additions & 3 deletions pubber/src/main/java/daq/pubber/ManagerBase.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package daq.pubber;

import static com.google.common.base.Preconditions.checkState;
import static com.google.udmi.util.GeneralUtils.ifNotNullGet;
import static com.google.udmi.util.GeneralUtils.getNow;
import static java.lang.String.format;
import static java.util.Optional.ofNullable;
import static java.util.concurrent.TimeUnit.SECONDS;

import com.google.daq.mqtt.util.CatchingScheduledThreadPoolExecutor;
import java.util.Date;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import udmi.schema.PubberOptions;

Expand All @@ -19,6 +21,7 @@ public abstract class ManagerBase {

public static final int DISABLED_INTERVAL = 0;
protected static final int DEFAULT_REPORT_SEC = 10;
protected static final int WAIT_TIME_SEC = 10;
protected final AtomicInteger sendRateSec = new AtomicInteger(DEFAULT_REPORT_SEC);
protected final PubberOptions options;
protected final ManagerHost host;
Expand All @@ -34,6 +37,15 @@ protected void updateState(Object state) {
host.update(state);
}

protected ScheduledFuture<?> scheduleFuture(Date futureTime, Runnable futureTask) {
if (executor.isShutdown() || executor.isTerminated()) {
throw new RuntimeException("Executor shutdown/terminated, not scheduling");
}
long delay = futureTime.getTime() - getNow().getTime();
debug(format("Scheduling future in %dms", delay));
return executor.schedule(futureTask, delay, TimeUnit.MILLISECONDS);
}

protected void debug(String message) {
host.debug(message);
}
Expand Down Expand Up @@ -69,8 +81,7 @@ protected void updateInterval(Integer sampleRateSec) {
protected synchronized void startPeriodicSend() {
checkState(periodicSender == null);
int sec = sendRateSec.get();
String simpleName = this.getClass().getSimpleName();
info(format("Setting %s sender with delay %ds", simpleName, sec));
warn(format("Starting %s sender with delay %ds", this.getClass().getSimpleName(), sec));
if (sec != 0) {
periodicSender = executor.scheduleAtFixedRate(this::periodicUpdate, sec, sec, SECONDS);
}
Expand All @@ -79,6 +90,7 @@ protected synchronized void startPeriodicSend() {
protected synchronized void cancelPeriodicSend() {
if (periodicSender != null) {
try {
warn(format("Terminating %s sender", this.getClass().getSimpleName()));
periodicSender.cancel(false);
} catch (Exception e) {
throw new RuntimeException("While cancelling executor", e);
Expand All @@ -87,4 +99,21 @@ protected synchronized void cancelPeriodicSend() {
}
}
}

private void stopExecutor() {
try {
executor.shutdown();
if (!executor.awaitTermination(WAIT_TIME_SEC, TimeUnit.SECONDS)) {
throw new RuntimeException("Failed to shutdown scheduled tasks");
}
} catch (Exception e) {
throw new RuntimeException("While stopping executor", e);
}
}


protected void shutdown() {
cancelPeriodicSend();
stopExecutor();
}
}
1 change: 1 addition & 0 deletions pubber/src/main/java/daq/pubber/PointsetManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class PointsetManager extends ManagerBase {
*/
public PointsetManager(ManagerHost host, PubberOptions options) {
super(host, options);
setExtraField(options.extraField);
updateState();
}

Expand Down
Loading
Loading