Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OpenXG-WIC-Cnf
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
3
Issues
3
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
CommunityXG
OpenXG-WIC-Cnf
Commits
63dfbc47
Commit
63dfbc47
authored
Sep 04, 2020
by
Elf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
中间节点进行计算
parent
5e506afb
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
86 additions
and
2 deletions
+86
-2
apps/cnf-distributed-business-computing/dbc-business-client/src/main/java/top/ninwoo/dbc/client/service/FileService.java
.../main/java/top/ninwoo/dbc/client/service/FileService.java
+2
-1
apps/cnf-distributed-business-computing/dbc-business-server/src/main/java/top/ninwoo/dbc/server/FileService.java
...rver/src/main/java/top/ninwoo/dbc/server/FileService.java
+13
-0
apps/cnf-distributed-business-computing/dbc-business-server/src/main/java/top/ninwoo/dbc/server/controller/ServerController.java
...va/top/ninwoo/dbc/server/controller/ServerController.java
+8
-1
apps/cnf-distributed-business-computing/dbc-business-server/src/main/java/top/ninwoo/dbc/server/serviceimpl/FileServiceImpl.java
...va/top/ninwoo/dbc/server/serviceimpl/FileServiceImpl.java
+62
-0
apps/cnf-distributed-file-transfer/dfs-transfer-client/src/main/java/top/ninwoo/app/dfs/client/controller/FileController.java
.../top/ninwoo/app/dfs/client/controller/FileController.java
+1
-0
No files found.
apps/cnf-distributed-business-computing/dbc-business-client/src/main/java/top/ninwoo/dbc/client/service/FileService.java
View file @
63dfbc47
...
...
@@ -165,9 +165,10 @@ public class FileService{
List
<
FileSlice
>
list
=
new
ArrayList
<>(
result
);
SplitResult
splitResult
=
new
SplitResult
();
splitResult
.
setFileSliceList
(
sortList
(
list
));
//merge
ComputingResult
computingResult
=
distributedComService
.
sliceComputing
(
splitResult
);
MergeResult
mergeResult
=
distributedComService
.
sliceMerge
(
computingResult
,
sliceNum
);
//save
try
{
saveFile
(
fileName
,
mergeResult
);
return
"success"
;
...
...
apps/cnf-distributed-business-computing/dbc-business-server/src/main/java/top/ninwoo/dbc/server/FileService.java
0 → 100644
View file @
63dfbc47
package
top.ninwoo.dbc.server
;
import
top.ninwoo.dbc.api.po.ComputingResult
;
import
top.ninwoo.dbc.api.po.FileSlice
;
import
java.io.IOException
;
public
interface
FileService
{
String
fileComputing
(
FileSlice
fileSlice
)
throws
IOException
;
void
fileSave
(
ComputingResult
computingResult
);
}
apps/cnf-distributed-business-computing/dbc-business-server/src/main/java/top/ninwoo/dbc/server/controller/ServerController.java
View file @
63dfbc47
package
top.ninwoo.dbc.server.controller
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
top.ninwoo.dbc.api.po.FileSlice
;
import
top.ninwoo.dbc.server.FileService
;
import
java.io.IOException
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.Map
;
...
...
@@ -16,6 +19,8 @@ public class ServerController {
public String hello(){
return "hello,springboot";
}*/
@Autowired
private
FileService
fileService
;
private
static
final
Map
<
Long
,
Map
<
Integer
,
FileSlice
>>
fileSliceMap
=
new
HashMap
<>();
...
...
@@ -25,7 +30,7 @@ public class ServerController {
}
@PostMapping
(
"/data/put/"
)
public
String
putData
(
@RequestBody
FileSlice
fileSlice
)
{
public
String
putData
(
@RequestBody
FileSlice
fileSlice
)
throws
IOException
{
if
(
fileSlice
==
null
)
{
return
"failed"
;
}
...
...
@@ -35,6 +40,8 @@ public class ServerController {
Map
<
Integer
,
FileSlice
>
sliceMap
=
fileSliceMap
.
get
(
fileSlice
.
getFileId
());
sliceMap
.
put
(
fileSlice
.
getSliceId
(),
fileSlice
);
//完成分散计算
fileService
.
fileComputing
(
fileSlice
);
return
"success"
;
}
...
...
apps/cnf-distributed-business-computing/dbc-business-server/src/main/java/top/ninwoo/dbc/server/serviceimpl/FileServiceImpl.java
0 → 100644
View file @
63dfbc47
package
top.ninwoo.dbc.server.serviceimpl
;
import
org.springframework.stereotype.Service
;
import
top.ninwoo.dbc.api.po.ComputingResult
;
import
top.ninwoo.dbc.api.po.FileSlice
;
import
top.ninwoo.dbc.server.FileService
;
import
javax.imageio.ImageIO
;
import
java.awt.image.BufferedImage
;
import
java.io.ByteArrayInputStream
;
import
java.io.File
;
import
java.io.IOException
;
@Service
public
class
FileServiceImpl
implements
FileService
{
//分散计算
@Override
public
String
fileComputing
(
FileSlice
fileSlice
)
throws
IOException
{
if
(
this
.
greySlice
(
fileSlice
)){
return
"sucess"
;
}
else
{
return
"failed"
;
}
}
//存储模块
//todo
//目前仅是灰度处理,如果为多个计算,则需要添加
@Override
public
void
fileSave
(
ComputingResult
computingResult
){}
/**
* 具体任务
* 灰度
* todo 以后继续添加
*/
private
boolean
greySlice
(
FileSlice
fileSlice
)
throws
IOException
{
//读图片
//npe,可能会出问题
if
(
fileSlice
.
getFileBytes
().
equals
(
null
)){
return
false
;
}
else
{
ByteArrayInputStream
bis
=
new
ByteArrayInputStream
(
fileSlice
.
getFileBytes
());
BufferedImage
image
=
ImageIO
.
read
(
bis
);
int
width
=
image
.
getWidth
();
int
height
=
image
.
getHeight
();
BufferedImage
grayImage
=
new
BufferedImage
(
width
,
height
,
BufferedImage
.
TYPE_BYTE_GRAY
);
for
(
int
j
=
0
;
j
<
width
;
j
++){
for
(
int
k
=
0
;
k
<
height
;
k
++){
int
rgb
=
image
.
getRGB
(
j
,
k
);
grayImage
.
setRGB
(
j
,
k
,
rgb
);
}
}
//这里需提供新的文件输出
ImageIO
.
write
(
grayImage
,
"jpg"
,
new
File
(
"/out.jpg"
));
return
true
;
}
}
}
apps/cnf-distributed-file-transfer/dfs-transfer-client/src/main/java/top/ninwoo/app/dfs/client/controller/FileController.java
View file @
63dfbc47
...
...
@@ -37,6 +37,7 @@ public class FileController {
//BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(new File(file.getOriginalFilename())));
FileOutputStream
out
=
new
FileOutputStream
(
new
File
(
file
.
getOriginalFilename
()));
byte
[]
bytes
=
file
.
getBytes
();
//发送切片
fileService
.
sendFile
(
fileId
,
bytes
);
//out.write(file.getBytes());
out
.
flush
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment