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
|
||||
import logging
|
||||
from flask import Flask
|
||||
from flask_restful import Api
|
||||
import sentry_sdk
|
||||
@ -8,8 +7,7 @@ from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration
|
||||
from healthcheck import HealthCheck
|
||||
|
||||
from errorhandlers import register_all_error_handlers
|
||||
from config import SENTRY_DSN, RELEASE_ID, RELEASEMODE, POSTGRES_DB, PORT, POSTGRES_HOSTNAME, POSTGRES_PASSWORD, \
|
||||
POSTGRES_USERNAME, DEBUG, JWT_SECRET_KEY
|
||||
from config import SENTRY_DSN, RELEASE_ID, RELEASEMODE, SQLALCHEMY_DATABASE_URI, JWT_SECRET_KEY
|
||||
from db import db
|
||||
from jwtman import jwtman
|
||||
from fbcrypt import bcrypt
|
||||
@ -40,8 +38,7 @@ if SENTRY_DSN:
|
||||
)
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = \
|
||||
f"postgresql://{POSTGRES_USERNAME}:{POSTGRES_PASSWORD}@{POSTGRES_HOSTNAME}:5432/{POSTGRES_DB}"
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = SQLALCHEMY_DATABASE_URI
|
||||
app.config['JWT_SECRET_KEY'] = JWT_SECRET_KEY
|
||||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
||||
|
||||
@ -52,17 +49,6 @@ ma.init_app(app)
|
||||
bcrypt.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(SignupApi, '/api/auth/signup')
|
||||
api.add_resource(LoginApi, '/api/auth/login')
|
||||
@ -86,11 +72,3 @@ register_all_error_handlers(app)
|
||||
@app.before_first_request
|
||||
def init_db():
|
||||
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"
|
||||
|
||||
|
||||
PORT = os.environ.get("VIDEON_PORT", 8080)
|
||||
DEBUG = os.environ.get("VIDEON_DEBUG", True)
|
||||
|
||||
|
||||
SENTRY_DSN = os.environ.get("SENTRY_DSN")
|
||||
RELEASE_ID = os.environ.get("RELEASE_ID", "test")
|
||||
RELEASEMODE = os.environ.get("VIDEON_RELEASEMODE", "dev")
|
||||
|
||||
POSTGRES_HOSTNAME = os.getenv("VIDEON_POSTGRES_HOSTNAME", "localhost")
|
||||
POSTGRES_USERNAME = os.getenv("VIDEON_POSTGRES_USERNAME", "videon")
|
||||
POSTGRES_PASSWORD = os.getenv("VIDEON_POSTGRES_PASSWORD", "videon")
|
||||
POSTGRES_DB = os.getenv("VIDEON_POSTGRES_DB", "videon")
|
||||
SQLALCHEMY_DATABASE_URI = os.getenv("SQLALCHEMY_DATABASE_URI", "sqlite://")
|
||||
|
||||
JWT_SECRET_KEY = os.getenv("VIDEON_POSTGRES_DB", str(uuid4()))
|
||||
|
||||
|
@ -40,7 +40,19 @@ class Kubectl:
|
||||
data={"TYPE": self.streamtype, "STREAM_KEY": self.stream_key,
|
||||
"PUSH_URLS": self.push_urls, "FFMPEG_ARGS": self.ffmpeg_args,
|
||||
"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):
|
||||
envs = [client.V1EnvFromSource(config_map_ref=client.V1ConfigMapEnvSource(name=self.name))]
|
||||
@ -87,7 +99,7 @@ class Kubectl:
|
||||
)
|
||||
)
|
||||
# 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):
|
||||
self.__create_configmap()
|
||||
@ -97,3 +109,8 @@ class Kubectl:
|
||||
def update_resource(self):
|
||||
self.__update_configmap()
|
||||
self.__delete_pod()
|
||||
|
||||
def delete_resource(self):
|
||||
self.__delete_deployment()
|
||||
self.__delete_configmap()
|
||||
self.__delete_service()
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
from uuid import UUID,uuid4
|
||||
from uuid import UUID, uuid4
|
||||
import datetime
|
||||
|
||||
from flask_jwt_extended import create_access_token, jwt_required, get_jwt_identity
|
||||
@ -12,6 +12,7 @@ from schemas import UserSchema, UserMetadataSchema, StreamResourceSchema, Ingest
|
||||
RestreamInputSchema
|
||||
from config import REGISTER_DISABLED
|
||||
import listdiffer
|
||||
from kuberclient import Kubectl
|
||||
|
||||
"""
|
||||
Flask Restful endpoints
|
||||
@ -186,6 +187,7 @@ class CreateIngestResource(Resource):
|
||||
ingest.stream_key = str(uuid4())
|
||||
try:
|
||||
db.session.add(ingest)
|
||||
Kubectl(name=ingest.id, resourcetype="ingest", stream_key=ingest.stream_key).create_resource()
|
||||
except Exception as e:
|
||||
current_app.logger.warning(e)
|
||||
abort(503, "object already exists")
|
||||
@ -234,7 +236,8 @@ class CreateRestreamResource(Resource):
|
||||
restream.parent_id = restreamobj['inputNeighbour']
|
||||
try:
|
||||
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:
|
||||
current_app.logger.warning(e)
|
||||
abort(503, "object already exists")
|
||||
@ -289,6 +292,8 @@ class CreateEncodeResource(Resource):
|
||||
|
||||
try:
|
||||
db.session.add(encoder)
|
||||
Kubectl(name=encoder.id, resourcetype="encoder",
|
||||
stream_key=encoder.stream_key).create_resource()
|
||||
except Exception as e:
|
||||
current_app.logger.warning(e)
|
||||
abort(503, "object already exists")
|
||||
@ -341,6 +346,7 @@ class ManipulateStreamResource(Resource):
|
||||
|
||||
try:
|
||||
db.session.delete(streamreousrce)
|
||||
Kubectl(name=streamreousrce.id, resourcetype=streamreousrce.resource_type).delete_resource()
|
||||
except Exception as e:
|
||||
current_app.logger.exception(e)
|
||||
abort(503, DB_ERROR_MSG)
|
||||
@ -393,6 +399,7 @@ class ModifyIngressResource(Resource):
|
||||
current_app.logger.warning(e)
|
||||
abort(503, "could not remove neighbourhood")
|
||||
else:
|
||||
Kubectl(name=ingest.id, resourcetype="ingest", stream_key=ingest.stream_key).update_resource()
|
||||
if currentoutputneighbours:
|
||||
for currentneighbour in currentoutputneighbours:
|
||||
try:
|
||||
@ -453,6 +460,10 @@ class ModifyRestreamResource(Resource):
|
||||
current_app.logger.warning(e)
|
||||
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()
|
||||
return self.streamresourceschema.dump(restream), 200
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user