@Test public void testLoadApplication_Lamp_Legacy_2() throws Exception { File directory = TestUtils.findTestFile( "/applications/lamp-legacy-with-facets-and-so-on" ); ApplicationLoadResult result = RuntimeModelIo.loadApplication( directory ); Assert.assertNotNull( result ); Assert.assertNotNull( result.applicationTemplate ); Assert.assertEquals( 3, result.loadErrors.size()); for( RoboconfError error : result.loadErrors ) Assert.assertEquals( ErrorCode.PROJ_NO_RESOURCE_DIRECTORY, error.getErrorCode()); Assert.assertEquals( "Legacy LAMP", result.applicationTemplate.getName()); Assert.assertEquals( "A sample LAMP application", result.applicationTemplate.getDescription()); Assert.assertEquals( "1.0.1-SNAPSHOT", result.applicationTemplate.getVersion()); Assert.assertEquals( "roboconf-1.0", result.applicationTemplate.getDslId()); Assert.assertNotNull( result.applicationTemplate.getGraphs()); Graphs g = result.applicationTemplate.getGraphs(); Assert.assertEquals( 3, g.getRootComponents().size()); Set<String> rootComponentNames = new HashSet<> (); for( Component c : g.getRootComponents()) { rootComponentNames.add( c.getName()); Assert.assertEquals( Constants.TARGET_INSTALLER, ComponentHelpers.findComponentInstaller( c )); Collection<Facet> facets = ComponentHelpers.findAllFacets( c ); Assert.assertEquals( 1, facets.size()); Assert.assertEquals( "Virtual_Machine", facets.iterator().next().getName()); Assert.assertEquals( 3, ComponentHelpers.findAllChildren( c ).size()); for( Component childComponent : ComponentHelpers.findAllChildren( c )) { Map<String,String> exportedVariables = ComponentHelpers.findAllExportedVariables( childComponent ); Map<String,ImportedVariable> importedVariables = ComponentHelpers.findAllImportedVariables( childComponent ); Collection<Component> children = ComponentHelpers.findAllChildren( childComponent ); if( "Tomcat".equals( childComponent.getName())) { Assert.assertEquals( "puppet", childComponent.getInstallerName()); Assert.assertEquals( 0, children.size()); Assert.assertEquals( 1, childComponent.getFacets().size()); Assert.assertEquals( "deployable", childComponent.getFacets().iterator().next().getName()); Assert.assertEquals( 2, exportedVariables.size()); Assert.assertTrue( exportedVariables.containsKey( "Tomcat.ip" )); Assert.assertEquals( "8009", exportedVariables.get( "Tomcat.portAJP" )); Assert.assertEquals( 2, importedVariables.size()); Assert.assertFalse( importedVariables.get( "MySQL.ip" ).isOptional()); Assert.assertFalse( importedVariables.get( "MySQL.ip" ).isExternal()); Assert.assertFalse( importedVariables.get( "MySQL.port" ).isOptional()); Assert.assertFalse( importedVariables.get( "MySQL.port" ).isExternal()); } else if( "MySQL".equals( childComponent.getName())) { Assert.assertEquals( "puppet", childComponent.getInstallerName()); Assert.assertEquals( 0, children.size()); Assert.assertEquals( 1, childComponent.getFacets().size()); Assert.assertEquals( "deployable", childComponent.getFacets().iterator().next().getName()); Assert.assertEquals( 2, exportedVariables.size()); Assert.assertTrue( exportedVariables.containsKey( "MySQL.ip" )); Assert.assertEquals( "3306", exportedVariables.get( "MySQL.port" )); Assert.assertEquals( 0, importedVariables.size()); } else if( "Apache".equals( childComponent.getName())) { Assert.assertEquals( "puppet", childComponent.getInstallerName()); Assert.assertEquals( 0, children.size()); Assert.assertEquals( 0, exportedVariables.size()); Assert.assertEquals( 1, childComponent.getFacets().size()); Assert.assertEquals( "deployable", childComponent.getFacets().iterator().next().getName()); Assert.assertEquals( 2, importedVariables.size()); Assert.assertFalse( importedVariables.get( "Tomcat.ip" ).isOptional()); Assert.assertFalse( importedVariables.get( "Tomcat.ip" ).isExternal()); Assert.assertFalse( importedVariables.get( "Tomcat.portAJP" ).isOptional()); Assert.assertFalse( importedVariables.get( "Tomcat.portAJP" ).isExternal()); } else { Assert.fail( "Unrecognized child." ); } } } Assert.assertEquals( 3, rootComponentNames.size()); Assert.assertTrue( rootComponentNames.contains( "VM" )); Assert.assertTrue( rootComponentNames.contains( "VM_EC2" )); Assert.assertTrue( rootComponentNames.contains( "VM_Openstack" )); Component vmOpenstack = ComponentHelpers.findComponent( g, "VM_Openstack" ); Map<String,String> exportedVariables = ComponentHelpers.findAllExportedVariables( vmOpenstack ); Assert.assertEquals( 4, exportedVariables.size()); Assert.assertEquals( "else", exportedVariables.get( "VM_Openstack.something" )); Assert.assertNull( exportedVariables.get( "Virtual_Machine.ip" )); Assert.assertTrue( exportedVariables.containsKey( "Virtual_Machine.ip" )); Assert.assertTrue( exportedVariables.containsKey( "VM_Openstack.ip" )); Assert.assertTrue( exportedVariables.containsKey( "VM.ip" )); Assert.assertEquals( ComponentHelpers.findComponent( g, "VM" ), vmOpenstack.getExtendedComponent()); Assert.assertNotNull( vmOpenstack.getExtendedComponent()); Set<String> expectedPaths = new HashSet<> (); expectedPaths.add( "/Apache VM" ); expectedPaths.add( "/Apache VM/Apache" ); expectedPaths.add( "/MySQL VM" ); expectedPaths.add( "/MySQL VM/MySQL" ); expectedPaths.add( "/Tomcat VM 1" ); expectedPaths.add( "/Tomcat VM 1/Tomcat" ); expectedPaths.add( "/Tomcat VM 2" ); expectedPaths.add( "/Tomcat VM 2/Tomcat" ); expectedPaths.add( "/Tomcat VM 3" ); expectedPaths.add( "/Tomcat VM 3/Tomcat" ); Set<String> realPaths = new HashSet<> (); for( Instance inst : InstanceHelpers.getAllInstances( result.getApplicationTemplate())) realPaths.add( InstanceHelpers.computeInstancePath( inst )); Assert.assertEquals( expectedPaths.size(), realPaths.size()); realPaths.removeAll( expectedPaths ); Assert.assertEquals( 0, realPaths.size()); Instance tomcat1 = InstanceHelpers.findInstanceByPath( result.getApplicationTemplate(), "/Tomcat VM 1/Tomcat" ); Instance tomcat2 = InstanceHelpers.findInstanceByPath( result.getApplicationTemplate(), "/Tomcat VM 2/Tomcat" ); Instance tomcat3 = InstanceHelpers.findInstanceByPath( result.getApplicationTemplate(), "/Tomcat VM 3/Tomcat" ); Assert.assertEquals( tomcat1.getComponent(), tomcat2.getComponent()); Assert.assertEquals( tomcat1.getComponent(), tomcat3.getComponent()); Assert.assertEquals( tomcat1.channels, tomcat2.channels ); Assert.assertEquals( tomcat1.channels, tomcat3.channels ); Assert.assertEquals( 0, tomcat1.getChildren().size()); Assert.assertEquals( 1, tomcat1.overriddenExports.size()); Assert.assertEquals( "9021", tomcat1.overriddenExports.get( "portAJP" )); Assert.assertEquals( "9021", InstanceHelpers.findAllExportedVariables( tomcat1 ).get( "Tomcat.portAJP" )); Assert.assertEquals( 0, tomcat2.getChildren().size()); Assert.assertEquals( 1, tomcat2.overriddenExports.size()); Assert.assertEquals( "9021", tomcat2.overriddenExports.get( "portAJP" )); Assert.assertEquals( "9021", InstanceHelpers.findAllExportedVariables( tomcat2 ).get( "Tomcat.portAJP" )); Assert.assertEquals( 0, tomcat3.getChildren().size()); Assert.assertEquals( 1, tomcat3.overriddenExports.size()); Assert.assertEquals( "9021", tomcat3.overriddenExports.get( "portAJP" )); Assert.assertEquals( "9021", InstanceHelpers.findAllExportedVariables( tomcat3 ).get( "Tomcat.portAJP" )); }
public static ApplicationLoadResult loadApplication( File projectDirectory ) { ApplicationLoadResult result = new ApplicationLoadResult(); ApplicationTemplate app = new ApplicationTemplate(); result.applicationTemplate = app; ApplicationTemplateDescriptor appDescriptor = null; File descDirectory = new File( projectDirectory, Constants.PROJECT_DIR_DESC ); DESC: if( ! descDirectory.exists()) { RoboconfError error = new RoboconfError( ErrorCode.PROJ_NO_DESC_DIR, directory( projectDirectory )); result.loadErrors.add( error ); } else { File descriptorFile = new File( descDirectory, Constants.PROJECT_FILE_DESCRIPTOR ); if( ! descriptorFile.exists()) { result.loadErrors.add( new RoboconfError( ErrorCode.PROJ_NO_DESC_FILE )); break DESC; } try { appDescriptor = ApplicationTemplateDescriptor.load( descriptorFile ); app.setName( appDescriptor.getName()); app.setDescription( appDescriptor.getDescription()); app.setVersion( appDescriptor.getVersion()); app.setDslId( appDescriptor.getDslId()); app.setExternalExportsPrefix( appDescriptor.getExternalExportsPrefix()); app.setTags( appDescriptor.tags ); for( Map.Entry<String,String> entry : appDescriptor.externalExports.entrySet()) app.externalExports.put( entry.getKey(), app.getExternalExportsPrefix() + "." + entry.getValue()); result.objectToSource.put( appDescriptor, new SourceReference( appDescriptor, descriptorFile, 1 )); for( Map.Entry<String,Integer> entry : appDescriptor.propertyToLine.entrySet()) { result.objectToSource.put( entry.getKey(), new SourceReference( entry.getKey(), descriptorFile, entry.getValue())); } Collection<ModelError> errors = RuntimeModelValidator.validate( appDescriptor ); result.loadErrors.addAll( errors ); } catch( IOException e ) { RoboconfError error = new RoboconfError( ErrorCode.PROJ_READ_DESC_FILE, exception( e )); result.loadErrors.add( error ); } } return loadApplication( projectDirectory, appDescriptor, result ); }
RuntimeModelIo { public static ApplicationLoadResult loadApplication( File projectDirectory ) { ApplicationLoadResult result = new ApplicationLoadResult(); ApplicationTemplate app = new ApplicationTemplate(); result.applicationTemplate = app; ApplicationTemplateDescriptor appDescriptor = null; File descDirectory = new File( projectDirectory, Constants.PROJECT_DIR_DESC ); DESC: if( ! descDirectory.exists()) { RoboconfError error = new RoboconfError( ErrorCode.PROJ_NO_DESC_DIR, directory( projectDirectory )); result.loadErrors.add( error ); } else { File descriptorFile = new File( descDirectory, Constants.PROJECT_FILE_DESCRIPTOR ); if( ! descriptorFile.exists()) { result.loadErrors.add( new RoboconfError( ErrorCode.PROJ_NO_DESC_FILE )); break DESC; } try { appDescriptor = ApplicationTemplateDescriptor.load( descriptorFile ); app.setName( appDescriptor.getName()); app.setDescription( appDescriptor.getDescription()); app.setVersion( appDescriptor.getVersion()); app.setDslId( appDescriptor.getDslId()); app.setExternalExportsPrefix( appDescriptor.getExternalExportsPrefix()); app.setTags( appDescriptor.tags ); for( Map.Entry<String,String> entry : appDescriptor.externalExports.entrySet()) app.externalExports.put( entry.getKey(), app.getExternalExportsPrefix() + "." + entry.getValue()); result.objectToSource.put( appDescriptor, new SourceReference( appDescriptor, descriptorFile, 1 )); for( Map.Entry<String,Integer> entry : appDescriptor.propertyToLine.entrySet()) { result.objectToSource.put( entry.getKey(), new SourceReference( entry.getKey(), descriptorFile, entry.getValue())); } Collection<ModelError> errors = RuntimeModelValidator.validate( appDescriptor ); result.loadErrors.addAll( errors ); } catch( IOException e ) { RoboconfError error = new RoboconfError( ErrorCode.PROJ_READ_DESC_FILE, exception( e )); result.loadErrors.add( error ); } } return loadApplication( projectDirectory, appDescriptor, result ); } }
RuntimeModelIo { public static ApplicationLoadResult loadApplication( File projectDirectory ) { ApplicationLoadResult result = new ApplicationLoadResult(); ApplicationTemplate app = new ApplicationTemplate(); result.applicationTemplate = app; ApplicationTemplateDescriptor appDescriptor = null; File descDirectory = new File( projectDirectory, Constants.PROJECT_DIR_DESC ); DESC: if( ! descDirectory.exists()) { RoboconfError error = new RoboconfError( ErrorCode.PROJ_NO_DESC_DIR, directory( projectDirectory )); result.loadErrors.add( error ); } else { File descriptorFile = new File( descDirectory, Constants.PROJECT_FILE_DESCRIPTOR ); if( ! descriptorFile.exists()) { result.loadErrors.add( new RoboconfError( ErrorCode.PROJ_NO_DESC_FILE )); break DESC; } try { appDescriptor = ApplicationTemplateDescriptor.load( descriptorFile ); app.setName( appDescriptor.getName()); app.setDescription( appDescriptor.getDescription()); app.setVersion( appDescriptor.getVersion()); app.setDslId( appDescriptor.getDslId()); app.setExternalExportsPrefix( appDescriptor.getExternalExportsPrefix()); app.setTags( appDescriptor.tags ); for( Map.Entry<String,String> entry : appDescriptor.externalExports.entrySet()) app.externalExports.put( entry.getKey(), app.getExternalExportsPrefix() + "." + entry.getValue()); result.objectToSource.put( appDescriptor, new SourceReference( appDescriptor, descriptorFile, 1 )); for( Map.Entry<String,Integer> entry : appDescriptor.propertyToLine.entrySet()) { result.objectToSource.put( entry.getKey(), new SourceReference( entry.getKey(), descriptorFile, entry.getValue())); } Collection<ModelError> errors = RuntimeModelValidator.validate( appDescriptor ); result.loadErrors.addAll( errors ); } catch( IOException e ) { RoboconfError error = new RoboconfError( ErrorCode.PROJ_READ_DESC_FILE, exception( e )); result.loadErrors.add( error ); } } return loadApplication( projectDirectory, appDescriptor, result ); } private  RuntimeModelIo(); }
RuntimeModelIo { public static ApplicationLoadResult loadApplication( File projectDirectory ) { ApplicationLoadResult result = new ApplicationLoadResult(); ApplicationTemplate app = new ApplicationTemplate(); result.applicationTemplate = app; ApplicationTemplateDescriptor appDescriptor = null; File descDirectory = new File( projectDirectory, Constants.PROJECT_DIR_DESC ); DESC: if( ! descDirectory.exists()) { RoboconfError error = new RoboconfError( ErrorCode.PROJ_NO_DESC_DIR, directory( projectDirectory )); result.loadErrors.add( error ); } else { File descriptorFile = new File( descDirectory, Constants.PROJECT_FILE_DESCRIPTOR ); if( ! descriptorFile.exists()) { result.loadErrors.add( new RoboconfError( ErrorCode.PROJ_NO_DESC_FILE )); break DESC; } try { appDescriptor = ApplicationTemplateDescriptor.load( descriptorFile ); app.setName( appDescriptor.getName()); app.setDescription( appDescriptor.getDescription()); app.setVersion( appDescriptor.getVersion()); app.setDslId( appDescriptor.getDslId()); app.setExternalExportsPrefix( appDescriptor.getExternalExportsPrefix()); app.setTags( appDescriptor.tags ); for( Map.Entry<String,String> entry : appDescriptor.externalExports.entrySet()) app.externalExports.put( entry.getKey(), app.getExternalExportsPrefix() + "." + entry.getValue()); result.objectToSource.put( appDescriptor, new SourceReference( appDescriptor, descriptorFile, 1 )); for( Map.Entry<String,Integer> entry : appDescriptor.propertyToLine.entrySet()) { result.objectToSource.put( entry.getKey(), new SourceReference( entry.getKey(), descriptorFile, entry.getValue())); } Collection<ModelError> errors = RuntimeModelValidator.validate( appDescriptor ); result.loadErrors.addAll( errors ); } catch( IOException e ) { RoboconfError error = new RoboconfError( ErrorCode.PROJ_READ_DESC_FILE, exception( e )); result.loadErrors.add( error ); } } return loadApplication( projectDirectory, appDescriptor, result ); } private  RuntimeModelIo(); static ApplicationLoadResult loadApplication( File projectDirectory ); static ApplicationLoadResult loadApplicationFlexibly( File projectDirectory ); static Graphs loadGraph( File graphFile, File graphDirectory, ApplicationLoadResult alr ); static InstancesLoadResult loadInstances( File instancesFile, File rootDirectory, Graphs graph, String applicationName ); static void writeInstances( File targetFile, Collection<Instance> rootInstances ); }
RuntimeModelIo { public static ApplicationLoadResult loadApplication( File projectDirectory ) { ApplicationLoadResult result = new ApplicationLoadResult(); ApplicationTemplate app = new ApplicationTemplate(); result.applicationTemplate = app; ApplicationTemplateDescriptor appDescriptor = null; File descDirectory = new File( projectDirectory, Constants.PROJECT_DIR_DESC ); DESC: if( ! descDirectory.exists()) { RoboconfError error = new RoboconfError( ErrorCode.PROJ_NO_DESC_DIR, directory( projectDirectory )); result.loadErrors.add( error ); } else { File descriptorFile = new File( descDirectory, Constants.PROJECT_FILE_DESCRIPTOR ); if( ! descriptorFile.exists()) { result.loadErrors.add( new RoboconfError( ErrorCode.PROJ_NO_DESC_FILE )); break DESC; } try { appDescriptor = ApplicationTemplateDescriptor.load( descriptorFile ); app.setName( appDescriptor.getName()); app.setDescription( appDescriptor.getDescription()); app.setVersion( appDescriptor.getVersion()); app.setDslId( appDescriptor.getDslId()); app.setExternalExportsPrefix( appDescriptor.getExternalExportsPrefix()); app.setTags( appDescriptor.tags ); for( Map.Entry<String,String> entry : appDescriptor.externalExports.entrySet()) app.externalExports.put( entry.getKey(), app.getExternalExportsPrefix() + "." + entry.getValue()); result.objectToSource.put( appDescriptor, new SourceReference( appDescriptor, descriptorFile, 1 )); for( Map.Entry<String,Integer> entry : appDescriptor.propertyToLine.entrySet()) { result.objectToSource.put( entry.getKey(), new SourceReference( entry.getKey(), descriptorFile, entry.getValue())); } Collection<ModelError> errors = RuntimeModelValidator.validate( appDescriptor ); result.loadErrors.addAll( errors ); } catch( IOException e ) { RoboconfError error = new RoboconfError( ErrorCode.PROJ_READ_DESC_FILE, exception( e )); result.loadErrors.add( error ); } } return loadApplication( projectDirectory, appDescriptor, result ); } private  RuntimeModelIo(); static ApplicationLoadResult loadApplication( File projectDirectory ); static ApplicationLoadResult loadApplicationFlexibly( File projectDirectory ); static Graphs loadGraph( File graphFile, File graphDirectory, ApplicationLoadResult alr ); static InstancesLoadResult loadInstances( File instancesFile, File rootDirectory, Graphs graph, String applicationName ); static void writeInstances( File targetFile, Collection<Instance> rootInstances );  }