2016-06-29 00:11:01 -07:00
|
|
|
/**
|
|
|
|
* Copyright 2015 LinkedIn Corp. All rights reserved.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
*/
|
2016-05-06 11:29:22 -07:00
|
|
|
package controllers.api.v1;
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
|
import dao.ScriptFinderDAO;
|
2016-12-12 09:42:10 -08:00
|
|
|
import java.net.URLDecoder;
|
2016-05-06 11:29:22 -07:00
|
|
|
import play.libs.Json;
|
|
|
|
import play.mvc.Controller;
|
|
|
|
import play.mvc.Result;
|
|
|
|
import play.Logger;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
|
|
public class ScriptFinder extends Controller
|
|
|
|
{
|
|
|
|
|
|
|
|
public static Result getAllScriptTypes()
|
|
|
|
{
|
|
|
|
ObjectNode result = Json.newObject();
|
|
|
|
|
|
|
|
result.put("status", "ok");
|
|
|
|
result.set("scriptTypes", Json.toJson(ScriptFinderDAO.getAllScriptTypes()));
|
|
|
|
return ok(result);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Result getScripts()
|
|
|
|
{
|
|
|
|
ObjectNode result = Json.newObject();
|
|
|
|
|
|
|
|
int page = 1;
|
|
|
|
String pageStr = request().getQueryString("page");
|
|
|
|
if (StringUtils.isBlank(pageStr))
|
|
|
|
{
|
|
|
|
page = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
page = Integer.parseInt(pageStr);
|
|
|
|
}
|
|
|
|
catch(NumberFormatException e)
|
|
|
|
{
|
|
|
|
Logger.error("ScriptFinder Controller getPagedScripts wrong page parameter. Error message: " +
|
|
|
|
e.getMessage());
|
|
|
|
page = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int size = 10;
|
|
|
|
String sizeStr = request().getQueryString("size");
|
|
|
|
if (StringUtils.isBlank(sizeStr))
|
|
|
|
{
|
|
|
|
size = 10;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
size = Integer.parseInt(sizeStr);
|
|
|
|
}
|
|
|
|
catch(NumberFormatException e)
|
|
|
|
{
|
|
|
|
Logger.error("ScriptFinder Controller getPagedScripts wrong size parameter. Error message: " +
|
|
|
|
e.getMessage());
|
|
|
|
size = 10;
|
|
|
|
}
|
|
|
|
}
|
2016-12-12 09:42:10 -08:00
|
|
|
|
2016-05-06 11:29:22 -07:00
|
|
|
String filterOptStr = request().getQueryString("query");
|
|
|
|
JsonNode filterOpt = null;
|
|
|
|
try
|
|
|
|
{
|
2016-12-12 09:42:10 -08:00
|
|
|
String filterOptStrDecode = URLDecoder.decode(filterOptStr, "UTF-8");
|
|
|
|
filterOpt = Json.parse(filterOptStrDecode);
|
2016-05-06 11:29:22 -07:00
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2016-12-12 09:42:10 -08:00
|
|
|
Logger.error("ScriptFinder Controller getScripts query filterOpt wrong JSON format. Error message: " +
|
2016-05-06 11:29:22 -07:00
|
|
|
e.getMessage());
|
|
|
|
filterOpt = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
result.put("status", "ok");
|
|
|
|
result.set("data", ScriptFinderDAO.getPagedScripts(filterOpt, page, size));
|
|
|
|
return ok(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Result getScriptRuntimeByJobID(int applicationID, int jobID)
|
|
|
|
{
|
|
|
|
ObjectNode result = Json.newObject();
|
|
|
|
|
|
|
|
int attemptNumber = 0;
|
|
|
|
String attemptStr = request().getQueryString("attempt_number");
|
|
|
|
if (StringUtils.isBlank(attemptStr))
|
|
|
|
{
|
|
|
|
attemptNumber = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
attemptNumber = Integer.parseInt(attemptStr);
|
|
|
|
}
|
|
|
|
catch(NumberFormatException e)
|
|
|
|
{
|
|
|
|
Logger.error("ScriptFinder Controller getPagedScripts wrong page parameter. Error message: " +
|
|
|
|
e.getMessage());
|
|
|
|
attemptNumber = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result.put("status", "ok");
|
|
|
|
result.set("data", Json.toJson(ScriptFinderDAO.getPagedScriptRuntime(applicationID, jobID)));
|
|
|
|
return ok(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Result getScriptLineageByJobID(int applicationID, int jobID)
|
|
|
|
{
|
|
|
|
ObjectNode result = Json.newObject();
|
|
|
|
|
|
|
|
int attemptNumber = 0;
|
|
|
|
String attemptStr = request().getQueryString("attempt_number");
|
|
|
|
if (StringUtils.isBlank(attemptStr))
|
|
|
|
{
|
|
|
|
attemptNumber = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
attemptNumber = Integer.parseInt(attemptStr);
|
|
|
|
}
|
|
|
|
catch(NumberFormatException e)
|
|
|
|
{
|
|
|
|
Logger.error("ScriptFinder Controller getPagedScripts wrong page parameter. Error message: " +
|
|
|
|
e.getMessage());
|
|
|
|
attemptNumber = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result.put("status", "ok");
|
|
|
|
result.set("data", Json.toJson(ScriptFinderDAO.getScriptLineage(applicationID, jobID)));
|
|
|
|
return ok(result);
|
|
|
|
}
|
|
|
|
}
|