Project

General

Profile

« Previous | Next » 

Revision 29044

Added by Eri Katsari over 10 years ago

m

View differences:

modules/dnet-openaire-stats/trunk/src/main/java/eu/dnetlib/data/mapreduce/hbase/statsExport/drivers/SqoopDriver.java
12 12
import org.apache.hadoop.fs.LocatedFileStatus;
13 13
import org.apache.hadoop.fs.Path;
14 14
import org.apache.hadoop.fs.RemoteIterator;
15
import org.apache.log4j.BasicConfigurator;
15 16
import org.apache.log4j.Logger;
16 17
import org.apache.sqoop.Sqoop;
17 18

  
......
67 68

  
68 69
					"--verbose", "--username", dbUser, "--password", dbPass, "--driver", "org.postgresql.Driver", "--batch", "--mapreduce-job-name", "Sqoop Stats Import", "-m", sqoopReducersCount };
69 70

  
70
			 
71
				int ret = Sqoop.runTool(str,conf);
72
				if (ret != 0) {
73
					log.error("Could not run Sqoop Tool " + Integer.toString(ret));
74
					throw new RuntimeException("Could not run Sqoop Tool " + Integer.toString(ret) );
75
				}
76
		 
71
			int ret = Sqoop.runTool(str);
72
			if (ret != 0) {
73
				log.error("Could not run Sqoop Tool " + Integer.toString(ret));
74
				throw new RuntimeException("Could not run Sqoop Tool " + Integer.toString(ret));
75
			}
76

  
77 77
			cleanUp(table.getKey());
78 78
		}
79 79
	}
......
94 94
		for (Entry<Object, Object> e : tableMappings.entrySet()) {
95 95
			String name = (String) e.getKey();
96 96
			for (String filename : fileNames) {
97
                 String str=filename.substring(filename.lastIndexOf('\\')+1);
98
				
99
                 String split[] = str.split("-");
97
				String str = filename.substring(filename.lastIndexOf('\\') + 1);
100 98

  
99
				String split[] = str.split("-");
100

  
101 101
				split[0] = split[0].replaceAll(".*/", "");
102
                 log.info(split[0]);
102
				log.info(split[0]);
103 103
				if (split[0].equals(name)) {
104 104

  
105 105
					tables.put((String) e.getValue(), filename);
......
125 125
	}
126 126

  
127 127
	public ArrayList<String> listHdfsDir() throws Exception {
128
		if (conf == null) {
129
			conf = new Configuration();
130
		}
128 131
		hdfs = FileSystem.get(conf);
129 132

  
130 133
		RemoteIterator<LocatedFileStatus> Files;
......
189 192
		tableMappings.load(file);
190 193
		file.close();
191 194
		if (tableMappings == null || tableMappings.isEmpty()) {
192
			throw new Exception("Could not load Table Mappings in sqoop init job");
195
			throw new Exception("Could not load Table Mconfappings in sqoop init job");
193 196
		}
194 197
	}
195 198

  
......
217 220
		}
218 221
	}
219 222

  
223
	public static void main(String[] args) {
224
		SqoopDriver sqoopDriver = new SqoopDriver();
225

  
226
		BasicConfigurator.configure();
227

  
228
		sqoopDriver.setDelim("!");
229
		sqoopDriver.setOutputPath("/tmp/test_stats/");
230

  
231
		sqoopDriver.setConnectionUrl("jdbc:postgresql://duffy.di.uoa.gr:5432/test_stats");
232
		sqoopDriver.setDbUser("sqoop");
233
		sqoopDriver.setDbPass("sqoop");
234
		sqoopDriver.setReducersCount("1");
235
		sqoopDriver.setRecsPerStatement("1000");
236
		sqoopDriver.setStatementPerTrans("1000");
237

  
238
		sqoopDriver.setUseHdfsStore(true);
239

  
240
		// HashMap<String, String> tables = new HashMap<String, String>();
241

  
242
		// tables.put("datasource", "/tmp/test_stats/datasource-r-00000");
243

  
244
		// throw new Exception(datasource + "  " + e +
245
		// sqoopDriver.getConnectionUrl() + sqoopDriver.getDbPass() +
246
		// sqoopDriver.getDbUser() );
247

  
248
		try {
249
			sqoopDriver.initSqoopJob();
250
			// sqoopDriver.run(tables);
251
		} catch (Exception e) {
252
			System.out.print("ERROR " + e.toString());
253
			e.printStackTrace();
254
		}
255

  
256
	}
257

  
220 258
	public String getConnectionUrl() {
221 259
		return connectionUrl;
222 260
	}
modules/dnet-openaire-stats/trunk/src/main/resources/eu/dnetlib/data/mapreduce/hbase/statsExport/log4j.properties
15 15
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
16 16
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
17 17

  
18
#log4j.rootLogger = WARN, R
19

  
20
#log4j.logger.gr.uoa = DEBUG
21
#log4j.logger.org.springframework = DEBUG, S
22
#log4j.additivity.org.springframework = false
23
#
24
#log4j.logger.com.opensymphony.xwork2.ognl.OgnlValueStack = FATAL
25
#log4j.logger.com.opensymphony.xwork2.ObjectFactory = FATAL
26
#
27
#log4j.appender.R=org.apache.log4j.RollingFileAppender
28
#log4j.appender.R.File=/tmp/log/validator.log
29
#log4j.appender.R.MaxFileSize=10MB
30
#log4j.appender.R.MaxBackupIndex=10
31
#log4j.appender.R.layout=org.apache.log4j.PatternLayout
32
#log4j.appender.R.layout.ConversionPattern= %d %p %t [%c] - %m%n
33
#
34
#log4j.appender.S=org.apache.log4j.RollingFileAppender
35
#log4j.appender.S.File=/tmp/log/spring-validator.log
36
#log4j.appender.S.MaxFileSize=10MB
37
#log4j.appender.S.MaxBackupIndex=10
38
#log4j.appender.S.layout=org.apache.log4j.PatternLayout
39
#log4j.appender.S.layout.ConversionPattern= %d %p %t [%c] - %m%n
modules/dnet-openaire-stats/trunk/pom.xml
12 12
	<version>0.0.1-SNAPSHOT</version>
13 13
	<build>
14 14
		<plugins>
15
 
15

  
16
			<plugin>
17
				<groupId>org.codehaus.mojo</groupId>
18
				<artifactId>exec-maven-plugin</artifactId>
19
				<version>1.2.1</version>
20
				<configuration>
21
					<mainClass>eu.dnetlib.data.mapreduce.hbase.statsExport.drivers.SqoopDriver</mainClass>
22
				</configuration>
23
			</plugin>
24
			 <plugin>
25
            <groupId>org.apache.maven.plugins</groupId>
26
            <artifactId>maven-shade-plugin</artifactId>
27
            <version>2.1</version>
28
            <executions>
29
                <execution>
30
                    <phase>package</phase>
31
                    <goals>
32
                        <goal>shade</goal>
33
                    </goals>
34
                    <configuration>
35
                        <transformers>
36
                            <transformer
37
                                implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
38
                            </transformer>
39
                        </transformers>
40
                    </configuration>
41
                </execution>
42
            </executions> </plugin>
16 43
		</plugins>
44

  
17 45
	</build>
18
	<dependencies> 
46
	<dependencies>
19 47

  
20
<dependency>
21
    <groupId>jdk.tools</groupId>
22
    <artifactId>jdk.tools</artifactId>
23
    <version>1.7.0_05</version>
24
    <scope>system</scope>
25
    <systemPath>${JAVA_HOME}/lib/tools.jar</systemPath>
26
</dependency>
27
 
28
 
29 48
		<dependency>
49
			<groupId>jdk.tools</groupId>
50
			<artifactId>jdk.tools</artifactId>
51
			<version>1.7.0_05</version>
52
			<scope>system</scope>
53
			<systemPath>${JAVA_HOME}/lib/tools.jar</systemPath>
54
		</dependency>
55
		<dependency>
56
			<groupId>org.apache.logging.log4j</groupId>
57
			<artifactId>log4j-api</artifactId>
58
			<version>2.0-rc2</version>
59
		</dependency>
60
		<dependency>
61
			<groupId>org.apache.logging.log4j</groupId>
62
			<artifactId>log4j-core</artifactId>
63
			<version>2.0-rc2</version>
64
		</dependency>
65
		<dependency>
66
			<groupId>log4j</groupId>
67
			<artifactId>log4j</artifactId>
68
			<version>1.2.17</version>
69
		</dependency>
70
		<dependency>
30 71
			<groupId>org.slf4j</groupId>
31 72
			<artifactId>slf4j-api</artifactId>
32 73
			<version>1.7.6</version>

Also available in: Unified diff