hdfs storage tested. jar package configuration added.

This commit is contained in:
Zhen Tang 2013-07-05 11:35:31 +08:00
parent 8a1a5a8cac
commit 3230a6bebe
7 changed files with 81 additions and 15 deletions

25
descriptor.xml Normal file
View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>jar-with-dependencies</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>false</useProjectArtifact>
<unpack>false</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>${project.build.outputDirectory}</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
</assembly>

26
pom.xml
View File

@ -49,6 +49,32 @@
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>descriptor.xml</descriptor>
</descriptors>
<appendAssemblyId>false</appendAssemblyId>
<archive>
<manifest>
<mainClass>org.bench4q.agent.Main</mainClass>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>assembly</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<finalName>bench4q-agent</finalName> <finalName>bench4q-agent</finalName>
</build> </build>
</project> </project>

View File

@ -40,8 +40,9 @@ public class AgentServer {
ServletContextHandler servletContextHandler = new ServletContextHandler(); ServletContextHandler servletContextHandler = new ServletContextHandler();
ServletHolder servletHolder = servletContextHandler.addServlet( ServletHolder servletHolder = servletContextHandler.addServlet(
DispatcherServlet.class, "/"); DispatcherServlet.class, "/");
servletHolder.setInitParameter("contextConfigLocation", servletHolder
"classpath*:/application-context.xml"); .setInitParameter("contextConfigLocation",
"classpath*:/org/bench4q/agent/config/application-context.xml");
this.getServer().setHandler(servletContextHandler); this.getServer().setHandler(servletContextHandler);
this.getServer().start(); this.getServer().start();
return true; return true;

View File

@ -1,7 +1,6 @@
package org.bench4q.agent.scenario; package org.bench4q.agent.scenario;
import java.io.File; import java.io.StringWriter;
import java.io.FileWriter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
@ -17,6 +16,7 @@ import javax.xml.bind.Marshaller;
import org.bench4q.agent.plugin.Plugin; import org.bench4q.agent.plugin.Plugin;
import org.bench4q.agent.plugin.PluginManager; import org.bench4q.agent.plugin.PluginManager;
import org.bench4q.agent.storage.HdfsStorage;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -24,6 +24,7 @@ import org.springframework.stereotype.Component;
public class ScenarioEngine { public class ScenarioEngine {
private PluginManager pluginManager; private PluginManager pluginManager;
private Map<UUID, ScenarioContext> runningTests; private Map<UUID, ScenarioContext> runningTests;
private HdfsStorage hdfsStorage;
public ScenarioEngine() { public ScenarioEngine() {
this.setRunningTests(new HashMap<UUID, ScenarioContext>()); this.setRunningTests(new HashMap<UUID, ScenarioContext>());
@ -38,6 +39,15 @@ public class ScenarioEngine {
this.pluginManager = pluginManager; this.pluginManager = pluginManager;
} }
private HdfsStorage getHdfsStorage() {
return hdfsStorage;
}
@Autowired
private void setHdfsStorage(HdfsStorage hdfsStorage) {
this.hdfsStorage = hdfsStorage;
}
public Map<UUID, ScenarioContext> getRunningTests() { public Map<UUID, ScenarioContext> getRunningTests() {
return runningTests; return runningTests;
} }
@ -147,7 +157,7 @@ public class ScenarioEngine {
} }
public String getPath() { public String getPath() {
return System.getProperty("user.dir"); return "hdfs://133.133.12.21:9000/home/bench4q/results";
} }
public void saveTestResults(UUID runId) { public void saveTestResults(UUID runId) {
@ -185,20 +195,22 @@ public class ScenarioEngine {
} }
private void doSaveTestResults(UUID runId, TestResult testResult) { private void doSaveTestResults(UUID runId, TestResult testResult) {
FileWriter fileWriter = null; StringWriter stringWriter = null;
try { try {
Marshaller marshaller = JAXBContext.newInstance( Marshaller marshaller = JAXBContext.newInstance(
testResult.getClass()).createMarshaller(); testResult.getClass()).createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
fileWriter = new FileWriter(new File(this.getPath() + "/" stringWriter = new StringWriter();
+ runId.toString() + ".xml")); String fileName = this.getPath() + "/" + runId.toString() + ".xml";
marshaller.marshal(testResult, fileWriter); marshaller.marshal(testResult, stringWriter);
String content = stringWriter.toString();
this.getHdfsStorage().writeFile(content, fileName);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
if (fileWriter != null) { if (stringWriter != null) {
try { try {
fileWriter.close(); stringWriter.close();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -16,9 +16,11 @@ import org.apache.hadoop.io.IOUtils;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Component @Component
public class HdfsService { public class HdfsStorage {
private FileSystem getFileSystem() throws IOException { private FileSystem getFileSystem() throws IOException {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
conf.set("mapred.jop.tracker", "hdfs://133.133.12.21:9001");
conf.set("fs.default.name", "hdfs://133.133.12.21:9000");
return FileSystem.get(conf); return FileSystem.get(conf);
} }

View File

@ -44,7 +44,7 @@ public class RunScenarioTest {
getUserBehaviorModel.setParameters(new ArrayList<ParameterModel>()); getUserBehaviorModel.setParameters(new ArrayList<ParameterModel>());
ParameterModel parameterModelOne = new ParameterModel(); ParameterModel parameterModelOne = new ParameterModel();
parameterModelOne.setKey("url"); parameterModelOne.setKey("url");
parameterModelOne.setValue("http://localhost:6565"); parameterModelOne.setValue("http://Bench4Q-Agent-1:6565");
getUserBehaviorModel.getParameters().add(parameterModelOne); getUserBehaviorModel.getParameters().add(parameterModelOne);
runScenarioModel.getUserBehaviors().add(getUserBehaviorModel); runScenarioModel.getUserBehaviors().add(getUserBehaviorModel);
UserBehaviorModel timerUserBehaviorModel = new UserBehaviorModel(); UserBehaviorModel timerUserBehaviorModel = new UserBehaviorModel();
@ -64,7 +64,7 @@ public class RunScenarioTest {
.setParameters(new ArrayList<ParameterModel>()); .setParameters(new ArrayList<ParameterModel>());
ParameterModel parameterModelThree = new ParameterModel(); ParameterModel parameterModelThree = new ParameterModel();
parameterModelThree.setKey("url"); parameterModelThree.setKey("url");
parameterModelThree.setValue("http://localhost:6565"); parameterModelThree.setValue("http://Bench4Q-Agent-1:6565");
postUserBehaviorModel.getParameters().add(parameterModelThree); postUserBehaviorModel.getParameters().add(parameterModelThree);
ParameterModel parameterModelFour = new ParameterModel(); ParameterModel parameterModelFour = new ParameterModel();
parameterModelFour.setKey("content"); parameterModelFour.setKey("content");
@ -75,7 +75,7 @@ public class RunScenarioTest {
runScenarioModel.getClass()).createMarshaller(); runScenarioModel.getClass()).createMarshaller();
StringWriter stringWriter = new StringWriter(); StringWriter stringWriter = new StringWriter();
marshaller.marshal(runScenarioModel, stringWriter); marshaller.marshal(runScenarioModel, stringWriter);
String url = "http://localhost:6565/test/run"; String url = "http://Bench4Q-Agent-1:6565/test/run";
String content = stringWriter.toString(); String content = stringWriter.toString();
System.out.println(content); System.out.println(content);
URL target = new URL(url); URL target = new URL(url);