Monday, July 21, 2014

A simple Oracle DB function to convert timestamp to date

In BRM, all the time and date is stored in number format and it is required to convert them if you are reading it from the DB.
Lots of developers write functions or utilities to convert it to date. Here is a similar function:

create or replace function u2d(
v_tstamp IN number)
return date
v_date date;

v_date := to_date('01-JAN-1970', 'DD-MON-YYYY') + (v_tstamp+19800)/86400;

Wednesday, July 10, 2013

Hash map implementation in C

I've written a hash map in C which is based on linked list data structure. It may be useful in various scenarios. Here is the list of the APIs implemented in this:

// Hash map structure
struct hash_map_t{
struct hash_map_t* nxt;
char* account_poid; //Key
int status;  // Value


 * Function to insert/update a key-value pair
 * If the key doesn't exist, this function will create a new node and add the 
 * key-value pair, if the key already exit, its value will be updated
void hash_map_set( struct hash_map_t* hm,
        char* acc_poid, 
        int         status);

 * Function to free the memory allocated by hash map
void    free_hash_map(struct  hash_map_t* hm);

 * Function to retrieve the map node with the kep acc_poid  
struct hash_map_t* getNodeWithKey(
                              struct hash_map_t* hm,
      char*                 acc_poid);

 * Function to retrieve the map node using value status   
struct hash_map_t* getNodeWithValue(
                               struct hash_map_t* hm,
       int                           status);

The code is attached at the following location:

If you've Scripd account, download it here:

Monday, April 8, 2013

BRM Errors

Title: AMT procedure errors

ORA-29280: invalid directory path
ORA-06512: at "WK33_PIN03.AMT_MV", line 347
ORA-06512: at line 1

Cause: The directory mentioned in of pin_amt application is not created or if it is created you are using the name in lowercase, change it to upper case.

ORA-29289: directory access denied
ORA-06512: at "WK33_PIN03.AMT_MV", line 347
ORA-06512: at line 1

Cause: Good news is that the directory exists but the db user with which pin_amt is being executed is not having read/write permission.

ORA-02055: distributed update operation failed; rollback required
ORA-54013: INSERT operation disallowed on virtual columns
ORA-06512: at "WK33_PIN03.AMT_MV", line 722
ORA-06512: at line 1

Cause: Some table in the AMT_METADATA is having virtual column, check what are the custom tables added and check which one has virtual columns.

Title: Cache entry not found

E Mon Apr  8 16:13:58 2013  <<hostname>>  cm:18233  fm_bill_utils_billing.c(49):1039 1:<<hostname>>:testnap:18231:-136099600:100001:1365405238:1
        Could not find cache entry: "PIN_SEQUENCE_TYPE_PACKAGE_ID"
E Mon Apr  8 16:13:58 2013  <<hostname>>  cm:18233  fm_subscription_purchase_deal.c:805 1:<<hostname>>:testnap:18231:-136099600:100001:1365405238:1
        op_subscription_purchase_deal error
        <field num=^Aopsflds:0,0 recid=0 reserved=3 reserved2=0 time(sec:usec)=0:0>
        <facility=0 msg_id=0 version=0>

Resolution: As the cache entry is missing, it means CM could not load few variable, restart cm to fix this.

Title: failed in initializing

-bash-3.2$ ./ -init
EBUF: errno=<PIN_ERR_BAD_CRYPT:15> location=<PIN_ERRLOC_DM:4> class=<UNKNOWN:0> field num=<0:0,0> recid=<0> reserved=<0>
0 PIN_FLD_POID                   POID [0] /config/pricing_admin -1 0
0 PIN_FLD_ACCOUNT_OBJ            POID [0] /account 1 0
0 PIN_FLD_HOSTNAME                STR [0] "-"
0 PIN_FLD_NAME                    STR [0] "config_pricing_admin"
0 PIN_FLD_PROGRAM_NAME            STR [0] "-"
0 PIN_FLD_CONFIG_INFO       SUBSTRUCT [0] allocated 6, used 6
1     PIN_FLD_HOSTNAME            STR [0] "sacjoshi-linux"
1     PIN_FLD_LOGIN               STR [0] "INTEGRATE"
1     PIN_FLD_NAME                STR [0] "brm11gdb"
1     PIN_FLD_PASSWD              STR [0] "integrate"
1     PIN_FLD_PORT                INT [0] 1521
1     PIN_FLD_SERVER_TYPE         STR [0] "oracle"
call_opcode: PCM_OP_CREATE_OBJ failed. at ./ line 504.
Initializing config object for pricing admin failed.

Resolution: - crypt md5 entry is not enabled, enable this entry in dm_oracle's pin.conf

Another issue that can sometimes occur due to installation issues is:

-bash-3.2$ ./ -set <admins.txt
EBUF: errno=<PIN_ERR_BAD_ARG:4> location=<PIN_ERRLOC_DM:4> class=<UNKNOWN:0> field num=<PIN_FLD_POID:7,16> recid=<0> reserved=<0>
0 PIN_FLD_RESULTS                  ARRAY [*] NULL
0 PIN_FLD_POID                      POID [0] /search -1 0
0 PIN_FLD_ARGS                     ARRAY [1] allocated 1, used 1
1     PIN_FLD_POID                  POID [0] /config/pricing_admin -1 0
0 PIN_FLD_TEMPLATE                   STR [0] "select X from /config/pricing_admin where F1 = V1 "
0 PIN_FLD_FLAGS                      INT [0] 0
call_opcode: PCM_OP_GLOBAL_SEARCH failed. at ./ line 504.
Search failed for /config/pricing_admin object.

Wednesday, November 2, 2011

Storable class to XML representation

I recently noticed this application that converts the storable class representation in database to XML format. Its syntax is:

storableclasstoxml [-h] [-r <filename> [-o <objectname>]]
-h : display help information
-r <filename> : retrieves storable class for
      1. /service and its sub classes
      2. /event and its sub classes
      3. /account class
      and write it to <filename>
-r <filename> -o <objectname> : retrieves storable class for
      <objectname> and write it to <filename>.
      <objectname> can be /service, /event, /account,
      /service/xyz or /event/xyz where xyz is a sub class
      of either /service or /event.  Multiple object types
      can be passed with comma(',') separated.

I'm not sure in which all scenarios this XML representation will be useful. If anyone get a chance to explore this or if someone has already explored, please share with me.

Wednesday, October 12, 2011

Some useful BRM flists

Here are some useful flists which will be useful for the POCs during development of Oracle BRM based applications.
1). Search flist to find the service and account objects (or POIDS) using the login field value when login is available in the the service

0 PIN_FLD_POID                      POID [0] /search -1 0
0 PIN_FLD_FLAGS                      INT [0] 256
0 PIN_FLD_INDEX_NAME                 STR [0] "service_login_i"
0 PIN_FLD_PARAMETERS                 STR [0] "telco/voice"
0 PIN_FLD_TEMPLATE                   STR [0] "select X from /service/$1 where F1 = V1 and  F2 = V2 "
0 PIN_FLD_RESULTS                  ARRAY [0] allocated 7, used 7
1     PIN_FLD_POID                  POID [0] NULL
1     PIN_FLD_ACCOUNT_OBJ           POID [0] NULL
1     PIN_FLD_LOGIN                  STR [0] NULL
1     PIN_FLD_PASSWD                 STR [0] NULL
1     PIN_FLD_PASSWD_EXPIRATION_T TSTAMP [0] (0) 01/01/1970 05:30:00:000 AM
1     PIN_FLD_PASSWD_STATUS         ENUM [0] 0
1     PIN_FLD_STATUS                ENUM [0] 0
0 PIN_FLD_ARGS                     ARRAY [1] allocated 1, used 1
1     PIN_FLD_POID                  POID [0] /service/ip -1 0
0 PIN_FLD_ARGS                     ARRAY [2] allocated 1, used 1
1     PIN_FLD_LOGIN                  STR [0] "your-login"

2). Search flist to find the service and account objects (or POIDS) using the alias field value when login is not  available in the the service

0 PIN_FLD_POID                      POID [0] /search -1 0
0 PIN_FLD_FLAGS                      INT [0] 256
0 PIN_FLD_INDEX_NAME                 STR [0] "service_alias_list_name_i"
0 PIN_FLD_PARAMETERS                 STR [0] "telco/voice"
0 PIN_FLD_TEMPLATE                   STR [0] "select X from /service/$1 where F1 = V1 and  F2 = V2 "
0 PIN_FLD_RESULTS                  ARRAY [0] allocated 7, used 7
1     PIN_FLD_POID                  POID [0] NULL
1     PIN_FLD_ACCOUNT_OBJ           POID [0] NULL
1     PIN_FLD_LOGIN                  STR [0] NULL
1     PIN_FLD_PASSWD                 STR [0] NULL
1     PIN_FLD_PASSWD_EXPIRATION_T TSTAMP [0] (0) 01/01/1970 05:30:00:000 AM
1     PIN_FLD_PASSWD_STATUS         ENUM [0] 0
1     PIN_FLD_STATUS                ENUM [0] 0
0 PIN_FLD_ARGS                     ARRAY [1] allocated 1, used 1
1     PIN_FLD_POID                  POID [0] /service/telco/gsm/telephony -1 0
0 PIN_FLD_ARGS                     ARRAY [2] allocated 1, used 1
1     PIN_FLD_ALIAS_LIST           ARRAY [*] allocated 1, used 1
2         PIN_FLD_NAME               STR [0] "9830000011"

3). Flist to create customer without plan/deals/products (PCM_OP_CUST_COMMIT_CUSTOMER)

0 PIN_FLD_POID POID [0] /plan 9198 0
1 PIN_FLD_POID POID [0] /account -1 0
1 PIN_FLD_POID POID [0] /payinfo/invoice -1 0
3 PIN_FLD_ADDRESS   STR [0] "Castro Street"
3 PIN_FLD_CITY   STR [0] "San Fransisco"
1 PIN_FLD_ADDRESS STR [0] "113, Castro Street"
1 PIN_FLD_CITY STR [0] "San Fransisco"
1 PIN_FLD_ZIP STR [0] "53038"
1 PIN_FLD_SERVICE_OBJ POID [0] /service/telco/gsm/telephony -1 0

Thursday, September 29, 2011

Enabling pin_virtual_time first time after BRM 7.4 installation

During development many times we need pin_virtual_time utility to move the BRM time forward to test many scenarios like billing, invoicing, dunning et.c.
After installing the BRM 7.4 components in the server, generally the pin_virtual_time_file is not created and also the entry is commented in almost all the component's pin.conf file.
Here are some tips to enable the pin_virtual_time (may be useful to novice BRM developers/testers)

1). Uncomment pin_virtual_time entry in all the components' pin.conf file. You may run the following command :
find  $PIN_HOME/ -name "pin.conf" | xargs sed -i 's/# - - pin_virtual_time/- - pin_virtual_time/g'
2). Restart the BRM server
3). Goto the $PIN_HOME/sys/test directory and execute
    $> pin_virtual_time
    This will create the pin_virtual_time_file and from now on you can move the time.

usage: pin_virtual_time [-h|-H|-?] [-f filename] [-m mode [value]]|[-i interval]
    -h, -H, -? print this message.
    -m ... set pin_virtual_time to mode, nothing or -i query pin_virtual_time
    mode is 0 (regular), 1 (fixed) or 2 (running)
    value as [mmdd]HHMM[[cc]yy][.SS]
    interval is time between queries in seconds

Monday, September 5, 2011

Search flist to find billinfo and account poid using account_no

Following is a complex search flist for finding BILLINFO poid and ACCOUNT poid using the ACCOUNT_NO field. As such this is used while running the bill utility during test runs but consider it as a sample for searching and extracting field values from two different storable class in single search. Generally, using a simple flist this is not achievable.

0 PIN_FLD_POID                      POID [0] /search -1 0
0 PIN_FLD_FLAGS                      INT [0] 768
0 PIN_FLD_TEMPLATE                   STR [0] " select X from /account 1, /billinfo 2 where 1.F1 = 2.F2 and 1.F3 = V3 "
0 PIN_FLD_RESULTS                  ARRAY [*] allocated 2, used 2
1     PIN_FLD_POID                  POID [0] NULL
1     PIN_FLD_LINKED_OBJ           ARRAY [2] allocated 3, used 3
2         PIN_FLD_ACCOUNT_OBJ       POID [0] NULL
2         PIN_FLD_LINK_DIRECTION    ENUM [0] 1
2         PIN_FLD_EXTRA_RESULTS    ARRAY [*] allocated 1, used 1
3             PIN_FLD_POID          POID [0] NULL
0 PIN_FLD_ARGS                     ARRAY [1] allocated 1, used 1
1     PIN_FLD_POID                  POID [0] NULL
0 PIN_FLD_ARGS                     ARRAY [2] allocated 1, used 1
1     PIN_FLD_ACCOUNT_OBJ           POID [0] NULL
0 PIN_FLD_ARGS                     ARRAY [3] allocated 1, used 1
1     PIN_FLD_ACCOUNT_NO             STR [0] ""

I will provide the explaination shortly.

Tuesday, May 31, 2011

Utility to move pin_virtual_time(mode 1) and execute pin_bill_day

It sounds like huh, why should I need a script for changing virtual time or executing pin_bill_day but it has utility. Specially for BRM testing, there are scenarios where the movement of time followed by execution of pin_bill_day and pin_ledger_report are required, e.g.
   - Testing of invalid (soft declined/hard declined) credit cards
   - Checking the monthly bill for a certain period of time
   - Accounting validation by looking at General Ledger(GL) reports of certain months
   - Checking the expiration of the non-currency date based resources valid for a year
   - and so on

So this script has the following modes of operation when you will execute it :

$> perl
Current time is : mode 1  1367341200  Tue Apr 30 10:00:00 2013
mode 1  1367341200  Tue Apr 30 10:00:00 2013

Select from the following :
        1. Increment time to next day
        2. Increment time to a date
        3. Move time to a date by incrementing one day at a time
        4. Move time to a date by incrementing one month at a time :
        5. Move time to a date by incrementing 15 days at a time
        Your Selection(1|2|3|4|5) :

Option1 : Increment time to next day and execute pin_bill_day and pin_ledger_report
Option2 : Increment time to a particular date in future like some date after few months in the same year or next year
Option3 : Increment time to a date in future by executing pin_bill_day and pin_ledger_report on each day of that period
Option4 : Increment time to few months by moving one month at a time and executing pin_bill_day and pin_ledger_report each month
Option5 : Increment time to a date by moving 15 day at once and executing pin_bill_day and pin_ledger_report

Here is the link of the script :

Tuesday, May 24, 2011

Guidelines to write a new FM in BRM

Creating a new FM

Steps to create a new FM in a CM :
  1. Define new opcodes
  2. Write a function to implement the new opcode
  3. Write a program to map opcodes to functions
  4. Create a shared library on UNIX i.e. ".so" file
  5. Configure the new FM as part of the CM

1. Defining new opcodes

You must define your custom opcodes, with their numbers, in a header file and execute on the file. creates an extension to the pcm_tbls.c file. Client applications use pcm_tbls.c to map a field or opcode to its number.

Portal opcodes and their numbers are defined in the ops/*.h files in the <BRM_HOME>/include directory.
To pass new opcodes from a client application to a new FM, use the PCM_OP macro.

To define a new opcode:
  a). Create a header file and define your new opcodes by using this format:
      #define    opcode_name_1    opcode_number_1

      For example, you might create a header file named my_opcodes.h with these definitions :

      #define MY_OP_SET_AGE     100001
      #define MY_OP_SET_LANGUAGE  100002

       Important: Numbers upto 100000 are reserved for use by BRM.

  b). Run the perl script by using this syntax: -L language -I input -O output -P java_package

 c). For the applications written in PCM C or PCM COM, create an entry using the following format in the pin.conf each application :
      - - ops_fields_extension_file ops_flds_ext

      Where ops_flds_ext is the file name and location of the memory-mapped extension file that was created by the script.
       Make sure that you included your header file both in the application that is calling the opcode and in the custom FM.

2. Writing a function to implement a new opcode 

     To implement a new opcode in BRM, you have to write a new function that calls the base system opcodes to access the DM. The new function then becomes part of the new FM shared library in UNIX.

     The new function you are implementing should conform to the PCM_OP calling convention.
     Use the PCM_OP_* reference pages as checklists and templates to determine what your custom function must implement. Pay particular attention to the input and output flists.

Important If you are adding a new function in the fm_utils module that can be called outside the module, add a prototype of that function in the fm_utils.h

3. Creating an opcode-to-function mapping file 

    You create a configuration program fm_*_config.c to map an opcode name to the function that implements it. This configuration file is read when a dynamic library is created, and the mapping information is stored in it.  When a parent CM is inititalized, it configures the opcode-function pairs into itself, and each child CM inherits the same configuration as its parent CM.

   The configuration program contains an array of struct cm_fm_config for each opcode and its corresponding function and the config function at the end.
   For a definition of this struct (cm_fm_config), see the cm_fm.h file in the BRM_SDK_HOME/include directory.
   The following example shows an opcode-to-function configuration file.

Important Include you ".h" file with your new custom opcodes

#ifndef lint
static  char    Sccs_id[] = "@(#) fm_custom_config.c 1.0 24 May 2011 %";

#include <stdio.h> /* for FILE * in pcm.h */
#include "ops/base.h"
#include "pcm.h"
#include "cm_fm.h"
#include "ops/my_header.h"

* Opcodes handled by this FM.
struct cm_fm_config my_config[] = {
/* opcode as a u_int, function name (as a string) */
{ MY_FIRST_OPCODE , "op_my_opcode" },
{ 0, (char *)0 }

void * my_config_func()
return ((void *) (my_config));

When the CM gets a MY_FIRST_OPCODE opcode through the PCM_OP call from a client application, the CM looks up at this table and calls the op_cust_create_acct() function.

4. Adding a new FM module to the CM configuration file 

The configuration file contain the names of the shared libraries that implement the base and custom opcodes. It also contains the names of the corresponding configuration files that contain the opcode-to-function mappings.

Use the entries for the system FMs in the default CM configuration file pin.conf in the BRM_HOME/sys/cm as an example to add your custom FM entries. For example, the typical entries for custom FMs look like:

- cm fm_module BRM_HOME/lib/ my_config - pin

In this example, I'm assuming that the new dynamic library that implements the new custom FM is copied to BRM_HOME/lib directory. "my_config" is the name of the configuration implementation that contains the name-to-function mapping of the new custom OpCode.

5. Compiling and linking a custom FM

Use the libraries in the Portal_SDK_home/lib for linking.
Each custom FM must be created as a shared library on UNIX

Thursday, May 5, 2011

Important classes in Oracle BRM

In BRM, account/customer related data such as names, addresses, profiles, current account balances, group charge sharing, and account hierarchy are stored. Plans/deals/products can be purchased by the customer which gets associated with their account. The customers can purchase one or more services like GSM/GPRS et.c. (in case the subscriber is a telecom subscriber).  Some of the key or most important BRM classes are:

/ACCOUNT :  This is one of the most important and key storable class of BRM that stores information about the customer. The customer information includes their contact info,status, locale and tax related information. Account class is mapped to account_t table and is uniquely identified by POID. Each account has a default balance group and is associated with the instances of billinfo, balance group,payment method, purchased products, purchased discounts and services.

/BALANCE_GROUP :  Stores the balance information for each currency and non-currency resources in an account . A balance group includes one or more sub-balances for each resource. The sub-balance contains the current amount, resource type, validity dates for the resource, rollover data, and sub-balance contributors. This storable class is mapped with the  bal_grp_t table in BRM database.

/BILL : This storable class contains the information for the bills generated for each customer based on the products they purchase or the usage they do. It includes information such as the amount due, amount adjusted, currency and bill number. A /bill object is created for each account that have a due at the beginning of a billing cycle. It contains information for the invoice and the billinfo object with which it is associated. It maps with the  bill_t  table in BRM database.

/BILLINFO: Stores all billing, payment method, accounting cycle, and hierarchy information necessary to bill an account. A default /billinfo object is created for every account. If the billinfo is subordinate, the /billinfo object points to the parent account and the parent account’s /billinfo object. It maps to billinfo_t table in BRM database.

/INVOICE: Stores a customer invoice and information about the invoice, such as the bill it is associated with. Each /bill object can have a corresponding /invoice object. It maps to invoice_t table in BRM database.

/ITEM: Created to bundle events, this table summarizes billable item activity by type. It maps to item_t table in BRM database. Rows in this table are added for each row in the BILL_T table.

/PAYINFO: Stores generic payment method information for an account. It maps to payinfo_t  table in BRM database.

/DEAL: Stores information about a deal.When you use Pricing Center and connect to the database, all /deal objects in the database are shown in Pricing Center. It maps to DEAL_T table in BRM database.

/PRODCUT: Stores the information for a single product. Maps to product_t table.

/DEVICE: Stores information about devices. There is a separate /device object for every device managed by BRM. Generic data applicable to all devices is stored in the parent /device object. Subclasses such as /device/num store information specific to a particular device type. It maps to device_t table in BRM database.

/PROFILE: Abstract class to support custom account information. To use a /profile object, always create a subclass. You can link an account to any number of /profile objects. Maps to profile_t table.

/EVENT : Abstract class to record system-initiated and user-initiated events. Event objects are related to a specific service or to an account. An event includes generic information such as start and end times as well the balance impacts that are incurred by the account due to this event. The /event object points to the account balance group that is impacted.Maps to event_t table in BRM database. The event class stores the event balance data in another table event_bal_impacts_t.

/PURCHASED_PRODUCT : Contains an entry for each product owned by an account at the time of conversion.Maps to purchased_product_t table in the BRM database.

/PURCHASED_DISCOUNT: Contains an entry for each discount owned by an account at the time of conversion.Maps to purchased_discount_t table in the BRM database.

/SERVICE : Stores generic service type information for accounts. There is one row in this table for each applicable service for each entry in ACCOUNT_T. In addition to a row in this table, a row must be created in the service type table, such as IP service or email. Maps to service_t table in the BRM database.

/CONFIG: Base class for configuration objects. Subclasses hold specific configuration information for various features, for example, /config/beid defines currency and non-currency resources. Maps to config_t  table.