Tutorial Overview

This tutorial guides a Vantiq developer through the steps that let you visualize, configure and deploy a Vantiq application to a multi-node Vantiq environment.

In this tutorial you will set up an environment containing three namespaces, import a project and use the Vantiq deployment tool to deploy the application to the target environment.
Then convert the application into a distributed application and deploy different resources to different nodes in the environment.

Part 1: Creating Two Additional Namespaces for Your Environment

Step 1: Creating Namespaces

This tutorial requires three namespaces. If you have not created new namespaces in Vantiq, you should first familiarize yourself with creating and managing
namespaces in the User and Namespace Administration Tutorial.

The first step in creating a new namespace is to change your Vantiq IDE environment to a namespace in which you have developer or higher privileges. From there, you will create more
namespaces as nodes within a deployment environment.

In the IDE, use the Administer button to select Namespaces to open the Namespaces pane. Use the Create New icon button (small plus sign in a circle at the top, right of the Namespaces pane) to create new namespaces with the following names: factory, store. You should be the admin of each of
these namespaces.

Namespaces

Change your Vantiq IDE to the factory namespace. Go to Administer > Advanced > Access Tokens. Click the Create New icon (“+” button) in the Access Tokens pane. Create an access token named “factoryToken” with expiration date in one year.
Then save the access token value somewhere so you can reference it in the next step of this tutorial.

Change to namespace store, and create an access token the same way. Save the access token for use in the next step.

Change back to your original developer namespace. This is the namespace where you will create your application, environment and deployment.

Step 2: Creating Nodes

Make sure you are in your assigned developer namespace, not the factory or store namespace. Go to Deploy > Nodes and click the Create New icon (“+” button) in the Nodes pane to create a new node named “factoryNode”. The URI of the node should match the URI of your current running IDE (e.g. https://dev.vantiq.com). Use “Credential Type” of “Access Token” and fill in the factoryToken value you saved from the previous step. Finally, add a property “type = factory” and save the Node.

factoryNode

Repeat the above steps to create a “storeNode” using the access token from the store namespace and create a new property “type = store”.
storeNode

The “type” property is required on both nodes for this tutorial application to work in later steps. You will use this property to partition resources onto different nodes.

Step 3: Creating the Environment

The next step is to create the environment that includes the factory node and the store node.
Go to Deploy > Environments and click the Create New icon (“+” button) in the environment list to create a new environment named “tutorialEnv”.

newEnvironment

When you click OK, the environment is created and a new IDE pane named “Environment: tutorialEnv” is automatically opened. In this environment detail pane, click the Add Nodes by Name button to display the Add Nodes dialog. Select both factoryNode and storeNode to be added to this environment.

addNodesByName

Don’t forget to save your environment. Now you should have an environment with two nodes in it.

environmentWithNodes

Part 2: Deploy a Project

Step 1: Import the deployment tutorial project

Click Projects > Import… and select Tutorials for the Select Import Type field. When the Select From Tutorials field appears, select Deployment Tutorial from the list.
Click the Import button and reload your browser.

Once project Deployment Tutorial is loaded, click on type com.vantiq.ims.Store in the Project Resource Graph and then click Add New Record to add a new record to type com.vantiq.ims.Store. Specify myStore for storeId and 100 for productCount.
Click on Add New Record to save the record. After that, use Show All Records from the Type:com.vantiq.ims.Store pane to verify there is a record for type com.vantiq.ims.Store.

AddNewRecord

Step 2: Test run the application

This sample application simulates inventory checking on a store and asks the factory for more products when inventory is low. The factory will also notify the store when more products are shipped.

On the project resource graph, click Client: DeploymentClient to open the client. Then run the client. Click the Order 1 and Order 10 buttons multiple times until the product count drops below 50. Wait for a few seconds, you should see a popup dialog saying “More products have arrived” and the product count reset to 100.

Step 3: Creating the deployment

The application is working fine and now it is time to deploy it to different namespaces.

Go to Deploy > Deployments, click the New button on the Deployments pane to create a new deployment with the following settings:

Name: testDeploy1
Project: DeploymentTutorial
Environment: tutorialEnv

newDeployment

Click on the Environment: tutorialEnv subtab to view the environment graph.

testDeploy2

factoryNode and storeNode are placed in a partition labeled “default”. This means all resources within the project will be deployed to every node in the environment. In this case, there are two nodes: storeNode and factoryNode.

Step 4: Customize the deployment

In Part 2, step 1, you manually added a new record of type com.vantiq.ims.Store to keep track of products in a store. You also need a way to do that after the type com.vantiq.ims.Store is deployed to a new node.

Click on the Settings subtab. Click the New Parameter “+” button for partition “default”. In the popup dialog, choose resource of type/com.vantiq.ims.Store and specify a record to be added to type com.vantiq.ims.Store on the target node by copying and pasting the following JSON:

[
    {
        "storeId": "newStore",
        "productCount": 101
    }
]

newParameter

The resulting parameter looks like this:

testDeploy3

Save the deployment.

Step 5: Deploy

Click on the Deploy Results subtab – note there is no result showing because you have not deployed anything yet. Click the Deploy button to start the deployment process. The deployment results will be updated.

testDeploy4

Click on “factoryNode” and “storeNode” in the results tree to view details of the deployment on each node.
Both nodes show exactly the same results because the whole project has been deployed to both of them.

Step 6: Verify Deployment

Switch to the factory namespace. Use the Projects menu button to select DeploymentTutorial_by_testDeploy1.
Test run Client: DeploymentClient as you have done in step 2. Verify the deployed application is working in this namespace.

Switch to the store namespace. You should be able to test run Client: DeploymentClient the same way.

Part 3: Convert to Distributed Application and Deploy to Multiple Nodes

Step 1: Clean up target namespaces using Undeploy.

Switch back to DeploymentTutorial namespace and find your testDeploy1 Deployment.
Click the Undeploy button to undeploy the application from all nodes. This will remove all resources from the target namespaces.
You can see what resources have been removed from the target namespace in the results subtab.
testDeploy_undeploy

Step 2: Make the application distributed

Up to this point, the entire application is running within the same namespace. You are now going to separate the storefront functionality and factory functionality by using the “PROCESSED BY” phrase in Rules and Procedures.

On the project resource graph, click Rule: com.vantiq.ims.checkInventory to open the rule detail pane. In the rule editor, line #5, uncomment the second half of the statement to make it read as follows:

PUBLISH {"storeId": t.value.storeId, "productCount":requestCount} TO TOPIC "/NewOrder"  
    PROCESSED BY {"ars_properties.type":"factory"}

It will publish to topic /com.vantiq.ims/NewOrder on a node whose ars_properties.type is factory.

On the project resource graph, click Procedure: com.vantiq.ims.shipToStore to open the procedure detail pane. In the procedure editor, line #2, uncomment the second half of the statement to make it read as follows:

EXECUTE pickupProducts(event) PROCESSED BY {"ars_properties.type":"store"}

It will execute the com.vantiq.ims.pickupProducts procedure on a node whose ars_properties.type is store.

In both cases you use ars_properties.type which you defined in the factory and store nodes earlier. In your future applications, you are free to use any properties you have defined on your nodes.

Save both the rule and the procedure. Now this application requires two nodes to run successfully.

Step 3: Project Partitions

Go to Project > Show Partitions.
projectPartitions

Since this is the first time viewing the project partitions, Vantiq automatically created two partitions by analyzing the “processed by” phrase used in rules and procedures.

Vantiq automatically places Type com.vantiq.ims.Store and its related client, rule and procedure in a partition with the title of {“ars_properties.type”:”store”}.

It also places topic /com.vantiq.ims/NewOrder and its related resources, distributeProductApp and com.vantiq.ims.shipToStore, into another partition titled {“ars_properties.type”:”factory”}

In a simple application like this, the auto-partition feature of Vantiq does all the work for you. In a more complicated application, you may need to move resources from partition to partition based on your application logic. To move resources, you can use drag and drop nodes in the graph. Or you can use the context menu on the tree.

Save the project to persist partitions before starting the Deployment steps.

Note: if you have visited the Project Partition pane before you modified Rule: com.vantiq.ims.checkInventory and Procedure: com.vantiq.ims.shipToStore, then you will need to click the Update Partitions toolbar button to pick up changes you made to the project and partition resources correctly.

Step 4: Add Deploy Parameter to New Partition

Since Type com.vantiq.ims.Store now belongs to partition {“ars_properties.type”:”store”}, you need to add a deploy parameter to the partition to add a new record to type com.vantiq.ims.Store on the target node.
Refer to Part 2, Step 2 for adding a deploy parameter. The only difference is that you need to select the partition {“ars_properties.type”:”store”} instead of “default”.
partitionParameters2

Step 5: Deploy the distributed application

In Deployment testDeploy1 pane, click on the Environment: tutorialEnv subtab to view the environment graph again.
You will see factoryNode and storeNode shown in different partitions. This means the resources in each partition will be deployed to different nodes.

Because custom partitions are defined, resources in the default partition will not be deployed. Therefore, the default partition is no longer shown here.
updateEnvironment

Click the Deploy button. Check the results subtab to verify that different resources were deployed to different nodes.
storeNodeResult
factoryNodeResult

Step 6: Verify Deployment

Switch to the factory namespace. Use the Projects menu button to select DeploymentTutorial_by_testDeploy1. You should see that App: distributeProductApp and Procedure: com.vantiq.ims.shipToStore were copied here. Also, a node named storeNode is copied here.

factoryNamespace

Switch to the store namespace and browse around. You should see a different set of resources and nodes copied here. View all records of type com.vantiq.ims.Store and you should see a record of newStore with a product count of 101. That matches the deployment parameter you created in a previous step.

Run the client DeploymentClient in this namespace. If you continue ordering products you should see that more products get delivered to this store when productCount is below 50. This shows that the application is now running successfully on two nodes.