Provisioning Logic

In this section, you will develop the APS types that will be loaded to the APS controller and the services that will function on the APS connector.

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

Services

In the declaration of an APS type, the first things are their APS ID and the type inheritance. You should specify the APS type that your custom APS type will implement (inherit) following these recommendations:

  • The APS type used to create the application instance must inherit the abstract Application APS type.

  • The APS type used to create a singular resource representing the main service on the customer side usually implements the abstract SubscriptionService APS type.

  • If there is no special assignment, an APS type usually implements the abstract APS type Resource.

In this project, you should define three services with parameters complying with the above implementation rules and the resource model as presented in the table:

Type

Type ID
Implements

Relation

cloud

contexts
(collection, optional)

context

cloud
(singular, required)
vpses
(collection, optional)

vps

context
(singular, required)

To comply with those requirements, the provisioning logic in the PHP files copied from the template should be modified as follows:

  • Replace the @type property with the correct type ID.

  • Replace the @implements property with the correct implementation.

  • Add the relationship as specified in the above table.

The following example illustrates the modification of the vpses.php file.

/**
 * @type("http://aps-standard.org/samples/basic1p/vps/1.0")
 * @implements("http://aps-standard.org/types/core/resource/1.0")
 */
class vps extends APS\ResourceBase {

   // Relation with the management context
   /**
    * @link("http://aps-standard.org/samples/basic1p/context/1.0")
    * @required
    */
   public $context;
   ...
}

VPS Type

Unlike the cloud and context APS types, the vps APS type must also define many properties assigned to a VPS and a pair of custom operations to start and stop the server.

Let us assume the following set of structures and primitive properties:

../../../../_images/basic-vps-props.png

The custom start and stop operations must change the state property of the selected servers to respectively Running and Stopped.

Continue Your Demo Project

This section continues the demo project from its previous step.

In the PHP files, configure the APS type, implementation, and relationship as explained earlier.

Application APS Type

Modify the main class in the scripts/clouds.php file as follows:

/**
 * Class cloud presents application and its global parameters
 * @type("http://aps-standard.org/samples/vpsdemo/cloud/1.0")
 * @implements("http://aps-standard.org/types/core/application/1.0")
 */
class cloud extends APS\ResourceBase {
   # Link to collection of contexts. Pay attention to [] brackets at the end of the @link line.
   /**
    * @link("http://aps-standard.org/samples/vpsdemo/context/1.0[]")
    */
   public $contexts;
}

Management Context APS Type

Modify the main class in the scripts/contexts.php file as follows:

/**
* Class context
* @type("http://aps-standard.org/samples/vpsdemo/context/1.0")
* @implements("http://aps-standard.org/types/core/subscription/service/1.0")
*/

class context extends \APS\ResourceBase
{
   ## Strong relation (link) to the application instance
   /**
   * @link("http://aps-standard.org/samples/vpsdemo/cloud/1.0")
   * @required
   */
   public $cloud;

   ## Weak relation (link) to collection of VPSes
   /**
    * @link("http://aps-standard.org/samples/vpsdemo/vps/1.0[]")
    */
   public $vpses;
}

Server Management Logic

The vpses.php script must define the required ID, implementation, links, and properties as follows.

  1. The set of properties in the vps type is pretty complicated and must be represented as structures with embedded other structures and primitive properties, as illustrated above.

    The Hardware structure contains two primitives, RAM and Disk, and the CPU structure, which in turn contains the CPU cores primitive. The Platform structure contains the Architecture primitive and the OS structure, which includes the Name and Version primitives. Define the structures before the declaration of the main vps class.

    • CPU structure:

      class CPU {
         /**
          * @type("integer")
          * @title("Number of CPUs")
          * @description("Number of CPU cores")
         */
         public $number;
      }
      
    • OS structure:

      class OS {
         /**
          * @type("string")
          * @title("OS Name")
          * @description("Operating System Name")
         */
         public $name;
      
         /**
          * @type("string")
          * @title("OS Version")
          * @description("Operating System version")
         */
         public $version;
      }
      
    • Hardware structure:

      class Hardware {
         /**
          * @type("integer")
          * @title("RAM Size")
         * @description("RAM size in GB")
         */
         public $memory;
      
        /**
         * @type("integer")
         * @title("Disk Space")
         * @description("Disk space in GB")
        */
            public $diskspace;
      
        /**
         * @type("CPU")
         * @title("CPU")
         * @description("Server CPU parameters")
        */
        public $CPU;
      }
      
    • Platform structure:

      class Platform {
         /**
         * @type("string")
         * @title("Architecture")
         * @description("Platform architecture")
         */
         public $arch;
      
         /**
         * @type("OS")
         * @title("OS Parameters")
         * @description("Parameters of operating system")
         */
         public $OS;
       }
      
  2. The new type vps must implement the APS core resource type. The respective service on the APS connector is defined by the main vps class inherited from the ResourceBase class that is shipped within the APS PHP framework:

    /**
    * @type("http://aps-standard.org/samples/vpsdemo/vps/1.0")
    * @implements("http://aps-standard.org/types/core/resource/1.0")
    */
    class vps extends APS\ResourceBase { ... }
    
  3. The new type vps has a required relation with the management context type:

    /**
     * @link("http://aps-standard.org/samples/vpsdemo/context/1.0")
     * @required
    */
    public $context;
    
  4. In addition to the structures, there are separate primitives: VPS name, description, and state. They must be defined in the vps class:

    /**
    * @type("string")
    * @title("name")
    * @description("Server Name")
    */
    public $name;
    
    /**
    * @type("string")
    * @title("Description")
    * @description("Server Description")
    */
    public $description;
    
    /**
    * @type("string")
    * @title("state")
    * @description("Server State")
    */
    public $state;
    
  5. The structures defined earlier now must be added to the vps type:

    /**
    * @type("Hardware")
    * @title("Hardware")
    * @description("Server Hardware")
    */
    public $hardware;
    
    /**
    * @type("Platform")
    * @title("Platform")
    * @description("OS Platform")
    */
    public $platform;
    

This completes development of the backend scripts implementing the resource model that looks as follows:

../../../../_images/basic-ide-types-diagram.png

Conclusion

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