Updated on 2023-11-15 GMT+08:00

Getting Started

Introduction

This chapter uses the Magento e-commerce platform as an example to show how to deploy applications by calling AOS APIs.

In this tutorial, you will create a Magento e-commerce platform as shown in Figure 1.

Figure 1 Magento e-commerce platform

For details about how to call APIs, see Calling APIs.

Procedure

  1. Call the API for creating a template to upload the public template Magento E-commerce Application (e-business-app).
  2. Call the API for querying the input parameters of a template to view the input parameters of the template. Some of these parameters need to be configured during stack creation.
  3. Call the API for creating a stack to create a Magento e-commerce platform stack.
  4. Call the API for querying a stack to check whether the stack has been successfully created.
  5. Call the API for querying a stack output to view the stack output and the created Magento e-commerce platform.

Orchestrating and Deploying the Magento E-commerce Platform

  1. Call the API for creating a template to upload the public template Magento E-commerce Application (e-business-app).

    1. Log in to the AOS console. In the navigation pane on the left, choose Template Market > Public Templates. In the Industry Templates area, click Magento E-commerce Application to view the template details. Click Download Template to save the template file, for example, e-business-app.yaml, to the local host.
      Figure 2 Selecting the public template
    2. Edit the Magento E-commerce Application template locally and save it to the e-business-app.yaml file. Upload the template file e-business-app.yaml to any path on the server where the curl command is executed, for example, /home/paas.
    3. Access the path of the template file on the server, call the API for creating a template, and upload the public template Magento E-commerce Application.
      curl -k -X POST -H "X-Auth-Token: ${Token}" -F "resource={\"name\": \"aos-magento\",\"description\":\"aos magento template\",\"version\": \"1.9\"}" -F "archive_content=@e-business-app.yaml" -i "${AOS_Endpoint}/v2/templates"

      Specify the following parameters:

      • Token: value of x-subject-token in the response header for obtaining a user token in making an API request
      • name: template name
      • description: template description
      • version: template version
      • archive_content: Template package to be uploaded. If you did not access the path of the template file when running the curl command, add a path to this parameter in the command. For example, if the template file e-business-app.yaml is in the /home/paas path, the command should be archive_content=@/home/paas/e-business-app.yaml.
      • AOS_Endpoint: {URI-scheme} :// {Endpoint} , for example, https://aos.cn-north-4.myhuaweicloud.com

      Response Body

      HTTP/1.1 100 Continue
      ......
      {
        "id": "10185add-acde-cc18-b8dd-b3a87a1f484c"
      }p

      Record the template ID 10185add-acde-cc18-b8dd-b3a87a1f484c, which will be used in stack creation.

  2. Call the API for querying the input parameters of a template to view the input parameters of the template. Some of these parameters need to be configured during stack creation.

    curl -k -X GET -H "X-Auth-Token: ${Token}" "${AOS_Endpoint}/v2/templates/${TEMPLATE_ID}/inputs"

    Specify the following parameters:

    • Token: value of x-subject-token in the response header for obtaining a user token in making an API request
    • TEMPLATE_ID: template ID obtained in Step 1.3
    • AOS_Endpoint: {URI-scheme} :// {Endpoint} , for example, https://aos.cn-north-4.myhuaweicloud.com

    Response Body

    {
     .......
      "app-name": {
        "default": "magento",
        "description": "application name",
        "immutable": false,
        "label": "magento",
        "usednodes": [
          "magento",
          "magento-service"
        ]
      },
      "magento-EIP": {
        "description": "external access address of the Magento service",
        "immutable": false,
        "label": "magento",
        "usednodes": [
          "magento-config"
        ]
      },
      "magento-EPORT": {
        "default": 32080,
        "description": "external listening port of the Magento service",
        "immutable": false,
        "label": "magento",
        "type": "integer",
        "usednodes": [
          "magento-config",
          "magento-service"
        ]
      },
      "mysql-database": {
        "default": "magento",
        "description": "MySQL database created for the Magento service"
        "immutable": false,
        "label": "mysql",
        "usednodes": [
          "mysql-conf"
        ]
      },
      "mysql-password": {
        "default": "******",
        "description": "password of the MySQL database",
        "immutable": false,
        "label": "mysql",
        "usednodes": [
          "mysql-conf"
        ]
      },
      "mysql-port": {
        "default": 3306,
        "description": "listening port of the MySQL database",
        "immutable": false,
        "label": "mysql",
        "type": "integer"
      },
     ......
    }

    When creating a stack from this template, you can configure the parameters in bold in the preceding script. These parameters define the template attributes. Default values will be used for unset parameters. In this example, you will need to change the values of magento-EIP and magento-EPORT, and retain the default values of other parameters.

  3. Call the API for creating a stack to create a Magento e-commerce platform stack.

    curl -k -X POST -H "X-Auth-Token: ${Token}" -d '{
      "name": "magento-stack-test",
      "project_id": "c51567523b744d098a8a81ede51894ac",
      "template_id": "'"${TEMPLATE_ID}"'",
      "force": true,
      "cluster_id": "f2637630-5d83-11e8-a6de-0255ac101a0c",
      "namespace": "default",
      "inputs_json": {
        "magento-EIP": "*.*.78.102",
        "magento-EPORT": 32080
      },
      "action_parameters": {
        "auto_create": true,
        "timeout": 20
      }
    }' "${AOS_Endpoint}/v2/stacks"

    Create an available container cluster which includes a node of 2 vCPUs and 4 GB of memory. The node should also be bound with an elastic IP.

    Specify the following parameters:

    • Token: value of x-subject-token in the response header for obtaining a user token in making an API request
    • name: Enter a stack name, for example, magento-stack-test.
    • project_id: project ID. For details about how to obtain a project ID, see Obtaining a Project ID.
    • cluster_id: cluster ID To obtain the cluster ID, log in to the CCE console. In the navigation pane on the left, select Resource Management > Clusters, and click the target cluster name to enter its details page. Obtain the cluster ID in the Basic Information area.
    • namespace: an available namespace in the cluster To obtain a namespace name, log in to the CCE console. In the navigation pane on the left, select Resource Management > Namespaces. Obtain namespace names on the page displayed.
    • magento-EIP: elastic IP address of the node To obtain an EIP, log in to the CCE console. In the navigation pane on the left, select Resource Management > Nodes, and click the target node name to enter its details page. Obtain the node's EIP in the Basic Information area.
    • magento-EPORT: Node port. Enter an integer ranging from 30000 to 32767 and ensure that the value is unique in the cluster. You can retain the default value 32080.
    When the stack is successfully created, the stack information is returned. Record the stack ID, which will be used in the following steps.
    {
        "force": true,
        "guid": "0cec7a8c-5fc1-11e8-a532-0242ac110007",
        "namespace": "default",
        "project_id": "c51567523b744d098a8a81ede51894ac",
        "cluster_name": "k8s19-lm-do-not-delete",
        "cluster_id": "f2637630-5d83-11e8-a6de-0255ac101a0c",
        "domain_id": "b0148a2cb4f347289b477bab429e48e7",
        "name": "magento-stack-test",
        "description": "",
        "status": "",
        "template_id": "10185add-acde-cc18-b8dd-b3a87a1f484c",
        "previous_template_id": "",
        "template_name": "aos-magento",
        "inputs_json": "......"
         ...
    }

  1. Call the API for querying a stack to check whether the stack has been successfully created.

    curl -k -X GET -H "X-Auth-Token: ${Token}" "${AOS_Endpoint}/v2/stacks/${STACK_ID}"

    Specify the following parameters:

    • Token: value of x-subject-token in the response header for obtaining a user token in making an API request
    • STACK_ID: stack ID obtained in Step 3
    • AOS_Endpoint: {URI-scheme} :// {Endpoint} , for example, https://aos.cn-north-4.myhuaweicloud.com

    Response Body

    {
        "force": true,
        "guid": "0cec7a8c-5fc1-11e8-a532-0242ac110007",
        "namespace": "default",
        "project_id": "c51567523b744d098a8a81ede51894ac",
        "cluster_name": "k8s19-lm-do-not-delete",
        "cluster_id": "f2637630-5d83-11e8-a6de-0255ac101a0c",
        "domain_id": "b0148a2cb4f347289b477bab429e48e7",
        "name": "magento-stack-test",
        "description": "",
        "status": "Running",
        "template_id": "10185add-acde-cc18-b8dd-b3a87a1f484c",
        "previous_template_id": "",
        "template_name": "aos-magento",
        "inputs_json":......
    }

    If the returned value of the status field is Running, the stack is successfully created. If the stack creation fails, you can view the log through subObjectStatuses.

  2. Call the API for querying stack output to view the stack output and the created Magento e-commerce platform.

    curl -k -X GET -H "X-Auth-Token: ${Token}" "${AOS_Endpoint}/v2/stacks/${STACK_ID}/outputs"

    Specify the following parameters:

    • Token: value of x-subject-token in the response header for obtaining a user token in making an API request
    • STACK_ID: stack ID obtained in Step 3
    • AOS_Endpoint: {URI-scheme} :// {Endpoint} , for example, https://aos.cn-north-4.myhuaweicloud.com

    Response Body

    {
        "outputs": {
            "ingress-admin_password": {
                "value": "******",
                "description": "Password of super user."
            },
            "magento-addr": {
                "value": "http://*.*.78.102:32080",
                "description": "Access URL for magento service."
            },
            "magento-admin_username": {
                "value": "admin",
                "description": "Super user name."
            }
        }
    }
    To access the Magento e-commerce platform, visit http://magento-EIP:magento-EPORT, for example, http://*.*.78.102:32080.
    Figure 3 Accessing the Magento e-commerce platform