Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
apollo
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
apollo
Commits
17261b68
Commit
17261b68
authored
Oct 28, 2019
by
Jared Tan
Committed by
kezhenxu94
Oct 28, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support dataChangeLastModifiedBy display after edited in a namespace (#2680)
parent
2b48b3d0
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
117 additions
and
11 deletions
+117
-11
apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/ItemController.java
...mework/apollo/adminservice/controller/ItemController.java
+20
-2
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/utils/ConfigChangeContentBuilder.java
...ramework/apollo/biz/utils/ConfigChangeContentBuilder.java
+17
-4
apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/MockBeanFactory.java
.../java/com/ctrip/framework/apollo/biz/MockBeanFactory.java
+11
-0
apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/utils/ConfigChangeContentBuilderTest.java
...work/apollo/biz/utils/ConfigChangeContentBuilderTest.java
+49
-0
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/api/AdminServiceAPI.java
...om/ctrip/framework/apollo/portal/api/AdminServiceAPI.java
+7
-0
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/bo/ItemBO.java
...a/com/ctrip/framework/apollo/portal/entity/bo/ItemBO.java
+1
-1
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ItemService.java
...om/ctrip/framework/apollo/portal/service/ItemService.java
+4
-0
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java
...rip/framework/apollo/portal/service/NamespaceService.java
+8
-4
No files found.
apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/ItemController.java
View file @
17261b68
...
@@ -12,6 +12,11 @@ import com.ctrip.framework.apollo.common.dto.ItemDTO;
...
@@ -12,6 +12,11 @@ import com.ctrip.framework.apollo.common.dto.ItemDTO;
import
com.ctrip.framework.apollo.common.exception.BadRequestException
;
import
com.ctrip.framework.apollo.common.exception.BadRequestException
;
import
com.ctrip.framework.apollo.common.exception.NotFoundException
;
import
com.ctrip.framework.apollo.common.exception.NotFoundException
;
import
com.ctrip.framework.apollo.common.utils.BeanUtils
;
import
com.ctrip.framework.apollo.common.utils.BeanUtils
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.stream.Collectors
;
import
org.springframework.web.bind.annotation.DeleteMapping
;
import
org.springframework.web.bind.annotation.DeleteMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PathVariable
;
...
@@ -21,8 +26,6 @@ import org.springframework.web.bind.annotation.RequestBody;
...
@@ -21,8 +26,6 @@ import org.springframework.web.bind.annotation.RequestBody;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.List
;
@RestController
@RestController
public
class
ItemController
{
public
class
ItemController
{
...
@@ -135,6 +138,21 @@ public class ItemController {
...
@@ -135,6 +138,21 @@ public class ItemController {
return
BeanUtils
.
batchTransform
(
ItemDTO
.
class
,
itemService
.
findItemsWithOrdered
(
appId
,
clusterName
,
namespaceName
));
return
BeanUtils
.
batchTransform
(
ItemDTO
.
class
,
itemService
.
findItemsWithOrdered
(
appId
,
clusterName
,
namespaceName
));
}
}
@GetMapping
(
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items/deleted"
)
public
List
<
ItemDTO
>
findDeletedItems
(
@PathVariable
(
"appId"
)
String
appId
,
@PathVariable
(
"clusterName"
)
String
clusterName
,
@PathVariable
(
"namespaceName"
)
String
namespaceName
)
{
List
<
Commit
>
commits
=
commitService
.
find
(
appId
,
clusterName
,
namespaceName
,
null
);
if
(
Objects
.
nonNull
(
commits
))
{
List
<
Item
>
deletedItems
=
commits
.
stream
()
.
map
(
item
->
ConfigChangeContentBuilder
.
convertJsonString
(
item
.
getChangeSets
()).
getDeleteItems
())
.
flatMap
(
Collection:
:
stream
)
.
collect
(
Collectors
.
toList
());
return
BeanUtils
.
batchTransform
(
ItemDTO
.
class
,
deletedItems
);
}
return
Collections
.
emptyList
();
}
@GetMapping
(
"/items/{itemId}"
)
@GetMapping
(
"/items/{itemId}"
)
public
ItemDTO
get
(
@PathVariable
(
"itemId"
)
long
itemId
)
{
public
ItemDTO
get
(
@PathVariable
(
"itemId"
)
long
itemId
)
{
Item
item
=
itemService
.
findOne
(
itemId
);
Item
item
=
itemService
.
findOne
(
itemId
);
...
...
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/utils/ConfigChangeContentBuilder.java
View file @
17261b68
package
com
.
ctrip
.
framework
.
apollo
.
biz
.
utils
;
package
com
.
ctrip
.
framework
.
apollo
.
biz
.
utils
;
import
com.google.gson.Gson
;
import
com.google.gson.GsonBuilder
;
import
com.ctrip.framework.apollo.biz.entity.Item
;
import
com.ctrip.framework.apollo.biz.entity.Item
;
import
com.ctrip.framework.apollo.core.utils.StringUtils
;
import
com.ctrip.framework.apollo.core.utils.StringUtils
;
import
com.google.gson.Gson
;
import
com.google.gson.GsonBuilder
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.LinkedList
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.List
;
...
@@ -84,4 +82,19 @@ public class ConfigChangeContentBuilder {
...
@@ -84,4 +82,19 @@ public class ConfigChangeContentBuilder {
return
target
;
return
target
;
}
}
public
static
ConfigChangeContentBuilder
convertJsonString
(
String
content
)
{
return
gson
.
fromJson
(
content
,
ConfigChangeContentBuilder
.
class
);
}
public
List
<
Item
>
getCreateItems
()
{
return
createItems
;
}
public
List
<
ItemPair
>
getUpdateItems
()
{
return
updateItems
;
}
public
List
<
Item
>
getDeleteItems
()
{
return
deleteItems
;
}
}
}
apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/MockBeanFactory.java
View file @
17261b68
package
com
.
ctrip
.
framework
.
apollo
.
biz
;
package
com
.
ctrip
.
framework
.
apollo
.
biz
;
import
com.ctrip.framework.apollo.biz.entity.Item
;
import
com.ctrip.framework.apollo.biz.entity.Namespace
;
import
com.ctrip.framework.apollo.biz.entity.Namespace
;
import
com.ctrip.framework.apollo.biz.entity.Release
;
import
com.ctrip.framework.apollo.biz.entity.Release
;
import
com.ctrip.framework.apollo.biz.entity.ServerConfig
;
import
com.ctrip.framework.apollo.biz.entity.ServerConfig
;
...
@@ -51,4 +52,14 @@ public class MockBeanFactory {
...
@@ -51,4 +52,14 @@ public class MockBeanFactory {
return
instance
;
return
instance
;
}
}
public
static
Item
mockItem
(
long
id
,
long
namespaceId
,
String
itemKey
,
String
itemValue
,
int
lineNum
)
{
Item
item
=
new
Item
();
item
.
setId
(
id
);
item
.
setKey
(
itemKey
);
item
.
setValue
(
itemValue
);
item
.
setLineNum
(
lineNum
);
item
.
setNamespaceId
(
namespaceId
);
return
item
;
}
}
}
apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/utils/ConfigChangeContentBuilderTest.java
0 → 100644
View file @
17261b68
package
com
.
ctrip
.
framework
.
apollo
.
biz
.
utils
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
com.ctrip.framework.apollo.biz.MockBeanFactory
;
import
com.ctrip.framework.apollo.biz.entity.Item
;
import
org.junit.Before
;
import
org.junit.Test
;
/**
* @author jian.tan
*/
public
class
ConfigChangeContentBuilderTest
{
private
final
ConfigChangeContentBuilder
configChangeContentBuilder
=
new
ConfigChangeContentBuilder
();
private
String
configString
;
@Before
public
void
initConfig
()
{
Item
createdItem
=
MockBeanFactory
.
mockItem
(
1
,
1
,
"timeout"
,
"100"
,
1
);
Item
updatedItem
=
MockBeanFactory
.
mockItem
(
1
,
1
,
"timeout"
,
"1001"
,
1
);
configChangeContentBuilder
.
createItem
(
createdItem
);
configChangeContentBuilder
.
updateItem
(
createdItem
,
updatedItem
);
configChangeContentBuilder
.
deleteItem
(
updatedItem
);
configString
=
configChangeContentBuilder
.
build
();
}
@Test
public
void
testHasContent
()
{
assertTrue
(
configChangeContentBuilder
.
hasContent
());
}
@Test
public
void
testConvertJsonString
()
{
ConfigChangeContentBuilder
contentBuilder
=
ConfigChangeContentBuilder
.
convertJsonString
(
configString
);
assertNotNull
(
contentBuilder
.
getCreateItems
());
assertNotNull
(
contentBuilder
.
getUpdateItems
().
get
(
0
).
oldItem
);
assertNotNull
(
contentBuilder
.
getUpdateItems
().
get
(
0
).
newItem
);
assertNotNull
(
contentBuilder
.
getDeleteItems
());
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/api/AdminServiceAPI.java
View file @
17261b68
...
@@ -159,6 +159,13 @@ public class AdminServiceAPI {
...
@@ -159,6 +159,13 @@ public class AdminServiceAPI {
return
Arrays
.
asList
(
itemDTOs
);
return
Arrays
.
asList
(
itemDTOs
);
}
}
public
List
<
ItemDTO
>
findDeletedItems
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespaceName
)
{
ItemDTO
[]
itemDTOs
=
restTemplate
.
get
(
env
,
"apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items/deleted"
,
ItemDTO
[].
class
,
appId
,
clusterName
,
namespaceName
);
return
Arrays
.
asList
(
itemDTOs
);
}
public
ItemDTO
loadItem
(
Env
env
,
String
appId
,
String
clusterName
,
String
namespaceName
,
String
key
)
{
public
ItemDTO
loadItem
(
Env
env
,
String
appId
,
String
clusterName
,
String
namespaceName
,
String
key
)
{
return
restTemplate
.
get
(
env
,
"apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items/{key}"
,
return
restTemplate
.
get
(
env
,
"apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items/{key}"
,
ItemDTO
.
class
,
appId
,
clusterName
,
namespaceName
,
key
);
ItemDTO
.
class
,
appId
,
clusterName
,
namespaceName
,
key
);
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/bo/ItemBO.java
View file @
17261b68
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ItemService.java
View file @
17261b68
...
@@ -110,6 +110,10 @@ public class ItemService {
...
@@ -110,6 +110,10 @@ public class ItemService {
return
itemAPI
.
findItems
(
appId
,
env
,
clusterName
,
namespaceName
);
return
itemAPI
.
findItems
(
appId
,
env
,
clusterName
,
namespaceName
);
}
}
public
List
<
ItemDTO
>
findDeletedItems
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespaceName
)
{
return
itemAPI
.
findDeletedItems
(
appId
,
env
,
clusterName
,
namespaceName
);
}
public
ItemDTO
loadItem
(
Env
env
,
String
appId
,
String
clusterName
,
String
namespaceName
,
String
key
)
{
public
ItemDTO
loadItem
(
Env
env
,
String
appId
,
String
clusterName
,
String
namespaceName
,
String
key
)
{
return
itemAPI
.
loadItem
(
env
,
appId
,
clusterName
,
namespaceName
,
key
);
return
itemAPI
.
loadItem
(
env
,
appId
,
clusterName
,
namespaceName
,
key
);
}
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java
View file @
17261b68
...
@@ -30,7 +30,6 @@ import java.util.Map;
...
@@ -30,7 +30,6 @@ import java.util.Map;
import
java.util.Set
;
import
java.util.Set
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Lazy
;
import
org.springframework.context.annotation.Lazy
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
...
@@ -224,6 +223,7 @@ public class NamespaceService {
...
@@ -224,6 +223,7 @@ public class NamespaceService {
//latest Release
//latest Release
ReleaseDTO
latestRelease
;
ReleaseDTO
latestRelease
;
Map
<
String
,
String
>
releaseItems
=
new
HashMap
<>();
Map
<
String
,
String
>
releaseItems
=
new
HashMap
<>();
Map
<
String
,
ItemDTO
>
deletedItemDTOs
=
new
HashMap
<>();
latestRelease
=
releaseService
.
loadLatestRelease
(
appId
,
env
,
clusterName
,
namespaceName
);
latestRelease
=
releaseService
.
loadLatestRelease
(
appId
,
env
,
clusterName
,
namespaceName
);
if
(
latestRelease
!=
null
)
{
if
(
latestRelease
!=
null
)
{
releaseItems
=
gson
.
fromJson
(
latestRelease
.
getConfigurations
(),
GsonType
.
CONFIG
);
releaseItems
=
gson
.
fromJson
(
latestRelease
.
getConfigurations
(),
GsonType
.
CONFIG
);
...
@@ -244,7 +244,11 @@ public class NamespaceService {
...
@@ -244,7 +244,11 @@ public class NamespaceService {
}
}
//deleted items
//deleted items
List
<
ItemBO
>
deletedItems
=
parseDeletedItems
(
items
,
releaseItems
);
itemService
.
findDeletedItems
(
appId
,
env
,
clusterName
,
namespaceName
).
forEach
(
item
->
{
deletedItemDTOs
.
put
(
item
.
getKey
(),
item
);
});
List
<
ItemBO
>
deletedItems
=
parseDeletedItems
(
items
,
releaseItems
,
deletedItemDTOs
);
itemBOs
.
addAll
(
deletedItems
);
itemBOs
.
addAll
(
deletedItems
);
modifiedItemCnt
+=
deletedItems
.
size
();
modifiedItemCnt
+=
deletedItems
.
size
();
...
@@ -281,7 +285,7 @@ public class NamespaceService {
...
@@ -281,7 +285,7 @@ public class NamespaceService {
namespace
.
setPublic
(
isPublic
);
namespace
.
setPublic
(
isPublic
);
}
}
private
List
<
ItemBO
>
parseDeletedItems
(
List
<
ItemDTO
>
newItems
,
Map
<
String
,
String
>
releaseItems
)
{
private
List
<
ItemBO
>
parseDeletedItems
(
List
<
ItemDTO
>
newItems
,
Map
<
String
,
String
>
releaseItems
,
Map
<
String
,
ItemDTO
>
deletedItemDTOs
)
{
Map
<
String
,
ItemDTO
>
newItemMap
=
BeanUtils
.
mapByKey
(
"key"
,
newItems
);
Map
<
String
,
ItemDTO
>
newItemMap
=
BeanUtils
.
mapByKey
(
"key"
,
newItems
);
List
<
ItemBO
>
deletedItems
=
new
LinkedList
<>();
List
<
ItemBO
>
deletedItems
=
new
LinkedList
<>();
...
@@ -291,7 +295,7 @@ public class NamespaceService {
...
@@ -291,7 +295,7 @@ public class NamespaceService {
ItemBO
deletedItem
=
new
ItemBO
();
ItemBO
deletedItem
=
new
ItemBO
();
deletedItem
.
setDeleted
(
true
);
deletedItem
.
setDeleted
(
true
);
ItemDTO
deletedItemDto
=
new
ItemDTO
(
);
ItemDTO
deletedItemDto
=
deletedItemDTOs
.
computeIfAbsent
(
key
,
k
->
new
ItemDTO
()
);
deletedItemDto
.
setKey
(
key
);
deletedItemDto
.
setKey
(
key
);
String
oldValue
=
entry
.
getValue
();
String
oldValue
=
entry
.
getValue
();
deletedItem
.
setItem
(
deletedItemDto
);
deletedItem
.
setItem
(
deletedItemDto
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment