This is an automated email from the ASF dual-hosted git repository.

smolnar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/knox.git


The following commit(s) were added to refs/heads/master by this push:
     new 17e96df  KNOX-2366 - Pinned topologies are expanded and general proxy 
information section is collapsed on HomePage by default (#335)
17e96df is described below

commit 17e96dfc1b895c0519a762ed22785e2cac7e0a3e
Author: Sandor Molnar <[email protected]>
AuthorDate: Thu May 7 10:06:13 2020 +0200

    KNOX-2366 - Pinned topologies are expanded and general proxy information 
section is collapsed on HomePage by default (#335)
---
 .../knox/gateway/config/impl/GatewayConfigImpl.java   | 10 +++++++++-
 gateway-service-metadata/pom.xml                      |  4 ++++
 .../service/metadata/KnoxMetadataResource.java        | 12 +++++++++++-
 .../gateway/service/metadata/TopologyInformation.java | 19 ++++++++++++++++++-
 .../service/metadata/TopologyInformationWrapper.java  |  7 ++++---
 .../org/apache/knox/gateway/config/GatewayConfig.java |  5 +++++
 .../org/apache/knox/gateway/GatewayTestConfig.java    |  5 +++++
 .../general.proxy.information.component.html          |  6 ++++--
 .../general.proxy.information.component.ts            |  7 ++++++-
 .../topologies/topology.information.component.html    | 14 ++++++++++++--
 .../app/topologies/topology.information.component.ts  |  6 ++++--
 .../home/app/topologies/topology.information.ts       |  1 +
 12 files changed, 83 insertions(+), 13 deletions(-)

diff --git 
a/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java
 
b/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java
index e9a9a00..6f690cc 100644
--- 
a/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java
+++ 
b/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java
@@ -39,6 +39,7 @@ import java.net.UnknownHostException;
 import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
@@ -252,6 +253,7 @@ public class GatewayConfigImpl extends Configuration 
implements GatewayConfig {
   private static final long KNOX_TOKEN_EVICTION_GRACE_PERIOD_DEFAULT = 
TimeUnit.HOURS.toSeconds(24);
   private static final boolean 
KNOX_TOKEN_PERMISSIVE_VALIDATION_ENABLED_DEFAULT = false;
 
+  private static final String KNOX_HOMEPAGE_PINNED_TOPOLOGIES =  
"knox.homepage.pinned.topologies";
   private static final String KNOX_HOMEPAGE_HIDDEN_TOPOLOGIES =  
"knox.homepage.hidden.topologies";
   private static final Set<String> KNOX_HOMEPAGE_HIDDEN_TOPOLOGIES_DEFAULT = 
new HashSet<>(Arrays.asList("admin", "manager", "knoxsso", "metadata", 
"homepage"));
 
@@ -1138,10 +1140,16 @@ public class GatewayConfigImpl extends Configuration 
implements GatewayConfig {
 
   @Override
   public Set<String> getHiddenTopologiesOnHomepage() {
-    final Set<String> hiddenTopologies = new 
HashSet<>(getStringCollection(KNOX_HOMEPAGE_HIDDEN_TOPOLOGIES));
+    final Set<String> hiddenTopologies = new 
HashSet<>(getTrimmedStringCollection(KNOX_HOMEPAGE_HIDDEN_TOPOLOGIES));
     return hiddenTopologies == null || hiddenTopologies.isEmpty() ? 
KNOX_HOMEPAGE_HIDDEN_TOPOLOGIES_DEFAULT : hiddenTopologies;
   }
 
+  @Override
+  public Set<String> getPinnedTopologiesOnHomepage() {
+    final Collection<String> pinnedTopologies = 
getTrimmedStringCollection(KNOX_HOMEPAGE_PINNED_TOPOLOGIES);
+    return pinnedTopologies == null ? Collections.emptySet() : new 
HashSet<>(pinnedTopologies);
+  }
+
   /**
    * @return returns whether know token permissive failure is enabled
    */
diff --git a/gateway-service-metadata/pom.xml b/gateway-service-metadata/pom.xml
index 1610ae5..fe05084 100644
--- a/gateway-service-metadata/pom.xml
+++ b/gateway-service-metadata/pom.xml
@@ -70,5 +70,9 @@
             <groupId>org.eclipse.persistence</groupId>
             <artifactId>eclipselink</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.glassfish.hk2.external</groupId>
+            <artifactId>javax.inject</artifactId>
+        </dependency>
     </dependencies>
 </project>
diff --git 
a/gateway-service-metadata/src/main/java/org/apache/knox/gateway/service/metadata/KnoxMetadataResource.java
 
b/gateway-service-metadata/src/main/java/org/apache/knox/gateway/service/metadata/KnoxMetadataResource.java
index 1a89fb6..6589849 100644
--- 
a/gateway-service-metadata/src/main/java/org/apache/knox/gateway/service/metadata/KnoxMetadataResource.java
+++ 
b/gateway-service-metadata/src/main/java/org/apache/knox/gateway/service/metadata/KnoxMetadataResource.java
@@ -36,6 +36,7 @@ import java.util.Optional;
 import java.util.Set;
 import java.util.TreeSet;
 
+import javax.inject.Singleton;
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.DefaultValue;
 import javax.ws.rs.GET;
@@ -63,12 +64,14 @@ import org.apache.knox.gateway.topology.Service;
 import org.apache.knox.gateway.topology.Topology;
 import org.apache.knox.gateway.util.X509CertificateUtil;
 
+@Singleton
 @Path("/api/v1/metadata")
 public class KnoxMetadataResource {
   private static final MetadataServiceMessages LOG = 
MessagesFactory.get(MetadataServiceMessages.class);
   private static final String SNAPSHOT_VERSION_POSTFIX = "-SNAPSHOT";
   private static final Set<String> UNREAL_SERVICES = 
Collections.unmodifiableSet(new HashSet<>(Arrays.asList("NAMENODE", 
"JOBTRACKER")));
 
+  private Set<String> pinnedTopologies;
   private java.nio.file.Path pemFilePath;
   private java.nio.file.Path jksFilePath;
 
@@ -209,13 +212,20 @@ public class KnoxMetadataResource {
               }
             });
           });
-          topologies.addTopology(topology.getName(), new 
TreeSet<>(apiServices), new TreeSet<>(uiServices));
+          topologies.addTopology(topology.getName(), 
isPinnedTopology(topology.getName(), config), new TreeSet<>(apiServices), new 
TreeSet<>(uiServices));
         }
       }
     }
     return topologies;
   }
 
+  boolean isPinnedTopology(String topologyName, GatewayConfig config) {
+    if (pinnedTopologies == null) {
+      pinnedTopologies = config.getPinnedTopologiesOnHomepage();
+    }
+    return pinnedTopologies.contains(topologyName);
+  }
+
   private Metadata getServiceMetadata(ServiceDefinitionRegistry 
serviceDefinitionRegistry, Service service) {
     final Optional<ServiceDefinitionPair> serviceDefinition = 
serviceDefinitionRegistry.getServiceDefinitions().stream()
         .filter(serviceDefinitionPair -> 
serviceDefinitionPair.getService().getRole().equalsIgnoreCase(service.getRole()))
diff --git 
a/gateway-service-metadata/src/main/java/org/apache/knox/gateway/service/metadata/TopologyInformation.java
 
b/gateway-service-metadata/src/main/java/org/apache/knox/gateway/service/metadata/TopologyInformation.java
index 067d73a..c544f77 100644
--- 
a/gateway-service-metadata/src/main/java/org/apache/knox/gateway/service/metadata/TopologyInformation.java
+++ 
b/gateway-service-metadata/src/main/java/org/apache/knox/gateway/service/metadata/TopologyInformation.java
@@ -24,11 +24,14 @@ import javax.xml.bind.annotation.XmlElementWrapper;
 import javax.xml.bind.annotation.XmlRootElement;
 
 @XmlRootElement(name = "topology")
-public class TopologyInformation {
+public class TopologyInformation implements Comparable<TopologyInformation>{
 
   @XmlElement(name = "topology")
   private String topologyName;
 
+  @XmlElement(name = "pinned")
+  private boolean pinned;
+
   @XmlElement(name = "service")
   @XmlElementWrapper(name = "apiServices")
   private Set<ServiceModel> apiServices;
@@ -45,6 +48,14 @@ public class TopologyInformation {
     this.topologyName = topologyName;
   }
 
+  public boolean isPinned() {
+    return pinned;
+  }
+
+  public void setPinned(boolean pinned) {
+    this.pinned = pinned;
+  }
+
   public Set<ServiceModel> getApiServices() {
     return apiServices;
   }
@@ -61,4 +72,10 @@ public class TopologyInformation {
     this.uiServices = uiServices;
   }
 
+  @Override
+  public int compareTo(TopologyInformation other) {
+    final int byPinned =  Boolean.compare(other.pinned, pinned);
+    return byPinned == 0 ? topologyName.compareTo(other.topologyName) : 
byPinned;
+  }
+
 }
diff --git 
a/gateway-service-metadata/src/main/java/org/apache/knox/gateway/service/metadata/TopologyInformationWrapper.java
 
b/gateway-service-metadata/src/main/java/org/apache/knox/gateway/service/metadata/TopologyInformationWrapper.java
index 0e9177b..5613b9f 100644
--- 
a/gateway-service-metadata/src/main/java/org/apache/knox/gateway/service/metadata/TopologyInformationWrapper.java
+++ 
b/gateway-service-metadata/src/main/java/org/apache/knox/gateway/service/metadata/TopologyInformationWrapper.java
@@ -17,8 +17,8 @@
  */
 package org.apache.knox.gateway.service.metadata;
 
-import java.util.HashSet;
 import java.util.Set;
+import java.util.TreeSet;
 
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
@@ -30,15 +30,16 @@ public class TopologyInformationWrapper {
 
   @XmlElement(name = "topologyInformation")
   @XmlElementWrapper(name = "topologyInformations")
-  private Set<TopologyInformation> topologies = new HashSet<>();
+  private Set<TopologyInformation> topologies = new TreeSet<>();
 
   public Set<TopologyInformation> getTopologies() {
     return topologies;
   }
 
-  public void addTopology(String name, Set<ServiceModel> apiServices, 
Set<ServiceModel> uiServices) {
+  public void addTopology(String name, boolean pinned, Set<ServiceModel> 
apiServices, Set<ServiceModel> uiServices) {
     final TopologyInformation topology = new TopologyInformation();
     topology.setTopologyName(name);
+    topology.setPinned(pinned);
     topology.setApiServices(apiServices);
     topology.setUiServices(uiServices);
     this.topologies.add(topology);
diff --git 
a/gateway-spi/src/main/java/org/apache/knox/gateway/config/GatewayConfig.java 
b/gateway-spi/src/main/java/org/apache/knox/gateway/config/GatewayConfig.java
index 1ca785c..2ebd9ae 100644
--- 
a/gateway-spi/src/main/java/org/apache/knox/gateway/config/GatewayConfig.java
+++ 
b/gateway-spi/src/main/java/org/apache/knox/gateway/config/GatewayConfig.java
@@ -679,6 +679,11 @@ public interface GatewayConfig {
   Set<String> getHiddenTopologiesOnHomepage();
 
   /**
+   * @return the list of pinned topologies on Knox homepage
+   */
+  Set<String> getPinnedTopologiesOnHomepage();
+
+  /**
    * @return returns whether know token permissive validation is enabled
    */
   boolean isKnoxTokenPermissiveValidationEnabled();
diff --git 
a/gateway-test-release-utils/src/main/java/org/apache/knox/gateway/GatewayTestConfig.java
 
b/gateway-test-release-utils/src/main/java/org/apache/knox/gateway/GatewayTestConfig.java
index 5e46f88..8c2a1da 100644
--- 
a/gateway-test-release-utils/src/main/java/org/apache/knox/gateway/GatewayTestConfig.java
+++ 
b/gateway-test-release-utils/src/main/java/org/apache/knox/gateway/GatewayTestConfig.java
@@ -795,6 +795,11 @@ public class GatewayTestConfig extends Configuration 
implements GatewayConfig {
     return Collections.emptySet();
   }
 
+  @Override
+  public Set<String> getPinnedTopologiesOnHomepage() {
+    return Collections.emptySet();
+  }
+
   /**
    * @return returns whether know token permissive failure is enabled
    */
diff --git 
a/knox-homepage-ui/home/app/generalProxyInformation/general.proxy.information.component.html
 
b/knox-homepage-ui/home/app/generalProxyInformation/general.proxy.information.component.html
index 4271b26..34fe871 100644
--- 
a/knox-homepage-ui/home/app/generalProxyInformation/general.proxy.information.component.html
+++ 
b/knox-homepage-ui/home/app/generalProxyInformation/general.proxy.information.component.html
@@ -12,8 +12,10 @@
   See the License for the specific language governing permissions and
   limitations under the License.
 -->
-<h4>General Proxy Information</h4>
-<div class="table-responsive">
+<div>
+     <h4 (click)="toggleBoolean('showGeneralProxyInformation')"><span 
[class]="'clickable inline-glyph glyhpicon glyphicon-' + 
(this['showGeneralProxyInformation'] ? 'minus' : 'plus')"></span>&nbsp;General 
Proxy Information</h4>
+</div>
+<div class="table-responsive" *ngIf="this['showGeneralProxyInformation']">
     <table class="table table-striped table-hover">
        <colgroup>
             <col width="30%">
diff --git 
a/knox-homepage-ui/home/app/generalProxyInformation/general.proxy.information.component.ts
 
b/knox-homepage-ui/home/app/generalProxyInformation/general.proxy.information.component.ts
index 7ba4abd..3d44a33 100644
--- 
a/knox-homepage-ui/home/app/generalProxyInformation/general.proxy.information.component.ts
+++ 
b/knox-homepage-ui/home/app/generalProxyInformation/general.proxy.information.component.ts
@@ -28,7 +28,9 @@ export class GeneralProxyInformationComponent implements 
OnInit {
 
     generalProxyInformation: GeneralProxyInformation;
 
-    constructor(private homepageService: HomepageService) {}
+    constructor(private homepageService: HomepageService) {
+        this['showGeneralProxyInformation'] = false;
+    }
 
     getVersion() {
         if (this.generalProxyInformation) {
@@ -66,4 +68,7 @@ export class GeneralProxyInformationComponent implements 
OnInit {
                             .then(generalProxyInformation => 
this.generalProxyInformation = generalProxyInformation);
     }
 
+    toggleBoolean(propertyName: string) {
+        this[propertyName] = !this[propertyName];
+    }
 }
diff --git 
a/knox-homepage-ui/home/app/topologies/topology.information.component.html 
b/knox-homepage-ui/home/app/topologies/topology.information.component.html
index 9d2e542..4ba685f 100644
--- a/knox-homepage-ui/home/app/topologies/topology.information.component.html
+++ b/knox-homepage-ui/home/app/topologies/topology.information.component.html
@@ -13,13 +13,22 @@
   limitations under the License.
 -->
 <hr/>
-<h4>Topologies</h4>
+<div>
+     <h4 (click)="toggleBoolean('showTopologies')"><span [class]="'clickable 
inline-glyph glyhpicon glyphicon-' + (this['showTopologies'] ? 'minus' : 
'plus')"></span>&nbsp;Topologies</h4>
+</div>
+<div *ngIf="this['showTopologies']">
 <ng-container *ngFor="let topology of topologies">
     <div>
       <span [class]="'clickable inline-glyph
       glyhpicon glyphicon-' + (this['showTopology_' + topology.topology] ? 
'minus' : 'plus')"
       (click)="toggleBoolean('showTopology_' + topology.topology)"></span>
       <span (click)="toggleBoolean('showTopology_' + 
topology.topology)"><strong>{{topology.topology}}</strong></span>
+      <span class="inline-glyph glyphicon glyphicon-pushpin btn btn-xs" 
*ngIf="topology.pinned"
+            title="You may unpin this topology in gateway-site.xml by removing 
it from the list declared in 'knox.homepage.pinned.topologies'"
+            data-toggle="tooltip"></span>
+      <span class="inline-glyph glyphicon glyphicon-cog btn btn-xs" 
*ngIf="!topology.pinned"
+            title="You may pin this topology in gateway-site.xml using the 
'knox.homepage.pinned.topologies' property"
+            data-toggle="tooltip"></span>
     </div>
 
     <div class="table-responsive" *ngIf="this['showTopology_' + 
topology.topology]">
@@ -75,4 +84,5 @@
         </table>
     </div>
 </ng-container>
-<hr />
\ No newline at end of file
+<hr />
+</div>
\ No newline at end of file
diff --git 
a/knox-homepage-ui/home/app/topologies/topology.information.component.ts 
b/knox-homepage-ui/home/app/topologies/topology.information.component.ts
index f71496d..f251a8f 100644
--- a/knox-homepage-ui/home/app/topologies/topology.information.component.ts
+++ b/knox-homepage-ui/home/app/topologies/topology.information.component.ts
@@ -34,7 +34,7 @@ export class TopologyInformationsComponent implements OnInit {
     setTopologies(topologies: TopologyInformation[]) {
         this.topologies = topologies;
         for (let topology of topologies) {
-            this['showTopology_' + topology.topology] = false;
+            this['showTopology_' + topology.topology] = topology.pinned;
         }
     }
 
@@ -46,7 +46,9 @@ export class TopologyInformationsComponent implements OnInit {
         this[enableServiceText] = true;
     }
 
-    constructor(private homepageService: HomepageService) {}
+    constructor(private homepageService: HomepageService) {
+        this['showTopologies'] = true;
+    }
 
     ngOnInit(): void {
         console.debug('TopologyInformationsComponent --> ngOnInit()');
diff --git a/knox-homepage-ui/home/app/topologies/topology.information.ts 
b/knox-homepage-ui/home/app/topologies/topology.information.ts
index 09d272a..5bb00a0 100644
--- a/knox-homepage-ui/home/app/topologies/topology.information.ts
+++ b/knox-homepage-ui/home/app/topologies/topology.information.ts
@@ -18,6 +18,7 @@ import {Service} from './service';
 
 export class TopologyInformation {
     topology: string;
+    pinned: boolean;
     apiServices: Service[];
     uiServices: Service[];
 }

Reply via email to