Application Packaging Standard

Last updated 14-Nov-2018

Get Resource Consumption

Let us suppose a provider has a 3rd party system that accounts the provider’s various resources. The system must also account application resources provided to the customers through the platform.

To achieve the goal, the system can use the typical APS REST operations under the provider credentials as explained in this document.

To use the provider resources, a customer must subscribe to at least one service template and get a subscription containing a list of limited resources. It means the main objects for the accounting system are the subscriptions with the resources inside them as well as the related objects, such as service templates and customers.

List all Subscriptions

A subscription is presented by an APS resource based on the platform subscription APS type whose properties, relationship, and operations the system should use.

The following command retrieves all subscriptions except for the provider’s built-in subscription whose ID is 1.

Request:

GET /aps/2/collections/subscriptions?ne(subscriptionId,1)

Sample response:

[
  {
    "aps": {
      "type": "http://parallels.com/aps/types/pa/subscription/1.0",
      "id": "0ad9545b-03fe-4421-8179-d174e58d2e93",
      "status": "aps:ready",
      "revision": 3,
      "modified": "2016-11-07T15:40:33Z"
    },
    "description": "",
    "disabled": false,
    "name": "Generic",
    "serviceTemplateId": 6,
    "subscriptionId": 13,
    "trial": false
  },
  {
    "aps": {
      "type": "http://parallels.com/aps/types/pa/subscription/1.0",
      "id": "fd50635c-e9be-494b-887c-e3bcaa86450e",
      "status": "aps:ready",
      "revision": 3,
      "modified": "2016-11-15T09:58:34Z"
    },
    "description": "",
    "disabled": false,
    "name": "Home Dashboard",
    "serviceTemplateId": 5,
    "subscriptionId": 14,
    "trial": false
  },
  {
    "aps": {
      "type": "http://parallels.com/aps/types/pa/subscription/1.0",
      "id": "d1d637c9-4b67-4045-be19-2f2f0f513288",
      "status": "aps:ready",
      "revision": 3,
      "modified": "2016-11-15T10:14:14Z"
    },
    "description": "",
    "disabled": false,
    "name": "Testing Offers",
    "serviceTemplateId": 7,
    "subscriptionId": 16,
    "trial": false
  }
]

Select Subscriptions

Select Subscriptions by Service Template

The serviceTemplateId property in the subscriptions allows selecting all subscriptions created from a certain service template. The following request retrieves all subscriptions created from the service template whose ID in the platform is 7.

Request:

GET /aps/2/collections/subscriptions?eq(serviceTemplateId,7)

The following response shows that only one subscription is based on the specified service template:

[
  {
    "aps": {
      "type": "http://parallels.com/aps/types/pa/subscription/1.0",
      "id": "d1d637c9-4b67-4045-be19-2f2f0f513288",
      "status": "aps:ready",
      "revision": 3,
      "modified": "2016-11-15T10:14:14Z"
    },
    "description": "",
    "disabled": false,
    "name": "Testing Offers",
    "serviceTemplateId": 7,
    "subscriptionId": 16,
    "trial": false
  }
]

Select Subscriptions by Account

Use the select RQL function to list all subscriptions along with the linked accounts, but show only the account companyName:

Request:

GET /aps/2/collections/subscriptions?select(account.companyName)

In the response, you will find not only the properties of every subscription but also the name of the account company that is the owner of the subscription and is linked with the latter:

[
  {
    "aps": {
      "type": "http://parallels.com/aps/types/pa/subscription/1.0",
      "id": "0ad9545b-03fe-4421-8179-d174e58d2e93",
      "status": "aps:ready",
      "revision": 3,
      "modified": "2016-11-07T15:40:33Z"
    },
    "description": "",
    "disabled": false,
    "name": "Generic",
    "serviceTemplateId": 6,
    "subscriptionId": 13,
    "trial": false,
    "account": {
      "aps": {
        "type": "http://parallels.com/aps/types/pa/account/1.2",
        "id": "0e16f418-704c-41d4-b30e-39b048e4b82e",
        "status": "aps:ready",
        "revision": 2,
        "modified": "2016-10-21T13:25:26Z"
      },
      "companyName": "1st APS inc."
    }
  },
  ...
]

To list the subscriptions of a certain customer, filter the subscriptions by the account.aps.id or account.companyName property as in the following example.

Request:

GET /aps/2/collections/subscriptions?select(account.companyName),eq(account.companyName,1st%20APS%20inc.)

The response contains the subscriptions of the specified company:

[
  {
    "aps": {
      "type": "http://parallels.com/aps/types/pa/subscription/1.0",
      "id": "0ad9545b-03fe-4421-8179-d174e58d2e93",
      "status": "aps:ready",
      "revision": 3,
      "modified": "2016-11-07T15:40:33Z"
    },
    "serviceTemplateId": 6,
    "subscriptionId": 13,
    "trial": false,
    "description": "",
    "disabled": false,
    "name": "Generic",
    "account": {
      "aps": {
        "type": "http://parallels.com/aps/types/pa/account/1.2",
        "id": "0e16f418-704c-41d4-b30e-39b048e4b82e",
        "status": "aps:ready",
        "revision": 2,
        "modified": "2016-10-21T13:25:26Z"
      },
      "companyName": "1st APS inc."
    }
  },
  {
    "aps": {
      "type": "http://parallels.com/aps/types/pa/subscription/1.0",
      "id": "d1d637c9-4b67-4045-be19-2f2f0f513288",
      "status": "aps:ready",
      "revision": 3,
      "modified": "2016-11-15T10:14:14Z"
    },
    "description": "",
    "disabled": false,
    "name": "Testing Offers",
    "serviceTemplateId": 7,
    "subscriptionId": 16,
    "trial": false,
    "account": {
      "aps": {
        "type": "http://parallels.com/aps/types/pa/account/1.2",
        "id": "0e16f418-704c-41d4-b30e-39b048e4b82e",
        "status": "aps:ready",
        "revision": 2,
        "modified": "2016-10-21T13:25:26Z"
      },
      "companyName": "1st APS inc."
    }
  },
  {
    "aps": {
      "type": "http://parallels.com/aps/types/pa/subscription/1.0",
      "id": "f95113fb-9b24-4669-8b26-17cb237fd79e",
      "status": "aps:ready",
      "revision": 3,
      "modified": "2016-11-15T12:53:27Z"
    },
    "description": "",
    "disabled": false,
    "name": "Offer-Counter-Users",
    "serviceTemplateId": 8,
    "subscriptionId": 17,
    "trial": false,
    "account": {
      "aps": {
        "type": "http://parallels.com/aps/types/pa/account/1.2",
        "id": "0e16f418-704c-41d4-b30e-39b048e4b82e",
        "status": "aps:ready",
        "revision": 2,
        "modified": "2016-10-21T13:25:26Z"
      },
      "companyName": "1st APS inc."
    }
  }
]

List Resource Usage

Since the platform subscription APS type implements the standard subscription APS type, consider both of them when seeking for a proper method or property as in the following case.

The standard subscription APS type defines the resources operation that lists all resources of a specified subscription with the limitation and actual usage for every resource. To get this data from one of the listed above subscriptions, run a REST request similar to the following:

Request:

GET /aps/2/resources/d1d637c9-4b67-4045-be19-2f2f0f513288/resources

The response shows the list of resources with the limit, usage, and unit properties in each of them as in this example:

[
  {
    "id": "1000072",
    "title": "OCU - App REF",
    "apsId": "1b7adee2-3121-4639-adde-5a85a6866da1",
    "apsType": "http://aps-standard.org/samples/offer-counter-user/cloud/1.0",
    "usage": 1,
    "limit": 1,
    "unit": "unit"
  },
  {
    "id": "1000073",
    "title": "OCU - Silver config",
    "apsId": "65e1bb24-f4bb-4a48-9d7d-c8967aedc978",
    "apsType": "http://aps-standard.org/samples/offer-counter-user/offer/1.0",
    "usage": 1,
    "limit": 10,
    "unit": "unit"
  },
  {
    "id": "1000074",
    "title": "OCU - Gold config",
    "apsId": "aad24762-2b28-44ff-ae96-4284b7d28940",
    "apsType": "http://aps-standard.org/samples/offer-counter-user/offer/1.0",
    "usage": 1,
    "limit": 5,
    "unit": "unit"
  },
  {
    "id": "1000075",
    "title": "OCU - VPS management",
    "apsType": "http://aps-standard.org/samples/offer-counter-user/context/1.0",
    "usage": 1,
    "limit": 1,
    "autoprovisioning": true,
    "unit": "unit"
  },
  {
    "id": "1000076",
    "title": "OCU - VPS",
    "apsType": "http://aps-standard.org/samples/offer-counter-user/vps/1.0",
    "usage": 2,
    "unit": "unit"
  },
  {
    "id": "1000077",
    "title": "OCU - CPU cores",
    "apsType": "http://aps-standard.org/samples/offer-counter-user/context/1.0",
    "property": "cpuusagetotal",
    "usage": 32,
    "limit": 100,
    "unit": "unit"
  },
  {
    "id": "1000078",
    "title": "OCU - RAM space",
    "apsType": "http://aps-standard.org/samples/offer-counter-user/context/1.0",
    "property": "memoryusagetotal",
    "usage": 3555328,
    "limit": 104857600,
    "unit": "KB"
  },
  {
    "id": "1000079",
    "title": "OCU - Disk space",
    "apsType": "http://aps-standard.org/samples/offer-counter-user/context/1.0",
    "property": "diskusagetotal",
    "usage": 138412032,
    "limit": 1048576000,
    "unit": "KB"
  }
]

The example demonstrates all possible kinds of platform resources presenting APS resources:

  • Resources of the Application Service resource class contain neither the apsId nor the property parameter. Such a resource maps to an APS type and presents the usage of all APS resources created from that APS type in the subscription. In the above example, the OCU - VPS management and OCU - VPS are the resources of this kind.
  • Resources of the Application Service Reference resource class contain the apsId parameter. Such a resource links to a provider’s shared APS resource whose APS ID equals the apsId parameter. In the example, the subscription contains the OCU - Silver config and OCU - Gold config resources referring to the respective APS resources shared for all customers. A resource of this kind shows the usage of the corresponding shared APS resource in the subscription.
  • Resources of the Application Counter resource class contain the property parameter. Such a resource presents an APS counter structure contained in one of the APS resources mapped to the Application Service resource class. In the example, the OCU - CPU cores, OCU - RAM space, and OCU - Disk space are the resources of this kind. They show the usage of the resources the platform polls periodically. Usually, providers sell such resources on the pay-as-you-go basis.