Skip to main content

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:

  1. Clone the Repository:

    git clone https://github.com/colmena-swarm/programming-model.git .
    
  2. Install Dependencies:

    python3 -m pip install .
    
  3. 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 @Persistent or @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])
    
  4. 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:

  1. Create the corresponding docker image locally
    docker --debug build -t colmenaswarm/programming-model:latest .
    
  2. 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 \
        --service_path=/app/<service_filename>
    

The build files will be included in the service folder specified.

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.

Besides the unit tests, it is possible to build a service code using the local version of the programming model. To do so, first build the distribution files using Python:

python3 -m build 

When building the service, add the variable build_file including the generated .tar.gz file from the dist/ folder:

    colmena_build --service_path="<path_to_the_service_root>" --build_file="<path_to_build_file>" \

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).

Metadata

Release files for colmena-swarm-pm 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for colmena-swarm-pm 0.1.4
File Size Uploaded
colmena_swarm_pm-0.1.4.tar.gz 24.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for colmena-swarm-pm 0.1.4
File Interpreter ABI Platform
colmena_swarm_pm-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 69.4 kB

Release files / colmena_swarm_pm-0.1.4.tar.gz

Download URL colmena_swarm_pm-0.1.4.tar.gz
Size 24.5 kB
Tags Source
SHA-256 checksum
How to use checksums
618c41a7b0f42e56ffb0e7fb11a7dc47435f01c32a419ba63d1367dee3fccd55
BLAKE2b-256 checksum
How to use checksums
94d59adc25f8d878ed273691372af4c99814c5f279750f08d4cff690a4f381e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.12.1.2 readme-renderer/44.0 requests/2.32.3 requests-toolbelt/1.0.0 urllib3/2.2.3 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

Release files / colmena_swarm_pm-0.1.4-py3-none-any.whl

Download URL colmena_swarm_pm-0.1.4-py3-none-any.whl
Size 44.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
38c262cf4913019a8a9f5844602f58e3a58be220f15c164b64d88b15356fb330
BLAKE2b-256 checksum
How to use checksums
048f7202d6de1110a3df8531e776e8daca27cb84f4543ecf9d2059e5729c07b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.12.1.2 readme-renderer/44.0 requests/2.32.3 requests-toolbelt/1.0.0 urllib3/2.2.3 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

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page