Flexera
Golang 1.16 | cobra , promptui CLI | interactive and non-interactive mode | CircleCI | travis CI
Complexity
Runtime complexity
-------------------
Indexing: O(n), n-> number of lines in the csv
Calculation: O(1), Amortized value, constant time, as the data is parsed from the index (ideally total user having those application id)
Storage complexity
------------------
O(s), s-> size of the data without comments that is currently being searched
Statistics
----------
Processing large CSV file ~1GB for calculating the licence cost , time taken <15 seconds
Processing large CSV file ~1GB for calculating the licence cost , < 5MB memory
Generating index for all the application id in ~1GB CSV file, ~4GB Memory consumed
Index structure
map [applicationId] -> [userId] -> Laptop -> Set(computerId)
Desktop -> Set(computerId)
Running Pre-built Image
To Run the pre-built image, the image can be downloaded from the following releases link
- Download the release corresponding to your Operating System architecture and run the command
The files need to be copied to the working directory
https://github.com/techievee/flexera/releases/tag/v1.1.0
Building image
There are multiple ways to build an image
git clone https://github.com/techievee/flexera.git
cd flexera
go build -trimpath -ldflags "-X main.Build=v1.1.0" -o ./flexera ./cmd
- using makefile (linux and mac)
git clone https://github.com/techievee/flexera.git
cd flexera
make all
make bin-darwin
make bin-windows
Program Components
The program consists of the following components
console
: Helps in invoking the program and to run in either interactive or non-interactive CLI mode
cmd
: Command processor that helps in executing commands
indexed_data
: Index processor, which stores and process index for inventory file based on the searched application id(s). Helps in searching data through index
data
: Data store that reads and process the csv files from disk to memory structures.
utilities
: Helper functions.
Command reference
Interactive Console
./flexera --help
flexera is a CLI library that indexes and search csv file for calculating the licencing cost.
This application is a tool that reads the csv files, indexes it and
calculates the total licences required for the application.
Usage:
flexera [flags]
flexera [command]
Available Commands:
calculate Flexera CLI Application to Index and Search CSV File Non interactively to find the total number of licence required
help Help about any command
Flags:
--config string config file (default is $HOME/flexera.yaml)
-f, --file string Path of the CSV file, Defaults to currentPath/sample-small.csv
-h, --help help for flexera
Use "flexera [command] --help" for more information about a command.
Non-Interactive Console
Flexera calculate is a CLI library that indexes and search CSV file.
This application is a tool that reads the csv file, indexes it and
searches them without any user interactions.
Usage:
flexera calculate [flags]
Flags:
-a, --application-id string ID of the application, for which the licences need to be calculated
-h, --help help for calculate
Global Flags:
--config string config file (default is $HOME/flexera.yaml)
-f, --file string Path of the CSV file, Defaults to currentPath/sample-small.csv
Program Specification
Interactive Console
-
Running the ./flexera
will invoke the Interactive CLI, the inventory input files need to be present in the directory where the command is present or need to overridden using -f or --file flags or FLEXERA_FILE environment variable
Invoking interactive command without any CLI flags
Invoking interactive command using the short flags
Invoking interactive command using the full flags
Invoking interactive command after setting environment variable
-
Press Enter to pass the entry screen
-
Use arrow keys and select the licence calculation option
-
Enter the application id for which the licences need to be calculated, Multiple applicationId can be provided separated by comma
While entering the application id string, it gets validated to passthrough the calculation command, the following rules apply
-
If enter is selected without any value it is considered as empty search, and it won't be validated
-
If calculation is performed providing one value or multiple comma separated value its considered as valid
-
If alphanumeric or text is entered for field, it won't allow to passthroughs, until the input is corrected
Invalid inputs
- Result gets displayed after the input is validated, along with runtime statistics
Non-Interactive Console
-
Running the ./flexera calculate
command (flexera with additional calculate verb) will invoke the Non-interactive CLI for one time run or calculation, the inventory input files need to be present in the directory where the command is present or need to overridden using -f or --file flags or FLEXERA_FILE environment variable along with the applicationId via -a short flag , --application-id, or env variable FLEXERA_APPLICATION_ID
Invoking non-interactive command with full flag name
Invoking non-interactive command using the short flags
Invoking non-interactive command after setting environment variable
-
Result gets displayed after the input is validated, along with runtime statistics
Assumptions
- If the computer type or any other value is empty, then they won’t be considered as any additional licence, that line of CSV is considered as a noisy data
ComputerID |
UserID |
ApplicationID |
ComputerType |
Comment |
1 |
- |
371 |
DESKTOP |
Exported from System A |
2 |
8361 |
- |
Desktop |
Exported from System B |
- |
4380 |
371 |
Desktop |
Exported from System A |
4 |
3312 |
371 |
- |
Exported from System A |
- The first line doesn't have UserID
- The second line doesn't have ApplicationId
- The third line doesn't have ComputerId
- The last line doesn't have Computer Type
All these data are skipped.
Result : 0
- If the computer with the same ComputerID is assigned to multiple users, then the licence is calculated based on the users
ComputerID |
UserID |
ApplicationID |
ComputerType |
Comment |
1 |
1 |
371 |
DESKTOP |
Exported from System A |
1 |
2 |
371 |
Desktop |
Exported from System B |
2 |
1 |
371 |
Desktop |
Exported from System A |
3 |
1 |
371 |
Laptop |
Exported from System A |
- Here, the computer with ComputerId = 1 is assigned to the user with UserID 1 and 2, then I would consider them as 2 licences as the calculations are based on the user and the combination of the computer.
Result: 3 licence
- for user 1, 2 licences(combined use for 2,3 and separate use of computer 1)
- for user 2 , 1 licence (computer 1)
- If the computer with the same ComputerID is assigned to laptop and desktop and assigned to a single user, it would be treated as invalid and licence for get calculated for that user, for that application.
ComputerID |
UserID |
ApplicationID |
ComputerType |
Comment |
1 |
1 |
371 |
DESKTOP |
Exported from System A |
1 |
1 |
371 |
laptop |
Exported from System B |
2 |
1 |
371 |
Desktop |
Exported from System A |
- Here, the Computer with ComputerId=1 is both laptop and desktop, hence both the data are considered as invalid and they are not included for the licence calculation for that user for that application
- the ComputerId=2 is desktop only, which is considerd as valid
Result: 1
Libraries used