volume的增删,启动,停止

web_backend_develope
chenlw 9 years ago
parent 278c3d3aae
commit f3b3b6dbf8

@ -85,11 +85,11 @@ PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"
)
</insert>
<delete id="remove" parameterType="java.lang.Integer">
<delete id="remove" parameterType="java.lang.String">
DELETE FROM
volume_info
WHERE
id = #{id}
name = #{name}
</delete>
</mapper>

@ -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);
}
}

@ -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;
}

@ -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<String> 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<String> getBricks() {
return bricks;
}
/**
* @param bricks the bricks to set
*/
public void setBricks(List<String> 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;
}
}

@ -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;
}

@ -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());
}
}
Loading…
Cancel
Save