Project

General

Profile

« Previous | Next » 

Revision 30055

Added by Marek Horst over 9 years ago

introducing oozie maven plugin required by IIS build system for monitoring oozie progress of executed job

View differences:

modules/icm-iis-oozie-maven-plugin/trunk/deploy.info
1
{
2
  "type_source": "SVN", 
3
  "goal": "package -U -T 4C source:jar", 
4
  "url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet40/modules/icm-iis-oozie-maven-plugin/trunk/", 
5
  "deploy_repository": "dnet4-snapshots", 
6
  "version": "4",
7
  "mail": "m.horst@icm.edu.pl",
8
  "deploy_repository_url": "http://maven.research-infrastructures.eu/nexus/content/repositories/dnet4-bootstrap-snapshot", 
9
  "name": "icm-iis-oozie-maven-plugin"
10
}
modules/icm-iis-oozie-maven-plugin/trunk/src/main/java/eu/dnetlib/maven/plugin/oozie/ReadJobId.java
1
package eu.dnetlib.maven.plugin.oozie;
2

  
3
import java.io.BufferedReader;
4
import java.io.File;
5
import java.io.FileInputStream;
6
import java.io.FileNotFoundException;
7
import java.io.IOException;
8
import java.io.InputStreamReader;
9

  
10
import org.apache.maven.plugin.AbstractMojo;
11
import org.apache.maven.plugin.MojoExecutionException;
12
import org.apache.maven.plugin.MojoFailureException;
13
import org.apache.maven.project.MavenProject;
14
import org.codehaus.plexus.util.StringUtils;
15

  
16
/**
17
 * Read oozie job identifier from log file.
18
 * @author mhorst
19
 *
20
 * @goal read-job-id
21
 */
22
public class ReadJobId extends AbstractMojo {
23
	
24

  
25
    public static final String PROPERTY_NAME_LOG_FILE_LOCATION = "logFileLocation";
26
    
27
	public static final String PROPERTY_NAME_OOZIE_JOB_ID = "oozieJobId";
28
	
29
	public static final String OOZIE_JOB_LOG_LINE_TOKEN_SEPARATOR = ":";
30
	
31
	public static final String OOZIE_JOB_LOG_LINE_PREFIX = "job" + OOZIE_JOB_LOG_LINE_TOKEN_SEPARATOR;
32
	
33
	/**
34
	 * @parameter expression="${properties.logFileLocation}"
35
	 */
36
	private String logFileLocation;
37
	
38
	/** @parameter default-value="${project}" */
39
	private MavenProject project;
40
	
41
    @Override
42
    public void execute() throws MojoExecutionException, MojoFailureException {
43
		String extractedOozieJobId = extractOozieJobId(logFileLocation);
44
		if (extractedOozieJobId!=null) {
45
			project.getProperties().setProperty(PROPERTY_NAME_OOZIE_JOB_ID, 
46
    				extractedOozieJobId);	
47
			System.out.println("extracted job identifier: " + extractedOozieJobId);
48
		} else {
49
			throw new MojoFailureException("unable to extract oozie job identifier from log file: " + 
50
					logFileLocation);
51
		}
52
    }
53
    
54
    /**
55
     * Extracts oozie job identifier from log file
56
     * @param logFileLocation
57
     * @return extracted oozie job identifier
58
     * @throws MojoExecutionException 
59
     */
60
    private String extractOozieJobId(String logFileLocation) throws MojoExecutionException {
61
    	try {
62
    		BufferedReader reader = new BufferedReader(new InputStreamReader(
63
        			new FileInputStream(new File(logFileLocation))));
64
    		String line;
65
    		try {
66
    			while ((line = reader.readLine())!=null) {
67
    				String trimmedLine = line.trim();
68
        			if (trimmedLine.startsWith(OOZIE_JOB_LOG_LINE_PREFIX)) {
69
        				String[] split = StringUtils.split(trimmedLine, OOZIE_JOB_LOG_LINE_TOKEN_SEPARATOR);
70
        				if (split.length == 2) {
71
        					return split[1].trim();
72
        				}
73
        			}
74
        		}
75
    			return null;
76
    		} finally {
77
    			reader.close();	
78
    		}
79
    	} catch (FileNotFoundException e) {
80
			throw new MojoExecutionException("unable to read log file: " + 
81
					logFileLocation, e);
82
    	} catch (IOException e) {
83
    		throw new MojoExecutionException("error occurred when reading log file: " + 
84
					logFileLocation, e);
85
		}
86
    }
87

  
88
}
0 89

  
modules/icm-iis-oozie-maven-plugin/trunk/src/main/java/eu/dnetlib/maven/plugin/oozie/CheckJobStatus.java
1
package eu.dnetlib.maven.plugin.oozie;
2

  
3
import org.apache.maven.plugin.AbstractMojo;
4
import org.apache.maven.plugin.MojoExecutionException;
5
import org.apache.maven.plugin.MojoFailureException;
6
import org.apache.oozie.client.AuthOozieClient;
7
import org.apache.oozie.client.OozieClient;
8
import org.apache.oozie.client.OozieClientException;
9
import org.apache.oozie.client.WorkflowJob.Status;
10

  
11

  
12

  
13
/**
14
 * Checks oozie job status.
15
 * @author mhorst
16
 *
17
 * @goal check-job-status
18
 */
19
public class CheckJobStatus extends AbstractMojo {
20
	
21

  
22
    public static final String PROPERTY_NAME_LOG_FILE_LOCATION = "logFileLocation";
23
	
24
	/**
25
	 * @parameter expression="${properties.oozieLocation}"
26
	 */
27
	private String oozieLocation;
28
	
29
	/**
30
	 * @parameter expression="${properties.jobId}"
31
	 */
32
	private String jobId;
33
	
34
	/**
35
	 * @parameter expression="${properties.maxExecutionTimeMins}"
36
	 */
37
	private Integer maxExecutionTimeMins;
38
	
39
	/**
40
	 * @parameter expression="${properties.checkIntervalSecs}"
41
	 */
42
	private Integer checkIntervalSecs = 5;
43
	
44
    @Override
45
    public void execute() throws MojoExecutionException, MojoFailureException {
46
    	OozieClient oozieClient = new OozieClient(oozieLocation);
47
//    	OozieClient oozieClient = new AuthOozieClient(oozieLocation);
48
    	long maxExecutionTime = 1000L * 60 * maxExecutionTimeMins;
49
    	long checkInterval = 1000L * checkIntervalSecs;
50
    	long startTime = System.currentTimeMillis();
51
    	try {
52
        	try {
53
        		while ((System.currentTimeMillis()-startTime)<maxExecutionTime) {
54
        			Thread.sleep(checkInterval);
55
        			Status status = oozieClient.getJobInfo(jobId).getStatus();
56
        			if (Status.SUCCEEDED.equals(status)) {
57
//        				TODO change to info
58
        				getLog().warn("job SUCCEEDED");
59
        				return;
60
        			} else if (Status.FAILED.equals(status) || Status.KILLED.equals(status)) {
61
        				System.out.print(oozieClient.getJobLog(jobId));
62
        				throw new MojoFailureException("job " + jobId + " finished with status: " + status);
63
        			} else {
64
//        				TODO change to info
65
        				getLog().warn("job " + jobId + " is still running with status: " + status);
66
        			}
67
        		}
68
        		System.out.print(oozieClient.getJobLog(jobId));
69
            	throw new MojoFailureException("Maximum execution time has passed!");
70
            	
71
        	} catch (InterruptedException e) {
72
        		System.out.print(oozieClient.getJobLog(jobId));
73
        		throw new MojoExecutionException("exception occured while sleeping", e);
74
    		}
75
    	} catch (OozieClientException e) {
76
			throw new MojoExecutionException("exception occured when obtaining status from oozie", e);
77
		}
78
    }
79
    
80
    public static void main(String[] args) throws OozieClientException {
81
    	String authOption = "SIMPLE";
82
    	String jobId = "0000503-140901135450278-oozie-oozi-W";
83
    	String oozieLocation = "http://master3.hadoop.iis.openaire.eu:11000/oozie/";
84
    	AuthOozieClient oozieClient = new AuthOozieClient(oozieLocation,
85
    			authOption);
86
    	System.out.println(System.getProperty("user.name"));
87
    	System.out.println(oozieClient.getAuthOption());
88
    	System.out.println(oozieClient.getJobInfo(jobId).getStatus());
89
	}
90

  
91
}
0 92

  
modules/icm-iis-oozie-maven-plugin/trunk/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3
	<parent>
4
    		<groupId>eu.dnetlib</groupId>
5
	        <artifactId>dnet-parent</artifactId>
6
            <version>1.0.0-SNAPSHOT</version>
7
	</parent>
8

  
9
	<version>0.0.1-SNAPSHOT</version>
10
	<modelVersion>4.0.0</modelVersion>
11
	<artifactId>icm-iis-oozie-maven-plugin</artifactId>
12
	<packaging>maven-plugin</packaging>
13
	<properties>
14
	</properties>
15

  
16
	<repositories>                                                                                                                                                                                
17
	    <repository>
18
	      <id>dnet-deps</id>
19
	      <name>dnet-dependencies</name>
20
	      <url>http://maven.research-infrastructures.eu/nexus/content/repositories/dnet-deps</url>
21
	      <layout>default</layout>
22
	    </repository>
23
		<repository>
24
			<id>cloudera</id>
25
			<name>Cloudera Repository</name>
26
			<url>https://repository.cloudera.com/artifactory/cloudera-repos</url>
27
			<releases>
28
				<enabled>true</enabled>
29
			</releases>
30
			<snapshots>
31
				<enabled>false</enabled>
32
			</snapshots>
33
		</repository>
34
	</repositories>
35

  
36
	<dependencies>
37
	<dependency>
38
	      <groupId>org.apache.maven</groupId>
39
	      <artifactId>maven-plugin-api</artifactId>
40
	      <version>2.0</version>
41
	    </dependency>
42
	    <dependency>
43
	      <groupId>org.apache.maven</groupId>
44
	      <artifactId>maven-project</artifactId>
45
	      <version>2.0</version>
46
	    </dependency>
47
	    <dependency>
48
			<groupId>org.apache.oozie</groupId>
49
			<artifactId>oozie-client</artifactId>
50
			<version>${iis.oozie.version}</version>
51
			<exclusions>
52
				<exclusion>
53
					<artifactId>slf4j-simple</artifactId>
54
					<groupId>org.slf4j</groupId>
55
				</exclusion>
56
			</exclusions>
57
		</dependency>
58
	</dependencies>
59
	<build>	
60
	<directory>target</directory>
61
    <outputDirectory>target/classes</outputDirectory>
62
    <finalName>${project.artifactId}-${project.version}</finalName>
63
    <testOutputDirectory>target/test-classes</testOutputDirectory>
64
    <plugins>
65
      <plugin>
66
        <groupId>org.apache.maven.plugins</groupId>
67
        <artifactId>maven-compiler-plugin</artifactId>
68
        <version>2.3.2</version>
69
        <configuration>
70
          <source>1.6</source>
71
          <target>1.6</target>
72
        </configuration>
73
      </plugin>
74
      <plugin>
75
        <groupId>org.apache.maven.plugins</groupId>
76
        <artifactId>maven-source-plugin</artifactId>
77
        <version>2.1.2</version>
78
        <executions>
79
          <execution>
80
            <id>attach-sources</id>
81
            <phase>verify</phase>
82
            <goals>
83
              <goal>jar-no-fork</goal>
84
            </goals>
85
          </execution>
86
        </executions>
87
      </plugin>
88
    </plugins>
89
	</build>
90

  
91
</project>
0 92

  
modules/icm-iis-oozie-maven-plugin/trunk/README.markdown
1
Maven plugin module prepared for oozie communication required by test verification profile.

Also available in: Unified diff