Skip to content

Commit

Permalink
Merge pull request #30 from SivaMaplelabs/pylint-fix
Browse files Browse the repository at this point in the history
Address the pylint warnings
  • Loading branch information
91pavan authored Sep 6, 2018
2 parents 464b7b6 + d457a88 commit d52fa1a
Showing 1 changed file with 43 additions and 39 deletions.
82 changes: 43 additions & 39 deletions scripts/components/files/producer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=line-too-long
"""
Name: Sample python code for Kafka Client
Purpose: Producing messages to Kafka topics
Expand All @@ -20,67 +21,70 @@
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied.
"""

import io
import sys, getopt, time
import datetime
import avro.schema
import avro.io
# pylint: disable=import-error
import sys
import getopt
import time
import random
from kafka import KafkaProducer
import ssl
import json
import avro.schema
import avro.io
from kafka import KafkaProducer

# Path to user.avsc avro schema
schema_path="/opt/pnda/dataplatform-raw.avsc"
# pylint: disable=invalid-name
schema_path = "/opt/pnda/dataplatform-raw.avsc"

# Kafka topic
topic = "raw.log.localtest"
schema = avro.schema.parse(open(schema_path).read())

extra=False
loopMode=False
rangeValue=1
sslEnable=False
extra = False
loopMode = False
rangeValue = 1
sslEnable = False

current_milli_time = lambda: int(round(time.time() * 1000))

# pylint: disable=superfluous-parens
try:
opts, args = getopt.getopt(sys.argv[1:],"he:lz",["extra=", "loop="])
opts, args = getopt.getopt(sys.argv[1:], "he:lz", ["extra=", "loop="])
except getopt.GetoptError:
print('producer.py [-e true] [-l true] [-z]')
sys.exit(2)

for opt, arg in opts:
if opt == '-h':
print('producer.py [-e true] [-l true]')
sys.exit()
elif opt in ("-e", "--extra"):
print("extra header requested")
extra = True
elif opt in ("-l", "--loop"):
print("loop mode")
loopMode = True
rangeValue=1000
elif opt in ("-z"):
sslEnable=True
if opt == '-h':
print('producer.py [-e true] [-l true]')
sys.exit()
elif opt in ("-e", "--extra"):
print("extra header requested")
extra = True
elif opt in ("-l", "--loop"):
print("loop mode")
loopMode = True
rangeValue = 1000
elif opt in ("-z"):
sslEnable = True

extrabytes = bytes('')

# pylint: disable=no-member
if sslEnable:
print("setting up SSL to PROTOCOL_TLSv1")
ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
ctx.load_cert_chain(certfile="../ca-cert", keyfile="../ca-key", password="test1234")
producer = KafkaProducer(bootstrap_servers=["ip6-localhost:9093"],security_protocol="SASL_SSL",\
ssl_context=ctx,\
sasl_mechanism="PLAIN",sasl_plain_username="test",sasl_plain_password="test")
print("setting up SSL to PROTOCOL_TLSv1")
ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
ctx.load_cert_chain(certfile="../ca-cert", keyfile="../ca-key", password="test1234")
producer = KafkaProducer(bootstrap_servers=["ip6-localhost:9093"], security_protocol="SASL_SSL",\
ssl_context=ctx,\
sasl_mechanism="PLAIN", sasl_plain_username="test", sasl_plain_password="test")
else:
producer = KafkaProducer(bootstrap_servers=["localhost:9092"])

producer = KafkaProducer(bootstrap_servers=["localhost:9092"])

for i in xrange(rangeValue):
#Prepare our msg data
rawvarie="python-random-"+str(random.randint(10,10000))+"-loop-"+str(i)
data = {"timestamp": current_milli_time(), "src": "ESC", "host_ip": "my_ipv6", "rawdata": rawvarie}
producer.send(topic, json.dumps(data))
if rangeValue > 1:
time.sleep(0.5)
#Prepare our msg data
rawvarie = "python-random-"+str(random.randint(10, 10000))+"-loop-"+str(i)
data = {"timestamp": current_milli_time(), "src": "ESC", "host_ip": "my_ipv6", "rawdata": rawvarie}
producer.send(topic, json.dumps(data))
if rangeValue > 1:
time.sleep(0.5)

0 comments on commit d52fa1a

Please sign in to comment.