[ 
https://issues.apache.org/jira/browse/KNOX-2134?focusedWorklogId=348308&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-348308
 ]

ASF GitHub Bot logged work on KNOX-2134:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 22/Nov/19 19:37
            Start Date: 22/Nov/19 19:37
    Worklog Time Spent: 10m 
      Work Description: risdenk commented on pull request #205: KNOX-2134 - Add 
caching to ZookeeperRemoteAliasService
URL: https://github.com/apache/knox/pull/205#discussion_r349760890
 
 

 ##########
 File path: 
gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/ZookeeperRemoteAliasService.java
 ##########
 @@ -228,35 +239,46 @@ public void removeAliasForCluster(final String 
clusterName, final String alias)
   }
 
   @Override
-  public char[] getPasswordFromAliasForCluster(String clusterName,
-      String alias, boolean generate) throws AliasServiceException {
+  public char[] getPasswordFromAliasForCluster(String clusterName, String 
alias, boolean generate)
+      throws AliasServiceException {
 
     char[] password = null;
 
-    /* try to get it from remote registry */
-    if (remoteClient != null) {
-      checkPathsExist(remoteClient);
-      String encrypted = null;
-
-      if(remoteClient.entryExists(buildAliasEntryName(clusterName, alias))) {
-        encrypted = remoteClient
-            .getEntryData(buildAliasEntryName(clusterName, alias));
+    // Try the local cache first
+    if (aliasCache.containsKey(clusterName)) {
+      String value = aliasCache.get(clusterName).get(alias);
+      if (value != null) {
+        password = value.toCharArray();
       }
+    }
 
-      /* Generate a new password */
-      if (encrypted == null) {
+    // If it wasn't found in the local cache, check the remote registry
+    if (password == null) {
+      /* try to get it from remote registry */
+      if (remoteClient != null) {
+        checkPathsExist(remoteClient);
+        String encrypted = null;
 
-        /* Generate a new password  */
-        if (generate) {
-          generateAliasForCluster(clusterName, alias);
-          password = getPasswordFromAliasForCluster(clusterName, alias);
+        if (remoteClient.entryExists(buildAliasEntryName(clusterName, alias))) 
{
+          encrypted = remoteClient
+              .getEntryData(buildAliasEntryName(clusterName, alias));
         }
 
-      } else {
-        try {
-          password = decrypt(encrypted).toCharArray();
-        } catch (final Exception e) {
-          throw new AliasServiceException(e);
+        /* Generate a new password */
+        if (encrypted == null) {
+
+          /* Generate a new password  */
+          if (generate) {
+            generateAliasForCluster(clusterName, alias);
+            password = getPasswordFromAliasForCluster(clusterName, alias);
+          }
+
+        } else {
+          try {
+            password = decrypt(encrypted).toCharArray();
+          } catch (final Exception e) {
+            throw new AliasServiceException(e);
+          }
 
 Review comment:
   I need to look at this in more detail - probably in an IDE. Just noting to 
myself to look closer.
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 348308)
    Time Spent: 50m  (was: 40m)

> Add caching to ZookeeperRemoteAliasService
> ------------------------------------------
>
>                 Key: KNOX-2134
>                 URL: https://issues.apache.org/jira/browse/KNOX-2134
>             Project: Apache Knox
>          Issue Type: Bug
>          Components: Server
>    Affects Versions: 1.3.0
>            Reporter: Philip Zampino
>            Assignee: Philip Zampino
>            Priority: Major
>             Fix For: 1.4.0
>
>          Time Spent: 50m
>  Remaining Estimate: 0h
>
> The ZookeeperRemoteAliasService implementation always goes to ZooKeeper to 
> retrieve alias data. Instead, it should cache the data locally to make 
> password retrieval much faster.
> The implementation already receives pushes from ZooKeeper when alias znodes 
> change, so instead of only updating the associated local alias service, it 
> can also update its own cache.
> This way, it only ever needs to go to ZooKeeper for add/remove operations.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to