Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
DEMO
spring-boot
Commits
8fb04416
Commit
8fb04416
authored
Jun 19, 2015
by
Phillip Webb
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2913 from akonczak/master
* pr/2913: Enable non local node Elasticsearch instances
parents
f22c91ac
2e66f174
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
9 deletions
+45
-9
ElasticsearchAutoConfiguration.java
...nfigure/elasticsearch/ElasticsearchAutoConfiguration.java
+19
-4
ElasticsearchAutoConfigurationTests.java
...re/elasticsearch/ElasticsearchAutoConfigurationTests.java
+26
-5
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchAutoConfiguration.java
View file @
8fb04416
...
...
@@ -16,6 +16,9 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
elasticsearch
;
import
java.util.Collections
;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
import
java.util.Properties
;
import
org.apache.commons.logging.Log
;
...
...
@@ -52,6 +55,14 @@ import org.springframework.util.StringUtils;
@EnableConfigurationProperties
(
ElasticsearchProperties
.
class
)
public
class
ElasticsearchAutoConfiguration
implements
DisposableBean
{
private
static
final
Map
<
String
,
String
>
DEFAULTS
;
static
{
Map
<
String
,
String
>
defaults
=
new
LinkedHashMap
<
String
,
String
>();
defaults
.
put
(
"http.enabled"
,
String
.
valueOf
(
false
));
defaults
.
put
(
"node.local"
,
String
.
valueOf
(
true
));
DEFAULTS
=
Collections
.
unmodifiableMap
(
defaults
);
}
private
static
Log
logger
=
LogFactory
.
getLog
(
ElasticsearchAutoConfiguration
.
class
);
@Autowired
...
...
@@ -77,11 +88,15 @@ public class ElasticsearchAutoConfiguration implements DisposableBean {
}
private
Client
createNodeClient
()
throws
Exception
{
ImmutableSettings
.
Builder
settings
=
ImmutableSettings
.
settingsBuilder
()
.
put
(
"http.enabled"
,
String
.
valueOf
(
false
))
.
put
(
this
.
properties
.
getProperties
());
ImmutableSettings
.
Builder
settings
=
ImmutableSettings
.
settingsBuilder
();
for
(
Map
.
Entry
<
String
,
String
>
entry
:
DEFAULTS
.
entrySet
())
{
if
(!
this
.
properties
.
getProperties
().
containsKey
(
entry
.
getKey
()))
{
settings
.
put
(
entry
.
getKey
(),
entry
.
getValue
());
}
}
settings
.
put
(
this
.
properties
.
getProperties
());
Node
node
=
new
NodeBuilder
().
settings
(
settings
)
.
clusterName
(
this
.
properties
.
getClusterName
()).
local
(
true
).
node
();
.
clusterName
(
this
.
properties
.
getClusterName
()).
node
();
this
.
releasable
=
node
;
return
node
.
client
();
}
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchAutoConfigurationTests.java
View file @
8fb04416
...
...
@@ -28,7 +28,6 @@ import org.springframework.boot.test.EnvironmentTestUtils;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
instanceOf
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertThat
;
...
...
@@ -53,7 +52,7 @@ public class ElasticsearchAutoConfigurationTests {
}
@Test
public
void
createNodeClient
()
{
public
void
createNodeClient
WithDefaults
()
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"spring.data.elasticsearch.properties.foo.bar:baz"
,
...
...
@@ -63,9 +62,31 @@ public class ElasticsearchAutoConfigurationTests {
ElasticsearchAutoConfiguration
.
class
);
this
.
context
.
refresh
();
assertEquals
(
1
,
this
.
context
.
getBeanNamesForType
(
Client
.
class
).
length
);
Client
client
=
this
.
context
.
getBean
(
Client
.
class
);
assertThat
(
client
,
instanceOf
(
NodeClient
.
class
));
assertThat
(((
NodeClient
)
client
).
settings
().
get
(
"foo.bar"
),
is
(
equalTo
(
"baz"
)));
NodeClient
client
=
(
NodeClient
)
this
.
context
.
getBean
(
Client
.
class
);
assertThat
(
client
.
settings
().
get
(
"foo.bar"
),
is
(
equalTo
(
"baz"
)));
assertThat
(
client
.
settings
().
get
(
"node.local"
),
is
(
equalTo
(
"true"
)));
assertThat
(
client
.
settings
().
get
(
"http.enabled"
),
is
(
equalTo
(
"false"
)));
}
@Test
public
void
createNodeClientWithOverrides
()
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"spring.data.elasticsearch.properties.foo.bar:baz"
,
"spring.data.elasticsearch.properties.path.data:target/data"
,
"spring.data.elasticsearch.properties.path.logs:target/logs"
,
"spring.data.elasticsearch.properties.node.local:false"
,
"spring.data.elasticsearch.properties.node.data:true"
,
"spring.data.elasticsearch.properties.http.enabled:true"
);
this
.
context
.
register
(
PropertyPlaceholderAutoConfiguration
.
class
,
ElasticsearchAutoConfiguration
.
class
);
this
.
context
.
refresh
();
assertEquals
(
1
,
this
.
context
.
getBeanNamesForType
(
Client
.
class
).
length
);
NodeClient
client
=
(
NodeClient
)
this
.
context
.
getBean
(
Client
.
class
);
assertThat
(
client
.
settings
().
get
(
"foo.bar"
),
is
(
equalTo
(
"baz"
)));
assertThat
(
client
.
settings
().
get
(
"node.local"
),
is
(
equalTo
(
"false"
)));
assertThat
(
client
.
settings
().
get
(
"node.data"
),
is
(
equalTo
(
"true"
)));
assertThat
(
client
.
settings
().
get
(
"http.enabled"
),
is
(
equalTo
(
"true"
)));
}
@Test
...
...
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