Project

General

Profile

1
package eu.dnetlib.functionality.modular.ui.workflows.values;
2

    
3
import com.google.common.base.Function;
4
import com.google.common.collect.Iterables;
5
import com.google.common.collect.Lists;
6
import eu.dnetlib.data.hadoop.rmi.HadoopService;
7
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
8
import eu.dnetlib.msro.workflows.util.ValidNodeValuesFetcher;
9
import org.apache.commons.logging.Log;
10
import org.apache.commons.logging.LogFactory;
11

    
12
import javax.annotation.Resource;
13
import java.util.List;
14
import java.util.Map;
15

    
16
public class ListHBaseTables extends ValidNodeValuesFetcher {
17

    
18
	/**
19
	 * logger.
20
	 */
21
	private static final Log log = LogFactory.getLog(ListHBaseTables.class);
22

    
23
	private final Function<String, DnetParamValue> f = new Function<String, DnetParamValue>() {
24

    
25
		@Override
26
		public DnetParamValue apply(final String s) {
27

    
28
			return new DnetParamValue(s, s);
29
		}
30
	};
31

    
32
	@Resource
33
	private UniqueServiceLocator serviceLocator;
34

    
35
	@Override
36
	protected List<DnetParamValue> obtainValues(final Map<String, String> params) throws Exception {
37
		List<DnetParamValue> res = Lists.newArrayList(Iterables.transform(listTables(params.get("cluster")), f));
38
		return res;
39
	}
40

    
41
	private List<String> listTables(final String cluster) {
42
		try {
43
			log.info("list tables for cluster: " + cluster);
44
			return serviceLocator.getService(HadoopService.class).listHbaseTables(cluster);
45
		} catch (Throwable e) {
46
			log.error(e);
47
			return Lists.newArrayList();
48
		}
49
	}
50
}
(4-4/5)