Application Packaging Standard

Last updated 18-Mar-2019

Provisioning Logic

Application provisioning logic must subscribe to the domain registration events and process those events in accordance with the Scenario.

../../../../_images/dns-step-model.png ../../../../_images/dns-step-meta.png ../../../../_images/dns-step-provision-b.png ../../../../_images/dns-step-presentation.png ../../../../_images/dns-step-deploy.png ../../../../_images/dns-step-provisioning.png

Requirements

In accordance with the Scenario and Resource Model the provisioning logic requires the following updates:

  • The context resource must subscribe to the “bind to domain” event.
  • The context resource must have a collection of links with the DNS zone resources. It must add such a link every time it processes the “bind to domain” event.
  • Every vps resource must have a link with a domain bound to the context resource and the links to those DNS records that are assigned to the VPS. So, a customer will not be able to create a VPS until at least one domain is registered by that customer.

Continue Your Demo Project

Continue the demo project started in the previous step. Update the provisioning logic of the context and vps APS types as required.

Management Context

A context resource must have a relationship with the collection of Hosted Domain resources. The related contexts service must subscribe to the Bind-to-Domain event and process it by adding a new link to each domain registered by the subscription owner.

Relationship

Edit the scripts/contexts.php script to update the management context provisioning logic as follows.

In the context class, add a collection of links with the resources based on the standard Domain APS type:

/**
 * @link("http://aps-standard.org/types/dns/domain/1.0[]")
 */
public $paDomains;

Event Processing

This is the key point of the demo project. The contexts service must subscribe the context resource to the “bind to domain” event and handle the event notifications.

Continue with editing the context class in the scripts/contexts.php file.

  1. In the context class, define a new method called onBindToDomain that will handle event notifications. The input parameter must comply with the Notification structure defined in the standard Resource APS type.

    /**
     * @verb(POST)
     * @path("/onBindToDomain")
     * @param("http://aps-standard.org/types/core/resource/1.0#Notification",body)
     */
    public function onBindToDomain($domainNotification) {
       ## For debugging only - log the input notification
       \APS\LoggerRegistry::get()->info("Domain bound: ".json_format($domainNotification));
    
       ## Connect to the APS controller
       $apsc2 = \APS\Request::getController();
    
       ##Impersonate the app to get access to a domain provided by the Domain Manager
       $apsc = $apsc2->impersonate($this);
    
       ## Get APS resource representing the registered domain
       $domain = $apsc->getResource($domainNotification->parameters->domain->id);
    
       ## Link the *management context* with the domain - add the link to collection paDomains
       $apsc->linkResource($this,'paDomains',$domain);
    }
    

    The handler reads the APS resource representing a domain zone bound to the subscription. Then, it links the context resource with the domain zone resource.

  2. In the provision method of the context class, subscribe the context resource to the “bind to domain” event. Specify the onBindToDomain method as the event handler. Create the subscription request structure using the BindServicesToDomain method in the APS PHP runtime EventSubscription class.

    public function provision() {
    
       #### Connect to the APS controller
       $apsc = \APS\Request::getController();
       if ($apsc == null) {
          error_log("apsc is null");
       }
    
       #### Create a subscription to the "bind-to-domain" event
       $subBindToDomain = new \APS\EventSubscription(
          \APS\EventSubscription::BindServicesToDomain,
          "onBindToDomain"
       );
    
       #### Create an "event source" object based on the standard class
       $subBindToDomain->source = new stdClass();
    
       #### Activate the event subscription
         ## Event source is the current hosting subscription
       $subBindToDomain->source->id=$this->subscription->aps->id;
       $apsc->subscribe($this, $subBindToDomain);
    }
    

VPS Resources

In terms of demonstration of the “bind to domain” event, this part of the provisioning logic is as important as the definition of the management context part. Some updates here are needed to enable a VPS to bind to a domain and to create DNS records in that domain. We suppose every VPS will get a DNS A record in the domain bound to the subscription and to the management context.

Since the vps type implements the standard Domain Service APS type, it has the required domain link with a domain and a records collection of links with DNS records in that domain.

The vps APS type also has the domainName property representing the linked domain.

Compared with the predecessor, the vps APS type needs one more DNS record - A record. For this purpose, add the ipAddress property to enable IP address assignment when creating a DNS A record:

/**
 * @type("string")
 * @title("IpAddress")
 * @description("IP address")
 */
public $ipAddress;

Conclusion

You have designed and updated the provisioning logic for the demo application. The updated APS types and their services are tightly bound with the domain registration system.

The provisioning part exposes the interface that the application UI can use to identify if there are registered domains to assign them to virtual servers and to bind a new VPS to DNS records in accordance with the scenario and the resource model.

The files you have updated are similar to the respective files in the sample package.