Commit 7aa8a33d authored by Deepak Nadig's avatar Deepak Nadig

POST templates and REST updates.

parent d298d867
......@@ -14,6 +14,7 @@ public class GridFtpConnectionString {
private IpAddress srchost, dsthost;
private PortNumber srcport, dstport;
private String username, event, filename;
private String enableDebug;
public GridFtpConnectionString(String username,
IpAddress srchost,
......@@ -31,6 +32,10 @@ public class GridFtpConnectionString {
this.filename = filename;
}
public GridFtpConnectionString(String enableDebug) {
this.enableDebug = enableDebug;
}
public String getUsername() {
return username;
}
......@@ -87,6 +92,21 @@ public class GridFtpConnectionString {
this.filename = filename;
}
public void logStats(GridFtpConnectionString connectionString) {
public String getEnableDebug() {
return enableDebug;
}
public void logStats() {
StringBuilder sb = new StringBuilder();
sb.append(this.username).append(" ")
.append(this.srchost)
.append(":").append(this.srcport.toString())
.append(" -> ").append(this.dsthost.toString())
.append(":").append(this.dstport.toString())
.append(" ").append(this.event)
.append(" ").append(this.filename);
log.info(sb.toString());
}
}
......@@ -63,19 +63,58 @@ public class SnagWebResource extends AbstractWebResource {
*
* @return status of the request - CREATED if the JSON is correct,
* BAD_REQUEST if the JSON is invalid
*
* @onos.rsModel post-transfers
*/
@POST
@Path("tcp")
@Path("transfers")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response postedFlows(InputStream stream) throws IOException {
connectionString = jsonToConnectionInfo(stream);
connectionString.logStats(connectionString);
connectionString.logStats();
return Response.ok(root).build();
}
/**
* Debug mode for GridFTP transfer information
* Information only available to the server logs
* <br>
* Criteria description:
*
* @return server debug for transfer connections - CREATED if the JSON is correct,
* BAD_REQUEST if the JSON is invalid
*
* @onos.rsModel post-enable-debug
*/
@POST
@Path("debug")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response enableDebug(InputStream stream) throws IOException {
JsonNode node;
try {
node = mapper().readTree(stream);
} catch (IOException e) {
throw new IllegalArgumentException("Unable to parse Debug POST request.", e);
}
String isDebug = node.path("enable").asText(null);
if (isDebug != null && isDebug.equals("true")) {
connectionString.logStats();
}
else {
throw new IllegalArgumentException("Arguments cannot be null");
}
return Response.ok(root).build();
}
private GridFtpConnectionString jsonToConnectionInfo(InputStream stream) {
JsonNode node;
try {
......
{
"type": "object",
"required": [
"enable"
],
"properties": {
"enable": {
"type": "string",
"example": "true"
}
}
}
\ No newline at end of file
{
"type": "object",
"required": [
"username","srchost","dsthost","srcport","dstport","event","filename"
],
"properties": {
"username": {
"type": "string",
"example": "testuser"
},
"srchost": {
"type": "string",
"example": "10.0.0.1"
},
"dsthost": {
"type": "string",
"example": "20.0.0.1"
},
"srcport": {
"type": "string",
"example": "11111"
},
"dstport": {
"type": "string",
"example": "22222"
},
"event": {
"type": "string",
"example": "STARTUP"
},
"filename": {
"type": "string",
"example": "somefile.ext"
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment