Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Create a virtual image of an operating system. As you set up a PHP runtime here, Ubuntu is recommended.

  2. Execute the following commands on the VM instance:

    TaskCommand

    Login to the instance using SSH and get root access to the instance

    sudo su
    Install zip and unzip
    apt-get install zip unzip
    Create a new directory named bin in the home directory
    mkdir ~/bin
    Download the config.sh to the ~/bin directory and make it executable. As this is a puppet-based configuration, the config.sh script is used to install the puppet agent to the instance. This puppet agent communicates with the puppet master and configures the required environment using puppet scripts. You configure the puppet master at the time the App Factory is installed. The config.sh script also configures the init.sh file to be executed automatically during the startup of the instance.
    chmod +x config.sh
    Download the init.sh to the ~/bin directory and make it an executable. 

    This init.sh script,

    • Starts the puppet agent
    • The cartridge agent needs several parameters from the Amazon EC2 metadata service as payload to communicate with the Stratos manager in the App Factory. The metadata service is used for virtual machine instances to retrieve instance-specific data. It supports two sets of APIs: an OpenStack metadata API and an EC2-compatible API. Instances access the metadata service on http://169.254.169.254
      Downloads the launch parameters from the Amazon EC2 metadata service using the following command: wget http://169.254.169.254/latest/user-data -O /tmp/payload/launch-params. 

    • Configurs the host file of the instance with the required host entries
    • Downloads the cartridge agent from the puppet master in the App Factory
     
    chmod +x init.sh
    Download the stratos_sendinfo.rb file to the ~/bin directory. 
    Create a directory named puppetinstall inside the ~/bin directory.mkdir ~/bin/puppetinstall
    Download the puppetinstall file to ~/bin/puppetinstall/ and make it an executable.chmod +x ~/bin/puppetinstall/puppetinstall
    In the above script file, set the TIMEZONE value that matched the timezone set in the puppet master using the following command. In this case, we are setting the timezone to Etc/UTC.sed -i 's:^TIMEZONE=.*$:TIMEZONE=\"Etc/UTC\":g' ~/bin/puppetinstall/puppetinstall
    Create a directory named apache-stratos-cartridge-agent in /mnt/
    mkdir /mnt/apache-stratos-cartridge-agent/

    Download the cartridge-agent.sh file to /mnt/apache-stratos-cartridge-agent/ and make it an executable. This script is used to configure and start the cartridge agent.

    chmod +x /mnt/apache-stratos-cartridge-agent/cartridge-agent.sh
    Execute the config.sh file using the following command:
    ~/bin/config.sh

    Provide the following details when prompted:

    Code Block
    This script will install and configure puppet agent, do you want to continue [y/N] y
    Please provide stratos service-name: php
    Please provide puppet master IP: <IP-Of-AppFactoryServer>
    Please provide puppet master hostname [puppet.test.org]: puppet.test.org
  3. In OpenStack, create a snapshot image of the runtime instance that you configured in the IaaS. Note that an ID is generated for the snapshot. We use that in step 5 below.

  4. Apache Stratos is set up at the time you install the App Factory. Log in to the Stratos manager consoles of all three stratos instances (dev, test, prod) as admin, using the following URLs.

  5. In the Stratos manager console, go to Configure Stratos > Partitions and add the partition definition. Following JSON object shows a sample partition definition.

    Code Block
    {
             "id": "P1",
             "provider": "openstack",
             "property": [ {
                     "name": "region",
                     "value": "RegionOne"
             } ]
    }

     

  6. Add this runtime configuration to the App Factory by saving it as an XML file in <AF_HOME>/repository/deployment/server/runtimes/. As hot deployment is enabled, it will be deployed automatically. 

    Code Block
    <Runtime>
        <Runtime>php</Runtime>
        <DeployerClassName>org.wso2.carbon.appfactory.jenkins.deploy.JenkinsArtifactDeployer</DeployerClassName>
        <PAASArtifactStorageURLPattern>{@stage}/as</PAASArtifactStorageURLPattern>
        <AliasPrefix>{@appName}</AliasPrefix>
        <CartridgeTypePrefix>php</CartridgeTypePrefix>
        <DeploymentPolicy>af-deployment</DeploymentPolicy>
        <AutoscalePolicy>economy</AutoscalePolicy>
        <SubscribeOnDeployment>true</SubscribeOnDeployment>
        <UndeployerClassName>org.wso2.carbon.appfactory.jenkins.deploy.JenkinsArtifactUndeployer</UndeployerClassName>
    </Runtime>

You have now created an virtual image of a PHP runtime. At the time users create new PHP applications in the App Factory, this virtual image is used to spawn new PHP runtime instances in the Cloud environment. Next, let's configure Apache Stratos as the PaaS environment for the App Factory to work with the Cloud instance.

Configuring Apache Stratos in the App Factory

Apache Stratos is an extensible PaaS framework that helps you run Apache Tomcat, PHP, and MySQL applications. You can extend it to support many more environments on all popular Cloud infrastructures. For developers, Stratos provides a cloud-based environment for developing, testing, and running scalable applications.

  1. Go to Configure Stratos > Autoscale policies in the Stratos manager console and add the autoscale policy. This policy defines how to scale up and down the resources of your Cloud instance depending on different conditions, demand and load. The following JSON object shows a sample autoscale policyThe elements of the above configuration are described below:

    ElementDescriptionData typeDefault value
    <Runtime>Name of the runtime that you wish to addString 
    <DeployerClassName>The fully qualified class name of the application deployerStringDefault is org.wso2.carbon.appfactory.jenkins.deploy.JenkinsArtifactDeployer
    <PAASArtifactStorageURLPattern>

    The artifact storage URL where the application artifact is stored. The URL is resolved using the stage of the application in the runtime.

    {@stage}- resolves the current stage of the application (e.g., Development, Testing, Production etc.) as the runtime prefix.
    String

    <@stage>/as

    'as' stands for Application Server.
    <AliasPrefix>Prefix of the aliasString 
    <CartridgeTypePrefix>Prefix of the cartridge typeString 
    <DeploymentPolicy>Deployment policy used for subscriptionStringaf-deployment
    <AutoscalePolicy>Autoscale policy used for subscriptionStringeconomy
    <SubscribeOnDeployment>Whether subscription is required at the time of deployment or not.BooleanFalse
    <UndeployerClassName>Fully qualified class name of the application un-deployerString

    org.wso2.carbon.appfactory.deployers.

    JenkinsS tratosUndeployer

You have now created an virtual image of a PHP runtime. At the time users create new PHP applications in the App Factory, this virtual image is used to spawn new PHP runtime instances in the Cloud environment. Next, let's configure Apache Stratos as the PaaS environment for the App Factory to work with the Cloud instance.

Configuring Apache Stratos in the App Factory

Apache Stratos is an extensible PaaS framework that helps you run Apache Tomcat, PHP, and MySQL applications. You can extend it to support many more environments on all popular Cloud infrastructures. For developers, Stratos provides a cloud-based environment for developing, testing, and running scalable applications.

  1. Apache Stratos is set up at the time you install the App Factory. Log in to the Stratos manager consoles of all three stratos instances (dev, test, prod) as admin, using the following URLs.

  2. In the Stratos manager console, go to Configure Stratos > Partitions and add the partition definition. Following JSON object shows a sample partition definition.

    Code Block
    {
         "    "id": "economyP1",
         "loadThresholds": {           "requestsInFlight"provider": {
    "openstack",
             "averageproperty": "300",[ {
             "gradient": "10",
              "secondDerivativename": "0.2"
      region",
            },           "memoryConsumptionvalue": {"RegionOne"
             }   "average": "80",]
    }

     

  3. Go to Configure Stratos > Autoscale policies in the Stratos manager console and add the autoscale policy. This policy defines how to scale up and down the resources of your Cloud instance depending on different conditions, demand and load. The following JSON object shows a sample autoscale policy.

    Code Block
    {
         "id": "economy",
         "gradientloadThresholds": {
    "10",          "secondDerivativerequestsInFlight": {
    "0.2"          "average": "300",
              "gradient": "10",
              "secondDerivative": "0.2"
               },
              "loadAveragememoryConsumption": {
                "average": "60080",
               "gradient": "2010",
             "secondDerivative": "0.2"
           },
         }
    }  "loadAverage": {
             "average": "600",
             "gradient": "20",
             "secondDerivative": "0.2"
          }
         }
    }
  4. Similarly, go to Configure Stratos > Deployment policies and add the deployment policy. The following JSON object shows a sample deployment policy.

    Code Block
    {
       "id": "deployp",
       "partitionGroup": {
         "id": "openstack",
         "partitionAlgo": "one-after-another",
         "partition": [
           {
             "id": "P1",
             "partitionMax": "10",
             "partitionMin": "2"
           }
         ]
       }
    }

     

  5. Go to Configure Stratos > Cartridges and add the cartridge definition. The following JSON object shows a sample cartridge definition for development environment.

    • Please change the placeholders with actual values. 
    • In this configuration, the cartridge type should be the concatenation of the CartridgeTypePrefix of the runtime and the environment type of the cartridge. The CartridgeTypePrefix is an element of the runtime configuration defined below. For example, if the CartridgeTypePrefix is Windows, then the cartridge type of development environment is windowsdevelopment.
    • The ImageId should be the ID of the image that was created when creating a snapshot image of the runtime in the IaaS. 
      Anchor
      step5
      step5
    Code Block
    {
        "type": "php",
          "provider": "apache",
          "host": "stratos.org",
          "displayName": "PHP",
          "description": "PHP Cartridge",
          "version": "7",
          "multiTenant": "false",
          "portMapping": [
             {
                "protocol": "http",
                "port": "80",
                "proxyPort": "8280"
             },
             {
                "protocol": "https",
                "port": "443",
                "proxyPort": "8243"
             }
           ],
        "deployment":{
        }, 
        "iaasProvider":[
            {
                "type":"openstack",
                "imageId":"RegionOne/58746cf5-2d59-4a6b-9e7c-9a580c8a242d",
                "maxInstanceLimit":"4",
                "property":[
                    {
                        "name": "instanceType",
                 	    "value": "RegionOne/3"
                    },
                    {
                        "name":"keyPair",
                        "value":"appfackey"
                    }
                ]
            }
        ]
    }

    The elements of the above configuration are described below:

    ElementDescriptionData typeDefault value<Runtime>Name of the runtime that you wish to addString <DeployerClassName>The fully qualified class name of the application deployerStringDefault is org.wso2.carbon.appfactory.jenkins.deploy.JenkinsArtifactDeployer<PAASArtifactStorageURLPattern>

    The artifact storage URL where the application artifact is stored. The URL is resolved using the stage of the application in the runtime.

    {@stage}- resolves the current stage of the application (e.g., Development, Testing, Production etc.) as the runtime prefix.String

    <@stage>/as

    'as' stands for Application Server.<AliasPrefix>Prefix of the aliasString <CartridgeTypePrefix>Prefix of the cartridge typeString <DeploymentPolicy>Deployment policy used for subscriptionStringaf-deployment<AutoscalePolicy>Autoscale policy used for subscriptionStringeconomy<SubscribeOnDeployment>Whether subscription is required at the time of deployment or not.BooleanFalse<UndeployerClassName>Fully qualified class name of the application un-deployerString

    org.wso2.carbon.appfactory.deployers.

    JenkinsS tratosUndeployer