Skip to content

Commit 84f1a50

Browse files
cloudian: HTTP204 is resource does not exist
Fixes regressions Signed-off-by: Rohit Yadav <[email protected]>
1 parent 635d1ca commit 84f1a50

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

plugins/integrations/cloudian/docs/connector.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ but there was a typo and it was mapped to 'admn'.
383383
----
384384
DEBUG [o.a.c.c.CloudianConnectorImpl] (qtp1809303591-31:ctx-6e8e8621 ctx-40a6e707) (logid:cd96b235) Attempting Cloudian SSO with user id=admn, group id=0
385385
DEBUG [o.a.c.c.c.CloudianClient] (qtp1809303591-31:ctx-6e8e8621 ctx-40a6e707) (logid:cd96b235) Trying to find Cloudian user with id=admn and group id=0
386-
INFO [c.c.a.ApiServer] (qtp1809303591-31:ctx-6e8e8621 ctx-40a6e707) (logid:cd96b235) Failed to find the requested resource and get valid response from Cloudian admin API call, please ask your administrator to diagnose and fix issues.
386+
INFO [c.c.a.ApiServer] (qtp1809303591-31:ctx-6e8e8621 ctx-40a6e707) (logid:cd96b235) Failed to find the requested resource and get valid response from Cloudian backend API call, please ask your administrator to diagnose and fix issues.
387387
----
388388

389389
==== Other Failures
@@ -407,8 +407,8 @@ INFO [c.c.a.ApiServer] (qtp1638771699-28:ctx-e8b5b507 ctx-0632d279) (logid:94e8
407407
----
408408
DEBUG [o.a.c.c.CloudianConnectorImpl] (qtp1809303591-23:ctx-e9d61989 ctx-78760902) (logid:d3ea9e30) Attempting Cloudian SSO with user id=753a62a8-978c-4bab-bfc4-b55ea2fda505, group id=16711de6-a806-11e7-b0a6-a434d91cd37e
409409
DEBUG [o.a.c.c.c.CloudianClient] (qtp1809303591-23:ctx-e9d61989 ctx-78760902) (logid:d3ea9e30) Trying to find Cloudian user with id=753a62a8-978c-4bab-bfc4-b55ea2fda505 and group id=16711de6-a806-11e7-b0a6-a434d91cd37e
410-
ERROR [o.a.c.c.c.CloudianClient] (qtp1809303591-23:ctx-e9d61989 ctx-78760902) (logid:d3ea9e30) Cloudian admin API authentication failed, please check Cloudian configuration. Admin auth principal=[principal: admin], password=incorrect-password, API url=https://admin.abc.xyz:19443
411-
INFO [c.c.a.ApiServer] (qtp1809303591-23:ctx-e9d61989 ctx-78760902) (logid:d3ea9e30) Cloudian admin API call unauthorized, please ask your administrator to fix integration issues.
410+
ERROR [o.a.c.c.c.CloudianClient] (qtp1809303591-23:ctx-e9d61989 ctx-78760902) (logid:d3ea9e30) Cloudian backend API authentication failed, please check Cloudian configuration. Admin auth principal=[principal: admin], password=incorrect-password, API url=https://admin.abc.xyz:19443
411+
INFO [c.c.a.ApiServer] (qtp1809303591-23:ctx-e9d61989 ctx-78760902) (logid:d3ea9e30) Cloudian backend API call unauthorized, please ask your administrator to fix integration issues.
412412
----
413413

414414
== Trouble Shooting

plugins/integrations/cloudian/src/org/apache/cloudstack/cloudian/client/CloudianClient.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,17 @@ private void checkAuthFailure(final HttpResponse response) {
108108
if (response != null && response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
109109
final Credentials credentials = httpContext.getCredentialsProvider().getCredentials(AuthScope.ANY);
110110
LOG.error("Cloudian admin API authentication failed, please check Cloudian configuration. Admin auth principal=" + credentials.getUserPrincipal() + ", password=" + credentials.getPassword() + ", API url=" + adminApiUrl);
111-
throw new ServerApiException(ApiErrorCode.UNAUTHORIZED, "Cloudian admin API call unauthorized, please ask your administrator to fix integration issues.");
111+
throw new ServerApiException(ApiErrorCode.UNAUTHORIZED, "Cloudian backend API call unauthorized, please ask your administrator to fix integration issues.");
112112
}
113113
}
114114

115115
private void checkResponseOK(final HttpResponse response) {
116-
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
117-
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to find the requested resource and get valid response from Cloudian admin API call, please ask your administrator to diagnose and fix issues.");
116+
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_NO_CONTENT) {
117+
LOG.debug("Requested Cloudian resource does not exist");
118+
return;
119+
}
120+
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK && response.getStatusLine().getStatusCode() != HttpStatus.SC_NO_CONTENT) {
121+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to find the requested resource and get valid response from Cloudian backend API call, please ask your administrator to diagnose and fix issues.");
118122
}
119123
}
120124

@@ -187,7 +191,9 @@ public CloudianUser listUser(final String userId, final String groupId) {
187191
try {
188192
final HttpResponse response = get(String.format("/user?userId=%s&groupId=%s", userId, groupId));
189193
checkResponseOK(response);
190-
if (response.getEntity() == null || response.getEntity().getContent() == null) {
194+
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_NO_CONTENT ||
195+
response.getEntity() == null ||
196+
response.getEntity().getContent() == null) {
191197
return null;
192198
}
193199
final ObjectMapper mapper = new ObjectMapper();
@@ -207,10 +213,12 @@ public List<CloudianUser> listUsers(final String groupId) {
207213
try {
208214
final HttpResponse response = get(String.format("/user/list?groupId=%s&userType=all&userStatus=active", groupId));
209215
checkResponseOK(response);
210-
final ObjectMapper mapper = new ObjectMapper();
211-
if (response.getEntity() == null || response.getEntity().getContent() == null) {
216+
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_NO_CONTENT ||
217+
response.getEntity() == null ||
218+
response.getEntity().getContent() == null) {
212219
return new ArrayList<>();
213220
}
221+
final ObjectMapper mapper = new ObjectMapper();
214222
return Arrays.asList(mapper.readValue(response.getEntity().getContent(), CloudianUser[].class));
215223
} catch (final IOException e) {
216224
LOG.error("Failed to list Cloudian users due to:", e);
@@ -276,7 +284,9 @@ public CloudianGroup listGroup(final String groupId) {
276284
try {
277285
final HttpResponse response = get(String.format("/group?groupId=%s", groupId));
278286
checkResponseOK(response);
279-
if (response.getEntity() == null || response.getEntity().getContent() == null){
287+
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_NO_CONTENT ||
288+
response.getEntity() == null ||
289+
response.getEntity().getContent() == null) {
280290
return null;
281291
}
282292
final ObjectMapper mapper = new ObjectMapper();
@@ -293,7 +303,9 @@ public List<CloudianGroup> listGroups() {
293303
try {
294304
final HttpResponse response = get("/group/list");
295305
checkResponseOK(response);
296-
if (response.getEntity() == null || response.getEntity().getContent() == null) {
306+
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_NO_CONTENT ||
307+
response.getEntity() == null ||
308+
response.getEntity().getContent() == null) {
297309
return new ArrayList<>();
298310
}
299311
final ObjectMapper mapper = new ObjectMapper();

0 commit comments

Comments
 (0)