IHAC who has a lot of
applications specified in OCI. And they have 5 OCI servers. Globally
from -
SELECT count(*) FROM
dwh_inventory.application;
- it is over 50'000.
Of the 5
insight-migration.py collects done, we had
50000,10'000,45000,50000,50000 applications. And trying to import
applications into CI is very very slow (if say 10 seconds per
application import, you get the picture), so we need to trim this
down.
When I was looking in
Applications.json, I see a lot of -
"assets":
[]
- which got me
thinking, why don't we just remove everything (every Application)
with -
"assets": []
We can use PowerShell
to process the JSON file (I really need to find time to learn
Python):
$apps = Get-Content -Raw -Path Applications.json | ConvertFrom-Json
To count the number of apps, it is just:
$apps.count
To find the number of apps with no assets:
($apps | where-object {$_.assets.count -eq 0}).count
Conversely, to find the numbers of apps with assets (in our case, this turns out to be a very tiny number compared to the total):
($apps | where-object {$_.assets.count -ne 0}).count
To get an output in JSON format of just the Applications which have assets:
$apps | where-object {$_.assets.count -ne 0} | ConvertTo-Json -Depth 3 | Set-Content Applications2.json
Or, even more directly:
(Get-Content -Raw -Path Applications.json | ConvertFrom-Json) | where-object {$_.assets.count -ne 0} | ConvertTo-Json -Depth 3 | Set-Content Applications-new.json
This should give you a much more compact Applications.json file (one renamed from the output above), and speed up your OCI to CI Application migration.
Note: The Applications-new.json file might be larger after running the above. This is simply due to extra spaces in the file, but if you ZIP the file, it will be smaller.
PS Interesting reading (use $PSVersionTable to check your PowerShell version):
Going Deep Converting PowerShell Objects to JSON | Jeff Brown Tech
~~~~~
Comments
Post a Comment