This commit is contained in:
parent
5e541640c1
commit
6404fccc8f
26
src/app.py
26
src/app.py
@ -1,5 +1,4 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import logging
|
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
from flask_restful import Api
|
from flask_restful import Api
|
||||||
import sentry_sdk
|
import sentry_sdk
|
||||||
@ -8,8 +7,7 @@ from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration
|
|||||||
from healthcheck import HealthCheck
|
from healthcheck import HealthCheck
|
||||||
|
|
||||||
from errorhandlers import register_all_error_handlers
|
from errorhandlers import register_all_error_handlers
|
||||||
from config import SENTRY_DSN, RELEASE_ID, RELEASEMODE, POSTGRES_DB, PORT, POSTGRES_HOSTNAME, POSTGRES_PASSWORD, \
|
from config import SENTRY_DSN, RELEASE_ID, RELEASEMODE, SQLALCHEMY_DATABASE_URI, JWT_SECRET_KEY
|
||||||
POSTGRES_USERNAME, DEBUG, JWT_SECRET_KEY
|
|
||||||
from db import db
|
from db import db
|
||||||
from jwtman import jwtman
|
from jwtman import jwtman
|
||||||
from fbcrypt import bcrypt
|
from fbcrypt import bcrypt
|
||||||
@ -40,8 +38,7 @@ if SENTRY_DSN:
|
|||||||
)
|
)
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config['SQLALCHEMY_DATABASE_URI'] = \
|
app.config['SQLALCHEMY_DATABASE_URI'] = SQLALCHEMY_DATABASE_URI
|
||||||
f"postgresql://{POSTGRES_USERNAME}:{POSTGRES_PASSWORD}@{POSTGRES_HOSTNAME}:5432/{POSTGRES_DB}"
|
|
||||||
app.config['JWT_SECRET_KEY'] = JWT_SECRET_KEY
|
app.config['JWT_SECRET_KEY'] = JWT_SECRET_KEY
|
||||||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
||||||
|
|
||||||
@ -52,17 +49,6 @@ ma.init_app(app)
|
|||||||
bcrypt.init_app(app)
|
bcrypt.init_app(app)
|
||||||
jwtman.init_app(app)
|
jwtman.init_app(app)
|
||||||
|
|
||||||
formatter = logging.Formatter(
|
|
||||||
fmt="%(asctime)s - %(levelname)s - %(module)s - %(message)s"
|
|
||||||
)
|
|
||||||
|
|
||||||
handler = logging.StreamHandler()
|
|
||||||
handler.setFormatter(formatter)
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
logger.setLevel(logging.DEBUG)
|
|
||||||
logger.addHandler(handler)
|
|
||||||
|
|
||||||
# api.add_resource(SampleResource, "/sample")
|
# api.add_resource(SampleResource, "/sample")
|
||||||
api.add_resource(SignupApi, '/api/auth/signup')
|
api.add_resource(SignupApi, '/api/auth/signup')
|
||||||
api.add_resource(LoginApi, '/api/auth/login')
|
api.add_resource(LoginApi, '/api/auth/login')
|
||||||
@ -86,11 +72,3 @@ register_all_error_handlers(app)
|
|||||||
@app.before_first_request
|
@app.before_first_request
|
||||||
def init_db():
|
def init_db():
|
||||||
db.create_all()
|
db.create_all()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
app.run(
|
|
||||||
debug=bool(DEBUG),
|
|
||||||
host="0.0.0.0",
|
|
||||||
port=int(PORT),
|
|
||||||
)
|
|
||||||
|
@ -13,18 +13,11 @@ __module_name__ = "config"
|
|||||||
__version__text__ = "1"
|
__version__text__ = "1"
|
||||||
|
|
||||||
|
|
||||||
PORT = os.environ.get("VIDEON_PORT", 8080)
|
|
||||||
DEBUG = os.environ.get("VIDEON_DEBUG", True)
|
|
||||||
|
|
||||||
|
|
||||||
SENTRY_DSN = os.environ.get("SENTRY_DSN")
|
SENTRY_DSN = os.environ.get("SENTRY_DSN")
|
||||||
RELEASE_ID = os.environ.get("RELEASE_ID", "test")
|
RELEASE_ID = os.environ.get("RELEASE_ID", "test")
|
||||||
RELEASEMODE = os.environ.get("VIDEON_RELEASEMODE", "dev")
|
RELEASEMODE = os.environ.get("VIDEON_RELEASEMODE", "dev")
|
||||||
|
|
||||||
POSTGRES_HOSTNAME = os.getenv("VIDEON_POSTGRES_HOSTNAME", "localhost")
|
SQLALCHEMY_DATABASE_URI = os.getenv("SQLALCHEMY_DATABASE_URI", "sqlite://")
|
||||||
POSTGRES_USERNAME = os.getenv("VIDEON_POSTGRES_USERNAME", "videon")
|
|
||||||
POSTGRES_PASSWORD = os.getenv("VIDEON_POSTGRES_PASSWORD", "videon")
|
|
||||||
POSTGRES_DB = os.getenv("VIDEON_POSTGRES_DB", "videon")
|
|
||||||
|
|
||||||
JWT_SECRET_KEY = os.getenv("VIDEON_POSTGRES_DB", str(uuid4()))
|
JWT_SECRET_KEY = os.getenv("VIDEON_POSTGRES_DB", str(uuid4()))
|
||||||
|
|
||||||
|
@ -42,6 +42,18 @@ class Kubectl:
|
|||||||
"ENCODE_PUSH_URL": self.encode_push_url})
|
"ENCODE_PUSH_URL": self.encode_push_url})
|
||||||
client.CoreV1Api().patch_namespaced_config_map(namespace="videon", name=self.name, body=configmap)
|
client.CoreV1Api().patch_namespaced_config_map(namespace="videon", name=self.name, body=configmap)
|
||||||
|
|
||||||
|
def __delete_configmap(self):
|
||||||
|
client.CoreV1Api().delete_namespaced_config_map(namespace="videon", name=self.name)
|
||||||
|
|
||||||
|
def __delete_service(self):
|
||||||
|
client.CoreV1Api().delete_namespaced_service(namespace="videon", name=self.name)
|
||||||
|
|
||||||
|
def __delete_deployment(self):
|
||||||
|
client.ExtensionsV1beta1Api().delete_namespaced_deployment(name=self.name, namespace="videon",
|
||||||
|
body=client.V1DeleteOptions(
|
||||||
|
propagation_policy="Foreground",
|
||||||
|
grace_period_seconds=5))
|
||||||
|
|
||||||
def __create_deployment(self):
|
def __create_deployment(self):
|
||||||
envs = [client.V1EnvFromSource(config_map_ref=client.V1ConfigMapEnvSource(name=self.name))]
|
envs = [client.V1EnvFromSource(config_map_ref=client.V1ConfigMapEnvSource(name=self.name))]
|
||||||
container = client.V1Container(
|
container = client.V1Container(
|
||||||
@ -87,7 +99,7 @@ class Kubectl:
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
# Creation of the Service in specified namespace
|
# Creation of the Service in specified namespace
|
||||||
core_v1_api.create_namespaced_service(namespace="videon", body=body)
|
core_v1_api.create_namespaced_service(namespace="videon", body=body, name=self.name)
|
||||||
|
|
||||||
def create_resource(self):
|
def create_resource(self):
|
||||||
self.__create_configmap()
|
self.__create_configmap()
|
||||||
@ -97,3 +109,8 @@ class Kubectl:
|
|||||||
def update_resource(self):
|
def update_resource(self):
|
||||||
self.__update_configmap()
|
self.__update_configmap()
|
||||||
self.__delete_pod()
|
self.__delete_pod()
|
||||||
|
|
||||||
|
def delete_resource(self):
|
||||||
|
self.__delete_deployment()
|
||||||
|
self.__delete_configmap()
|
||||||
|
self.__delete_service()
|
||||||
|
@ -12,6 +12,7 @@ from schemas import UserSchema, UserMetadataSchema, StreamResourceSchema, Ingest
|
|||||||
RestreamInputSchema
|
RestreamInputSchema
|
||||||
from config import REGISTER_DISABLED
|
from config import REGISTER_DISABLED
|
||||||
import listdiffer
|
import listdiffer
|
||||||
|
from kuberclient import Kubectl
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Flask Restful endpoints
|
Flask Restful endpoints
|
||||||
@ -186,6 +187,7 @@ class CreateIngestResource(Resource):
|
|||||||
ingest.stream_key = str(uuid4())
|
ingest.stream_key = str(uuid4())
|
||||||
try:
|
try:
|
||||||
db.session.add(ingest)
|
db.session.add(ingest)
|
||||||
|
Kubectl(name=ingest.id, resourcetype="ingest", stream_key=ingest.stream_key).create_resource()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
current_app.logger.warning(e)
|
current_app.logger.warning(e)
|
||||||
abort(503, "object already exists")
|
abort(503, "object already exists")
|
||||||
@ -234,7 +236,8 @@ class CreateRestreamResource(Resource):
|
|||||||
restream.parent_id = restreamobj['inputNeighbour']
|
restream.parent_id = restreamobj['inputNeighbour']
|
||||||
try:
|
try:
|
||||||
db.session.add(restream)
|
db.session.add(restream)
|
||||||
db.session.commit()
|
Kubectl(name=restream.id, resourcetype="restream",
|
||||||
|
stream_key=restream.stream_key, push_urls=restreamobj['outputURLs']).create_resource()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
current_app.logger.warning(e)
|
current_app.logger.warning(e)
|
||||||
abort(503, "object already exists")
|
abort(503, "object already exists")
|
||||||
@ -289,6 +292,8 @@ class CreateEncodeResource(Resource):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
db.session.add(encoder)
|
db.session.add(encoder)
|
||||||
|
Kubectl(name=encoder.id, resourcetype="encoder",
|
||||||
|
stream_key=encoder.stream_key).create_resource()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
current_app.logger.warning(e)
|
current_app.logger.warning(e)
|
||||||
abort(503, "object already exists")
|
abort(503, "object already exists")
|
||||||
@ -341,6 +346,7 @@ class ManipulateStreamResource(Resource):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
db.session.delete(streamreousrce)
|
db.session.delete(streamreousrce)
|
||||||
|
Kubectl(name=streamreousrce.id, resourcetype=streamreousrce.resource_type).delete_resource()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
current_app.logger.exception(e)
|
current_app.logger.exception(e)
|
||||||
abort(503, DB_ERROR_MSG)
|
abort(503, DB_ERROR_MSG)
|
||||||
@ -393,6 +399,7 @@ class ModifyIngressResource(Resource):
|
|||||||
current_app.logger.warning(e)
|
current_app.logger.warning(e)
|
||||||
abort(503, "could not remove neighbourhood")
|
abort(503, "could not remove neighbourhood")
|
||||||
else:
|
else:
|
||||||
|
Kubectl(name=ingest.id, resourcetype="ingest", stream_key=ingest.stream_key).update_resource()
|
||||||
if currentoutputneighbours:
|
if currentoutputneighbours:
|
||||||
for currentneighbour in currentoutputneighbours:
|
for currentneighbour in currentoutputneighbours:
|
||||||
try:
|
try:
|
||||||
@ -453,6 +460,10 @@ class ModifyRestreamResource(Resource):
|
|||||||
current_app.logger.warning(e)
|
current_app.logger.warning(e)
|
||||||
abort(503, "object already exists")
|
abort(503, "object already exists")
|
||||||
|
|
||||||
|
if currentoutputurlurls != restreamobj['outputURLs']:
|
||||||
|
Kubectl(name=restream.id, resourcetype="restream", stream_key=restream.stream_key,
|
||||||
|
push_urls=restreamobj['outputURLs']).update_resource()
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return self.streamresourceschema.dump(restream), 200
|
return self.streamresourceschema.dump(restream), 200
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user