Skip to content

Commit abdc5d0

Browse files
author
Alex Meadows
committed
process_tracker_python-90 Add contact information to data source
✨ Added Contact
1 parent e57764d commit abdc5d0

File tree

5 files changed

+183
-16
lines changed

5 files changed

+183
-16
lines changed

process_tracker/cli.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,12 @@ def upgrade():
7272
help="For clusters, the unit of processing ability (Ghz, CPU, DPU, etc.",
7373
)
7474
@click.option(
75-
"--memory-unit", help="For clusters, the unit of allocated memory (MB, GB, etc."
75+
"--memory-unit", help="For clusters, the unit of allocated memory (MB, GB, etc.)"
7676
)
7777
@click.option(
7878
"--cluster", help="For cluster/process relationships, the name of the cluster"
7979
)
80+
@click.option("--email", help="For contacts, the contact's email address.")
8081
def create(
8182
topic,
8283
name,
@@ -87,6 +88,7 @@ def create(
8788
max_memory=None,
8889
memory_unit=None,
8990
cluster=None,
91+
email=None,
9092
):
9193
"""
9294
Create an item that is within the valid topics list.
@@ -109,6 +111,8 @@ def create(
109111
:type memory_unit: string
110112
:param cluster: For cluster/process relationships, the name of the cluster.
111113
:type cluster: string
114+
:param email: For contacts, the contact's email address.
115+
:type email: string
112116
"""
113117
click.echo("Attempting to create %s with name %s" % (topic, name))
114118
data_store.topic_creator(
@@ -121,6 +125,7 @@ def create(
121125
processing_unit=processing_unit,
122126
memory_unit=memory_unit,
123127
cluster=cluster,
128+
email=email,
124129
)
125130

126131

@@ -175,6 +180,7 @@ def delete(topic, name, parent=None, child=None, cluster=None):
175180
@click.option(
176181
"--memory-unit", help="For clusters, the unit of allocated memory (MB, GB, etc."
177182
)
183+
@click.option("--email", help="For contacts, the contact's email address.")
178184
def update(
179185
topic,
180186
name,
@@ -183,6 +189,7 @@ def update(
183189
max_memory=None,
184190
processing_unit=None,
185191
memory_unit=None,
192+
email=None,
186193
):
187194
"""
188195
Update an item that is within the valid topics list and not a pre-loaded item.
@@ -200,6 +207,8 @@ def update(
200207
:type processing_unit: string
201208
:param memory_unit: For performance clusters, the unit of allocated memory to the cluster
202209
:type memory_unit: string
210+
:param email: For contacts, the contact's email address.
211+
:type email: string
203212
"""
204213
click.echo(
205214
"Attempting to update %s with name %s to %s" % (topic, initial_name, name)
@@ -212,6 +221,7 @@ def update(
212221
max_memory=max_memory,
213222
processing_unit=processing_unit,
214223
memory_unit=memory_unit,
224+
email=email,
215225
)
216226

217227

process_tracker/models/contact.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# SQLAlchemy Models
2+
# Models for Contact entities
3+
4+
from sqlalchemy import Column, Integer, Sequence, String
5+
from process_tracker.models.model_base import Base
6+
7+
8+
class Contact(Base):
9+
10+
__tablename__ = "contact_lkup"
11+
__table_args__ = {"schema": "process_tracker"}
12+
13+
contact_id = Column(
14+
Integer,
15+
Sequence("contact_lkup_contact_id_seq", schema="process_tracker"),
16+
primary_key=True,
17+
nullable=False,
18+
)
19+
contact_name = Column(String(250), nullable=False, unique=True)
20+
contact_email = Column(String(750), nullable=True, unique=True)
21+
22+
def __repr__(self):
23+
return "<Contact id=%s, name=%s>" % (self.contact_id, self.contact_name)

process_tracker/models/source.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,29 @@ def __repr__(self):
5050
return "<Source (name=%s)>" % self.source_name
5151

5252

53+
class SourceContact(Base):
54+
55+
__tablename__ = "source_contact"
56+
__table_args__ = {"schema": "process_tracker"}
57+
58+
source_id = Column(
59+
Integer,
60+
ForeignKey("process_tracker.source_lkup.source_id"),
61+
nullable=False,
62+
primary_key=True,
63+
)
64+
contact_id = Column(
65+
Integer,
66+
ForeignKey("process_tracker.contact_lkup.contact_id"),
67+
nullable=False,
68+
primary_key=True,
69+
)
70+
71+
UniqueConstraint(source_id, contact_id)
72+
sources = relationship("Source")
73+
contacts = relationship("Contact")
74+
75+
5376
class SourceDatasetType(Base):
5477

5578
__tablename__ = "source_dataset_type"

process_tracker/utilities/data_store.py

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from process_tracker.models.model_base import Base
1313
from process_tracker.models.actor import Actor
1414
from process_tracker.models.capacity import Cluster, ClusterProcess
15+
from process_tracker.models.contact import Contact
1516
from process_tracker.models.extract import ExtractStatus
1617
from process_tracker.models.process import (
1718
ErrorType,
@@ -198,6 +199,7 @@ def topic_creator(
198199
max_memory=None,
199200
memory_unit=None,
200201
cluster=None,
202+
email=None,
201203
):
202204
"""
203205
For the command line tool, validate the topic and create the new instance.
@@ -220,6 +222,8 @@ def topic_creator(
220222
:type memory_unit: string
221223
:param cluster: For cluster/process relationships, the name of the cluster.
222224
:type cluster: string
225+
:param email: For contacts, the contact's email address
226+
:type email: string
223227
:return:
224228
"""
225229
self.logger.info("Attempting to create %s item: %s" % (topic, name))
@@ -230,6 +234,12 @@ def topic_creator(
230234
item = self.get_or_create_item(model=Actor, actor_name=name)
231235
self.logger.info("Actor created: %s" % item.__repr__)
232236

237+
elif topic == "contact":
238+
item = self.get_or_create_item(
239+
model=Contact, contact_name=name, contact_email=email
240+
)
241+
self.logger.info("Contact created: %s" % item.__repr__)
242+
233243
elif topic == "cluster":
234244
item = self.get_or_create_item(
235245
model=Cluster,
@@ -257,16 +267,16 @@ def topic_creator(
257267

258268
self.logger.info("Cluster Process created: %s" % item.__repr__)
259269

270+
elif topic == "error type":
271+
item = self.get_or_create_item(model=ErrorType, error_type_name=name)
272+
self.logger.info("Error Type created: %s" % item.__repr__)
273+
260274
elif topic == "extract status":
261275
item = self.get_or_create_item(
262276
model=ExtractStatus, extract_status_name=name
263277
)
264278
self.logger.info("Extract Status created: %s" % item.__repr__)
265279

266-
elif topic == "error type":
267-
item = self.get_or_create_item(model=ErrorType, error_type_name=name)
268-
self.logger.info("Error Type created: %s" % item.__repr__)
269-
270280
elif topic == "process dependency":
271281
parent_process = self.get_or_create_item(
272282
model=Process, process_name=parent, create=False
@@ -283,18 +293,18 @@ def topic_creator(
283293

284294
self.logger.info("Process Dependency created: %s" % item.__repr__)
285295

286-
elif topic == "process type":
287-
item = self.get_or_create_item(
288-
model=ProcessType, process_type_name=name
289-
)
290-
self.logger.info("Process Type created: %s" % item.__repr__)
291-
292296
elif topic == "process status":
293297
item = self.get_or_create_item(
294298
model=ProcessStatus, process_status_name=name
295299
)
296300
self.logger.info("Process Status created: %s" % item.__repr__)
297301

302+
elif topic == "process type":
303+
item = self.get_or_create_item(
304+
model=ProcessType, process_type_name=name
305+
)
306+
self.logger.info("Process Type created: %s" % item.__repr__)
307+
298308
elif topic == "source":
299309
item = self.get_or_create_item(model=Source, source_name=name)
300310
self.logger.info("Source created: %s" % item.__repr__)
@@ -339,6 +349,13 @@ def topic_deleter(self, topic, name, parent=None, child=None, cluster=None):
339349
self.session.query(Actor).filter(Actor.actor_name == name).delete()
340350
self.logger.info("%s %s deleted." % (topic, name))
341351

352+
elif topic == "contact":
353+
item_delete = True
354+
self.session.query(Contact).filter(
355+
Contact.contact_name == name
356+
).delete()
357+
self.logger.info("%s %s deleted." % (topic, name))
358+
342359
elif topic == "cluster":
343360
item_delete = True
344361
self.session.query(Cluster).filter(
@@ -448,6 +465,7 @@ def topic_updater(
448465
processing_unit=None,
449466
max_memory=None,
450467
memory_unit=None,
468+
email=None,
451469
):
452470
"""
453471
For the command line tool, validate that the topic name is not a default value and if not, update it.
@@ -465,6 +483,8 @@ def topic_updater(
465483
:type processing_unit: string
466484
:param memory_unit: For performance clusters, the unit of allocated memory to the cluster
467485
:type memory_unit: string
486+
:param email: For contacts, the contact's email address
487+
:type email: string
468488
:return:
469489
"""
470490
if self.topic_validator(topic=topic):
@@ -475,6 +495,17 @@ def topic_updater(
475495
item.actor_name = name
476496
self.logger.info("%s %s updated." % (topic, name))
477497

498+
elif topic == "contact":
499+
item = self.get_or_create_item(
500+
model=Contact, create=False, contact_name=initial_name
501+
)
502+
503+
item.contact_name = name
504+
505+
if email is not None:
506+
item.contact_email = email
507+
self.logger.info("%s %s updated." % (topic, name))
508+
478509
elif topic == "cluster":
479510
item = self.get_or_create_item(
480511
model=Cluster, create=False, cluster_name=initial_name
@@ -615,13 +646,15 @@ def topic_validator(self, topic):
615646
"actor",
616647
"cluster",
617648
"cluster process",
649+
"contact",
618650
"error type",
619651
"extract status",
620652
"process dependency",
621653
"process run",
622654
"process status",
623655
"process type",
624656
"source",
657+
"source contact",
625658
"tool",
626659
]
627660

0 commit comments

Comments
 (0)