KVM Operations Policy what if key is not present

Not applicable

How could I use A Raise Fault policy if not do it into a FaultRules tag, if Key is not found in a KVMOP Step ?

for example:

 <Put override="true">
        <Key>
            <Parameter>a</Parameter>
        </Key>
        <Value>b</Value>
 </Put>
<Get assignTo="variable" index="1">
        <Key>
            <Parameter ref="inputVar"/>
        </Key>
</Get>

if inputVar = "c", are there any error codes raised for this? How can I use Raise Fault for this if not FaultRules when the variable is not found in the collection of KV-pairs in the KVMOP

Solved Solved
0 18 1,006
1 ACCEPTED SOLUTION

adas
Participant V

@Hanzel Garcia Yes seems like a fair ask and a genuine requirement. I would open a bug for this and have our team look into it.

View solution in original post

18 REPLIES 18

Just FYI, Fault Rules can be defined only in Proxy, Target endpoints. Fault rules in policy is not supported as of today. Tag was earlier mentioned in policies documentation pages by mistake.

Ah yes, i knew that. But i wanted let sets say a "escape goat" for this that supposedly a FaultRule would be activated when Key is not found in the KVMOP.

Not applicable

Nope, When I used trace, there were no errors raised (no faults raised) and it returned 200 OK response to me. even without the Fault Rule I guess it would have thrown me the error that the key I used is not at the KVMOP collections right?

Can you post your KVM policy here to investigate ? You would like to raise a fault when key is not present right ?

Mines kinda confidential but I'll post something similar(similar as in edited key/value only)

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<KeyValueMapOperations async="false" continueOnError="false" enabled="true" name="KeyValueMapOpertaionsHasAccount">
    <DisplayName>KeyValueMapOpertaions.HasAccount</DisplayName>
    <Properties/>
    <ExclusiveCache>false</ExclusiveCache>
    <ExpiryTimeInSecs>-1</ExpiryTimeInSecs>
    <Put override="true">
        <Key>
            <Parameter>a</Parameter>
        </Key>
        <Value>
             {

		"body":"i am batman"

	     }
        </Value>
    </Put>
    <Put override="true">
        <Key>
            <Parameter>b</Parameter>
        </Key>
        <Value>
             {

		"body":"i am superman"

	     }
        </Value>
    </Put>
    <Get assignTo="mockResponse" index="1">
        <Key>
            <Parameter ref="letterVar"/>
        </Key>
    </Get>
    <Scope>apiproxy</Scope>
</KeyValueMapOperations>


@Hanzel Garcia , I have updated my answer. See solution that worked for me 🙂

Dear @Hanzel Garcia ,

KVM Policy doesn't support out of the box as of today. But you can use Raise fault policy something like below using condition statement. See attached proxy to see it in action.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ProxyEndpoint name="default">
    <Description/>
    <PreFlow name="PreFlow">
        <Request>
            <Step>
                <Name>putUrl</Name>
            </Step>
            <Step>
                <Name>Raise-Fault-1</Name>
                <Condition>(newVariable is null)</Condition>
            </Step>
        </Request>
        <Response/>
    </PreFlow>
    <Flows/>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>
    <HTTPProxyConnection>
        <BasePath>/kvmweather</BasePath>
        <VirtualHost>default</VirtualHost>
        <VirtualHost>secure</VirtualHost>
    </HTTPProxyConnection>
    <RouteRule name="default">
        <TargetEndpoint>default</TargetEndpoint>
    </RouteRule>
</ProxyEndpoint>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<KeyValueMapOperations name="putUrl" mapIdentifier="urlMapper" continueOnError="false">
    <Scope>apiproxy</Scope>
    <Put override="true">
        <Key>
            <Parameter>myName</Parameter>
        </Key>
        <Value>"Anil"</Value>
        <Value>"Sagar"</Value>
    </Put>
    <Get assignTo="newVariable" index="1">
        <Key>
            <Parameter>myNameNot</Parameter>
        </Key>
    </Get>
</KeyValueMapOperations>

Seems like it's either a bug or feature is missing. You can propose same in our Ideas section.

Cheers,

Anil Sagar

I believe its not out of the box idea, since these error codes (KeyIsMissing, ValueIsMissing), I believe this is a bug, if not please give an example where these two are purposely drawn as error, give me a sample zip if you must. Coz it seems, instead of a default error handler when they are not found, I had to setup a "manual" checking if those are null. Yes its not much to add just another step, but for the sake of beautiful infrastructure, I believe this is one step to a brighter one 🙂

@Hanzel Garcia , I think error codes (KeyIsMissing, ValueIsMissing) are raised when Key or Value tags are missing from the policy. Need to verify. Yes, You are right there should be default checking instead of manual validation. Good idea for our ideas section. Please feel free to post an idea..

Keep me posted @Anil Sagar about this also 😄 Thanks!

Any update on this? My Proxy relies heavily on the KVM and on the error it supposedly should throw.

@arghya das

please check also a resolution for this. I need to somehow implement FaultRules when Key is not found in the list of KVM values on the KVM Operations Policy.

adas
Participant V

@Hanzel Garcia Yes seems like a fair ask and a genuine requirement. I would open a bug for this and have our team look into it.

Thanks, I hope this would be considered soon or ASAP.

what is final solution to it. @dino 

RaiseFault with a Condition testing the variable, seems like a reasonable approach.  Is there any reason that is not acceptable ?

I do not want to use raise fault, but want to assign other value if no value found in KVM. how to do it?

@dino 

 

You can use a flow sequence like this:

<Step>
  <Name>KVM-Get-Value</Name>
</Step>
<Step>
  <Name>AM-Assign-Value</Name>
  <Condition>retrieved_value = null</Condition>
</Step>

...where the variable you are loading from KVM is retrieved_value. In the event there is no value found in the KVM, then the AssignMessage policy sets a default value.  Like this: 

<AssignMessage name='AM-Assign-Value'>
  <AssignVariable>
    <Name>retrieved_value</Name>
    <Value>default-value-here</Value>
  </AssignVariable>
</AssignMessage>