COLMENA Programming model library
Project description
COLMENA Programming Model
This GitHub repository contains all the files and software necessary to create applications to be deployed on a COLMENA platform. COLMENA (COLaboración entre dispositivos Mediante tecnología de ENjAmbre) aims to ease the development, deployment, operation and maintenance of extremely-high available, reliable and intelligent services running seamlessly across the device-edge-cloud continuum. It leverages a swarm approach organising a dynamic group of autonomous, collaborative nodes following an agile, fully-decentralised, robust, secure and trustworthy open architecture.
Table of Contents
Repository Structure
The repository is organized into the following directories and files:
Directories
- colmena: Contains the python library with the programming model and abstractions.
- examples: Example applications used for testing.
- scripts: Scripts to create a COLMENA service bundle from the application source code.
- test: Scripts and configuration files used for testing.
Files
- .gitignore: Specifies files and directories to be ignored by Git.
- changeLog: Change highlights associated with official releases.
- CODE_OF_CONDUCT.md: Outlines the expected behavior and guidelines for participants within the project's community.
- CONTRIBUTING.md: Overview of the repository, setup instructions, and basic usage examples.
- Dockerfile: File used to create a Docker image for the deployment tool.
- LICENSE: License information for the repository.
- pyproject.toml: Configuration file necessary for building role images.
- README.md: Overview of the repository, setup instructions, and basic usage examples.
Getting Started
To get started with the COLMENA programming model, follow these steps:
-
Clone the Repository:
git clone https://github.com/colmena-swarm/programming-model.git .
-
Install Dependencies:
python3 -m pip install .
-
Create a sample application:
To do so, create a Python file with the application code. The file should contain at least two classes, the service class and the context class. You can find an example in test/examples/example_application.py.
Service class
The service class extends Service, and contains one inner class per role. For example, in example_application.py there are two roles:
class ExampleApplication(Service): # ... class Sensing(Role): # ... class Processing(Role): # ...
The init function of the Service class is annotated with different elements: abstractions to be used by the roles (@Channel, @Metric), KPIS for the QoS evaluation (@KPI), and the context (@Context). To continue with the example:
class ExampleApplication(Service): @Context(class_ref=CompanyPremises, name="company_premises") @Channel(name="buffer", scope=" ") @Channel(name="result", scope=" ") @Metric(name="sensed") @Metric(name="processed") def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs)
Finally, the init functions of the roles are also annotated with the abstractions and role KPIs.
class Processing(Role): @Channel(name="result") @Channel(name="buffer") @Metric(name="processed") @Requirements("CPU") @KPI("buffer_queue_size[100000000s] < 10") def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs)
Note that the abstractions must be first initialized by decorating the service class and then specified in all the roles that will use them:
Each role has a behavior function, which can be annotated with
@Persistentor@Async:@Async(image="buffer") def behavior(self, image):
If it's asynchronous, the function will be called when there are new elements in the channel (and these will be passed as parameters). The persistent functions will be executed continuously.
Context class
The context class must contain an attribute structure specifying the hierarchy of the context, and a function locate that returns the agent's position depending on the device's parameters.
class CompanyPremises(Context): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.structure = { "floor1": ["reception"], "floor2": ["reception", "open_space"], "floor3": ["open_space", "manager_office"], } def locate(self, device): print(self.structure["floor1"][0])
-
Build the service:
colmena_build --service_path="<path_to_the_service_root>" \
The outcome of the building process will be left at <path_to_the_service_root>/<service_modulename>/build.
Docker
Alternatively, the service can also be created using docker:
- Create the corresponding docker image locally
docker --debug build -t colmenaswarm/programming-model:latest .
- Execute the image mounting as a volume the folder containing the code of service.
docker run --rm \ -v <path-to-application>:/app \ colmenaswarm/programming-model:latest \ --module_name=<service_modulename> \ --service_name=<service_classname>
Testing
The folder tests/ contains example applications and a series of python tests (test_examples.py) to verify the correct behavior. To run all tests, execute the following commands on a terminal:
cd test
python3 -m pytest test_examples.py
The tests will make sure that all the files and folders are created properly (test_build_files), that the roles of each service execute without errors (test_roles_in_services), and that the build command runs (test_build).
For adding a new test/example, include the code of the service in the folder and also the reference service model JSON file to compare with. Bear in mind to include it as part of the testing script in order to execute it automatically.
Contributing
Please read our contribution guidelines before making a pull request.
License
The COLMENA programming model is released under the Apache 2.0 license. Copyright © 2022-2024 Barcelona Supercomputing Center - Centro Nacional de Supercomputación. All rights reserved. See the LICENSE file for more information.
This work is co-financed by the COLMENA project of the UNICO I+D Cloud program that has the Ministry for Digital Transformation and of Civil Service and the EU-Next Generation EU as financing entities, within the framework of the PRTR and the MRR. It has also been supported by the Spanish Government (PID2019-107255GB-C21), MCIN/AEI /10.13039/501100011033 (CEX2021-001148-S), and Generalitat de Catalunya (2021-SGR-00412).
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file colmena_swarm_pm-0.1.1.tar.gz.
File metadata
- Download URL: colmena_swarm_pm-0.1.1.tar.gz
- Upload date:
- Size: 22.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.12.1.2 readme-renderer/44.0 requests/2.31.0 requests-toolbelt/1.0.0 urllib3/1.26.5 tqdm/4.65.1 importlib-metadata/6.8.0 keyring/24.3.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be195c9b56a337e6160ae2e2fe747e45ef39c70911190a2d9e269cdb3b21cedf
|
|
| MD5 |
cd5ce938c6550889d85832896b26afaf
|
|
| BLAKE2b-256 |
d3d544444a8d1a1b81627f630963aac6465a1f4bc7546d4f46d29d189b992de7
|
File details
Details for the file colmena_swarm_pm-0.1.1-py3-none-any.whl.
File metadata
- Download URL: colmena_swarm_pm-0.1.1-py3-none-any.whl
- Upload date:
- Size: 40.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.12.1.2 readme-renderer/44.0 requests/2.31.0 requests-toolbelt/1.0.0 urllib3/1.26.5 tqdm/4.65.1 importlib-metadata/6.8.0 keyring/24.3.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8dd96cfdf4012c9920cd89b73609fb43a842a7160ae2f2b9875928053138590f
|
|
| MD5 |
b03c0d9dfc7d6748236727d1bc0127bb
|
|
| BLAKE2b-256 |
6f76d0cbf91f748ebb5ad8c3dbce11e123945ee4cfedc8cef3150b3aebe4c3d1
|