Skip to content

Commit 0961a36

Browse files
committed
protocol update wip
1 parent 599dec8 commit 0961a36

File tree

14 files changed

+69
-74
lines changed

14 files changed

+69
-74
lines changed

e2e/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ RUN pip install Flask
66
RUN pip install PyYAML
77
RUN pip install vertx-eventbus-client
88

9-
COPY sourceplusplus-0.1.5.tar.gz .
9+
COPY sourceplusplus-*.tar.gz ./sourceplusplus.tar.gz
1010

11-
RUN pip install sourceplusplus-0.1.5.tar.gz
11+
RUN pip install sourceplusplus.tar.gz
1212

1313
COPY E2ETest.py .
1414

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from setuptools import setup
33

44
setup(name='sourceplusplus',
5-
version='0.1.5',
5+
version='0.4.0',
66
description='Source++ Python Probe',
77
url='https://github.com/sourceplusplus/probe-python',
88
author='Source++',

sourceplusplus/SourcePlusPlus.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from sourceplusplus import __version__
1313
from .control.LiveInstrumentRemote import LiveInstrumentRemote
1414
from .models.command.LiveInstrumentCommand import LiveInstrumentCommand
15-
from .models.instrument.common.LiveInstrumentType import LiveInstrumentType
1615

1716

1817
class SourcePlusPlus(object):
@@ -137,28 +136,22 @@ def __send_connected(self, eb: EventBus):
137136
# send probe connected event
138137
reply_address = str(uuid.uuid4())
139138
eb.send(address="spp.platform.status.probe-connected", body={
140-
"probeId": self.probe_config["spp"]["probe_id"],
139+
"instanceId": self.probe_config["spp"]["probe_id"],
141140
"connectionTime": round(time.time() * 1000),
142141
"meta": probe_metadata
143142
}, reply_handler=lambda msg: self.__register_remotes(eb, reply_address, msg["body"]))
144143

145144
def __register_remotes(self, eb, reply_address, status):
146145
eb.unregister_handler(reply_address)
147146
eb.register_handler(
148-
address="spp.probe.command.live-breakpoint-remote:" + self.probe_config["spp"]["probe_id"],
147+
address="spp.probe.command.live-instrument-remote",
149148
handler=lambda msg: self.instrument_remote.handle_instrument_command(
150-
LiveInstrumentCommand.from_json(json.dumps(msg["body"])), LiveInstrumentType.BREAKPOINT
149+
LiveInstrumentCommand.from_json(json.dumps(msg["body"]))
151150
)
152151
)
153152
eb.register_handler(
154-
address="spp.probe.command.live-log-remote:" + self.probe_config["spp"]["probe_id"],
153+
address="spp.probe.command.live-instrument-remote:" + self.probe_config["spp"]["probe_id"],
155154
handler=lambda msg: self.instrument_remote.handle_instrument_command(
156-
LiveInstrumentCommand.from_json(json.dumps(msg["body"])), LiveInstrumentType.LOG
157-
)
158-
)
159-
eb.register_handler(
160-
address="spp.probe.command.live-meter-remote:" + self.probe_config["spp"]["probe_id"],
161-
handler=lambda msg: self.instrument_remote.handle_instrument_command(
162-
LiveInstrumentCommand.from_json(json.dumps(msg["body"])), LiveInstrumentType.METER
155+
LiveInstrumentCommand.from_json(json.dumps(msg["body"]))
163156
)
164157
)

sourceplusplus/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
__version__ = '0.1.5'
1+
__version__ = '0.4.0'
22
__name__ = 'Source++'
33
agent_name = 'Source++ Python Probe'

sourceplusplus/control/ContextReceiver.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def apply_log(live_log_id, globals, locals):
8484
)
8585
except Exception:
8686
pass
87-
LiveInstrumentRemote.eb.send(address="spp.platform.status.live-log-removed", body={
87+
LiveInstrumentRemote.eb.send(address="spp.processor.status.live-instrument-removed", body={
8888
"log": live_log.to_json(),
8989
"occurredAt": round(time.time() * 1000)
9090
})
@@ -148,8 +148,8 @@ def apply_breakpoint(live_breakpoint_id, globals, locals):
148148
)
149149
except Exception:
150150
pass
151-
LiveInstrumentRemote.eb.send(address="spp.platform.status.live-breakpoint-removed", body={
152-
"breakpoint": live_breakpoint.to_json(),
151+
LiveInstrumentRemote.eb.send(address="spp.processor.status.live-instrument-removed", body={
152+
"instrument": live_breakpoint.to_json(),
153153
"occurredAt": round(time.time() * 1000)
154154
})
155155

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import json
21
import sys
32
import threading
3+
from typing import List
4+
5+
import humps
46
from nopdb import nopdb
57
from vertx import EventBus
68

79
from sourceplusplus.models.command.CommandType import CommandType
810
from sourceplusplus.models.command.LiveInstrumentCommand import LiveInstrumentCommand
9-
from sourceplusplus.models.command.LiveInstrumentContext import LiveInstrumentContext
1011
from sourceplusplus.models.instrument.LiveBreakpoint import LiveBreakpoint
1112
from sourceplusplus.models.instrument.LiveLog import LiveLog
1213
from sourceplusplus.models.instrument.LiveMeter import LiveMeter
@@ -25,14 +26,15 @@ def __init__(self, eb: EventBus):
2526
LiveInstrumentRemote.dbg.start()
2627
threading.settrace(sys.gettrace())
2728

28-
def add_live_instrument(self, context: LiveInstrumentContext, instrument_type: LiveInstrumentType):
29-
for i in context.instruments:
29+
def add_live_instrument(self, instruments: List[dict]):
30+
for inst_dict in instruments:
31+
instrument_type: LiveInstrumentType = LiveInstrumentType.from_string(inst_dict["type"])
3032
if instrument_type == LiveInstrumentType.BREAKPOINT:
31-
live_instrument = LiveBreakpoint.from_json(i)
33+
live_instrument = LiveBreakpoint.from_dict(inst_dict)
3234
elif instrument_type == LiveInstrumentType.LOG:
33-
live_instrument = LiveLog.from_json(i)
35+
live_instrument = LiveLog.from_dict(inst_dict)
3436
else:
35-
live_instrument = LiveMeter.from_json(i)
37+
live_instrument = LiveMeter.from_dict(inst_dict)
3638
bp = LiveInstrumentRemote.dbg.breakpoint(
3739
file=live_instrument.location.source[live_instrument.location.source.rfind("/") + 1:],
3840
line=live_instrument.location.line
@@ -41,46 +43,47 @@ def add_live_instrument(self, context: LiveInstrumentContext, instrument_type: L
4143
if instrument_type == LiveInstrumentType.BREAKPOINT:
4244
bp.exec("import sourceplusplus.control.ContextReceiver as ContextReceiver\n"
4345
"ContextReceiver.apply_breakpoint('" + live_instrument.id + "',globals(),locals())")
44-
self.eb.publish(address="spp.platform.status.live-breakpoint-applied", body=json.loads(i))
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)
4549
elif instrument_type == LiveInstrumentType.LOG:
4650
bp.exec("import sourceplusplus.control.ContextReceiver as ContextReceiver\n"
4751
"ContextReceiver.apply_log('" + live_instrument.id + "',globals(),locals())")
48-
self.eb.publish(address="spp.platform.status.live-log-applied", body=json.loads(i))
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)
4955
else:
5056
bp.exec("import sourceplusplus.control.ContextReceiver as ContextReceiver\n"
5157
"ContextReceiver.apply_meter('" + live_instrument.id + "',globals(),locals())")
52-
self.eb.publish(address="spp.platform.status.live-meter-applied", body=json.loads(i))
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)
5361

54-
def remove_live_instrument(self, context: LiveInstrumentContext, type: LiveInstrumentType):
62+
def remove_live_instrument(self, command: LiveInstrumentCommand):
5563
print("Removing live instrument(s)")
56-
for i in context.instruments:
64+
for inst_dict in command.instruments:
5765
if type == LiveInstrumentType.BREAKPOINT:
58-
instrument = LiveBreakpoint.from_json(i)
66+
instrument = LiveBreakpoint.from_dict(inst_dict)
5967
elif type == LiveInstrumentType.LOG:
60-
instrument = LiveLog.from_json(i)
68+
instrument = LiveLog.from_dict(inst_dict)
6169
else:
62-
instrument = LiveMeter.from_json(i)
70+
instrument = LiveMeter.from_dict(inst_dict)
6371
try:
6472
LiveInstrumentRemote.dbg.remove_callback(LiveInstrumentRemote.instruments.pop(instrument.id)[0]._handle)
6573
except KeyError:
6674
pass
67-
for i in context.locations:
68-
loc = LiveSourceLocation.from_json(i)
75+
for inst_dict in command.locations:
76+
loc = LiveSourceLocation.from_json(inst_dict)
6977
delete = []
7078
for key, val in LiveInstrumentRemote.instruments.items():
7179
if val[1].type == type and val[1].location == loc:
7280
delete.append(key)
73-
for i in delete:
74-
del LiveInstrumentRemote.instruments[i]
81+
for inst_dict in delete:
82+
del LiveInstrumentRemote.instruments[inst_dict]
7583

76-
def handle_instrument_command(self, command: LiveInstrumentCommand, instrument_type: LiveInstrumentType):
84+
def handle_instrument_command(self, command: LiveInstrumentCommand):
7785
print("Received command: " + command.command_type)
7886
if command.command_type == CommandType.ADD_LIVE_INSTRUMENT:
79-
if instrument_type == LiveInstrumentType.BREAKPOINT:
80-
self.add_live_instrument(command.context, LiveInstrumentType.BREAKPOINT)
81-
elif instrument_type == LiveInstrumentType.LOG:
82-
self.add_live_instrument(command.context, LiveInstrumentType.LOG)
83-
else:
84-
self.add_live_instrument(command.context, LiveInstrumentType.METER)
87+
self.add_live_instrument(command.instruments)
8588
elif command.command_type == CommandType.REMOVE_LIVE_INSTRUMENT:
86-
self.remove_live_instrument(command.context, instrument_type)
89+
self.remove_live_instrument(command)

sourceplusplus/models/command/CommandType.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22

33

44
class CommandType(str, Enum):
5-
GET_LIVE_INSTRUMENTS = "GET_LIVE_INSTRUMENTS"
65
ADD_LIVE_INSTRUMENT = "ADD_LIVE_INSTRUMENT"
76
REMOVE_LIVE_INSTRUMENT = "REMOVE_LIVE_INSTRUMENT"
Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
import json
2+
from typing import List
23

34
import humps
45

56
from .CommandType import CommandType
6-
from .LiveInstrumentContext import LiveInstrumentContext
77

88

99
class LiveInstrumentCommand(object):
10-
def __init__(self, command_type: CommandType, context: LiveInstrumentContext):
10+
def __init__(self, command_type: CommandType, instruments: List[dict], locations: List[dict]):
1111
self.command_type = command_type
12-
self.context = context
12+
self.instruments = instruments
13+
self.locations = locations
1314

1415
def to_json(self):
1516
return json.dumps(self, default=lambda o: humps.camelize(o.__dict__))
1617

1718
@classmethod
1819
def from_json(cls, json_str):
1920
json_dict = humps.decamelize(json.loads(json_str))
20-
# todo: easier way to convert
21-
context = LiveInstrumentContext([], [])
22-
for key in json_dict["context"]:
23-
setattr(context, key, json_dict["context"][key])
24-
return LiveInstrumentCommand(json_dict["command_type"], context)
21+
return LiveInstrumentCommand(json_dict["command_type"], json_dict["instruments"], json_dict["locations"])

sourceplusplus/models/command/LiveInstrumentContext.py

Lines changed: 0 additions & 13 deletions
This file was deleted.

sourceplusplus/models/instrument/LiveBreakpoint.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ def __init__(self, location: LiveSourceLocation):
1616
self.type = LiveInstrumentType.BREAKPOINT
1717

1818
@classmethod
19-
def from_json(cls, json_str):
20-
json_dict = humps.decamelize(json.loads(json_str))
19+
def from_dict(cls, json_dict):
2120
# todo: easier way to convert
2221
location = LiveSourceLocation(json_dict["location"]["source"], json_dict["location"]["line"])
2322
bp = LiveBreakpoint(location)
@@ -27,3 +26,7 @@ def from_json(cls, json_str):
2726
bp.throttle = HitThrottle(json_dict["throttle"]["limit"], ThrottleStep(json_dict["throttle"]["step"]))
2827
bp.type = LiveInstrumentType.BREAKPOINT
2928
return bp
29+
30+
@classmethod
31+
def from_json(cls, json_str):
32+
return cls.from_dict(humps.decamelize(json.loads(json_str)))

0 commit comments

Comments
 (0)