Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: (classic)

...

Warning
titleDraft Specification

This specification is currently a draft under development.

Subscription Event Protocol

The CloudOS Subscription Event Protocol provides an event based model for managing subscriptions between Personal Clouds. The current implementation of the protocol will create a symmetric relationship between both Personal Clouds. In order to used Cloud subscriptions are done in such a way that both the originating and target clouds end up with a unique event channel to the other that is specific to the purpose for the subscription. 

Rulesets do not manage subscriptions directly, but rather rely on the CloudOS service to do it for them. Consequently, to use the Subscription Event Protocol, the CloudOS service ruleset must be installed in the Personal Cloud for both the originating originator and target. The CloudOS service listens for certain events, manages subscriptions, and provides functions for getting information about subscriptions. Developers need not be concerned with the details of how subscriptions are created between clouds, just the service interface documented here. 

Events

Subscribe

The system:subscribe event is used to create a Personal Channel channel between two Personal Clouds.

...

Domaincloudos

...

Typesubscribe

...

AttributeschannelName

...

, namespace

...

, relationship

...

, targetChannel, subAttrs

The attributes have the following semantics:

  • The channelName attribute is a label associated with the subscription that should convey meaning to developer. The channelName is only used as a component in the creation of the event channel tokenidentifier. If no channelName is specified the value of "orphan" will be used.
  • The namespace attribute is provided as a means for the developer to group subscriptions within a single, or group, or applications. The namespace is used to filter the list of subscriptions returned by the subscriptionList() function. If not no namespace is specified the value of "shared" will be used.
  • The relationship attribute is provided as a means for allows the developer to characterize the relationship between the originating originator and target Personal Cloudclouds. The relationship attribute should be specified as a pair of values separated by a dash (e.g. parent-child, peer-peer, master-slave). The first value of the relationship attribute will be stored with the originating Personal Cloud subscription, the second value will be stored with the target Personal Cloud subscription. The relationship attribute values are used to filter the list of subscriptions returned by the subscriptionList() function. If not no relationship is specified the value of "peer-peer" will be used.
  • The targetChannel attribute is the Personal Channel token event channel identifier (ECI) for the target Personal Cloud cloud to which the subscription is to be made.
The sending Personal Cloud will have the following event raised to signal that the subscription request has been received:
  • domain: cloudos
  • type: subscriptionRequestAdded
  • attributes: targetChannel, backChannel, namespace, relationship, channelName

 

...

  • Usually, this is the well-known ECI (doorbell) for the target cloud. The well-known ECI provides a means for bootstrapping subscriptions between clouds.
  • The subAttrs is an optional attribute that you can use to pass a JSON hash for key/value pairs to the target personal cloud.

Any ruleset wishing to create the subscription signals the CloudOS to do so by raising the system:subscribe event. This is most often done in a rule postlude as shown in the following example:

Code Block
languagejavascript
themeConfluence
fired {
  raise cloudos event subscribe
    with channelName   = "Coworkers Bob+Ted"
    and  namespace     = "MyFriends"
    and  relationship  = "friend-friend"
    and  targetChannel = "3f15b820-
af7f
fa7f-012f-4c6e-
00163ebczzzz"
00163ebccdcd"
    and  subAttr       = {"name": "Ed Orcutt", "age": "43"}
    and  _api = "sky";
}

 

The Personal Cloud receiving the subscription request will have the following event raised

The CloudOS service raises the cloudos:subscriptionRequestAdded to the originating cloud:

Domaincloudos
Type
subscriptionRequestAdded
Attributes
targetChannel, backChannel, namespace, relationship, channelName

The backChannel attribute contains an ECI for the originating cloud that the CloudOS service has created and will pass to the target cloud. 

The following rule would be selected upon seeing the cloudos:subscriptionRequestAdded event with appropriate values for the event attributes:

Code Block
languagejavascript
themeConfluence
rule process_subscriptionRequestAdded {
  select when cloudos subscriptionRequestAdded
    namespace re/MyFriends/"
    channelName re/Coworkers Bob+Ted/
    relationship re/friend-friend/
  ...
}

Upon see the subscription, the CloudOS service in the target cloud raises the cloudos:subscriptionRequestPending to signal the receipt of a pending subscription request:

domain: attributes:
Domaincloudos
  • type: subscriptionRequestPending
  • Type
    subscriptionRequestPending
    Attributes
    eventChannel, namespace,
    relationship
     relationship, channelName

     

    Code Block
    , subAttrs

    Note: The subAttrs attribute is encoded, you will want to decode() it prior to use.

    The following rule would be selected upon seeing the cloudos:subscriptionRequestAdded event with appropriate values for the event attributes:

    Code Block
    languagejavascript
    themeConfluence
    languagejavascript
    rule 
    receive
    process_
    subscriptionRequestAdded
    subscriptionRequestPending {
      select when cloudos 
    subscriptionRequestAdded
    subscriptionRequestPending
        namespace re/MyFriends/"
        channelName re/Coworkers Bob+Ted/
        relationship re/friend-friend/
     
    
      pre {
        subAttrs = event:attr("subAttrs").decode();
      }
      ...
    }

    Subscription Event Flow

    Image Added

    1. The cloudos:subscribe event is raised by the originating personal cloud.
    2. CloudOS will create a new channel and raise the cloudos:subscriptionRequestAdded event within the originating personal cloud. The main purpose for raising this event is to provide the application developer the opportunity to capture the newly created channel, backChannel.
    3. CloudOS then raises an event to the target personal cloud over the targentChannel (typically the doorbell ECI) requesting the subscription.
    4. CloudOS in the target personal cloud will raise the cloudos:subscriptionRequestPending giving rulesets the opportunity to respond with either an approval or rejection (see below).

    Subscription Approval or Rejection

    With the subscription request pending approval, the Personal Cloud which received the request target cloud can either approve or reject the request.

    Approval

    To approve the subscription request

    ...

    • domain: cloudos
    • type: subscriptionRequestApproved
    • attributes: eventChannel

     

    ...

    a ruleset in the the target cloud raises the cloudos:subscriptionRequestApproved event to signal the CloudOS service that the subscription is approved:

    Domaincloudos
    Type
    subscriptionRequestApproved
    Attributes
    eventChannel, approveAttrs

    The approveAttrs attribute is an optional parameter that can be used to pass a JSON hash of key/value pairs to the originating personal cloud.

    For example, the following postlude would raise the cloudos:subscriptionRequestApproved event:

    Code Block
    languagejavascript
    themeConfluence
    fired {
      raise cloudos event subscriptionRequestApproved
        with eventChannel = "3f15b820-af7f-012f-4c6e-00163ebcaaaa"
        and  approveAttrs = {"name": "Fred Wilson" , "age": "22" }
        and  _api = "sky";
    }

    For example, this postlude might be in a rule that has received input from the user indicating the user has approved the request. For some requests in some clouds, you may want to create a rule that rule that automatically approves the request. 

    Once the subscription request is approved

    ...

    • domain: cloudos
    • type: CloudOS_subscriptionAdded
    • attributes: eventChannel, backChannel, namespace, relationship, channelName

     

    ...

    themeConfluence
    languagejavascript

    ...

    , the CloudOS service in both the orginating and target clouds will raise the cloudos:subscriptionAdded event so that a ruleset can take additional actions once the subscription has been created:

    Domaincloudos
    Type
    subscriptionAdded
    Attributes
    eventChannel, backChannel, namespace, relationship, channelName, approveAttrs

    Note: The approvalAttrs attribute is encoded, you will want to decode() it prior to use.

    The following shows a rule that is selected when the cloudos:subscriptionAdded event is raised:

    Code Block
    languagejavascript
    themeConfluence
    rule process_subscriptionAdded {
      select when cloudos 
    subscriptionRequestAdded
    subscriptionAdded
        namespace re/MyFriends
    "
    /
        channelName re/Coworkers Bob+Ted/
        relationship re/friend-friend/
     
    
      pre {
        approveAttrs = event:attr("approveAttrs").decode();
      }
      ...
    }

    Subscription Approval Event Flow

    Image Added

    1. The cloudos:subscriptionRequestApproved event is raised into the target personal cloud after creating a new channel.
    2. CloudOS raises the cloudos:subscriptionAdded event within the target personal cloud.
    3. CloudOS raises a event over the eventChannel to the originating personal cloud to indicate that the subscription request has been approved.
    4. Within the originating personal cloud CloudOS raises the cloudos:subscriptionAdded event.

    Rejection

    To reject the subscription request

    the following event should be raised:
    • domain: cloudos
    • type: subscriptionRequestRejected
    • attributes: eventChannel

     

    Code BlockthemeConfluence

    a ruleset in the the target cloud raises the cloudos:subscriptionRequestRejected event to signal the CloudOS service that the subscription is rejected:

    Domaincloudos
    Type
    subscriptionRequestRejected
    Attributes
    eventChannel

    For example, the following postlude would raise the cloudos:subscriptionRequestRejected event:

    Code Block
    languagejavascript
    themeConfluence
    fired {
      raise cloudos event subscriptionRequestRejected
        with eventChannel = "3f15b820-af7f-012f-4c6e-00163ebcaaaa"
        and  _api = "sky";
    }
     

    When the subscription request is rejected the

    following event will be raised with the Personal Cloud:
    • domain: cloudos
    • type: subscriptionRejected
    • attributes: eventChannel, namespace, relationship, channelName
    And the following event will be raised in the Personal Cloud which made the subscription request:
    • domain: cloudos
    • type: subscriptionRejected
    • attributes: backChannel, namespace, relationship, channelName
    Code Block
    themeConfluence
    languagejavascript
    fired {
      raise cloudos event subscribe
        with channelName   = "Coworkers Bob+Ted"
        and  namespace     = "DocSample"
        and  relationship  = "friend-friend"
        and  targetChannel = "3f15b820-af7f-012f-4c6e-00163ebczzzz"
        and  _api = "sky";
    }

     

    Unsubscribe

    The system:unsubscribe event is used to remove the Personal Channels between two Personal Clouds.

    • domain: cloudos
    • type: unsubscribe
    • attribute: backChannel
    The backChannel attribute uniquely identifies the Personal Channel within the Personal Cloud, and provided to the target Personal Cloud for raising events into the current Personal Cloud. The backChannel is one of the attributes provided by the subscriptionList() function.
    During the processing of removing the Personal Channels bewteen the two Personal Clouds callback events are raised within each respective Personal Cloud. These events are raised to enable the developer to take additional actions when the Personal Channels are actually being removed.
    • domain: cloudos
    • type: CloudOS_subscriptionRemoved
    • attributes: eventChannel, backChannel, namespace, relationship, channelName
    The eventChannel attribute is the Personal Channel token for the remote Personal Cloud, while the backChannel is the Personal Channel token for the current Personal Cloud.

     

    Code Block
    themeConfluence
    languagejavascript
    always {
      raise system event unsubscribe
        with backChannel = "3f15b820-af7f-012f-4c6e-00163ebcfddfd"
        and  _api = "sky";
    }

     

    Functions

    CloudOS service will raise the cloudos:subscriptionRejected event within the target cloud (i.e. the cloud rejecting the subscription):

    Domaincloudos
    Type
    subscriptionRejected
    Attributes
    eventChannel, namespace, relationship, channelName

    The following rule is selected when the cloudos:subscriptionRejected event is seen:

    Code Block
    languagejavascript
    themeConfluence
    rule receive_subscriptionRejected {
      select when cloudos subscriptionRejected
        namespace re/MyFriends/
        channelName re/Coworkers Bob+Ted/
        relationship re/friend-friend/
      ...
    }

    In addition, the CloudOS service raises the cloudos:subscriptionRejected event in the originating cloud:

    Domaincloudos
    Type
    subscriptionRejected
    Attributes
    backChannel, namespace, relationship, channelName

    The only difference is that the attribute backChannel is contains the value of the ECI to the target cloud. 

    The following rule is selected when the cloudos:subscriptionRejected event is raised:

    Code Block
    languagejavascript
    themeConfluence
    rule receive_subscriptionRejected {
      select when cloudos subscriptionRejected
        namespace re/MyFriends/
        channelName re/Coworkers Bob+Ted/
        relationship re/friend-friend/
      ...
    }

    Subscription Rejection Event Flow

    Image Added

    1. The cloudos:subscriptionRequestRejected event is raised into the target personal cloud.
    2. CloudOS raises the cloudos:subscriptionRejected event within the target personal cloud.
    3. CloudOS raises an event over the eventChannel to the originating personal cloud to indicate that the subscription request was rejected.
    4. Within the originating personal cloud CloudOS raises the cloudos:subscriptionRejected event.

    Unsubscribe

    A ruleset that wishes to remove the channels between two clouds raises the cloudos:unsubscribe event:

    Domaincloudos
    Type
    unsubscribe
    Attributes
    targetChannel

    The targetChannel attribute uniquely identifies the channel to be unsubscribed. The backChannel is one of the results provided by the subscriptionList() function.

    The following postlude shows this event being raised:

    Code Block
    languagejavascript
    themeConfluence
    fired {
      raise cloudos event unsubscribe
        with targetChannel = "3f15b820-7aff-012f-4c6e-00163ebcfddfd"
        and  _api = "sky";
    }

    The CloudOS service in both the originating and target clouds raises the cloudos:subscriptionRemoved event so that rulesets within the respective clouds can take any appropriate action:

    Domaincloudos
    Type
    subscriptionRemoved
    Attributes
    eventChannel, backChannel, namespace, relationship, channelName, approveAttrs

    Note: The approvalAttrs attribute is encoded, you will want to decode() it prior to use.

    The following rule is selected when the cloudos:CloudOS_subscriptionRemoved event is raised:

    Code Block
    languagejavascript
    themeConfluence
    rule receive_subscriptionRemoved {
      select when cloudos subscriptionRemoved
        namespace re/MyFriends/
        channelName re/Coworkers Bob+Ted/
        relationship re/friend-friend/
      pre {
        approveAttrs = event:attr("approveAttrs");
      }
      ...
    }

    Unsubscribe Event Flow

    Image Added

    1. The cloudos:unsubscribe event is raised into the originating personal cloud. Note that it is also possible to raised the cloudos:unsubscribe event in the target personal cloud as well. "Originating" and "target" are relative to where the cloudos:unsubscribe event is raised. 
    2. CloudOS raises the cloudos:subscriptionRemoved event within the originating personal cloud.
    3. CloudOS raises an event over the eventChannel to the target personal cloud to indicate that the subscription has been removed.
    4. CloudOS raises the cloudos:subscriptionRemoved event within the target personal cloud.

    Functions

    The CloudOS service provides the following functions. In order to use these functions, a ruleset must include the CloudOS service ruleset as a module:

    Code Block
    languagejavascript
    themeConfluence
    use module a169x625 alias CloudOS

    subscriptionList(namespace, relationship)

    The subscriptionList() function will return a map of the subscriptions within the specified namespace and relationship. In order to use the function you must include the CloudOS module as a pragma in the meta section of your ruleset:

    use module a169x625 alias CloudOS

      

    Code Block
    languagejavascript
    themeConfluence
    pre {
      friendsList = CloudOS:subscriptionList("myConnections", "friend");
    }

    getAllSubscriptions()

    The getAllSubscriptions() function will return a map of all active subscriptions within the current Personal Cloud. The subscription sample application provides an example of using this function.

    Code Block
    languagejavascript
    themeConfluence
    pre {
      allSubscriptions = CloudOS:getAllSubscriptions();
    }

    getAllPendingApproval()

    The getAllPendingApproval() function returns a map of all subscription request that are pending your approval. The subscription sample application provides an example of using this function.

    Code Block
    languagejavascript
    themeConfluence
    pre {
      allSubscriptionsPendingApproval = CloudOS:getAllPendingApproval();
    }

    getAllPendingSubscriptions

    The getAllPendingSubscriptions() function returns a map of all subscription request that have been generated within this Personal Cloud. The subscription sample application provides an example of using this function.

    Code Block
    languagejavascript
    themeConfluence
    pre {
      allSubscriptionRequest = CloudOS:getAllPendingSubscriptions();
    }