Skip to content

Commit

Permalink
download handle
Browse files Browse the repository at this point in the history
Signed-off-by: wmqwxb <[email protected]>
  • Loading branch information
wmqwxb committed Nov 2, 2023
1 parent f5b73d0 commit 0518230
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -388,24 +388,6 @@ public ResponseResult getDagDependencies(String param) {
JSONObject data = resultObject.getJSONObject(Dict.DATA);
JSONObject component_need_run = data.getJSONObject(Dict.COMPONENT_NEED_RUN);
ArrayList<Map<String, Object>> componentList = new ArrayList<>();

JSONObject dependencies = data.getJSONObject(Dict.COMPONENT_DEPENDENCIES);
Set<String> dependencyKeys = dependencies.keySet();
for (String componentName: dependencyKeys) {
JSONArray newArray = new JSONArray();
JSONArray array = dependencies.getJSONArray(componentName);

for (int i = 0;i<array.size();i++) {
JSONObject dep = array.getJSONObject(i);
String compName = dep.getString(Dict.COMPONENT_NAME);
if (compName == null || compName.isEmpty()) {
continue;
}
newArray.add(dep);
}
dependencies.put(componentName,newArray);
}

Set<String> keys = component_need_run.keySet();
for (Object o : keys) {
HashMap<String, Object> component = new HashMap<>();
Expand Down Expand Up @@ -450,6 +432,12 @@ public ResponseResult getModel(@Valid @RequestBody ComponentQueryDTO componentQu
return new ResponseResult<>(ErrorCode.FATEFLOW_ERROR_CONNECTION);
}

JSONObject resultObject = JSON.parseObject(result);
Integer retCode = resultObject.getInteger(Dict.CODE);
if (retCode != 0) {
return ResponseUtil.buildResponse(null, null);
}

return ResponseUtil.buildResponse(result, null);
}

Expand Down
78 changes: 22 additions & 56 deletions src/main/java/org/fedai/fate/board/services/JobManagerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -283,81 +283,47 @@ public String getComponentCommand(ComponentQueryDTO componentQueryDTO) {

public ResponseResult download(DownloadQO downloadQO, HttpServletResponse response) {

//check input parameters
String jobId = downloadQO.getJobId();
String role = downloadQO.getRole();
String type = downloadQO.getType();
String partyId = downloadQO.getPartyId();

if (StringUtils.isEmpty(jobId)) {
log.error("parameter null:jobId");
return new ResponseResult(ErrorCode.ERROR_PARAMETER);
}
if (StringUtils.isEmpty(role)) {
log.error("parameter null:role");
return new ResponseResult(ErrorCode.ERROR_PARAMETER);
}
if (StringUtils.isEmpty(type)) {
log.error("parameter null:type");
return new ResponseResult(ErrorCode.ERROR_PARAMETER);
}

if (!LogFileService.checkParameters("^[0-9a-zA-Z\\-_]+$", jobId, role, type)) {
log.error("parameter error: illegal characters in role or jobId or type");
return new ResponseResult(ErrorCode.ERROR_PARAMETER);
}
if (StringUtils.isEmpty(partyId)) {
log.error("parameter null:partyId");
return new ResponseResult(ErrorCode.ERROR_PARAMETER);
}


Map<String, Object> query = new HashMap<>();
query.put("job_id", jobId);
HashMap<String, Object> jobParams = Maps.newHashMap();
jobParams.put(Dict.JOBID, jobId);
jobParams.put((Dict.ROLE), role);
jobParams.put(Dict.PARTY_ID, partyId);
String result = null;
try {
result = flowFeign.post(Dict.URL_CONFIG_CAT, JSON.toJSONString(query));
result = flowFeign.get(Dict.URL_JOB_DATAVIEW, jobParams);
} catch (Exception e) {
logger.error("connect fateflow error:", e);
//todo
// throw new Exception(ErrorCode.FATEFLOW_ERROR_CONNECTION.getMsg());
// return new ResponseResult<>(ErrorCode.FATEFLOW_ERROR_CONNECTION);
return new ResponseResult<>(ErrorCode.FATEFLOW_ERROR_CONNECTION);
}
JSONObject resultObject = JSON.parseObject(result);
JSONObject dataObject = resultObject.getJSONObject(Dict.DATA);
JSONObject dslObject = dataObject.getJSONObject("dsl");
JSONObject runtime_confObject = dataObject.getJSONObject("runtime_conf");
JSONObject responseObject;


String fileOutputName = "";
if ((result == null) || (0 == result.trim().length())) {
return new ResponseResult<>(ErrorCode.FATEFLOW_ERROR_NULL_RESULT);
}

if ("dsl".equals(type)) {
fileOutputName = "job_dsl_" + jobId + ".json";
responseObject = dslObject;
JSONObject resultObject = JSON.parseObject(result);
Integer retcode = resultObject.getInteger(Dict.CODE);
if (retcode == null) {
return new ResponseResult<>(ErrorCode.FATEFLOW_ERROR_WRONG_RESULT);
}
JSONObject dagInfo;
if (retcode == 0) {
JSONArray jsonArray = resultObject.getJSONArray(Dict.DATA);
JSONObject data = jsonArray == null ? null : (JSONObject)jsonArray.get(0);
dagInfo = data.getJSONObject("dag");
} else {
if ("guest".equals(role) || "local".equals(role)) {
fileOutputName = "runtime_config_" + jobId + ".json";
responseObject = runtime_confObject;
} else if ("host".equals(role)) {
fileOutputName = "runtime_config_" + jobId + ".json";
responseObject = getHostConfig(runtime_confObject);
} else {
log.error("download error: role:{} doesn't support", role);
return new ResponseResult(ErrorCode.ERROR_PARAMETER);
}

return new ResponseResult<>(retcode, resultObject.getString(Dict.RETMSG));
}


String fileOutputName = jobId + ".yaml";
response.setBufferSize(1024 * 1000);
response.setContentType("application/force-download");
response.setHeader("Content-Disposition", "attachment;fileName=" + fileOutputName);
try {
OutputStream os = response.getOutputStream();
os.write(JSON.toJSONBytes(responseObject, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteDateUseDateFormat));
// os.flush();
// os.close();
os.write(JSON.toJSONBytes(dagInfo, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteDateUseDateFormat));
log.info("download success,file :{}", fileOutputName);
} catch (Exception e) {
log.error("download failed", e);
Expand Down

0 comments on commit 0518230

Please sign in to comment.