@Test public void testFindAllExportedVariables_withFacets() { Component component = new Component( "comp 1" ); component.addExportedVariable( new ExportedVariable( "var1", "another value" )); component.addExportedVariable( new ExportedVariable( "var2", "var 2 value" )); component.addExportedVariable( new ExportedVariable( "ip", null )); Facet f1 = new Facet( "f1" ); f1.addExportedVariable( new ExportedVariable( "param1", "value1" )); component.associateFacet( f1 ); Facet f2 = new Facet( "f2" ); f2.addExportedVariable( new ExportedVariable( "param2", "value2" )); component.associateFacet( f2 ); Facet f3 = new Facet( "f3" ); f3.addExportedVariable( new ExportedVariable( "param3", "value3" )); component.associateFacet( f3 ); component.addExportedVariable( new ExportedVariable( "f3.param3", "component overrides facet" )); Facet f4 = new Facet( "f4" ); f4.addExportedVariable( new ExportedVariable( "param4-1", "value4" )); f4.addExportedVariable( new ExportedVariable( "param4-2", "value4" )); f2.extendFacet( f4 ); f2.addExportedVariable( new ExportedVariable( "f4.param4-1", "facet overrides facet" )); Instance instance = new Instance( "inst 1" ); instance.setComponent( component ); instance.overriddenExports.put( "var1", "some value" ); instance.overriddenExports.put( "toto.ip", null ); instance.overriddenExports.put( "f1.param1", "my-value" ); instance.data.put( Instance.IP_ADDRESS, "192.168.1.18" ); Component extendedComponent = new Component( "extended" ); extendedComponent.addExportedVariable( new ExportedVariable( "v", "hop" )); component.extendComponent( extendedComponent ); component.addExportedVariable( new ExportedVariable( "extended.v", "nop" )); Map<String,String> map = InstanceHelpers.findAllExportedVariables( instance ); Assert.assertEquals( 16, map.size()); Assert.assertEquals( "some value", map.get( "comp 1.var1" )); Assert.assertEquals( "var 2 value", map.get( "comp 1.var2" )); Assert.assertEquals( "192.168.1.18", map.get( "comp 1.ip" )); Assert.assertEquals( "192.168.1.18", map.get( "toto.ip" )); Assert.assertEquals( "nop", map.get( "extended.v" )); Assert.assertEquals( "my-value", map.get( "f1.param1" )); Assert.assertEquals( "value1", map.get( "comp 1.param1" )); Assert.assertEquals( "value2", map.get( "f2.param2" )); Assert.assertEquals( "value2", map.get( "comp 1.param2" )); Assert.assertEquals( "component overrides facet", map.get( "f3.param3" )); Assert.assertEquals( "component overrides facet", map.get( "comp 1.param3" )); Assert.assertEquals( "facet overrides facet", map.get( "f4.param4-1" )); Assert.assertEquals( "value4", map.get( "f4.param4-2" )); }
public static Map<String,String> findAllExportedVariables( Instance instance ) { Map<String,String> result = new HashMap<> (); if( instance.getComponent() != null ) result.putAll( ComponentHelpers.findAllExportedVariables( instance.getComponent())); Map<String,Set<String>> localNameToFullNames = new HashMap<> (); for( String inheritedVarName : result.keySet()) { String localName = VariableHelpers.parseVariableName( inheritedVarName ).getValue(); Set<String> fullNames = localNameToFullNames.get( localName ); if( fullNames == null ) fullNames = new HashSet<> (); fullNames.add( inheritedVarName ); localNameToFullNames.put( localName, fullNames ); } for( Map.Entry<String,String> entry : instance.overriddenExports.entrySet()) { Set<String> fullNames = localNameToFullNames.get( entry.getKey()); if( fullNames == null ) { result.put( entry.getKey(), entry.getValue()); } else if( fullNames.size() == 1 ) { result.put( fullNames.iterator().next(), entry.getValue()); } else { result.put( entry.getKey(), entry.getValue()); for( String name : fullNames ) result.put( name, entry.getValue()); } } String ip = findRootInstance( instance ).data.get( Instance.IP_ADDRESS ); if( ip != null ) VariableHelpers.updateNetworkVariables( result, ip ); Map<String,String> updatedResult = new LinkedHashMap<>( result.size()); for( Map.Entry<String,String> entry : result.entrySet()) { String value = entry.getValue(); if( value != null ) { for( Map.Entry<String,String> rbcfMetaVar : DockerAndScriptUtils.buildReferenceMap( instance ).entrySet()) { value = value.replace( "$(" + rbcfMetaVar.getKey() + ")", rbcfMetaVar.getValue()); } } updatedResult.put( entry.getKey(), value ); } return updatedResult; }
InstanceHelpers { public static Map<String,String> findAllExportedVariables( Instance instance ) { Map<String,String> result = new HashMap<> (); if( instance.getComponent() != null ) result.putAll( ComponentHelpers.findAllExportedVariables( instance.getComponent())); Map<String,Set<String>> localNameToFullNames = new HashMap<> (); for( String inheritedVarName : result.keySet()) { String localName = VariableHelpers.parseVariableName( inheritedVarName ).getValue(); Set<String> fullNames = localNameToFullNames.get( localName ); if( fullNames == null ) fullNames = new HashSet<> (); fullNames.add( inheritedVarName ); localNameToFullNames.put( localName, fullNames ); } for( Map.Entry<String,String> entry : instance.overriddenExports.entrySet()) { Set<String> fullNames = localNameToFullNames.get( entry.getKey()); if( fullNames == null ) { result.put( entry.getKey(), entry.getValue()); } else if( fullNames.size() == 1 ) { result.put( fullNames.iterator().next(), entry.getValue()); } else { result.put( entry.getKey(), entry.getValue()); for( String name : fullNames ) result.put( name, entry.getValue()); } } String ip = findRootInstance( instance ).data.get( Instance.IP_ADDRESS ); if( ip != null ) VariableHelpers.updateNetworkVariables( result, ip ); Map<String,String> updatedResult = new LinkedHashMap<>( result.size()); for( Map.Entry<String,String> entry : result.entrySet()) { String value = entry.getValue(); if( value != null ) { for( Map.Entry<String,String> rbcfMetaVar : DockerAndScriptUtils.buildReferenceMap( instance ).entrySet()) { value = value.replace( "$(" + rbcfMetaVar.getKey() + ")", rbcfMetaVar.getValue()); } } updatedResult.put( entry.getKey(), value ); } return updatedResult; } }
InstanceHelpers { public static Map<String,String> findAllExportedVariables( Instance instance ) { Map<String,String> result = new HashMap<> (); if( instance.getComponent() != null ) result.putAll( ComponentHelpers.findAllExportedVariables( instance.getComponent())); Map<String,Set<String>> localNameToFullNames = new HashMap<> (); for( String inheritedVarName : result.keySet()) { String localName = VariableHelpers.parseVariableName( inheritedVarName ).getValue(); Set<String> fullNames = localNameToFullNames.get( localName ); if( fullNames == null ) fullNames = new HashSet<> (); fullNames.add( inheritedVarName ); localNameToFullNames.put( localName, fullNames ); } for( Map.Entry<String,String> entry : instance.overriddenExports.entrySet()) { Set<String> fullNames = localNameToFullNames.get( entry.getKey()); if( fullNames == null ) { result.put( entry.getKey(), entry.getValue()); } else if( fullNames.size() == 1 ) { result.put( fullNames.iterator().next(), entry.getValue()); } else { result.put( entry.getKey(), entry.getValue()); for( String name : fullNames ) result.put( name, entry.getValue()); } } String ip = findRootInstance( instance ).data.get( Instance.IP_ADDRESS ); if( ip != null ) VariableHelpers.updateNetworkVariables( result, ip ); Map<String,String> updatedResult = new LinkedHashMap<>( result.size()); for( Map.Entry<String,String> entry : result.entrySet()) { String value = entry.getValue(); if( value != null ) { for( Map.Entry<String,String> rbcfMetaVar : DockerAndScriptUtils.buildReferenceMap( instance ).entrySet()) { value = value.replace( "$(" + rbcfMetaVar.getKey() + ")", rbcfMetaVar.getValue()); } } updatedResult.put( entry.getKey(), value ); } return updatedResult; } private  InstanceHelpers(); }
InstanceHelpers { public static Map<String,String> findAllExportedVariables( Instance instance ) { Map<String,String> result = new HashMap<> (); if( instance.getComponent() != null ) result.putAll( ComponentHelpers.findAllExportedVariables( instance.getComponent())); Map<String,Set<String>> localNameToFullNames = new HashMap<> (); for( String inheritedVarName : result.keySet()) { String localName = VariableHelpers.parseVariableName( inheritedVarName ).getValue(); Set<String> fullNames = localNameToFullNames.get( localName ); if( fullNames == null ) fullNames = new HashSet<> (); fullNames.add( inheritedVarName ); localNameToFullNames.put( localName, fullNames ); } for( Map.Entry<String,String> entry : instance.overriddenExports.entrySet()) { Set<String> fullNames = localNameToFullNames.get( entry.getKey()); if( fullNames == null ) { result.put( entry.getKey(), entry.getValue()); } else if( fullNames.size() == 1 ) { result.put( fullNames.iterator().next(), entry.getValue()); } else { result.put( entry.getKey(), entry.getValue()); for( String name : fullNames ) result.put( name, entry.getValue()); } } String ip = findRootInstance( instance ).data.get( Instance.IP_ADDRESS ); if( ip != null ) VariableHelpers.updateNetworkVariables( result, ip ); Map<String,String> updatedResult = new LinkedHashMap<>( result.size()); for( Map.Entry<String,String> entry : result.entrySet()) { String value = entry.getValue(); if( value != null ) { for( Map.Entry<String,String> rbcfMetaVar : DockerAndScriptUtils.buildReferenceMap( instance ).entrySet()) { value = value.replace( "$(" + rbcfMetaVar.getKey() + ")", rbcfMetaVar.getValue()); } } updatedResult.put( entry.getKey(), value ); } return updatedResult; } private  InstanceHelpers(); static String computeInstancePath( Instance inst ); static boolean haveSamePath( Instance i1, Instance i2 ); static String findInstanceName( String instancePath ); static List<Instance> buildHierarchicalList( Instance inst ); static void insertChild( Instance parent, Instance child ); static Map<String,String> findAllExportedVariables( Instance instance ); static Instance findInstanceByPath( AbstractApplication application, String instancePath ); static Instance findInstanceByPath( Instance rootInstance, String instancePath ); static List<Instance> findInstancesByComponentName( AbstractApplication application, String componentName ); static Instance findRootInstance( Instance instance ); static Instance findScopedInstance( Instance instance ); static List<Instance> findAllScopedInstances( AbstractApplication app ); static List<Instance> getAllInstances( AbstractApplication application ); static boolean tryToInsertChildInstance( AbstractApplication application, Instance parentInstance, Instance childInstance ); static boolean hasChildWithThisName( AbstractApplication application, Instance parentInstance, String nameToSearch ); static File findInstanceDirectoryOnAgent( Instance instance ); static int countInstances( String instancePath ); static Instance replicateInstance( Instance instance ); static boolean isTarget( Instance instance ); static void removeOffScopeInstances( Instance scopedInstance ); static String findRootInstancePath( String scopedInstancePath ); static void fixOverriddenExports( Instance instance ); }
InstanceHelpers { public static Map<String,String> findAllExportedVariables( Instance instance ) { Map<String,String> result = new HashMap<> (); if( instance.getComponent() != null ) result.putAll( ComponentHelpers.findAllExportedVariables( instance.getComponent())); Map<String,Set<String>> localNameToFullNames = new HashMap<> (); for( String inheritedVarName : result.keySet()) { String localName = VariableHelpers.parseVariableName( inheritedVarName ).getValue(); Set<String> fullNames = localNameToFullNames.get( localName ); if( fullNames == null ) fullNames = new HashSet<> (); fullNames.add( inheritedVarName ); localNameToFullNames.put( localName, fullNames ); } for( Map.Entry<String,String> entry : instance.overriddenExports.entrySet()) { Set<String> fullNames = localNameToFullNames.get( entry.getKey()); if( fullNames == null ) { result.put( entry.getKey(), entry.getValue()); } else if( fullNames.size() == 1 ) { result.put( fullNames.iterator().next(), entry.getValue()); } else { result.put( entry.getKey(), entry.getValue()); for( String name : fullNames ) result.put( name, entry.getValue()); } } String ip = findRootInstance( instance ).data.get( Instance.IP_ADDRESS ); if( ip != null ) VariableHelpers.updateNetworkVariables( result, ip ); Map<String,String> updatedResult = new LinkedHashMap<>( result.size()); for( Map.Entry<String,String> entry : result.entrySet()) { String value = entry.getValue(); if( value != null ) { for( Map.Entry<String,String> rbcfMetaVar : DockerAndScriptUtils.buildReferenceMap( instance ).entrySet()) { value = value.replace( "$(" + rbcfMetaVar.getKey() + ")", rbcfMetaVar.getValue()); } } updatedResult.put( entry.getKey(), value ); } return updatedResult; } private  InstanceHelpers(); static String computeInstancePath( Instance inst ); static boolean haveSamePath( Instance i1, Instance i2 ); static String findInstanceName( String instancePath ); static List<Instance> buildHierarchicalList( Instance inst ); static void insertChild( Instance parent, Instance child ); static Map<String,String> findAllExportedVariables( Instance instance ); static Instance findInstanceByPath( AbstractApplication application, String instancePath ); static Instance findInstanceByPath( Instance rootInstance, String instancePath ); static List<Instance> findInstancesByComponentName( AbstractApplication application, String componentName ); static Instance findRootInstance( Instance instance ); static Instance findScopedInstance( Instance instance ); static List<Instance> findAllScopedInstances( AbstractApplication app ); static List<Instance> getAllInstances( AbstractApplication application ); static boolean tryToInsertChildInstance( AbstractApplication application, Instance parentInstance, Instance childInstance ); static boolean hasChildWithThisName( AbstractApplication application, Instance parentInstance, String nameToSearch ); static File findInstanceDirectoryOnAgent( Instance instance ); static int countInstances( String instancePath ); static Instance replicateInstance( Instance instance ); static boolean isTarget( Instance instance ); static void removeOffScopeInstances( Instance scopedInstance ); static String findRootInstancePath( String scopedInstancePath ); static void fixOverriddenExports( Instance instance );  }