Skip to content

Commit fd26b37

Browse files
committed
protocol update wip
1 parent 7333842 commit fd26b37

File tree

6 files changed

+62
-15
lines changed

6 files changed

+62
-15
lines changed

sourceplusplus/control/LiveInstrumentRemote.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import sys
22
import threading
3-
from typing import List
43

5-
import humps
64
from nopdb import nopdb
75
from vertx import EventBus
86

@@ -26,8 +24,8 @@ def __init__(self, eb: EventBus):
2624
LiveInstrumentRemote.dbg.start()
2725
threading.settrace(sys.gettrace())
2826

29-
def add_live_instrument(self, instruments: List[dict]):
30-
for inst_dict in instruments:
27+
def add_live_instrument(self, command: LiveInstrumentCommand):
28+
for inst_dict in command.instruments:
3129
instrument_type: LiveInstrumentType = LiveInstrumentType.from_string(inst_dict["type"])
3230
if instrument_type == LiveInstrumentType.BREAKPOINT:
3331
live_instrument = LiveBreakpoint.from_dict(inst_dict)
@@ -43,21 +41,15 @@ def add_live_instrument(self, instruments: List[dict]):
4341
if instrument_type == LiveInstrumentType.BREAKPOINT:
4442
bp.exec("import sourceplusplus.control.ContextReceiver as ContextReceiver\n"
4543
"ContextReceiver.apply_breakpoint('" + live_instrument.id + "',globals(),locals())")
46-
body = humps.camelize(inst_dict)
47-
body["meta"] = inst_dict["meta"]
48-
self.eb.publish(address="spp.processor.status.live-instrument-applied", body=body)
44+
self.eb.publish(address="spp.processor.status.live-instrument-applied", body=live_instrument.to_dict())
4945
elif instrument_type == LiveInstrumentType.LOG:
5046
bp.exec("import sourceplusplus.control.ContextReceiver as ContextReceiver\n"
5147
"ContextReceiver.apply_log('" + live_instrument.id + "',globals(),locals())")
52-
body = humps.camelize(inst_dict)
53-
body["meta"] = inst_dict["meta"]
54-
self.eb.publish(address="spp.processor.status.live-instrument-applied", body=body)
48+
self.eb.publish(address="spp.processor.status.live-instrument-applied", body=live_instrument.to_dict())
5549
else:
5650
bp.exec("import sourceplusplus.control.ContextReceiver as ContextReceiver\n"
5751
"ContextReceiver.apply_meter('" + live_instrument.id + "',globals(),locals())")
58-
body = humps.camelize(inst_dict)
59-
body["meta"] = inst_dict["meta"]
60-
self.eb.publish(address="spp.processor.status.live-instrument-applied", body=body)
52+
self.eb.publish(address="spp.processor.status.live-instrument-applied", body=live_instrument.to_dict())
6153

6254
def remove_live_instrument(self, command: LiveInstrumentCommand):
6355
print("Removing live instrument(s)")
@@ -84,6 +76,6 @@ def remove_live_instrument(self, command: LiveInstrumentCommand):
8476
def handle_instrument_command(self, command: LiveInstrumentCommand):
8577
print("Received command: " + command.command_type)
8678
if command.command_type == CommandType.ADD_LIVE_INSTRUMENT:
87-
self.add_live_instrument(command.instruments)
79+
self.add_live_instrument(command)
8880
elif command.command_type == CommandType.REMOVE_LIVE_INSTRUMENT:
8981
self.remove_live_instrument(command)

sourceplusplus/models/instrument/LiveBreakpoint.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ def __init__(self, location: LiveSourceLocation):
1515
self.hit_limit = 1
1616
self.type = LiveInstrumentType.BREAKPOINT
1717

18+
def to_dict(self):
19+
dict = humps.camelize(json.loads(self.to_json()))
20+
dict["meta"] = self.__dict__["meta"]
21+
return dict
22+
1823
@classmethod
1924
def from_dict(cls, json_dict):
2025
# todo: easier way to convert

sourceplusplus/models/instrument/LiveLog.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ def __init__(self, location: LiveSourceLocation):
1717
self.hit_limit = None
1818
self.type = LiveInstrumentType.LOG
1919

20+
def to_dict(self):
21+
dict = humps.camelize(json.loads(self.to_json()))
22+
dict["meta"] = self.__dict__["meta"]
23+
return dict
24+
2025
@classmethod
2126
def from_dict(cls, json_dict):
2227
# todo: easier way to convert

sourceplusplus/models/instrument/LiveMeter.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ def __init__(self, location: LiveSourceLocation):
1515
self.hit_limit = -1
1616
self.type = LiveInstrumentType.METER
1717

18+
def to_dict(self):
19+
dict = humps.camelize(json.loads(self.to_json()))
20+
dict["meta"] = self.__dict__["meta"]
21+
return dict
22+
1823
@classmethod
1924
def from_dict(cls, json_dict):
2025
# todo: easier way to convert

sourceplusplus/models/instrument/common/LiveSourceLocation.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44

55

66
class LiveSourceLocation(object):
7-
def __init__(self, source, line, commit_id=None, file_checksum=None):
7+
def __init__(self, source, line, service=None, service_instance=None, commit_id=None, file_checksum=None):
88
self.source = source
99
self.line = line
10+
self.service = service
11+
self.service_instance = service_instance
1012
self.commit_id = commit_id
1113
self.file_checksum = file_checksum
1214

tests/instrument_serialization/tests.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import time
33
import unittest
44

5+
from sourceplusplus.models.command.LiveInstrumentCommand import LiveInstrumentCommand
56
from sourceplusplus.models.instrument.LiveBreakpoint import LiveBreakpoint
67
from sourceplusplus.models.instrument.LiveLog import LiveLog
78
from sourceplusplus.models.instrument.common.LiveSourceLocation import LiveSourceLocation
@@ -11,6 +12,43 @@
1112

1213
class TestSum(unittest.TestCase):
1314

15+
def test_command_serialization(self):
16+
raw_command = {
17+
"commandType": "ADD_LIVE_INSTRUMENT",
18+
"instruments": [
19+
{
20+
"location": {
21+
"source": "E2ETest.py",
22+
"line": 18, "service": None,
23+
"serviceInstance": None,
24+
"commitId": None,
25+
"fileChecksum": None
26+
},
27+
"condition": None,
28+
"expiresAt": None,
29+
"hitLimit": 1,
30+
"id": "3145bbee-8d81-4184-8c3d-f97f208a6e15",
31+
"applyImmediately": False,
32+
"applied": False,
33+
"pending": True,
34+
"throttle": {
35+
"limit": 1,
36+
"step": "SECOND"
37+
},
38+
"meta": {
39+
"created_at": "1644293169743",
40+
"created_by": "system",
41+
"hit_count": 0
42+
},
43+
"type": "BREAKPOINT"
44+
}
45+
],
46+
"locations": []
47+
}
48+
command = LiveInstrumentCommand.from_json(json.dumps(raw_command))
49+
bp = LiveBreakpoint.from_dict(command.instruments[0])
50+
self.assertEqual(raw_command["instruments"][0], LiveBreakpoint.from_json(bp.to_json()).to_dict())
51+
1452
def test_deserialize_breakpoint(self):
1553
raw_bp = {
1654
"location": {

0 commit comments

Comments
 (0)