@Test public void testAllCommands() throws Exception { File f = TestUtils.findTestFile( "/commands/create-and-delete.commands" ); CommandsExecutor executor = new CommandsExecutor( this.manager, this.app, f ); String targetId = this.manager.targetsMngr().createTarget( "id: tid\nhandler: h" ); Assert.assertEquals( "tid", targetId ); List<String> instancePaths = new ArrayList<> (); for( Instance inst : InstanceHelpers.getAllInstances( this.app )) instancePaths.add( InstanceHelpers.computeInstancePath( inst )); int instancesCount = InstanceHelpers.getAllInstances( this.app ).size(); Assert.assertTrue( instancePaths.contains( "/tomcat-vm" )); executor.execute(); instancePaths.clear();; for( Instance inst : InstanceHelpers.getAllInstances( this.app )) instancePaths.add( InstanceHelpers.computeInstancePath( inst )); Assert.assertEquals( instancesCount + 5, instancePaths.size()); Assert.assertTrue( instancePaths.contains( "/tomcat 1" )); Assert.assertTrue( instancePaths.contains( "/tomcat 1/tomcat-server" )); Assert.assertTrue( instancePaths.contains( "/tomcat 1/tomcat-server/hello-world" )); Assert.assertTrue( instancePaths.contains( "/tomcat 2" )); Assert.assertTrue( instancePaths.contains( "/tomcat 2/tomcat-server" )); Assert.assertTrue( instancePaths.contains( "/tomcat 2/tomcat-server/hello-world" )); Assert.assertTrue( instancePaths.contains( "/tomcat 3" )); Assert.assertTrue( instancePaths.contains( "/tomcat 3/my-tomcat-server" )); Assert.assertFalse( instancePaths.contains( "/tomcat 3/tomcat-server/hello-world" )); Assert.assertFalse( instancePaths.contains( "/tomcat 3/my-tomcat-server/hello-world" )); Assert.assertFalse( instancePaths.contains( "/tomcat-vm" )); Instance instance = InstanceHelpers.findInstanceByPath( this.app, "/tomcat 1" ); Assert.assertNotNull( instance ); Assert.assertNull( this.manager.targetsMngr().findTargetId( this.app, "/tomcat 1" )); instance = InstanceHelpers.findInstanceByPath( this.app, "/tomcat 2" ); Assert.assertNotNull( instance ); Assert.assertNull( this.manager.targetsMngr().findTargetId( this.app, "/tomcat 2" )); instance = InstanceHelpers.findInstanceByPath( this.app, "/tomcat 3" ); Assert.assertNotNull( instance ); Assert.assertEquals( targetId, this.manager.targetsMngr().findTargetId( this.app, "/tomcat 3" )); }
public void execute() throws CommandException { try { CommandsParser parser = new CommandsParser( this.app, this.commandsFile ); if( RoboconfErrorHelpers.containsCriticalErrors( parser.getParsingErrors())) throw new CommandException( "Invalid command file. " + this.commandsFile.getName() + " contains errors." ); for( AbstractCommandInstruction instr : parser.getInstructions()) { if( instr.isDisabled()) { this.logger.fine( "Skipping disabled instruction: " + instr.getClass().getSimpleName()); this.instructionSkipped = true; continue; } AbstractCommandExecution executor = findExecutor( instr ); if( executor == null ) { this.logger.fine( "Skipping non-executable instruction: " + instr.getClass().getSimpleName()); continue; } executor.setExecutionContext( this.executionContext ); executor.execute(); } } catch( CommandException e ) { throw e; } catch( Exception e ) { throw new CommandException( e ); } }
CommandsExecutor { public void execute() throws CommandException { try { CommandsParser parser = new CommandsParser( this.app, this.commandsFile ); if( RoboconfErrorHelpers.containsCriticalErrors( parser.getParsingErrors())) throw new CommandException( "Invalid command file. " + this.commandsFile.getName() + " contains errors." ); for( AbstractCommandInstruction instr : parser.getInstructions()) { if( instr.isDisabled()) { this.logger.fine( "Skipping disabled instruction: " + instr.getClass().getSimpleName()); this.instructionSkipped = true; continue; } AbstractCommandExecution executor = findExecutor( instr ); if( executor == null ) { this.logger.fine( "Skipping non-executable instruction: " + instr.getClass().getSimpleName()); continue; } executor.setExecutionContext( this.executionContext ); executor.execute(); } } catch( CommandException e ) { throw e; } catch( Exception e ) { throw new CommandException( e ); } } }
CommandsExecutor { public void execute() throws CommandException { try { CommandsParser parser = new CommandsParser( this.app, this.commandsFile ); if( RoboconfErrorHelpers.containsCriticalErrors( parser.getParsingErrors())) throw new CommandException( "Invalid command file. " + this.commandsFile.getName() + " contains errors." ); for( AbstractCommandInstruction instr : parser.getInstructions()) { if( instr.isDisabled()) { this.logger.fine( "Skipping disabled instruction: " + instr.getClass().getSimpleName()); this.instructionSkipped = true; continue; } AbstractCommandExecution executor = findExecutor( instr ); if( executor == null ) { this.logger.fine( "Skipping non-executable instruction: " + instr.getClass().getSimpleName()); continue; } executor.setExecutionContext( this.executionContext ); executor.execute(); } } catch( CommandException e ) { throw e; } catch( Exception e ) { throw new CommandException( e ); } } CommandsExecutor( Manager manager, Application app, File commandsFile );  CommandsExecutor(
			Manager manager,
			Application app,
			File commandsFile,
			CommandExecutionContext executionContext ); }
CommandsExecutor { public void execute() throws CommandException { try { CommandsParser parser = new CommandsParser( this.app, this.commandsFile ); if( RoboconfErrorHelpers.containsCriticalErrors( parser.getParsingErrors())) throw new CommandException( "Invalid command file. " + this.commandsFile.getName() + " contains errors." ); for( AbstractCommandInstruction instr : parser.getInstructions()) { if( instr.isDisabled()) { this.logger.fine( "Skipping disabled instruction: " + instr.getClass().getSimpleName()); this.instructionSkipped = true; continue; } AbstractCommandExecution executor = findExecutor( instr ); if( executor == null ) { this.logger.fine( "Skipping non-executable instruction: " + instr.getClass().getSimpleName()); continue; } executor.setExecutionContext( this.executionContext ); executor.execute(); } } catch( CommandException e ) { throw e; } catch( Exception e ) { throw new CommandException( e ); } } CommandsExecutor( Manager manager, Application app, File commandsFile );  CommandsExecutor(
			Manager manager,
			Application app,
			File commandsFile,
			CommandExecutionContext executionContext ); void execute(); boolean wereInstructionSkipped(); }
CommandsExecutor { public void execute() throws CommandException { try { CommandsParser parser = new CommandsParser( this.app, this.commandsFile ); if( RoboconfErrorHelpers.containsCriticalErrors( parser.getParsingErrors())) throw new CommandException( "Invalid command file. " + this.commandsFile.getName() + " contains errors." ); for( AbstractCommandInstruction instr : parser.getInstructions()) { if( instr.isDisabled()) { this.logger.fine( "Skipping disabled instruction: " + instr.getClass().getSimpleName()); this.instructionSkipped = true; continue; } AbstractCommandExecution executor = findExecutor( instr ); if( executor == null ) { this.logger.fine( "Skipping non-executable instruction: " + instr.getClass().getSimpleName()); continue; } executor.setExecutionContext( this.executionContext ); executor.execute(); } } catch( CommandException e ) { throw e; } catch( Exception e ) { throw new CommandException( e ); } } CommandsExecutor( Manager manager, Application app, File commandsFile );  CommandsExecutor(
			Manager manager,
			Application app,
			File commandsFile,
			CommandExecutionContext executionContext ); void execute(); boolean wereInstructionSkipped();  }