From f3b3b6dbf8c8e3ef8e4da3e5c342a0c160804c01 Mon Sep 17 00:00:00 2001 From: chenlw <874313221@qq.com> Date: Fri, 23 Sep 2016 20:37:15 +0800 Subject: [PATCH] =?UTF-8?q?volume=E7=9A=84=E5=A2=9E=E5=88=A0=EF=BC=8C?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=EF=BC=8C=E5=81=9C=E6=AD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/com/dao/mapper/VolumeMapper.xml | 4 +- .../platform/controller/VolumeController.java | 68 +++++++++++++++++++ src/com/platform/dao/VolumeDao.java | 2 +- .../platform/entities/VolumeInitEntity.java | 34 ++++++++++ src/com/platform/service/IVolumeService.java | 15 ++++ .../service/impl/VolumeServiceImpl.java | 59 ++++++++++++++++ 6 files changed, 179 insertions(+), 3 deletions(-) create mode 100644 src/com/platform/controller/VolumeController.java create mode 100644 src/com/platform/service/IVolumeService.java create mode 100644 src/com/platform/service/impl/VolumeServiceImpl.java diff --git a/src/com/dao/mapper/VolumeMapper.xml b/src/com/dao/mapper/VolumeMapper.xml index 146d83fd..29f0a59b 100644 --- a/src/com/dao/mapper/VolumeMapper.xml +++ b/src/com/dao/mapper/VolumeMapper.xml @@ -85,11 +85,11 @@ PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN" ) - + DELETE FROM volume_info WHERE - id = #{id} + name = #{name} \ No newline at end of file diff --git a/src/com/platform/controller/VolumeController.java b/src/com/platform/controller/VolumeController.java new file mode 100644 index 00000000..a787ce07 --- /dev/null +++ b/src/com/platform/controller/VolumeController.java @@ -0,0 +1,68 @@ +package com.platform.controller; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +import com.base.BaseController; +import com.platform.entities.VolumeInitEntity; +import com.platform.service.IVolumeService; +import com.platform.utils.Configs; + +@Controller +public class VolumeController extends BaseController{ + + public static Logger log = Configs.DAILY_ROLLING_LOGGER; + + @Resource(name = "volumeService") + private IVolumeService volumeService; + + + @RequestMapping(value = "/volume/insert", method = RequestMethod.POST) + @ResponseBody + public void volumeInsert(HttpServletRequest res, HttpServletResponse req, + @RequestBody VolumeInitEntity entity) throws Exception { + Configs.CONSOLE_LOGGER.error("/oracle/{name}/extract"); + volumeService.save(entity); + req.setStatus(200); + } + + @RequestMapping(value = "/volume/{name}/delete", method = RequestMethod.POST) + @ResponseBody + public void volumeDelete(HttpServletRequest res, HttpServletResponse req, + @RequestBody VolumeInitEntity entity) throws Exception { + Configs.CONSOLE_LOGGER.error("/oracle/{name}/extract"); + volumeService.delete(entity); + req.setStatus(200); + } + + + @RequestMapping(value = "/volume/{name}/start", method = RequestMethod.POST) + @ResponseBody + public void volumeStart(HttpServletRequest res, HttpServletResponse req, + @RequestBody VolumeInitEntity entity) throws Exception { + Configs.CONSOLE_LOGGER.error("/oracle/{name}/extract"); + res.setCharacterEncoding("UTF-8"); + volumeService.start(entity); + req.setStatus(200); + } + + + @RequestMapping(value = "/volume/{name}/stop", method = RequestMethod.POST) + @ResponseBody + public void volumeStop(HttpServletRequest res, HttpServletResponse req, + @RequestBody VolumeInitEntity entity) throws Exception { + Configs.CONSOLE_LOGGER.error("/oracle/{name}/extract"); + res.setCharacterEncoding("UTF-8"); + volumeService.stop(entity); + req.setStatus(200); + } + +} diff --git a/src/com/platform/dao/VolumeDao.java b/src/com/platform/dao/VolumeDao.java index db4e9c93..1d1d0232 100644 --- a/src/com/platform/dao/VolumeDao.java +++ b/src/com/platform/dao/VolumeDao.java @@ -23,5 +23,5 @@ public interface VolumeDao { int save(VolumeInitEntity data) throws Exception; - int remove(int id) throws Exception; + int remove(String name) throws Exception; } diff --git a/src/com/platform/entities/VolumeInitEntity.java b/src/com/platform/entities/VolumeInitEntity.java index fa0a70d9..fef17763 100644 --- a/src/com/platform/entities/VolumeInitEntity.java +++ b/src/com/platform/entities/VolumeInitEntity.java @@ -1,5 +1,7 @@ package com.platform.entities; +import java.util.List; + public class VolumeInitEntity { private int id; @@ -11,6 +13,10 @@ public class VolumeInitEntity { private String path; private String mark; + + private List bricks; + + private String mountPoint; /** * @return the id @@ -81,6 +87,34 @@ public class VolumeInitEntity { public void setMark(String mark) { this.mark = mark; } + + /** + * @return the bricks + */ + public List getBricks() { + return bricks; + } + + /** + * @param bricks the bricks to set + */ + public void setBricks(List bricks) { + this.bricks = bricks; + } + + /** + * @return the mountPoint + */ + public String getMountPoint() { + return mountPoint; + } + + /** + * @param mountPoint the mountPoint to set + */ + public void setMountPoint(String mountPoint) { + this.mountPoint = mountPoint; + } } diff --git a/src/com/platform/service/IVolumeService.java b/src/com/platform/service/IVolumeService.java new file mode 100644 index 00000000..15e211a7 --- /dev/null +++ b/src/com/platform/service/IVolumeService.java @@ -0,0 +1,15 @@ +package com.platform.service; + +import com.platform.entities.VolumeInitEntity; + +public interface IVolumeService { + + public int save(VolumeInitEntity entity) throws Exception; + + public int delete(VolumeInitEntity entity) throws Exception; + + public int start(VolumeInitEntity entity) throws Exception; + + public int stop(VolumeInitEntity entity) throws Exception; + +} diff --git a/src/com/platform/service/impl/VolumeServiceImpl.java b/src/com/platform/service/impl/VolumeServiceImpl.java new file mode 100644 index 00000000..c674f4db --- /dev/null +++ b/src/com/platform/service/impl/VolumeServiceImpl.java @@ -0,0 +1,59 @@ +package com.platform.service.impl; + +import javax.annotation.Resource; + +import org.springframework.stereotype.Service; + +import com.platform.dao.VolumeDao; +import com.platform.entities.VolumeInitEntity; +import com.platform.glusterfs.SetVolume; +import com.platform.service.IVolumeService; + +@Service(value = "volumeService") +public class VolumeServiceImpl implements IVolumeService { + + /** gfs的api */ + SetVolume volumeService = new SetVolume(); + + @Resource(name = "volumeDao") + private VolumeDao volumeDao; + + + @Override + public int save(VolumeInitEntity entity) throws Exception { + //createVolume("lili_test1", 0, "distributed", bricksToCreate, "/home/lili_test1_point") + if (null == entity.getBricks()) { + return -1; + } + volumeService.createVolume(entity.getName(), 0, "distributed", entity.getBricks(), entity.getMountPoint()); + volumeDao.save(entity); + return 0; + } + + @Override + public int delete(VolumeInitEntity entity) throws Exception { + if (null == entity.getName() || "".equals(entity.getName())) { + return -1; + } + volumeService.deleteVolume(entity.getName()); + volumeDao.remove(entity.getName()); + return 0; + } + + @Override + public int start(VolumeInitEntity entity) throws Exception { + if (null == entity.getName() || "".equals(entity.getName())) { + return -1; + } + return volumeService.startVolume(entity.getName()); + } + + @Override + public int stop(VolumeInitEntity entity) throws Exception { + if (null == entity.getName() || "".equals(entity.getName())) { + return -1; + } + return volumeService.stopVolume(entity.getName()); + } + +}