Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
discovery
Overview
Overview
Details
Activity
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
谢捷峰
discovery
Commits
9caf8be5
Commit
9caf8be5
authored
Jul 19, 2018
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加图形化灰度发布功能
parent
b3a0a451
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
73 additions
and
15 deletions
+73
-15
discovery-console-desktop/src/main/java/com/nepxion/discovery/console/desktop/controller/ServiceController.java
+36
-15
discovery-console-desktop/src/main/java/com/nepxion/discovery/console/desktop/controller/ServiceErrorHandler.java
+33
-0
discovery-console-desktop/src/main/java/com/nepxion/discovery/console/desktop/workspace/ServiceTopology.java
+4
-0
No files found.
discovery-console-desktop/src/main/java/com/nepxion/discovery/console/desktop/controller/ServiceController.java
View file @
9caf8be5
...
...
@@ -12,6 +12,7 @@ package com.nepxion.discovery.console.desktop.controller;
import
java.util.List
;
import
java.util.Map
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.MediaType
;
...
...
@@ -29,41 +30,42 @@ public class ServiceController {
static
{
restTemplate
=
new
RestTemplate
();
restTemplate
.
setErrorHandler
(
new
ServiceErrorHandler
());
}
public
static
Map
<
String
,
List
<
InstanceEntity
>>
getInstanceMap
()
{
String
url
=
getUrl
()
+
"/console/instance-map"
;
String
json
=
restTemplate
.
getForEntity
(
url
,
String
.
class
).
getBody
();
String
result
=
restTemplate
.
getForEntity
(
url
,
String
.
class
).
getBody
();
return
convert
(
json
,
new
TypeReference
<
Map
<
String
,
List
<
InstanceEntity
>>>()
{
return
convert
(
result
,
new
TypeReference
<
Map
<
String
,
List
<
InstanceEntity
>>>()
{
});
}
public
static
List
<
String
>
getVersions
(
InstanceEntity
instance
)
{
String
url
=
"http://"
+
instance
.
getHost
()
+
":"
+
instance
.
getPort
()
+
"/version/view"
;
String
json
=
restTemplate
.
getForEntity
(
url
,
String
.
class
).
getBody
();
String
result
=
restTemplate
.
getForEntity
(
url
,
String
.
class
).
getBody
();
return
convert
(
json
,
new
TypeReference
<
List
<
String
>>()
{
return
convert
(
result
,
new
TypeReference
<
List
<
String
>>()
{
});
}
public
static
List
<
String
>
getRules
(
InstanceEntity
instance
)
{
String
url
=
"http://"
+
instance
.
getHost
()
+
":"
+
instance
.
getPort
()
+
"/config/view"
;
String
json
=
restTemplate
.
getForEntity
(
url
,
String
.
class
).
getBody
();
String
result
=
restTemplate
.
getForEntity
(
url
,
String
.
class
).
getBody
();
return
convert
(
json
,
new
TypeReference
<
List
<
String
>>()
{
return
convert
(
result
,
new
TypeReference
<
List
<
String
>>()
{
});
}
public
static
RouterEntity
routes
(
InstanceEntity
instance
,
String
routeServiceIds
)
{
String
url
=
"http://"
+
instance
.
getHost
()
+
":"
+
instance
.
getPort
()
+
"/router/routes"
;
String
json
=
restTemplate
.
postForEntity
(
url
,
routeServiceIds
,
String
.
class
).
getBody
();
String
result
=
restTemplate
.
postForEntity
(
url
,
routeServiceIds
,
String
.
class
).
getBody
();
return
convert
(
json
,
new
TypeReference
<
RouterEntity
>()
{
return
convert
(
result
,
new
TypeReference
<
RouterEntity
>()
{
});
}
...
...
@@ -75,18 +77,36 @@ public class ServiceController {
headers
.
setContentType
(
MediaType
.
APPLICATION_JSON_UTF8
);
HttpEntity
<
String
>
entity
=
new
HttpEntity
<
String
>(
config
,
headers
);
String
json
=
restTemplate
.
postForEntity
(
url
,
entity
,
String
.
class
).
getBody
();
String
result
=
restTemplate
.
postForEntity
(
url
,
entity
,
String
.
class
).
getBody
();
return
convert
(
json
,
new
TypeReference
<
List
<
ResultEntity
>>()
{
return
convert
(
result
,
new
TypeReference
<
List
<
ResultEntity
>>()
{
});
}
public
static
String
configUpdate
(
InstanceEntity
instance
,
String
config
)
{
String
url
=
"http://"
+
instance
.
getHost
()
+
":"
+
instance
.
getPort
()
+
"/config/update-sync"
;
// 解决中文乱码
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setContentType
(
MediaType
.
APPLICATION_JSON_UTF8
);
HttpEntity
<
String
>
entity
=
new
HttpEntity
<
String
>(
config
,
headers
);
String
result
=
restTemplate
.
postForEntity
(
url
,
entity
,
String
.
class
).
getBody
();
if
(!
StringUtils
.
equals
(
result
,
"OK"
))
{
ServiceErrorHandler
errorHandler
=
(
ServiceErrorHandler
)
restTemplate
.
getErrorHandler
();
result
=
errorHandler
.
getCause
();
}
return
result
;
}
public
static
List
<
ResultEntity
>
configClear
(
String
serviceId
)
{
String
url
=
getUrl
()
+
"/console/config/clear/"
+
serviceId
;
String
json
=
restTemplate
.
postForEntity
(
url
,
null
,
String
.
class
).
getBody
();
String
result
=
restTemplate
.
postForEntity
(
url
,
null
,
String
.
class
).
getBody
();
return
convert
(
json
,
new
TypeReference
<
List
<
ResultEntity
>>()
{
return
convert
(
result
,
new
TypeReference
<
List
<
ResultEntity
>>()
{
});
}
...
...
@@ -99,11 +119,11 @@ public class ServiceController {
return
url
;
}
private
static
<
T
>
T
convert
(
String
json
,
TypeReference
<
T
>
typeReference
)
{
private
static
<
T
>
T
convert
(
String
result
,
TypeReference
<
T
>
typeReference
)
{
try
{
return
JacksonSerializer
.
fromJson
(
json
,
typeReference
);
return
JacksonSerializer
.
fromJson
(
result
,
typeReference
);
}
catch
(
Exception
e
)
{
throw
new
IllegalArgumentException
(
json
);
throw
new
IllegalArgumentException
(
result
);
}
}
}
\ No newline at end of file
discovery-console-desktop/src/main/java/com/nepxion/discovery/console/desktop/controller/ServiceErrorHandler.java
0 → 100644
View file @
9caf8be5
package
com
.
nepxion
.
discovery
.
console
.
desktop
.
controller
;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import
java.io.IOException
;
import
java.io.InputStream
;
import
org.apache.commons.io.IOUtils
;
import
org.springframework.http.client.ClientHttpResponse
;
import
org.springframework.web.client.DefaultResponseErrorHandler
;
public
class
ServiceErrorHandler
extends
DefaultResponseErrorHandler
{
private
String
cause
;
@Override
public
void
handleError
(
ClientHttpResponse
response
)
throws
IOException
{
// 这里绝对不能关闭InputStream
InputStream
inputStream
=
response
.
getBody
();
cause
=
IOUtils
.
toString
(
inputStream
,
"UTF-8"
);
}
public
String
getCause
()
{
return
cause
;
}
}
\ No newline at end of file
discovery-console-desktop/src/main/java/com/nepxion/discovery/console/desktop/workspace/ServiceTopology.java
View file @
9caf8be5
...
...
@@ -760,6 +760,10 @@ public class ServiceTopology extends AbstractTopology {
}
else
if
(
node
!=
null
)
{
InstanceEntity
instance
=
(
InstanceEntity
)
node
.
getUserObject
();
String
result
=
ServiceController
.
configUpdate
(
instance
,
dynamicRule
);
showResult
(
result
);
refreshGrayState
(
node
);
}
...
...
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