Reconnect to auth url in case of ClientProtocolException
We had a case where the authorization VIP was reset after the monasca-api started. The auth connection pool did not try to reconnect since we did not meet the configured idle time, and we had to restart the monasca-api. This fix will allow the monasca-api to reconnect the auth pool connections when we get an exception. Change-Id: I7e45970360720193b2d0ba27964bc22f66db79d3
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
|
* (C) Copyright 2014,2016 Hewlett Packard Enterprise Development LP
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||||
* in compliance with the License. You may obtain a copy of the License at
|
* in compliance with the License. You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||||
* or implied. See the License for the specific language governing permissions and limitations under
|
* or implied. See the License for the specific language governing permissions and limitations under
|
||||||
@@ -42,12 +42,19 @@ public class TokenCache {
|
|||||||
|
|
||||||
String value = null;
|
String value = null;
|
||||||
AuthClient client = null;
|
AuthClient client = null;
|
||||||
|
boolean discarded = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
client = factory.getClient();
|
client = factory.getClient();
|
||||||
value = client.validateTokenForServiceEndpointV3(key);
|
value = client.validateTokenForServiceEndpointV3(key);
|
||||||
|
} catch (ClientProtocolException e) {
|
||||||
|
factory.discard(client);
|
||||||
|
logger.warn("Validate token failed with ClientProtocolException. Discarding AuthClient connection from pool to create a new connection.");
|
||||||
|
logger.warn("ClientProtocolException " + e.getMessage() + " " + e);
|
||||||
|
discarded = true;
|
||||||
|
throw e;
|
||||||
} finally {
|
} finally {
|
||||||
if (client != null)
|
if (client != null && !discarded)
|
||||||
factory.recycle(client);
|
factory.recycle(client);
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
|
Reference in New Issue
Block a user