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.