Pattern-type (Part 6): How to add operation with SmartCloud Application Services

When you define a role in a pattern type, you can associate to this role a number of operations you would like to launch once the pattern is deployed. These operations will be available from the ‘Manage’ panel under the operation tab.

In the example below, I will add a ‘Send string to log’ operation to my ‘ServerStandalone’ role.

To implement an operation, you will have to add an extra file called ‘operation.json’ next to the metadata.json file in the appmodel directory. This file specify which script have to be launched and the script have to be placed under the part role directory.

PS: Notice, I use the new Eclipse plugin provided by the PDK version 1.0.3 to develop my pattern-type plugin.

Operation.json file:

Please find here a screen-shot of the operation file using the PDK plugin:

and here the source version of it:

{
   "ServerStandalone": [
      {
         "id": "myoperation",
         "label": "Send String to log",
         "description": "Send a string to the log file.",
         "category": "Logs",
         "script": "myoperation.py",
         "attributes": [
            {
               "id": "stringToLog",
               "type": "string",
               "required": true,
               "label": "String to log",
               "description": "This string will be logged."
            }
         ]
      }
   ]
}

You can see for each role, we can define a number of operation, each operation has an id, label, description, category, script and a list of attributes.

The category is used to put together a number of operation in the UI.

The script is a python script and must be placed in the role script directory of the part as shown above.

The attributes will be shown in the UI:

We will see later, how to retrieve the value of these attribute in the script.

Now, the only thing we still have to do is writing the script.

Script:

We will implement a very simple script. This script will simply retrieve the ‘stringToLog’ attribute value and post it in the log file.

You can retrieve an attribute value using the following syntax:

maestro.operation[‘parms’][{attributeName}];

where attributeName is the name of the attribute you would like to retrieve.

So, here the script snippet and must be placed in the role script directory.

import maestro;
import logging;

logger = logging.getLogger("myoperation.py");
par1 = maestro.operation['parms']['stringToLog'];
logger.debug('StringToLog value %s' % par1);

Final Test:

After having provision a pattern based on this pattern-type, click ‘Manage’ on the top right corner after having selecting the virtual application pattern instance and from the ‘Operation’ tab you can select the role, this will show the operations available for this role.

Enter a string in the ‘String to log’ field:

and when the operation is executed you will see at the bottom of the screen:

We can check the result in the log file:

myoperation.py 47921433917888 pid=13123 DEBUG StringToLog value Test String

Conclusion:

Using the operation.json file, you can associate operation to the role.

 

References

More information on operation in the IWD Documentation here:

– Pattern-type (Part 5): Scaling in/out based on your own monitoring collector with SmartCloud Application Services

– Pattern-type (Part 4): Adding your own monitoring collector to a pattern-type with SmartCloud Application Services

– Pattern-type (Part 3): Adding Static scalability to a pattern-type with SmartCloud Application Services

– Pattern-type (Part 2): Create step-by-step a Master-Slave pattern-type with SmartCloud Application Workload Services

– Pattern-type (Part 1): Create step-by-step a simple pattern-type with SmartCloud Application Workload Services

– IWD infocenter