Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Piotr Sowinski
nxcals
Commits
b0694083
Commit
b0694083
authored
Jan 05, 2017
by
Jakub Wozniak
Browse files
Progress for the service discovery
parent
f6835c93
Changes
5
Hide whitespace changes
Inline
Side-by-side
accsoft-nxcals-service/build.gradle
View file @
b0694083
...
...
@@ -9,6 +9,7 @@ mainClassName='cern.accsoft.nxcals.service.Application'
repositories
{
//
mavenCentral()
mavenCentral
()
}
dependencies
{
testCompile
(
'org.springframework.boot:spring-boot-starter-test:1.4.0.RELEASE'
)
}
//dependencies { }
accsoft-nxcals-service/gradle.properties
0 → 100644
View file @
b0694083
systemProp.http.proxyHost
=
nxcals-test1
systemProp.http.proxyPort
=
8888
#systemProp.http.proxyUser=userid
#systemProp.http.proxyPassword=password
systemProp.http.nonProxyHosts
=
*.cern.ch|localhost
\ No newline at end of file
accsoft-nxcals-service/product.xml
View file @
b0694083
...
...
@@ -27,6 +27,13 @@
<dep
product=
"spring-boot-starter-data-jpa"
version=
"1.4.0.RELEASE"
/>
<dep
product=
"spring-boot-starter-cache"
version=
"1.4.0.RELEASE"
/>
<dep
product=
"spring-context-support"
version=
"4.3.2.RELEASE"
/>
<dep
product=
"spring-cloud-starter-zookeeper-discovery"
version=
"1.0.3.RELEASE"
/>
<!--<dep product="curator-framework" version="2.11.1"/>-->
<!--<dep product="curator-recipes" version="2.11.1"/>-->
<!--<dep product="curator-test" version="2.11.1" exclude="true" local="true"/>-->
<!--<dep product="curator-x-discovery" version="2.11.1"/>-->
<dep
product=
"spring-boot-starter-test"
version=
"1.4.0.RELEASE"
local=
"true"
excluded=
"true"
/>
<dep
product=
"hibernate-ehcache"
version=
"5.0.9.Final"
/>
<dep
product=
"jmx_prometheus_javaagent"
version=
"0.7"
/>
<dep
product=
"commons-codec"
version=
"1.10"
/>
...
...
accsoft-nxcals-service/src/main/java/cern/accsoft/nxcals/service/discovery/Discovery.java
0 → 100644
View file @
b0694083
package
cern.accsoft.nxcals.service.discovery
;
import
org.apache.curator.utils.CloseableUtils
;
import
org.apache.curator.framework.CuratorFramework
;
import
org.apache.curator.x.discovery.ServiceDiscovery
;
import
org.apache.curator.x.discovery.ServiceDiscoveryBuilder
;
import
org.apache.curator.x.discovery.ServiceInstance
;
import
org.apache.curator.x.discovery.UriSpec
;
import
org.apache.curator.x.discovery.details.JsonInstanceSerializer
;
import
java.io.Closeable
;
import
java.io.IOException
;
/**
* This shows a very simplified method of registering an instance with the service discovery. Each individual
* instance in your distributed set of applications would create an instance of something similar to ExampleServer,
* start it when the application comes up and close it when the application shuts down.
*/
public
class
Discovery
implements
Closeable
{
private
final
ServiceDiscovery
<
InstanceDetails
>
serviceDiscovery
;
private
final
ServiceInstance
<
InstanceDetails
>
thisInstance
;
public
ExampleServer
(
CuratorFramework
client
,
String
path
,
String
serviceName
,
String
description
)
throws
Exception
{
// in a real application, you'd have a convention of some kind for the URI layout
UriSpec
uriSpec
=
new
UriSpec
(
"{scheme}://foo.com:{port}"
);
thisInstance
=
ServiceInstance
.<
InstanceDetails
>
builder
()
.
name
(
serviceName
)
.
payload
(
new
InstanceDetails
(
description
))
.
port
((
int
)
(
65535
*
Math
.
random
()))
// in a real application, you'd use a common port
.
uriSpec
(
uriSpec
)
.
build
();
// if you mark your payload class with @JsonRootName the provided JsonInstanceSerializer will work
JsonInstanceSerializer
<
InstanceDetails
>
serializer
=
new
JsonInstanceSerializer
<
InstanceDetails
>(
InstanceDetails
.
class
);
serviceDiscovery
=
ServiceDiscoveryBuilder
.
builder
(
InstanceDetails
.
class
)
.
client
(
client
)
.
basePath
(
path
)
.
serializer
(
serializer
)
.
thisInstance
(
thisInstance
)
.
build
();
}
public
ServiceInstance
<
InstanceDetails
>
getThisInstance
()
{
return
thisInstance
;
}
public
void
start
()
throws
Exception
{
serviceDiscovery
.
start
();
}
@Override
public
void
close
()
throws
IOException
{
CloseableUtils
.
closeQuietly
(
serviceDiscovery
);
}
}
\ No newline at end of file
accsoft-nxcals-service/src/main/java/cern/accsoft/nxcals/service/discovery/InstanceDetails.java
0 → 100644
View file @
b0694083
package
cern.accsoft.nxcals.service.discovery
;
/**
* Created by jwozniak on 02/01/17.
*/
public
class
InstanceDetails
{
}
Write
Preview
Supports
Markdown
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