Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

Set Active Environment Using a Tool

jefftuckerbofa
jefftuckerbofa Posts: 229

is it possible to set the active environment using something like an extension tool? I'd like to have multiple environments to set the value of endpoints and I would like to set the active environment based on a value from a Data Source. Can this be done, and if so is it thread safe.... meaning would the active environment only apply to the current thread? Thanks. JT

Comments

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,

    I would like to understand your use case. You say you want to have multiple environments and use those are the value of endpoints. What endpoints are you trying to parameterize?

    If you have a data source and are using that could you put the endpoint information into a column instead?

  • jefftuckerbofa
    jefftuckerbofa Posts: 229

    Yes. Using a data source would work fine. Here's where I would like to go:

    userId comes from the incoming request body

    Data Source Table: Config
    userId, envId

    Data Source Table: Endpoints
    envId, endpoint1, endpoint2, endpoint3

    So I'd like to see an example that selects the appropriate row from Endpoints using the envId. IOW, using SQL as an example:

    select Endpoints.* from Config, Endpoints where Config.envId=Endpoints.envId

    JT

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,

    One idea would be to set up a "user" responder, which correlations on "userId" in the table "Config", then it would have a messaging client chained to the incoming request that would send the "envId" in a request to an "endpoints" responder. The "endpoints" responder would have a data source correlation on the "Endpoints" table using the incoming "envId" and in its response return the data from the data source columns. The "user" responder's messaging client would then data bank the values the come back in the response. Then you can use the data banked values in the "user" responder as normal.

    This will do the "join" of the data sources that you want without scripting. Let me know if this makes sense, thanks!

  • jefftuckerbofa
    jefftuckerbofa Posts: 229
    edited July 2020

    I was hoping to do something scripted.. I see an example (updated with my DS names):

    def addDataSources(context) :smile:
    ds = ArrayList()
    ds.add("Config")
    ds.add("Endpoints")
    return ds

    That looks interesting, but I am not exactly sure how to define the method to use the incoming userId to "join those up" and get the appropriate endpoints.

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,

    There isn't an API for "joining" two data sources. You would have to do the join manually but most of the scripting context methods will assume that row has been set by data source correlation which in your use case it will not be. I think there might be some methods to return the list of values for a column name by you will have to construct the idea of a "row" based on indexes and I think it will get very messy.

    I would recommend using the approach of having the two responders to do the data source correlation and "join" that way.

  • jefftuckerbofa
    jefftuckerbofa Posts: 229

    Sounds good. I'll give it a try and update this thread with what I come up with and how it works. As always, thanks! JT

  • jefftuckerbofa
    jefftuckerbofa Posts: 229

    I think what's going to work best for me is to use an actual Database config. It will allow me to more easily drive the configuration without having to redeploy the VA. Thanks for the discussion. Very useful. JT

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,

    Glad you found an approach that will work!