17
17
package com .webank .wedatasphere .dss .orchestrator .server .restful ;
18
18
19
19
import com .webank .wedatasphere .dss .common .exception .DSSErrorException ;
20
+ import com .webank .wedatasphere .dss .common .exception .DSSRuntimeException ;
20
21
import com .webank .wedatasphere .dss .common .label .DSSLabel ;
21
22
import com .webank .wedatasphere .dss .common .label .EnvDSSLabel ;
22
23
import com .webank .wedatasphere .dss .common .label .LabelKeyConvertor ;
31
32
import com .webank .wedatasphere .dss .standard .app .sso .Workspace ;
32
33
import com .webank .wedatasphere .dss .standard .sso .utils .SSOHelper ;
33
34
import org .apache .commons .io .IOUtils ;
35
+ import org .apache .linkis .common .io .FsPath ;
36
+ import org .apache .linkis .filesystem .service .FsService ;
34
37
import org .apache .linkis .server .Message ;
35
38
import org .apache .linkis .server .security .SecurityFilter ;
39
+ import org .apache .linkis .storage .fs .FileSystem ;
36
40
import org .slf4j .Logger ;
37
41
import org .slf4j .LoggerFactory ;
38
42
import org .springframework .beans .factory .annotation .Autowired ;
@@ -57,6 +61,8 @@ public class OrchestratorIERestful {
57
61
@ Autowired
58
62
private BMLService bmlService ;
59
63
@ Autowired
64
+ private FsService fsService ;
65
+ @ Autowired
60
66
OrchestratorService orchestratorService ;
61
67
@ Autowired
62
68
private DSSOrchestratorContext orchestratorContext ;
@@ -66,30 +72,43 @@ public Message importOrcFile(HttpServletRequest req,
66
72
@ RequestParam (required = false , name = "projectName" ) String projectName ,
67
73
@ RequestParam (required = false , name = "projectID" ) Long projectID ,
68
74
@ RequestParam (required = false , name = "labels" ) String labels ,
69
- @ RequestParam (required = false , name = "file" ) List <MultipartFile > files ) throws DSSErrorException , Exception {
70
- if (null == files || files .size () == 0 ) {
75
+ @ RequestParam (required = false , name = "packageFile" ) MultipartFile packageFile ,
76
+ @ RequestParam (required = false , name = "packageUri" ) String packageUri ) throws Exception {
77
+
78
+ if (null == packageFile && packageUri == null ) {
71
79
throw new DSSErrorException (100788 , "Import orchestrator failed for files is empty" );
72
80
}
73
- Long importOrcId = 0L ;
74
- for (MultipartFile p : files ) {
75
- InputStream inputStream = p .getInputStream ();
76
- String fileName = new String (p .getOriginalFilename ().getBytes ("ISO8859-1" ), "UTF-8" );
77
- String userName = SecurityFilter .getLoginUsername (req );
78
- //调用工具类生产label
79
- List <DSSLabel > dssLabelList = getDSSLabelList (labels );
80
- Workspace workspace = SSOHelper .getWorkspace (req );
81
+ String userName = SecurityFilter .getLoginUsername (req );
82
+ //调用工具类生产label
83
+ List <DSSLabel > dssLabelList = getDSSLabelList (labels );
84
+ Workspace workspace = SSOHelper .getWorkspace (req );
85
+ InputStream inputStream ;
86
+ String fileName ;
87
+ if (packageFile != null ) {
88
+ inputStream = packageFile .getInputStream ();
89
+ fileName = new String (packageFile .getOriginalFilename ().getBytes ("ISO8859-1" ), "UTF-8" );
81
90
//3、打包新的zip包上传BML
82
- Map <String , Object > resultMap = bmlService .upload (userName , inputStream ,
83
- fileName , projectName );
84
- try {
85
- RequestImportOrchestrator importRequest = new RequestImportOrchestrator (userName , projectName ,
86
- projectID , resultMap .get ("resourceId" ).toString (),
87
- resultMap .get ("version" ).toString (), null , dssLabelList , workspace );
88
- importOrcId = orchestratorContext .getDSSOrchestratorPlugin (ImportDSSOrchestratorPlugin .class ).importOrchestrator (importRequest );
89
- } catch (Exception e ) {
90
- logger .error ("Import orchestrator failed for " , e );
91
- throw new DSSErrorException (100789 , "Import orchestrator failed for " + e .getMessage ());
91
+ logger .info ("User {} begin to import orchestrator file" , userName );
92
+ } else {
93
+ FsPath fsPath = new FsPath (packageUri );
94
+ FileSystem fileSystem = fsService .getFileSystem (userName , fsPath );
95
+ if ( !fileSystem .exists (fsPath ) ) {
96
+ throw new DSSRuntimeException ("路径上不存在文件!" );
92
97
}
98
+ inputStream = fileSystem .read (fsPath );
99
+ fileName = packageUri .substring (packageUri .lastIndexOf ('/' ) + 1 );
100
+ }
101
+
102
+ Map <String , Object > resultMap = bmlService .upload (userName , inputStream , fileName , projectName );
103
+ Long importOrcId ;
104
+ try {
105
+ RequestImportOrchestrator importRequest = new RequestImportOrchestrator (userName , projectName ,
106
+ projectID , resultMap .get ("resourceId" ).toString (),
107
+ resultMap .get ("version" ).toString (), null , dssLabelList , workspace );
108
+ importOrcId = orchestratorContext .getDSSOrchestratorPlugin (ImportDSSOrchestratorPlugin .class ).importOrchestrator (importRequest );
109
+ } catch (Exception e ) {
110
+ logger .error ("Import orchestrator failed for " , e );
111
+ throw new DSSErrorException (100789 , "Import orchestrator failed for " + e .getMessage ());
93
112
}
94
113
return Message .ok ().data ("importOrcId" , importOrcId );
95
114
}
0 commit comments