src/main/java/org/jboss/loom/MigrationEngine.java
private void performActions() throws MigrationException {
        log.debug("======== performActions() ========");
        
        boolean dryRun = config.getGlobal().isDryRun();
        if(dryRun)
            log.info("\n** This is a DRY RUN, operations are not really performed, only prepared and listed. **\n");
        String dryPrefix = dryRun ? "(DRY RUN) " : "";
        
        // Clear CLI commands, should there be any.
        ctx.getBatch().clear();
        
        // Sort the actions according to dependencies. MIGR-104
        List<IMigrationAction> actions = ctx.getActions();
        List<IMigrationAction> sorted = ActionDependencySorter.sort( actions );
        
        // Store CLI actions into an ordered list.
        // In perform(), they are just put into a batch. Using this, we can tell which one failed.
        List<CliCommandAction> cliActions = new LinkedList();

        // Perform the actions.
        log.info(dryPrefix + "Performing actions:");
        for( IMigrationAction action : sorted ) {
            if( action instanceof CliCommandAction )
                cliActions.add((CliCommandAction) action);
        
            log.info("    " + action.toDescription());
            action.setMigrationContext(ctx); // Again. To be sure.
            
            // On dry run, CliCommandActions can still be performed as they only add to the batch.
            if( (action instanceof CliCommandAction) ||  ! dryRun )
                try {
                    action.perform();
                } catch( ActionException ex ){
                    throw ex;
                } catch( Throwable ex ){
                    throw new ActionException( action, "Failed to perform action:\n"+action.toDescription()+"\n    " + ex.getMessage(), ex);
                }
        }
        
        /// DEBUG: Dump created CLI operations
        log.debug(dryPrefix + "Management operations in batch:");
        int i = 1;
        for( BatchedCommand command : ctx.getBatch().getCommands() ){
            log.debug("    " + i++ + ": " + command.getCommand());
        }

        // Execution
        log.debug(dryPrefix + "Executing CLI batch:");
        try {
            if( ! dryRun )
                AS7CliUtils.executeRequest( ctx.getBatch().toRequest(), config.getGlobal().getAS7Config() );
        }
        catch( CliBatchException ex ){
            //Integer index = AS7CliUtils.parseFailedOperationIndex( ex.getResponseNode() );
            BatchFailure failure = AS7CliUtils.extractFailedOperationNode( ex.getResponseNode() );
            if( null == failure ){
                log.warn("Unable to parse CLI batch operation index: " + ex.getResponseNode());
                throw new MigrationException("Executing a CLI batch failed: " + ex, ex);
            }
            
            IMigrationAction causeAction;
                    
            // First, try if it's a BatchedCommandWithAction, and get the action if so.
            BatchedCommand cmd = ctx.getBatch().getCommands().get( failure.getIndex() - 1 );
            if( cmd instanceof BatchedCommandWithAction )
                causeAction = ((BatchedCommandWithAction)cmd).getAction();
            // Then shoot blindly into cliActions. May be wrong offset - some actions create multiple CLI commands! TODO.
            else
                causeAction = cliActions.get( failure.getIndex() - 1 );
            
            throw new ActionException( causeAction, "Executing a CLI batch failed: " + failure.getMessage());
        }
        catch( Exception ex ) {
            throw new MigrationException("Executing a CLI batch failed: " + ex, ex);
        }
        
    }
/**
     *  Performs the actions.
     *  Should do all the active steps: File manipulation, AS CLI commands etc.
     * @throws MigrationException 
     */
Performs the actions.
Should do all the active steps: File manipulation, AS CLI commands etc.
Performs the actions . Should do all the active steps : File manipulation AS CLI commands etc .
private void performActions() throws MigrationException {
        log.debug("======== performActions() ========");
        boolean dryRun = config.getGlobal().isDryRun();
        if(dryRun)
            log.info("\n** This is a DRY RUN, operations are not really performed, only prepared and listed. **\n");
        String dryPrefix = dryRun ? "(DRY RUN) " : "";
        ctx.getBatch().clear();
        List<IMigrationAction> actions = ctx.getActions();
        List<IMigrationAction> sorted = ActionDependencySorter.sort( actions );
        List<CliCommandAction> cliActions = new LinkedList();
        log.info(dryPrefix + "Performing actions:");
        for( IMigrationAction action : sorted ) {
            if( action instanceof CliCommandAction )
                cliActions.add((CliCommandAction) action);
            log.info("    " + action.toDescription());
            action.setMigrationContext(ctx); 
            if( (action instanceof CliCommandAction) ||  ! dryRun )
                try {
                    action.perform();
                } catch( ActionException ex ){
                    throw ex;
                } catch( Throwable ex ){
                    throw new ActionException( action, "Failed to perform action:\n"+action.toDescription()+"\n    " + ex.getMessage(), ex);
                }
        }
        log.debug(dryPrefix + "Management operations in batch:");
        int i = 1;
        for( BatchedCommand command : ctx.getBatch().getCommands() ){
            log.debug("    " + i++ + ": " + command.getCommand());
        }
        log.debug(dryPrefix + "Executing CLI batch:");
        try {
            if( ! dryRun )
                AS7CliUtils.executeRequest( ctx.getBatch().toRequest(), config.getGlobal().getAS7Config() );
        }
        catch( CliBatchException ex ){
            BatchFailure failure = AS7CliUtils.extractFailedOperationNode( ex.getResponseNode() );
            if( null == failure ){
                log.warn("Unable to parse CLI batch operation index: " + ex.getResponseNode());
                throw new MigrationException("Executing a CLI batch failed: " + ex, ex);
            }
            IMigrationAction causeAction;
            BatchedCommand cmd = ctx.getBatch().getCommands().get( failure.getIndex() - 1 );
            if( cmd instanceof BatchedCommandWithAction )
                causeAction = ((BatchedCommandWithAction)cmd).getAction();
            else
                causeAction = cliActions.get( failure.getIndex() - 1 );
            throw new ActionException( causeAction, "Executing a CLI batch failed: " + failure.getMessage());
        }
        catch( Exception ex ) {
            throw new MigrationException("Executing a CLI batch failed: " + ex, ex);
        }
    }
private void performActions ( ) throws MigrationException { log . debug ( "======== performActions() ========" ) ; boolean dryRun = config . getGlobal ( ) . isDryRun ( ) ; if ( dryRun ) log . info ( "\n** This is a DRY RUN, operations are not really performed, only prepared and listed. **\n" ) ; String dryPrefix = dryRun ? "(DRY RUN) " : "" ; ctx . getBatch ( ) . clear ( ) ; List < IMigrationAction > actions = ctx . getActions ( ) ; List < IMigrationAction > sorted = ActionDependencySorter . sort ( actions ) ; List < CliCommandAction > cliActions = new LinkedList ( ) ; log . info ( dryPrefix + "Performing actions:" ) ; for ( IMigrationAction action : sorted ) { if ( action instanceof CliCommandAction ) cliActions . add ( ( CliCommandAction ) action ) ; log . info ( "    " + action . toDescription ( ) ) ; action . setMigrationContext ( ctx ) ; if ( ( action instanceof CliCommandAction ) || ! dryRun ) try { action . perform ( ) ; } catch ( ActionException ex ) { throw ex ; } catch ( Throwable ex ) { throw new ActionException ( action , "Failed to perform action:\n" + action . toDescription ( ) + "\n    " + ex . getMessage ( ) , ex ) ; } } log . debug ( dryPrefix + "Management operations in batch:" ) ; int i = 1 ; for ( BatchedCommand command : ctx . getBatch ( ) . getCommands ( ) ) { log . debug ( "    " + i ++ + ": " + command . getCommand ( ) ) ; } log . debug ( dryPrefix + "Executing CLI batch:" ) ; try { if ( ! dryRun ) AS7CliUtils . executeRequest ( ctx . getBatch ( ) . toRequest ( ) , config . getGlobal ( ) . getAS7Config ( ) ) ; } catch ( CliBatchException ex ) { BatchFailure failure = AS7CliUtils . extractFailedOperationNode ( ex . getResponseNode ( ) ) ; if ( null == failure ) { log . warn ( "Unable to parse CLI batch operation index: " + ex . getResponseNode ( ) ) ; throw new MigrationException ( "Executing a CLI batch failed: " + ex , ex ) ; } IMigrationAction causeAction ; BatchedCommand cmd = ctx . getBatch ( ) . getCommands ( ) . get ( failure . getIndex ( ) - 1 ) ; if ( cmd instanceof BatchedCommandWithAction ) causeAction = ( ( BatchedCommandWithAction ) cmd ) . getAction ( ) ; else causeAction = cliActions . get ( failure . getIndex ( ) - 1 ) ; throw new ActionException ( causeAction , "Executing a CLI batch failed: " + failure . getMessage ( ) ) ; } catch ( Exception ex ) { throw new MigrationException ( "Executing a CLI batch failed: " + ex , ex ) ; } }
Performs the actions.
Performs the actions .
// Clear CLI commands, should there be any. // Sort the actions according to dependencies. MIGR-104 // Store CLI actions into an ordered list. // In perform(), they are just put into a batch. Using this, we can tell which one failed. // Perform the actions. // Again. To be sure. // On dry run, CliCommandActions can still be performed as they only add to the batch. /// DEBUG: Dump created CLI operations // Execution //Integer index = AS7CliUtils.parseFailedOperationIndex( ex.getResponseNode() ); // First, try if it's a BatchedCommandWithAction, and get the action if so. // Then shoot blindly into cliActions. May be wrong offset - some actions create multiple CLI commands! TODO.