cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2458
Views
1
Helpful
5
Comments
Orf Gelbrich
Cisco Employee
Cisco Employee
Task Name

Multi Column CSV file read and great DB entries

Description

Prerequisites

Tested on UCSD  6.5

CategoryWorkflow
ComponentsvSphere 5.x
User Inputsinputs length have been tested up to 1300 characters


Instructions for Regular Workflow Use:

  1. Download the attached .ZIP file below to your computer. *Remember the location of the saved file on your computer.
  2. Unzip the file on your computer. Should end up with a .WFD file.
  3. Log in to UCS Director as a user that has "system-admin" privileges.
  4. Navigate to "Policies-->Orchestration" and click on "Import".
  5. Click "Browse" and navigate to the location on your computer where the .WFD file resides. Choose the .WFD file and click "Open".
  6. Click "Upload" and then "OK" once the file upload is completed. Then click "Next".
  7. Click the "Select" button next to "Import Workflows". Click the "Check All" button to check all checkboxes and then the "Select" button.
  8. Click "Submit".
  9. A new folder should appear in "Policies-->Orchestration" that contains the imported workflow. You will now need to update the included tasks with information about the specific environment.

User Input:

Screen Shot 2017-03-20 at 12.46.38 PM.png

The workflow:

Screen Shot 2017-03-20 at 12.46.25 PM.png

Workflow run:

Screen Shot 2017-03-20 at 12.46.10 PM.png

Screen Shot 2017-03-20 at 12.45.27 PM.png

Log file:

Screen Shot 2017-03-20 at 12.45.56 PM.png

Script Module:

Screen Shot 2017-03-20 at 12.53.51 PM.png

Tabular report in multcolread:

Screen Shot 2017-03-20 at 12.54.14 PM.png

The script:

Screen Shot 2017-03-20 at 12.54.53 PM.png

The Code:

Note:  Column A is being used for the selection process to provide the whole line of values.

//Provide import statements here if needed for your written code.

//Write your own logic at appropriate place as indicated below for populating the records.

//DO NOT EDIT OR DELETE ANYTHING IN THE AUTOGENERATED CODE.

function implementationForTabularReport(report)

{

var model = new TabularReportInternalModel();

model.addTextColumn("A","A");

model.addTextColumn("B","B");

model.addTextColumn("C","C");

model.addTextColumn("D","D");

model.completedHeader();

//You can get values from the DB and populate the model object as shown below

//which got generated based on the Column Entries.

//model.addTextValue("A");

//model.addTextValue("B");

//model.addTextValue("C");

//model.addTextValue("D");

//model.completedRow();

//START OF YOUR IMPLEMENTATION.

importPackage(com.cloupia.service.cIM.inframgr);

importPackage(com.cloupia.service.cIM.inframgr.workflowmgr);

// importPackage(java.util);

// importPackage(java.lang);

importPackage(com.cloupia.service.cIM.inframgr.customactions);

importPackage(com.cloupia.service.cIM.inframgr.forms.wizard);

importPackage(com.cloupia.service.cIM.inframgr);

importPackage(com.cloupia.model.cIM);

importPackage(com.cloupia.feature.customactions.lovproviders);

importPackage(java.util);

importPackage(java.io);

importPackage(com.cloupia.service.cIM.inframgr.forms.wizard);

var fileReader = new FileReader("/tmp/info.csv");

var br = new BufferedReader(fileReader);

var tokens;

var UCSDLoopCounter = new ArrayList();

while(true){

       var line = br.readLine();

       if(line == null)break;

       logger.addInfo("Line" + line);

       tokens = line.split(",");

//model.addTextValue(tokens[0]);

//Assume In the tabular report col ‘A’ is marked as management column

model.addTextValue(tokens[0]+"@"+tokens[1]+"@"+tokens[2]+"@"+tokens[3]);//We need to set the values like this to the management column of the tabular report.

model.addTextValue(tokens[1]);

model.addTextValue(tokens[2]);

model.addTextValue(tokens[3]);

model.completedRow();

//END OF YOUR IMPLEMENTATION.

model.updateReport(report);

}

Sample CSV file:

[root@localhost ~]# cat /tmp/info.csv


mgt,VW,Jetta,Silver

mgt,VW,Golf,Silver

mgt,Chevy,Truck,2500

mgt,Potiac,2Door,Blue

mgt,Chevy,Suburban,Green

mgt,Chevy,Suburban,Black_Silver

mgt,Ford,EscordGT,Black

mgt,VW,Van,Red

mgt,Chevy,Vega,red


If this is attempted on UCSD version below 6.5 this has to be disabled:

This is not recommended for a production system!

Total disable of security policies

=================================

vi /opt/infra/bin/inframgr.env

#Original

#JVM_ARGS="-DSVC=$SVC -Xms$MEMORY_MIN -Xmx$MEMORY_MAX $REMOTE_DEBUG_OPTS -Djava.security.manager -Djava.security.policy=security.policy -DpreInitSchema=true -verbose:gc -Dfile.encoding=UTF-8 $JMX_OPTS"

#Modification

JVM_ARGS="-DSVC=$SVC -Xms$MEMORY_MIN -Xmx$MEMORY_MAX $REMOTE_DEBUG_OPTS  -DpreInitSchema=true -verbose:gc -Dfile.encoding=UTF-8 $JMX_OPTS"

Comments
dkhwch
Level 1
Level 1
Hello Orf Thank you very much for this post, it was really helpful to me. I imported your workflow and it worked well. General Information: --------------------- I use UCSD Version 6.6 If I’m talking about filtering I mean “Admin Input Filter” for a Workflow User Input. -------------------- I have some questions / problems with which you can maybe help me: Problems / Questions: If i have a Tabular Report like in your example with a CSV file in /tmp and i have a column named "NodeID". And then i want to filter for example: NodeID CONTAINS ${SomeInputField} I get the following error: access denied ("java.io.FilePermission" "/tmp/info5.csv" "read") I know i can filter in the top right corner of the Tabular Report but maybe i would still want to filter based on previous selection. If i provide the values for the Tabular Report static: model.addTextValue("Management"); model.addTextValue("Tenant_Description_02"); model.completedRow(); .. Then the filtering works fine. I thought oh ok, so i'll just create myself a tool which reads a CSV file and generates an output like that..which then I can copy paste in my tabular report. But in this filed i'm limited to 8192 characters.. Coming back to why i would want to filter based on previous input filed. ( for exmaple: NodeID CONTAINS ${SomeInputField}) Maybe further down in my Workflow an input field from Cisco out of the Box Task which is also like a Tabular Report. (for example this type: APIC Device Fabric Leaf Active Node Identity) Now if I had my custom Tabular Report as in input field before this” APIC Device Fabric Leaf Active Node Identity” input I would want to filter based on value of a specific column from my custom Tabular Report. So now if that’s possible or how to do this because I cannot say CONTAINS ${Input Field Name.ColumnName)… and I can also not filter based on task outputs (like your ChopByAtSymbol) since I only have this value when I click on submit.. Im using something similar in my workflows but instead of Tabular Report I will filter based on a previous simple LOV Input field. Then I can use in for example my tabular input “APIC Device Fabric Leaf Active Node Identity” ColumnX CONTAINS ${previousLOVInputfield} and this works great. So now the improvement would be If I could do the same thing just using a tabular report instead of a simple LOV as a filter for my next Inputs (because i have multiple values in a tabular report which i can then use for other tasks with your ChopAtBySymbol Task). Or if that’s not possible It would be nice if I could filter my custom Tabular Report based on previous simple LOV input and not get this java error. I hope you got what my problem / question is… it’s a bit complex for me to write it down like that if you want me to open a post where I could also use printscreens etc. to make things clearer. Also sorry for by simple (bad english). Thank you very much in advance Kind regards, Dominik
Orf Gelbrich
Cisco Employee
Cisco Employee

Have you played with Input Rules in the input section? They can handle a contains. 

 

Screen Shot 2018-11-09 at 5.48.47 AM.png

Orf Gelbrich
Cisco Employee
Cisco Employee

Another option would be to look into validated input variables and these examples here.  You can hit the bash shell before the workflow actually runs and make decisions.  Like check if the host name is correct with a sql call, or look at some file or do some computation.  

 

Screen Shot 2018-11-09 at 5.50.09 AM.png

dkhwch
Level 1
Level 1

Thank you very much for the quick response.

 

Yes i've used input rules in my workflows, but thanks to your note, i had a look at the example folder again and found some helpful use cases.

Also these input validators look very interesting i didn't know you can actually do some computation before the workflow runs. I need to have a deeper look at it and see what i can do with it.

 

Do you know if there's a way to fix the following error: AdminInputFilter.PNG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

I crated this "BIT_Leaf_Provisioning" Tabular Report with your example above (based on CSV input).

 

 

 

Orf Gelbrich
Cisco Employee
Cisco Employee

Here is my e-mail. ogelbric@cisco.com.   Send me an e-mail and I can send you some experimental workaround. 


Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community:

Quick Links