@Override public Graphs getGraphs() { return this.template == null ? null : this.template.getGraphs(); }
public Graphs getGraphs() { return this.application.getTemplate().getGraphs(); }
@Override protected String renderDocumentIndex() { // What keys should we inject in the index? List<String> keys = new ArrayList<> (); keys.add( "introduction" ); keys.add( "components" ); if( this.options.containsKey( DocConstants.OPTION_RECIPE )) { if( ! this.applicationTemplate.getGraphs().getFacetNameToFacet().isEmpty()) keys.add( "facets" ); } else { keys.add( "instances" ); } // Create the index StringBuilder sb = new StringBuilder(); sb.append( "<ul>\n" ); for( String key : keys ) { sb.append( "\t<li><a href=\"index.html#" ); sb.append( this.messages.get( key ).toLowerCase()); sb.append( "\">" ); sb.append( this.messages.get( key )); sb.append( "</a></li>\n" ); } sb.append( "</ul>\n" ); this.menu = sb.toString(); return ""; }
keys.add( "components" ); if( this.options.containsKey( DocConstants.OPTION_RECIPE ) ) { if( ! this.applicationTemplate.getGraphs().getFacetNameToFacet().isEmpty() ) keys.add( "facets" );
@Override protected String renderDocumentIndex() { // What keys should we inject in the index? List<String> keys = new ArrayList<> (); keys.add( "introduction" ); keys.add( "components" ); if( this.options.containsKey( DocConstants.OPTION_RECIPE )) { if( ! this.applicationTemplate.getGraphs().getFacetNameToFacet().isEmpty()) keys.add( "facets" ); } else { keys.add( "instances" ); } // Create the index StringBuilder sb = new StringBuilder(); sb.append( "<ul>\n" ); for( String key : keys ) { sb.append( "\t<li><a href=\"index.html#" ); sb.append( this.messages.get( key ).toLowerCase()); sb.append( "\">" ); sb.append( this.messages.get( key )); sb.append( "</a></li>\n" ); } sb.append( "</ul>\n" ); this.menu = sb.toString(); return ""; }
keys.add( "components" ); if( this.options.containsKey( DocConstants.OPTION_RECIPE ) ) { if( ! this.applicationTemplate.getGraphs().getFacetNameToFacet().isEmpty() ) keys.add( "facets" );
if( alr.getApplicationTemplate().getGraphs() != null ) {
/** * Restores instances and set them in the application. * @param ma the application * @param configurationDirectory the configuration directory */ public static InstancesLoadResult restoreInstances( ManagedApplication ma ) { File sourceFile = new File( ma.getDirectory(), Constants.PROJECT_DIR_INSTANCES + "/" + INSTANCES_FILE ); Graphs graphs = ma.getApplication().getTemplate().getGraphs(); InstancesLoadResult result; if( sourceFile.exists()) result = RuntimeModelIo.loadInstances( sourceFile, sourceFile.getParentFile(), graphs, ma.getApplication().getName()); else result = new InstancesLoadResult(); return result; }
BLOCK: if( alr.getApplicationTemplate().getGraphs() != null ) { candidates = ComponentHelpers.findAllChildren( parentComponent ); else if( Utils.isEmptyOrWhitespaces( ctx.parentInstanceType )) candidates = alr.getApplicationTemplate().getGraphs().getRootComponents(); else this.errorMsg = "Component " + ctx.parentInstanceType + " does not exist.";
@Test public void testFromGraphs_complexApplication() throws Exception { ApplicationTemplate app = ComplexApplicationFactory1.newApplication(); compareGraphs( app.getGraphs(), false ); }
@Test public void testFindAllExtendingComponents_complex1() { ApplicationTemplate app = ComplexApplicationFactory1.newApplication(); Component tomcat8 = ComponentHelpers.findComponent( app.getGraphs(), ComplexApplicationFactory1.TOMCAT_8 ); Assert.assertNotNull( tomcat8 ); Collection<Component> extending = ComponentHelpers.findAllExtendingComponents( tomcat8 ); Assert.assertEquals( 0, extending.size()); Component tomcat = ComponentHelpers.findComponent( app.getGraphs(), ComplexApplicationFactory1.TOMCAT ); Assert.assertNotNull( tomcat ); extending = ComponentHelpers.findAllExtendingComponents( tomcat ); Assert.assertEquals( 1, extending.size()); Assert.assertTrue( extending.contains( tomcat8 )); }
@Test public void testFindAllExtendedComponents_complex1() { ApplicationTemplate app = ComplexApplicationFactory1.newApplication(); Component tomcat = ComponentHelpers.findComponent( app.getGraphs(), ComplexApplicationFactory1.TOMCAT ); Assert.assertNotNull( tomcat ); Collection<Component> extended = ComponentHelpers.findAllExtendedComponents( tomcat ); Assert.assertEquals( 1, extended.size()); Assert.assertTrue( extended.contains( tomcat )); Component tomcat8 = ComponentHelpers.findComponent( app.getGraphs(), ComplexApplicationFactory1.TOMCAT_8 ); Assert.assertNotNull( tomcat8 ); extended = ComponentHelpers.findAllExtendedComponents( tomcat8 ); Assert.assertEquals( 2, extended.size()); Assert.assertTrue( extended.contains( tomcat )); Assert.assertTrue( extended.contains( tomcat8 )); }
@Test public void testParsingWithInexistingDirectory() { ApplicationLoadResult alr = RuntimeModelIo.loadApplication( new File( "inexiting" )); Assert.assertNotNull( alr.getApplicationTemplate()); Assert.assertNull( alr.getApplicationTemplate().getGraphs()); Assert.assertNotSame( 0, alr.getLoadErrors().size()); }
@Test public void testFindAllComponents_extended() { ApplicationTemplate app = ComplexApplicationFactory1.newApplication(); app.getGraphs().getRootComponents().clear(); Component root1 = new Component( "root1" ).installerName( Constants.TARGET_INSTALLER ); Component root2 = new Component( "root2" ); Component root3 = new Component( "root3" ); Assert.assertEquals( 0, ComponentHelpers.findAllComponents( app ).size()); app.getGraphs().getRootComponents().add( root1 ); Assert.assertEquals( 1, ComponentHelpers.findAllComponents( app ).size()); root2.extendComponent( root1 ); Assert.assertEquals( 2, ComponentHelpers.findAllComponents( app ).size()); root3.extendComponent( root2 ); Assert.assertEquals( 3, ComponentHelpers.findAllComponents( app ).size()); app.getGraphs().getRootComponents().add( root2 ); app.getGraphs().getRootComponents().add( root3 ); Assert.assertEquals( 3, ComponentHelpers.findAllComponents( app ).size()); Component childComponent = new Component( "child" ).installerName( "script" ); root3.addChild( childComponent ); Assert.assertEquals( 4, ComponentHelpers.findAllComponents( app ).size()); }
@Test public void testFindComponentDependenciesFor_namesOnly() { ApplicationTemplate app = ComplexApplicationFactory1.newApplication(); // Root with no dependency Component comp = ComponentHelpers.findComponent( app.getGraphs(), ComplexApplicationFactory1.ROOT_1 ); Assert.assertNotNull( comp ); Map<String,Boolean> map = ComponentHelpers.findComponentDependenciesFor( comp ); Assert.assertEquals( 0, map.size()); // Application with several dependencies comp = ComponentHelpers.findComponent( app.getGraphs(), ComplexApplicationFactory1.APP_1 ); Assert.assertNotNull( comp ); map = ComponentHelpers.findComponentDependenciesFor( comp ); Assert.assertEquals( 1, map.size()); Assert.assertTrue( map.containsKey( ComplexApplicationFactory1.FACET_DATABASE )); Assert.assertTrue( map.get( ComplexApplicationFactory1.FACET_DATABASE )); // Another application comp = ComponentHelpers.findComponent( app.getGraphs(), ComplexApplicationFactory1.APP_2 ); Assert.assertNotNull( comp ); map = ComponentHelpers.findComponentDependenciesFor( comp ); Assert.assertEquals( 2, map.size()); Assert.assertTrue( map.containsKey( ComplexApplicationFactory1.MYSQL )); Assert.assertFalse( map.get( ComplexApplicationFactory1.MYSQL )); Assert.assertTrue( map.containsKey( ComplexApplicationFactory1.MONGO_DB )); Assert.assertTrue( map.get( ComplexApplicationFactory1.MONGO_DB )); // And another one comp = ComponentHelpers.findComponent( app.getGraphs(), ComplexApplicationFactory1.APP_3 ); Assert.assertNotNull( comp ); map = ComponentHelpers.findComponentDependenciesFor( comp ); Assert.assertEquals( 0, map.size()); }
Component root1 = ComponentHelpers.findComponent( app.getGraphs(), ComplexApplicationFactory1.ROOT_1 ); Assert.assertNotNull( root1 ); Collection<Component> ancestors = ComponentHelpers.findAllAncestors( root1 ); Assert.assertEquals( 0, ancestors.size()); Component root2 = ComponentHelpers.findComponent( app.getGraphs(), ComplexApplicationFactory1.ROOT_2 ); Assert.assertNotNull( root2 ); ancestors = ComponentHelpers.findAllAncestors( root2 ); Assert.assertEquals( 0, ancestors.size()); Component mongoDb = ComponentHelpers.findComponent( app.getGraphs(), ComplexApplicationFactory1.MONGO_DB ); Assert.assertNotNull( mongoDb ); ancestors = ComponentHelpers.findAllAncestors( mongoDb ); Assert.assertTrue( ancestors.contains( root1 )); Component glassfish = ComponentHelpers.findComponent( app.getGraphs(), ComplexApplicationFactory1.GLASSFISH ); Assert.assertNotNull( glassfish ); ancestors = ComponentHelpers.findAllAncestors( glassfish ); Component tomcat = ComponentHelpers.findComponent( app.getGraphs(), ComplexApplicationFactory1.TOMCAT ); Assert.assertNotNull( tomcat ); ancestors = ComponentHelpers.findAllAncestors( tomcat ); Component tomcat8 = ComponentHelpers.findComponent( app.getGraphs(), ComplexApplicationFactory1.TOMCAT_8 ); Assert.assertNotNull( tomcat8 ); ancestors = ComponentHelpers.findAllAncestors( tomcat8 );
Component comp = ComponentHelpers.findComponent( app.getGraphs(), ComplexApplicationFactory1.ROOT_1 ); Assert.assertNotNull( comp ); comp = ComponentHelpers.findComponent( app.getGraphs(), ComplexApplicationFactory1.MYSQL ); Assert.assertNotNull( comp ); comp = ComponentHelpers.findComponent( app.getGraphs(), ComplexApplicationFactory1.MONGO_DB ); Assert.assertNotNull( comp ); comp = ComponentHelpers.findComponent( app.getGraphs(), ComplexApplicationFactory1.APP_3 ); Assert.assertNotNull( comp );
Component root1 = ComponentHelpers.findComponent( app.getGraphs(), ComplexApplicationFactory1.ROOT_1 ); Assert.assertNotNull( root1 ); Assert.assertTrue( facets.contains( new Facet( ComplexApplicationFactory1.FACET_VM ))); Component mongoDb = ComponentHelpers.findComponent( app.getGraphs(), ComplexApplicationFactory1.MONGO_DB ); Assert.assertNotNull( mongoDb ); facets = ComponentHelpers.findAllFacets( mongoDb ); Assert.assertEquals( 0, facets.size()); Component glassfish = ComponentHelpers.findComponent( app.getGraphs(), ComplexApplicationFactory1.GLASSFISH ); Assert.assertNotNull( glassfish ); facets = ComponentHelpers.findAllFacets( glassfish ); Assert.assertTrue( facets.contains( new Facet( ComplexApplicationFactory1.FACET_DEPLOYABLE ))); Component tomcat = ComponentHelpers.findComponent( app.getGraphs(), ComplexApplicationFactory1.TOMCAT ); Assert.assertNotNull( tomcat ); facets = ComponentHelpers.findAllFacets( tomcat ); Assert.assertTrue( facets.contains( new Facet( ComplexApplicationFactory1.FACET_DEPLOYABLE ))); Component tomcat8 = ComponentHelpers.findComponent( app.getGraphs(), ComplexApplicationFactory1.TOMCAT_8 ); Assert.assertNotNull( tomcat8 ); facets = ComponentHelpers.findAllFacets( tomcat8 );
@Test public void testLoadApplication_Mongo() throws Exception { File directory = TestUtils.findTestFile( "/applications/mongo" ); ApplicationLoadResult result = RuntimeModelIo.loadApplication( directory ); Assert.assertNotNull( result ); Assert.assertNotNull( result.applicationTemplate ); Assert.assertEquals( 0, result.applicationTemplate.externalExports.size()); Assert.assertEquals( 2, result.loadErrors.size()); for( RoboconfError error : result.loadErrors ) Assert.assertEquals( ErrorCode.PROJ_NO_RESOURCE_DIRECTORY, error.getErrorCode()); Assert.assertEquals( "Mongo", result.applicationTemplate.getName()); 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( 0, vmComponent.getFacets().size()); Collection<Component> children = ComponentHelpers.findAllChildren( vmComponent ); Assert.assertEquals( 1, children.size()); Component childComponent = children.iterator().next(); Assert.assertEquals( "puppet", childComponent.getInstallerName()); Assert.assertEquals( 0, childComponent.getChildren().size()); Assert.assertEquals( 2, childComponent.exportedVariables.size()); Assert.assertNull( childComponent.exportedVariables.get( "Mongo.ip" )); Assert.assertEquals( "27017", ComponentHelpers.findAllExportedVariables( childComponent ).get( "Mongo.port" )); Assert.assertEquals( 2, childComponent.importedVariables.size()); Assert.assertTrue( childComponent.importedVariables.containsKey( "Mongo.ip" )); Assert.assertTrue( childComponent.importedVariables.containsKey( "Mongo.port" )); }
@Test public void testChain() { ApplicationTemplate app = new ApplicationTemplate().name( "ins" ).description( "desc" ).version( "snapshot" ).graphs( new Graphs()); Assert.assertEquals( "ins", app.getName()); Assert.assertEquals( "desc", app.getDescription()); Assert.assertEquals( "snapshot", app.getVersion()); Assert.assertNotNull( app.getGraphs()); }