Sunday, 6 November 2016

Planning to FDMEE with a little help from Groovy

I was recently asked whether it would be possible to run FDMEE data load rules from within a planning task list, this was for an 11.1.2.4 on-premise environment.

Currently there is no default functionality to do this so if you want to be restricted to using what is available then the short answer would be no, if you are open to a little customisation then there are possible solutions and in this post I will cover one of the ideas I came up with.

Before thinking about planning it is worth understanding what options are available to run FDMEE rules outside of the user interface, if this was Oracle EPM Cloud then there are REST resources available which I blogged about here, at the time of writing this these have not yet made it down to on-premise but hopefully will soon.

For on-premise there is the option of calling SOAP based Web Services or posting to a java servlet which is the method the FDMEE batch scripts use, I wrote about both methods here.

Out of the options I decided on the servlet method as it is pretty simple to use and does not require additional configuration like the SOAP Web Services.

I am not going to cover all the details on the servlet as there is no point in duplicating what I have written in the past.

In summary the URL for the servlet is :

http(s)://<webserver>:<port>/aif/BatchExecutionServlet

The following parameters with assigned values should be posted to the servlet.

TYPE
RULE_NAME
IMPORT_FROM_SOURCE
EXPORT_TO_TARGET
EXEC_MODE
EXPORT_MODE 
EXC_RATE_FLAG
START_PERIOD_NAME
END_PERIOD_NAME
SYNC_MODE
USER_NAME
PASSWORD

An example of running an FDMEE data load rule would be:


A response would then be returned providing information on whether the rule was successfully started.


In my example I am setting the “SYNC_MODE” to false which means a response is returned once the rule has started or if there was a problem running the rule.

It is possible to set the value to true which will return a response once the rule has completed or failed, there are risks involved with this depending on the time the rule takes to run, you could end up holding on to sessions and generating stuck threads.

So now I have a method to run a rule but how can this be run from a planning task list.

For on-premise the list of available task types are:


Out of the list possibilities are either URL , Business rule or Form with Business Rule attached, the problem with URL is it will be using a GET method and there is not much room for it being dynamic.

Which leaves a business rule or a form containing a business rule, it is certainly possible to create a Java custom defined function to post to the servlet, the problem with CDFs is that they need to be compiled, copied to the correct location on the Essbase server, registered, if anything needs updating then we need to go through the process again which is not great.

Luckily there is another option, starting with Calculation Manager 11.1.2.4.006 there were two new CDFs introduced, @CalcMgrGroovyNumber and @CalcMgrGroovyString

There is currently not much in terms of documentation from Oracle on these functions, personally I think Calculation Manager documentation is pretty poor, anyway this is where Celvin comes to the rescue, Celvin has wrote a great OTN article which provides the lowdown on these functions

I am not going to steal any of Celvin’s limelight so go and read the article to understand the functions in detail, you may get sore eyes from some of the small screenshots though :)

Basically if you are running Calculation Manager 11.1.2.4.006+ and Planning 11.1.2.4.002+ you will be able to take advantage of this functionality, with these CDFs you can run Groovy scripts which will compile at runtime so you don’t get the headache like with Java CDFs

The OTN article focused on Essbase so I was keen to see if not only would it work with Planning but could it deliver my requirements.

There are a few configuration steps that are required before you can start using the Groovy functionality.

Download the latest Apache Groovy jar file.

Copy the jar to <MIDDLEWARE_HOME>\EPMSystem11R1\products\Essbase\EssbaseServer\java\udf

Create a whitelist properties file in the same directory to define which Java/Groovy packages/classes will be allowed in your Groovy scripts.

I included the following to be whitelisted.


You will see that I included the Calc Manager CDF logger class which helps provide additional logging to the one included with the Groovy CDFs.

The way I wanted to work with the Groovy functionality was to have a planning web form which would hold some information on the FDMEE rule, there would a business rule attached to the form with additional run time prompts, when running the business rule, the values held in the variables would be passed into the rule, the rule would then pass these into a Groovy script, the Groovy script would then make the http post to run the FDMEE rule based on the values passed into the script, the result of running the FDMEE rule would then be stored in the planning form and if there was a problem running the FDMEE rule an error message would be generated in planning.

It is much easier to understand if I break it down, starting with the business rule in Calculation Manager.


The first two "RUNJAVA" lines set the logging level and the format of the log, I have gone for “FINE” as it records the right level of detail in the log that I am looking for.

The default location of the log is the same as the essbase.log, it is possible to change the location of the log, in the end solution I set the log in the FDMEE shared location so it was easier to access it.

The third "RUNJAVA" line defines that script will be compiled as it will be run from within a FIX, the script is file based and located in the FDMEE shared location, I kept it there for ease of maintenance and migrations, finally a list of variables which will be passed into the Groovy script.


The next section of the script an Essbase calc script variable is defined which will hold the value returned from calling the Groovy script.

A FIX is used to narrow down the intersection of data on the planning form.

Member “FDMEE_Run_Date” will store the current date.

“FDMEE_Rule_Status” will hold the value returned from the Groovy script, the value determines the status of running the FDMEE rule, in planning the member has a Smart List assigned to provide a friendly status name instead of a number.

In my example I am using the @CalcMgrGroovyNumber function, the name of the script is included, it is a bit of a shame that when you are using a file you have to use the script name twice, it would be nice if you could allocate a name for the script instead of the full path.

There is then a list of variables and the values which are passed into the Groovy script, these are mainly set by run time prompts which you will see shortly.

I could have used the @CalcMgrGroovyString function but I wanted to return a value so I could then generate an error message to inform the user that running the rule failed and why it failed.


As for the Groovy script well I am not going to include every line of code but first static variables are defined and then the parameters and values are built up for posting to the servlet, the values are the ones passed into the Groovy script.


A single user with an encrypted password is used to run the FDMEE rules


I use the Calc Manager CDF logger class which I added to the whitelist properties file to write the full posting string to the log.

A http connection is made to the FDMEE servlet and the parameters posted to the servlet.


The response from the FDMEE servlet is then parsed and depending on the return string a value is returned to the business rule.

So let’s see it all in action, a form was created and added to a task list, the form displays the user and the available FDMEE load rules in the POV, these are controlled by access permissions.


Two members hold the status and date which you will have seen as part of the business rule.

The business rule was attached to the form.


Running the rule displays the list of run time prompts with default values which can be overridden.


I used substitution variables for the start and end period of the FDMEE load rule, I did have an issue in Calc Manager where if a string variable value contains a hyphen it would treat it as a number when passing into the rule, to get around this I had to remove the hyphen and then add it back in again in the Groovy script, I have never got round to looking if there is another way round this or if it is a bug.

I know I could have moved some of the variables into the form but most of this is for demo purposes and the final solution was slightly different, the good thing is there are different ways of achieving the same end result.

If there are no problems running the FDMEE rule the standard business rule information message is displayed.


Then the form is populated with the status and run date.


So let us run the rule again and enter an invalid value into a run time variable.


Now an error message is returned to the user.


The form is updated to reflect this error.


The form and rule with prompts can also be run from Smart View.


I also created a review form which shows the current status of the FDMEE rules that have been run from planning.


The log is formatted in the way I set in the business rule and contains the additional lines that I added in the Groovy script, using the “FINE” log level it also includes the value returned to the business rule.


Well there you go that was my first journey into using Groovy with planning which I hope you found interesting.

Monday, 24 October 2016

EPM and ORDS – Part 4

On to the final part of the series looking at Oracle Rest Data Services (ORDS) and EPM, a quick recap of the previous posts:

Part 1 – Overview of ORDS and process to get up and running with it.

Part 2 – ORDS administration using SQL Developer and “AutoREST” functionality.

Part 3 – Developing REST resources using SQL Developer and protecting resources with security.

In this final instalment I will go through a few REST examples using ORDS with EPM and cover some of the functionality that has not been discussed up to now.

I am going to assume you have read through Parts 1 to 3 so have a good understanding of what ORDS is all about.

In the last part I went through an example of creating a resource against a planning applications audit database table, the audit table is probably one of the most common tables you would want to access directly as currently with on-premise planning there is no access to the data through the user interface.

So say you have provided one or more REST resources to the table and delivered this in a structured format, up to now I have only used JSON as the data format but it is also possible to change this to deliver the content in CSV format.

To do this I am going to take my existing “audit” module and select “Add Template”


I am going to name this resource “expcsv”


In the “Data Format” drop-down list there are the options of JSON or CSV so for this example I have chosen CSV


I don’t believe the pagination size is honoured when using CSV so be careful to restrict what is returned using SQL if the results contain a large amount of rows.

I copied the same SQL from the example in Part 2 and uploaded the module.

If you enter the resource URL into a browser or REST client the response will be outputted in CSV format.


In scripting terms, it is extremely simple to generate a CSV file from the REST resource.


Now you have a locally generated CSV file, in the desired format and can be delivered whenever required.


I know this would be beneficial for many planning on-premise users out there.

Let us take another example that could be useful in the planning community and that is dimension metadata.

There are a number of standard ways to get dimension information out of planning but it is not so customisable and this is where SQL and ORDS can deliver.

I have created a new module and template in exactly the same way as all my examples.


As for the SQL to generate if you have a search on the internet there are some resources out there which will get you on your way.

I have created a SQL query to return product member information from the demo planning application.


The query generates the following output:


I have kept it simple and the SQL can be enhanced to output any of the member property information.

Once the module has been uploaded the dimension metadata will be available in JSON or CSV format depending on the data format type chosen.


Once again this is very easy to translate into a script and with a few lines of code you have access to the metadata which you can then further process if required.


Right, time to take it one step further and look at changing settings in a planning application, please be aware this is just an example and I am only demonstrating it to show what is possible with ORDS.

A common setting change in a planning application is maintenance mode, it is certainly possible to do this via command line but wouldn’t it be nice to have a REST resource to achieve this functionality.

I am going to create a new module called “maint”


In the template I am going to use a bind variable called “type” using the format {varname}


When using the resource, you put a value into the URL for the variable and then this is passed in and the value can be accessed which I will demonstrate shortly.

For the first time I am going to be using “PL/SQL” as the source type as this allows us to get a little more creative than just using SQL.


With the resource created the PL/SQL can be created in exactly the same way as when using SQL.


The table HSP_SYSTEMCFG has a column called LOGIN_LEVEL which basically relates to the maintenance mode.

If the value is 0 then all users can access the planning application, if 2 then only administrators can access and if 3 then just the owner.

There is a possible value of 1 which means interactive but that is not part of the functionality in the user interface or through the command line so I am leaving it out.

In the script there is the variable “:type” and the value in the REST resource URL will be passed into this variable, I am using friendly names for the variable instead of a number.

As planning uses a caching system it is not enough to just update the table, to get around the caching the HSP_ACTION table can be populated to update the cache, if you want to understand more about updating the cache then you can read all about it here.

To put this into action couldn’t be easier and can be achieved in a browser or a one-line script.

To put the application into administrator maintenance mode the URL includes “admin”


If a success response is returned the maintenance mode should have been updated

A quick check in the planning application confirms the setting has been applied.


The application will not be accessible for planning users.


By entering “all” into the request the application be can be returned to all user access.


The maintenance mode setting has been successfully updated.


Users can now access the application.


So this solution provides an effective alternative to using the command line utility without the hassle of having to run it from the planning server.

I know that the focus up to now has been around planning so let us look at a few other EPM areas.

The Shared Services database has a lot of useful content, take LCM for example and migration status information.

The migration status report can be accessed through Shared Services but there is no option to automatically generate this information for download and no way to customise it.

ORDS can come to the rescue again, I created a new module and two resources, one for returning LCM status information and the other for LCM failures based on passing in the migration ID.


The SQL is based on tables starting with "LCM_*" and the output provides more information than is currently available through the Shared Services report.


In scripting terms, it is doesn’t take much effort to produce an enhanced migration status report.


Filtering the returned rows to show only failures could be achieved using parameters in the URL or in a script.


The response provides the migration ID which then can be used in the second resource to return detailed information about a failure.


This provides quick access to details on why the migration failed without the requirement to log into Shared Services.


A report could be automatically generated and distributed which is currently not possible through Shared Services.

Moving on to FDMEE, a mass of information to choose from but how about batch scheduler details which is currently not easily obtained without having to log into the ODI studio or console.


A bit of custom SQL and batch schedule details can be returned with ease.


The same goes for scripting the output.


Next on to Calculation Manager, wouldn’t it be nice to be able to get a report of all the rules and the script content.

This can be achieved by either going to the calc manager database tables or the planning applications, I found it easier to parse the entries in the planning application tables.

The following example filters on a specific rule, if you wanted to return all the rules then just remove the filter parameters in the URL.


To replicate this with a script I created the following.


I then redirected this to a CSV file.


Now I have list of rules and script content which can be opened and viewed in Excel.


Not a bad way to document business rules and can be run whenever required without any convoluted processes

With all the examples I have been using the GET method so how about inserting data using the POST method, well say I have an automated process that loads member information from a database table, an easy way to populate this table would be to put it into the hands of ORDS to manage.

One way of doing this could by using the “AutoREST” functionality and all that would be required would to enable the database table for REST services and create an alias.

I created an alias of “prod” for table “VISPROD”, to insert a row into the table I could POST the following JSON.


The table will then have the row inserted.


This is fine for small inserts but what if I want an easier method to insert multiple rows using CSV format.

The good news is “AutoREST” also comes with a batch load option and is available to any table that has been REST enabled.

I can insert multiple rows using CSV format with the following operation.


The batch load functionality has many parameters available and in the above example I am truncating the table before inserting.

The response will include the number of records processed and failed.


The rows should then be visible in the table.


If I wanted to load data directly from a file, then this is pretty simple to do as well.


The post to the REST resource would just need the CSV file to be included.


To delete a row from a table can be achieved using the DELETE method and including filter parameters to specify the row.


The response will confirm the number of rows deleted.


Well I am going to leave it there for the series on ORDS as I have covered a hell of a lot, as you probably gathered I am a big fan of the product and if you are an Oracle database customer then I really don’t see why you wouldn’t consider using ORDS as there is no extra cost involved, there is so potential to assist in delivering beneficial solutions without a big hassle.

If you are interested in understanding more about ORDS and how it could help you then please feel free to get in touch.