Post

1 follower Follow
0
Avatar

Accessing meter(limiter) information

Is there a way in our code to access information about a user's subscription?  I am interested in knowing what the limiter upper boundary is for a limiter meter.   How do I get this information, both if I am using the local API as well as the normal Apprenda API?

Dwight Smith

Please sign in to leave a comment.

21 comments

0
Avatar

Hi Dwight,

 

In order to access information about a subscription, you can use the Subscription Context.

Information on the different types of context's can be found here:  http://docs.apprenda.com/3-5/contexts

And Information on how to use the Subscription Context to get context information can be found here:  http://docs.apprenda.com/3-5/features

 

More information about the methods that are available for you can be found here:  http://docs.apprenda.com/api/class_apprenda_1_1_saa_s_grid_1_1_subscription_1_1_subscription_context.html

Please let me know if you need any more help,

 

Best regards,

 

Bernie

Bernie Herdan 0 votes
0
Avatar

Thanks, Bernie.

 

I saw the SubscriptionContext class and the method GetLimitCount which will get the information I want.  However, I want to find all the Features the current User has before checking the Limits on each one.  I have not been able to find a method which returns the Features for a User. 

I tried GetSubscriptions method on ITenantUser, but it always returns no subscriptions, even though I have meters defined in the executionContext section of the mock file.  I am probably missing something here, so your help would be appreciated.

 

Thanks much.

Dwight

Dwight Smith 0 votes
0
Avatar

Hi Dwight,

You were correct on using GetSubcriptions. What you would want to do, is call that method, and then select the specific Subscription that pertains to the application you are looking for. Once you have that, you can call Subscription Item and Subscription Meter to verify their status.

With regards to the mock file, does it work for any other queries with this configuration? It may be that you miss-configured a section.

Best Regards,

Bernie

Bernie Herdan 0 votes
0
Avatar

Bernie,

I have attached the mock file to this comment.  All the queries regarding Session, User, Role and Securables work just fine. 

However, the GetSubscriptions callback result is always null..

Thanks

Dwight

Dwight Smith 0 votes
0
Avatar

Hi Dwight,

It seems like you are missing the section of the mocker where you define the actual subscriptions. 

In order to do that, you must first define a subscription group (the entitlement definition plan that the subscription belongs to), and then the subscription inside it. I am attaching a sample subscription group below. Make sure you modify the subscriptionID to match that of your context, as well as the assignedTo to match your userID.

This code should go right before the </tenant> tag.

 

Please let me know if you run into any issues,

Best regards,

Bernie

 

<subscriptionGroup id="c2cc964e-03a3-4d61-9b56-fd1fd62eb592" name="GroupName">

<profile id="f6f9c460-b463-4128-b822-c98a145bdf75" providerId="00000000-0000-0000-0000-000000000000" autoRenew="false" sourceVersionId="00000000-0000-0000-0000-000000000000" sourceOfferingId="00000000-0000-0000-0000-000000000000" sourcePlanId="00000000-0000-0000-0000-000000000000" createdDate="0001-01-01T00:00:00" assignedTo="00000000-0000-0000-0000-000000000000">

<nextRenewalDate xsi:nil="true" />

<lastRenewalDate xsi:nil="true" />

<terminationDate xsi:nil="true" />

<status>Active</status>

<subscriptionItems />

<subscriptionMeters />

</profile>

<subscriptions>

<subscription id="b4bc3487-eac5-455f-a55d-b0c39f31a6b1" providerId="00000000-0000-0000-0000-000000000000" autoRenew="false" sourceVersionId="00000000-0000-0000-0000-000000000000" sourceOfferingId="00000000-0000-0000-0000-000000000000" sourcePlanId="00000000-0000-0000-0000-000000000000" createdDate="0001-01-01T00:00:00" assignedTo="00000000-0000-0000-0000-000000000000">

<nextRenewalDate xsi:nil="true" />

<lastRenewalDate xsi:nil="true" />

<terminationDate xsi:nil="true" />

<status>Active</status>

<subscriptionItems />

<subscriptionMeters />

</subscription>

</subscriptions>

</subscriptionGroup>

</subscriptionGroups>

Bernie Herdan 0 votes
0
Avatar

Bernie,

Apparently, the apprendaLocal tag only accepts the following children:  tenants, executionContext.  So where does the subscriptionGroups tag belong in the xml?  Can I download the schema from somewhere?  The documentation and mocker file samples does not show anything about the subscriptionGroups tag (at least that I can find).

Thanks,

Dwight

Dwight Smith 0 votes
0
Avatar

Hi Dwight,

It goes inside the tenants tag as follows:

 

<tenants>

  <tenant>

     <users>  ... </roles>

     <roles>  ... </roles>

     <subscriptionGroups> ... </subscriptionGroups>

  </tenant>

</tenant>

 

I'll check to see if I can find a full schema to send you, but in the mean time try that out and let me know if it doesn't work.

Best regards,

Bernie

Bernie Herdan 0 votes
0
Avatar

Bernie,

Okay, I attached the mock xml file with what I have so far that does not cause schema errors.  Now I need to know how to set the properties of the subscriptionMeter that show that it is a Limiter and how do I define its upper count?  Or, do I just do that in the executionContext section? 

Thanks.

Dwight

 

Dwight Smith 0 votes
0
Avatar

Hi Dwight,

It would be a mix of both.

First you would need to tie the feature with the subscription by establishing a subscription meter, and then you would need to define it under the current context.

If you look at your Apprenda.mock.xml file, you can search for "Feature 1". In the first result, you will see how you can tie it with the parent subscription, and in the second result, you can see how you can establish the upper bound and current count.

Regards,

Bernie

Bernie Herdan 0 votes
0
Avatar

Bernie,

When I added the subscriptionGroups section to the mock xml file, I am now getting a ProtocolException returned from the Apprenda Local API.  This only happens when the subscriptionGroups xml section is in the mocker file.   I have attached the file.  Can you tell me what is wrong with the subscriptionGroups section?

Thanks,

Dwight

Dwight Smith 0 votes
0
Avatar

Hi Dwight,

One of the issues that I see is that there is a mismatch between the subscription ID provided in the execution context, and the actual ID of the subscription (second field inside the <subscription> tag). 

Another issue is that the subscription is still not assigned to the user defined in the execution context. You currently have the "assignedTo" field in the <subscription> tag set to " 00000000-0000-0000-0000-000000000000" while your userID is "724EA69A-E270-4C59-AC3C-C33F18458AD9"

Editing those might take care of the exception.

Thanks,

Bernie

Bernie Herdan 0 votes
0
Avatar

Bernie,

I made the corrections and still got the error.  But thinking more about a ProtocolException error, that exception usually occurs when there is a configuration or binding error with the service.  So, after more investigation, I determined that the ProtocolException is raised when the mock file is over a certain size, regardless of the contents of the file.  This seems to be a configuration issue triggered by the size of the mock file.  Have you run into this before? 

Dwight Smith 0 votes
0
Avatar

Bernie,

Everything works now.  Thanks for your help. 

The mock file size issue was overcome by deleting all the comments and other extraneous stuff not necessary.

Dwight

Dwight Smith 0 votes
0
Avatar

Bernie,

It seems there is one more issue.  The following call to the GetLimit method raises a System.Runtime.Serialization.SerializationException:

ITenantMeter meter = (from a in _apprendaUserSubscriptions[0].SubscriptionMeters select a).FirstOrDefault();
                    if (meter != null)
                        Apprenda.SaaSGrid.Subscription.SubscriptionContext.Instance.GetLimit(meter.ReferenceFeatureName, InitMetersResult);

I have attached the latest mock file.

Thanks,

Dwight

Dwight Smith 0 votes
0
Avatar

Hi Dwight,

Does the Serialization exception throw an error message?

Also, is it coming from the first statement, or the one after the If?

Thanks,

Bernie

Bernie Herdan 0 votes
0
Avatar

Bernie,

I have not been able to retrieve the error message from the exception.  The exception is raised on the call to GetLimit method after the if statement.

 

Dwight

Dwight Smith 0 votes
0
Avatar

Bernie,

I may have mislead you on the exception.  Upon further investigation, it seems to be a System.Exception with a message of "An Async callback threw and exception.".

 

Dwight

Dwight Smith 0 votes
0
Avatar

Bernie,

I put the solution (InnReservas.zip) into the Apprenda Support folder on our FTP site.  I believe you have  the connection and login info for that.  If  not, let me know.

The call to the GetLimit method is in ApprendaModel.cs which is in the InnReservas project in the Models folder.  The call is in the InitApprendaUserSubscriptionsResult method.

Dwight

Dwight Smith 0 votes
0
Avatar

Hi Dwight,

I seem to have misplaced the password I used last month. Would it be possible for you to auto-generate a new one?

Thank you,

Bernie

Bernie Herdan 0 votes