Skip to content

Commit 635d1ca

Browse files
cloudian: fix logging and error handling, updated docs
Signed-off-by: Rohit Yadav <[email protected]>
1 parent b302e5c commit 635d1ca

File tree

3 files changed

+86
-129
lines changed

3 files changed

+86
-129
lines changed

plugins/integrations/cloudian/docs/connector.txt

Lines changed: 37 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -351,16 +351,6 @@ is therefore integrated with the Management Server's log files. Logging
351351
is only output when the connector is enabled and appropriate logging
352352
configuration has been setup, for example:
353353

354-
----
355-
# cat /etc/cloudstack/management/log4j-cloud.xml
356-
357-
[...snipped...]
358-
<category name="org.apache.cloudstack.cloudian">
359-
<priority value="DEBUG"/>
360-
</category>
361-
[...snipped...]
362-
----
363-
364354
.Connector Log File
365355
----
366356
view /var/log/cloudstack/management/management-server.log
@@ -379,7 +369,7 @@ INFO [o.a.c.s.m.m.i.DefaultModuleDefinitionSet] (localhost-startStop-1:null) (l
379369
DEBUG [c.c.a.ApiServer] (localhost-startStop-1:null) (logid:) Discovered plugin CloudianConnectorImpl
380370
INFO [o.a.c.s.m.m.i.DefaultModuleDefinitionSet] (localhost-startStop-1:null) (logid:) Starting module [cloudian]
381371
...
382-
DEBUG [c.c.c.CloudianConnectorImpl] (localhost-startStop-1:null) (logid:) Cloudian connector is enabled, completed configuration, integration is ready. Cloudian admin host:admin.hs.yadav.xyz, port:19443
372+
DEBUG [c.c.c.CloudianConnectorImpl] (localhost-startStop-1:null) (logid:) Cloudian connector is enabled, completed configuration, integration is ready. Cloudian admin host:admin.abc.xyz, port:19443
383373
----
384374

385375
==== SSO Failures
@@ -391,25 +381,34 @@ but there was a typo and it was mapped to 'admn'.
391381

392382
.Example of an SSO Failure
393383
----
394-
[c.c.c.CloudianIntegrationServlet] (catalina-exec-23:null) EndUser: *admin|b3ebfd90-d73d-11e3-9a7c-002170530220|4069e3d2-d73d-11e3-9a7c-002170530220
395-
[c.c.c.CloudianIntegrationServlet] (catalina-exec-23:null) Mapping admin to 'admn'
396-
[c.c.c.CloudianIntegrationServlet] (catalina-exec-23:null) SSO login failed for admn user. Check config.
397-
[c.c.c.CloudianIntegrationServlet] (catalina-exec-23:null) SSO login failed. Removing any existing SSO Cookie.
384+
DEBUG [o.a.c.c.CloudianConnectorImpl] (qtp1809303591-31:ctx-6e8e8621 ctx-40a6e707) (logid:cd96b235) Attempting Cloudian SSO with user id=admn, group id=0
385+
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.
398387
----
399388

400389
==== Other Failures
401390

402-
Connectivity problems with the Cloudian Admin server will probably be the
403-
source of other problems logged. Below, we have incorrectly configured
404-
Basic Auth and the connector is unable to connect to the Cloudian Admin server.
391+
Connectivity problems with the Cloudian Admin server will probably be the
392+
source of other problems logged. Below, we have logs from a timeout/connectivity
393+
issue and incorrectly configured Basic Auth which causes authorization failures
394+
and the connector fails to connect to the Cloudian Admin server.
395+
396+
.Admin Server connection problem due to time out
397+
----
398+
DEBUG [o.a.c.c.CloudianConnectorImpl] (qtp1809303591-372:ctx-a707eecc ctx-0e85865f) (logid:3efb32f0) Attempting Cloudian SSO with user id=753a62a8-978c-4bab-bfc4-b55ea2fda505, group id=16711de6-a806-11e7-b0a6-a434d91cd37e
399+
DEBUG [o.a.c.c.c.CloudianClient] (qtp1809303591-372:ctx-a707eecc ctx-0e85865f) (logid:3efb32f0) Trying to find Cloudian user with id=753a62a8-978c-4bab-bfc4-b55ea2fda505 and group id=16711de6-a806-11e7-b0a6-a434d91cd37e
400+
ERROR [o.a.c.c.c.CloudianClient] (qtp1809303591-372:ctx-a707eecc ctx-0e85865f) (logid:3efb32f0) Failed to list Cloudian user due to:
401+
org.apache.http.conn.ConnectTimeoutException: Connect to admin.hs.yadav.xyz:19443 [admin.abc.xyz/10.5.1.6] failed: connect timed out
402+
[...snipped...]
403+
INFO [c.c.a.ApiServer] (qtp1638771699-28:ctx-e8b5b507 ctx-0632d279) (logid:94e8345e) Operation timed out, please try again.
404+
----
405405

406406
.Admin Server Connection problem logging in as admin
407407
----
408-
[c.c.c.CloudianIntegrationServlet] (catalina-exec-17:null) EndUser: *admin|b3ebfd90-d73d-11e3-9a7c-002170530220|4069e3d2-d73d-11e3-9a7c-002170530220
409-
[c.c.c.CloudianIntegrationServlet] (catalina-exec-17:null) Mapping admin to 'admin'
410-
[o.a.c.h.a.AuthChallengeProcessor] (catalina-exec-17:null) basic authentication scheme selected
411-
[o.a.c.h.HttpMethodDirector] (catalina-exec-17:null) Failure authenticating with BASIC 'CloudianAdmin'@admin.cloudian.com:18081
412-
[c.c.c.CloudianIntegrationServlet] (catalina-exec-17:null) SSO login request failed for '*admin|b3ebfd90-d73d-11e3-9a7c-002170530220|4069e3d2-d73d-11e3-9a7c-002170530220'
408+
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
409+
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.
413412
----
414413

415414
== Trouble Shooting
@@ -422,20 +421,18 @@ There are a few things which can go wrong for SSO. Here are the
422421
most common problems and things to check.
423422
+
424423
.SSO Check List
425-
* Does the mapping of adminUserId point to the correct Cloudian user
426-
in the <<properties,Connector Properties File>>?
424+
* Does the global settings 'cloudian.cmc.admin.user' point to the correct
425+
Cloudian (admin) user?
427426
* Is SSO configured and enabled on Cloudian HyperStore CMC?
428427
* Check for errors in the CMC log file.
429-
* Are both CloudStack and HyperStore CMC configured with the same
430-
ssoSharedKey?
431-
* Try running 'cloudian-cloudstack.sh configure' which runs through
432-
the connectivity settings.
428+
* Are both CloudStack and HyperStore CMC configured with the same
429+
'cloudian.sso.key'?
433430
* Check the /var/log/cloudstack/management/management-server.log file and
434431
search for errors relating to SSO.
435-
* Try access the CMC host directly from the problem users host using
436-
the configured cmcHost, cmcPort and cmcProtocol configured in the
437-
<<properties,Connector Properties File>>.
438-
* If you log out of the management server and log in again, does
432+
* Try access the CMC host directly from the problem users host using
433+
the configured 'cloudian.cmc.host', 'cloudian.cmc.port' and 'cloudian.cmc.protocol'
434+
configured in the CloudStack global settings.
435+
* If you log out of the management server and log in again, does
439436
the 'Cloudian Storage' button work?
440437

441438
. Adding/Deleting Domains or Accounts fails
@@ -445,73 +442,15 @@ has changed with the connection or the admin server is down?
445442
+
446443
.Admin Check List
447444
* Is the admin server alive and listening?
448-
* Run the 'cloudian-cloudstack.sh configure' script as it tests the connection
449-
using the configured properties. This will usually identify the problem.
445+
* Try access the admin server host directly from the problem users host using
446+
the configured 'cloudian.admin.host', 'cloudian.admin.port' and
447+
'cloudian.admin.protocol' configured in the CloudStack global settings. Check
448+
the configured auth settings 'cloudian.admin.user' and
449+
'cloudian.admin.password'.
450+
* If you're experiencing timeout issues, trying changing the API timeout value
451+
defined in 'cloudian.api.request.timeout' global setting.
450452
* Look for errors in the admin log file /var/log/cloudian/cloudian-admin.log.
451453

452-
. CloudStack Patching
453-
+
454-
The enable and disable options of the 'cloudian-cloudstack.sh' script
455-
usually manages all the patching for you. The following shows you
456-
the normal clean state of the cloudstack-management installation. Note
457-
though that the output will vary slightly depending on your installation
458-
and what you have changed.
459-
+
460-
.With Connector not installed
461-
----
462-
# rpm -qV cloudstack-management
463-
S.5....T. c /etc/cloudstack/management/db.properties
464-
.......T. /var/run/cloudstack-management.pid
465-
----
466-
+
467-
.With Connector installed
468-
----
469-
# rpm -qV cloudstack-management
470-
471-
# rpm -qV cloudstack-management
472-
S.5....T. c /etc/cloudstack/management/db.properties
473-
S.5....T. /usr/share/cloudstack-management/webapps/client/plugins/plugins.js
474-
S.5....T. /usr/share/cloudstack-management/webapps/client/plugins/plugins.js.gz
475-
.......T. /var/run/cloudstack-management.pid
476-
----
477-
478-
. Fail-safe botched scripts recovery
479-
+
480-
This procedure is probably not required but is noted here as a
481-
fail-safe recovery method if things fail when you for update
482-
packages or otherwise and unexpected things happen.
483-
+
484-
RPM is luckily a great way to manage application files on a machine
485-
as the original RPM contains everything you need to recover and
486-
re-install the original state of the CloudStack Application. If
487-
things don't work for some reason and you want to back things out
488-
, but disable doesn't work for some reason, you can do the following:
489-
+
490-
.First, try uninstall the connector
491-
----
492-
# rpm -e cloudian-cloudplatform
493-
----
494-
+
495-
If that fails to uninstall for some reason you can try to uninstall
496-
it using the '--noscripts' option as below:
497-
+
498-
.Optionally, force uninstall the connector (if uninstall fails)
499-
----
500-
# rpm -e --noscripts cloudian-cloudplatform
501-
----
502-
+
503-
Next re-install (without uninstalling) CloudStack. Re-install
504-
will keep any configuration files belonging to CloudStack intact
505-
and just gets the application files back to its initial installation
506-
state.
507-
+
508-
[subs="attributes"]
509-
----
510-
# yum reinstall ./CloudStack-{cpver}.0.0-rhel/cloudstack-management-{cpver}.0.0-1.el6.x86_64.rpm
511-
----
512-
+
513-
At this point you can install, configure and enable the connector again.
514-
515454
''''
516455

517456
_Confidentiality Notice_

plugins/integrations/cloudian/src/org/apache/cloudstack/cloudian/CloudianConnectorImpl.java

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
import org.apache.cloudstack.acl.RoleType;
3131
import org.apache.cloudstack.api.ApiErrorCode;
3232
import org.apache.cloudstack.api.ServerApiException;
33-
import org.apache.cloudstack.cloudian.api.CloudianSsoLoginCmd;
3433
import org.apache.cloudstack.cloudian.api.CloudianIsEnabledCmd;
34+
import org.apache.cloudstack.cloudian.api.CloudianSsoLoginCmd;
3535
import org.apache.cloudstack.cloudian.client.CloudianClient;
3636
import org.apache.cloudstack.cloudian.client.CloudianGroup;
3737
import org.apache.cloudstack.cloudian.client.CloudianUser;
@@ -85,20 +85,11 @@ private CloudianClient getClient() {
8585
throw new CloudRuntimeException("Failed to create and return Cloudian API client instance");
8686
}
8787

88-
private boolean addOrUpdateGroup(final Domain domain) {
88+
private boolean addGroup(final Domain domain) {
8989
if (domain == null || !isEnabled()) {
9090
return false;
9191
}
9292
final CloudianClient client = getClient();
93-
final CloudianGroup existingGroup = client.listGroup(domain.getUuid());
94-
if (existingGroup != null) {
95-
if (!existingGroup.getActive() || !existingGroup.getGroupName().equals(domain.getPath())) {
96-
existingGroup.setActive(true);
97-
existingGroup.setGroupName(domain.getPath());
98-
return client.updateGroup(existingGroup);
99-
}
100-
return true;
101-
}
10293
final CloudianGroup group = new CloudianGroup();
10394
group.setGroupId(domain.getUuid());
10495
group.setGroupName(domain.getPath());
@@ -127,23 +118,13 @@ private boolean removeGroup(final Domain domain) {
127118
return false;
128119
}
129120

130-
private boolean addOrUpdateUserAccount(final Account account, final Domain domain) {
121+
private boolean addUserAccount(final Account account, final Domain domain) {
131122
if (account == null || domain == null || !isEnabled()) {
132123
return false;
133124
}
134125
final User accountUser = userDao.listByAccount(account.getId()).get(0);
135-
final String fullName = String.format("%s %s (%s)", accountUser.getFirstname(), accountUser.getLastname(), account.getAccountName());
136126
final CloudianClient client = getClient();
137-
final CloudianUser existingUser = client.listUser(account.getUuid(), domain.getUuid());
138-
if (existingUser != null) {
139-
if (!existingUser.getActive() || !existingUser.getFullName().equals(fullName)) {
140-
existingUser.setActive(true);
141-
existingUser.setEmailAddr(accountUser.getEmail());
142-
existingUser.setFullName(fullName);
143-
return client.updateUser(existingUser);
144-
}
145-
return true;
146-
}
127+
final String fullName = String.format("%s %s (%s)", accountUser.getFirstname(), accountUser.getLastname(), account.getAccountName());
147128
final CloudianUser user = new CloudianUser();
148129
user.setUserId(account.getUuid());
149130
user.setGroupId(domain.getUuid());
@@ -154,6 +135,25 @@ private boolean addOrUpdateUserAccount(final Account account, final Domain domai
154135
return client.addUser(user);
155136
}
156137

138+
private boolean updateUserAccount(final Account account, final Domain domain, final CloudianUser existingUser) {
139+
if (account == null || domain == null || !isEnabled()) {
140+
return false;
141+
}
142+
final CloudianClient client = getClient();
143+
if (existingUser != null) {
144+
final User accountUser = userDao.listByAccount(account.getId()).get(0);
145+
final String fullName = String.format("%s %s (%s)", accountUser.getFirstname(), accountUser.getLastname(), account.getAccountName());
146+
if (!existingUser.getActive() || !existingUser.getFullName().equals(fullName) || !existingUser.getEmailAddr().equals(accountUser.getEmail())) {
147+
existingUser.setActive(true);
148+
existingUser.setFullName(fullName);
149+
existingUser.setEmailAddr(accountUser.getEmail());
150+
return client.updateUser(existingUser);
151+
}
152+
return true;
153+
}
154+
return false;
155+
}
156+
157157
private boolean removeUserAccount(final Account account) {
158158
if (account == null || !isEnabled()) {
159159
return false;
@@ -197,13 +197,31 @@ public String generateSsoUrl() {
197197
if (caller.getAccountName().equals("admin") && caller.getRoleId() == RoleType.Admin.getId()) {
198198
user = CloudianCmcAdminUser.value();
199199
group = "0";
200-
final CloudianUser adminUser = getClient().listUser(user, group);
201-
if (adminUser == null) {
202-
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to find mapped Cloudian admin user, please fix integration issues.");
200+
}
201+
202+
LOG.debug(String.format("Attempting Cloudian SSO with user id=%s, group id=%s", user, group));
203+
204+
final CloudianUser ssoUser = getClient().listUser(user, group);
205+
if (ssoUser == null || !ssoUser.getActive()) {
206+
LOG.debug(String.format("Failed to find existing Cloudian user id=%s in group id=%s", user, group));
207+
final CloudianGroup ssoGroup = getClient().listGroup(group);
208+
if (ssoGroup == null) {
209+
LOG.debug(String.format("Failed to find existing Cloudian group id=%s, trying to add it", group));
210+
if (!addGroup(domain)) {
211+
LOG.error("Failed to add missing Cloudian group id=" + group);
212+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Aborting Cloudian SSO, failed to add group to Cloudian.");
213+
}
214+
}
215+
if (!addUserAccount(caller, domain)) {
216+
LOG.error("Failed to add missing Cloudian group id=" + group);
217+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Aborting Cloudian SSO, failed to add user to Cloudian.");
218+
}
219+
final CloudianUser addedSsoUser = getClient().listUser(user, group);
220+
if (addedSsoUser == null || !addedSsoUser.getActive()) {
221+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Aborting Cloudian SSO, failed to find mapped Cloudian user, please fix integration issues.");
203222
}
204223
} else {
205-
addOrUpdateGroup(domain);
206-
addOrUpdateUserAccount(caller, domain);
224+
updateUserAccount(caller, domain, ssoUser);
207225
}
208226

209227
return CloudianUtils.generateSSOUrl(getCmcUrl(), user, group, CloudianSsoKey.value());
@@ -235,7 +253,7 @@ public void onPublishMessage(String senderAddress, String subject, Object args)
235253
final Account account = accountDao.findById(accountId);
236254
final Domain domain = domainDao.findById(account.getDomainId());
237255

238-
if (!addOrUpdateUserAccount(account, domain)) {
256+
if (!addUserAccount(account, domain)) {
239257
LOG.warn(String.format("Failed to add account in Cloudian while adding CloudStack account=%s in domain=%s", account.getAccountName(), domain.getPath()));
240258
}
241259
} catch (final Exception e) {
@@ -263,7 +281,7 @@ public void onPublishMessage(String senderAddress, String subject, Object args)
263281
public void onPublishMessage(String senderAddress, String subject, Object args) {
264282
try {
265283
final Domain domain = domainDao.findById((Long) args);
266-
if (!addOrUpdateGroup(domain)) {
284+
if (!addGroup(domain)) {
267285
LOG.warn(String.format("Failed to add group in Cloudian while adding CloudStack domain=%s id=%s", domain.getPath(), domain.getId()));
268286
}
269287
} catch (final Exception e) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ private void checkAuthFailure(final HttpResponse response) {
114114

115115
private void checkResponseOK(final HttpResponse response) {
116116
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
117-
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to get valid response from Cloudian admin API call, please ask your administrator to fix diagnose and fix issues.");
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.");
118118
}
119119
}
120120

0 commit comments

Comments
 (0)