Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
佳 邓
Gitlab4j Api
Commits
d003fbd9
Unverified
Commit
d003fbd9
authored
Nov 09, 2019
by
Greg Messner
Committed by
GitHub
Nov 09, 2019
Browse files
Add support for new health check JSON format - #468 (#474)
parent
039d3277
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/models/HealthCheckInfo.java
View file @
d003fbd9
package
org.gitlab4j.api.models
;
import
java.io.IOException
;
import
org.gitlab4j.api.utils.JacksonJson
;
import
com.fasterxml.jackson.core.JsonParser
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.DeserializationContext
;
import
com.fasterxml.jackson.databind.JsonDeserializer
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.annotation.JsonDeserialize
;
public
class
HealthCheckInfo
{
@JsonDeserialize
(
using
=
HealthCheckItemDeserializer
.
class
)
private
HealthCheckItem
dbCheck
;
@JsonDeserialize
(
using
=
HealthCheckItemDeserializer
.
class
)
private
HealthCheckItem
redisCheck
;
@JsonDeserialize
(
using
=
HealthCheckItemDeserializer
.
class
)
private
HealthCheckItem
cacheCheck
;
@JsonDeserialize
(
using
=
HealthCheckItemDeserializer
.
class
)
private
HealthCheckItem
queuesCheck
;
@JsonDeserialize
(
using
=
HealthCheckItemDeserializer
.
class
)
private
HealthCheckItem
sharedStateCheck
;
@JsonDeserialize
(
using
=
HealthCheckItemDeserializer
.
class
)
private
HealthCheckItem
fsShardsCheck
;
@JsonDeserialize
(
using
=
HealthCheckItemDeserializer
.
class
)
private
HealthCheckItem
gitalyCheck
;
public
HealthCheckItem
getDbCheck
()
{
...
...
@@ -71,4 +95,29 @@ public class HealthCheckInfo {
public
String
toString
()
{
return
(
JacksonJson
.
toJsonString
(
this
));
}
/**
* This desrializer can deserialize on object containing a HealthCheckItem or an
* array containing a single HealthCheckItem.
*/
private
static
class
HealthCheckItemDeserializer
extends
JsonDeserializer
<
HealthCheckItem
>
{
private
static
final
ObjectMapper
mapper
=
new
JacksonJson
().
getObjectMapper
();
@Override
public
HealthCheckItem
deserialize
(
JsonParser
jsonParser
,
DeserializationContext
ctx
)
throws
IOException
,
JsonProcessingException
{
HealthCheckItem
healthCheckItem
=
null
;
JsonNode
tree
=
jsonParser
.
readValueAsTree
();
if
(
tree
.
isArray
())
{
JsonNode
node
=
tree
.
get
(
0
);
healthCheckItem
=
mapper
.
treeToValue
(
node
,
HealthCheckItem
.
class
);
}
else
if
(
tree
.
isObject
())
{
healthCheckItem
=
mapper
.
treeToValue
(
tree
,
HealthCheckItem
.
class
);
}
return
(
healthCheckItem
);
}
}
}
src/test/java/org/gitlab4j/api/TestGitLabApiBeans.java
View file @
d003fbd9
...
...
@@ -262,6 +262,12 @@ public class TestGitLabApiBeans {
assertTrue
(
compareJson
(
healthCheck
,
"health-check.json"
));
}
@Test
public
void
testHealthCheckInfoNew
()
throws
Exception
{
HealthCheckInfo
healthCheck
=
unmarshalResource
(
HealthCheckInfo
.
class
,
"health-check-new.json"
);
assertTrue
(
compareJson
(
healthCheck
,
"health-check.json"
));
}
@Test
public
void
testImportStatus
()
throws
Exception
{
ImportStatus
importStatus
=
unmarshalResource
(
ImportStatus
.
class
,
"import-status.json"
);
...
...
src/test/resources/org/gitlab4j/api/health-check-new.json
0 → 100644
View file @
d003fbd9
{
"queues_check"
:
[{
"status"
:
"ok"
}],
"redis_check"
:
[{
"status"
:
"ok"
}],
"shared_state_check"
:
[{
"status"
:
"ok"
}],
"fs_shards_check"
:
[{
"labels"
:
{
"shard"
:
"default"
},
"status"
:
"ok"
}],
"db_check"
:
[{
"status"
:
"failed"
,
"message"
:
"Problem with database."
}],
"cache_check"
:
[{
"status"
:
"ok"
}]
}
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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