package com.ctrip.xpipe.redis.console.controller.api;

import com.ctrip.xpipe.redis.console.controller.AbstractConsoleController;
import com.ctrip.xpipe.redis.console.model.DcModel;
import com.ctrip.xpipe.redis.console.model.DcTbl;
import com.ctrip.xpipe.redis.console.service.DcService;
import com.ctrip.xpipe.spring.AbstractController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author taotaotu
 * May 23, 2019
 */

@RestController
@RequestMapping(AbstractController.API_PREFIX)
public class DcApiController extends AbstractConsoleController {

    @Autowired
    private DcService dcService;

    @RequestMapping(value = "/dc", method = RequestMethod.POST)
    public RetMessage addDc(HttpServletRequest request, @RequestBody DcModel dcModel){

        logger.info("[DcApiController][addDc]request ip:{}, create a new dc, zoneId:{}, dc_name:{}, description:{}",request.getRemoteHost(),
                dcModel.getZone_id(), dcModel.getDc_name(), dcModel.getDescription());

        try {
            dcService.insertWithPartField(dcModel.getZone_id(), dcModel.getDc_name(), dcModel.getDescription());
        }catch (Exception e){
            logger.error("[DcApiController][addDc]add dc exception!", e);
            return RetMessage.createFailMessage(e.getMessage());
        }

        return RetMessage.createSuccessMessage();
    }

}

@@ -119,24 +119,148 @@
 Controller;%0A
+import com.ctrip.xpipe.redis.console.migration.status.ClusterStatus;%0Aimport com.ctrip.xpipe.redis.console.model.ClusterTbl;%0A
 import com.c
@@ -345,24 +345,85 @@
 odel.DcTbl;%0A
+import com.ctrip.xpipe.redis.console.service.ClusterService;%0A
 import com.c
@@ -675,16 +675,39 @@
 Request;
+%0Aimport java.util.List;
 %0A%0A/**%0A *
@@ -923,16 +923,79 @@
 rvice;%0A%0A
+    @Autowired%0A    private ClusterService clusterService;%0A    %0A
     @Req
@@ -1731,10 +1731,853 @@
 %0A    %7D%0A%0A
+    @RequestMapping(value = %22/debug/reset/clusters/%7BdcName%7D%22, method = RequestMethod.POST)%0A    public RetMessage resetDcClusters(HttpServletRequest request, @PathVariable String dcName)%7B%0A%0A        logger.info(%22%5BresetDcClusters%5D%5BaddDc%5Drequest ip:%7B%7D%22, request.getRemoteHost());%0A%0A        try %7B%0A            List%3CClusterTbl%3E clusters = clusterService.findAllClustersByDcName(dcName);%0A            for (ClusterTbl cluster : clusters) %7B%0A                if (ClusterStatus.isSameClusterStatus(cluster.getStatus(), ClusterStatus.Normal)) %7B%0A                    continue;%0A                %7D%0A                clusterService.updateStatusById(cluster.getId(), ClusterStatus.Normal);%0A            %7D%0A        %7D catch (Exception e) %7B%0A            return RetMessage.createFailMessage(e.getMessage());%0A        %7D%0A%0A        return RetMessage.createSuccessMessage();%0A    %7D%0A%0A
 %7D%0A

add debug api