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

Remove etcd #7

Merged
merged 17 commits into from
Aug 26, 2019
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
d564bcb
removing subtree pull killrvideo_docker_common
jeffreyscarpenter Jun 26, 2019
9db9934
replacing hardcoded Kafka IP with environment variable
jeffreyscarpenter Jul 24, 2019
0701183
correcting default Kafka connection points - port not included
jeffreyscarpenter Jul 26, 2019
e63f4e4
converting most configuration to environment variables
jeffreyscarpenter Jul 26, 2019
c6e5282
updating version number
jeffreyscarpenter Jul 26, 2019
b2fa311
changing service port
jeffreyscarpenter Jul 26, 2019
45bc384
removing python-etcd library
jeffreyscarpenter Jul 26, 2019
952f854
creating both Cluster and Session inside retry loop
jeffreyscarpenter Jul 26, 2019
5cd42d9
removing docker-compose related files
jeffreyscarpenter Aug 9, 2019
562cd66
updating README to reflect updated instructions for running in Docker
jeffreyscarpenter Aug 9, 2019
1b0dea4
adding retry loop to check for schema creation, updating version to m…
jeffreyscarpenter Aug 14, 2019
88b9e7f
setting release candidate version
jeffreyscarpenter Aug 15, 2019
7f9af26
renaming environment variable to be more descriptive (KILLRVIDEO_KAFK…
jeffreyscarpenter Aug 16, 2019
68ff390
adding docker-compose files and removing VERSION file
jeffreyscarpenter Aug 22, 2019
139c67f
reminder to set environment variables
jeffreyscarpenter Aug 22, 2019
278485d
fixing backend-external configuration to run services outside of Docker
jeffreyscarpenter Aug 24, 2019
7c3b62a
usability improvement - added stop script for external backend config…
jeffreyscarpenter Aug 26, 2019
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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ WORKDIR /app

ENV PYTHONPATH "${PYTHONPATH}:/${WORKDIR}"

EXPOSE 8899
EXPOSE 50101

CMD ["python", "./__init__.py"]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Install and run:
* `python3 -m venv venv`
* `source venv/bin/activate`
* Run supporting infrastructure using Docker
* `./setup-docker.sh`
* `docker-compose up -d`
* See the instructions in the [killrvideo-docker-common][https://github.com/KillrVideo/killrvideo-docker-common] repository for running the supporting infrastructure
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Link is not rendered by github. I think the markdown is not correct here.
image

* The documentation describes an option to run the KillrVideo python services in a Docker container
* Run the Python KillrVideo services
* `python killrvideo/__init__.py`
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
DOCKER_BUILD_TAG=0.9.1
DOCKER_BUILD_TAG=3.0.1-rc1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't fully agree with this VERSION file approach. Imho, git tag is much more reliable and obvious source of truth. As long as you have both, you will have inconsistencies between them. Take a look at this:

  1. We take git tag as a source of truth: https://github.com/KillrVideo/killrvideo-dse-config/blob/master/.travis.yml#L15
  2. We take hardcoded data in a file as a source of truth https://github.com/KillrVideo/killrvideo-dse-config/blob/1a31a70883597d98b4f90a86986f782d5e3319b4/build/docker-build.sh#L5

It's just a question of time when someone (like me) will forget to update the version file and - ooops - we have a wrong image.

98 changes: 0 additions & 98 deletions docker-compose.yaml

This file was deleted.

59 changes: 24 additions & 35 deletions killrvideo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
from concurrent import futures
import grpc
import etcd
import time
import logging
import json
import os

from dse.cluster import Cluster, ExecutionProfile, EXEC_PROFILE_DEFAULT, EXEC_PROFILE_GRAPH_DEFAULT
from dse_graph import DseGraph
from dse.auth import PlainTextAuthProvider
from dse import ConsistencyLevel
from dse.auth import PlainTextAuthProvider
from dse.cluster import Cluster, ExecutionProfile, EXEC_PROFILE_DEFAULT, EXEC_PROFILE_GRAPH_DEFAULT, NoHostAvailable
from dse_graph import DseGraph
from dse.policies import TokenAwarePolicy, DCAwareRoundRobinPolicy
import dse.cqlengine.connection

Expand Down Expand Up @@ -37,28 +36,14 @@ def serve():

dse_username = os.getenv('KILLRVIDEO_DSE_USERNAME')
dse_password = os.getenv('KILLRVIDEO_DSE_PASSWORD')
dse_contact_points = os.getenv('KILLRVIDEO_DSE_CONTACT_POINTS', 'dse').split(',')
service_port = os.getenv('KILLRVIDEO_SERVICE_PORT', '50101')

file = open('config.json', 'r')
config = json.load(file)

service_port = config['SERVICE_PORT']
service_host = config['SERVICE_HOST']
etcd_port = config['ETCD_PORT']
contact_points = config['CONTACT_POINTS']
default_consistency_level = config['DEFAULT_CONSISTENCY_LEVEL']

service_address = service_host + ":" + str(service_port)
etcd_client = etcd.Client(host=service_host, port=etcd_port)

# Wait for Cassandra (DSE) to be up, aka registered in etcd
while True:
try:
etcd_client.read('/killrvideo/services/cassandra')
break # if we get here, Cassandra is registered and should be available
except etcd.EtcdKeyNotFound:
logging.info('Waiting for Cassandra to be registered in etcd, sleeping 10s')
time.sleep(10)

# Initialize Cassandra Driver and Mapper
load_balancing_policy = TokenAwarePolicy(DCAwareRoundRobinPolicy())
profile = ExecutionProfile(consistency_level=ConsistencyLevel.name_to_value[default_consistency_level],
Expand All @@ -69,11 +54,25 @@ def serve():
if dse_username:
auth_provider = PlainTextAuthProvider(username=dse_username, password=dse_password)

cluster = Cluster(contact_points=contact_points,
execution_profiles={EXEC_PROFILE_DEFAULT: profile, EXEC_PROFILE_GRAPH_DEFAULT: graph_profile},
auth_provider = auth_provider)
# Wait for Cassandra (DSE) to be up
session = None
while not session:
try:
session = Cluster(contact_points=dse_contact_points,
execution_profiles={EXEC_PROFILE_DEFAULT: profile, EXEC_PROFILE_GRAPH_DEFAULT: graph_profile},
auth_provider = auth_provider).connect("killrvideo")
except (NoHostAvailable):
logging.info('Waiting for Cassandra (DSE) to be available')
time.sleep(10)

# Additional retry loop to check if dummy keyspace exists
while True:
logging.info('Checking for schema to be created...')
result = session.execute('SELECT keyspace_name FROM system_schema.keyspaces WHERE keyspace_name=\'kv_init_done\'')
if result.one(): # any result indicates keyspace has been created
break
time.sleep(10)

session = cluster.connect("killrvideo")
dse.cqlengine.connection.set_session(session)

# Initialize GRPC Server
Expand All @@ -90,19 +89,9 @@ def serve():
VideoCatalogServiceServicer(grpc_server, VideoCatalogService(session=session))

# Start GRPC Server
grpc_server.add_insecure_port('[::]:' + str(service_port))
grpc_server.add_insecure_port('[::]:' + service_port)
grpc_server.start()

# Register Services with etcd
etcd_client.write('/killrvideo/services/CommentsService/killrvideo-python', service_address)
etcd_client.write('/killrvideo/services/RatingsService/killrvideo-python', service_address)
etcd_client.write('/killrvideo/services/SearchService/killrvideo-python', service_address)
etcd_client.write('/killrvideo/services/StatisticsService/killrvideo-python', service_address)
etcd_client.write('/killrvideo/services/SuggestedVideoService/killrvideo-python', service_address)
#etcd_client.write('/killrvideo/services/UploadsService/killrvideo-python', service_address)
etcd_client.write('/killrvideo/services/UserManagementService/killrvideo-python', service_address)
etcd_client.write('/killrvideo/services/VideoCatalogService/killrvideo-python', service_address)

# Keep application alive
try:
while True:
Expand Down
3 changes: 2 additions & 1 deletion killrvideo/comments/comments_events_kafka.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from kafka import KafkaProducer
from .comments_events_pb2 import UserCommentedOnVideo
from common.common_types_conversions import UUID_to_grpc, datetime_to_Timestamp, TimeUUID_to_grpc
Expand All @@ -8,7 +9,7 @@ class CommentsPublisher(object):
"""Provides methods that publish events associated with the Comments Service."""

def __init__(self):
self.producer = KafkaProducer(bootstrap_servers='10.0.75.1:9092',
self.producer = KafkaProducer(bootstrap_servers=os.getenv('KILLRVIDEO_KAFKA', 'kafka'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, KILLRVIDEO_KAFKA_HOST or anything like that? KILLRVIDEO_KAFKA doesn't sound obvious enough.

client_id='killrvideo-python:CommentsService')


Expand Down
4 changes: 0 additions & 4 deletions killrvideo/config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
{
"SERVICE_PORT": 8899,
"SERVICE_HOST": "10.0.75.1",
"ETCD_PORT": 2379,
"CONTACT_POINTS": ["10.0.75.1"],
"DEFAULT_CONSISTENCY_LEVEL": "LOCAL_QUORUM"
}
3 changes: 2 additions & 1 deletion killrvideo/ratings/ratings_events_kafka.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import os
from kafka import KafkaProducer
from .ratings_events_pb2 import UserRatedVideo
from common.common_types_conversions import UUID_to_grpc, grpc_to_UUID, datetime_to_Timestamp, Timestamp_to_datetime
Expand All @@ -9,7 +10,7 @@ class RatingPublisher(object):
"""Provides methods that publish events associated with the Ratings Service."""

def __init__(self):
self.producer = KafkaProducer(bootstrap_servers='10.0.75.1:9092',
self.producer = KafkaProducer(bootstrap_servers=os.getenv('KILLRVIDEO_KAFKA', 'kafka'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, KILLRVIDEO_KAFKA_HOST looks better imho.

client_id='killrvideo-python:RatingsService')


Expand Down
6 changes: 2 additions & 4 deletions killrvideo/suggested_videos/suggested_videos_events_kafka.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import os
import threading
from kafka import KafkaConsumer
from user_management.user_management_events_pb2 import UserCreated
Expand All @@ -10,16 +11,13 @@
USER_RATED_VIDEO_TOPIC = 'topic-kv-videoRating'
YOUTUBE_VIDEO_ADDED_TOPIC = 'topic-kv-videoCreation'

BOOTSTRAP_SERVERS = '10.0.75.1:9092'


class SuggestedVideoKafkaConsumer(threading.Thread):
def __init__(self, suggested_videos_consumer):
threading.Thread.__init__(self)
self.suggested_videos_consumer = suggested_videos_consumer

def run(self):
consumer = KafkaConsumer(bootstrap_servers=BOOTSTRAP_SERVERS,
consumer = KafkaConsumer(bootstrap_servers=os.getenv('KILLRVIDEO_KAFKA', 'kafka'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, KILLRVIDEO_KAFKA_HOST looks better imho.

client_id='killrvideo-python:SuggestedVideosService',
fetch_max_wait_ms=10000) # poll every 10 seconds for new events

Expand Down
3 changes: 2 additions & 1 deletion killrvideo/user_management/user_management_events_kafka.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import os
from kafka import KafkaProducer
from .user_management_events_pb2 import UserCreated
from common.common_types_conversions import UUID_to_grpc, datetime_to_Timestamp
Expand All @@ -9,7 +10,7 @@ class UserManagementPublisher(object):
"""Provides methods that publish events associated with the User Management Service."""

def __init__(self):
self.producer = KafkaProducer(bootstrap_servers='10.0.75.1:9092',
self.producer = KafkaProducer(bootstrap_servers=os.getenv('KILLRVIDEO_KAFKA', 'kafka'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, KILLRVIDEO_KAFKA_HOST looks better imho.

client_id='killrvideo-python:UserManagementService')


Expand Down
3 changes: 2 additions & 1 deletion killrvideo/video_catalog/video_catalog_events_kafka.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import os
from kafka import KafkaProducer
from .video_catalog_events_pb2 import YouTubeVideoAdded
from common.common_types_conversions import UUID_to_grpc, datetime_to_Timestamp
Expand All @@ -9,7 +10,7 @@ class VideoCatalogPublisher(object):
"""Provides methods that publish events associated with the Video Catalog Service."""

def __init__(self):
self.producer = KafkaProducer(bootstrap_servers='10.0.75.1:9092',
self.producer = KafkaProducer(bootstrap_servers=os.getenv('KILLRVIDEO_KAFKA', 'kafka'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, KILLRVIDEO_KAFKA_HOST looks better imho.

client_id='killrvideo-python:VideoCatalogService')


Expand Down
4 changes: 0 additions & 4 deletions lib/killrvideo-docker-common/.gitignore

This file was deleted.

Loading