Add apache license to helix-ui; 4 -> 2 spaces indent
Project: http://git-wip-us.apache.org/repos/asf/helix/repo Commit: http://git-wip-us.apache.org/repos/asf/helix/commit/46407b31 Tree: http://git-wip-us.apache.org/repos/asf/helix/tree/46407b31 Diff: http://git-wip-us.apache.org/repos/asf/helix/diff/46407b31 Branch: refs/heads/master Commit: 46407b31dd1a1a99af35365b0ca8c7c3552005a5 Parents: d301c6c Author: Greg Brandt <[email protected]> Authored: Sat Mar 28 12:46:47 2015 -0700 Committer: Greg Brandt <[email protected]> Committed: Sat Mar 28 12:46:47 2015 -0700 ---------------------------------------------------------------------- .../org/apache/helix/ui/HelixUIApplication.java | 103 +++--- .../ui/HelixUIApplicationConfiguration.java | 47 ++- .../apache/helix/ui/api/ClusterConnection.java | 43 ++- .../org/apache/helix/ui/api/ClusterSpec.java | 65 ++-- .../org/apache/helix/ui/api/ConfigTableRow.java | 93 +++-- .../helix/ui/api/D3ResourceCoCentricCircle.java | 228 ++++++------ .../org/apache/helix/ui/api/IdealStateSpec.java | 169 +++++---- .../org/apache/helix/ui/api/InstanceSpec.java | 65 ++-- .../org/apache/helix/ui/api/ResourceSpec.java | 61 +-- .../apache/helix/ui/api/ResourceStateSpec.java | 111 +++--- .../helix/ui/api/ResourceStateTableRow.java | 123 ++++--- .../ui/health/ClusterConnectionHealthCheck.java | 41 ++- .../apache/helix/ui/resource/AdminResource.java | 275 +++++++------- .../helix/ui/resource/DashboardResource.java | 287 ++++++++------- .../helix/ui/resource/VisualizerResource.java | 86 +++-- .../apache/helix/ui/task/ClearClientCache.java | 45 ++- .../helix/ui/task/ClearDataCacheTask.java | 45 ++- .../org/apache/helix/ui/util/ClientCache.java | 154 ++++---- .../org/apache/helix/ui/util/DataCache.java | 368 ++++++++++--------- .../ui/util/DropWizardApplicationRunner.java | 134 ++++--- .../helix/ui/util/ZkAddressValidator.java | 67 ++-- .../org/apache/helix/ui/view/ClusterView.java | 143 +++---- .../org/apache/helix/ui/view/LandingView.java | 25 +- .../org/apache/helix/ui/view/ResourceView.java | 169 +++++---- 24 files changed, 1701 insertions(+), 1246 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/helix/blob/46407b31/helix-ui/src/main/java/org/apache/helix/ui/HelixUIApplication.java ---------------------------------------------------------------------- diff --git a/helix-ui/src/main/java/org/apache/helix/ui/HelixUIApplication.java b/helix-ui/src/main/java/org/apache/helix/ui/HelixUIApplication.java index aad605b..c6e366e 100644 --- a/helix-ui/src/main/java/org/apache/helix/ui/HelixUIApplication.java +++ b/helix-ui/src/main/java/org/apache/helix/ui/HelixUIApplication.java @@ -1,5 +1,24 @@ package org.apache.helix.ui; +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + import com.google.common.collect.ImmutableMap; import io.dropwizard.Application; import io.dropwizard.assets.AssetsBundle; @@ -19,56 +38,56 @@ import org.eclipse.jetty.util.component.AbstractLifeCycle; import org.eclipse.jetty.util.component.LifeCycle; public class HelixUIApplication extends Application<HelixUIApplicationConfiguration> { - @Override - public String getName() { - return "helix-ui"; - } + @Override + public String getName() { + return "helix-ui"; + } - @Override - public void initialize(Bootstrap<HelixUIApplicationConfiguration> bootstrap) { - bootstrap.addBundle(new ViewBundle<HelixUIApplicationConfiguration>() { - @Override - public ImmutableMap<String, ImmutableMap<String, String>> getViewConfiguration(HelixUIApplicationConfiguration config) { - return config.getViewRendererConfiguration(); - } - }); - bootstrap.addBundle(new AssetsBundle("/assets/css", "/assets/css", null, "css")); - bootstrap.addBundle(new AssetsBundle("/assets/js", "/assets/js", null, "js")); - bootstrap.addBundle(new AssetsBundle("/assets/img", "/assets/img", null, "img")); - bootstrap.addBundle(new AssetsBundle("/assets/fonts", "/assets/fonts", null, "fonts")); - } + @Override + public void initialize(Bootstrap<HelixUIApplicationConfiguration> bootstrap) { + bootstrap.addBundle(new ViewBundle<HelixUIApplicationConfiguration>() { + @Override + public ImmutableMap<String, ImmutableMap<String, String>> getViewConfiguration(HelixUIApplicationConfiguration config) { + return config.getViewRendererConfiguration(); + } + }); + bootstrap.addBundle(new AssetsBundle("/assets/css", "/assets/css", null, "css")); + bootstrap.addBundle(new AssetsBundle("/assets/js", "/assets/js", null, "js")); + bootstrap.addBundle(new AssetsBundle("/assets/img", "/assets/img", null, "img")); + bootstrap.addBundle(new AssetsBundle("/assets/fonts", "/assets/fonts", null, "fonts")); + } - @Override - public void run(HelixUIApplicationConfiguration config, Environment environment) throws Exception { - final ZkAddressValidator zkAddressValidator = new ZkAddressValidator(config.getZkAddresses()); - final ClientCache clientCache = new ClientCache(zkAddressValidator); + @Override + public void run(HelixUIApplicationConfiguration config, Environment environment) throws Exception { + final ZkAddressValidator zkAddressValidator = new ZkAddressValidator(config.getZkAddresses()); + final ClientCache clientCache = new ClientCache(zkAddressValidator); - // Close all connections when application stops - environment.lifecycle().addLifeCycleListener(new AbstractLifeCycle.AbstractLifeCycleListener() { - @Override - public void lifeCycleStopping(LifeCycle event) { - clientCache.invalidateAll(); - } - }); + // Close all connections when application stops + environment.lifecycle().addLifeCycleListener(new AbstractLifeCycle.AbstractLifeCycleListener() { + @Override + public void lifeCycleStopping(LifeCycle event) { + clientCache.invalidateAll(); + } + }); - DataCache dataCache = new DataCache(clientCache); + DataCache dataCache = new DataCache(clientCache); - DashboardResource dashboardResource - = new DashboardResource(clientCache, dataCache, config.isAdminMode()); + DashboardResource dashboardResource + = new DashboardResource(clientCache, dataCache, config.isAdminMode()); - environment.healthChecks().register("clusterConnection", new ClusterConnectionHealthCheck(clientCache)); - environment.jersey().register(dashboardResource); - environment.jersey().register(new VisualizerResource(clientCache, dataCache)); - environment.admin().addTask(new ClearDataCacheTask(dataCache)); - environment.admin().addTask(new ClearClientCache(clientCache)); + environment.healthChecks().register("clusterConnection", new ClusterConnectionHealthCheck(clientCache)); + environment.jersey().register(dashboardResource); + environment.jersey().register(new VisualizerResource(clientCache, dataCache)); + environment.admin().addTask(new ClearDataCacheTask(dataCache)); + environment.admin().addTask(new ClearClientCache(clientCache)); - if (config.isAdminMode()) { - environment.jersey().register(new AdminResource(clientCache, dataCache)); - } + if (config.isAdminMode()) { + environment.jersey().register(new AdminResource(clientCache, dataCache)); } + } - public static void main(String[] args) throws Exception { - new HelixUIApplication().run(args); - } + public static void main(String[] args) throws Exception { + new HelixUIApplication().run(args); + } } http://git-wip-us.apache.org/repos/asf/helix/blob/46407b31/helix-ui/src/main/java/org/apache/helix/ui/HelixUIApplicationConfiguration.java ---------------------------------------------------------------------- diff --git a/helix-ui/src/main/java/org/apache/helix/ui/HelixUIApplicationConfiguration.java b/helix-ui/src/main/java/org/apache/helix/ui/HelixUIApplicationConfiguration.java index e2f433e..4daa298 100644 --- a/helix-ui/src/main/java/org/apache/helix/ui/HelixUIApplicationConfiguration.java +++ b/helix-ui/src/main/java/org/apache/helix/ui/HelixUIApplicationConfiguration.java @@ -1,5 +1,24 @@ package org.apache.helix.ui; +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + import com.fasterxml.jackson.annotation.JsonProperty; import com.google.common.collect.ImmutableMap; import io.dropwizard.Configuration; @@ -8,23 +27,23 @@ import javax.validation.constraints.NotNull; import java.util.Set; public class HelixUIApplicationConfiguration extends Configuration { - @NotNull - private ImmutableMap<String, ImmutableMap<String, String>> viewRendererConfiguration = ImmutableMap.of(); + @NotNull + private ImmutableMap<String, ImmutableMap<String, String>> viewRendererConfiguration = ImmutableMap.of(); - private boolean adminMode = false; + private boolean adminMode = false; - private Set<String> zkAddresses; + private Set<String> zkAddresses; - @JsonProperty("viewRendererConfiguration") - public ImmutableMap<String, ImmutableMap<String, String>> getViewRendererConfiguration() { - return viewRendererConfiguration; - } + @JsonProperty("viewRendererConfiguration") + public ImmutableMap<String, ImmutableMap<String, String>> getViewRendererConfiguration() { + return viewRendererConfiguration; + } - public boolean isAdminMode() { - return adminMode; - } + public boolean isAdminMode() { + return adminMode; + } - public Set<String> getZkAddresses() { - return zkAddresses; - } + public Set<String> getZkAddresses() { + return zkAddresses; + } } http://git-wip-us.apache.org/repos/asf/helix/blob/46407b31/helix-ui/src/main/java/org/apache/helix/ui/api/ClusterConnection.java ---------------------------------------------------------------------- diff --git a/helix-ui/src/main/java/org/apache/helix/ui/api/ClusterConnection.java b/helix-ui/src/main/java/org/apache/helix/ui/api/ClusterConnection.java index 94af4cf..9ad89c6 100644 --- a/helix-ui/src/main/java/org/apache/helix/ui/api/ClusterConnection.java +++ b/helix-ui/src/main/java/org/apache/helix/ui/api/ClusterConnection.java @@ -1,22 +1,41 @@ package org.apache.helix.ui.api; +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + import org.apache.helix.manager.zk.ZkClient; import org.apache.helix.tools.ClusterSetup; public class ClusterConnection { - private final ZkClient zkClient; - private final ClusterSetup clusterSetup; + private final ZkClient zkClient; + private final ClusterSetup clusterSetup; - public ClusterConnection(ZkClient zkClient) { - this.zkClient = zkClient; - this.clusterSetup = new ClusterSetup(zkClient); - } + public ClusterConnection(ZkClient zkClient) { + this.zkClient = zkClient; + this.clusterSetup = new ClusterSetup(zkClient); + } - public ZkClient getZkClient() { - return zkClient; - } + public ZkClient getZkClient() { + return zkClient; + } - public ClusterSetup getClusterSetup() { - return clusterSetup; - } + public ClusterSetup getClusterSetup() { + return clusterSetup; + } } http://git-wip-us.apache.org/repos/asf/helix/blob/46407b31/helix-ui/src/main/java/org/apache/helix/ui/api/ClusterSpec.java ---------------------------------------------------------------------- diff --git a/helix-ui/src/main/java/org/apache/helix/ui/api/ClusterSpec.java b/helix-ui/src/main/java/org/apache/helix/ui/api/ClusterSpec.java index 1e09615..95ac591 100644 --- a/helix-ui/src/main/java/org/apache/helix/ui/api/ClusterSpec.java +++ b/helix-ui/src/main/java/org/apache/helix/ui/api/ClusterSpec.java @@ -1,33 +1,52 @@ package org.apache.helix.ui.api; +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + public class ClusterSpec { - private final String zkAddress; - private final String clusterName; + private final String zkAddress; + private final String clusterName; - public ClusterSpec(String zkAddress, String clusterName) { - this.zkAddress = zkAddress; - this.clusterName = clusterName; - } + public ClusterSpec(String zkAddress, String clusterName) { + this.zkAddress = zkAddress; + this.clusterName = clusterName; + } - public String getZkAddress() { - return zkAddress; - } + public String getZkAddress() { + return zkAddress; + } - public String getClusterName() { - return clusterName; - } + public String getClusterName() { + return clusterName; + } - @Override - public boolean equals(Object o) { - if (!(o instanceof ClusterSpec)) { - return false; - } - ClusterSpec c = (ClusterSpec) o; - return c.zkAddress.equals(zkAddress) && c.clusterName.equals(clusterName); + @Override + public boolean equals(Object o) { + if (!(o instanceof ClusterSpec)) { + return false; } + ClusterSpec c = (ClusterSpec) o; + return c.zkAddress.equals(zkAddress) && c.clusterName.equals(clusterName); + } - @Override - public int hashCode() { - return zkAddress.hashCode() + 13 * clusterName.hashCode(); - } + @Override + public int hashCode() { + return zkAddress.hashCode() + 13 * clusterName.hashCode(); + } } http://git-wip-us.apache.org/repos/asf/helix/blob/46407b31/helix-ui/src/main/java/org/apache/helix/ui/api/ConfigTableRow.java ---------------------------------------------------------------------- diff --git a/helix-ui/src/main/java/org/apache/helix/ui/api/ConfigTableRow.java b/helix-ui/src/main/java/org/apache/helix/ui/api/ConfigTableRow.java index bd423f5..fac5091 100644 --- a/helix-ui/src/main/java/org/apache/helix/ui/api/ConfigTableRow.java +++ b/helix-ui/src/main/java/org/apache/helix/ui/api/ConfigTableRow.java @@ -1,49 +1,68 @@ package org.apache.helix.ui.api; +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + public class ConfigTableRow implements Comparable<ConfigTableRow> { - private final String scope; - private final String entity; - private final String name; - private final String value; - - public ConfigTableRow(String scope, - String entity, - String name, - String value) throws Exception { - this.scope = scope; - this.entity = entity; - this.name = name; - this.value = value; - } + private final String scope; + private final String entity; + private final String name; + private final String value; - public String getScope() { - return scope; - } + public ConfigTableRow(String scope, + String entity, + String name, + String value) throws Exception { + this.scope = scope; + this.entity = entity; + this.name = name; + this.value = value; + } - public String getEntity() { - return entity; - } + public String getScope() { + return scope; + } - public String getName() { - return name; - } + public String getEntity() { + return entity; + } - public String getValue() { - return value; - } + public String getName() { + return name; + } - @Override - public int compareTo(ConfigTableRow o) { - int nameResult = name.compareTo(o.getName()); - if (nameResult != 0) { - return nameResult; - } + public String getValue() { + return value; + } - int valueResult = value.compareTo(o.getValue()); - if (valueResult != 0) { - return valueResult; - } + @Override + public int compareTo(ConfigTableRow o) { + int nameResult = name.compareTo(o.getName()); + if (nameResult != 0) { + return nameResult; + } - return 0; + int valueResult = value.compareTo(o.getValue()); + if (valueResult != 0) { + return valueResult; } + + return 0; + } } http://git-wip-us.apache.org/repos/asf/helix/blob/46407b31/helix-ui/src/main/java/org/apache/helix/ui/api/D3ResourceCoCentricCircle.java ---------------------------------------------------------------------- diff --git a/helix-ui/src/main/java/org/apache/helix/ui/api/D3ResourceCoCentricCircle.java b/helix-ui/src/main/java/org/apache/helix/ui/api/D3ResourceCoCentricCircle.java index b9548bf..08246bd 100644 --- a/helix-ui/src/main/java/org/apache/helix/ui/api/D3ResourceCoCentricCircle.java +++ b/helix-ui/src/main/java/org/apache/helix/ui/api/D3ResourceCoCentricCircle.java @@ -1,116 +1,138 @@ package org.apache.helix.ui.api; +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + import com.fasterxml.jackson.annotation.JsonInclude; -import java.util.*; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; @JsonInclude(JsonInclude.Include.NON_NULL) public class D3ResourceCoCentricCircle { - public enum CircleType { - CLUSTER, - INSTANCE, - PARTITION - } - - private final String name; - private final String parentName; - private final String state; - private final int size; - private final CircleType circleType; - private final Set<D3ResourceCoCentricCircle> children; - - public D3ResourceCoCentricCircle(String name, - String parentName, - String state, - int size, - CircleType circleType, - Set<D3ResourceCoCentricCircle> children) { - this.name = name; - this.parentName = parentName; - this.state = state; - this.size = size; - this.circleType = circleType; - this.children = children; - } - - public String getName() { - return name; - } - - public String getParentName() { - return parentName; + public enum CircleType { + CLUSTER, + INSTANCE, + PARTITION + } + + private final String name; + private final String parentName; + private final String state; + private final int size; + private final CircleType circleType; + private final Set<D3ResourceCoCentricCircle> children; + + public D3ResourceCoCentricCircle(String name, + String parentName, + String state, + int size, + CircleType circleType, + Set<D3ResourceCoCentricCircle> children) { + this.name = name; + this.parentName = parentName; + this.state = state; + this.size = size; + this.circleType = circleType; + this.children = children; + } + + public String getName() { + return name; + } + + public String getParentName() { + return parentName; + } + + public String getState() { + return state; + } + + public int getSize() { + return size; + } + + public CircleType getCircleType() { + return circleType; + } + + public Set<D3ResourceCoCentricCircle> getChildren() { + return children; + } + + public static D3ResourceCoCentricCircle fromResourceStateSpec(ResourceStateSpec resourceStateSpec) { + Map<String, Set<D3ResourceCoCentricCircle>> partitionByInstance + = new HashMap<String, Set<D3ResourceCoCentricCircle>>(); + + // Group by instance (first level) + for (ResourceStateTableRow row : resourceStateSpec.getResourceStateTable()) { + Set<D3ResourceCoCentricCircle> partitionCircles = partitionByInstance.get(row.getInstanceName()); + if (partitionCircles == null) { + partitionCircles = new HashSet<D3ResourceCoCentricCircle>(); + partitionByInstance.put(row.getInstanceName(), partitionCircles); + } + partitionCircles.add(new D3ResourceCoCentricCircle( + row.getPartitionName(), + row.getInstanceName(), + row.getExternal(), + 10, + CircleType.PARTITION, + null)); } - public String getState() { - return state; + // Group into cluster + Set<D3ResourceCoCentricCircle> instanceCircles = new HashSet<D3ResourceCoCentricCircle>(); + for (Map.Entry<String, Set<D3ResourceCoCentricCircle>> entry : partitionByInstance.entrySet()) { + + InstanceSpec instanceSpec = resourceStateSpec.getInstanceSpecs().get(entry.getKey()); + if (instanceSpec == null) { + throw new IllegalStateException("No instance spec for " + entry.getKey()); + } + + String state; + if (!instanceSpec.isLive()) { + state = "DEAD"; + } else if (!instanceSpec.isEnabled()) { + state = "DISABLED"; + } else { + state = "LIVE"; + } + + instanceCircles.add(new D3ResourceCoCentricCircle( + entry.getKey(), + resourceStateSpec.getResource(), + state, + 100, + CircleType.INSTANCE, + entry.getValue())); } - public int getSize() { - return size; - } - - public CircleType getCircleType() { - return circleType; - } - - public Set<D3ResourceCoCentricCircle> getChildren() { - return children; - } - - public static D3ResourceCoCentricCircle fromResourceStateSpec(ResourceStateSpec resourceStateSpec) { - Map<String, Set<D3ResourceCoCentricCircle>> partitionByInstance - = new HashMap<String, Set<D3ResourceCoCentricCircle>>(); - - // Group by instance (first level) - for (ResourceStateTableRow row : resourceStateSpec.getResourceStateTable()) { - Set<D3ResourceCoCentricCircle> partitionCircles = partitionByInstance.get(row.getInstanceName()); - if (partitionCircles == null) { - partitionCircles = new HashSet<D3ResourceCoCentricCircle>(); - partitionByInstance.put(row.getInstanceName(), partitionCircles); - } - partitionCircles.add(new D3ResourceCoCentricCircle( - row.getPartitionName(), - row.getInstanceName(), - row.getExternal(), - 10, - CircleType.PARTITION, - null)); - } - - // Group into cluster - Set<D3ResourceCoCentricCircle> instanceCircles = new HashSet<D3ResourceCoCentricCircle>(); - for (Map.Entry<String, Set<D3ResourceCoCentricCircle>> entry : partitionByInstance.entrySet()) { - - InstanceSpec instanceSpec = resourceStateSpec.getInstanceSpecs().get(entry.getKey()); - if (instanceSpec == null) { - throw new IllegalStateException("No instance spec for " + entry.getKey()); - } - - String state; - if (!instanceSpec.isLive()) { - state = "DEAD"; - } else if (!instanceSpec.isEnabled()) { - state = "DISABLED"; - } else { - state = "LIVE"; - } - - instanceCircles.add(new D3ResourceCoCentricCircle( - entry.getKey(), - resourceStateSpec.getResource(), - state, - 100, - CircleType.INSTANCE, - entry.getValue())); - } - - return new D3ResourceCoCentricCircle( - resourceStateSpec.getIdealState().getResourceName(), - null, - "", - 900, - CircleType.CLUSTER, - instanceCircles); - } + return new D3ResourceCoCentricCircle( + resourceStateSpec.getIdealState().getResourceName(), + null, + "", + 900, + CircleType.CLUSTER, + instanceCircles); + } } http://git-wip-us.apache.org/repos/asf/helix/blob/46407b31/helix-ui/src/main/java/org/apache/helix/ui/api/IdealStateSpec.java ---------------------------------------------------------------------- diff --git a/helix-ui/src/main/java/org/apache/helix/ui/api/IdealStateSpec.java b/helix-ui/src/main/java/org/apache/helix/ui/api/IdealStateSpec.java index f37b939..6ba2a67 100644 --- a/helix-ui/src/main/java/org/apache/helix/ui/api/IdealStateSpec.java +++ b/helix-ui/src/main/java/org/apache/helix/ui/api/IdealStateSpec.java @@ -1,94 +1,111 @@ package org.apache.helix.ui.api; -import org.apache.helix.model.IdealState; +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ -import java.util.List; +import org.apache.helix.model.IdealState; public class IdealStateSpec { - private final int numPartitions; - private final String replicas; - private final String instanceGroupTag; - private final int maxPartitionsPerInstance; - private final String rebalanceMode; - private final String rebalancerClassName; - private final String stateModel; - private final int bucketSize; - private final int rebalanceTimerPeriod; - private final boolean batchMessageMode; + private final int numPartitions; + private final String replicas; + private final String instanceGroupTag; + private final int maxPartitionsPerInstance; + private final String rebalanceMode; + private final String rebalancerClassName; + private final String stateModel; + private final int bucketSize; + private final int rebalanceTimerPeriod; + private final boolean batchMessageMode; - public IdealStateSpec(int numPartitions, - String replicas, - String instanceGroupTag, - int maxPartitionsPerInstance, - String rebalanceMode, - String rebalancerClassName, - String stateModel, - int bucketSize, - int rebalanceTimerPeriod, - boolean batchMessageMode) { - this.numPartitions = numPartitions; - this.replicas = replicas; - this.instanceGroupTag = instanceGroupTag; - this.maxPartitionsPerInstance = maxPartitionsPerInstance; - this.rebalanceMode = rebalanceMode; - this.rebalancerClassName = rebalancerClassName; - this.stateModel = stateModel; - this.bucketSize = bucketSize; - this.rebalanceTimerPeriod = rebalanceTimerPeriod; - this.batchMessageMode = batchMessageMode; - } + public IdealStateSpec(int numPartitions, + String replicas, + String instanceGroupTag, + int maxPartitionsPerInstance, + String rebalanceMode, + String rebalancerClassName, + String stateModel, + int bucketSize, + int rebalanceTimerPeriod, + boolean batchMessageMode) { + this.numPartitions = numPartitions; + this.replicas = replicas; + this.instanceGroupTag = instanceGroupTag; + this.maxPartitionsPerInstance = maxPartitionsPerInstance; + this.rebalanceMode = rebalanceMode; + this.rebalancerClassName = rebalancerClassName; + this.stateModel = stateModel; + this.bucketSize = bucketSize; + this.rebalanceTimerPeriod = rebalanceTimerPeriod; + this.batchMessageMode = batchMessageMode; + } - public int getNumPartitions() { - return numPartitions; - } + public int getNumPartitions() { + return numPartitions; + } - public String getReplicas() { - return replicas; - } + public String getReplicas() { + return replicas; + } - public String getInstanceGroupTag() { - return instanceGroupTag; - } + public String getInstanceGroupTag() { + return instanceGroupTag; + } - public int getMaxPartitionsPerInstance() { - return maxPartitionsPerInstance; - } + public int getMaxPartitionsPerInstance() { + return maxPartitionsPerInstance; + } - public String getRebalanceMode() { - return rebalanceMode; - } + public String getRebalanceMode() { + return rebalanceMode; + } - public String getRebalancerClassName() { - return rebalancerClassName; - } + public String getRebalancerClassName() { + return rebalancerClassName; + } - public String getStateModel() { - return stateModel; - } + public String getStateModel() { + return stateModel; + } - public int getBucketSize() { - return bucketSize; - } + public int getBucketSize() { + return bucketSize; + } - public int getRebalanceTimerPeriod() { - return rebalanceTimerPeriod; - } + public int getRebalanceTimerPeriod() { + return rebalanceTimerPeriod; + } - public boolean isBatchMessageMode() { - return batchMessageMode; - } + public boolean isBatchMessageMode() { + return batchMessageMode; + } - public static IdealStateSpec fromIdealState(IdealState idealState) { - return new IdealStateSpec( - idealState.getNumPartitions(), - idealState.getReplicas(), - idealState.getInstanceGroupTag(), - idealState.getMaxPartitionsPerInstance(), - idealState.getRebalanceMode().toString(), - idealState.getRebalancerClassName(), - idealState.getStateModelDefRef(), - idealState.getBucketSize(), - idealState.getRebalanceTimerPeriod(), - idealState.getBatchMessageMode()); - } + public static IdealStateSpec fromIdealState(IdealState idealState) { + return new IdealStateSpec( + idealState.getNumPartitions(), + idealState.getReplicas(), + idealState.getInstanceGroupTag(), + idealState.getMaxPartitionsPerInstance(), + idealState.getRebalanceMode().toString(), + idealState.getRebalancerClassName(), + idealState.getStateModelDefRef(), + idealState.getBucketSize(), + idealState.getRebalanceTimerPeriod(), + idealState.getBatchMessageMode()); + } } http://git-wip-us.apache.org/repos/asf/helix/blob/46407b31/helix-ui/src/main/java/org/apache/helix/ui/api/InstanceSpec.java ---------------------------------------------------------------------- diff --git a/helix-ui/src/main/java/org/apache/helix/ui/api/InstanceSpec.java b/helix-ui/src/main/java/org/apache/helix/ui/api/InstanceSpec.java index e87932c..6ce008d 100644 --- a/helix-ui/src/main/java/org/apache/helix/ui/api/InstanceSpec.java +++ b/helix-ui/src/main/java/org/apache/helix/ui/api/InstanceSpec.java @@ -1,32 +1,51 @@ package org.apache.helix.ui.api; +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + public class InstanceSpec implements Comparable<InstanceSpec> { - private final String instanceName; - private final boolean enabled; - private final boolean live; + private final String instanceName; + private final boolean enabled; + private final boolean live; - public InstanceSpec(String instanceName, - boolean enabled, - boolean live) { - this.instanceName = instanceName; - this.enabled = enabled; - this.live = live; - } + public InstanceSpec(String instanceName, + boolean enabled, + boolean live) { + this.instanceName = instanceName; + this.enabled = enabled; + this.live = live; + } - public String getInstanceName() { - return instanceName; - } + public String getInstanceName() { + return instanceName; + } - public boolean isEnabled() { - return enabled; - } + public boolean isEnabled() { + return enabled; + } - public boolean isLive() { - return live; - } + public boolean isLive() { + return live; + } - @Override - public int compareTo(InstanceSpec o) { - return instanceName.compareTo(o.instanceName); - } + @Override + public int compareTo(InstanceSpec o) { + return instanceName.compareTo(o.instanceName); + } } http://git-wip-us.apache.org/repos/asf/helix/blob/46407b31/helix-ui/src/main/java/org/apache/helix/ui/api/ResourceSpec.java ---------------------------------------------------------------------- diff --git a/helix-ui/src/main/java/org/apache/helix/ui/api/ResourceSpec.java b/helix-ui/src/main/java/org/apache/helix/ui/api/ResourceSpec.java index 284fbaa..1309886 100644 --- a/helix-ui/src/main/java/org/apache/helix/ui/api/ResourceSpec.java +++ b/helix-ui/src/main/java/org/apache/helix/ui/api/ResourceSpec.java @@ -1,31 +1,50 @@ package org.apache.helix.ui.api; +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + public class ResourceSpec extends ClusterSpec { - private final String resourceName; + private final String resourceName; - public ResourceSpec(String zkAddress, String clusterName, String resourceName) { - super(zkAddress, clusterName); - this.resourceName = resourceName; - } + public ResourceSpec(String zkAddress, String clusterName, String resourceName) { + super(zkAddress, clusterName); + this.resourceName = resourceName; + } - public String getResourceName() { - return resourceName; - } + public String getResourceName() { + return resourceName; + } - @Override - public boolean equals(Object o) { - if (!(o instanceof ResourceSpec)) { - return false; - } - ResourceSpec c = (ResourceSpec) o; - return getZkAddress().equals(c.getZkAddress()) - && getClusterName().equals(c.getClusterName()) - && resourceName.equals(c.getResourceName()); + @Override + public boolean equals(Object o) { + if (!(o instanceof ResourceSpec)) { + return false; } + ResourceSpec c = (ResourceSpec) o; + return getZkAddress().equals(c.getZkAddress()) + && getClusterName().equals(c.getClusterName()) + && resourceName.equals(c.getResourceName()); + } - @Override - public int hashCode() { - return super.hashCode() + 27 * resourceName.hashCode(); - } + @Override + public int hashCode() { + return super.hashCode() + 27 * resourceName.hashCode(); + } } http://git-wip-us.apache.org/repos/asf/helix/blob/46407b31/helix-ui/src/main/java/org/apache/helix/ui/api/ResourceStateSpec.java ---------------------------------------------------------------------- diff --git a/helix-ui/src/main/java/org/apache/helix/ui/api/ResourceStateSpec.java b/helix-ui/src/main/java/org/apache/helix/ui/api/ResourceStateSpec.java index 08a8f73..64fd48f 100644 --- a/helix-ui/src/main/java/org/apache/helix/ui/api/ResourceStateSpec.java +++ b/helix-ui/src/main/java/org/apache/helix/ui/api/ResourceStateSpec.java @@ -1,5 +1,24 @@ package org.apache.helix.ui.api; +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + import org.apache.helix.model.ExternalView; import org.apache.helix.model.IdealState; @@ -9,60 +28,60 @@ import java.util.Map; import java.util.Set; public class ResourceStateSpec { - private final String resource; - private final IdealState idealState; - private final ExternalView externalView; - private final Map<String, InstanceSpec> instanceSpecs; + private final String resource; + private final IdealState idealState; + private final ExternalView externalView; + private final Map<String, InstanceSpec> instanceSpecs; - public ResourceStateSpec(String resource, - IdealState idealState, - ExternalView externalView, - Map<String, InstanceSpec> instanceSpecs) { - this.resource = resource; - this.idealState = idealState; - this.externalView = externalView; - this.instanceSpecs = instanceSpecs; - } + public ResourceStateSpec(String resource, + IdealState idealState, + ExternalView externalView, + Map<String, InstanceSpec> instanceSpecs) { + this.resource = resource; + this.idealState = idealState; + this.externalView = externalView; + this.instanceSpecs = instanceSpecs; + } - public String getResource() { - return resource; - } - - public IdealState getIdealState() { - return idealState; - } + public String getResource() { + return resource; + } - public ExternalView getExternalView() { - return externalView; - } + public IdealState getIdealState() { + return idealState; + } - public Map<String, InstanceSpec> getInstanceSpecs() { - return instanceSpecs; - } + public ExternalView getExternalView() { + return externalView; + } - public List<ResourceStateTableRow> getResourceStateTable() { - List<ResourceStateTableRow> resourceStateTable = new ArrayList<ResourceStateTableRow>(); - Set<String> partitionNames = idealState.getPartitionSet(); - for (String partitionName : partitionNames) { - Map<String, String> stateMap = idealState.getInstanceStateMap(partitionName); - if (stateMap != null) { - for (Map.Entry<String, String> entry : stateMap.entrySet()) { - String instanceName = entry.getKey(); - String ideal = entry.getValue(); + public Map<String, InstanceSpec> getInstanceSpecs() { + return instanceSpecs; + } - String external = null; - if (externalView != null) { - Map<String, String> externalStateMap = externalView.getStateMap(partitionName); - if (externalStateMap != null) { - external = externalStateMap.get(instanceName); - } - } + public List<ResourceStateTableRow> getResourceStateTable() { + List<ResourceStateTableRow> resourceStateTable = new ArrayList<ResourceStateTableRow>(); + Set<String> partitionNames = idealState.getPartitionSet(); + for (String partitionName : partitionNames) { + Map<String, String> stateMap = idealState.getInstanceStateMap(partitionName); + if (stateMap != null) { + for (Map.Entry<String, String> entry : stateMap.entrySet()) { + String instanceName = entry.getKey(); + String ideal = entry.getValue(); - resourceStateTable.add(new ResourceStateTableRow(resource, partitionName, instanceName, ideal, external)); - } + String external = null; + if (externalView != null) { + Map<String, String> externalStateMap = externalView.getStateMap(partitionName); + if (externalStateMap != null) { + external = externalStateMap.get(instanceName); } - } + } - return resourceStateTable; + resourceStateTable.add(new ResourceStateTableRow(resource, partitionName, instanceName, ideal, external)); + } + } } + + return resourceStateTable; + } } http://git-wip-us.apache.org/repos/asf/helix/blob/46407b31/helix-ui/src/main/java/org/apache/helix/ui/api/ResourceStateTableRow.java ---------------------------------------------------------------------- diff --git a/helix-ui/src/main/java/org/apache/helix/ui/api/ResourceStateTableRow.java b/helix-ui/src/main/java/org/apache/helix/ui/api/ResourceStateTableRow.java index bf0ce08..4ae559b 100644 --- a/helix-ui/src/main/java/org/apache/helix/ui/api/ResourceStateTableRow.java +++ b/helix-ui/src/main/java/org/apache/helix/ui/api/ResourceStateTableRow.java @@ -1,69 +1,88 @@ package org.apache.helix.ui.api; +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + public class ResourceStateTableRow implements Comparable<ResourceStateTableRow> { - private static final String NA = "N/A"; + private static final String NA = "N/A"; - private final String resourceName; - private final String partitionName; - private final String instanceName; - private final String ideal; - private final String external; + private final String resourceName; + private final String partitionName; + private final String instanceName; + private final String ideal; + private final String external; - public ResourceStateTableRow(String resourceName, - String partitionName, - String instanceName, - String ideal, - String external) { - this.resourceName = resourceName; - this.partitionName = partitionName; - this.instanceName = instanceName; - this.ideal = ideal; - this.external = external == null ? NA : external; - } + public ResourceStateTableRow(String resourceName, + String partitionName, + String instanceName, + String ideal, + String external) { + this.resourceName = resourceName; + this.partitionName = partitionName; + this.instanceName = instanceName; + this.ideal = ideal; + this.external = external == null ? NA : external; + } - public String getResourceName() { - return resourceName; - } + public String getResourceName() { + return resourceName; + } - public String getPartitionName() { - return partitionName; - } + public String getPartitionName() { + return partitionName; + } - public String getInstanceName() { - return instanceName; - } + public String getInstanceName() { + return instanceName; + } - public String getIdeal() { - return ideal; - } + public String getIdeal() { + return ideal; + } - public String getExternal() { - return external; - } + public String getExternal() { + return external; + } - @Override - public int compareTo(ResourceStateTableRow r) { - int partitionResult = partitionName.compareTo(r.getPartitionName()); - if (partitionResult != 0) { - return partitionResult; - } + @Override + public int compareTo(ResourceStateTableRow r) { + int partitionResult = partitionName.compareTo(r.getPartitionName()); + if (partitionResult != 0) { + return partitionResult; + } - int instanceResult = instanceName.compareTo(r.getInstanceName()); - if (instanceResult != 0) { - return instanceResult; - } + int instanceResult = instanceName.compareTo(r.getInstanceName()); + if (instanceResult != 0) { + return instanceResult; + } - int idealResult = ideal.compareTo(r.getIdeal()); - if (idealResult != 0) { - return idealResult; - } + int idealResult = ideal.compareTo(r.getIdeal()); + if (idealResult != 0) { + return idealResult; + } - int externalResult = external.compareTo(r.getExternal()); - if (externalResult != 0) { - return externalResult; - } + int externalResult = external.compareTo(r.getExternal()); + if (externalResult != 0) { + return externalResult; + } - return 0; + return 0; - } + } } http://git-wip-us.apache.org/repos/asf/helix/blob/46407b31/helix-ui/src/main/java/org/apache/helix/ui/health/ClusterConnectionHealthCheck.java ---------------------------------------------------------------------- diff --git a/helix-ui/src/main/java/org/apache/helix/ui/health/ClusterConnectionHealthCheck.java b/helix-ui/src/main/java/org/apache/helix/ui/health/ClusterConnectionHealthCheck.java index 4c6df61..0540072 100644 --- a/helix-ui/src/main/java/org/apache/helix/ui/health/ClusterConnectionHealthCheck.java +++ b/helix-ui/src/main/java/org/apache/helix/ui/health/ClusterConnectionHealthCheck.java @@ -1,5 +1,24 @@ package org.apache.helix.ui.health; +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + import com.codahale.metrics.health.HealthCheck; import org.apache.helix.ui.util.ClientCache; @@ -7,18 +26,18 @@ import java.util.Set; public class ClusterConnectionHealthCheck extends HealthCheck { - private final ClientCache clientCache; + private final ClientCache clientCache; - public ClusterConnectionHealthCheck(ClientCache clientCache) { - this.clientCache = clientCache; - } + public ClusterConnectionHealthCheck(ClientCache clientCache) { + this.clientCache = clientCache; + } - @Override - protected Result check() throws Exception { - Set<String> deadConnections = clientCache.getDeadConnections(); - if (!deadConnections.isEmpty()) { - return Result.unhealthy("Dead connections to " + deadConnections); - } - return Result.healthy(); + @Override + protected Result check() throws Exception { + Set<String> deadConnections = clientCache.getDeadConnections(); + if (!deadConnections.isEmpty()) { + return Result.unhealthy("Dead connections to " + deadConnections); } + return Result.healthy(); + } } http://git-wip-us.apache.org/repos/asf/helix/blob/46407b31/helix-ui/src/main/java/org/apache/helix/ui/resource/AdminResource.java ---------------------------------------------------------------------- diff --git a/helix-ui/src/main/java/org/apache/helix/ui/resource/AdminResource.java b/helix-ui/src/main/java/org/apache/helix/ui/resource/AdminResource.java index e6318f2..2bf1bc5 100644 --- a/helix-ui/src/main/java/org/apache/helix/ui/resource/AdminResource.java +++ b/helix-ui/src/main/java/org/apache/helix/ui/resource/AdminResource.java @@ -1,5 +1,24 @@ package org.apache.helix.ui.resource; +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + import org.apache.helix.manager.zk.ZKUtil; import org.apache.helix.model.IdealState; import org.apache.helix.model.InstanceConfig; @@ -14,168 +33,168 @@ import java.util.List; @Path("/admin") public class AdminResource { - private final ClientCache clientCache; - private final DataCache dataCache; + private final ClientCache clientCache; + private final DataCache dataCache; + + public AdminResource(ClientCache clientCache, DataCache dataCache) { + this.clientCache = clientCache; + this.dataCache = dataCache; + } + + @Path("/{zkAddress}/{clusterName}") + @POST + public Response addCluster(@PathParam("zkAddress") String zkAddress, + @PathParam("clusterName") String clusterName) throws Exception { + dataCache.invalidate(); - public AdminResource(ClientCache clientCache, DataCache dataCache) { - this.clientCache = clientCache; - this.dataCache = dataCache; + ClusterSetup clusterSetup = clientCache.get(zkAddress).getClusterSetup(); + + if (clusterSetup.getClusterManagementTool().getClusters().contains(clusterName)) { + return Response.status(Response.Status.CONFLICT).build(); } - @Path("/{zkAddress}/{clusterName}") - @POST - public Response addCluster(@PathParam("zkAddress") String zkAddress, - @PathParam("clusterName") String clusterName) throws Exception { - dataCache.invalidate(); + clusterSetup.addCluster(clusterName, false); - ClusterSetup clusterSetup = clientCache.get(zkAddress).getClusterSetup(); + dataCache.invalidate(); - if (clusterSetup.getClusterManagementTool().getClusters().contains(clusterName)) { - return Response.status(Response.Status.CONFLICT).build(); - } + return Response.ok().build(); + } - clusterSetup.addCluster(clusterName, false); + @Path("/{zkAddress}/{clusterName}") + @DELETE + public Response dropCluster(@PathParam("zkAddress") String zkAddress, + @PathParam("clusterName") String clusterName) throws Exception { + dataCache.invalidate(); - dataCache.invalidate(); + ClusterSetup clusterSetup = clientCache.get(zkAddress).getClusterSetup(); - return Response.ok().build(); + if (!clusterSetup.getClusterManagementTool().getClusters().contains(clusterName)) { + throw new NotFoundException(); } - @Path("/{zkAddress}/{clusterName}") - @DELETE - public Response dropCluster(@PathParam("zkAddress") String zkAddress, - @PathParam("clusterName") String clusterName) throws Exception { - dataCache.invalidate(); + clusterSetup.getClusterManagementTool().dropCluster(clusterName); - ClusterSetup clusterSetup = clientCache.get(zkAddress).getClusterSetup(); + return Response.noContent().build(); + } - if (!clusterSetup.getClusterManagementTool().getClusters().contains(clusterName)) { - throw new NotFoundException(); - } + @Path("/{zkAddress}/{clusterName}/instances/{instanceName}") + @POST + public Response addInstance(@PathParam("zkAddress") String zkAddress, + @PathParam("clusterName") String clusterName, + @PathParam("instanceName") String instanceName, + @QueryParam("disable") boolean disable, + @QueryParam("failIfNoInstance") boolean failIfNoInstance) throws Exception { + dataCache.invalidate(); - clusterSetup.getClusterManagementTool().dropCluster(clusterName); + ClusterSetup clusterSetup = clientCache.get(zkAddress).getClusterSetup(); - return Response.noContent().build(); - } + List<String> instances = clusterSetup.getClusterManagementTool().getInstancesInCluster(clusterName); - @Path("/{zkAddress}/{clusterName}/instances/{instanceName}") - @POST - public Response addInstance(@PathParam("zkAddress") String zkAddress, - @PathParam("clusterName") String clusterName, - @PathParam("instanceName") String instanceName, - @QueryParam("disable") boolean disable, - @QueryParam("failIfNoInstance") boolean failIfNoInstance) throws Exception { - dataCache.invalidate(); + Response response; - ClusterSetup clusterSetup = clientCache.get(zkAddress).getClusterSetup(); + if (instances.contains(instanceName)) { + response = Response.notModified().build(); + } else if (failIfNoInstance) { + return Response.status(Response.Status.BAD_REQUEST).build(); + } else { + clusterSetup.addInstanceToCluster(clusterName, instanceName); + response = Response.ok().build(); + } - List<String> instances = clusterSetup.getClusterManagementTool().getInstancesInCluster(clusterName); + clusterSetup.getClusterManagementTool().enableInstance(clusterName, instanceName, !disable); - Response response; + return response; + } - if (instances.contains(instanceName)) { - response = Response.notModified().build(); - } else if (failIfNoInstance) { - return Response.status(Response.Status.BAD_REQUEST).build(); - } else { - clusterSetup.addInstanceToCluster(clusterName, instanceName); - response = Response.ok().build(); - } + @Path("/{zkAddress}/{clusterName}/instances/{instanceName}") + @DELETE + public Response dropInstance(@PathParam("zkAddress") String zkAddress, + @PathParam("clusterName") String clusterName, + @PathParam("instanceName") String instanceName) throws Exception { + dataCache.invalidate(); - clusterSetup.getClusterManagementTool().enableInstance(clusterName, instanceName, !disable); + ClusterSetup clusterSetup = clientCache.get(zkAddress).getClusterSetup(); - return response; - } + InstanceConfig instanceConfig + = clusterSetup.getClusterManagementTool().getInstanceConfig(clusterName, instanceName); - @Path("/{zkAddress}/{clusterName}/instances/{instanceName}") - @DELETE - public Response dropInstance(@PathParam("zkAddress") String zkAddress, - @PathParam("clusterName") String clusterName, - @PathParam("instanceName") String instanceName) throws Exception { - dataCache.invalidate(); + if (instanceConfig == null) { + throw new NotFoundException(); + } else if (instanceConfig.getInstanceEnabled()) { + return Response.status(Response.Status.BAD_REQUEST) + .header("X-Error-Message", "Cannot drop instance that is enabled") + .build(); + } - ClusterSetup clusterSetup = clientCache.get(zkAddress).getClusterSetup(); + clusterSetup.dropInstanceFromCluster(clusterName, instanceName); - InstanceConfig instanceConfig - = clusterSetup.getClusterManagementTool().getInstanceConfig(clusterName, instanceName); + return Response.noContent().build(); + } - if (instanceConfig == null) { - throw new NotFoundException(); - } else if (instanceConfig.getInstanceEnabled()) { - return Response.status(Response.Status.BAD_REQUEST) - .header("X-Error-Message", "Cannot drop instance that is enabled") - .build(); - } + @Path("/{zkAddress}/{clusterName}/resources/{resourceName}/{partitions}/{replicas}") + @POST + public Response addResource(@PathParam("zkAddress") String zkAddress, + @PathParam("clusterName") String clusterName, + @PathParam("resourceName") String resourceName, + @PathParam("partitions") int partitions, + @PathParam("replicas") String replicas, + @QueryParam("rebalance") boolean rebalance, + @QueryParam("stateModel") String stateModel, + @QueryParam("rebalanceMode") String rebalanceMode) throws Exception { + dataCache.invalidate(); - clusterSetup.dropInstanceFromCluster(clusterName, instanceName); + ClusterConnection conn = clientCache.get(zkAddress); + ClusterSetup clusterSetup = conn.getClusterSetup(); - return Response.noContent().build(); + if (!ZKUtil.isClusterSetup(clusterName, conn.getZkClient())) { + return Response.status(Response.Status.BAD_REQUEST).build(); } - @Path("/{zkAddress}/{clusterName}/resources/{resourceName}/{partitions}/{replicas}") - @POST - public Response addResource(@PathParam("zkAddress") String zkAddress, - @PathParam("clusterName") String clusterName, - @PathParam("resourceName") String resourceName, - @PathParam("partitions") int partitions, - @PathParam("replicas") String replicas, - @QueryParam("rebalance") boolean rebalance, - @QueryParam("stateModel") String stateModel, - @QueryParam("rebalanceMode") String rebalanceMode) throws Exception { - dataCache.invalidate(); - - ClusterConnection conn = clientCache.get(zkAddress); - ClusterSetup clusterSetup = conn.getClusterSetup(); - - if (!ZKUtil.isClusterSetup(clusterName, conn.getZkClient())) { - return Response.status(Response.Status.BAD_REQUEST).build(); - } - - IdealState existingIdealState - = clusterSetup.getClusterManagementTool().getResourceIdealState(clusterName, resourceName); - - IdealState idealState = new IdealState(resourceName); - idealState.setNumPartitions(partitions); - idealState.setReplicas(replicas); - idealState.setStateModelDefRef(stateModel == null - ? "OnlineOffline" : stateModel); - idealState.setRebalanceMode(rebalanceMode == null - ? IdealState.RebalanceMode.FULL_AUTO : IdealState.RebalanceMode.valueOf(rebalanceMode)); - - Response response; - - if (existingIdealState == null) { - clusterSetup.getClusterManagementTool().addResource(clusterName, resourceName, idealState); - response = Response.ok().build(); - } else if (!existingIdealState.equals(idealState)) { - return Response.status(Response.Status.CONFLICT).build(); - } else { - response = Response.notModified().build(); - } - - if (rebalance) { // TODO this will break if replicas is not integer (e.g. N) - clusterSetup.rebalanceResource(clusterName, resourceName, Integer.valueOf(replicas)); - } - - return response; + IdealState existingIdealState + = clusterSetup.getClusterManagementTool().getResourceIdealState(clusterName, resourceName); + + IdealState idealState = new IdealState(resourceName); + idealState.setNumPartitions(partitions); + idealState.setReplicas(replicas); + idealState.setStateModelDefRef(stateModel == null + ? "OnlineOffline" : stateModel); + idealState.setRebalanceMode(rebalanceMode == null + ? IdealState.RebalanceMode.FULL_AUTO : IdealState.RebalanceMode.valueOf(rebalanceMode)); + + Response response; + + if (existingIdealState == null) { + clusterSetup.getClusterManagementTool().addResource(clusterName, resourceName, idealState); + response = Response.ok().build(); + } else if (!existingIdealState.equals(idealState)) { + return Response.status(Response.Status.CONFLICT).build(); + } else { + response = Response.notModified().build(); } - @Path("/{zkAddress}/{clusterName}/resources/{resourceName}") - @DELETE - public Response dropResource(@PathParam("zkAddress") String zkAddress, - @PathParam("clusterName") String clusterName, - @PathParam("resourceName") String resourceName) throws Exception { - dataCache.invalidate(); + if (rebalance) { // TODO this will break if replicas is not integer (e.g. N) + clusterSetup.rebalanceResource(clusterName, resourceName, Integer.valueOf(replicas)); + } - ClusterSetup clusterSetup = clientCache.get(zkAddress).getClusterSetup(); + return response; + } - List<String> resources = clusterSetup.getClusterManagementTool().getResourcesInCluster(clusterName); - if (!resources.contains(resourceName)) { - throw new NotFoundException(); - } + @Path("/{zkAddress}/{clusterName}/resources/{resourceName}") + @DELETE + public Response dropResource(@PathParam("zkAddress") String zkAddress, + @PathParam("clusterName") String clusterName, + @PathParam("resourceName") String resourceName) throws Exception { + dataCache.invalidate(); - clusterSetup.dropResourceFromCluster(clusterName, resourceName); + ClusterSetup clusterSetup = clientCache.get(zkAddress).getClusterSetup(); - return Response.noContent().build(); + List<String> resources = clusterSetup.getClusterManagementTool().getResourcesInCluster(clusterName); + if (!resources.contains(resourceName)) { + throw new NotFoundException(); } + + clusterSetup.dropResourceFromCluster(clusterName, resourceName); + + return Response.noContent().build(); + } } http://git-wip-us.apache.org/repos/asf/helix/blob/46407b31/helix-ui/src/main/java/org/apache/helix/ui/resource/DashboardResource.java ---------------------------------------------------------------------- diff --git a/helix-ui/src/main/java/org/apache/helix/ui/resource/DashboardResource.java b/helix-ui/src/main/java/org/apache/helix/ui/resource/DashboardResource.java index cb154e5..450c02e 100644 --- a/helix-ui/src/main/java/org/apache/helix/ui/resource/DashboardResource.java +++ b/helix-ui/src/main/java/org/apache/helix/ui/resource/DashboardResource.java @@ -1,5 +1,24 @@ package org.apache.helix.ui.resource; +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + import com.google.common.collect.ImmutableList; import org.apache.helix.manager.zk.ZKUtil; import org.apache.helix.model.ExternalView; @@ -18,147 +37,147 @@ import java.util.*; @Path("/dashboard") @Produces(MediaType.TEXT_HTML) public class DashboardResource { - private static final List<String> REBALANCE_MODES = ImmutableList.of( - IdealState.RebalanceMode.SEMI_AUTO.toString(), - IdealState.RebalanceMode.FULL_AUTO.toString(), - IdealState.RebalanceMode.CUSTOMIZED.toString(), - IdealState.RebalanceMode.USER_DEFINED.toString(), - IdealState.RebalanceMode.TASK.toString()); - - private final boolean adminMode; - private final ClientCache clientCache; - private final DataCache dataCache; - - public DashboardResource(ClientCache clientCache, - DataCache dataCache, - boolean adminMode) { - this.clientCache = clientCache; - this.dataCache = dataCache; - this.adminMode = adminMode; + private static final List<String> REBALANCE_MODES = ImmutableList.of( + IdealState.RebalanceMode.SEMI_AUTO.toString(), + IdealState.RebalanceMode.FULL_AUTO.toString(), + IdealState.RebalanceMode.CUSTOMIZED.toString(), + IdealState.RebalanceMode.USER_DEFINED.toString(), + IdealState.RebalanceMode.TASK.toString()); + + private final boolean adminMode; + private final ClientCache clientCache; + private final DataCache dataCache; + + public DashboardResource(ClientCache clientCache, + DataCache dataCache, + boolean adminMode) { + this.clientCache = clientCache; + this.dataCache = dataCache; + this.adminMode = adminMode; + } + + @GET + public LandingView getLandingView() { + return new LandingView(); + } + + @GET + @Path("/{zkAddress}") + public ClusterView getClusterView(@PathParam("zkAddress") String zkAddress) throws Exception { + clientCache.get(zkAddress); // n.b. will validate + return getClusterView(zkAddress, null); + } + + @GET + @Path("/{zkAddress}/{cluster}") + public ClusterView getClusterView( + @PathParam("zkAddress") String zkAddress, + @PathParam("cluster") String cluster) throws Exception { + ClusterConnection clusterConnection = clientCache.get(zkAddress); + + // All clusters + List<String> clusters = dataCache.getClusterCache().get(zkAddress); + + // The active cluster + String activeCluster = cluster == null ? clusters.get(0) : cluster; + ClusterSpec clusterSpec = new ClusterSpec(zkAddress, activeCluster); + + // Check it + if (!ZKUtil.isClusterSetup(activeCluster, clusterConnection.getZkClient())) { + return new ClusterView(adminMode, zkAddress, clusters, false, activeCluster, null, null, null, null, null); } - @GET - public LandingView getLandingView() { - return new LandingView(); + // Resources in the active cluster + List<String> activeClusterResources = dataCache.getResourceCache().get(clusterSpec); + + // Instances in active cluster + List<InstanceSpec> instanceSpecs = dataCache.getInstanceCache().get(clusterSpec); + + // State models in active cluster + List<String> stateModels + = clusterConnection.getClusterSetup().getClusterManagementTool().getStateModelDefs(activeCluster); + + // Config table + List<ConfigTableRow> configTable = dataCache.getConfigCache().get(clusterSpec); + + return new ClusterView( + adminMode, + zkAddress, + clusters, + true, + activeCluster, + activeClusterResources, + instanceSpecs, + configTable, + stateModels, + REBALANCE_MODES); + } + + @GET + @Path("/{zkAddress}/{cluster}/{resource}") + public ResourceView getResourceView( + @PathParam("zkAddress") String zkAddress, + @PathParam("cluster") String cluster, + @PathParam("resource") String resource) throws Exception { + ClusterConnection clusterConnection = clientCache.get(zkAddress); + + // All clusters + List<String> clusters = dataCache.getClusterCache().get(zkAddress); + + // The active cluster + String activeCluster = cluster == null ? clusters.get(0) : cluster; + ClusterSpec clusterSpec = new ClusterSpec(zkAddress, activeCluster); + + // Check it + if (!ZKUtil.isClusterSetup(activeCluster, clusterConnection.getZkClient())) { + return new ResourceView( + adminMode, zkAddress, clusters, false, activeCluster, null, null, null, null, null, null, null); } - @GET - @Path("/{zkAddress}") - public ClusterView getClusterView(@PathParam("zkAddress") String zkAddress) throws Exception { - clientCache.get(zkAddress); // n.b. will validate - return getClusterView(zkAddress, null); + // Resources in the active cluster + List<String> activeClusterResources = dataCache.getResourceCache().get(clusterSpec); + if (!activeClusterResources.contains(resource)) { + throw new NotFoundException("No resource " + resource + " in " + activeCluster); } - @GET - @Path("/{zkAddress}/{cluster}") - public ClusterView getClusterView( - @PathParam("zkAddress") String zkAddress, - @PathParam("cluster") String cluster) throws Exception { - ClusterConnection clusterConnection = clientCache.get(zkAddress); - - // All clusters - List<String> clusters = dataCache.getClusterCache().get(zkAddress); - - // The active cluster - String activeCluster = cluster == null ? clusters.get(0) : cluster; - ClusterSpec clusterSpec = new ClusterSpec(zkAddress, activeCluster); - - // Check it - if (!ZKUtil.isClusterSetup(activeCluster, clusterConnection.getZkClient())) { - return new ClusterView(adminMode, zkAddress, clusters, false, activeCluster, null, null, null, null, null); - } - - // Resources in the active cluster - List<String> activeClusterResources = dataCache.getResourceCache().get(clusterSpec); - - // Instances in active cluster - List<InstanceSpec> instanceSpecs = dataCache.getInstanceCache().get(clusterSpec); - - // State models in active cluster - List<String> stateModels - = clusterConnection.getClusterSetup().getClusterManagementTool().getStateModelDefs(activeCluster); - - // Config table - List<ConfigTableRow> configTable = dataCache.getConfigCache().get(clusterSpec); - - return new ClusterView( - adminMode, - zkAddress, - clusters, - true, - activeCluster, - activeClusterResources, - instanceSpecs, - configTable, - stateModels, - REBALANCE_MODES); + // Instances in active cluster + List<InstanceSpec> instanceSpecs = dataCache.getInstanceCache().get(clusterSpec); + Map<String, InstanceSpec> instanceSpecMap = new HashMap<String, InstanceSpec>(instanceSpecs.size()); + for (InstanceSpec instanceSpec : instanceSpecs) { + instanceSpecMap.put(instanceSpec.getInstanceName(), instanceSpec); } - @GET - @Path("/{zkAddress}/{cluster}/{resource}") - public ResourceView getResourceView( - @PathParam("zkAddress") String zkAddress, - @PathParam("cluster") String cluster, - @PathParam("resource") String resource) throws Exception { - ClusterConnection clusterConnection = clientCache.get(zkAddress); - - // All clusters - List<String> clusters = dataCache.getClusterCache().get(zkAddress); - - // The active cluster - String activeCluster = cluster == null ? clusters.get(0) : cluster; - ClusterSpec clusterSpec = new ClusterSpec(zkAddress, activeCluster); - - // Check it - if (!ZKUtil.isClusterSetup(activeCluster, clusterConnection.getZkClient())) { - return new ResourceView( - adminMode, zkAddress, clusters, false, activeCluster, null, null, null, null, null, null, null); - } - - // Resources in the active cluster - List<String> activeClusterResources = dataCache.getResourceCache().get(clusterSpec); - if (!activeClusterResources.contains(resource)) { - throw new NotFoundException("No resource " + resource + " in " + activeCluster); - } - - // Instances in active cluster - List<InstanceSpec> instanceSpecs = dataCache.getInstanceCache().get(clusterSpec); - Map<String, InstanceSpec> instanceSpecMap = new HashMap<String, InstanceSpec>(instanceSpecs.size()); - for (InstanceSpec instanceSpec : instanceSpecs) { - instanceSpecMap.put(instanceSpec.getInstanceName(), instanceSpec); - } - - // Resource state - IdealState idealState - = clusterConnection.getClusterSetup().getClusterManagementTool().getResourceIdealState(cluster, resource); - ExternalView externalView - = clusterConnection.getClusterSetup().getClusterManagementTool().getResourceExternalView(cluster, resource); - ResourceStateSpec resourceStateSpec - = new ResourceStateSpec(resource, idealState, externalView, instanceSpecMap); - List<ResourceStateTableRow> resourceStateTable - = resourceStateSpec.getResourceStateTable(); - - // Resource config - List<ConfigTableRow> configTable = dataCache.getResourceConfigCache().get(new ResourceSpec(zkAddress, activeCluster, resource)); - - // Resource instances - Set<String> resourceInstances = new HashSet<String>(); - for (ResourceStateTableRow row : resourceStateTable) { - resourceInstances.add(row.getInstanceName()); - } - - return new ResourceView( - adminMode, - zkAddress, - clusters, - true, - activeCluster, - activeClusterResources, - resource, - resourceStateTable, - resourceInstances, - configTable, - IdealStateSpec.fromIdealState(idealState), - instanceSpecs); + // Resource state + IdealState idealState + = clusterConnection.getClusterSetup().getClusterManagementTool().getResourceIdealState(cluster, resource); + ExternalView externalView + = clusterConnection.getClusterSetup().getClusterManagementTool().getResourceExternalView(cluster, resource); + ResourceStateSpec resourceStateSpec + = new ResourceStateSpec(resource, idealState, externalView, instanceSpecMap); + List<ResourceStateTableRow> resourceStateTable + = resourceStateSpec.getResourceStateTable(); + + // Resource config + List<ConfigTableRow> configTable = dataCache.getResourceConfigCache().get(new ResourceSpec(zkAddress, activeCluster, resource)); + + // Resource instances + Set<String> resourceInstances = new HashSet<String>(); + for (ResourceStateTableRow row : resourceStateTable) { + resourceInstances.add(row.getInstanceName()); } + + return new ResourceView( + adminMode, + zkAddress, + clusters, + true, + activeCluster, + activeClusterResources, + resource, + resourceStateTable, + resourceInstances, + configTable, + IdealStateSpec.fromIdealState(idealState), + instanceSpecs); + } } http://git-wip-us.apache.org/repos/asf/helix/blob/46407b31/helix-ui/src/main/java/org/apache/helix/ui/resource/VisualizerResource.java ---------------------------------------------------------------------- diff --git a/helix-ui/src/main/java/org/apache/helix/ui/resource/VisualizerResource.java b/helix-ui/src/main/java/org/apache/helix/ui/resource/VisualizerResource.java index 289d84e..f96d541 100644 --- a/helix-ui/src/main/java/org/apache/helix/ui/resource/VisualizerResource.java +++ b/helix-ui/src/main/java/org/apache/helix/ui/resource/VisualizerResource.java @@ -1,9 +1,31 @@ package org.apache.helix.ui.resource; +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + import org.apache.helix.model.ExternalView; import org.apache.helix.model.IdealState; import org.apache.helix.tools.ClusterSetup; -import org.apache.helix.ui.api.*; +import org.apache.helix.ui.api.ClusterSpec; +import org.apache.helix.ui.api.D3ResourceCoCentricCircle; +import org.apache.helix.ui.api.InstanceSpec; +import org.apache.helix.ui.api.ResourceStateSpec; import org.apache.helix.ui.util.ClientCache; import org.apache.helix.ui.util.DataCache; @@ -15,39 +37,39 @@ import java.util.Map; @Path("/visualizer") public class VisualizerResource { - private final ClientCache clientCache; - private final DataCache dataCache; + private final ClientCache clientCache; + private final DataCache dataCache; + + public VisualizerResource(ClientCache clientCache, DataCache dataCache) { + this.clientCache = clientCache; + this.dataCache = dataCache; + } - public VisualizerResource(ClientCache clientCache, DataCache dataCache) { - this.clientCache = clientCache; - this.dataCache = dataCache; + @GET + @Path("/{zkAddress}/{clusterName}/{resourceName}") + @Produces(MediaType.APPLICATION_JSON) + public D3ResourceCoCentricCircle getD3HelixResource( + @PathParam("zkAddress") String zkAddress, + @PathParam("clusterName") String clusterName, + @PathParam("resourceName") String resourceName) throws Exception { + ClusterSetup clusterSetup = clientCache.get(zkAddress).getClusterSetup(); + + IdealState idealState + = clusterSetup.getClusterManagementTool().getResourceIdealState(clusterName, resourceName); + ExternalView externalView + = clusterSetup.getClusterManagementTool().getResourceExternalView(clusterName, resourceName); + if (idealState == null) { + throw new NotFoundException("No resource ideal state for " + resourceName); } - @GET - @Path("/{zkAddress}/{clusterName}/{resourceName}") - @Produces(MediaType.APPLICATION_JSON) - public D3ResourceCoCentricCircle getD3HelixResource( - @PathParam("zkAddress") String zkAddress, - @PathParam("clusterName") String clusterName, - @PathParam("resourceName") String resourceName) throws Exception { - ClusterSetup clusterSetup = clientCache.get(zkAddress).getClusterSetup(); - - IdealState idealState - = clusterSetup.getClusterManagementTool().getResourceIdealState(clusterName, resourceName); - ExternalView externalView - = clusterSetup.getClusterManagementTool().getResourceExternalView(clusterName, resourceName); - if (idealState == null) { - throw new NotFoundException("No resource ideal state for " + resourceName); - } - - // Instances in active cluster - List<InstanceSpec> instanceSpecs = dataCache.getInstanceCache().get(new ClusterSpec(zkAddress, clusterName)); - Map<String, InstanceSpec> instanceSpecMap = new HashMap<String, InstanceSpec>(instanceSpecs.size()); - for (InstanceSpec instanceSpec : instanceSpecs) { - instanceSpecMap.put(instanceSpec.getInstanceName(), instanceSpec); - } - - return D3ResourceCoCentricCircle.fromResourceStateSpec( - new ResourceStateSpec(resourceName, idealState, externalView, instanceSpecMap)); + // Instances in active cluster + List<InstanceSpec> instanceSpecs = dataCache.getInstanceCache().get(new ClusterSpec(zkAddress, clusterName)); + Map<String, InstanceSpec> instanceSpecMap = new HashMap<String, InstanceSpec>(instanceSpecs.size()); + for (InstanceSpec instanceSpec : instanceSpecs) { + instanceSpecMap.put(instanceSpec.getInstanceName(), instanceSpec); } + + return D3ResourceCoCentricCircle.fromResourceStateSpec( + new ResourceStateSpec(resourceName, idealState, externalView, instanceSpecMap)); + } }
