Skip to content

Commit

Permalink
express mode 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
dogfootman committed Nov 7, 2022
1 parent 766d056 commit 19fe8b9
Show file tree
Hide file tree
Showing 13 changed files with 576 additions and 80 deletions.
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,9 @@ func main() {
// TODO : namespace는 서버에 저장된 것을 사용하는데... 자칫하면 namespace와 다른 mcis의 vm으로 날아갈 수 있지 않나???
e.GET("/operation/manages/mcismng/:mcisID", controller.GetMcisInfoData)

e.POST("/operation/manages/mcismng/:mcisID/vm/reg/proc", controller.VmRegProc) // vm 등록이므로 vmID없이 reg/proc
e.POST("/operation/manages/mcismng/:mcisID/vm/reg/proc", controller.VmRegProc) // vm 등록이므로 vmID없이 reg/proc
e.POST("/operation/manages/mcismng/:mcisID/vmlist/reg/proc", controller.VmListRegProc) // 여러 vm등록
e.POST("/operation/manages/mcismng/:mcisID/vmdynamic/proc", controller.VmDynamicRegProc)
e.GET("/operation/manages/mcismng/:mcisID/vm/:vmID", controller.GetVmInfoData)
e.GET("/operation/manages/mcismng/:mcisID/vnet/:vnetID", controller.GetVmInfoDataByVnet) // MCIS내 특정 Vnet을 사용하는 vm목록

Expand Down
105 changes: 100 additions & 5 deletions src/controller/McisController.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,25 +492,83 @@ func McisDynamicRegProc(c echo.Context) error {
// map[description:bb installMonAgent:yes name:aa vm:[map[connectionName:gcp-asia-east1 description:dd imageId:gcp-jsyoo-ubuntu name:cc provider:GCP securityGroupIds:[gcp-jsyoo-sg-01] specId:gcp-jsyoo-01 sshKeyId:gcp-jsyoo-sshkey subnetId:jsyoo-gcp-sub-01 vNetId:jsyoo-gcp-01 vm_add_cnt:0 vm_cnt:]]]
log.Println("get info")

mcisInfo := &tbmcis.TbMcisDynamicReq{}
if err := c.Bind(mcisInfo); err != nil {
mcisReqInfo := &tbmcis.TbMcisDynamicReq{}
if err := c.Bind(mcisReqInfo); err != nil {
log.Println(err)
return c.JSON(http.StatusBadRequest, map[string]interface{}{
"message": "fail",
"status": "5001",
})
}
log.Println(mcisInfo) // 여러개일 수 있음.
log.Println(mcisReqInfo) // 여러개일 수 있음.

defaultNameSpaceID := loginInfo.DefaultNameSpaceID
// TODO : defaultNameSpaceID 가 없으면 설정화면으로 보낼 것

// // socket의 key 생성 : ns + 구분 + id
taskKey := defaultNameSpaceID + "||" + "mcis" + "||" + mcisInfo.Name // TODO : 공통 function으로 뺄 것.
taskKey := defaultNameSpaceID + "||" + "mcis" + "||" + mcisReqInfo.Name // TODO : 공통 function으로 뺄 것.

service.StoreWebsocketMessage(util.TASK_TYPE_MCIS, taskKey, util.MCIS_LIFECYCLE_CREATE, util.TASK_STATUS_REQUEST, c) // session에 작업내용 저장

go service.RegMcisDynamicByAsync(defaultNameSpaceID, mcisInfo, c)
go service.RegMcisDynamicByAsync(defaultNameSpaceID, mcisReqInfo, c)
// 원래는 호출 결과를 return하나 go routine으로 바꾸면서 요청성공으로 return
log.Println("before return")
return c.JSON(http.StatusOK, map[string]interface{}{
"message": "success",
"status": 200,
})

}

// VM (Subgroup 추가)
func VmDynamicRegProc(c echo.Context) error {
log.Println("McisDynamicRegProc : ")
loginInfo := service.CallLoginInfo(c)
if loginInfo.UserID == "" {
return c.Redirect(http.StatusTemporaryRedirect, "/login")
}

log.Println("get info")
mcisID := c.Param("mcisID")

//vmReqInfo := &tbmcis.TbVmDynamicReq{}
//if err := c.Bind(vmReqInfo); err != nil {
// log.Println(err)
// return c.JSON(http.StatusBadRequest, map[string]interface{}{
// "message": "fail",
// "status": "5001",
// })
//}
//log.Println(vmReqInfo) // 여러개일 수 있음.

mcisReqInfo := &tbmcis.TbMcisDynamicReq{}
if err := c.Bind(mcisReqInfo); err != nil {
log.Println(err)
return c.JSON(http.StatusBadRequest, map[string]interface{}{
"message": "fail",
"status": "5001",
})
}
log.Println(mcisReqInfo)

defaultNameSpaceID := loginInfo.DefaultNameSpaceID

vmReqList := mcisReqInfo.Vm
for _, vmReqInfo := range vmReqList {
taskKey := defaultNameSpaceID + "||" + "vm" + "||" + vmReqInfo.Name // TODO : 공통 function으로 뺄 것.

service.StoreWebsocketMessage(util.TASK_TYPE_MCIS, taskKey, util.MCIS_LIFECYCLE_CREATE, util.TASK_STATUS_REQUEST, c) // session에 작업내용 저장

go service.RegVmDynamicByAsync(defaultNameSpaceID, mcisID, &vmReqInfo, c)
}

// // socket의 key 생성 : ns + 구분 + id
//taskKey := defaultNameSpaceID + "||" + "vm" + "||" + vmReqInfo.Name // TODO : 공통 function으로 뺄 것.

//service.StoreWebsocketMessage(util.TASK_TYPE_MCIS, taskKey, util.MCIS_LIFECYCLE_CREATE, util.TASK_STATUS_REQUEST, c) // session에 작업내용 저장

//go service.RegVmDynamicByAsync(defaultNameSpaceID, mcisID, vmReqInfo, c)

// 원래는 호출 결과를 return하나 go routine으로 바꾸면서 요청성공으로 return
log.Println("before return")
return c.JSON(http.StatusOK, map[string]interface{}{
Expand Down Expand Up @@ -802,7 +860,44 @@ func VmRegProc(c echo.Context) error {
"message": "Call success",
"status": 200,
})
}

// MCIS에 VM 목록으로 추가 등록
func VmListRegProc(c echo.Context) error {
log.Println("VmListRegProc : ")
loginInfo := service.CallLoginInfo(c)
if loginInfo.UserID == "" {
return c.Redirect(http.StatusTemporaryRedirect, "/login")
}

// mCISInfo := &tumblebug.McisInfo{}
mcisReqInfo := &tbmcis.TbMcisReq{}
if err := c.Bind(mcisReqInfo); err != nil {
// if err := c.Bind(mCISInfoList); err != nil {
log.Println(err)
return c.JSON(http.StatusBadRequest, map[string]interface{}{
"message": "fail",
"status": "fail",
})
}
log.Println(mcisReqInfo)

defaultNameSpaceID := loginInfo.DefaultNameSpaceID
mcisID := c.Param("mcisID")

vms := mcisReqInfo.Vm
for _, vmInfo := range vms {
taskKey := defaultNameSpaceID + "||" + "vm" + "||" + mcisID + "||" + vmInfo.Name
service.StoreWebsocketMessage(util.TASK_TYPE_VM, taskKey, util.VM_LIFECYCLE_CREATE, util.TASK_STATUS_REQUEST, c) // session에 작업내용 저장

// go 루틴 호출 : return 값은 session에 저장
go service.AsyncRegVm(defaultNameSpaceID, mcisID, &vmInfo, c)
}

return c.JSON(http.StatusOK, map[string]interface{}{
"message": "Call success",
"status": 200,
})
}

// Register existing VM in a CSP to Cloud-Barista MCIS
Expand Down
40 changes: 40 additions & 0 deletions src/service/McisHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,46 @@ func RegMcisDynamicByAsync(nameSpaceID string, mcisInfo *tbmcis.TbMcisDynamicReq
}
}

// Add VM dynamically from common spec and image
func RegVmDynamicByAsync(nameSpaceID string, mcisID string, vmReqInfo *tbmcis.TbVmDynamicReq, c echo.Context) {
var originalUrl = "/ns/{nsId}/mcis/{mcisId}/vmDynamic"

var paramMapper = make(map[string]string)
paramMapper["{nsId}"] = nameSpaceID
paramMapper["{mcisId}"] = mcisID

urlParam := util.MappingUrlParameter(originalUrl, paramMapper)

url := util.TUMBLEBUG + urlParam

pbytes, _ := json.Marshal(vmReqInfo)
resp, err := util.CommonHttp(url, pbytes, http.MethodPost)

respBody := resp.Body
respStatus := resp.StatusCode

taskKey := nameSpaceID + "||" + "vm" + "||" + vmReqInfo.Name // TODO : 공통 function으로 뺄 것.

if err != nil {
fmt.Println(err)
log.Println("RegVmDynamicByAsync ", err)

StoreWebsocketMessage(util.TASK_TYPE_MCIS, taskKey, util.MCIS_LIFECYCLE_CREATE, util.TASK_STATUS_FAIL, c) // session에 작업내용 저장

}

if respStatus != 200 && respStatus != 201 { // 호출은 정상이나, 가져온 결과값이 200, 201아닌 경우 message에 담겨있는 것을 WebStatus에 set

failResultInfo := tbcommon.TbSimpleMsg{}
json.NewDecoder(respBody).Decode(&failResultInfo)
log.Println("RegVmDynamicByAsync ", failResultInfo)
StoreWebsocketMessage(util.TASK_TYPE_MCIS, taskKey, util.MCIS_LIFECYCLE_CREATE, util.TASK_STATUS_FAIL, c) // session에 작업내용 저장
} else {

StoreWebsocketMessage(util.TASK_TYPE_MCIS, taskKey, util.MCIS_LIFECYCLE_CREATE, util.TASK_STATUS_COMPLETE, c) // session에 작업내용 저장
}
}

// Recommend MCIS plan (filter and priority)
// 실제로는 추천 image 목록
// async 로 만들 지
Expand Down
169 changes: 162 additions & 7 deletions src/static/assets/js/operation/manages/mcismng/mciscreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,14 @@ function displayNewServerForm() {
}
}

function closeNewServerForm() {
var simpleServerConfig = $("#simpleServerConfig");
// 모드가 바뀌면 Form을 Clear 한다.
function closeNewServerForm() {
var expressServerConfig = $("#expressServerConfig");
var simpleServerConfig = $("#simpleServerConfig");
var expertServerConfig = $("#expertServerConfig");
var importServerConfig = $("#importServerConfig");

expressServerConfig.removeClass("active");
simpleServerConfig.removeClass("active");
expertServerConfig.removeClass("active");
importServerConfig.removeClass("active");
Expand Down Expand Up @@ -101,6 +105,9 @@ function deployMcis() {
new_obj['description'] = mcis_desc
new_obj['installMonAgent'] = installMonAgent

// Express_Server_Config_Arr 은 별도처리


if (Simple_Server_Config_Arr) {
vm_len = Simple_Server_Config_Arr.length;
for (var i in Simple_Server_Config_Arr) {
Expand Down Expand Up @@ -367,12 +374,118 @@ function getSpecListCallbackSuccess(caller, data) {
}
}

function getSecurityGroupListCallbackSuccess(caller) {

function getSecurityGroupListCallbackSuccess(caller, data) {
if ( caller == "searchSecurityGroupAssistAtReg"){
var rowCount = 0;
var html = "";
data.forEach(function (vSecurityGroupItem, vSecurityGroupIndex) {


var firewallRulesArr = vSecurityGroupItem.firewallRules;
var firewallRules = firewallRulesArr[0];
console.log("firewallRules");
console.log(firewallRules);
rowCount++;
html += '<tr>'

+ '<td class="overlay hidden column-50px" data-th="">'
+ ' <input type="checkbox" name="securityGroupAssist_chk" id="securityGroupAssist_Raw_' + vSecurityGroupIndex + '" title="" />'
+ ' <input type="hidden" name="securityGroupAssist_id" id="securityGroupAssist_id_' + vSecurityGroupIndex + '" value="' + vSecurityGroupItem.id + '"/>'
+ ' <input type="hidden" name="securityGroupAssist_name" id="securityGroupAssist_name_' + vSecurityGroupIndex + '" value="' + vSecurityGroupItem.name + '"/>'
+ ' <input type="hidden" name="securityGroupAssist_vNetId" id="securityGroupAssist_vNetId_' + vSecurityGroupIndex + '" value="' + vSecurityGroupItem.vNetId + '"/>'

+ ' <input type="hidden" name="securityGroupAssist_connectionName" id="securityGroupAssist_connectionName_' + vSecurityGroupIndex + '" value="' + vSecurityGroupItem.connectionName + '"/>'
+ ' <input type="hidden" name="securityGroupAssist_description" id="securityGroupAssist_description_' + vSecurityGroupIndex + '" value="' + vSecurityGroupItem.description + '"/>'

+ ' <input type="hidden" name="securityGroupAssist_cspSecurityGroupId" id="securityGroupAssist_cspSecurityGroupId_' + vSecurityGroupIndex + '" value="' + vSecurityGroupItem.cspSecurityGroupId + '"/>'
+ ' <input type="hidden" name="securityGroupAssist_cspSecurityGroupName" id="securityGroupAssist_cspSecurityGroupName_' + vSecurityGroupIndex + '" value="' + vSecurityGroupItem.cspSecurityGroupName + '"/>'
+ ' <input type="hidden" name="securityGroupAssist_firewallRules_cidr" id="securityGroupAssist_firewallRules_cidr_' + vSecurityGroupIndex + '" value="' + firewallRules.cidr + '"/>'
+ ' <input type="hidden" name="securityGroupAssist_firewallRules_direction" id="securityGroupAssist_firewallRules_direction_' + vSecurityGroupIndex + '" value="' + firewallRules.direction + '"/>'

+ ' <input type="hidden" name="securityGroup_firewallRules_fromPort" id="securityGroup_firewallRules_fromPort_' + vSecurityGroupIndex + '" value="' + firewallRules.fromPort + '"/>'
+ ' <input type="hidden" name="securityGroup_firewallRules_toPort" id="securityGroup_firewallRules_toPort_' + vSecurityGroupIndex + '" value="' + firewallRules.toPort + '"/>'
+ ' <input type="hidden" name="securityGroup_firewallRules_ipProtocol" id="securityGroup_firewallRules_ipProtocol_' + vSecurityGroupIndex + '" value="' + firewallRules.ipProtocol + '"/>'

+ ' <label for="td_ch1"></label> <span class="ov off"></span>'
+ '</td>'
+ '<td class="btn_mtd ovm td_left" data-th="Name">'
+ vSecurityGroupItem.name
+ '</td>'
+ '<td class="btn_mtd ovm td_left" data-th="ConnectionName">'
+ vSecurityGroupItem.vNetId
+ '</td>'
+ '<td class="overlay hidden" data-th="Description">' + vSecurityGroupItem.description + '</td>'

+ '</tr>'

});
if (rowCount === 0) {
html += '<tr><td class="overlay hidden" data-th="" colspan="4">No Data</td></tr>'
}
$("#assistSecurityGroupList").empty()
$("#assistSecurityGroupList").append(html)

}
}

function getNetworkListCallbackSuccess(caller) {

function getNetworkListCallbackSuccess(caller, data) {
var html = "";
if ( caller == "searchNetworkAssistAtReg"){
//assistVnetList
var calNetIndex = 0;
data.forEach(function (vNetItem, vNetIndex) {
subnetInfoList = vNetItem.subnetInfoList;
subnetInfoList.forEach(function (subnetItem, subnetIndex) {
console.log(subnetItem)

var subnetId = subnetItem.name


html += '<tr onclick="setAssistValue(' + calNetIndex + ');">'
html += ' <input type="hidden" name="vNetAssist_id" id="vNetAssist_id_' + calNetIndex + '" value="' + vNetItem.id + '"/>'
html += ' <input type="hidden" name="vNetAssist_connectionName" id="vNetAssist_connectionName_' + vNetIndex + '" value="' + vNetItem.connectionName + '"/>'
html += ' <input type="hidden" name="vNetAssist_name" id="vNetAssist_name_' + calNetIndex + '" value="' + vNetItem.name + '"/>'
html += ' <input type="hidden" name="vNetAssist_description" id="vNetAssist_description_' + calNetIndex + '" value="' + vNetItem.description + '"/>'
html += ' <input type="hidden" name="vNetAssist_cidrBlock" id="vNetAssist_cidrBlock_' + calNetIndex + '" value="' + vNetItem.cidrBlock + '"/>'
html += ' <input type="hidden" name="vNetAssist_cspVnetName" id="vNetAssist_cspVnetName_' + calNetIndex + '" value="' + vNetItem.cspVNetName + '"/>'

html += ' <input type="hidden" name="vNetAssist_subnetId" id="vNetAssist_subnetId_' + calNetIndex + '" value="' + subnetItem.id + '"/>'
html += ' <input type="hidden" name="vNetAssist_subnetName" id="vNetAssist_subnetName_' + calNetIndex + '" value="' + subnetItem.name + '"/>'

html += ' <td class="overlay hidden" data-th="Name">' + vNetItem.name + '</td>'
html += ' <td class="btn_mtd ovm td_left" data-th="CidrBlock">'
html += ' ' + vNetItem.cidrBlock
html += ' </td>'
html += ' <td class="btn_mtd ovm td_left" data-th="SubnetId">' + subnetItem.id + "<br>" + subnetItem.ipv4_CIDR

html += ' </td>'
html += ' <td class="overlay hidden" data-th="Description">' + vNetItem.description + '</td>'
html += '</tr>'
});
calNetIndex++
});

if (calNetIndex === 0) {
html += '<tr><td class="overlay hidden" data-th="" colspan="4">No Data</td></tr>'
}
$("#assistVnetList").empty()
$("#assistVnetList").append(html)

$("#assistVnetList tr").each(function () {
$selector = $(this)

$selector.on("click", function () {

if ($(this).hasClass("on")) {
$(this).removeClass("on");
} else {
$(this).addClass("on")
$(this).siblings().removeClass("on");
}
})
})
}
}

// 등록된 spec조회 성공 시 table에 뿌려주고, 클릭시 spec 내용 set.
Expand Down Expand Up @@ -653,13 +766,55 @@ function filterSecurityGroupList(keywords, caller) {
}

// pathfinder.js에서 호출하기 때문에 임시로 만들어 둠
function getSecurityGroupCallbackFail (error){
console.log(error)
}
function getSecurityGroupListCallbackFail(error) {

console.log(error)
}

var totalSshKeyListByNamespace = new Array();
function getSshKeyListCallbackSuccess(caller, data) {
totalSshKeyListByNamespace = data;
//totalSshKeyListByNamespace = data;
var html = "";
var rowCount = 0;
data.forEach(function (vSshKeyItem, vSshKeyIndex) {



rowCount++;
html += '<tr onclick="setAssistValue(' + vSshKeyIndex + ');">'
+ ' <input type="hidden" id="sshKeyAssist_id_' + vSshKeyIndex + '" value="' + vSshKeyItem.id + '"/>'
+ ' <input type="hidden" id="sshKeyAssist_name_' + vSshKeyIndex + '" value="' + vSshKeyItem.name + '"/>'
+ ' <input type="hidden" id="sshKeyAssist_connectionName_' + vSshKeyIndex + '" value="' + vSshKeyItem.connectionName + '"/>'
+ ' <input type="hidden" id="sshKeyAssist_description_' + vSshKeyIndex + '" value="' + vSshKeyItem.description + '"/>'
+ '<td class="overlay hidden" data-th="Name">' + vSshKeyItem.name + '</td>'
+ '<td class="overlay hidden" data-th="ConnectionName">' + vSshKeyItem.connectionName + '</td>'
+ '<td class="overlay hidden" data-th="Description">' + vSshKeyItem.description + '</td>'
+ '</td>'
+ '</tr>'

});

if (rowCount === 0) {
html += '<tr><td class="overlay hidden" data-th="" colspan="3">No Data</td></tr>'
}
$("#assistSshKeyList").empty()
$("#assistSshKeyList").append(html)

$("#assistSshKeyList tr").each(function () {
$selector = $(this)

$selector.on("click", function () {

if ($(this).hasClass("on")) {
$(this).removeClass("on");
} else {
$(this).addClass("on")
$(this).siblings().removeClass("on");
}
})
})
}
// 전체 목록에서 filter
function filterSshKeyList(keywords, caller) {
Expand Down
Loading

0 comments on commit 19fe8b9

Please sign in to comment.