socialforge/controller/VncController.java

55 lines
1.9 KiB
Java
Raw Normal View History

2018-07-03 18:34:21 +08:00
package com.educoder.bridge.controller;
import com.alibaba.fastjson.JSONObject;
import com.educoder.bridge.service.VncService;
import com.educoder.bridge.utils.Base64Util;
import com.educoder.bridge.utils.JedisUtil;
import com.educoder.bridge.utils.PortUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@Api(value = "vnc控制器", hidden = true)
@RestController
@RequestMapping("/vnc")
public class VncController {
@Autowired
private VncService vncService;
private static final Logger logger = LoggerFactory.getLogger(VncController.class);
@RequestMapping(path = "/getvnc")
@ApiOperation(value = "图形界面", httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public JSONObject getvnc(
@ApiParam(name = "tpiID", required = true, value = "实训实例的ID") @RequestParam String tpiID,
@ApiParam(name = "containers", required = true, value = "需要使用的容器,base64编码") @RequestParam String containers)
throws Exception{
JSONObject response = new JSONObject();
String podName = "vnc-" + tpiID;
containers = Base64Util.decode(containers);
// 为vnc分配port
String port = JedisUtil.hget("port", podName);
if (port == null) {
port = PortUtil.getPort() + "";
JedisUtil.hset("port", podName, port);
}
vncService.getvnc(tpiID, containers);
response.put("code", 0);
response.put("port", port);
return response;
}
}