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