@Test public void testDuplicateInstance_singleInstance() { Instance original = new Instance( "inst" ).channel( "chan" ).component( new Component( "comp" )); original.overriddenExports.put( "test", "test" ); original.overriddenExports.put( "A.port", "8012" ); original.data.put( "some", "data" ); original.getImports().put( "facet-name", new ArrayList<Import> ()); original.setStatus( InstanceStatus.DEPLOYED_STARTED ); Instance copy = InstanceHelpers.replicateInstance( original ); Assert.assertEquals( original.getName(), copy.getName()); Assert.assertEquals( original.channels, copy.channels ); Assert.assertEquals( original.overriddenExports.size(), copy.overriddenExports.size()); Assert.assertEquals( "test", copy.overriddenExports.get( "test" )); Assert.assertEquals( "8012", copy.overriddenExports.get( "A.port" )); Assert.assertEquals( 0, copy.getImports().size()); Assert.assertEquals( original.getComponent(), copy.getComponent()); Assert.assertEquals( InstanceStatus.NOT_DEPLOYED, copy.getStatus()); }
public static Instance replicateInstance( Instance instance ) { Map<Instance,Instance> instanceToDuplicate = new HashMap<> (); List<Instance> toProcess = new ArrayList<> (); toProcess.add( instance ); while( ! toProcess.isEmpty()) { Instance current = toProcess.remove( 0 ); Instance copy = new Instance(); copy.name( current.getName()); copy.component( current.getComponent()); copy.channels.addAll( current.channels ); copy.overriddenExports.putAll( current.overriddenExports ); instanceToDuplicate.put( current, copy ); Instance parent = instanceToDuplicate.get( current.getParent()); if( parent != null ) insertChild( parent, copy ); toProcess.addAll( current.getChildren()); } return instanceToDuplicate.get( instance ); }
InstanceHelpers { public static Instance replicateInstance( Instance instance ) { Map<Instance,Instance> instanceToDuplicate = new HashMap<> (); List<Instance> toProcess = new ArrayList<> (); toProcess.add( instance ); while( ! toProcess.isEmpty()) { Instance current = toProcess.remove( 0 ); Instance copy = new Instance(); copy.name( current.getName()); copy.component( current.getComponent()); copy.channels.addAll( current.channels ); copy.overriddenExports.putAll( current.overriddenExports ); instanceToDuplicate.put( current, copy ); Instance parent = instanceToDuplicate.get( current.getParent()); if( parent != null ) insertChild( parent, copy ); toProcess.addAll( current.getChildren()); } return instanceToDuplicate.get( instance ); } }
InstanceHelpers { public static Instance replicateInstance( Instance instance ) { Map<Instance,Instance> instanceToDuplicate = new HashMap<> (); List<Instance> toProcess = new ArrayList<> (); toProcess.add( instance ); while( ! toProcess.isEmpty()) { Instance current = toProcess.remove( 0 ); Instance copy = new Instance(); copy.name( current.getName()); copy.component( current.getComponent()); copy.channels.addAll( current.channels ); copy.overriddenExports.putAll( current.overriddenExports ); instanceToDuplicate.put( current, copy ); Instance parent = instanceToDuplicate.get( current.getParent()); if( parent != null ) insertChild( parent, copy ); toProcess.addAll( current.getChildren()); } return instanceToDuplicate.get( instance ); } private  InstanceHelpers(); }
InstanceHelpers { public static Instance replicateInstance( Instance instance ) { Map<Instance,Instance> instanceToDuplicate = new HashMap<> (); List<Instance> toProcess = new ArrayList<> (); toProcess.add( instance ); while( ! toProcess.isEmpty()) { Instance current = toProcess.remove( 0 ); Instance copy = new Instance(); copy.name( current.getName()); copy.component( current.getComponent()); copy.channels.addAll( current.channels ); copy.overriddenExports.putAll( current.overriddenExports ); instanceToDuplicate.put( current, copy ); Instance parent = instanceToDuplicate.get( current.getParent()); if( parent != null ) insertChild( parent, copy ); toProcess.addAll( current.getChildren()); } return instanceToDuplicate.get( instance ); } 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 Instance replicateInstance( Instance instance ) { Map<Instance,Instance> instanceToDuplicate = new HashMap<> (); List<Instance> toProcess = new ArrayList<> (); toProcess.add( instance ); while( ! toProcess.isEmpty()) { Instance current = toProcess.remove( 0 ); Instance copy = new Instance(); copy.name( current.getName()); copy.component( current.getComponent()); copy.channels.addAll( current.channels ); copy.overriddenExports.putAll( current.overriddenExports ); instanceToDuplicate.put( current, copy ); Instance parent = instanceToDuplicate.get( current.getParent()); if( parent != null ) insertChild( parent, copy ); toProcess.addAll( current.getChildren()); } return instanceToDuplicate.get( instance ); } 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 );  }