Skip to content
Snippets Groups Projects
Commit 5849def3 authored by Francesco Siddi's avatar Francesco Siddi
Browse files

Merge pull request #39 from fsiddi/pr/38

Pr/38
parents 81bfea62 d1d2e6b3
No related branches found
No related tags found
No related merge requests found
......@@ -9,3 +9,5 @@
venv/
*.log
.ropeproject/*
config.py
!*/config.py
brender.py 100644 → 100755
#!/usr/bin/python
#!/usr/bin/env python
import sys
import os
from threading import Thread
......@@ -6,51 +6,32 @@ import socket
import time
import subprocess
try:
import config
print('[Info] Loading configuration from config.py')
Server = config.Server
Dashboard = config.Dashboard
Worker = config.Worker
except ImportError:
print('[Warning] No configuration file were found! Unsing default config settings.')
print('[Warning] For more info see config.py.example file o README file.')
Server = None
Dashboard = None
Worker = None
if len(sys.argv) < 2:
sys.exit('Usage: %s component-name (i.e. server, dashboard or worker)' % sys.argv[0])
elif (sys.argv[1] == 'worker'):
print 'running worker'
"""
# this is going to be an HTTP request to the server with all the info
# for registering the render node
def register_worker():
import httplib
while True:
try:
connection = httplib.HTTPConnection('127.0.0.1', PORT)
connection.request("GET", "/info")
break
except socket.error:
pass
time.sleep(0.1)
http_request('connect', {'mac_address': MAC_ADDRESS,
'port': PORT,
'hostname': HOSTNAME,
'system': SYSTEM})
"""
from worker import start_worker
"""
if os.environ.get('WERKZEUG_RUN_MAIN') != 'true':
register_thread = Thread(target=register_worker)
register_thread.setDaemon(False)
register_thread.start()
app.run(host='0.0.0.0')
"""
start_worker()
import worker
worker.serve(Worker)
elif (sys.argv[1] == 'dashboard'):
print 'running dashboard'
from dashboard import app
app.run(host='0.0.0.0')
import dashboard
dashboard.serve(Dashboard)
elif (sys.argv[1] == 'server'):
print 'running server'
from server import app
app.run(host='0.0.0.0')
import server
server.serve(Server)
else:
sys.exit('Usage: %s component-name (i.e. server, dashboard or worker)' % sys.argv[0])
#from server import app
#from server import db
#db.create_all()
#app.run()
sys.exit('Usage: %s component-name (i.e. server, dashboard or worker)' % sys.argv[0])
\ No newline at end of file
import os
class Config(object):
DATABASE=os.path.join(os.path.dirname(__file__), 'server', 'brender.sqlite')
DEBUG=False
BRENDER_SERVER='localhost:9999'
class Server(Config):
DEBUG=True
PORT=9999
HOST='localhost'
class Dashboard(Config):
DEBUG=True
PORT=8888
HOST='localhost'
class Worker(Config):
DEBUG=True
PORT=5000
# worker will accept request based on IP (because of his registration process to server)
# use HOST='0.0.0.0' to enable worker to serve on all IP when use it in a cluster
HOST='127.0.0.1'
from flask import Flask
app = Flask(__name__)
from dashboard import controllers
app.config.update(
controllers.app.config.update(
SECRET_KEY='A0Zr98j/3yX R~XHH!jmN]LWX/,?RT',
DEBUG=True,
SERVER_NAME='brender-flask:8888'
DEBUG=False,
HOST='localhost',
PORT=8888,
BRENDER_SERVER='localhost:9999'
)
from dashboard import controllers
def serve(user_config=None):
config = controllers.app.config
if user_config:
config.from_object(user_config)
config.update(
SERVER_NAME="%s:%s" % (config['HOST'], config['PORT'])
)
controllers.BRENDER_SERVER = config['BRENDER_SERVER']
controllers.app.run(config['HOST'], config['PORT'])
from dashboard import app
import glob
import json
import os
......@@ -16,7 +15,10 @@ from flask import (flash,
url_for,
make_response)
BRENDER_SERVER = 'brender-server:9999'
app = Flask(__name__)
# TODO: find a better way to fill/use this variable
BRENDER_SERVER = ''
def http_request(ip_address, method, post_params=False):
# post_params must be a dictionnary
......
import urllib
import time
from flask import Flask, render_template, jsonify, redirect, url_for, request
from model import *
from modules.jobs import jobs_module
from modules.workers import workers_module
from modules.shots import shots_module
from modules.shows import shows_module
from modules.settings import settings_module
from modules.stats import stats_module
from server import controllers
import model
import os
app = Flask(__name__)
app.config.update(
DEBUG=True,
SERVER_NAME='brender-server:9999'
# This is the default server configuration, in case the user will not provide one.
# The Application is configured to run on local-host and port 9999
# The brender.sqlite database will be created inside of the server folder
controllers.app.config.update(
DEBUG=False,
HOST='localhost',
PORT=9999,
DATABASE=os.path.join(os.path.dirname(controllers.__file__), 'brender.sqlite')
)
from server import controllers
def serve(user_config=None):
config = controllers.app.config
if user_config:
config.from_object(user_config)
model.DATABASE = config['DATABASE']
model.create_database()
# Set SEVER_NAME value according to application configuration
config.update(
SERVER_NAME="%s:%d" % (config['HOST'], config['PORT'])
)
app.register_blueprint(workers_module)
app.register_blueprint(jobs_module)
app.register_blueprint(shots_module)
app.register_blueprint(shows_module)
app.register_blueprint(settings_module)
app.register_blueprint(stats_module)
\ No newline at end of file
#controllers.app.run(host='0.0.0.0')
# Run application
controllers.app.run(
controllers.app.config['HOST'],
controllers.app.config['PORT'],
)
from server import app
from server import render_template, jsonify, redirect, url_for, request
from model import *
from modules.jobs import jobs_module
from modules.workers import workers_module
from modules.shots import shots_module
from modules.shows import shows_module
from modules.settings import settings_module
from modules.stats import stats_module
from flask import Flask, render_template, jsonify, redirect, url_for, request
app = Flask(__name__)
@app.route('/')
def index():
#add_random_workers(2)
......@@ -65,3 +73,10 @@ def connect():
# the code below is executed if the request method
# was GET or the credentials were invalid
return jsonify(error=error)
app.register_blueprint(workers_module)
app.register_blueprint(jobs_module)
app.register_blueprint(shots_module)
app.register_blueprint(shows_module)
app.register_blueprint(settings_module)
app.register_blueprint(stats_module)
from peewee import *
from datetime import date
import random
DATABASE = 'server/brender.sqlite'
DATABASE = None
db = SqliteDatabase(DATABASE)
......@@ -143,12 +143,12 @@ def create_database():
"""
try:
with open(DATABASE):
pass
# connect to database found in DATABASE
db.init(DATABASE)
except IOError:
print('[Info] Creating brender.sqlite database')
open(DATABASE, 'a').close()
# before creating tables we should connect to it
db.init(DATABASE)
create_tables()
print('[Info] Database created')
create_database()
import socket
import urllib
import time
import sys
import subprocess
import platform
import flask
import os
import select
from threading import Thread
from flask import Flask, redirect, url_for, request, jsonify
from uuid import getnode as get_mac_address
from worker import controllers
BRENDER_SERVER = 'http://brender-server:9999'
MAC_ADDRESS = get_mac_address() # the MAC address of the worker
HOSTNAME = socket.gethostname() # the hostname of the worker
SYSTEM = platform.system() + ' ' + platform.release()
PORT = 5000
app = Flask(__name__)
app.config.update(
DEBUG=True,
controllers.app.config.update(
DEBUG=False,
HOST='127.0.0.1',
PORT=5000,
BRENDER_SERVER='localhost:9999'
)
def http_request(command, values):
params = urllib.urlencode(values)
try:
urllib.urlopen(BRENDER_SERVER + '/' + command, params)
#print(f.read())
except IOError:
print("[Warning] Could not connect to server to register")
# this is going to be an HTTP request to the server with all the info
# for registering the render node
def register_worker():
import httplib
while True:
try:
connection = httplib.HTTPConnection('127.0.0.1', PORT)
connection.request("GET", "/info")
break
except socket.error:
pass
time.sleep(0.1)
# Use muliprocessing to register the client the worker to the server
# while the worker app starts up
def serve(user_config=None):
config = controllers.app.config
http_request('connect', {'mac_address': MAC_ADDRESS,
'port': PORT,
'hostname': HOSTNAME,
'system': SYSTEM})
if user_config:
config.from_object(user_config)
config.update(
SERVER_NAME="%s:%s" % (config['HOST'], config['PORT'])
)
controllers.BRENDER_SERVER = config['BRENDER_SERVER']
# we use muliprocessing to register the client the worker to the server
# while the worker app starts up
def start_worker():
if os.environ.get('WERKZEUG_RUN_MAIN') != 'true':
register_thread = Thread(target=register_worker)
register_thread = Thread(target=controllers.register_worker)
register_thread.setDaemon(False)
register_thread.start()
from worker import controllers
app.run(host='0.0.0.0')
controllers.app.run(config['HOST'], config['PORT'])
......@@ -13,13 +13,39 @@ from threading import Thread
from flask import Flask, redirect, url_for, request, jsonify
from uuid import getnode as get_mac_address
from worker import app
BRENDER_SERVER = 'http://brender-server:9999'
MAC_ADDRESS = get_mac_address() # the MAC address of the worker
HOSTNAME = socket.gethostname() # the hostname of the worker
SYSTEM = platform.system() + ' ' + platform.release()
app = Flask(__name__)
BRENDER_SERVER=''
def http_request(command, values):
params = urllib.urlencode(values)
try:
urllib.urlopen('http://' + BRENDER_SERVER + '/' + command, params)
#print(f.read())
except IOError:
print("[Warning] Could not connect to server to register")
# this is going to be an HTTP request to the server with all the info
# for registering the render node
def register_worker():
import httplib
while True:
try:
connection = httplib.HTTPConnection('127.0.0.1', app.config['PORT'])
connection.request("GET", "/info")
break
except socket.error:
pass
time.sleep(0.1)
http_request('connect', {'mac_address': MAC_ADDRESS,
'port': app.config['PORT'],
'hostname': HOSTNAME,
'system': SYSTEM})
def _checkProcessOutput(process):
ready = select.select([process.stdout.fileno(),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment