@Test public void testLoadApplication_Lamp_Legacy_1() throws Exception { File directory = TestUtils.findTestFile( "/applications/lamp-legacy-with-only-components" ); ApplicationLoadResult result = RuntimeModelIo.loadApplication( directory ); Assert.assertNotNull( result ); Assert.assertNotNull( result.applicationTemplate ); Assert.assertEquals( 4, 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()); List<String> tags = Arrays.asList( "test", "lamp", "example" ); Assert.assertEquals( new TreeSet<>( tags ), result.applicationTemplate.getTags()); Assert.assertNotNull( result.applicationTemplate.getGraphs()); Graphs g = result.applicationTemplate.getGraphs(); Assert.assertEquals( 1, g.getRootComponents().size()); Component vmComponent = g.getRootComponents().iterator().next(); Assert.assertEquals( "VM", vmComponent.getName()); Assert.assertEquals( "target", vmComponent.getInstallerName()); Assert.assertEquals( 3, vmComponent.getChildren().size()); for( Component childComponent : ComponentHelpers.findAllChildren( vmComponent )) { 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( 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()); SourceReference sr = result.getObjectToSource().get( childComponent ); Assert.assertNotNull( sr ); Assert.assertEquals( new File( directory, "graph/lamp.graph" ), sr.getSourceFile()); Assert.assertEquals( 22, sr.getLine()); } else if( "MySQL".equals( childComponent.getName())) { Assert.assertEquals( "puppet", childComponent.getInstallerName()); Assert.assertEquals( 0, children.size()); Assert.assertEquals( 2, exportedVariables.size()); Assert.assertTrue( exportedVariables.containsKey( "MySQL.ip" )); Assert.assertNull( exportedVariables.get( "MySQL.port" )); Assert.assertEquals( 0, importedVariables.size()); SourceReference sr = result.getObjectToSource().get( childComponent ); Assert.assertNotNull( sr ); Assert.assertEquals( new File( directory, "graph/lamp.graph" ), sr.getSourceFile()); Assert.assertEquals( 16, sr.getLine()); } else if( "Apache".equals( childComponent.getName())) { Assert.assertEquals( "puppet", childComponent.getInstallerName()); Assert.assertEquals( 0, children.size()); Assert.assertEquals( 0, exportedVariables.size()); Assert.assertEquals( 2, childComponent.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()); SourceReference sr = result.getObjectToSource().get( childComponent ); Assert.assertNotNull( sr ); Assert.assertEquals( new File( directory, "graph/lamp.graph" ), sr.getSourceFile()); Assert.assertEquals( 30, sr.getLine()); } else { Assert.fail( "Unrecognized child." ); } } Assert.assertEquals( 3, result.applicationTemplate.getRootInstances().size()); for( Instance i : result.applicationTemplate.getRootInstances()) { if( "Apache VM".equals( i.getName())) { Assert.assertEquals( "VM", i.getComponent().getName()); Assert.assertEquals( 1, i.getChildren().size()); Instance child = i.getChildren().iterator().next(); Assert.assertEquals( 0, child.getChildren().size()); Assert.assertEquals( i, child.getParent()); Assert.assertEquals( "Apache", child.getName()); Assert.assertEquals( "Apache", child.getComponent().getName()); } else if( "MySQL VM".equals( i.getName())) { Assert.assertEquals( "VM", i.getComponent().getName()); Assert.assertEquals( 1, i.getChildren().size()); Instance child = i.getChildren().iterator().next(); Assert.assertEquals( 0, child.getChildren().size()); Assert.assertEquals( i, child.getParent()); Assert.assertEquals( "MySQL", child.getName()); Assert.assertEquals( "MySQL", child.getComponent().getName()); Map<String,String> exportedVariables = InstanceHelpers.findAllExportedVariables( child ); Assert.assertEquals( "3306", exportedVariables.get( "MySQL.port" )); Assert.assertNull( child.getComponent().exportedVariables.get( "MySQL.port" )); Assert.assertNotNull( child.getComponent().exportedVariables.get( "port" )); Assert.assertNull( child.getComponent().exportedVariables.get( "port" ).getValue()); } else if( "Tomcat VM 1".equals( i.getName())) { Assert.assertEquals( "VM", i.getComponent().getName()); Assert.assertEquals( 1, i.getChildren().size()); Instance child = i.getChildren().iterator().next(); Assert.assertEquals( 0, child.getChildren().size()); Assert.assertEquals( i, child.getParent()); Assert.assertEquals( "Tomcat", child.getName()); Assert.assertEquals( "Tomcat", child.getComponent().getName()); } else { Assert.fail( "Unrecognized instance." ); } } }
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 );  }