add ways to upload config file
This commit is contained in:
parent
864debb487
commit
22c76452be
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,11 @@
|
|||
-- Adminer 3.7.1 MySQL dump
|
||||
|
||||
SET NAMES utf8;
|
||||
SET foreign_key_checks = 0;
|
||||
SET time_zone = '+08:00';
|
||||
SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
|
||||
|
||||
CREATE DATABASE `bench4q-master-yvAxaJI0` /*!40100 DEFAULT CHARACTER SET utf8 */;
|
||||
USE `bench4q-master-yvAxaJI0`;
|
||||
|
||||
-- 2014-01-20 15:37:24
|
12
pom.xml
12
pom.xml
|
@ -32,10 +32,15 @@
|
|||
<artifactId>spring-webmvc</artifactId>
|
||||
<version>3.2.4.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.jackson</groupId>
|
||||
<artifactId>jackson-core-lgpl</artifactId>
|
||||
<version>1.9.13</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.jackson</groupId>
|
||||
<artifactId>jackson-mapper-asl</artifactId>
|
||||
<version>1.9.12</version>
|
||||
<version>1.9.13</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.hadoop</groupId>
|
||||
|
@ -62,6 +67,11 @@
|
|||
<artifactId>spring-test</artifactId>
|
||||
<version>3.2.5.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-fileupload</groupId>
|
||||
<artifactId>commons-fileupload</artifactId>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package org.bench4q.agent.api;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
@ -35,7 +37,9 @@ import org.springframework.web.bind.annotation.PathVariable;
|
|||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/test")
|
||||
|
@ -56,12 +60,28 @@ public class TestController {
|
|||
this.scenarioEngine = scenarioEngine;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/prepare/{fileName}", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public String prepare(@RequestParam MultipartFile file,
|
||||
@PathVariable String fileName) {
|
||||
RunScenarioResultModel result = new RunScenarioResultModel();
|
||||
try {
|
||||
File receiveFile = new File("Upload"
|
||||
+ System.getProperty("file.separator") + fileName);
|
||||
file.transferTo(receiveFile);
|
||||
result.setRunId(UUID.randomUUID());
|
||||
return "It's ok!";
|
||||
} catch (IOException e) {
|
||||
logger.error("/prepare/fileName", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/run", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public RunScenarioResultModel run(
|
||||
@RequestBody RunScenarioModel runScenarioModel)
|
||||
throws UnknownHostException {
|
||||
// Scenario scenario = extractScenario(runScenarioModel);
|
||||
Scenario scenario = Scenario.scenarioBuilder(runScenarioModel);
|
||||
UUID runId = UUID.randomUUID();
|
||||
System.out.println(runScenarioModel.getPoolSize());
|
||||
|
|
|
@ -1,57 +1,48 @@
|
|||
package org.bench4q.agent.parameterization.impl;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Para_Table {
|
||||
|
||||
public int state = 0;// 1 sequence 2 random
|
||||
public class Table
|
||||
{
|
||||
private final String source;
|
||||
|
||||
public Table()
|
||||
{
|
||||
source =
|
||||
}
|
||||
public List<TableRow> rows = new ArrayList<TableRow>();
|
||||
|
||||
public int getTime= 0;
|
||||
public boolean add(TableRow r)
|
||||
{
|
||||
return rows.add(r);
|
||||
}
|
||||
public TableRow pop()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class TableRow
|
||||
{
|
||||
List<String> cells = new ArrayList<String>();
|
||||
}
|
||||
public String getTableColumnValue(UUID id, Map<String, Object> objCache,
|
||||
String source, String sourceValue, String firstRow, String nextRow,
|
||||
String splitChar, String lineChar) {
|
||||
if(source == "file")
|
||||
{
|
||||
try {
|
||||
File file = new File(sourceValue);
|
||||
BufferedReader reader = new BufferedReader(new FileReader(file));
|
||||
//reader.
|
||||
} catch (FileNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
// public int state = 0;// 1 sequence 2 random
|
||||
// public class Table
|
||||
// {
|
||||
// private final String source;
|
||||
//
|
||||
// public Table()
|
||||
// {
|
||||
// source =
|
||||
// }
|
||||
// public List<TableRow> rows = new ArrayList<TableRow>();
|
||||
//
|
||||
// public int getTime= 0;
|
||||
// public boolean add(TableRow r)
|
||||
// {
|
||||
// return rows.add(r);
|
||||
// }
|
||||
// public TableRow pop()
|
||||
// {
|
||||
//
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public class TableRow
|
||||
// {
|
||||
// List<String> cells = new ArrayList<String>();
|
||||
// }
|
||||
// public String getTableColumnValue(UUID id, Map<String, Object> objCache,
|
||||
// String source, String sourceValue, String firstRow, String nextRow,
|
||||
// String splitChar, String lineChar) {
|
||||
// if(source == "file")
|
||||
// {
|
||||
// try {
|
||||
// File file = new File(sourceValue);
|
||||
// BufferedReader reader = new BufferedReader(new FileReader(file));
|
||||
// //reader.
|
||||
// } catch (FileNotFoundException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<root>
|
||||
<property name= "source" type="option">
|
||||
<value>file</value>
|
||||
<value>input</value>
|
||||
</property>
|
||||
<property name="sourceValue" type="string">
|
||||
</property>
|
||||
<property name="firstRow" type="integer">
|
||||
</property>
|
||||
<property name="nextRow" type="option">
|
||||
<value>sequence</value>
|
||||
<value>random</value>
|
||||
</property>
|
||||
<property name="splitChar" type="char">
|
||||
</property>
|
||||
<property name="lineChar" type="char">
|
||||
</property>
|
||||
<property name="source" type="option">
|
||||
<value>file</value>
|
||||
<value>input</value>
|
||||
</property>
|
||||
<property name="sourceValue" type="string">
|
||||
</property>
|
||||
<property name="firstRow" type="integer">
|
||||
</property>
|
||||
<property name="nextRow" type="option">
|
||||
<value>sequence</value>
|
||||
<value>random</value>
|
||||
</property>
|
||||
<property name="splitChar" type="char">
|
||||
</property>
|
||||
<property name="lineChar" type="char">
|
||||
</property>
|
||||
</root>
|
||||
|
|
|
@ -1,10 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:mvc="http://www.springframework.org/schema/mvc"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
|
||||
<context:component-scan base-package="org.bench4q" />
|
||||
<mvc:annotation-driven />
|
||||
</beans>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:mvc="http://www.springframework.org/schema/mvc"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
|
||||
<context:component-scan base-package="org.bench4q" />
|
||||
<mvc:annotation-driven />
|
||||
|
||||
|
||||
<bean id="multipartResolver"
|
||||
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
|
||||
<property name="maxUploadSize" value="5000000" />
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
|
|
@ -1,276 +0,0 @@
|
|||
package Communication;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class HttpRequester {
|
||||
private String defaultContentEncoding;
|
||||
|
||||
public HttpRequester() {
|
||||
this.setDefaultContentEncoding(Charset.defaultCharset().name());
|
||||
}
|
||||
|
||||
public String getDefaultContentEncoding() {
|
||||
return defaultContentEncoding;
|
||||
}
|
||||
|
||||
public void setDefaultContentEncoding(String defaultContentEncoding) {
|
||||
this.defaultContentEncoding = defaultContentEncoding;
|
||||
}
|
||||
|
||||
public HttpResponse sendPost(String urlString, Map<String, String> params,
|
||||
Map<String, String> properties) throws IOException {
|
||||
return this.send(urlString, "POST", params, "", properties);
|
||||
}
|
||||
|
||||
public HttpResponse sendPostXml(String urlString, String contentString,
|
||||
Map<String, String> properties) throws IOException {
|
||||
if (properties == null) {
|
||||
properties = new HashMap<String, String>();
|
||||
}
|
||||
properties.put("Content-Type", "application/xml");
|
||||
return this.send(urlString, "POST", null, contentString, properties);
|
||||
}
|
||||
|
||||
public HttpResponse sendGet(String urlString, Map<String, String> params,
|
||||
Map<String, String> properties) throws IOException {
|
||||
return this.send(urlString, "GET", params, "", properties);
|
||||
}
|
||||
|
||||
private HttpResponse send(String urlString, String method,
|
||||
Map<String, String> parameters, String Content,
|
||||
Map<String, String> propertys) throws IOException {
|
||||
HttpURLConnection urlConnection = null;
|
||||
|
||||
if (method.equalsIgnoreCase("GET") && parameters != null) {
|
||||
StringBuffer param = new StringBuffer();
|
||||
int i = 0;
|
||||
for (String key : parameters.keySet()) {
|
||||
if (i == 0)
|
||||
param.append("?");
|
||||
else
|
||||
param.append("&");
|
||||
String encodedValue = URLEncoder.encode(parameters.get(key),
|
||||
"UTF-8");
|
||||
param.append(key).append("=").append(encodedValue);
|
||||
i++;
|
||||
}
|
||||
urlString += param;
|
||||
}
|
||||
|
||||
if (!urlString.startsWith("http://")) {
|
||||
urlString = "http://" + urlString;
|
||||
}
|
||||
URL url = new URL(urlString);
|
||||
urlConnection = (HttpURLConnection) url.openConnection();
|
||||
|
||||
urlConnection.setRequestMethod(method);
|
||||
urlConnection.setDoOutput(true);
|
||||
urlConnection.setDoInput(true);
|
||||
urlConnection.setUseCaches(false);
|
||||
|
||||
if (propertys != null)
|
||||
for (String key : propertys.keySet()) {
|
||||
urlConnection.addRequestProperty(key, propertys.get(key));
|
||||
}
|
||||
|
||||
if (method.equalsIgnoreCase("POST") && parameters != null) {
|
||||
StringBuffer param = new StringBuffer();
|
||||
for (String key : parameters.keySet()) {
|
||||
param.append("&");
|
||||
String encodedValueString = URLEncoder.encode(
|
||||
parameters.get(key), "UTF-8");
|
||||
param.append(key).append("=").append(encodedValueString);
|
||||
}
|
||||
urlConnection.getOutputStream().write(param.toString().getBytes());
|
||||
urlConnection.getOutputStream().flush();
|
||||
urlConnection.getOutputStream().close();
|
||||
} else if (method.equalsIgnoreCase("POST") && !Content.isEmpty()) {
|
||||
urlConnection.getOutputStream().write(Content.getBytes());
|
||||
urlConnection.getOutputStream().flush();
|
||||
urlConnection.getOutputStream().close();
|
||||
}
|
||||
return this.makeContent(urlString, urlConnection);
|
||||
}
|
||||
|
||||
private HttpResponse makeContent(String urlString,
|
||||
HttpURLConnection urlConnection) {
|
||||
HttpResponse httpResponser = new HttpResponse();
|
||||
try {
|
||||
InputStream in = urlConnection.getInputStream();
|
||||
BufferedReader bufferedReader = new BufferedReader(
|
||||
new InputStreamReader(in));
|
||||
httpResponser.contentCollection = new Vector<String>();
|
||||
StringBuffer temp = new StringBuffer();
|
||||
String line = bufferedReader.readLine();
|
||||
while (line != null) {
|
||||
httpResponser.contentCollection.add(line);
|
||||
temp.append(line).append("\r\n");
|
||||
line = bufferedReader.readLine();
|
||||
}
|
||||
bufferedReader.close();
|
||||
|
||||
String ecod = urlConnection.getContentEncoding();
|
||||
if (ecod == null)
|
||||
ecod = this.defaultContentEncoding;
|
||||
|
||||
httpResponser.setUrlString(urlString);
|
||||
httpResponser.setDefaultPort(urlConnection.getURL()
|
||||
.getDefaultPort());
|
||||
httpResponser.setPort(urlConnection.getURL().getPort());
|
||||
httpResponser.setProtocol(urlConnection.getURL().getProtocol());
|
||||
|
||||
httpResponser.setContent(new String(temp.toString().getBytes(),
|
||||
ecod));
|
||||
httpResponser.setContentEncoding(ecod);
|
||||
httpResponser.setCode(urlConnection.getResponseCode());
|
||||
httpResponser.setMessage(urlConnection.getResponseMessage());
|
||||
httpResponser.setContentType(urlConnection.getContentType());
|
||||
httpResponser.setConnectTimeout(urlConnection.getConnectTimeout());
|
||||
httpResponser.setReadTimeout(urlConnection.getReadTimeout());
|
||||
return httpResponser;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} finally {
|
||||
if (urlConnection != null)
|
||||
urlConnection.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
public class HttpResponse {
|
||||
|
||||
String urlString;
|
||||
|
||||
int defaultPort;
|
||||
|
||||
int port;
|
||||
|
||||
String protocol;
|
||||
|
||||
String contentEncoding;
|
||||
|
||||
String content;
|
||||
|
||||
String contentType;
|
||||
|
||||
int code;
|
||||
|
||||
String message;
|
||||
|
||||
int connectTimeout;
|
||||
|
||||
int readTimeout;
|
||||
|
||||
Vector<String> contentCollection;
|
||||
|
||||
public String getUrlString() {
|
||||
return urlString;
|
||||
}
|
||||
|
||||
public void setUrlString(String urlString) {
|
||||
this.urlString = urlString;
|
||||
}
|
||||
|
||||
public int getDefaultPort() {
|
||||
return defaultPort;
|
||||
}
|
||||
|
||||
public void setDefaultPort(int defaultPort) {
|
||||
this.defaultPort = defaultPort;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public String getProtocol() {
|
||||
return protocol;
|
||||
}
|
||||
|
||||
public void setProtocol(String protocol) {
|
||||
this.protocol = protocol;
|
||||
}
|
||||
|
||||
public String getContentEncoding() {
|
||||
return contentEncoding;
|
||||
}
|
||||
|
||||
public void setContentEncoding(String contentEncoding) {
|
||||
this.contentEncoding = contentEncoding;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
return contentType;
|
||||
}
|
||||
|
||||
public void setContentType(String contentType) {
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public int getConnectTimeout() {
|
||||
return connectTimeout;
|
||||
}
|
||||
|
||||
public void setConnectTimeout(int connectTimeout) {
|
||||
this.connectTimeout = connectTimeout;
|
||||
}
|
||||
|
||||
public int getReadTimeout() {
|
||||
return readTimeout;
|
||||
}
|
||||
|
||||
public void setReadTimeout(int readTimeout) {
|
||||
this.readTimeout = readTimeout;
|
||||
}
|
||||
|
||||
public Vector<String> getContentCollection() {
|
||||
return contentCollection;
|
||||
}
|
||||
|
||||
public void setContentCollection(Vector<String> contentCollection) {
|
||||
this.contentCollection = contentCollection;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
package org.bench4q.agent.test;
|
||||
|
||||
public class TestControllerTest {
|
||||
|
||||
}
|
|
@ -13,6 +13,8 @@ import javax.xml.bind.JAXBException;
|
|||
import javax.xml.bind.Unmarshaller;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bench4q.share.communication.HttpRequester;
|
||||
import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.agent.BehaviorBriefModel;
|
||||
import org.bench4q.share.models.agent.RunScenarioModel;
|
||||
|
@ -22,9 +24,6 @@ import org.bench4q.share.models.agent.statistics.AgentBehaviorsBriefModel;
|
|||
import org.bench4q.share.models.agent.statistics.AgentPageBriefModel;
|
||||
import org.junit.Test;
|
||||
|
||||
import Communication.HttpRequester;
|
||||
import Communication.HttpRequester.HttpResponse;
|
||||
|
||||
public class TestWithScriptFile {
|
||||
private HttpRequester httpRequester;
|
||||
private String url = "http://localhost:6565/test";
|
||||
|
@ -176,6 +175,18 @@ public class TestWithScriptFile {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrepare() throws IOException {
|
||||
HttpResponse httpResponse = this.getHttpRequester().postMultiFile(
|
||||
url + "/prepare/" + "ready.txt",
|
||||
"Scripts" + System.getProperty("file.separator")
|
||||
+ "forGoodRecord.xml");
|
||||
assertNotNull(httpResponse);
|
||||
assertNotNull(httpResponse.getContent());
|
||||
assertEquals(200, httpResponse.getCode());
|
||||
System.out.println(httpResponse.getContent());
|
||||
}
|
||||
|
||||
private void pageBrief(int i) throws IOException, JAXBException {
|
||||
try {
|
||||
HttpResponse httpResponse = this.getHttpRequester().sendGet(
|
||||
|
|
Loading…
Reference in New Issue