Repository: ambari Updated Branches: refs/heads/branch-2.4 ca6c48369 -> e5051c758
AMBARI-17270. Show better error message when remote cluster attached to view is deleted. (Gaurav Nagar via dipayanb) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/e5051c75 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/e5051c75 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/e5051c75 Branch: refs/heads/branch-2.4 Commit: e5051c758267bcc4dd53d950843725a724406f42 Parents: ca6c483 Author: Dipayan Bhowmick <dipayan.bhowm...@gmail.com> Authored: Fri Jun 17 15:29:38 2016 +0530 Committer: Dipayan Bhowmick <dipayan.bhowm...@gmail.com> Committed: Fri Jun 17 15:29:38 2016 +0530 ---------------------------------------------------------------------- .../controllers/ambariViews/ViewsEditCtrl.js | 4 +++ .../server/view/IllegalClusterException.java | 30 ++++++++++++++++++++ .../view/RemoteAmbariClusterRegistry.java | 12 +++++--- .../apache/ambari/server/view/ViewRegistry.java | 15 ++++++---- .../apache/ambari/view/hive2/HelpService.java | 3 +- .../apache/ambari/view/hive/HelpService.java | 3 +- 6 files changed, 56 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/e5051c75/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/ambariViews/ViewsEditCtrl.js ---------------------------------------------------------------------- diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/ambariViews/ViewsEditCtrl.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/ambariViews/ViewsEditCtrl.js index 207ecca..7bb4039 100644 --- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/ambariViews/ViewsEditCtrl.js +++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/ambariViews/ViewsEditCtrl.js @@ -64,8 +64,10 @@ angular.module('ambariAdminConsole') function initCtrlVariables(instance) { $scope.data.clusterType = instance.ViewInstanceInfo.cluster_type; var clusterId = instance.ViewInstanceInfo.cluster_handle; + if (!clusterId) $scope.data.clusterType = 'NONE'; switch($scope.data.clusterType) { case 'LOCAL_AMBARI': + $scope.cluster = null; $scope.clusters.forEach(function(cluster){ if(cluster.id == clusterId){ $scope.cluster = cluster; @@ -73,6 +75,7 @@ angular.module('ambariAdminConsole') }) break; case 'REMOTE_AMBARI': + $scope.data.remoteCluster = null; $scope.remoteClusters.forEach(function(cluster){ if(cluster.id == clusterId){ $scope.data.remoteCluster = cluster; @@ -80,6 +83,7 @@ angular.module('ambariAdminConsole') }) break; } + $scope.originalClusterType = $scope.data.clusterType; $scope.isConfigurationEmpty = !$scope.numberOfClusterConfigs; $scope.isSettingsEmpty = !$scope.numberOfSettingsConfigs; http://git-wip-us.apache.org/repos/asf/ambari/blob/e5051c75/ambari-server/src/main/java/org/apache/ambari/server/view/IllegalClusterException.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/view/IllegalClusterException.java b/ambari-server/src/main/java/org/apache/ambari/server/view/IllegalClusterException.java new file mode 100644 index 0000000..0d4587b --- /dev/null +++ b/ambari-server/src/main/java/org/apache/ambari/server/view/IllegalClusterException.java @@ -0,0 +1,30 @@ +/** + * 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. + */ + +package org.apache.ambari.server.view; + +public class IllegalClusterException extends RuntimeException { + + public IllegalClusterException(Throwable ex) { + this("Failed to get cluster information associated with this view instance", ex); + } + + public IllegalClusterException(String message, Throwable cause) { + super(message, cause); + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/e5051c75/ambari-server/src/main/java/org/apache/ambari/server/view/RemoteAmbariClusterRegistry.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/view/RemoteAmbariClusterRegistry.java b/ambari-server/src/main/java/org/apache/ambari/server/view/RemoteAmbariClusterRegistry.java index 5e168ee..9f927b0 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/view/RemoteAmbariClusterRegistry.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/view/RemoteAmbariClusterRegistry.java @@ -19,6 +19,7 @@ package org.apache.ambari.server.view; import org.apache.ambari.server.AmbariException; +import org.apache.ambari.server.ClusterNotFoundException; import org.apache.ambari.server.configuration.Configuration; import org.apache.ambari.server.orm.dao.RemoteAmbariClusterDAO; import org.apache.ambari.server.orm.entities.RemoteAmbariClusterEntity; @@ -48,7 +49,7 @@ public class RemoteAmbariClusterRegistry { @Inject private Configuration configuration; - public RemoteAmbariCluster get(Long clusterId) throws MalformedURLException { + public RemoteAmbariCluster get(Long clusterId) throws MalformedURLException, ClusterNotFoundException { RemoteAmbariCluster remoteAmbariCluster = clusterMap.get(clusterId); if (remoteAmbariCluster == null) { RemoteAmbariCluster cluster = getCluster(clusterId); @@ -60,8 +61,11 @@ public class RemoteAmbariClusterRegistry { } - private RemoteAmbariCluster getCluster(Long clusterId) throws MalformedURLException { + private RemoteAmbariCluster getCluster(Long clusterId) throws MalformedURLException, ClusterNotFoundException { RemoteAmbariClusterEntity remoteAmbariClusterEntity = remoteAmbariClusterDAO.findById(clusterId); + if (remoteAmbariClusterEntity == null) { + throw new ClusterNotFoundException(clusterId); + } RemoteAmbariCluster remoteAmbariCluster = new RemoteAmbariCluster(remoteAmbariClusterEntity, configuration); return remoteAmbariCluster; } @@ -73,7 +77,7 @@ public class RemoteAmbariClusterRegistry { */ public void update(RemoteAmbariClusterEntity entity) { remoteAmbariClusterDAO.update(entity); - clusterMap.remove(entity.getName()); + clusterMap.remove(entity.getId()); } /** @@ -83,7 +87,7 @@ public class RemoteAmbariClusterRegistry { */ public void delete(RemoteAmbariClusterEntity entity) { remoteAmbariClusterDAO.delete(entity); - clusterMap.remove(entity.getName()); + clusterMap.remove(entity.getId()); } /** http://git-wip-us.apache.org/repos/asf/ambari/blob/e5051c75/ambari-server/src/main/java/org/apache/ambari/server/view/ViewRegistry.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/view/ViewRegistry.java b/ambari-server/src/main/java/org/apache/ambari/server/view/ViewRegistry.java index 9760c28..ae04b99 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/view/ViewRegistry.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/view/ViewRegistry.java @@ -27,6 +27,7 @@ import com.google.inject.Guice; import com.google.inject.Injector; import com.google.inject.persist.Transactional; import org.apache.ambari.server.AmbariException; +import org.apache.ambari.server.ClusterNotFoundException; import org.apache.ambari.server.api.resources.ResourceInstanceFactoryImpl; import org.apache.ambari.server.api.resources.SubResourceDefinition; import org.apache.ambari.server.api.resources.ViewExternalSubResourceDefinition; @@ -110,11 +111,9 @@ import javax.inject.Singleton; import javax.xml.bind.JAXBException; import java.beans.IntrospectionException; import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; -import java.net.URL; import java.nio.file.Path; import java.util.Collection; import java.util.Collections; @@ -934,13 +933,19 @@ public class ViewRegistry { try { return new ClusterImpl(clustersProvider.get().getCluster(clusterId)); } catch (AmbariException e) { - LOG.warn("Could not find the cluster identified by " + clusterId + "."); + LOG.error("Could not find the cluster identified by {}.", clusterId); + throw new IllegalClusterException(e); } - } else if(clusterId != null && viewInstance.getClusterType() == ClusterType.REMOTE_AMBARI){ + + } else if (clusterId != null && viewInstance.getClusterType() == ClusterType.REMOTE_AMBARI) { try { return remoteAmbariClusterRegistry.get(clusterId); } catch (MalformedURLException e) { - LOG.warn("Cannot get Remote Cluster ." + e.getMessage() ,e); + LOG.error("Remote Cluster with id={} had invalid URL.", clusterId, e); + throw new IllegalClusterException(e); + } catch (ClusterNotFoundException e) { + LOG.error("Cannot get Remote Cluster with id={}.", clusterId, e); + throw new IllegalClusterException(e); } } } http://git-wip-us.apache.org/repos/asf/ambari/blob/e5051c75/contrib/views/hive-next/src/main/java/org/apache/ambari/view/hive2/HelpService.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive-next/src/main/java/org/apache/ambari/view/hive2/HelpService.java b/contrib/views/hive-next/src/main/java/org/apache/ambari/view/hive2/HelpService.java index 95aa3f5..702b38a 100644 --- a/contrib/views/hive-next/src/main/java/org/apache/ambari/view/hive2/HelpService.java +++ b/contrib/views/hive-next/src/main/java/org/apache/ambari/view/hive2/HelpService.java @@ -32,6 +32,7 @@ import javax.ws.rs.Produces; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import java.io.IOException; /** * Help service @@ -102,7 +103,7 @@ public class HelpService extends BaseService { ATSRequestsDelegateImpl atsimpl = new ATSRequestsDelegateImpl(context, ATSParserFactory.getATSUrl(context)); atsimpl.checkATSStatus(); return getOKResponse(); - }catch (Exception e){ + }catch (IOException e){ throw new WebApplicationException(e); } } http://git-wip-us.apache.org/repos/asf/ambari/blob/e5051c75/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/HelpService.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/HelpService.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/HelpService.java index f18a422..dcddf6d 100644 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/HelpService.java +++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/HelpService.java @@ -33,6 +33,7 @@ import javax.ws.rs.Produces; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import java.io.IOException; /** * Help service @@ -102,7 +103,7 @@ public class HelpService extends BaseService { ATSRequestsDelegateImpl atsimpl = new ATSRequestsDelegateImpl(context, new ATSParserFactory(context).getATSUrl()); atsimpl.checkATSStatus(); return getOKResponse(); - }catch (Exception e){ + }catch (IOException e){ throw new WebApplicationException(e); } }