Authored by qinchao

项目列表挪到后台

package com.ui.cloud.task;
import com.ui.contants.HttpUriContants;
import com.ui.http.HttpRestClient;
import com.ui.model.BaseResponse;
import com.ui.project.Project;
import com.ui.project.ProjectOnlineResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.stereotype.Component;
import java.util.Map;
import java.util.stream.Collectors;
/**
* Created by craig.qin on 2018/6/14.
* 从后台load出项目列表(java)
*/
@Component
public class ProjectsLoader {
@Autowired
private HttpRestClient httpClient;
private ProjectOnlineResponse projectOnline;
public ProjectOnlineResponse getProjectOnline(){
if(projectOnline==null){
reload();
}
return projectOnline;
}
public ProjectOnlineResponse getProjectOnline(boolean refreshForce){
if(refreshForce){
reload();
}
return getProjectOnline();
}
public void reload(){
ProjectOnlineResponse pro=null;
BaseResponse<ProjectOnlineResponse> response = httpClient.exchangeForpost(HttpUriContants.LOAD_JAVA_PROJECT_ONLINE, new ParameterizedTypeReference<BaseResponse<ProjectOnlineResponse>>() {
}, null);
if(response!=null&&response.getCode()==200){
pro=response.getData();
//把list转成map,放到最后
Map<String,Project> map =pro.getJavaList().stream().collect(Collectors.toMap(Project::getName, Project->Project));
pro.setJavaMap(map);
}
projectOnline=pro;
}
}
... ...
... ... @@ -236,6 +236,7 @@ public class HttpUriContants {
/**
* 工单系统
*/
public static final String LOAD_JAVA_PROJECT_ONLINE = "/releaseWork/loadJavaProjectOnline";
public static final String GET_RELEASEWORKJOBS = "/releaseWork/getReleaseWorkJobs";
public static final String GET_RELEASEWORKJOB_ID = "/releaseWork/getReleaseWorkJob";
public static final String CREATE_RELEASEWORKJOB = "/releaseWork/createReleaseWorkJob";
... ...
... ... @@ -28,9 +28,6 @@ public class ProjectEnvironment {
}
public static List<String> getJavaEnvList(String project) {
return ProjectOnline.getJavaProjectByName(project).getSupportEnvList();
}
public static String getUrl(String envi){
if(map.containsKey(envi)){
... ...
package com.ui.project;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class ProjectOnline {
private final static String JAVA_ENV_QCLOUD_AZ1="qcloud";
private final static String JAVA_ENV_QCLOUD_AZ2="qcloudaz2";
private final static String JAVA_ENV_QCLOUD_AZ3="qcloudaz3";
public final static String JAVA_ENV_ALL=JAVA_ENV_QCLOUD_AZ1+","+JAVA_ENV_QCLOUD_AZ2+","+JAVA_ENV_QCLOUD_AZ3;
///// 暂时只有media有
private final static String JAVA_ENV_QCLOUD_ENV_GRAY="qcloud_gray";
private static List<Project> JAVA_LIST = new ArrayList<>();
private static Map<String,Project> JAVA_MAP = new HashMap<>();
static{
// java 核心服务
JAVA_LIST.add(new Project("1","yohobuy-activity","129","yoho30",JAVA_ENV_ALL, "java 核心服务",true));
JAVA_LIST.add(new Project("1","yohobuy-wechat","248","yoho30",JAVA_ENV_ALL, "java 核心服务",true));
JAVA_LIST.add(new Project("1","yoho-sns","125","yoho30",JAVA_ENV_ALL,"java 核心服务",true));
JAVA_LIST.add(new Project("1","yoho-erp-gateway","977","yoho30",JAVA_ENV_ALL,"java 核心服务",true));
JAVA_LIST.add(new Project("1","yoho-message","123","yoho30",JAVA_ENV_ALL,"java 核心服务",true));
JAVA_LIST.add(new Project("1","uic","439","yoho30",JAVA_ENV_ALL,"java 核心服务",true));
JAVA_LIST.add(new Project("1","yoho-users","134","yoho30",JAVA_ENV_ALL,"java 核心服务",true));
JAVA_LIST.add(new Project("1","yohobuy-resources","122","yoho30",JAVA_ENV_ALL,"java 核心服务",true));
JAVA_LIST.add(new Project("1","yohobuy-promotion","140","yoho30",JAVA_ENV_ALL,"java 核心服务",true));
JAVA_LIST.add(new Project("1","yohobuy-product","143","yoho30",JAVA_ENV_ALL,"java 核心服务",true));
JAVA_LIST.add(new Project("1","yohobuy-order","124","yoho30",JAVA_ENV_ALL,"java 核心服务",true));
JAVA_LIST.add(new Project("1","yohobuy-brower","131","yoho30",JAVA_ENV_ALL,"java 核心服务",true));
JAVA_LIST.add(new Project("1","yohobuy-bigdata","144","yoho30",JAVA_ENV_ALL,"java 核心服务",true));
JAVA_LIST.add(new Project("1","yoho-gateway","126","yoho30",JAVA_ENV_ALL,"java 核心服务",true));
JAVA_LIST.add(new Project("1","yohobuy-risk","932","yoho30",JAVA_ENV_ALL,"java 核心服务",true));
//只有qcloud : java服务-单中心
JAVA_LIST.add(new Project("1","yoho-push","137","yoho30",JAVA_ENV_QCLOUD_AZ1,"java服务-单中心",true));
JAVA_LIST.add(new Project("1","cms_push","514","yoho30",JAVA_ENV_QCLOUD_AZ1,"java服务-单中心",true));
JAVA_LIST.add(new Project("1","yoho-social","353","yoho30",JAVA_ENV_QCLOUD_AZ1,"java服务-单中心",true));
JAVA_LIST.add(new Project("1","yohobuy-union","133","yoho30",JAVA_ENV_QCLOUD_AZ1,"java服务-单中心",true));
JAVA_LIST.add(new Project("1","yohobuy-crm","275","yoho30",JAVA_ENV_QCLOUD_AZ1,"java服务-单中心",true));
JAVA_LIST.add(new Project("1","yohobuy-task","138","yoho30",JAVA_ENV_QCLOUD_AZ1,"java服务-单中心",true));
JAVA_LIST.add(new Project("1","yoho-message-controller","684","yoho30",JAVA_ENV_QCLOUD_AZ1,"java服务-单中心",true));
JAVA_LIST.add(new Project("1","yoho-message-sender","685","yoho30",JAVA_ENV_QCLOUD_AZ1,"java服务-单中心",true));
//只有灰度环境: 媒体java (灰度)
JAVA_LIST.add(new Project("1", "yoho-now", "690", "YOHONow",JAVA_ENV_QCLOUD_ENV_GRAY,"媒体java (灰度)",false));
JAVA_LIST.add(new Project("1","yoho-mars","737","media",JAVA_ENV_QCLOUD_ENV_GRAY,"媒体java (灰度)",false));
JAVA_LIST.add(new Project("1","yohomars-platform","764","media",JAVA_ENV_QCLOUD_ENV_GRAY,"媒体java (灰度)",false));
JAVA_LIST.add(new Project("1","yohonow-platform","775","media",JAVA_ENV_QCLOUD_ENV_GRAY,"媒体java (灰度)",false));
//JAVA_LIST.add(new Project("1","yoho-cobar","461","yoho30"));
//JAVA_LIST.add(new Project("1","yohobuy-global","679","yoho30"));
//JAVA_LIST.add(new Project("1","mars_push","494","yoho30"));
//JAVA_LIST.add(new Project("1","yoho-union-recomand","789","yoho30"));
//只有qcloud、 qcloud灰度。 线下店java服务
JAVA_LIST.add(new Project("1","yohobuy-shops","490","yoho30",JAVA_ENV_QCLOUD_AZ1+","+JAVA_ENV_QCLOUD_ENV_GRAY,"线下店java服务",false));
JAVA_LIST.add(new Project("1","yohobuy-portal-gateway","557","yoho30",JAVA_ENV_QCLOUD_AZ1+","+JAVA_ENV_QCLOUD_ENV_GRAY,"线下店java服务",false));
JAVA_LIST.add(new Project("1","yohobuy-extendstore","852","yoho30",JAVA_ENV_QCLOUD_AZ1+","+JAVA_ENV_QCLOUD_ENV_GRAY,"线下店java服务",false));
JAVA_LIST.add(new Project("2","yoho-search-service","12","yoho-search",JAVA_ENV_QCLOUD_AZ1+","+JAVA_ENV_QCLOUD_AZ2,"",true));
JAVA_LIST.add(new Project("2","yoho-search-consumer","8","yoho-search",JAVA_ENV_QCLOUD_AZ1+","+JAVA_ENV_QCLOUD_AZ2,"",true));
JAVA_LIST.add(new Project("2","yoho-search-producer","7","yoho-search",JAVA_ENV_QCLOUD_AZ1+","+JAVA_ENV_QCLOUD_AZ2,"",true));
JAVA_LIST.add(new Project("2","yoho-search-adaptor","13","yoho-search",JAVA_ENV_QCLOUD_AZ1+","+JAVA_ENV_QCLOUD_AZ2,"",true));
JAVA_LIST.add(new Project("2","yohomars-search-service","554","yoho-search",JAVA_ENV_QCLOUD_AZ1,"",true));
JAVA_LIST.add(new Project("3","yohobuy-platform","110","platform",JAVA_ENV_QCLOUD_AZ1+","+JAVA_ENV_QCLOUD_ENV_GRAY,"",true));
//把list转成map,放到最后
JAVA_MAP=JAVA_LIST.stream().collect(Collectors.toMap(Project::getName,Project->Project));
}
public static List<Project> getJavaList() {
return JAVA_LIST;
}
public static Project getJavaProjectByName(String projectName) {
return JAVA_MAP.get(projectName);
}
/**
* 中心切换之后,需要
*/
public static List<Project> getNeedRestartJavaList() {
return JAVA_LIST.stream().filter(p->p.isNeedRestartAfterSwitch()).collect(Collectors.toList());
}
}
package com.ui.project;
import lombok.Data;
import java.util.List;
import java.util.Map;
@Data
public class ProjectOnlineResponse {
//java 环境列表串
private String javaEnvAll;
private List<Project> javaList;
private Map<String,Project> javaMap;
}
... ...
... ... @@ -5,25 +5,28 @@ import com.alibaba.fastjson.JSONArray;
import com.ui.contants.HttpUriContants;
import com.ui.http.HttpRestClient;
import com.ui.model.BaseResponse;
import com.ui.model.domain.BuildMessage;
import com.ui.model.domain.DockerProjectModel;
import com.ui.model.req.BuildRequest;
import com.ui.model.req.DockerInfoReq;
import com.ui.model.req.DockerJenkinsReq;
import com.ui.model.req.User;
import com.ui.model.req.*;
import com.ui.project.ProjectEnvironment;
import com.ui.project.ProjectOnline;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import javax.annotation.PostConstruct;
import javax.servlet.http.HttpSession;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
... ...
... ... @@ -3,6 +3,7 @@ package com.ui.ctrl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ui.cloud.task.ProjectsLoader;
import com.ui.contants.AlarmGroupContants;
import com.ui.contants.HttpUriContants;
import com.ui.ctrl.util.ReleaseCheck;
... ... @@ -10,9 +11,10 @@ import com.ui.http.HttpRestClient;
import com.ui.model.BaseResponse;
import com.ui.model.domain.BuildMessage;
import com.ui.model.req.*;
import com.ui.project.Project;
import com.ui.project.ProjectEnvironment;
import com.ui.project.ProjectMutex;
import com.ui.project.ProjectOnline;
import com.ui.project.ProjectOnlineResponse;
import lombok.Data;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.lang.StringUtils;
... ... @@ -35,11 +37,15 @@ import java.util.*;
public class ProjectBuildCtrl {
Logger log = LoggerFactory.getLogger(ProjectBuildCtrl.class);
//需要特殊处理的项目
//private final String PROJECT_NAME_YOHO_SEARCH_SERVICE="yoho-search-service";
private final List<String> lb_proejct_list=new ArrayList<String>() {{
//add("yoho-search-service");
//add("uic");
}};
@Autowired
private ProjectsLoader projectsLoader;
@Autowired
private HttpRestClient httpRestClient;
... ... @@ -93,16 +99,17 @@ public class ProjectBuildCtrl {
}
}
model.addAttribute("environments", Arrays.asList(ProjectOnline.JAVA_ENV_ALL.split(",")));
model.addAttribute("environments", Arrays.asList(projectsLoader.getProjectOnline().getJavaEnvAll().split(",")));
ModelAndView mv=new ModelAndView("project/project");
return mv;
}
@RequestMapping("/toHistory")
public ModelAndView toHistory(Model model) {
model.addAttribute("environments", Arrays.asList(ProjectOnline.JAVA_ENV_ALL.split(",")));
ProjectOnlineResponse projectOnline=projectsLoader.getProjectOnline(true);
model.addAttribute("environments", Arrays.asList(projectOnline.getJavaEnvAll().split(",")));
model.addAttribute("projects", ProjectOnline.getJavaList());
model.addAttribute("projects", projectOnline.getJavaList());
return new ModelAndView("project/history");
}
... ... @@ -116,7 +123,7 @@ public class ProjectBuildCtrl {
@ResponseBody
public String getProjects() {
try {
return JSONArray.toJSON(ProjectOnline.getJavaList()).toString();
return JSONArray.toJSON(projectsLoader.getProjectOnline().getJavaList()).toString();
} catch (Exception ex) {
return "failed";
}
... ... @@ -141,9 +148,10 @@ public class ProjectBuildCtrl {
}
public List<String> getJavaProjectEnvList(List<String> projArray) {
Map<String,Project> javaMap=projectsLoader.getProjectOnline().getJavaMap();
List<String> envs=new ArrayList<>();
for(int i=0;i<projArray.size();i++){
List<String> ls= ProjectEnvironment.getJavaEnvList(projArray.get(i));
List<String> ls= javaMap.get(projArray.get(i)).getSupportEnvList();
if(i==0){
envs.addAll(ls);
}else{
... ...
package com.ui.ctrl;
import com.alibaba.fastjson.JSONArray;
import com.google.common.collect.Lists;
import com.ui.contants.HttpUriContants;
import com.ui.http.HttpRestClient;
import com.ui.model.BaseResponse;
import com.ui.project.ProjectOnline;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
... ... @@ -18,7 +16,10 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 限流调整
... ...
... ... @@ -3,13 +3,17 @@ package com.ui.ctrl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ui.cloud.task.ProjectsLoader;
import com.ui.contants.HttpUriContants;
import com.ui.contants.ProjectConstant;
import com.ui.http.HttpRestClient;
import com.ui.model.BaseResponse;
import com.ui.model.domain.DockerProjectModel;
import com.ui.model.req.*;
import com.ui.project.*;
import com.ui.project.Platform;
import com.ui.project.Project;
import com.ui.project.ProjectEnvironment;
import com.ui.project.ProjectMutex;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -19,7 +23,6 @@ import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
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 org.springframework.web.servlet.ModelAndView;
... ... @@ -46,6 +49,9 @@ public class WorkSystemCtrl {
ProjectBuildCtrl projectBuildCtrl;
@Autowired
private ProjectsLoader projectsLoader;
@Autowired
HttpRestClient httpRestClient;
@RequestMapping("/toAddWork")
... ... @@ -110,7 +116,7 @@ public class WorkSystemCtrl {
@ResponseBody
public List<Project> getProjectsByPlatform(String platform,String projectType) {
if (Platform.JAVA.equals(platform)) {
return ProjectOnline.getJavaList();
return projectsLoader.getProjectOnline().getJavaList();
} else if (Platform.PHP.equals(platform)) {
String result = httpRestClient.get("http://"+ ProjectConstant.DEPLOY_IP+":8883/php/getProjects", String.class, null);
return JSON.parseObject(result,List.class);
... ...
... ... @@ -3,22 +3,20 @@ package com.ui.ctrl.app;
import com.alibaba.fastjson.JSONArray;
import com.ui.app.common.ErrorCode;
import com.ui.app.req.*;
import com.ui.app.resp.NodeBuildResp;
import com.ui.app.resp.NodeBuildState;
import com.ui.contants.HttpUriContants;
import com.ui.cloud.task.ProjectsLoader;
import com.ui.http.HttpRestClient;
import com.ui.model.BaseResponse;
import com.ui.model.domain.BuildMessage;
import com.ui.model.req.BuildRequest;
import com.ui.project.Project;
import com.ui.project.ProjectEnvironment;
import com.ui.project.ProjectOnline;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.web.bind.annotation.*;
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.RestController;
import java.util.HashMap;
import java.util.LinkedList;
... ... @@ -38,6 +36,9 @@ public class AppProjectBuildCtrl {
@Autowired
private HttpRestClient httpClient;
@Autowired
private ProjectsLoader projectsLoader;
/**
* 获取所有项目
*
... ... @@ -46,9 +47,9 @@ public class AppProjectBuildCtrl {
@RequestMapping(value = "app_getbuildprojectlist", method = RequestMethod.POST)
public BaseResponse getProjects(@RequestBody AppBaseReq appBaseReq) {
BaseResponse baseResponse = new BaseResponse();
baseResponse.setData(ProjectOnline.getJavaList());
//baseResponse.setData(projectsLoader.getProjectOnline().getJavaList());
List<String> stringList = new LinkedList<>();
for (Project project : ProjectOnline.getJavaList()) {
for (Project project : projectsLoader.getProjectOnline().getJavaList()) {
stringList.add(project.getName());
}
baseResponse.setData(stringList);
... ...
package com.ui.ctrl.app;
import com.alibaba.fastjson.JSONArray;
import com.ui.User.UserAuthLocal;
import com.ui.app.common.ErrorCode;
import com.ui.app.req.*;
import com.ui.app.req.AppBaseReq;
import com.ui.app.req.HandleWorkJob;
import com.ui.app.req.WorkJob;
import com.ui.contants.HttpUriContants;
import com.ui.http.HttpRestClient;
import com.ui.model.BaseResponse;
import com.ui.model.domain.BuildMessage;
import com.ui.model.rep.PageResponse;
import com.ui.model.req.*;
import com.ui.project.Project;
import com.ui.project.ProjectEnvironment;
import com.ui.project.ProjectOnline;
import com.ui.model.req.HandledJob;
import com.ui.model.req.PendingJob;
import com.ui.model.req.User;
import com.ui.model.req.WorkSystemReq;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -21,12 +21,6 @@ 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.RestController;
import org.springframework.web.servlet.ModelAndView;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
/**
... ...