|
@@ -10,11 +10,13 @@ import io.kubernetes.client.openapi.apis.CoreV1Api;
|
|
|
import io.kubernetes.client.openapi.models.V1Container;
|
|
|
import io.kubernetes.client.openapi.models.V1EnvVar;
|
|
|
import io.kubernetes.client.openapi.models.V1ObjectMeta;
|
|
|
+import io.minio.PutObjectOptions;
|
|
|
import io.minio.errors.*;
|
|
|
import io.renren.common.utils.*;
|
|
|
|
|
|
import io.renren.modules.sys.entity.VisiWorkflowEntity;
|
|
|
import io.renren.modules.sys.service.VisiWorkflowService;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
@@ -1410,422 +1412,175 @@ public class VisiWorkflowController extends AbstractController {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取输入csv表头信息
|
|
|
+ *
|
|
|
+ * @param params workflow名称
|
|
|
+ * @return workflow执行状态
|
|
|
+ *
|
|
|
+ */
|
|
|
+ @RequestMapping("/getCSVHeader")
|
|
|
+ public R getCSVHeaderInfo(@RequestParam Map<String, Object> params) throws IOException, InvalidResponseException, InvalidKeyException, NoSuchAlgorithmException, ErrorResponseException, XmlParserException, InvalidBucketNameException, InsufficientDataException, InternalException {
|
|
|
+ Object filename = params.get("filename");//工作流名称
|
|
|
+ Object bucketname = params.get("bucketname");//工作流名称
|
|
|
+ System.out.println(bucketname.toString());
|
|
|
+ System.out.println(filename.toString());
|
|
|
+ InputStream fileInputStream = null;
|
|
|
+ if(bucketname.toString().equals("visiarguartifact")){
|
|
|
+ fileInputStream = MinIoUtils.getFileInputStream(bucketname.toString(), "argoworkflow" + "/" + filename.toString());
|
|
|
|
|
|
- //应用JSONObject接收数据
|
|
|
+ }else{
|
|
|
+ fileInputStream = MinIoUtils.getFileInputStream(bucketname.toString(), filename.toString()+".csv");
|
|
|
+ }
|
|
|
+
|
|
|
+ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fileInputStream));
|
|
|
+
|
|
|
+
|
|
|
+ String line = null;
|
|
|
+ int index=0;//总行数
|
|
|
+ int col = 0;//列
|
|
|
+ //表头
|
|
|
+ String[] headerinfo = null;
|
|
|
+ //前五行数据
|
|
|
+ List<String[]> allString = new ArrayList<>();
|
|
|
+
|
|
|
+ //读取每行,直到为空
|
|
|
+ while((line=bufferedReader.readLine())!=null){
|
|
|
+ index++;
|
|
|
+ if(index==1){
|
|
|
+ //读取首行
|
|
|
+ headerinfo = line.split(",");//CSV格式文件为逗号分隔符文件,这里根据逗号切分
|
|
|
+ col = headerinfo.length;
|
|
|
+ for (String s : headerinfo) {
|
|
|
+ System.out.println(s);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ allString.add(line.split(","));
|
|
|
+ }
|
|
|
+
|
|
|
+// else if(index<=5){ //读取五行
|
|
|
+// allString.add(line.split(","));
|
|
|
+// }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return R.ok().put("index", index).put("col",col).put("headerinfo",headerinfo).put("allstring",allString);
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
- @RequestMapping("/submit") public R Submit(@RequestBody JSONObject jsonObject){
|
|
|
- //连接argo
|
|
|
- //创建Workflowtemplate
|
|
|
-
|
|
|
- ApiClient defaultClient = Configuration.getDefaultApiClient();
|
|
|
- defaultClient.setBasePath("http://192.168.222.100:32639");
|
|
|
-
|
|
|
- // WorkflowTemplateServiceApi apiInstance = new WorkflowTemplateServiceApi(defaultClient);
|
|
|
- WorkflowServiceApi apiInstance = new WorkflowServiceApi(defaultClient);
|
|
|
- // String namespace = "default"; // String |
|
|
|
- String namespace = "argo"; // String |
|
|
|
- // WorkflowTemplateCreateRequest body = new WorkflowTemplateCreateRequest(); // WorkflowTemplateCreateRequest |
|
|
|
-
|
|
|
-
|
|
|
- //2.1createOptions CreateOptions [optional]
|
|
|
- //2.2namespace String [optional]
|
|
|
- body.setNamespace(namespace);
|
|
|
- //2.3template WorkflowTemplate [optional]
|
|
|
- WorkflowTemplate workflowTemplate1 = new WorkflowTemplate();
|
|
|
-
|
|
|
- //2.3.1 apiVersion
|
|
|
- workflowTemplate1.apiVersion("argoproj.io/v1alpha1");
|
|
|
- //2.3.2 kind
|
|
|
- //workflowTemplate1.kind("Workflow");
|
|
|
- workflowTemplate1.setKind("WorkflowTemplate");
|
|
|
- //2.3.3 Metadata
|
|
|
- V1ObjectMeta v1ObjectMeta = new V1ObjectMeta();
|
|
|
- //2.3.3.1
|
|
|
- //20210907 zhang 每一个流程自行设置 英文名称 暂时先固定
|
|
|
- v1ObjectMeta.setGenerateName("hello-world-parameters-");//此处name是设置一个然后每次随机添加后缀,创建完返回名称
|
|
|
-
|
|
|
-
|
|
|
- //2.3.3.2
|
|
|
- v1ObjectMeta.setNamespace(namespace);
|
|
|
- //workflowTemplate1.metadata(v1ObjectMeta);
|
|
|
- workflowTemplate1.setMetadata(v1ObjectMeta);
|
|
|
-
|
|
|
- //2.3.4 spec
|
|
|
- WorkflowTemplateSpec workflowTemplateSpec = new WorkflowTemplateSpec();
|
|
|
- workflowTemplateSpec.setEntrypoint("dagtest");//入口位置,设置Template类型为DAG的模板名称 自拟/固定?
|
|
|
- //参数
|
|
|
- // Arguments arguments = new Arguments();
|
|
|
- // Parameter parameter = new Parameter();
|
|
|
- // parameter.setName("message");
|
|
|
- // parameter.setValue("hello");
|
|
|
- // arguments.addParametersItem(parameter);
|
|
|
- // workflowTemplateSpec.setArguments(arguments);
|
|
|
-
|
|
|
- //各个Template
|
|
|
- List<Template> templateslist = new LinkedList<Template>();
|
|
|
- Template dagtemp = new Template();
|
|
|
- dagtemp.setName("dagtest"); //是否固定?与 入口位置相同
|
|
|
- DAGTemplate dagTemplate = new DAGTemplate();
|
|
|
-
|
|
|
- List<DAGTask> taskslist = new LinkedList<DAGTask>();
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- //20210721
|
|
|
- //获取前端流程数据
|
|
|
- // JSONObject cells = jsonObject.getJSONObject("cells");
|
|
|
- //获取各个cell数据
|
|
|
- JSONArray cellsarray = jsonObject.getJSONArray("cells");
|
|
|
- System.out.println(cellsarray);
|
|
|
-
|
|
|
-
|
|
|
- //节点id 对应相应的dagtask name
|
|
|
- Map<String,String> idtempname= new HashMap<String,String>();
|
|
|
- for(int i=0;i<cellsarray.size();i++){
|
|
|
- //判断若为rect,则表示节点,存储template数据,创建新的Template,并加入DAGTAsk中
|
|
|
- if(cellsarray.getJSONObject(i).getString("shape").equals("template-node")){
|
|
|
-
|
|
|
- String rectid = cellsarray.getJSONObject(i).getString("id");
|
|
|
-
|
|
|
-
|
|
|
- //获取数据
|
|
|
- JSONObject rectdata = cellsarray.getJSONObject(i).getJSONObject("data");//获取你想获取的内容
|
|
|
- //templateName --存放于template中
|
|
|
- String templateName = rectdata.getString("templateName");
|
|
|
- //templateImage --存放于 V1Container 中
|
|
|
- String templateImage = rectdata.getString("templateImage");
|
|
|
- //templateCommand List<String> command --存放于 V1Container 中
|
|
|
- List<String> command = new LinkedList<String>();
|
|
|
- JSONObject templateCommand = rectdata.getJSONObject("templateCommand");
|
|
|
- //然后通过循环遍历出的key值
|
|
|
- for(Map.Entry<String, Object> entry : templateCommand.entrySet()) {
|
|
|
- command.add(entry.getValue().toString());
|
|
|
- }
|
|
|
-
|
|
|
- //templateArgs --存放于 V1Container 中
|
|
|
- List<String> args = new LinkedList<String>();
|
|
|
- JSONObject templateargs = rectdata.getJSONObject("templateArgs");
|
|
|
- //然后通过循环遍历出的key值
|
|
|
- for(Map.Entry<String, Object> entry : templateargs.entrySet()) {
|
|
|
- String value = entry.getValue().toString();
|
|
|
- args.add(entry.getValue().toString());
|
|
|
- }
|
|
|
-
|
|
|
- //参数 --类型暂未确定
|
|
|
- //inputsparameters --存放于template中
|
|
|
- List<Parameter> inputsparalist = new LinkedList<Parameter>();
|
|
|
- JSONArray inputsparameters = rectdata.getJSONArray("inputsparameters");
|
|
|
- // List<String> inputsparam = new LinkedList<String>();
|
|
|
- for(int j=0;j<inputsparameters.size();j++){
|
|
|
- String paramname = inputsparameters.getJSONObject(j).getString("name");
|
|
|
- Parameter parameter = new Parameter();
|
|
|
- parameter.setName(paramname);
|
|
|
- inputsparalist.add(parameter);
|
|
|
- // inputparam.add(inputparameters.getJSONObject(j).getString("name"));
|
|
|
- }
|
|
|
-
|
|
|
- //20210915 zhang inputs artifacts
|
|
|
- //inputs artifacts --存放于template中
|
|
|
- List<Artifact> inputsartilist = new LinkedList<Artifact>();
|
|
|
- JSONArray inputsartifacts = rectdata.getJSONArray("inputsartifacts");
|
|
|
- for(int j=0;j<inputsartifacts.size();j++){
|
|
|
- String artiname = inputsartifacts.getJSONObject(j).getString("name");
|
|
|
- String artipath = inputsartifacts.getJSONObject(j).getString("path");
|
|
|
- Artifact artifact = new Artifact();
|
|
|
- artifact.setName(artiname);
|
|
|
- artifact.setPath(artipath);
|
|
|
- inputsartilist.add(artifact);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- Inputs inputs = new Inputs();
|
|
|
- inputs.setParameters(inputsparalist);
|
|
|
- inputs.setArtifacts(inputsartilist);
|
|
|
-
|
|
|
- //20210915 zhang output
|
|
|
- //outputsparameters --存放于template中
|
|
|
- List<Parameter> outputsparalist = new LinkedList<Parameter>();
|
|
|
- JSONArray outputsparameters = rectdata.getJSONArray("outputsparameters");
|
|
|
- for(int j=0;j<outputsparameters.size();j++){
|
|
|
- String outparamname = outputsparameters.getJSONObject(j).getString("name");
|
|
|
- Parameter outparameter = new Parameter();
|
|
|
- outparameter.setName(outparamname);
|
|
|
- outputsparalist.add(outparameter);
|
|
|
- // inputparam.add(inputparameters.getJSONObject(j).getString("name"));
|
|
|
- }
|
|
|
-
|
|
|
- //20210915 zhang outputs artifacts
|
|
|
- //outputs artifacts --存放于template中
|
|
|
- List<Artifact> outputartilist = new LinkedList<Artifact>();
|
|
|
-
|
|
|
- JSONArray outputsartifacts = rectdata.getJSONArray("outputsartifacts");
|
|
|
- for(int j=0;j<outputsartifacts.size();j++){
|
|
|
- String outartiname = outputsartifacts.getJSONObject(j).getString("name");
|
|
|
- String outartipath = outputsartifacts.getJSONObject(j).getString("path");
|
|
|
- Artifact outartifact = new Artifact();
|
|
|
- outartifact.setName(outartiname);
|
|
|
- outartifact.setPath(outartipath);
|
|
|
- outputartilist.add(outartifact);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- Outputs outputs = new Outputs();
|
|
|
- outputs.setParameters(outputsparalist);
|
|
|
- outputs.setArtifacts(outputartilist);
|
|
|
-
|
|
|
-
|
|
|
- //argumentsparameters --存放于DAGTask中
|
|
|
- List<Parameter> argumparalist = new LinkedList<Parameter>();
|
|
|
- JSONArray argumentsparameters = rectdata.getJSONArray("argumentsparameters");
|
|
|
- // List<String> argumentsparam = new LinkedList<String>();
|
|
|
- // List<String> argumentsvalue = new LinkedList<String>();
|
|
|
- for(int j=0;j<argumentsparameters.size();j++){
|
|
|
- String arguparaname = argumentsparameters.getJSONObject(j).getString("name");
|
|
|
- String arguparavalue = argumentsparameters.getJSONObject(j).getString("value");
|
|
|
- //20210909 zhang 需要对arguments的value 值做处理
|
|
|
-
|
|
|
- Parameter argupara = new Parameter();
|
|
|
- argupara.setName(arguparaname);
|
|
|
- argupara.setValue(arguparavalue);
|
|
|
- argumparalist.add(argupara);
|
|
|
- // argumentsparam.add(paremname);
|
|
|
- // argumentsvalue.add(paramvalue);
|
|
|
- }
|
|
|
-
|
|
|
- //20210913 artifacts -------input中也包含
|
|
|
- List<Artifact> artifactlist = new LinkedList<Artifact>();
|
|
|
- JSONArray argumentsartifacts = rectdata.getJSONArray("argumentsartifacts");
|
|
|
- for(int j=0;j<argumentsartifacts.size();j++){
|
|
|
- String arguartiname = argumentsartifacts.getJSONObject(j).getString("name");
|
|
|
- String arguartifrom = argumentsartifacts.getJSONObject(j).getString("valuefrom");
|
|
|
- //20210909 zhang 需要对arguments的value 值做处理
|
|
|
-
|
|
|
- Artifact arguartifact = new Artifact();
|
|
|
- arguartifact.setName(arguartiname);
|
|
|
- arguartifact.setFrom(arguartifrom);
|
|
|
- artifactlist.add(arguartifact);
|
|
|
- }
|
|
|
-
|
|
|
- Arguments arguments = new Arguments();
|
|
|
- arguments.setParameters(argumparalist);
|
|
|
- arguments.setArtifacts(artifactlist);
|
|
|
-
|
|
|
- //通过Rect型节点数据 创建template,将template作为DAGTask添加到List<DAGTask>中,
|
|
|
- Template template = new Template();
|
|
|
- template.setName(templateName);
|
|
|
- template.setInputs(inputs);
|
|
|
- template.setOutputs(outputs);
|
|
|
- //设置template类型为Container
|
|
|
- V1Container containertemp = new V1Container();
|
|
|
- containertemp.setImage(templateImage);
|
|
|
- containertemp.setCommand(command); //List<String> command
|
|
|
- containertemp.args(args); //List<String> args
|
|
|
-
|
|
|
- template.setContainer(containertemp);
|
|
|
- //添加至workflowTemplate的List<Template> templateslist中
|
|
|
- templateslist.add(template);
|
|
|
- //添加至DAG中
|
|
|
- DAGTask dagTask = new DAGTask();
|
|
|
- dagTask.setName(template.getName()); //此处可变
|
|
|
- dagTask.setArguments(arguments);
|
|
|
- dagTask.setTemplate(template.getName());
|
|
|
-
|
|
|
- //记录对应节点 id 以及添加至DAG中的dagtask中的Name
|
|
|
- idtempname.put(rectid,dagTask.getName());
|
|
|
- // for(int k=0;k<edgearray.size();k++){
|
|
|
- // String targetID = edgearray.getJSONObject(i).getString("targetID");
|
|
|
- // if(targetID.equals(rectid)){
|
|
|
- //
|
|
|
- // }
|
|
|
- // }
|
|
|
- // dagTask.setDependencies();//依赖于DAGTask 的name
|
|
|
- // //依赖关系需由边决定 如果此处已经添加至taskslist中, 后续根据边添加其依赖如果不起作用,则需先遍历边确定依赖关系,然后在此处寻找遍历边的关系结果,直接填充
|
|
|
-
|
|
|
-
|
|
|
- taskslist.add(dagTask);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- // //判断若为edge,则表示边,存储节点前后依赖关系,为target节点(有ID)对应的template,在DAG中为其相应的DAGTask添加dependence,为source节点(通过ID查询)对应的templateName
|
|
|
- // if(cellsarray.getJSONObject(i).getString("shape").equals("edge")){
|
|
|
- // //获取源节点ID
|
|
|
- // JSONObject edgesource = cellsarray.getJSONObject(i).getJSONObject("source");
|
|
|
- // String sourceID = edgesource.getString("cell");
|
|
|
- // //获取目标节点ID
|
|
|
- // JSONObject edgetarget = cellsarray.getJSONObject(i).getJSONObject("target");
|
|
|
- // String targetID = edgetarget.getString("cell");
|
|
|
- // System.out.println("edge:"+cellsarray.getJSONObject(i).getString("id")+" sourceId :"+sourceID+" targetID: "+targetID);
|
|
|
- //
|
|
|
- // }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- //
|
|
|
- //创建DAGTasks成功后,遍历所有边,为目标节点对应的DAGTask 添加 源节点对应的DAGTask 依赖
|
|
|
- for(int i=0;i<cellsarray.size();i++){
|
|
|
- //判断若为edge,则表示边,存储节点前后依赖关系,为target节点(有ID)对应的template,在DAG中为其相应的DAGTask添加dependence,为source节点(通过ID查询)对应的templateName
|
|
|
- if(cellsarray.getJSONObject(i).getString("shape").equals("edge")){
|
|
|
- //获取源节点ID
|
|
|
- JSONObject edgesource = cellsarray.getJSONObject(i).getJSONObject("source");
|
|
|
- String sourceID = edgesource.getString("cell");
|
|
|
-
|
|
|
- //获取目标节点ID
|
|
|
- JSONObject edgetarget = cellsarray.getJSONObject(i).getJSONObject("target");
|
|
|
- String targetID = edgetarget.getString("cell");
|
|
|
-
|
|
|
- //根据目标节点ID获取目标节点对应的DAGTask name
|
|
|
- String targetname = idtempname.get(targetID);
|
|
|
- //根据源节点ID获取源节点对应的DAGTask name
|
|
|
- String sourcename = idtempname.get(sourceID);
|
|
|
-
|
|
|
- //20210730--------增加条件分支后 ,需判断根据源节点id获取到的DAGTask name是否为空;若为空,则表示其源节点为条件节点,则不添加依赖关系,应添加 条件when
|
|
|
- //若条件节点连接的还是条件节点,则该条件节点连接的目标节点id -------则还是条件分支引出来的边,已做处理
|
|
|
- //若普通节点引出边到条件节点,则遍历taskslist不会找到对应的dagtask name
|
|
|
- // ---------------现在需清楚怎样判断条件节点的哪一条边条件为真,哪一条边条件为假
|
|
|
- if(sourcename!=null){
|
|
|
- for(DAGTask dagTask:taskslist){
|
|
|
- if(dagTask.getName().equals(targetname)){
|
|
|
- dagTask.addDependenciesItem(sourcename);
|
|
|
- //是否需要break?
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //20210730 zhang
|
|
|
- //创建DAGTasks成功后,遍历所有条件节点,为目标节点对应的DAGTask 添加 目标节点对应的DAGTask when条件
|
|
|
- for(int i=0;i<cellsarray.size();i++){
|
|
|
- //条件节点暂时类型为polygon
|
|
|
- if(cellsarray.getJSONObject(i).getString("shape").equals("polygon")){
|
|
|
- JSONObject conditiondata = cellsarray.getJSONObject(i).getJSONObject("data");
|
|
|
- //获取条件
|
|
|
- String inputcondition = conditiondata.getString("inputcondition");
|
|
|
- //获取条件为真的边连接的节点的id
|
|
|
- String truetargetid = conditiondata.getString("truetargetid");
|
|
|
- //根据目标节点ID获取目标节点对应的DAGTask name
|
|
|
- String truetargetname = idtempname.get(truetargetid);
|
|
|
- System.out.println("条件:"+inputcondition);
|
|
|
- System.out.println("条件为真:"+truetargetid+" --DAGTask name: "+truetargetname);
|
|
|
-
|
|
|
- //获取条件为假的边连接的节点的id
|
|
|
- String falsetargetid = conditiondata.getString("falsetargetid");
|
|
|
- //根据目标节点ID获取目标节点对应的DAGTask name
|
|
|
- String falsetargetname = idtempname.get(falsetargetid);
|
|
|
- System.out.println("条件为假:"+falsetargetid+" --DAGTask name: "+falsetargetname);
|
|
|
-
|
|
|
-
|
|
|
- //若条件节点连接的还是条件节点,则该条件节点连接的目标节点id 并没有对应的DAGTask,查询不到其对应的targetname, 因此进行下列程序判断的时候并不会添加 条件
|
|
|
- for(DAGTask dagTask:taskslist){
|
|
|
- //考虑如果多个条件节点连接,先判断是否 -------前端判断?
|
|
|
- //如果有多个条件节点指向同一个节点,则表示可能该 节点对应的when已有值,不能直接覆盖,需进行 与 添加
|
|
|
-
|
|
|
- //真
|
|
|
- if(dagTask.getName().equals(truetargetname)){
|
|
|
- String dagTaskWhen = dagTask.getWhen();
|
|
|
- System.out.println("为真 条件");
|
|
|
- if(dagTaskWhen!= null){
|
|
|
- //添加条件语句
|
|
|
- dagTask.setWhen(dagTaskWhen+"&&("+inputcondition+")");
|
|
|
- System.out.println("为真 条件:"+dagTask.getWhen());
|
|
|
- //是否需要break?
|
|
|
- }else{
|
|
|
- dagTask.setWhen(inputcondition);
|
|
|
- System.out.println("为真 条件:"+dagTask.getWhen());
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- //假
|
|
|
- if(dagTask.getName().equals(falsetargetname)){
|
|
|
- //添加条件语句 需对原语句取反 添加!还是??????????????????
|
|
|
- //参数为String
|
|
|
- String invcondition = "!("+inputcondition+")";
|
|
|
-
|
|
|
- String dagTaskWhen = dagTask.getWhen();
|
|
|
- if(dagTaskWhen!= null){
|
|
|
- //添加条件语句
|
|
|
- dagTask.setWhen(dagTaskWhen+"&&("+invcondition+")");
|
|
|
- //是否需要break?
|
|
|
- System.out.println("为假 条件:"+dagTask.getWhen());
|
|
|
- }else{
|
|
|
- dagTask.setWhen(invcondition);
|
|
|
- System.out.println("为假 条件:"+dagTask.getWhen());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- dagTemplate.setTasks(taskslist);
|
|
|
- dagtemp.setDag(dagTemplate);
|
|
|
- templateslist.add(dagtemp); //添加Dag template
|
|
|
-
|
|
|
- workflowTemplateSpec.setTemplates(templateslist);
|
|
|
- workflowTemplate1.setSpec(workflowTemplateSpec);
|
|
|
- body.setTemplate(workflowTemplate1);
|
|
|
- WorkflowTemplate resultWorkflowtemplate = null;
|
|
|
- System.out.println("body"+body.toString());
|
|
|
- try {
|
|
|
- resultWorkflowtemplate = apiInstance.workflowTemplateServiceCreateWorkflowTemplate(namespace, body);
|
|
|
- } catch (ApiException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- //获取创建成功的WorkflowTemplate Name
|
|
|
- System.out.println(resultWorkflowtemplate.getMetadata().getName());
|
|
|
- String workflowTempname = resultWorkflowtemplate.getMetadata().getName();
|
|
|
-
|
|
|
- //完成workflowTemplate创建,以此workflowtemplate为模板,提交workflow
|
|
|
-
|
|
|
- WorkflowServiceApi workflowServiceApi = new WorkflowServiceApi(defaultClient);
|
|
|
- // String namespace = "default"; // String | //对应命名空间下的workflowTemplate
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- WorkflowSubmitRequest workflowbody = new WorkflowSubmitRequest();
|
|
|
- workflowbody.setResourceKind("WorkflowTemplate");
|
|
|
- // workflowbody.setResourceName("hello-world-parameters-2p2kg");
|
|
|
- workflowbody.setResourceName("hello-world-parameters-wcwfs");
|
|
|
-
|
|
|
- SubmitOpts submitOpts = new SubmitOpts();
|
|
|
- //submitOpts.setLabels("workflows.argoproj.io/workflow-template=hello-argo");
|
|
|
- submitOpts.setGenerateName("hello-world-"); //GenerateName overrides metadata.generateName
|
|
|
- //submitOpts.setLabels("workflows.argoproj.io/archive-strategy: \"false\""); //Labels adds to metadata.labels
|
|
|
- //submitOpts.setEntryPoint("whalesay"); //Entrypoint overrides spec.entrypoint
|
|
|
- //submitOpts.setName("whalesay"); //Name overrides metadata.name
|
|
|
- //submitOpts.addParametersItem("templates");
|
|
|
-
|
|
|
- //submitOpts.setParameters();
|
|
|
- //submitOpts.setParameters();
|
|
|
-
|
|
|
- submitOpts.setServiceAccount("report-api");
|
|
|
- workflowbody.setSubmitOptions(submitOpts);
|
|
|
-
|
|
|
-
|
|
|
- // workflowbody.setNamespace(namespace); //暂时无用
|
|
|
- //
|
|
|
- // workflowbody.setResourceKind("WorkflowTemplate");
|
|
|
- // workflowbody.setResourceName(workflowTempname);
|
|
|
- // SubmitOpts submitOpts = new SubmitOpts();
|
|
|
- // submitOpts.setGenerateName("hello-world-zhang-"); //GenerateName overrides metadata.generateName
|
|
|
- // submitOpts.setServiceAccount("report-api");
|
|
|
- // workflowbody.setSubmitOptions(submitOpts);
|
|
|
- Workflow resultWorkflow = null;
|
|
|
- try {
|
|
|
- resultWorkflow = apiInstance.workflowServiceSubmitWorkflow(namespace, workflowbody);
|
|
|
- // resultWorkflow = workflowServiceApi.workflowServiceSubmitWorkflow(namespace, workflowbody);
|
|
|
- } catch (ApiException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- System.out.println(resultWorkflow.getMetadata().getName());
|
|
|
-
|
|
|
-
|
|
|
- return R.ok();
|
|
|
- }
|
|
|
+ * 根据行列创建新的csv文件
|
|
|
+ *
|
|
|
+ * @param params workflow名称
|
|
|
+ * @return workflow执行状态
|
|
|
+ *
|
|
|
*/
|
|
|
+ @RequestMapping("/getnewfile")
|
|
|
+ public R getnewfile(@RequestParam Map<String, Object> params) throws IOException, InvalidResponseException, InvalidKeyException, NoSuchAlgorithmException, ErrorResponseException, XmlParserException, InvalidBucketNameException, InsufficientDataException, InternalException {
|
|
|
+ Object filename = params.get("filename");//文件名称
|
|
|
+ Object bucketname = params.get("bucketname");//桶名称
|
|
|
+ Object rowminnum = params.get("rowminnum");
|
|
|
+ Object rowmaxnum = params.get("rowmaxnum");
|
|
|
+ Object colminnum = params.get("colminnum");
|
|
|
+ Object colmaxnum = params.get("colmaxnum");
|
|
|
+
|
|
|
+ System.out.println(bucketname.toString());
|
|
|
+ System.out.println(filename.toString());
|
|
|
+ // 1.读取原数据集
|
|
|
+ InputStream fileInputStream = null;
|
|
|
+ if(bucketname.toString().equals("visiarguartifact")){
|
|
|
+ fileInputStream = MinIoUtils.getFileInputStream(bucketname.toString(), "argoworkflow" + "/" + filename.toString());
|
|
|
+
|
|
|
+ }else{
|
|
|
+ fileInputStream = MinIoUtils.getFileInputStream(bucketname.toString(), filename.toString()+".csv");
|
|
|
+ }
|
|
|
+
|
|
|
+ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fileInputStream));
|
|
|
+ String line = null;
|
|
|
+ int index=0;//总行数
|
|
|
+ int col = 0;//列
|
|
|
+ //表头
|
|
|
+ String[] headerinfo = null;
|
|
|
+ //前五行数据
|
|
|
+ List<String[]> allString = new ArrayList<>();
|
|
|
+ //读取每行,直到为空
|
|
|
+ while((line=bufferedReader.readLine())!=null){
|
|
|
+ index++;
|
|
|
+ if(index==1){
|
|
|
+ //读取首行
|
|
|
+ headerinfo = line.split(",");//CSV格式文件为逗号分隔符文件,这里根据逗号切分
|
|
|
+ col = headerinfo.length;
|
|
|
+// for (String s : headerinfo) {
|
|
|
+// System.out.println(s);
|
|
|
+// }
|
|
|
+ }else{
|
|
|
+ allString.add(line.split(","));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //2.根据行列限制设置新文件
|
|
|
+
|
|
|
+ List<String[]> newallString = new ArrayList<>();
|
|
|
+ for (int i = Integer.parseInt(rowminnum.toString()); i <= Integer.parseInt(rowmaxnum.toString()); i++) {
|
|
|
+ StringBuffer str = new StringBuffer();
|
|
|
+ String[] oldstrings = allString.get(i);
|
|
|
+ for (int j = Integer.parseInt(colminnum.toString()); j <= Integer.parseInt(colmaxnum.toString()); j++) {
|
|
|
+ str.append(oldstrings[j]).append(",");
|
|
|
+ }
|
|
|
+ String[] split = str.toString().split(",");
|
|
|
+ newallString.add(split);
|
|
|
+ }
|
|
|
+
|
|
|
+ //2.1 设置输出的文件路径
|
|
|
+ //如果该目录下不存在该文件,则文件会被创建到指定目录下。如果该目录有同名文件,那么该文件将被覆盖。
|
|
|
+ File writeFile = new File("src/main/resources/"+"new"+filename.toString());
|
|
|
+
|
|
|
+ try{
|
|
|
+ //2.2 通过BufferedReader类创建一个使用默认大小输出缓冲区的缓冲字符输出流
|
|
|
+ BufferedWriter writeText = new BufferedWriter(new FileWriter(writeFile));
|
|
|
+ if(Integer.parseInt(rowminnum.toString())!=0){
|
|
|
+ //选中的行不包含表头,添加
|
|
|
+ writeText.write(StringUtils.join(headerinfo,","));
|
|
|
+ writeText.newLine();
|
|
|
+ }
|
|
|
+ //2.3 将文档的下一行数据赋值给lineData,并判断是否为空,若不为空则输出
|
|
|
+ for(int i=0;i<newallString.size();i++){
|
|
|
+
|
|
|
+ //调用write的方法将字符串写到流中
|
|
|
+ writeText.write(StringUtils.join(newallString.get(i),","));
|
|
|
+ writeText.newLine(); //换行
|
|
|
+
|
|
|
+ }
|
|
|
+ //使用缓冲区的刷新方法将数据刷到目的地中
|
|
|
+ writeText.flush();
|
|
|
+ //关闭缓冲区,缓冲区没有调用系统底层资源,真正调用底层资源的是FileWriter对象,缓冲区仅仅是一个提高效率的作用
|
|
|
+ //因此,此处的close()方法关闭的是被缓存的流对象
|
|
|
+ writeText.close();
|
|
|
+ }catch (FileNotFoundException e){
|
|
|
+ System.out.println("没有找到指定文件");
|
|
|
+ }catch (IOException e){
|
|
|
+ System.out.println("文件读写出错");
|
|
|
+ }
|
|
|
+
|
|
|
+ //上传新文件到minio
|
|
|
+// MinIoUtils.uploadMultipartFile(file, "visiarguartifact", "argoworkflow" + "/" + file.getOriginalFilename());
|
|
|
+
|
|
|
+ MinIoUtils.uploadLocalFile("visiarguartifact","argoworkflow" + "/" + writeFile.getName(),writeFile.getPath(),null);
|
|
|
+ String newfileurl = MinIoUtils.getFileUrl("visiarguartifact", "argoworkflow" + "/" + writeFile.getName());
|
|
|
+ //上传成功后删除本地文件
|
|
|
+ if(writeFile.exists()) {//判断路径是否存在
|
|
|
+// if(file.isFile()){//boolean isFile():测试此抽象路径名表示的文件是否是一个标准文件。
|
|
|
+// file.delete();
|
|
|
+// }
|
|
|
+ writeFile.delete();
|
|
|
+ }else {
|
|
|
+ System.out.println("该file路径不存在!!");
|
|
|
+ }
|
|
|
+
|
|
|
+ return R.ok().put("newfilename", "new"+filename.toString()).put("newfileurl",newfileurl);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
|
|
|
}
|