<commit_before>package io.biblia.workflows.manager.action;

import com.google.common.base.Preconditions;

import io.biblia.workflows.definition.Action;

public class ActionSubmitter implements Runnable {
	
	private final Action action;
	
	public ActionSubmitter(Action action) {
		Preconditions.checkNotNull(action);
		this.action = action;
	}
	
	@Override
	public void run() {
	
		try {
			this.submitAction(this.action);
		}
		catch(Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * Submits an action to hadoop to be processed.
	 * @param action
	 */
	private void submitAction(Action action) {
		
		//TODO
		
		
		//1.2, Update database with submitted
		//1.2.1 If database accepts update by comparing versions
		// Submit to Oozie.
		//1.2.2 If there is an error submitting action, update
		//database with state: Ready.
		///1.2.3 Otherwise, if the submission of the action goes well
		//and I get back a workflow id, save the workflow id to the 
		//mongodatabase.  
		//
		//If there is an error talking to the database at any of this 
		//points, this is a critical error of the system and needs to 
		//be logged and taken care of.
		//
		
     
	}

}<commit_msg>Added the complete outline of the ActionSubmitter.<commit_after>package io.biblia.workflows.manager.action;

import com.google.common.base.Preconditions;

import io.biblia.workflows.definition.Action;
import io.biblia.workflows.manager.oozie.OozieClientUtil;

public class ActionSubmitter implements Runnable {
	
	private final Action action;
	private final ActionPersistance persistance;
  
	public ActionSubmitter(Action action, ActionPersistance persistance) {
		Preconditions.checkNotNull(action);
      Preconditions.checkNotNull(persistance);
		this.action = action;
      this.persistance = persistance;
	}
	
	@Override
	public void run() {
	
		try {
			this.submitAction(this.action);
		}
		catch(Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * Submits an action to hadoop to be processed.
	 * @param action
	 */
	private void submitAction(Action action) {
		
		
		  //1.2, Update database with submitted
		  try {
            this.persistance.updateActionState(action, ActionState.SUBMITTED);
        }
        catch (OutdatedActionException ex) {
            return;
        }
		
        //1.2.1 If database accepts update by comparing versions
		  // Submit to Oozie.
		  try{
			   String submissionId = OozieClientUtil.submitAndStartOozieJob(action);
        }
        catch(OozieClientException | IOException ex) {
            ex.printStackTrace();
            
             //	1.2.1.1 If there is an error submitting action, update
				//database with state: READY.
				try{
            	 this.persistance.updateActionState(action, ActionState.READY);  
            }
            catch(OutdatedActionException ex) {
                return;
            }
				
            return;
        }
        try {                        
            this.persistance.addActionSubmissionId(action, submissionId);
        }
        catch(OutdatedActionException ex) {
            //This exception is not supposed to be thrown in here. Log the error
            //as a bug to be fixed later on.
        }
     
	}

}
{'fraction_non_alphanumeric': 0.08611544461778471, 'fraction_numerical': 0.0062402496099844, 'mean_word_length': 2.3997879109225875, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1793729', 'n_tokens_mistral': 1021, 'n_tokens_neox': 906, 'n_words': 267}