Skip to content

Commit e02e05b

Browse files
committed
Performance Cluster Management
Confirmed cluster is wired in correctly for CLI. Also hit circular reference issue and had to tweak code to use just the data_store object from the process_tracker (since that is the primary object users use and everything ties back to process). Working on #11
1 parent 5a41458 commit e02e05b

File tree

10 files changed

+340
-31
lines changed

10 files changed

+340
-31
lines changed

process_tracker/cli.py

Lines changed: 115 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,39 @@ def upgrade():
5454
"-p", "--parent", help="The parent process' name, if creating a process dependency"
5555
)
5656
@click.option(
57-
"-c", "--child", help="The child process' name, if creating a process dependency"
57+
"-c",
58+
"--child",
59+
help="The child process' name, if creating a process dependency. For cluster/process relationships, the name of "
60+
"the process.",
5861
)
59-
def create(topic, name, parent=None, child=None):
62+
@click.option(
63+
"--max-processing",
64+
help="For clusters, the max processing ability allocated to the cluster",
65+
)
66+
@click.option(
67+
"--max-memory", help="For clusters, the max memory allocated to the cluster"
68+
)
69+
@click.option(
70+
"--processing-unit",
71+
help="For clusters, the unit of processing ability (Ghz, CPU, DPU, etc.",
72+
)
73+
@click.option(
74+
"--memory-unit", help="For clusters, the unit of allocated memory (MB, GB, etc."
75+
)
76+
@click.option(
77+
"--cluster", help="For cluster/process relationships, the name of the cluster"
78+
)
79+
def create(
80+
topic,
81+
name,
82+
parent=None,
83+
child=None,
84+
max_processing=None,
85+
processing_unit=None,
86+
max_memory=None,
87+
memory_unit=None,
88+
cluster=None,
89+
):
6090
"""
6191
Create an item that is within the valid topics list.
6292
:param topic: The name of the topic.
@@ -65,11 +95,32 @@ def create(topic, name, parent=None, child=None):
6595
:type name: string
6696
:param parent: The parent process' name, if creating a process dependency
6797
:type parent: string
68-
:param child: The child process' name, if creating a process dependency
98+
:param child: The child process' name, if creating a process dependency. For cluster/process relationships, the
99+
name of the process.
69100
:type child: string
101+
:param max_processing: For performance clusters, the maximum processing ability allocated to the cluster
102+
:type max_processing: integer
103+
:param max_memory: For performance clusters, the maximum memory allocated to the cluster
104+
:type max_memory: integer
105+
:param processing_unit: For performance clusters, the unit of processing ability allocated to the cluster
106+
:type processing_unit: string
107+
:param memory_unit: For performance clusters, the unit of allocated memory to the cluster
108+
:type memory_unit: string
109+
:param cluster: For cluster/process relationships, the name of the cluster.
110+
:type cluster: string
70111
"""
71112
click.echo("Attempting to create %s with name %s" % (topic, name))
72-
data_store.topic_creator(topic=topic, name=name, parent=parent, child=child)
113+
data_store.topic_creator(
114+
topic=topic,
115+
name=name,
116+
parent=parent,
117+
child=child,
118+
max_processing=max_processing,
119+
max_memory=max_memory,
120+
processing_unit=processing_unit,
121+
memory_unit=memory_unit,
122+
cluster=cluster,
123+
)
73124

74125

75126
@main.command()
@@ -81,7 +132,10 @@ def create(topic, name, parent=None, child=None):
81132
@click.option(
82133
"-c", "--child", help="The child process' name, if deleting a process dependency"
83134
)
84-
def delete(topic, name, parent=None, child=None):
135+
@click.option(
136+
"--cluster", help="For cluster/process relationships, the name of the cluster"
137+
)
138+
def delete(topic, name, parent=None, child=None, cluster=None):
85139
"""
86140
Delete an item that is within the valid topics list and not a pre-loaded item.
87141
:param topic: The name of the topic.
@@ -90,20 +144,71 @@ def delete(topic, name, parent=None, child=None):
90144
:type name: string
91145
:param parent: The parent process' name, if deleting a process dependency
92146
:type parent: string
93-
:param child: The child process' name, if deleting a process dependency
147+
:param child: The child process' name, if deleting a process dependency. For cluster/process relationships, the
148+
name of the process.
94149
:type child: string
150+
:param cluster: For cluster/process relationships, the name of the cluster.
151+
:type cluster: string
95152
"""
96153
click.echo("Attempting to delete %s with name %s" % (topic, name))
97-
data_store.topic_deleter(topic=topic, name=name, parent=parent, child=child)
154+
data_store.topic_deleter(
155+
topic=topic, name=name, parent=parent, child=child, cluster=cluster
156+
)
98157

99158

100159
@main.command()
101160
@click.option("-t", "--topic", help="The topic being created")
102161
@click.option("-i", "--initial-name", help="The name that needs to be changed.")
103162
@click.option("-n", "--name", help="The new name for the topic.")
104-
def update(topic, initial_name, name):
105-
163+
@click.option(
164+
"--max-processing",
165+
help="For clusters, the max processing ability allocated to the cluster",
166+
)
167+
@click.option(
168+
"--max-memory", help="For clusters, the max memory allocated to the cluster"
169+
)
170+
@click.option(
171+
"--processing-unit",
172+
help="For clusters, the unit of processing ability (Ghz, CPU, DPU, etc.",
173+
)
174+
@click.option(
175+
"--memory-unit", help="For clusters, the unit of allocated memory (MB, GB, etc."
176+
)
177+
def update(
178+
topic,
179+
initial_name,
180+
name,
181+
max_processing=None,
182+
max_memory=None,
183+
processing_unit=None,
184+
memory_unit=None,
185+
):
186+
"""
187+
Update an item that is within the valid topics list and not a pre-loaded item.
188+
:param topic: The name of the topic.
189+
:type topic: string
190+
:param initial_name: The revised name of the topic item to be updated.
191+
:type initial_name: string
192+
:param name: The original name of the topic item to be updated.
193+
:type name: string
194+
:param max_processing: For performance clusters, the maximum processing ability allocated to the cluster
195+
:type max_processing: string
196+
:param max_memory: For performance clusters, the maximum memory allocated to the cluster
197+
:type max_memory: string
198+
:param processing_unit: For performance clusters, the unit of processing ability allocated to the cluster
199+
:type processing_unit: string
200+
:param memory_unit: For performance clusters, the unit of allocated memory to the cluster
201+
:type memory_unit: string
202+
"""
106203
click.echo(
107204
"Attempting to update %s with name %s to %s" % (topic, initial_name, name)
108205
)
109-
data_store.topic_updater(topic=topic, initial_name=initial_name, name=name)
206+
data_store.topic_updater(
207+
topic=topic,
208+
initial_name=initial_name,
209+
name=name,
210+
max_processing=max_processing,
211+
max_memory=max_memory,
212+
processing_unit=processing_unit,
213+
memory_unit=memory_unit,
214+
)

process_tracker/data_store.py

Lines changed: 121 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from process_tracker.models.model_base import Base
1212
from process_tracker.models.actor import Actor
13+
from process_tracker.models.capacity import Cluster, ClusterProcess
1314
from process_tracker.models.extract import ExtractStatus
1415
from process_tracker.models.process import (
1516
ErrorType,
@@ -182,7 +183,18 @@ def initialize_data_store(self, overwrite=False):
182183

183184
self.logger.debug("Finished the initialization check.")
184185

185-
def topic_creator(self, topic, name, parent=None, child=None):
186+
def topic_creator(
187+
self,
188+
topic,
189+
name,
190+
parent=None,
191+
child=None,
192+
max_processing=None,
193+
processing_unit=None,
194+
max_memory=None,
195+
memory_unit=None,
196+
cluster=None,
197+
):
186198
"""
187199
For the command line tool, validate the topic and create the new instance.
188200
:param topic: The name of the topic.
@@ -191,8 +203,19 @@ def topic_creator(self, topic, name, parent=None, child=None):
191203
:type name: string
192204
:param parent: The parent process' name, if creating a process dependency
193205
:type parent: string
194-
:param child: The child process' name, if creating a process dependency
206+
:param child: The child process' name, if creating a process dependency.For cluster/process relationships, the
207+
name of the process.
195208
:type child: string
209+
:param max_processing: For performance clusters, the maximum processing ability allocated to the cluster
210+
:type max_processing: string
211+
:param max_memory: For performance clusters, the maximum memory allocated to the cluster
212+
:type max_memory: string
213+
:param processing_unit: For performance clusters, the unit of processing ability allocated to the cluster
214+
:type processing_unit: string
215+
:param memory_unit: For performance clusters, the unit of allocated memory to the cluster
216+
:type memory_unit: string
217+
:param cluster: For cluster/process relationships, the name of the cluster.
218+
:type cluster: string
196219
:return:
197220
"""
198221
self.logger.info("Attempting to create %s item: %s" % (topic, name))
@@ -203,6 +226,33 @@ def topic_creator(self, topic, name, parent=None, child=None):
203226
item = self.get_or_create_item(model=Actor, actor_name=name)
204227
self.logger.info("Actor created: %s" % item.__repr__)
205228

229+
elif topic == "cluster":
230+
item = self.get_or_create_item(
231+
model=Cluster,
232+
cluster_name=name,
233+
cluster_max_memory=max_memory,
234+
cluster_max_memory_unit=memory_unit,
235+
cluster_max_processing=max_processing,
236+
cluster_max_processing_unit=processing_unit,
237+
)
238+
self.logger.info("Cluster created: %s" % item.__repr__)
239+
240+
elif topic == "cluster process":
241+
cluster = self.get_or_create_item(
242+
model=Cluster, create=False, cluster_name=cluster
243+
)
244+
process = self.get_or_create_item(
245+
model=Process, create=False, process_name=child
246+
)
247+
248+
item = self.get_or_create_item(
249+
model=ClusterProcess,
250+
cluster_id=cluster.cluster_id,
251+
process_id=process.process_id,
252+
)
253+
254+
self.logger.info("Cluster Process created: %s" % item.__repr__)
255+
206256
elif topic == "extract status":
207257
item = self.get_or_create_item(
208258
model=ExtractStatus, extract_status_name=name
@@ -260,7 +310,7 @@ def topic_creator(self, topic, name, parent=None, child=None):
260310

261311
return item
262312

263-
def topic_deleter(self, topic, name, parent=None, child=None):
313+
def topic_deleter(self, topic, name, parent=None, child=None, cluster=None):
264314
"""
265315
For the command line tool, validate that the topic name is not a default value and if not, delete it.
266316
:param topic: The SQLAlchemy object type
@@ -269,8 +319,9 @@ def topic_deleter(self, topic, name, parent=None, child=None):
269319
:type name: string
270320
:param parent: The parent process' name, if deleting a process dependency
271321
:type parent: string
272-
:param child: The child process' name, if deleting a process dependency
322+
:param child: The child process' name, if deleting a process dependency. For cluster/process relationship, the name of the process.
273323
:type child: string
324+
:param cluster: For cluster/process relationship, the name of the cluster.
274325
:return:
275326
"""
276327
item_delete = False
@@ -284,6 +335,33 @@ def topic_deleter(self, topic, name, parent=None, child=None):
284335
self.session.query(Actor).filter(Actor.actor_name == name).delete()
285336
self.logger.info("%s %s deleted." % (topic, name))
286337

338+
elif topic == "cluster":
339+
item_delete = True
340+
self.session.query(Cluster).filter(
341+
Cluster.cluster_name == name
342+
).delete()
343+
self.logger.info("%s %s deleted." % (topic, name))
344+
345+
elif topic == "cluster process":
346+
item_delete = True
347+
cluster = self.get_or_create_item(
348+
model=Cluster, create=False, cluster_name=cluster
349+
)
350+
process = self.get_or_create_item(
351+
model=Process, create=False, process_name=child
352+
)
353+
354+
item = self.get_or_create_item(
355+
model=ClusterProcess,
356+
create=False,
357+
cluster_id=cluster.cluster_id,
358+
process_id=process.process_id,
359+
)
360+
361+
self.session.delete(item)
362+
363+
self.logger.info("%s %s - %s deleted." % (topic, cluster, child))
364+
287365
elif topic == "extract status" and name not in preload_extract_status_types:
288366
item_delete = True
289367
self.session.query(ExtractStatus).filter(
@@ -359,7 +437,16 @@ def topic_deleter(self, topic, name, parent=None, child=None):
359437

360438
return "blarg"
361439

362-
def topic_updater(self, topic, initial_name, name):
440+
def topic_updater(
441+
self,
442+
topic,
443+
initial_name,
444+
name,
445+
max_processing=None,
446+
processing_unit=None,
447+
max_memory=None,
448+
memory_unit=None,
449+
):
363450
"""
364451
For the command line tool, validate that the topic name is not a default value and if not, update it.
365452
:param topic: name of the SQLAlchemy object
@@ -368,6 +455,14 @@ def topic_updater(self, topic, initial_name, name):
368455
:type initial_name: string
369456
:param name: The updated name of the object to be updated.
370457
:type name: string
458+
:param max_processing: For performance clusters, the maximum processing ability allocated to the cluster
459+
:type max_processing: string
460+
:param max_memory: For performance clusters, the maximum memory allocated to the cluster
461+
:type max_memory: string
462+
:param processing_unit: For performance clusters, the unit of processing ability allocated to the cluster
463+
:type processing_unit: string
464+
:param memory_unit: For performance clusters, the unit of allocated memory to the cluster
465+
:type memory_unit: string
371466
:return:
372467
"""
373468
if self.topic_validator(topic=topic):
@@ -378,6 +473,26 @@ def topic_updater(self, topic, initial_name, name):
378473
item.actor_name = name
379474
self.logger.info("%s %s updated." % (topic, name))
380475

476+
elif topic == "cluster":
477+
item = self.get_or_create_item(
478+
model=Cluster, create=False, cluster_name=initial_name
479+
)
480+
481+
item.cluster_name = name
482+
if max_memory is not None:
483+
item.cluster_max_memory = max_memory
484+
485+
if memory_unit is not None:
486+
item.cluster_max_memory_unit = memory_unit
487+
488+
if max_processing is not None:
489+
item.cluster_max_processing = max_processing
490+
491+
if processing_unit is not None:
492+
item.cluster_max_processing_unit = processing_unit
493+
494+
self.logger.info("%s %s updated." % (topic, name))
495+
381496
elif (
382497
topic == "extract status"
383498
and initial_name not in preload_extract_status_types
@@ -455,6 +570,7 @@ def topic_validator(self, topic):
455570
# Only data store topics that should be allowed to be created from the command line tool.
456571
valid_topics = [
457572
"actor",
573+
"cluster",
458574
"error type",
459575
"extract status",
460576
"process dependency",

process_tracker/extract_tracker.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from sqlalchemy.orm import aliased
88

9-
from process_tracker.data_store import DataStore
109
from process_tracker.location_tracker import LocationTracker
1110
from process_tracker.utilities.settings import SettingsManager
1211
from process_tracker.utilities import utilities
@@ -62,7 +61,9 @@ def __init__(
6261
elif location_path is not None:
6362
self.logger.info("Location path provided. Creating Location object.")
6463
self.location = LocationTracker(
65-
location_name=location_name, location_path=location_path
64+
location_name=location_name,
65+
location_path=location_path,
66+
data_store=self.data_store,
6667
)
6768
else:
6869
raise Exception("A location object or location_path must be provided.")

0 commit comments

Comments
 (0)