Skip to content

Instantly share code, notes, and snippets.

@zevnull
Created May 20, 2013 12:37
Show Gist options
  • Save zevnull/5611974 to your computer and use it in GitHub Desktop.
Save zevnull/5611974 to your computer and use it in GitHub Desktop.
Get set of NSDs from config file
/**
* Get set of NSDs from config file
*
* @return set of NSDs from config file
*/
public Set<String> getNSDsSetFromConfig()
{
DMLogger.methodStarted();
String jsonTxt = "";
try
{
jsonTxt = ssh.runCommand( "less /etc/ddn/directmon/system-config.json" );
}
catch( Exception e )
{
String errorText = " Error with 'ssh.runCommand( \"less /etc/ddn/directmon/system-config.json\" );' , e";
DMLogger.errorInMethod( errorText );
throw new RuntimeException( errorText );
}
JSONObject json = ( JSONObject ) JSONSerializer.toJSON( jsonTxt );
Set<String> s = json.keySet();
List<String> solutionsWithNSD = new ArrayList<String>();
List<String> solutionTypes = new ArrayList<String>();
for( Object value : s )
{
if( !value.toString().contains( ":sfa" ) )
{
Set<String> keySet = json.getJSONObject( value.toString() ).keySet();
solutionsWithNSD.addAll( keySet );
solutionTypes.add( value.toString() );
}
}
List<Collection> nsdAndStorageList = new ArrayList<Collection>();
for( Object value : s )
{
if( !value.toString().contains( ":sfa" ) )
{
for( String nsdSolution : solutionsWithNSD )
{
nsdAndStorageList.add( json.getJSONObject( value.toString() ).getJSONObject( nsdSolution ).values() );
}
}
}
List<String> nsdList = new ArrayList<String>();
for (Collection aNsdAndStorageList : nsdAndStorageList) {
int currentNdsCount = aNsdAndStorageList.toArray()[0].toString().split("],").length;
for (int j = 0; j < currentNdsCount; j++) {
// [["qa-nsd1"
String tmp = aNsdAndStorageList.toArray()[0].toString().split("],")[j].split(",\"nsd\",")[0];
tmp = tmp.substring(tmp.indexOf("\"") + 1, tmp.length() - 1);
nsdList.add(tmp);
}
}
Set<String> result = new TreeSet<String>( nsdList );
DMLogger.methodFinished( result );
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment