hdfs storage tested. jar package configuration added.
This commit is contained in:
parent
8a1a5a8cac
commit
3230a6bebe
|
@ -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
26
pom.xml
|
@ -49,6 +49,32 @@
|
|||
</dependency>
|
||||
</dependencies>
|
||||
<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>
|
||||
</build>
|
||||
</project>
|
|
@ -40,8 +40,9 @@ public class AgentServer {
|
|||
ServletContextHandler servletContextHandler = new ServletContextHandler();
|
||||
ServletHolder servletHolder = servletContextHandler.addServlet(
|
||||
DispatcherServlet.class, "/");
|
||||
servletHolder.setInitParameter("contextConfigLocation",
|
||||
"classpath*:/application-context.xml");
|
||||
servletHolder
|
||||
.setInitParameter("contextConfigLocation",
|
||||
"classpath*:/org/bench4q/agent/config/application-context.xml");
|
||||
this.getServer().setHandler(servletContextHandler);
|
||||
this.getServer().start();
|
||||
return true;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.bench4q.agent.scenario;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
|
@ -17,6 +16,7 @@ import javax.xml.bind.Marshaller;
|
|||
|
||||
import org.bench4q.agent.plugin.Plugin;
|
||||
import org.bench4q.agent.plugin.PluginManager;
|
||||
import org.bench4q.agent.storage.HdfsStorage;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
@ -24,6 +24,7 @@ import org.springframework.stereotype.Component;
|
|||
public class ScenarioEngine {
|
||||
private PluginManager pluginManager;
|
||||
private Map<UUID, ScenarioContext> runningTests;
|
||||
private HdfsStorage hdfsStorage;
|
||||
|
||||
public ScenarioEngine() {
|
||||
this.setRunningTests(new HashMap<UUID, ScenarioContext>());
|
||||
|
@ -38,6 +39,15 @@ public class ScenarioEngine {
|
|||
this.pluginManager = pluginManager;
|
||||
}
|
||||
|
||||
private HdfsStorage getHdfsStorage() {
|
||||
return hdfsStorage;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setHdfsStorage(HdfsStorage hdfsStorage) {
|
||||
this.hdfsStorage = hdfsStorage;
|
||||
}
|
||||
|
||||
public Map<UUID, ScenarioContext> getRunningTests() {
|
||||
return runningTests;
|
||||
}
|
||||
|
@ -147,7 +157,7 @@ public class ScenarioEngine {
|
|||
}
|
||||
|
||||
public String getPath() {
|
||||
return System.getProperty("user.dir");
|
||||
return "hdfs://133.133.12.21:9000/home/bench4q/results";
|
||||
}
|
||||
|
||||
public void saveTestResults(UUID runId) {
|
||||
|
@ -185,20 +195,22 @@ public class ScenarioEngine {
|
|||
}
|
||||
|
||||
private void doSaveTestResults(UUID runId, TestResult testResult) {
|
||||
FileWriter fileWriter = null;
|
||||
StringWriter stringWriter = null;
|
||||
try {
|
||||
Marshaller marshaller = JAXBContext.newInstance(
|
||||
testResult.getClass()).createMarshaller();
|
||||
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
|
||||
fileWriter = new FileWriter(new File(this.getPath() + "/"
|
||||
+ runId.toString() + ".xml"));
|
||||
marshaller.marshal(testResult, fileWriter);
|
||||
stringWriter = new StringWriter();
|
||||
String fileName = this.getPath() + "/" + runId.toString() + ".xml";
|
||||
marshaller.marshal(testResult, stringWriter);
|
||||
String content = stringWriter.toString();
|
||||
this.getHdfsStorage().writeFile(content, fileName);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (fileWriter != null) {
|
||||
if (stringWriter != null) {
|
||||
try {
|
||||
fileWriter.close();
|
||||
stringWriter.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -16,9 +16,11 @@ import org.apache.hadoop.io.IOUtils;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class HdfsService {
|
||||
public class HdfsStorage {
|
||||
private FileSystem getFileSystem() throws IOException {
|
||||
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);
|
||||
}
|
||||
|
|
@ -44,7 +44,7 @@ public class RunScenarioTest {
|
|||
getUserBehaviorModel.setParameters(new ArrayList<ParameterModel>());
|
||||
ParameterModel parameterModelOne = new ParameterModel();
|
||||
parameterModelOne.setKey("url");
|
||||
parameterModelOne.setValue("http://localhost:6565");
|
||||
parameterModelOne.setValue("http://Bench4Q-Agent-1:6565");
|
||||
getUserBehaviorModel.getParameters().add(parameterModelOne);
|
||||
runScenarioModel.getUserBehaviors().add(getUserBehaviorModel);
|
||||
UserBehaviorModel timerUserBehaviorModel = new UserBehaviorModel();
|
||||
|
@ -64,7 +64,7 @@ public class RunScenarioTest {
|
|||
.setParameters(new ArrayList<ParameterModel>());
|
||||
ParameterModel parameterModelThree = new ParameterModel();
|
||||
parameterModelThree.setKey("url");
|
||||
parameterModelThree.setValue("http://localhost:6565");
|
||||
parameterModelThree.setValue("http://Bench4Q-Agent-1:6565");
|
||||
postUserBehaviorModel.getParameters().add(parameterModelThree);
|
||||
ParameterModel parameterModelFour = new ParameterModel();
|
||||
parameterModelFour.setKey("content");
|
||||
|
@ -75,7 +75,7 @@ public class RunScenarioTest {
|
|||
runScenarioModel.getClass()).createMarshaller();
|
||||
StringWriter stringWriter = new 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();
|
||||
System.out.println(content);
|
||||
URL target = new URL(url);
|
||||
|
|
Loading…
Reference in New Issue