Project

General

Profile

1
package eu.dnetlib.msro.workflows.hadoop;
2

    
3
import javax.annotation.Resource;
4

    
5
import org.apache.commons.lang.StringUtils;
6
import org.springframework.beans.factory.annotation.Value;
7

    
8
import com.googlecode.sarasvati.Arc;
9
import com.googlecode.sarasvati.NodeToken;
10

    
11
import eu.dnetlib.data.hadoop.rmi.HadoopService;
12
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
13
import eu.dnetlib.msro.workflows.nodes.AsyncJobNode;
14

    
15
/**
16
 * The Class SetClusterAndTableJobNode.
17
 */
18
public class SetClusterAndTableJobNode extends AsyncJobNode {
19

    
20
	/** The cluster. */
21
	private String cluster;
22

    
23
	/** The table. */
24
	@Value("${hbase.mapred.datatable}")
25
	private String table;
26

    
27
	/** The table param. */
28
	private String tableParam;
29

    
30
	/** The service locator. */
31
	@Resource
32
	private UniqueServiceLocator serviceLocator;
33

    
34
	/*
35
	 * (non-Javadoc)
36
	 * 
37
	 * @see eu.dnetlib.msro.workflows.nodes.AsyncJobNode#execute(com.googlecode.sarasvati.NodeToken)
38
	 */
39
	@Override
40
	protected String execute(final NodeToken token) throws Exception {
41

    
42
		if (StringUtils.isBlank(getCluster())) throw new IllegalArgumentException("missing cluster name parameter");
43
		if (StringUtils.isBlank(table)) throw new IllegalArgumentException("missing table name parameter");
44
		if (!serviceLocator.getService(HadoopService.class).existHbaseTable(getCluster(), table))
45
			throw new IllegalArgumentException(String.format("unexisting table %s on cluster %s", table, getCluster()));
46

    
47
		token.getEnv().setAttribute("cluster", getCluster());
48
		token.getEnv().setAttribute(getTableParam(), table);
49

    
50
		return Arc.DEFAULT_ARC;
51
	}
52

    
53
	/**
54
	 * Gets the cluster.
55
	 *
56
	 * @return the cluster
57
	 */
58
	public String getCluster() {
59
		return cluster;
60
	}
61

    
62
	/**
63
	 * Sets the cluster.
64
	 *
65
	 * @param cluster
66
	 *            the new cluster
67
	 */
68
	public void setCluster(final String cluster) {
69
		this.cluster = cluster;
70
	}
71

    
72
	/**
73
	 * Gets the table param.
74
	 *
75
	 * @return the table param
76
	 */
77
	public String getTableParam() {
78
		return tableParam;
79
	}
80

    
81
	/**
82
	 * Sets the table param.
83
	 *
84
	 * @param tableParam
85
	 *            the new table param
86
	 */
87
	public void setTableParam(final String tableParam) {
88
		this.tableParam = tableParam;
89
	}
90

    
91
}
(8-8/10)