Skip to content

Commit

Permalink
portal文本初步编辑
Browse files Browse the repository at this point in the history
  • Loading branch information
lepdou committed Apr 12, 2016
1 parent a3ba41c commit 2dc30c7
Show file tree
Hide file tree
Showing 16 changed files with 696 additions and 64 deletions.
Expand Up @@ -4,13 +4,16 @@

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
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 com.ctrip.apollo.biz.entity.Item;
import com.ctrip.apollo.biz.service.ItemService;
import com.ctrip.apollo.biz.service.ViewService;
import com.ctrip.apollo.biz.utils.BeanUtils;
import com.ctrip.apollo.core.dto.ItemChangeSets;
import com.ctrip.apollo.core.dto.ItemDTO;

@RestController
Expand All @@ -24,8 +27,8 @@ public class ItemController {

@RequestMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items")
public List<ItemDTO> findItems(@PathVariable("appId") String appId,
@PathVariable("clusterName") String clusterName,
@PathVariable("namespaceName") String namespaceName) {
@PathVariable("clusterName") String clusterName,
@PathVariable("namespaceName") String namespaceName) {
List<Item> items = viewService.findItems(appId, clusterName, namespaceName);
return BeanUtils.batchTransform(ItemDTO.class, items);
}
Expand All @@ -35,4 +38,5 @@ public ItemDTO findOne(@PathVariable("itemId") long itemId) {
Item item = itemService.findOne(itemId);
return BeanUtils.transfrom(ItemDTO.class, item);
}

}
@@ -0,0 +1,70 @@
package com.ctrip.apollo.core.dto;

import java.util.LinkedList;
import java.util.List;

/**
* storage cud result
*/
public class ItemChangeSets {

private String modifyBy;
private List<ItemDTO> createItems;
private List<ItemDTO> updateItems;
private List<ItemDTO> deletedItems;

public void addCreatedItem(ItemDTO item) {
if (createItems == null) {
createItems = new LinkedList<>();
}
createItems.add(item);
}

public void addupdateItem(ItemDTO item) {
if (updateItems == null) {
updateItems = new LinkedList<>();
}
updateItems.add(item);
}

public void addDeletedItem(ItemDTO item) {
if (deletedItems == null) {
deletedItems = new LinkedList<>();
}
deletedItems.add(item);
}


public List<ItemDTO> getCreateItems() {
return createItems;
}

public List<ItemDTO> getUpdateItems() {
return updateItems;
}

public List<ItemDTO> getDeletedItems() {
return deletedItems;
}

public void setCreateItems(List<ItemDTO> createItems) {
this.createItems = createItems;
}

public void setUpdateItems(List<ItemDTO> updateItems) {
this.updateItems = updateItems;
}

public void setDeletedItems(List<ItemDTO> deletedItems) {
this.deletedItems = deletedItems;
}

public String getModifyBy() {
return modifyBy;
}

public void setModifyBy(String modifyBy) {
this.modifyBy = modifyBy;
}

}
13 changes: 13 additions & 0 deletions apollo-core/src/main/java/com/ctrip/apollo/core/dto/ItemDTO.java
Expand Up @@ -82,4 +82,17 @@ public Date getDataChangeLastModifiedTime() {
public void setDataChangeLastModifiedTime(Date dataChangeLastModifiedTime) {
this.dataChangeLastModifiedTime = dataChangeLastModifiedTime;
}

@Override
public String toString() {
return "ItemDTO{" +
"id=" + id +
", namespaceId=" + namespaceId +
", key='" + key + '\'' +
", value='" + value + '\'' +
", comment='" + comment + '\'' +
", dataChangeLastModifiedBy='" + dataChangeLastModifiedBy + '\'' +
", dataChangeLastModifiedTime=" + dataChangeLastModifiedTime +
'}';
}
}
@@ -0,0 +1,31 @@
package com.ctrip.apollo.core.entity;

/**
* declare biz code and simple msg. maybe http response code is 200.
*/
public class SimpleRestfulResponse {

private int code;
private String msg;

public SimpleRestfulResponse(int code, String msg){
this.code = code;
this.msg = msg;
}

public int getCode() {
return code;
}

public void setCode(int code) {
this.code = code;
}

public String getMsg() {
return msg;
}

public void setMsg(String msg) {
this.msg = msg;
}
}
Expand Up @@ -11,75 +11,89 @@

import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;


@Service
public class AdminServiceAPI {

@Service
public static class AppAPI extends API {

public static String APP_API = "/apps";

public AppDTO[] getApps(Apollo.Env env) {
return restTemplate.getForObject(getAdminServiceHost(env) + APP_API, AppDTO[].class);
public List<AppDTO> getApps(Apollo.Env env) {
return Arrays.asList(restTemplate.getForObject(getAdminServiceHost(env) + APP_API, AppDTO[].class));
}
}


@Service
public static class NamespaceAPI extends API {

public NamespaceDTO[] findGroupsByAppAndCluster(String appId, Apollo.Env env,
public List<NamespaceDTO> findGroupsByAppAndCluster(String appId, Apollo.Env env,
String clusterName) {
if (StringUtils.isContainEmpty(appId, clusterName)) {
return null;
}

return restTemplate.getForObject(
return Arrays.asList(restTemplate.getForObject(
getAdminServiceHost(env) + String.format("apps/%s/clusters/%s/namespaces", appId, clusterName),
NamespaceDTO[].class);
NamespaceDTO[].class));
}
}

@Service
public static class ItemAPI extends API {

public ItemDTO[] findItems(String appId, Apollo.Env env, String clusterName, String namespace) {
if (StringUtils.isContainEmpty(appId, clusterName, namespace)) {
public NamespaceDTO loadNamespace(String appId, Apollo.Env env,
String clusterName, String namespaceName) {
if (StringUtils.isContainEmpty(appId, clusterName, namespaceName)) {
return null;
}

return restTemplate.getForObject(getAdminServiceHost(env) + String
.format("apps/%s/clusters/%s/namespaces/%s/items", appId,
clusterName, namespace),
ItemDTO[].class);
return restTemplate.getForObject(getAdminServiceHost(env) +
String.format("apps/%s/clusters/%s/namespaces/%s", appId, clusterName,
namespaceName), NamespaceDTO.class);
}
}

}
@Service
public static class ItemAPI extends API {

@Service
public static class ClusterAPI extends API {
public List<ItemDTO> findItems(String appId, Apollo.Env env, String clusterName, String namespace) {
if (StringUtils.isContainEmpty(appId, clusterName, namespace)) {
return null;
}

public ClusterDTO[] findClustersByApp(String appId, Apollo.Env env) {
if (StringUtils.isContainEmpty(appId)) {
return null;
return Arrays.asList(restTemplate.getForObject(getAdminServiceHost(env) + String
.format("apps/%s/clusters/%s/namespaces/%s/items", appId,
clusterName, namespace),
ItemDTO[].class));
}

return restTemplate.getForObject(getAdminServiceHost(env) + String.format("apps/%s/clusters", appId),
ClusterDTO[].class);
}
}

@Service
public static class ReleaseAPI extends API{
@Service
public static class ClusterAPI extends API {

public ReleaseDTO loadLatestRelease(String appId, Apollo.Env env, String clusterName, String namespace){
if (StringUtils.isContainEmpty(appId, clusterName, namespace)){
return null;
public List<ClusterDTO> findClustersByApp(String appId, Apollo.Env env) {
if (StringUtils.isContainEmpty(appId)) {
return null;
}

return Arrays.asList(restTemplate.getForObject(getAdminServiceHost(env) + String.format("apps/%s/clusters", appId),
ClusterDTO[].class));
}
return restTemplate.getForObject(getAdminServiceHost(env) + String
.format("apps/%s/clusters/%s/namespaces/%s/releases/latest", appId,
clusterName, namespace), ReleaseDTO.class);
}
}

}
@Service
public static class ReleaseAPI extends API {

public ReleaseDTO loadLatestRelease(String appId, Apollo.Env env, String clusterName, String namespace) {
if (StringUtils.isContainEmpty(appId, clusterName, namespace)) {
return null;
}
return restTemplate.getForObject(getAdminServiceHost(env) + String
.format("apps/%s/clusters/%s/namespaces/%s/releases/latest", appId,
clusterName, namespace), ReleaseDTO.class);
}
}

}
Expand Up @@ -2,13 +2,19 @@


import com.ctrip.apollo.Apollo;
import com.ctrip.apollo.core.entity.SimpleRestfulResponse;
import com.ctrip.apollo.core.utils.StringUtils;
import com.ctrip.apollo.portal.entity.NamespaceVO;
import com.ctrip.apollo.portal.entity.SimpleResponse;
import com.ctrip.apollo.portal.service.ConfigService;
import com.ctrip.apollo.portal.service.txtresolver.TextResolverResult;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
Expand All @@ -21,11 +27,30 @@ public class ConfigController {
private ConfigService configService;

@RequestMapping("/apps/{appId}/env/{env}/clusters/{clusterName}/namespaces")
public List<NamespaceVO> findNamespaces(@PathVariable String appId, @PathVariable String env, @PathVariable String clusterName){
if (StringUtils.isContainEmpty(appId, env, clusterName)){
public List<NamespaceVO> findNamespaces(@PathVariable String appId, @PathVariable String env,
@PathVariable String clusterName) {
if (StringUtils.isContainEmpty(appId, env, clusterName)) {
throw new IllegalArgumentException("app id and cluster name can not be empty");
}

return configService.findNampspaces(appId, Apollo.Env.valueOf(env), clusterName);
}

@RequestMapping(value = "/apps/{appId}/env/{env}/clusters/{clusterName}/namespaces/{namespaceName}/modify", method = RequestMethod.GET)
public ResponseEntity<SimpleRestfulResponse> modifyConfigs(@PathVariable String appId, @PathVariable String env,
@PathVariable String clusterName,
@PathVariable String namespaceName,
String configText) {
TextResolverResult result =
configService.resolve(appId, Apollo.Env.valueOf(env), clusterName, namespaceName, configText);
TextResolverResult.Code code = result.getCode();

if (code == TextResolverResult.Code.OK) {
return ResponseEntity.status(HttpStatus.OK).body(new SimpleRestfulResponse(code.getValue(), "success"));
} else {
return ResponseEntity.status(HttpStatus.OK)
.body(new SimpleRestfulResponse(code.getValue(), code.getBaseMsg() + result.getExtensionMsg()));
}
}

}
@@ -0,0 +1,28 @@
package com.ctrip.apollo.portal.entity;

public class SimpleResponse {

private int code;
private String msg;

public SimpleResponse(int code, String msg){
this.code = code;
this.msg = msg;
}

public int getCode() {
return code;
}

public void setCode(int code) {
this.code = code;
}

public String getMsg() {
return msg;
}

public void setMsg(String msg) {
this.msg = msg;
}
}
Expand Up @@ -17,7 +17,7 @@ public class ClusterService {
private AdminServiceAPI.ClusterAPI clusterAPI;

public List<ClusterDTO> findClusters(Apollo.Env env, String appId){
return Arrays.asList(clusterAPI.findClustersByApp(appId, env));
return clusterAPI.findClustersByApp(appId, env);
}

}

0 comments on commit 2dc30c7

Please sign in to comment.