Layer7 API Management

Expand all | Collapse all

Cluster wide context variable

Jump to Best Answer
  • 1.  Cluster wide context variable

    Posted 02-22-2017 08:19 AM

    Hi all,

     

    We have a customer asking us for a way to use a “cluster wide context variable”. They compare this to how they can read a cluster property from any session on any policy. But they also need the ability to write to this variable, which is not possible directly from a policy for a cluster property. I know this can be done through the restman interface, but so far I have been unable to create a working example policy. Does anybody have or can anybody create a sample policy or at least a sample request which shows how we can post to restman for adding and updating a cluster property?

     

    Thanks and regards,

     

    Maarten van Holst Pellekaan



  • 2.  Re: Cluster wide context variable

    Posted 02-22-2017 08:48 AM

    Hello Maarten

     

    Is the customer trying to achieve cross cluster caching, using CLWs via Restman would seem like the wrong approach. CA APIM Support can provide a tactical assertion to perform RemoteCache to Memcached, Coherence, and GemFire servers.

     

    You could consider storing values in a JDBC database as well. 

     

    Christopher Clark

    CA Support 



  • 3.  Re: Cluster wide context variable

    Posted 02-22-2017 09:05 AM

    Hello Christopher,

     

    Thank you for the feedback. It is not caching.

    What the customer needs is a variable that can be shared over multiple requests.

    The idea is to obtain a token, save that to the “cluster wide context variable” and allow further requests to use this.

     

    Regards,

     

    Maarten van Holst Pellekaan.



  • 4.  Re: Cluster wide context variable

    Posted 02-22-2017 05:45 PM

    Hi Maarten,

    Store to cache assertion, and Look up in cache assertion could be the better choice, as things like token is not permanent.

     

    Regards,

    Mark



  • 5.  Re: Cluster wide context variable

    Posted 02-23-2017 03:08 PM

    Hey Mark,

     

    The original question is for some way to implement a "cluster wide context variable". So the use case is not about caching multiple values from multiple requests, it is more about sharing one value/variable over multiple requests. Correct me if I'm wrong, but as far as I know the cache is in memory so it is not persistent and not synced across cluster nodes. Setting up a database connection just for storing and updating a variable seems somewhat redundant if basically the same functionality is already available as cluster properties.

    The cluster properties would provide this functionality, we just need a way to set the value. This can be achieved through a REST call, we are just having trouble getting the syntax right to do the call to write/update the cluster property so we were hoping someone could provide a working example.

     

    Hope that helps with understanding the specific use case and that someone can provide an example.

     

    Thanks,

    Michiel



  • 6.  Re: Cluster wide context variable
    Best Answer

    Posted 02-23-2017 06:46 PM

    Hello Michiel,

    You're right, store to cache is not cluster wide, it can be shared to requests of a gateway only.

     

    But the resteman is different between versions, for example, on gateway 8.4, you can only create new cwp, but cannot update it.

     

    The example below is tested on gateway 9.2,

     

    create or update cwp via restman
    1. gen id
    # mysql -e "select md5(uuid());"
    +----------------------------------+
    | md5(uuid()) |
    +----------------------------------+
    | 45f1f2e528887e575244b39ec6034f87 |
    +----------------------------------+
    2. call restman
    method: PUT
    URL: https://<gateway>:8443/restman/1.0/clusterProperties/45f1f2e528887e575244b39ec6034f87
    Content-Type: application/xml

    body:
    <l7:ClusterProperty version="0" xmlns:l7="http://ns.l7tech.com/2010/04/gateway-management">
    <l7:Name>cwpbymark</l7:Name>
    <l7:Value>value</l7:Value>
    </l7:ClusterProperty>

     

    Regards,

    Mark



  • 7.  Re: Cluster wide context variable

    Posted 02-24-2017 07:08 AM

    Hi Mark,

     

    Thank you. We sent this solution to the customer and are awaiting their response.

    I will let you know if it works for them.

     

    Regards,

     

    Maarten.



  • 8.  Re: Cluster wide context variable

    Posted 02-27-2017 07:41 AM

    We've made an encapsulated assertion for this one.

     

     

     

    Here's the XML part.

     

    <?xml version="1.0" encoding="UTF-8"?>
    <wsp:Policy xmlns:L7p="http://www.layer7tech.com/ws/policy" xmlns:wsp="http://schemas.xmlsoap.org/ws/2002/12/policy">
    <wsp:All wsp:Usage="Required">
    <L7p:AuditDetailAssertion>
    <L7p:Detail stringValue="Policy Fragment: Mofidy Cluster Wide Property"/>
    </L7p:AuditDetailAssertion>
    <L7p:HttpRoutingAssertion>
    <L7p:HttpMethod httpMethod="GET"/>
    <L7p:ProtectedServiceUrl stringValue="https://localhost:7443/restman/1.0/clusterProperties?name=${clusterProperty}"/>
    <L7p:ProxyPassword stringValueNull="null"/>
    <L7p:ProxyUsername stringValueNull="null"/>
    <L7p:RequestHeaderRules httpPassthroughRuleSet="included">
    <L7p:ForwardAll booleanValue="true"/>
    <L7p:Rules httpPassthroughRules="included">
    <L7p:item httpPassthroughRule="included">
    <L7p:Name stringValue="Cookie"/>
    </L7p:item>
    <L7p:item httpPassthroughRule="included">
    <L7p:Name stringValue="SOAPAction"/>
    </L7p:item>
    </L7p:Rules>
    </L7p:RequestHeaderRules>
    <L7p:RequestParamRules httpPassthroughRuleSet="included">
    <L7p:ForwardAll booleanValue="true"/>
    <L7p:Rules httpPassthroughRules="included"/>
    </L7p:RequestParamRules>
    <L7p:ResponseHeaderRules httpPassthroughRuleSet="included">
    <L7p:ForwardAll booleanValue="true"/>
    <L7p:Rules httpPassthroughRules="included">
    <L7p:item httpPassthroughRule="included">
    <L7p:Name stringValue="Set-Cookie"/>
    </L7p:item>
    </L7p:Rules>
    </L7p:ResponseHeaderRules>
    <L7p:SamlAssertionVersion intValue="2"/>
    </L7p:HttpRoutingAssertion>
    <L7p:ResponseXpathAssertion>
    <L7p:VariablePrefix stringValue="clusterPropertyId"/>
    <L7p:XpathExpression xpathExpressionValue="included">
    <L7p:Expression stringValue="/s:List/s:Item/s:Id"/>
    <L7p:Namespaces mapValue="included">
    <L7p:entry>
    <L7p:key stringValue="s"/>
    <L7p:value stringValue="http://schemas.xmlsoap.org/soap/envelope/"/>
    </L7p:entry>
    </L7p:Namespaces>
    <L7p:XpathVersion xpathVersion="XPATH_1_0"/>
    </L7p:XpathExpression>
    </L7p:ResponseXpathAssertion>
    <L7p:SetVariable>
    <L7p:Base64Expression stringValue="PGw3OkNsdXN0ZXJQcm9wZXJ0eSB4bWxuczpsNz0naHR0cDovL25zLmw3dGVjaC5jb20vMjAxMC8wNC9nYXRld2F5LW1hbmFnZW1lbnQnPg0KICAgICAgICAgPGw3Ok5hbWU+JHtjbHVzdGVyUHJvcGVydHl9PC9sNzpOYW1lPg0KICAgICAgICAgPGw3OlZhbHVlPiR7Y2x1c3RlclZhbHVlfTwvbDc6VmFsdWU+DQo8L2w3OkNsdXN0ZXJQcm9wZXJ0eT4i"/>
    <L7p:ContentType stringValue="text/xml; charset=utf-8"/>
    <L7p:DataType variableDataType="message"/>
    <L7p:VariableToSet stringValue="myreq"/>
    </L7p:SetVariable>
    <L7p:HttpRoutingAssertion>
    <L7p:HttpMethod httpMethod="PUT"/>
    <L7p:ProtectedServiceUrl stringValue="https://localhost:7443/restman/1.0/clusterProperties/${clusterPropertyId}"/>
    <L7p:ProxyPassword stringValueNull="null"/>
    <L7p:ProxyUsername stringValueNull="null"/>
    <L7p:RequestHeaderRules httpPassthroughRuleSet="included">
    <L7p:ForwardAll booleanValue="true"/>
    <L7p:Rules httpPassthroughRules="included">
    <L7p:item httpPassthroughRule="included">
    <L7p:Name stringValue="Cookie"/>
    </L7p:item>
    <L7p:item httpPassthroughRule="included">
    <L7p:Name stringValue="SOAPAction"/>
    </L7p:item>
    </L7p:Rules>
    </L7p:RequestHeaderRules>
    <L7p:RequestMsgSrc stringValue="myreq"/>
    <L7p:RequestParamRules httpPassthroughRuleSet="included">
    <L7p:ForwardAll booleanValue="true"/>
    <L7p:Rules httpPassthroughRules="included"/>
    </L7p:RequestParamRules>
    <L7p:ResponseHeaderRules httpPassthroughRuleSet="included">
    <L7p:ForwardAll booleanValue="true"/>
    <L7p:Rules httpPassthroughRules="included">
    <L7p:item httpPassthroughRule="included">
    <L7p:Name stringValue="Set-Cookie"/>
    </L7p:item>
    </L7p:Rules>
    </L7p:ResponseHeaderRules>
    <L7p:SamlAssertionVersion intValue="2"/>
    </L7p:HttpRoutingAssertion>
    </wsp:All>
    </wsp:Policy>



  • 9.  Re: Cluster wide context variable

    Posted 02-28-2017 02:24 AM

    Hi,

     

    Thank you very much on behalf of the customer!

     

    Regards,

     

    Maarten.