From 84f1a50713f09c46bfd4efce6447df374236b20e Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Wed, 4 Oct 2017 12:10:49 +0530 Subject: [PATCH] cloudian: HTTP204 is resource does not exist Fixes regressions Signed-off-by: Rohit Yadav --- .../integrations/cloudian/docs/connector.txt | 6 ++-- .../cloudian/client/CloudianClient.java | 28 +++++++++++++------ 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/plugins/integrations/cloudian/docs/connector.txt b/plugins/integrations/cloudian/docs/connector.txt index 33bed321ec2..b2aa81c199f 100644 --- a/plugins/integrations/cloudian/docs/connector.txt +++ b/plugins/integrations/cloudian/docs/connector.txt @@ -383,7 +383,7 @@ but there was a typo and it was mapped to 'admn'. ---- DEBUG [o.a.c.c.CloudianConnectorImpl] (qtp1809303591-31:ctx-6e8e8621 ctx-40a6e707) (logid:cd96b235) Attempting Cloudian SSO with user id=admn, group id=0 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 -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. +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. ---- ==== Other Failures @@ -407,8 +407,8 @@ INFO [c.c.a.ApiServer] (qtp1638771699-28:ctx-e8b5b507 ctx-0632d279) (logid:94e8 ---- 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 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 -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 -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. +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 +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. ---- == Trouble Shooting diff --git a/plugins/integrations/cloudian/src/org/apache/cloudstack/cloudian/client/CloudianClient.java b/plugins/integrations/cloudian/src/org/apache/cloudstack/cloudian/client/CloudianClient.java index ed45c5c4c72..afcf425a97f 100644 --- a/plugins/integrations/cloudian/src/org/apache/cloudstack/cloudian/client/CloudianClient.java +++ b/plugins/integrations/cloudian/src/org/apache/cloudstack/cloudian/client/CloudianClient.java @@ -108,13 +108,17 @@ public class CloudianClient { if (response != null && response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) { final Credentials credentials = httpContext.getCredentialsProvider().getCredentials(AuthScope.ANY); LOG.error("Cloudian admin API authentication failed, please check Cloudian configuration. Admin auth principal=" + credentials.getUserPrincipal() + ", password=" + credentials.getPassword() + ", API url=" + adminApiUrl); - throw new ServerApiException(ApiErrorCode.UNAUTHORIZED, "Cloudian admin API call unauthorized, please ask your administrator to fix integration issues."); + throw new ServerApiException(ApiErrorCode.UNAUTHORIZED, "Cloudian backend API call unauthorized, please ask your administrator to fix integration issues."); } } private void checkResponseOK(final HttpResponse response) { - if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { - 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."); + if (response.getStatusLine().getStatusCode() == HttpStatus.SC_NO_CONTENT) { + LOG.debug("Requested Cloudian resource does not exist"); + return; + } + if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK && response.getStatusLine().getStatusCode() != HttpStatus.SC_NO_CONTENT) { + 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."); } } @@ -187,7 +191,9 @@ public class CloudianClient { try { final HttpResponse response = get(String.format("/user?userId=%s&groupId=%s", userId, groupId)); checkResponseOK(response); - if (response.getEntity() == null || response.getEntity().getContent() == null) { + if (response.getStatusLine().getStatusCode() == HttpStatus.SC_NO_CONTENT || + response.getEntity() == null || + response.getEntity().getContent() == null) { return null; } final ObjectMapper mapper = new ObjectMapper(); @@ -207,10 +213,12 @@ public class CloudianClient { try { final HttpResponse response = get(String.format("/user/list?groupId=%s&userType=all&userStatus=active", groupId)); checkResponseOK(response); - final ObjectMapper mapper = new ObjectMapper(); - if (response.getEntity() == null || response.getEntity().getContent() == null) { + if (response.getStatusLine().getStatusCode() == HttpStatus.SC_NO_CONTENT || + response.getEntity() == null || + response.getEntity().getContent() == null) { return new ArrayList<>(); } + final ObjectMapper mapper = new ObjectMapper(); return Arrays.asList(mapper.readValue(response.getEntity().getContent(), CloudianUser[].class)); } catch (final IOException e) { LOG.error("Failed to list Cloudian users due to:", e); @@ -276,7 +284,9 @@ public class CloudianClient { try { final HttpResponse response = get(String.format("/group?groupId=%s", groupId)); checkResponseOK(response); - if (response.getEntity() == null || response.getEntity().getContent() == null){ + if (response.getStatusLine().getStatusCode() == HttpStatus.SC_NO_CONTENT || + response.getEntity() == null || + response.getEntity().getContent() == null) { return null; } final ObjectMapper mapper = new ObjectMapper(); @@ -293,7 +303,9 @@ public class CloudianClient { try { final HttpResponse response = get("/group/list"); checkResponseOK(response); - if (response.getEntity() == null || response.getEntity().getContent() == null) { + if (response.getStatusLine().getStatusCode() == HttpStatus.SC_NO_CONTENT || + response.getEntity() == null || + response.getEntity().getContent() == null) { return new ArrayList<>(); } final ObjectMapper mapper = new ObjectMapper();