<commit_before># Demo scenario

In this example there are 2 services:
- analytics_pipeline- it consists of kafka, spark, hdfs, zookeeper and is offered in two different contexts
  - *stage*: in sharing all consumers of analytics_pipeline get to share the same instance
  - *production*: a single production instance with more memory, better replicas count, etc 
- twitter_stats - it depends on analytics_pipeline and consists of 3 components (publisher, stats, ui).
  It gets data from Twitter in real time, calculates top hashtags using an external analytics_pipeline service and displays
  results on a web page.  

These services have different owners, who can fully control how their services get offered and shared:
- Frank defined analytics_pipeline
- John defined twitter_stats
- Alice, Bob, Carol are services consumers and/or code contributors
- Sam is a domain admin for Aptomi

This example illustrates a few important things that Aptomi does:
1. Service definitions & instantiation
    - Service owners publish their services and fully define how they get offered & shares to others
    - Implementation details are abstracted away from consumers, so they can consume other services without knowing the inner-workings
1. Service update
    - Change parameter/label with a single command and re-apply only the required delta 
1. Service reuse
    - Alice and Bob share the same instance of analytics_pipeline in staging
1. Policy & rules
    - Different people have different access rights within Aptomi object model
    - Aptomi can allocate instances with different parameters in different clusters (e.g. based on consumer identity)

# Instructions

1. First of all, bootstrap Aptomi on behalf on Sam (domain admin) to import k8s clusters and rules. ACL rules are defined in such
a way that Sam is a domain admin, John/Frank are namespace admins, and Alice/Bob/Carol are service consumers
    ```
    aptomictl policy apply --username Sam --config /etc/aptomi/config.yaml -f examples/03-twitter-analytics/policy/Sam
    ```
1. Import analytics_pipeline service definition on behalf of Frank
    ```
    aptomictl policy apply --username Frank --config /etc/aptomi/config.yaml -f examples/03-twitter-analytics/policy/Frank
    ```
1. Import analytics_pipeline service definition on behalf of John
    ```
    aptomictl policy apply --username John --config /etc/aptomi/config.yaml -f examples/03-twitter-analytics/policy/John
    ```
1. At this point all service definition have been published to Aptomi, but nothing has been instantiated yet. You can see
that in Aptomi UI.
    [TODO]

1. Now let's have consumers declare 'dependencies' on the services defined by John and Frank. John requests an instance
    ```
    aptomictl apply policy --username John --config /etc/aptomi/config.yaml -f examples/03-twitter-analytics/policy/john-prod-ts.yaml
    ```
    Aptomi allocates a production instance in cluster [TODO]:
    [TODO] picture
    [TODO] delta

1. Alice and Bob request instances
    ```
    aptomictl policy apply --username Alice --config /etc/aptomi/config.yaml -f examples/03-twitter-analytics/policy/alice-stage-ts.yaml
    aptomictl policy apply --username Bob --config /etc/aptomi/config.yaml -f examples/03-twitter-analytics/policy/bob-stage-ts.yaml
    ```
    Alice tests a change. Bob looks at Mexico.
    Aptomi allocates staging instances in cluster [TODO]:<commit_msg>fix policy apply instructions<commit_after># Demo scenario

In this example there are 2 services:
- analytics_pipeline- it consists of kafka, spark, hdfs, zookeeper and is offered in two different contexts
  - *stage*: in sharing all consumers of analytics_pipeline get to share the same instance
  - *production*: a single production instance with more memory, better replicas count, etc 
- twitter_stats - it depends on analytics_pipeline and consists of 3 components (publisher, stats, ui).
  It gets data from Twitter in real time, calculates top hashtags using an external analytics_pipeline service and displays
  results on a web page.  

These services have different owners, who can fully control how their services get offered and shared:
- Frank defined analytics_pipeline
- John defined twitter_stats
- Alice, Bob, Carol are services consumers and/or code contributors
- Sam is a domain admin for Aptomi

This example illustrates a few important things that Aptomi does:
1. Service definitions & instantiation
    - Service owners publish their services and fully define how they get offered & shares to others
    - Implementation details are abstracted away from consumers, so they can consume other services without knowing the inner-workings
1. Service update
    - Change parameter/label with a single command and re-apply only the required delta 
1. Service reuse
    - Alice and Bob share the same instance of analytics_pipeline in staging
1. Policy & rules
    - Different people have different access rights within Aptomi object model
    - Aptomi can allocate instances with different parameters in different clusters (e.g. based on consumer identity)

# Instructions

1. First of all, bootstrap Aptomi on behalf on Sam (domain admin) to import k8s clusters and rules. ACL rules are defined in such
a way that Sam is a domain admin, John/Frank are namespace admins, and Alice/Bob/Carol are service consumers
    ```
    aptomictl policy apply --username Sam --config /etc/aptomi/config.yaml -f examples/03-twitter-analytics/policy/Sam
    ```
1. Import analytics_pipeline service definition on behalf of Frank
    ```
    aptomictl policy apply --username Frank --config /etc/aptomi/config.yaml -f examples/03-twitter-analytics/policy/Frank
    ```
1. Import analytics_pipeline service definition on behalf of John
    ```
    aptomictl policy apply --username John --config /etc/aptomi/config.yaml -f examples/03-twitter-analytics/policy/John
    ```
1. At this point all service definition have been published to Aptomi, but nothing has been instantiated yet. You can see
that in Aptomi UI.
    [TODO]

1. Now let's have consumers declare 'dependencies' on the services defined by John and Frank. John requests an instance
    ```
    aptomictl policy apply --username John --config /etc/aptomi/config.yaml -f examples/03-twitter-analytics/policy/john-prod-ts.yaml
    ```
    Aptomi allocates a production instance in cluster [TODO]:
    [TODO] picture
    [TODO] delta

1. Alice and Bob request instances
    ```
    aptomictl policy apply --username Alice --config /etc/aptomi/config.yaml -f examples/03-twitter-analytics/policy/alice-stage-ts.yaml
    aptomictl policy apply --username Bob --config /etc/aptomi/config.yaml -f examples/03-twitter-analytics/policy/bob-stage-ts.yaml
    ```
    Alice tests a change. Bob looks at Mexico.
    Aptomi allocates staging instances in cluster [TODO]:
{'fraction_non_alphanumeric': 0.06445941986522122, 'fraction_numerical': 0.00732493407559332, 'mean_word_length': 3.767458100558659, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '917662', 'n_tokens_mistral': 1784, 'n_tokens_neox': 1741, 'n_words': 840}