Service Virtualization

Expand all | Collapse all

Is there a way to perform activities before listener step in VSM

  • 1.  Is there a way to perform activities before listener step in VSM

    Posted Jun 14, 2016 06:02 PM


    Hi All,

    I am looking for a way to perform activities before listener step in VSM. The activities are like any activity like file operation or JMS queue cleanup etc.

    Please help. Thanks.



  • 2.  Re: Is there a way to perform activities before listener step in VSM

    Posted Jun 15, 2016 08:08 AM

    sure.. just edit the VSM in Workstation, click in the listen step, right click on the canvas, and select Add Step after

    add the step, then open the listen step and make it go to where it used to go, then edit the new step and make its next step the listen.

    note that the end of the VSM has Listen as its next step... change as required.

     

    I do this in my custom services.



  • 3.  Re: Is there a way to perform activities before listener step in VSM

    Posted Jun 15, 2016 10:19 AM

    Hi sdetweil2, Can you please tell me what kind of activities your step is performing ? Is it a kind of JDBC/MQ server start or MQ queue creation ? Have you used a subprocess step or direct step ?



  • 4.  Re: Is there a way to perform activities before listener step in VSM

    Broadcom Employee
    Posted Jun 15, 2016 10:24 AM

    Aniket - You can add any step type before the listen step - one step for file operation - another one for JMS queue clean up etc - as per your requirement - as long as the listen / VSI lookup/ respond workflow is maintained



  • 5.  Re: Is there a way to perform activities before listener step in VSM

    Posted Jun 15, 2016 11:07 AM

    Mine reads a file using a JSR 223 script step and my own written code.. but as Prem mentions, you can do just about anything. I



  • 6.  Re: Is there a way to perform activities before listener step in VSM

    Posted Jun 15, 2016 03:34 PM

    Here's a picture as an example.  The real point to notice is that the Responder Step loops to the Listen Step. This model does this because we do not want the steps prior to the Listen step to execute more than once.  In the example below, some data was being loaded into the Shared Model Map (SMM) -- that occurs one time.  When the loop that loads the SMM is finished, it branches to the LISTEN step.  From then on, all instances of this service, and their corresponding transactions, consume information by accessing the SMM.  The first two steps in the model are performed prior to the LISTEN step.  Disregard all the commentary -- that was part of the description specific to this model's behavior.

    09_VSM_v1.gif



  • 7.  Re: Is there a way to perform activities before listener step in VSM

    Posted Jun 16, 2016 11:39 AM

    Hi Joel, this is very helpful. I have added my custom script step before listener and implementing a logic. About SSM, is it a part of DevTest 9.1 Solution or will be the part of next beta release.

     

    More things i would like to ask -

    1. Is it a best practice to redirect a flow always from Responder to  Listener. Or I can redirect to my custom script and manage response.

    2. Is there any way where I can perform my post activities after sending response to the client

    3. On virtual service shutdown request, is there any hook into the VSM where I can perform post execution activities

    Thanks.



  • 8.  Re: Is there a way to perform activities before listener step in VSM

    Posted Jun 16, 2016 12:18 PM

    2. just like before listen, you can add steps after respond, and have your step next got to listen

    1. on each step there is a 'next' step config.. in my vsm. I build the content and then let the normal VSM responder handle it.

        I fill in properties that are used in the selected response message.

    3. there is nothing built in to notify the VSM of shutdown..  I ended up writing a listener class

    you can see this in the lisa sdk javadoc

     

     

    import com.itko.lisa.test.TestEvent;

    import com.itko.lisa.test.TestEventListener;

    import com.itko.lisa.test.TestExec;

     

    public class TestListener implements TestEventListener{

        private TestExec ts=null;

        public TestListener(TestExec t)

        {

            ts=t;

            ts.log("listener constructed");

        }

        @Override

        public void testEvent(TestEvent arg0) throws Exception {

            // TODO Auto-generated method stub

            //ts.log("event fired");

            if(arg0.getEventId()==TestEvent.EVENT_NORMALEND||

               arg0.getEventId()==TestEvent.EVENT_ABEND||       

               arg0.getEventId()==TestEvent.EVENT_STOPTESTSIGNAL

               )

            {

                if(ts!=null)

                    ts.log("end event fired");

                //--> call shutdown handler ---- here

            }       

        }

    }



  • 9.  Re: Is there a way to perform activities before listener step in VSM
    Best Answer

    Posted Jun 16, 2016 12:26 PM

    The use of the Shared Model Map has been around since since r7.0, possibly earlier.  There is also a Persistent Model Map implementation where information is persisted rather than kept in memory. 

     

    Check out the scripting guide:  DevTest 8.0 - Scripting Guide - V1.1.pdf  

     

    SMM is a thread safe hash table that is sharable only within the VSE in which it is running.  SMM stores key/value or key/object pairs.  You need to watch VSE memory.  Storing a high number of entries having a large footprint can be detrimental.  And, your application needs to manage whatever you put here.  Since SMM is in-memory, it is cleared if the VSE service is stopped/started.

     

    Persistent map supports key/value (string).  The Persistent map is persisted into the DevTest database.  PMM has the ability to expire entries stored here.  A good bit of this is explained in the Scripting Guide. 

     

    1) You can direct flows according to your particular business requirements.  It is not mandatory that the Responder branch back to the Listener step.  However, in the majority of cases, some step in the model should eventually branch to LISTEN or the service just ends -- same as a test case would end.

     

    2) Yes.  There are situations where additional processing occurs after the response has been sent to the client.  If you need the lisa_vse_request or lisa_vse_response objects, you may need to save off the data prior to sending the response.  I have seen visibility to some objects go away after the Responder step fires.

     

    3) I do not know.  You might be able to use an existing Companion, create a custom Companion, or set up some sort of Event Listener to perform shutdown / cleanup activities.  Typically, the Portal and/or Console are used to 'shut down' a service. An actual request (incoming transaction) is not sent to the service so the Listen step is not 'fired'.  Since more than one instance of a VSM (service) could be running, I do not know how the threading model would treat this scenario.  You might force a cleanup before a running instance of your service finishes -- not sure.   



  • 10.  Re: Is there a way to perform activities before listener step in VSM

    Posted Jun 15, 2016 03:55 PM

    this is what ours looks like.. it is driven from an external control file, can use ssl to listen or not,

    can pass thru to the original server ssl, or not, reloads the profile of transactions it supports (data driven spreadsheet like),

    converts the user known spec to the software required format, handles basic auth, and does extensive wildcard matching including structures and arrays (our messages are very complex with lots of optional fields)

     

    everything is controlled external to the vsm/vsi. we never match any VSI pattern. every team runs the same exact VSI, and just updates the control file (new URIs) and spreadsheets (data driven)

     

    vms-model.jpg



  • 11.  Re: Is there a way to perform activities before listener step in VSM

    Posted Jun 15, 2016 05:05 PM

    sdetweil2 can you please explain me how are using both ssl non non ssl step in single model ? which is the assertion that does this ? currently we are maintain two services because of this .. I guess your solution helps to keep only one service which does both the job.



  • 12.  Re: Is there a way to perform activities before listener step in VSM

    Posted Jun 15, 2016 05:44 PM

    exactly my prior problem. two identical services to maintain, and listen was the only difference.. sadly the product cannot do either/or with changed properties {{}} on the fly

    I moved the listen port config and the ssl cert file config to the external file as well..

    sure.. the 1st step reads the profile, and sets a property to SSL or NONSSL (use property cause I will only go thru that step once)

    and then the second step uses assert to go to the appropriate listen (if ssl jump, else fall thru to normal listen)

    listenssl.jpg

    both listens then go to the same next step, load profile, which reads the same profile for the transaction config

    (if the in memory config is empty or any file changed)

     

    note that having both listens in the same service causes the Service console to get confused and display both, even if only one is actually being used.  (my service is ssl or not, one or the other, not BOTH in one transaction..

    see how to clean up UI for a service in the Service Console



  • 13.  Re: Is there a way to perform activities before listener step in VSM

    Posted Jun 15, 2016 07:02 PM

    Thanks sdetweil2  for quick response..

    couple of doubts..

    1. ssl cert file config to the external file as well..  > how did you move this.. are we able to mention ssl cert path in config and read it ?

     

    2. reads the profile and sets ssl or non .. please share how are you reading this,

     

    further steps I understood, how you diverting the calls to secure and non-secure..



  • 14.  Re: Is there a way to perform activities before listener step in VSM

    Posted Jun 15, 2016 07:17 PM

    1. yes, I use properties

    you could always have the filename in the project config file, didn't need to be hard coded.

    you could put the certfile file IN the project too.. but then you have to open the project anytime you need to change it

    which means you need a system with workstation, someone with skill, have to make a new mar. etc,etc,etc,etc

    never mind.. just tell me the filename (full path) on this system and we'll use THAT.

    sslinfo.jpg

     

    2. i used a JSR 223 script step, groovy,

    and then just read the file... its keyword = value

    <code>

    def StatementSeparator="="

    // listen via non-ssl port

    testExec.setStateValue("listenssl","false");

    // use the service internal name as part of the profile name

    def filename=testExec.getStateValue("user.dir")+"/hotDeploy/"+"service."+testExec.getStateValue("testCase")+".profile";

    // save the profile name for later uses

    testExec.setStateValue("profile_name",filename);
    def profile=new File(filename);
    //println("profile opened="+filename)
    // loop thru the profile, one line at a time, put data in 'line' variable
    profile.eachLine { line ->

    // watch out for tab characters

    line=line.replaceAll("\t"," ")

    // allow indentation

    // but remove it to work on the content

    line=strip(line)

    // ignore comments and blank lines
    if(!line.startsWith("#") && !line.startsWith("//") && (line.length()!=0))
    {
    // everything is keyword = value
    def keyword=line
    def value=""
    if(line.contains(StatementSeparator))
           (keyword,value) = line.split(StatementSeparator)
    value=strip(value)
    //if(debug && _logger!=null)
    //    _logger.info("keyword="+keyword+"="+"value="+value)

     

    switch (strip(keyword))
    {       
    case "port":
        testExec.setStateValue("listen_port",value);
    break;
    case "certfile":
        testExec.setStateValue("certfile",value);
    break;
    case "certfilepw":
        testExec.setStateValue("certfilepw",value);
    break;
    case "listenssl":
    if(value.equalsIgnoreCase("true"))
    {
    testExec.setStateValue("listenssl","true");
    testExec.setStateValue("certfilepw","Password");
    }
    default:
    break;

     

    }
    }
    }

    </code>



  • 15.  Re: Is there a way to perform activities before listener step in VSM

    Posted Jun 16, 2016 01:42 PM

    Thanks sdetweil2 for sharing these across.

    I had looked through the script, bit confused on what exactly trying to do here

    filename=testExec.getStateValue("user.dir")+"/hotDeploy/"+"service."+testExec.getStateValue("testCase")+".pr..

     

    could you please tel me what the content will be captured by this script..

    sorry I am not expert in groovy at the moment 

     



  • 16.  Re: Is there a way to perform activities before listener step in VSM

    Posted Jun 16, 2016 02:09 PM

    I wanted some way to make the profile unique by service(without editing the vsm), so I could run multiple on the same VSE without collisions.

    so I used the name of the service, testExec.getStateValue("testCase") ,to construct the filename

     

    note that this value is different than the external mar filename.

    DT will only allow ONE instance of a service by name to be installed at a time

    try to upload a second, and it will overlay the prior version.

     

    and this looks for the control file in the product hotDeploy folder. hotDeploy has to be there of the product will not run.

     

    groovy is almost identical to java..