< Previous | Next >

Lesson 2: Creating component processes

Component processes describe automated tasks that run on components. Component processes can deploy, install, uninstall, update, or run other tasks on a component.

About this task

There are three types of processes:
  • Generic processes run outside the context of components or applications. Generic processes are shown on the top-level Processes tab.
  • Application processes run within the context of applications. In many cases, application processes call component processes. For example, an application process can call the component processes that deploy those components.
  • Component processes run tasks on a single component, such as deploying it, uninstalling it, or running configuration tasks on it.

Processes are a list of steps and connections between those steps. Each step is an individual command that runs on a target computer. Steps can manipulate files, run system commands, download files, and run programs. Plug-ins contribute most of these steps; plug-ins are available that work with many different types of software. For information about steps that are provided by plug-ins, see the documentation for the individual plug-in on IBM® developerWorks®: UrbanCode Deploy Plug-ins.

Each component must have at least one component process to deploy or install the component. In this lesson, you create a deployment process for each of the three components. Later, you create an application process that calls these component processes to deploy each component.

Creating a component process for the web component

The component process for the web component downloads the most recent version of the component artifacts and puts those artifacts in the correct folder.

About this task

Follow these steps to create the component process that deploys the web component:

Procedure

  1. From the Components tab, click the JPetStore-WEB component.
  2. Click Processes and then click Create Process.
  3. In the Create Process window, specify the name to be Deploy web component.
  4. In the Process Type list, select Deployment. This list has other options for processes that uninstall or configure components.
  5. Accept the default values for the other properties and click Save.
  6. From the list of processes, click the new process. The process opens in the process editor. This editor shows the steps in the process in a graphical form, as a flowchart. The Start and Finish boxes represent the beginning and the end of the process. From here, you add steps to the process and link them between the Start and Finish steps to show the order of the steps.
  7. Add a step to clean any files out of the working directory. The process runs within a working directory. To ensure that you are using the most recent version of the files in the web component, run a command to clean the working directory:
    1. At the left of the process editor, under Step Palette, expand Utilities > FileUtils. The Step Palette menu shows the available steps. You can explore the trees to find steps, or you can type into the search box at the top of the window.
    2. Under the FileUtils tree item, click and drag the Delete Files and Directories step to the process editor. The Edit Properties window opens, showing the properties for the step. Some of these properties are unique to the step and others are the same for all steps.
    3. In the Name field, specify the name to be Clean working directory.
    4. In the Base Directory field, specify a single period (.).
    5. In the Include field, specify an asterisk (*).
    6. Accept the defaults for the other properties and then click OK.
    The new step appears as a box in the process editor. Later, you connect this step to the other steps in the process. The process editor looks like the following figure:
    The new process with one step in the flow
  8. Add a step to download the latest version of the component artifacts. The Download Artifacts step is used in most deployment processes. This step downloads the specified version of the component artifacts to the target computer. When you run the process, you will specify whether to use the most recent version of the component artifacts or a specific version.
    1. Under Step Palette, expand Repositories > Artifact > IBM UrbanCode Deploy and drag the Download Artifacts step to the process editor.
    2. In the Edit Properties window, accept the default values and then click OK.
  9. Add a step to remove the old web content from the server:
    1. Expand Utilities > FileUtils and drag another Delete Files and Directories step to the process editor.
    2. In the Edit Properties window, specify the name to be Remove old content.
    3. In the Base Directory field, specify the following directory:
      webapps/${p:environment/tomcat.contextroot}
      The variable represents the location where Tomcat stores your deployed files. You specify a value for this variable later.
    4. In the Include field, specify the following directory:
      images
    5. In the Working Directory field, specify the following variable:
      ${p:environment/tomcat.home}
      This variable represents the main folder of the Tomcat web server. You will specify a value for this variable later.
    6. Accept the default values in the other fields and click OK.
  10. Add a step to deploy the new content to the server. This step copies the component artifacts to the application server.
    1. Expand Utilities > FileUtils and drag a Move Directory step to the process editor.
    2. In the Edit Properties window, specify the name to be Deploy new content.
    3. In the Source Directory field, specify a single period (.).
    4. In the Destination Directory field, specify the following directory:
      ${p:environment/tomcat.home}/webapps/${p:environment/tomcat.contextroot}/
    5. In the Include Files field, specify the following code:
      images/*
    6. Accept the default values in the other fields and click OK.
    Now the process has four steps, as in the following figure:
    The four steps of the process, which are placed in order between the Start and Finish steps
  • Each step has three icons at the upper right corner of the step. The Edit icon opens the same Edit Properties window that opens when you create the step. The X icon deletes the step. The Copy icon copies the step to the Clipboard folder so you can duplicate it.

    Also, if you move the mouse over a step, an arrow icon appears over the center of the step. This icon is used to create links between steps.

    Clicking the arrow button at the center of the step

    1. Connect the steps in the order that they run:
      1. Move the mouse over the Start step, and click and drag the arrow icon to the Clean working directory step. The arrow between these steps represents the flow of activity from one step to another, as in the following figure:
        The link that connects the Start step to the Clean working directory step
      2. Similarly, drag an arrow from the Clean working directory step to the Download Artifacts step.
      3. Drag an arrow from the Download Artifacts step to the Remove old content step.
      4. Drag an arrow from the Remove old content step to the Deploy new content step.
      5. Drag an arrow from the Deploy new content step to the Finish step.
      You can connect steps in a sequence like these steps, or you can run steps in parallel with each other by creating more links. However, processes always start with the Start step and end with the End step. The sequence of steps in this process is as follows:
      1. Start
      2. Clean working directory
      3. Download Artifacts
      4. Remove old content
      5. Deploy new content
      6. Finish
    2. Save the process by clicking the Save icon under Tools.

    Results

    The complete component process for the web component looks like the following figure:
    The complete component process, which removes the old version of the artifacts and deploys the new version to the application server

    Creating a component process for the application component

    The application component consists of a single WAR file. This component process downloads the most recent version of the WAR file, updates values in the file, and deploys the file on the application server.

    Procedure

    1. From the Components tab, click the JPetStore-APP component.
    2. Click Processes and then click Create Process.
    3. In the Create Process window, specify the name to be Deploy application component.
    4. In the Process Type list, select Deployment.
    5. Accept the default values for the other properties and click Save.
    6. From the list of processes, click the new process to open it in the process editor.
    7. Add a step to clean the working directory. As you did for the web component, add a Delete Files and Directories step named Clean working directory and specify a period in the Base Directory field and an asterisk in the Include field.
    8. Add a step to download the artifacts. As you did for the web component, add a Download Artifacts step and accept the default properties.
    9. Add a step to extract the WAR file. You must extract the WAR file so you can update a property file with the database connection information.
      1. In the list of available steps, expand the Utilities > FileUtils folder and drag an Unzip step to the process editor.
      2. Specify the name to be Expand WAR.
      3. In the Extract directory field, specify the following code:
        ./JPetStore_expanded
      4. In the .zip files field, specify the following file:
        JPetStore.war
      5. In the Include Files field, specify the following code:
        **/*
      6. Click OK.
    10. Add a step to update the property file with the location of the database:
      1. In the list of available steps, expand the Utilities > FileUtils folder and add an Update Java Properties File step to the process editor.
      2. Specify the name to be Update property file.
      3. In the Directory Offset field, specify the following folder:
        ./JPetStore_expanded/WEB-INF/classes/properties
      4. In the File Includes field, specify the following file:
        database.properties
      5. In the Add/Update properties field, specify the following code:
        url=${p:environment/db.url}
        This code updates the url property in the property file with the location of the database. The code ${p:environment/db.url} is a variable that represents the location of the database component when the application is deployed.
      6. Click OK.
    11. Add a step to update the WAR file with the new property file.
      1. From the list of available steps, expand the Utilities > FileUtils folder and add a Create .zip File step to the process editor.
      2. Specify the name to be Update WAR.
      3. In the .zip File Name field, specify the JPetStore.war file.
      4. In the Base Directory field, specify the following folder:
        ./JPetStore_expanded
      5. In the Include field, specify the following code:
        **/*
      6. Select the Update Existing check box.
      7. Click OK.
    12. Add a step to start Tomcat:
      1. In the list of available steps, expand the Application Server > Java > Tomcat folder and add a Start Tomcat step to the process editor. If this step is not in the tree, install the Tomcat plug-in as described in the Prerequisites for this tutorial.
      2. Accept the default name Start Tomcat.
      3. In the Launcher field, specify the following code:
        ${p:environment/tomcat.start}
        This code is another variable that represents the command to start Tomcat.
      4. In the Startup timeout (in seconds) field, specify 60.
      5. In the Port field, specify the port 8081.
      6. Click OK.
    13. Add a step to remove any previous versions of the application:
      1. In the list of available steps, expand the Application Server > Java > Tomcat folder and add an Undeploy Application step to the process editor.
      2. Accept the default name Undeploy Application.
      3. In the Tomcat Manager URL field, specify the following code:
        ${p:environment/tomcat.manager.url}
      4. In the Tomcat Manager User Name field, specify the user name for the Tomcat server. You specified this user name and its password in Configuring the agent and target system. If you used the code examples from that topic, the user name and password are tomcatmanager.
      5. In the Tomcat Manager Password field, specify the password for the Tomcat server.
      6. In the Context Name field, specify the following context name, including the preceding forward slash:
        /${p:environment/tomcat.contextroot}
        Ensure that you include a slash (/) before the variable.
      7. Click OK.
    14. Add a step to deploy the updated WAR file to the application server:
      1. In the list of available steps, expand the Application Server > Java > Tomcat folder and add a Deploy Application step to the process editor.
      2. Accept the default name Deploy Application.
      3. In the Tomcat Manager URL field, specify the following code:
        ${p:environment/tomcat.manager.url}
      4. In the Tomcat Manager User Name field, specify the user name for the Tomcat server.
      5. In the Tomcat Manager Password field, specify the password for the Tomcat server.
      6. In the Context Name field, specify the following context name:
        /${p:environment/tomcat.contextroot}
        Ensure that you include a slash (/) before the variable.
      7. In the War File Path field, specify the following path:
        ./JPetStore.war
      8. Click OK.
    15. Connect the steps in the following order:
      1. Start
      2. Clean working directory
      3. Download Artifacts
      4. Expand WAR
      5. Update Property File
      6. Update WAR
      7. Start Tomcat
      8. Undeploy Application
      9. Deploy Application
      10. Finish
    16. Change the conditional flag on the link between the Undeploy Application and Deploy Application steps to both by clicking the green check mark on the connection until it turns to a gray circle, as shown in the following figure:
      Clicking the green check mark between the Undeploy Application and Deploy Application steps to turn it to a gray circle
      Each connection from one step to another has a conditional flag. The conditional flag specifies a condition for the connection. Three conditional flags are available:
      • By default, the conditional flag on each connection is set to success, which is represented by a green check mark. The process follows these connections when the step succeeds.
      • The conditional flag fail is represented by a red dash (-). The process follows these connections when the step fails.
      • The conditional flag both is represented by a gray circle. The process follows these connections regardless of whether the step succeeded or failed.
      The Undeploy Application step fails if no previous versions of the application are installed. In this case, setting the conditional flag on the connection to both specifies that the process keeps running whether the step fails or succeeds.
    17. Save the process.

    Results

    The complete component process for the application component looks like the following figure:
    The complete component process that deploys the application

    Creating a component process for the database component

    The deployment process for the database component updates the database with sample values.

    Procedure

    1. From the Components tab, click the JPetStore-DB component.
    2. Click Processes and then click Create Process.
    3. In the Create Process window, specify the name to be Deploy database component.
    4. In the Process Type list, select Deployment.
    5. Accept the default values for the other properties and click Save.
    6. From the list of processes, click the new process to open it in the process editor.
    7. Add a step to download the artifacts. As you did for the web component, add a Download Artifacts step and accept the default properties.
    8. Add a step to update the database:
      1. In the list of available steps, expand the Database > DBUpgrader folder and add an Upgrade DB step to the process editor. If this step is not in the tree, install the database upgrade plug-in as described in the Prerequisites for this tutorial.
      2. In the Edit Properties window, in the Name field, accept the default value of Upgrade DB.
      3. In the Driver Classname field, specify the following class:
        com.mysql.jdbc.Driver
      4. In the DB Driver Jar field, specify the following path:
        lib/mysql-connector-java-5.1.20-bin.jar
        This file is provided in the source code for the component.
      5. In the URL field, specify the following variable:
        ${p:environment/db.url}
      6. In the User field, specify the user ID of the database user. If you used the examples in Configuring the agent and target system, the user ID is jpetstore.
      7. In the Password field, specify the password of the database user. If you used the examples in Configuring the agent and target system, the password is jppwd.
      8. In the SQL File path field, specify a single period: . .
      9. In the SQL File Include field, specify the extension *.xml .
      10. In the Current Version SQL field, specify the following SQL code:
        SELECT VER FROM DB_VERSION WHERE RELEASE_NAME = ?
      11. In the Delete Version SQL field, specify the following SQL code:
        DELETE FROM DB_VERSION WHERE RELEASE_NAME = ?
      12. In the Update Version SQL field, specify the following SQL code:
        INSERT INTO DB_VERSION (RELEASE_NAME,VER) VALUES(?,?)
      13. Click OK.
    9. Connect the steps in the following order:
      1. Start
      2. Download Artifacts
      3. Upgrade DB
      4. Finish
    10. Save the process.

    Results

    The complete component process for the database component looks like the following figure:
    The complete component process that deploys the database

    Lesson checkpoint

    In this lesson, you created component processes to deploy the components.

    You can use component processes to automate many different tasks on components. However, you generally do not run component processes directly; in most cases, you add them to application processes. Later in this tutorial, you will create an application process for these three component processes.

    Processes consist of steps, which are provided by plug-ins. To see a list of plug-ins that are available, and for documentation on those plug-ins and steps, see IBM developerWorks: UrbanCode Deploy Plug-ins.

    < Previous | Next >

    Feedback