First Commit with skeleton code 93/5093/1
authorRahul <r.banerji@samsung.com>
Tue, 10 Nov 2020 07:12:14 +0000 (07:12 +0000)
committerRahul <r.banerji@samsung.com>
Mon, 16 Nov 2020 06:31:39 +0000 (06:31 +0000)
Change-Id: I61a0d9607bc8f32c20efb415da399788c6c79c92
Signed-off-by: Rahul Banerji <r.banerji@samsung.com>
.gitattributes [new file with mode: 0644]
.gitignore [new file with mode: 0644]
Dockerfile [new file with mode: 0644]
LICENSE.txt [new file with mode: 0644]
resources/pod.yaml [new file with mode: 0644]
resources/test_route.rt [new file with mode: 0644]
setup.py [new file with mode: 0644]
src/__init__.py [new file with mode: 0644]
src/main.py [new file with mode: 0644]

diff --git a/.gitattributes b/.gitattributes
new file mode 100644 (file)
index 0000000..38b6a85
--- /dev/null
@@ -0,0 +1,21 @@
+# https://help.github.com/articles/dealing-with-line-endings/
+
+# Set the default behavior, in case people don't have core.autocrlf set.
+*        text=auto
+
+# Explicitly declare text files you want to always be normalized
+# and converted to native line endings on checkout.
+*.css    text
+*.htm    text diff=html
+*.html   text diff=html
+*.java   text diff=java
+*.js     text
+*.jsp    text
+*.less   text
+*.properties text
+*.sql    text
+*.xml    text
+
+# Denote all files that are truly binary and should not be modified.
+*.png binary
+*.jpg binary
diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..59135fc
--- /dev/null
@@ -0,0 +1,113 @@
+# misc cruft
+*.log
+log.txt
+rmr/*
+docs_and_diagrams/
+
+# documentation
+.tox
+docs/_build/
+
+# standard python ignore template
+.pytest_cache/
+xunit-results.xml
+.DS_Store
+# Byte-compiled / optimized / DLL files
+__pycache__/
+*.py[cod]
+*$py.class
+
+# C extensions
+*.so
+
+# Distribution / packaging
+.Python
+env/
+build/
+develop-eggs/
+dist/
+downloads/
+eggs/
+.eggs/
+lib/
+lib64/
+parts/
+sdist/
+var/
+*.egg-info/
+.installed.cfg
+*.egg
+
+# PyInstaller
+#  Usually these files are written by a python script from a template
+#  before PyInstaller builds the exe, so as to inject date/other infos into it.
+*.manifest
+*.spec
+
+# Installer logs
+pip-log.txt
+pip-delete-this-directory.txt
+
+# Unit test / coverage reports
+htmlcov/
+venv-tox/
+.tox/
+.coverage
+.coverage.*
+.cache
+nosetests.xml
+coverage.xml
+*,cover
+.hypothesis/
+
+# Translations
+*.mo
+*.pot
+
+# Django stuff:
+*.log
+local_settings.py
+
+# Flask stuff:
+instance/
+.webassets-cache
+
+# Scrapy stuff:
+.scrapy
+
+# Sphinx documentation
+docs/_build/
+
+# PyBuilder
+target/
+
+# IPython Notebook
+.ipynb_checkpoints
+
+# pyenv
+.python-version
+
+# celery beat schedule file
+celerybeat-schedule
+
+# dotenv
+.env
+
+# virtualenv
+venv/
+ENV/
+
+# Spyder project settings
+.spyderproject
+
+# Rope project settings
+.ropeproject
+
+# Test report
+xunit-reports
+coverage-reports
+
+# Eclipse
+.project
+.pydevproject
+.settings
diff --git a/Dockerfile b/Dockerfile
new file mode 100644 (file)
index 0000000..34578ff
--- /dev/null
@@ -0,0 +1,37 @@
+# ==================================================================================
+#   Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved.
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#          http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+# ==================================================================================
+FROM python:3.8-alpine
+
+# copy rmr libraries from builder image in lieu of an Alpine package
+COPY --from=nexus3.o-ran-sc.org:10002/o-ran-sc/bldr-alpine3-rmr:4.0.5 /usr/local/lib64/librmr* /usr/local/lib64/
+# RMR setup
+RUN mkdir -p /opt/route/
+COPY resources/test_route.rt /opt/route/test_route.rt
+ENV LD_LIBRARY_PATH /usr/local/lib/:/usr/local/lib64
+ENV RMR_SEED_RT /opt/route/test_route.rt
+
+# sdl needs gcc
+RUN apk update && apk add gcc musl-dev bash
+
+# Install
+COPY setup.py /tmp
+COPY LICENSE.txt /tmp/
+COPY src/ /tmp/src
+RUN pip install /tmp
+
+# Run
+ENV PYTHONUNBUFFERED 1
+CMD run-hw-python.py
diff --git a/LICENSE.txt b/LICENSE.txt
new file mode 100644 (file)
index 0000000..69a2cef
--- /dev/null
@@ -0,0 +1,29 @@
+
+       Unless otherwise specified, all software contained herein is licensed
+       under the Apache License, Version 2.0 (the "Software License");
+       you may not use this software except in compliance with the Software
+       License. You may obtain a copy of the Software License at
+
+               http://www.apache.org/licenses/LICENSE-2.0
+
+       Unless required by applicable law or agreed to in writing, software
+       distributed under the Software License is distributed on an "AS IS" BASIS,
+       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+       See the Software License for the specific language governing permissions
+       and limitations under the Software License.
+
+
+
+       Unless otherwise specified, all documentation contained herein is licensed
+       under the Creative Commons License, Attribution 4.0 Intl. (the
+       "Documentation License"); you may not use this documentation except in
+       compliance with the Documentation License. You may obtain a copy of the
+       Documentation License at
+
+               https://creativecommons.org/licenses/by/4.0/
+
+       Unless required by applicable law or agreed to in writing, documentation
+       distributed under the Documentation License is distributed on an "AS IS"
+       BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+       implied. See the Documentation License for the specific language governing
+       permissions and limitations under the Documentation License.
diff --git a/resources/pod.yaml b/resources/pod.yaml
new file mode 100644 (file)
index 0000000..30f55b9
--- /dev/null
@@ -0,0 +1,14 @@
+apiVersion: v1
+kind: Pod
+metadata:
+  name: hwxapp
+  labels:
+    role: xapp
+spec:
+  containers:
+    - name: hwxapp-py
+      image: hwxapp-py:1.0
+      ports:
+        - name: rmr
+          containerPort: 4560
+          protocol: TCP
diff --git a/resources/test_route.rt b/resources/test_route.rt
new file mode 100644 (file)
index 0000000..7f69614
--- /dev/null
@@ -0,0 +1,3 @@
+newrt|start
+rte|13111|127.0.0.1:4560
+newrt|end
diff --git a/setup.py b/setup.py
new file mode 100644 (file)
index 0000000..0da755d
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,30 @@
+# ==================================================================================
+#
+#       Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved.
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#          http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+# ==================================================================================
+
+from setuptools import setup, find_packages
+
+setup(
+    name='hw_python',
+    version='0.0.1',
+    packages=find_packages(),
+    url='https://gerrit.o-ran-sc.org/r/admin/repos/ric-app/hw-python',
+    license='Apache 2.0',
+    install_requires=["ricxappframe>=1.1.1,<2.0.0"],
+    entry_points={"console_scripts": ["run-hw-python.py=src.main:start"]},  # adds a magical entrypoint for Docker
+    data_files=[("", ["LICENSE.txt"])],
+)
+
diff --git a/src/__init__.py b/src/__init__.py
new file mode 100644 (file)
index 0000000..4f7e5d5
--- /dev/null
@@ -0,0 +1,16 @@
+# ==================================================================================
+#
+#       Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved.
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#          http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+# ==================================================================================
diff --git a/src/main.py b/src/main.py
new file mode 100644 (file)
index 0000000..10ad0f8
--- /dev/null
@@ -0,0 +1,74 @@
+# ==================================================================================
+#
+#       Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved.
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#          http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+# ==================================================================================
+
+import json
+from os import getenv
+from ricxappframe.xapp_frame import RMRXapp, rmr
+from ricxappframe.alarm import alarm
+
+
+# pylint: disable=invalid-name
+rmr_xapp = None
+
+
+def post_init(self):
+    """
+    Function that runs when xapp initialization is complete
+    """
+    self.logger.info("post_init called")
+
+def handle_config_change(self, config):
+    """
+    Function that runs at start and on every configuration file change.
+    """
+    self.logger.info("handle_config_change: config: {}".format(config))
+
+
+def default_handler(self, summary, sbuf):
+    """
+    Function that processes messages for which no handler is defined
+    """
+    self.logger.info("default_handler called")
+    self.rmr_free(sbuf)
+
+
+def start(thread=False):
+    """
+    This is a convenience function that allows this xapp to run in Docker
+    for "real" (no thread, real SDL), but also easily modified for unit testing
+    (e.g., use_fake_sdl). The defaults for this function are for the Dockerized xapp.
+    """
+    global rmr_xapp
+    fake_sdl = getenv("USE_FAKE_SDL", True)
+    config_file = getenv("CONFIG_FILE", None)
+    rmr_xapp = RMRXapp(default_handler,
+                       config_handler=handle_config_change,
+                       rmr_port=4560,
+                       post_init=post_init,
+                       use_fake_sdl=bool(fake_sdl))
+    rmr_xapp.run(thread)
+
+
+def stop():
+    """
+    can only be called if thread=True when started
+    TODO: could we register a signal handler for Docker SIGTERM that calls this?
+    """
+    rmr_xapp.stop()
+
+if __name__ == "__main__":
+    start()