Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wrr-cat
apollo
提交
fc4f3e85
apollo
项目概览
wrr-cat
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
apollo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
fc4f3e85
编写于
11月 30, 2016
作者:
张
张乐
提交者:
GitHub
11月 30, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #465 from nobodyiam/json-yml-support
support json and yml config files
上级
8c71054d
e546f67e
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
240 addition
and
119 deletion
+240
-119
apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/ReleaseHistoryController.java
...llo/adminservice/controller/ReleaseHistoryController.java
+0
-97
apollo-client/src/main/java/com/ctrip/framework/apollo/internals/JsonConfigFile.java
.../com/ctrip/framework/apollo/internals/JsonConfigFile.java
+18
-0
apollo-client/src/main/java/com/ctrip/framework/apollo/internals/PlainTextConfigFile.java
...ctrip/framework/apollo/internals/PlainTextConfigFile.java
+28
-0
apollo-client/src/main/java/com/ctrip/framework/apollo/internals/XmlConfigFile.java
...a/com/ctrip/framework/apollo/internals/XmlConfigFile.java
+1
-19
apollo-client/src/main/java/com/ctrip/framework/apollo/internals/YamlConfigFile.java
.../com/ctrip/framework/apollo/internals/YamlConfigFile.java
+17
-0
apollo-client/src/main/java/com/ctrip/framework/apollo/internals/YmlConfigFile.java
...a/com/ctrip/framework/apollo/internals/YmlConfigFile.java
+17
-0
apollo-client/src/main/java/com/ctrip/framework/apollo/spi/DefaultConfigFactory.java
.../com/ctrip/framework/apollo/spi/DefaultConfigFactory.java
+9
-0
apollo-client/src/test/java/com/ctrip/framework/apollo/AllTests.java
...nt/src/test/java/com/ctrip/framework/apollo/AllTests.java
+2
-1
apollo-client/src/test/java/com/ctrip/framework/apollo/internals/JsonConfigFileTest.java
.../ctrip/framework/apollo/internals/JsonConfigFileTest.java
+112
-0
apollo-client/src/test/java/com/ctrip/framework/apollo/spi/DefaultConfigFactoryTest.java
.../ctrip/framework/apollo/spi/DefaultConfigFactoryTest.java
+24
-0
apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigFileFormat.java
...m/ctrip/framework/apollo/core/enums/ConfigFileFormat.java
+7
-1
apollo-portal/src/main/resources/static/namespace.html
apollo-portal/src/main/resources/static/namespace.html
+3
-0
apollo-portal/src/main/resources/static/scripts/directive/namespace-panel-directive.js
...ces/static/scripts/directive/namespace-panel-directive.js
+2
-1
未找到文件。
apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/ReleaseHistoryController.java
浏览文件 @
fc4f3e85
package
com.ctrip.framework.apollo.adminservice.controller
;
import
com.google.common.base.Strings
;
import
com.google.common.collect.Sets
;
import
com.google.gson.Gson
;
import
com.google.gson.reflect.TypeToken
;
import
com.ctrip.framework.apollo.biz.entity.Namespace
;
import
com.ctrip.framework.apollo.biz.entity.Release
;
import
com.ctrip.framework.apollo.biz.entity.ReleaseHistory
;
import
com.ctrip.framework.apollo.biz.repository.NamespaceRepository
;
import
com.ctrip.framework.apollo.biz.repository.ReleaseHistoryRepository
;
import
com.ctrip.framework.apollo.biz.repository.ReleaseRepository
;
import
com.ctrip.framework.apollo.biz.service.ReleaseHistoryService
;
import
com.ctrip.framework.apollo.common.constants.ReleaseOperation
;
import
com.ctrip.framework.apollo.common.dto.PageDTO
;
import
com.ctrip.framework.apollo.common.dto.ReleaseHistoryDTO
;
import
com.ctrip.framework.apollo.common.utils.BeanUtils
;
...
...
@@ -20,20 +12,15 @@ import com.ctrip.framework.apollo.common.utils.BeanUtils;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.util.CollectionUtils
;
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.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.lang.reflect.Type
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
/**
* @author Jason Song(song_s@ctrip.com)
...
...
@@ -48,15 +35,6 @@ public class ReleaseHistoryController {
@Autowired
private
ReleaseHistoryService
releaseHistoryService
;
@Autowired
private
ReleaseRepository
releaseRepository
;
@Autowired
private
NamespaceRepository
namespaceRepository
;
@Autowired
private
ReleaseHistoryRepository
releaseHistoryRepository
;
@RequestMapping
(
value
=
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/releases/histories"
,
method
=
RequestMethod
.
GET
)
public
PageDTO
<
ReleaseHistoryDTO
>
findReleaseHistoriesByNamespace
(
...
...
@@ -80,81 +58,6 @@ public class ReleaseHistoryController {
releaseHistoryDTOs
.
add
(
dto
);
}
return
new
PageDTO
<>(
releaseHistoryDTOs
,
pageable
,
result
.
getTotalElements
());
}
@RequestMapping
(
value
=
"/release-histories/conversions"
,
method
=
RequestMethod
.
POST
)
public
void
releaseHistoryConversion
(
@RequestParam
(
name
=
"namespaceId"
,
required
=
false
)
String
namespaceId
)
{
Iterable
<
Namespace
>
namespaces
;
if
(
Strings
.
isNullOrEmpty
(
namespaceId
))
{
namespaces
=
namespaceRepository
.
findAll
();
}
else
{
Set
<
Long
>
idList
=
Arrays
.
stream
(
namespaceId
.
split
(
","
)).
map
(
Long:
:
valueOf
).
collect
(
Collectors
.
toSet
());
namespaces
=
namespaceRepository
.
findAll
(
idList
);
}
for
(
Namespace
namespace
:
namespaces
)
{
List
<
Release
>
releases
=
releaseRepository
.
findByAppIdAndClusterNameAndNamespaceNameOrderByIdAsc
(
namespace
.
getAppId
(),
namespace
.
getClusterName
(),
namespace
.
getNamespaceName
());
if
(
CollectionUtils
.
isEmpty
(
releases
))
{
continue
;
}
Release
previousRelease
=
null
;
Set
<
ReleaseHistory
>
releaseHistories
=
Sets
.
newLinkedHashSet
();
//ordered set
for
(
Release
release
:
releases
)
{
List
<
ReleaseHistory
>
histories
=
releaseHistoryService
.
findReleaseHistoriesByReleaseId
(
release
.
getId
());
//already processed
if
(!
CollectionUtils
.
isEmpty
(
histories
))
{
continue
;
}
long
previousReleaseId
=
previousRelease
==
null
?
0
:
previousRelease
.
getId
();
ReleaseHistory
releaseHistory
=
assembleReleaseHistory
(
release
,
ReleaseOperation
.
NORMAL_RELEASE
,
previousReleaseId
);
releaseHistories
.
add
(
releaseHistory
);
//rollback
if
(
release
.
isAbandoned
()
&&
previousRelease
!=
null
)
{
releaseHistory
.
setDataChangeLastModifiedTime
(
release
.
getDataChangeCreatedTime
());
ReleaseHistory
rollBackReleaseHistory
=
assembleReleaseHistory
(
previousRelease
,
ReleaseOperation
.
ROLLBACK
,
release
.
getId
());
rollBackReleaseHistory
.
setDataChangeCreatedBy
(
release
.
getDataChangeLastModifiedBy
());
rollBackReleaseHistory
.
setDataChangeCreatedTime
(
release
.
getDataChangeLastModifiedTime
());
rollBackReleaseHistory
.
setDataChangeLastModifiedTime
(
release
.
getDataChangeLastModifiedTime
());
releaseHistories
.
add
(
rollBackReleaseHistory
);
}
else
{
previousRelease
=
release
;
}
}
releaseHistoryRepository
.
save
(
releaseHistories
);
}
}
public
ReleaseHistory
assembleReleaseHistory
(
Release
release
,
int
releaseOperation
,
long
previousReleaseId
)
{
ReleaseHistory
releaseHistory
=
new
ReleaseHistory
();
releaseHistory
.
setAppId
(
release
.
getAppId
());
releaseHistory
.
setClusterName
(
release
.
getClusterName
());
releaseHistory
.
setNamespaceName
(
release
.
getNamespaceName
());
releaseHistory
.
setBranchName
(
release
.
getClusterName
());
releaseHistory
.
setReleaseId
(
release
.
getId
());
releaseHistory
.
setPreviousReleaseId
(
previousReleaseId
);
releaseHistory
.
setOperation
(
releaseOperation
);
releaseHistory
.
setOperationContext
(
"{}"
);
//default empty object
releaseHistory
.
setDataChangeCreatedBy
(
release
.
getDataChangeCreatedBy
());
releaseHistory
.
setDataChangeCreatedTime
(
release
.
getDataChangeCreatedTime
());
releaseHistory
.
setDataChangeLastModifiedTime
(
release
.
getDataChangeLastModifiedTime
());
releaseHistory
.
setDataChangeLastModifiedBy
(
"apollo"
);
//mark
return
releaseHistory
;
}
}
apollo-client/src/main/java/com/ctrip/framework/apollo/internals/JsonConfigFile.java
0 → 100644
浏览文件 @
fc4f3e85
package
com.ctrip.framework.apollo.internals
;
import
com.ctrip.framework.apollo.core.enums.ConfigFileFormat
;
/**
* @author Jason Song(song_s@ctrip.com)
*/
public
class
JsonConfigFile
extends
PlainTextConfigFile
{
public
JsonConfigFile
(
String
namespace
,
ConfigRepository
configRepository
)
{
super
(
namespace
,
configRepository
);
}
@Override
public
ConfigFileFormat
getConfigFileFormat
()
{
return
ConfigFileFormat
.
JSON
;
}
}
apollo-client/src/main/java/com/ctrip/framework/apollo/internals/PlainTextConfigFile.java
0 → 100644
浏览文件 @
fc4f3e85
package
com.ctrip.framework.apollo.internals
;
import
com.ctrip.framework.apollo.core.ConfigConsts
;
/**
* @author Jason Song(song_s@ctrip.com)
*/
public
abstract
class
PlainTextConfigFile
extends
AbstractConfigFile
{
public
PlainTextConfigFile
(
String
namespace
,
ConfigRepository
configRepository
)
{
super
(
namespace
,
configRepository
);
}
@Override
public
String
getContent
()
{
if
(
m_configProperties
.
get
()
==
null
)
{
return
null
;
}
return
m_configProperties
.
get
().
getProperty
(
ConfigConsts
.
CONFIG_FILE_CONTENT_KEY
);
}
@Override
public
boolean
hasContent
()
{
if
(
m_configProperties
.
get
()
==
null
)
{
return
false
;
}
return
m_configProperties
.
get
().
containsKey
(
ConfigConsts
.
CONFIG_FILE_CONTENT_KEY
);
}
}
apollo-client/src/main/java/com/ctrip/framework/apollo/internals/XmlConfigFile.java
浏览文件 @
fc4f3e85
package
com.ctrip.framework.apollo.internals
;
import
com.ctrip.framework.apollo.core.ConfigConsts
;
import
com.ctrip.framework.apollo.core.enums.ConfigFileFormat
;
/**
* @author Jason Song(song_s@ctrip.com)
*/
public
class
XmlConfigFile
extends
Abstrac
tConfigFile
{
public
class
XmlConfigFile
extends
PlainTex
tConfigFile
{
public
XmlConfigFile
(
String
namespace
,
ConfigRepository
configRepository
)
{
super
(
namespace
,
configRepository
);
}
@Override
public
String
getContent
()
{
if
(
m_configProperties
.
get
()
==
null
)
{
return
null
;
}
return
m_configProperties
.
get
().
getProperty
(
ConfigConsts
.
CONFIG_FILE_CONTENT_KEY
);
}
@Override
public
boolean
hasContent
()
{
if
(
m_configProperties
.
get
()
==
null
)
{
return
false
;
}
return
m_configProperties
.
get
().
containsKey
(
ConfigConsts
.
CONFIG_FILE_CONTENT_KEY
);
}
@Override
public
ConfigFileFormat
getConfigFileFormat
()
{
return
ConfigFileFormat
.
XML
;
...
...
apollo-client/src/main/java/com/ctrip/framework/apollo/internals/YamlConfigFile.java
0 → 100644
浏览文件 @
fc4f3e85
package
com.ctrip.framework.apollo.internals
;
import
com.ctrip.framework.apollo.core.enums.ConfigFileFormat
;
/**
* @author Jason Song(song_s@ctrip.com)
*/
public
class
YamlConfigFile
extends
PlainTextConfigFile
{
public
YamlConfigFile
(
String
namespace
,
ConfigRepository
configRepository
)
{
super
(
namespace
,
configRepository
);
}
@Override
public
ConfigFileFormat
getConfigFileFormat
()
{
return
ConfigFileFormat
.
YAML
;
}
}
apollo-client/src/main/java/com/ctrip/framework/apollo/internals/YmlConfigFile.java
0 → 100644
浏览文件 @
fc4f3e85
package
com.ctrip.framework.apollo.internals
;
import
com.ctrip.framework.apollo.core.enums.ConfigFileFormat
;
/**
* @author Jason Song(song_s@ctrip.com)
*/
public
class
YmlConfigFile
extends
PlainTextConfigFile
{
public
YmlConfigFile
(
String
namespace
,
ConfigRepository
configRepository
)
{
super
(
namespace
,
configRepository
);
}
@Override
public
ConfigFileFormat
getConfigFileFormat
()
{
return
ConfigFileFormat
.
YML
;
}
}
apollo-client/src/main/java/com/ctrip/framework/apollo/spi/DefaultConfigFactory.java
浏览文件 @
fc4f3e85
...
...
@@ -5,10 +5,13 @@ import com.ctrip.framework.apollo.ConfigFile;
import
com.ctrip.framework.apollo.core.enums.ConfigFileFormat
;
import
com.ctrip.framework.apollo.internals.ConfigRepository
;
import
com.ctrip.framework.apollo.internals.DefaultConfig
;
import
com.ctrip.framework.apollo.internals.JsonConfigFile
;
import
com.ctrip.framework.apollo.internals.LocalFileConfigRepository
;
import
com.ctrip.framework.apollo.internals.PropertiesConfigFile
;
import
com.ctrip.framework.apollo.internals.RemoteConfigRepository
;
import
com.ctrip.framework.apollo.internals.XmlConfigFile
;
import
com.ctrip.framework.apollo.internals.YamlConfigFile
;
import
com.ctrip.framework.apollo.internals.YmlConfigFile
;
import
com.ctrip.framework.apollo.util.ConfigUtil
;
import
org.slf4j.Logger
;
...
...
@@ -40,6 +43,12 @@ public class DefaultConfigFactory implements ConfigFactory {
return
new
PropertiesConfigFile
(
namespace
,
configRepository
);
case
XML:
return
new
XmlConfigFile
(
namespace
,
configRepository
);
case
JSON:
return
new
JsonConfigFile
(
namespace
,
configRepository
);
case
YAML:
return
new
YamlConfigFile
(
namespace
,
configRepository
);
case
YML:
return
new
YmlConfigFile
(
namespace
,
configRepository
);
}
return
null
;
...
...
apollo-client/src/test/java/com/ctrip/framework/apollo/AllTests.java
浏览文件 @
fc4f3e85
...
...
@@ -4,6 +4,7 @@ package com.ctrip.framework.apollo;
import
com.ctrip.framework.apollo.integration.ConfigIntegrationTest
;
import
com.ctrip.framework.apollo.internals.DefaultConfigManagerTest
;
import
com.ctrip.framework.apollo.internals.DefaultConfigTest
;
import
com.ctrip.framework.apollo.internals.JsonConfigFileTest
;
import
com.ctrip.framework.apollo.internals.LocalFileConfigRepositoryTest
;
import
com.ctrip.framework.apollo.internals.PropertiesConfigFileTest
;
import
com.ctrip.framework.apollo.internals.RemoteConfigLongPollServiceTest
;
...
...
@@ -28,7 +29,7 @@ import org.junit.runners.Suite.SuiteClasses;
RemoteConfigRepositoryTest
.
class
,
SimpleConfigTest
.
class
,
DefaultConfigFactoryTest
.
class
,
ConfigIntegrationTest
.
class
,
ExceptionUtilTest
.
class
,
XmlConfigFileTest
.
class
,
PropertiesConfigFileTest
.
class
,
RemoteConfigLongPollServiceTest
.
class
,
DateParserTest
.
class
,
DurationParserTest
.
class
DurationParserTest
.
class
,
JsonConfigFileTest
.
class
})
public
class
AllTests
{
...
...
apollo-client/src/test/java/com/ctrip/framework/apollo/internals/JsonConfigFileTest.java
0 → 100644
浏览文件 @
fc4f3e85
package
com.ctrip.framework.apollo.internals
;
import
com.ctrip.framework.apollo.core.ConfigConsts
;
import
com.ctrip.framework.apollo.core.enums.ConfigFileFormat
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.mockito.runners.MockitoJUnitRunner
;
import
java.util.Properties
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
mockito
.
Mockito
.
when
;
/**
* @author Jason Song(song_s@ctrip.com)
*/
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
JsonConfigFileTest
{
private
String
someNamespace
;
@Mock
private
ConfigRepository
configRepository
;
@Before
public
void
setUp
()
throws
Exception
{
someNamespace
=
"someName"
;
}
@Test
public
void
testWhenHasContent
()
throws
Exception
{
Properties
someProperties
=
new
Properties
();
String
key
=
ConfigConsts
.
CONFIG_FILE_CONTENT_KEY
;
String
someValue
=
"someValue"
;
someProperties
.
setProperty
(
key
,
someValue
);
when
(
configRepository
.
getConfig
()).
thenReturn
(
someProperties
);
JsonConfigFile
configFile
=
new
JsonConfigFile
(
someNamespace
,
configRepository
);
assertEquals
(
ConfigFileFormat
.
JSON
,
configFile
.
getConfigFileFormat
());
assertEquals
(
someNamespace
,
configFile
.
getNamespace
());
assertTrue
(
configFile
.
hasContent
());
assertEquals
(
someValue
,
configFile
.
getContent
());
}
@Test
public
void
testWhenHasNoContent
()
throws
Exception
{
when
(
configRepository
.
getConfig
()).
thenReturn
(
null
);
JsonConfigFile
configFile
=
new
JsonConfigFile
(
someNamespace
,
configRepository
);
assertFalse
(
configFile
.
hasContent
());
assertNull
(
configFile
.
getContent
());
}
@Test
public
void
testWhenConfigRepositoryHasError
()
throws
Exception
{
when
(
configRepository
.
getConfig
()).
thenThrow
(
new
RuntimeException
(
"someError"
));
JsonConfigFile
configFile
=
new
JsonConfigFile
(
someNamespace
,
configRepository
);
assertFalse
(
configFile
.
hasContent
());
assertNull
(
configFile
.
getContent
());
}
@Test
public
void
testOnRepositoryChange
()
throws
Exception
{
Properties
someProperties
=
new
Properties
();
String
key
=
ConfigConsts
.
CONFIG_FILE_CONTENT_KEY
;
String
someValue
=
"someValue"
;
String
anotherValue
=
"anotherValue"
;
someProperties
.
setProperty
(
key
,
someValue
);
when
(
configRepository
.
getConfig
()).
thenReturn
(
someProperties
);
JsonConfigFile
configFile
=
new
JsonConfigFile
(
someNamespace
,
configRepository
);
assertEquals
(
someValue
,
configFile
.
getContent
());
Properties
anotherProperties
=
new
Properties
();
anotherProperties
.
setProperty
(
key
,
anotherValue
);
configFile
.
onRepositoryChange
(
someNamespace
,
anotherProperties
);
assertEquals
(
anotherValue
,
configFile
.
getContent
());
}
@Test
public
void
testWhenConfigRepositoryHasErrorAndThenRecovered
()
throws
Exception
{
Properties
someProperties
=
new
Properties
();
String
key
=
ConfigConsts
.
CONFIG_FILE_CONTENT_KEY
;
String
someValue
=
"someValue"
;
someProperties
.
setProperty
(
key
,
someValue
);
when
(
configRepository
.
getConfig
()).
thenThrow
(
new
RuntimeException
(
"someError"
));
JsonConfigFile
configFile
=
new
JsonConfigFile
(
someNamespace
,
configRepository
);
assertFalse
(
configFile
.
hasContent
());
assertNull
(
configFile
.
getContent
());
configFile
.
onRepositoryChange
(
someNamespace
,
someProperties
);
assertTrue
(
configFile
.
hasContent
());
assertEquals
(
someValue
,
configFile
.
getContent
());
}
}
apollo-client/src/test/java/com/ctrip/framework/apollo/spi/DefaultConfigFactoryTest.java
浏览文件 @
fc4f3e85
...
...
@@ -5,9 +5,12 @@ import com.ctrip.framework.apollo.ConfigFile;
import
com.ctrip.framework.apollo.core.enums.ConfigFileFormat
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.internals.DefaultConfig
;
import
com.ctrip.framework.apollo.internals.JsonConfigFile
;
import
com.ctrip.framework.apollo.internals.LocalFileConfigRepository
;
import
com.ctrip.framework.apollo.internals.PropertiesConfigFile
;
import
com.ctrip.framework.apollo.internals.XmlConfigFile
;
import
com.ctrip.framework.apollo.internals.YamlConfigFile
;
import
com.ctrip.framework.apollo.internals.YmlConfigFile
;
import
com.ctrip.framework.apollo.util.ConfigUtil
;
import
org.junit.Before
;
...
...
@@ -79,6 +82,7 @@ public class DefaultConfigFactoryTest extends ComponentTestCase {
public
void
testCreateConfigFile
()
throws
Exception
{
String
someNamespace
=
"someName"
;
String
anotherNamespace
=
"anotherName"
;
String
yetAnotherNamespace
=
"yetAnotherNamespace"
;
Properties
someProperties
=
new
Properties
();
LocalFileConfigRepository
someLocalConfigRepo
=
mock
(
LocalFileConfigRepository
.
class
);
...
...
@@ -86,11 +90,18 @@ public class DefaultConfigFactoryTest extends ComponentTestCase {
doReturn
(
someLocalConfigRepo
).
when
(
defaultConfigFactory
).
createLocalConfigRepository
(
someNamespace
);
doReturn
(
someLocalConfigRepo
).
when
(
defaultConfigFactory
).
createLocalConfigRepository
(
anotherNamespace
);
doReturn
(
someLocalConfigRepo
).
when
(
defaultConfigFactory
).
createLocalConfigRepository
(
yetAnotherNamespace
);
ConfigFile
propertyConfigFile
=
defaultConfigFactory
.
createConfigFile
(
someNamespace
,
ConfigFileFormat
.
Properties
);
ConfigFile
xmlConfigFile
=
defaultConfigFactory
.
createConfigFile
(
anotherNamespace
,
ConfigFileFormat
.
XML
);
ConfigFile
jsonConfigFile
=
defaultConfigFactory
.
createConfigFile
(
yetAnotherNamespace
,
ConfigFileFormat
.
JSON
);
ConfigFile
ymlConfigFile
=
defaultConfigFactory
.
createConfigFile
(
someNamespace
,
ConfigFileFormat
.
YML
);
ConfigFile
yamlConfigFile
=
defaultConfigFactory
.
createConfigFile
(
someNamespace
,
ConfigFileFormat
.
YAML
);
assertThat
(
"Should create PropertiesConfigFile for properties format"
,
propertyConfigFile
,
is
(
instanceOf
(
PropertiesConfigFile
.
class
)));
...
...
@@ -99,6 +110,19 @@ public class DefaultConfigFactoryTest extends ComponentTestCase {
assertThat
(
"Should create XmlConfigFile for xml format"
,
xmlConfigFile
,
is
(
instanceOf
(
XmlConfigFile
.
class
)));
assertEquals
(
anotherNamespace
,
xmlConfigFile
.
getNamespace
());
assertThat
(
"Should create JsonConfigFile for json format"
,
jsonConfigFile
,
is
(
instanceOf
(
JsonConfigFile
.
class
)));
assertEquals
(
yetAnotherNamespace
,
jsonConfigFile
.
getNamespace
());
assertThat
(
"Should create YmlConfigFile for yml format"
,
ymlConfigFile
,
is
(
instanceOf
(
YmlConfigFile
.
class
)));
assertEquals
(
someNamespace
,
ymlConfigFile
.
getNamespace
());
assertThat
(
"Should create YamlConfigFile for yaml format"
,
yamlConfigFile
,
is
(
instanceOf
(
YamlConfigFile
.
class
)));
assertEquals
(
someNamespace
,
yamlConfigFile
.
getNamespace
());
}
public
static
class
MockConfigUtil
extends
ConfigUtil
{
...
...
apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigFileFormat.java
浏览文件 @
fc4f3e85
...
...
@@ -6,7 +6,7 @@ import com.ctrip.framework.apollo.core.utils.StringUtils;
* @author Jason Song(song_s@ctrip.com)
*/
public
enum
ConfigFileFormat
{
Properties
(
"properties"
),
XML
(
"xml"
);
Properties
(
"properties"
),
XML
(
"xml"
)
,
JSON
(
"json"
),
YML
(
"yml"
),
YAML
(
"yaml"
)
;
private
String
value
;
...
...
@@ -27,6 +27,12 @@ public enum ConfigFileFormat {
return
Properties
;
case
"xml"
:
return
XML
;
case
"json"
:
return
JSON
;
case
"yml"
:
return
YML
;
case
"yaml"
:
return
YAML
;
}
throw
new
IllegalArgumentException
(
value
+
" can not map enum"
);
}
...
...
apollo-portal/src/main/resources/static/namespace.html
浏览文件 @
fc4f3e85
...
...
@@ -97,6 +97,9 @@
<select
class=
"form-control"
name=
"format"
ng-model=
"appNamespace.format"
>
<option
value=
"properties"
>
properties
</option>
<option
value=
"xml"
>
xml
</option>
<option
value=
"json"
>
json
</option>
<option
value=
"yml"
>
yml
</option>
<option
value=
"yaml"
>
yaml
</option>
</select>
</div>
...
...
apollo-portal/src/main/resources/static/scripts/directive/namespace-panel-directive.js
浏览文件 @
fc4f3e85
...
...
@@ -226,7 +226,8 @@ function directive($window, toastr, AppUtil, EventManager, PermissionService, Na
//namespace view name hide suffix
namespace
.
viewName
=
namespace
.
baseInfo
.
namespaceName
.
replace
(
"
.xml
"
,
""
).
replace
(
"
.properties
"
,
""
);
"
.properties
"
,
""
).
replace
(
"
.json
"
,
""
).
replace
(
"
.yml
"
,
""
)
.
replace
(
"
.yaml
"
,
""
);
if
(
!
viewType
)
{
if
(
namespace
.
isPropertiesFormat
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录