You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by db...@apache.org on 2016/05/24 09:03:17 UTC
ambari git commit: AMBARI-16812. Editing local cluster name breaks
all view instances. (Gaurav Nagar via dipayanb)
Repository: ambari
Updated Branches:
refs/heads/trunk 313605e10 -> e5474c2f7
AMBARI-16812. Editing local cluster name breaks all view instances. (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/e5474c2f
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/e5474c2f
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/e5474c2f
Branch: refs/heads/trunk
Commit: e5474c2f75b294aee834e2746e2dba0784a1851b
Parents: 313605e
Author: Dipayan Bhowmick <di...@gmail.com>
Authored: Tue May 24 14:32:57 2016 +0530
Committer: Dipayan Bhowmick <di...@gmail.com>
Committed: Tue May 24 14:32:57 2016 +0530
----------------------------------------------------------------------
.../ambariViews/CreateViewInstanceCtrl.js | 19 +++++---
.../controllers/ambariViews/ViewsEditCtrl.js | 28 +++++++++---
.../remoteClusters/RemoteClustersEditCtrl.js | 13 ++++--
.../admin-web/app/scripts/services/Cluster.js | 2 +-
.../app/scripts/services/RemoteCluster.js | 2 +-
.../ui/admin-web/app/scripts/services/View.js | 4 +-
.../admin-web/app/views/ambariViews/create.html | 4 +-
.../admin-web/app/views/ambariViews/edit.html | 4 +-
.../remoteClusters/editRemoteClusterPage.html | 2 +-
.../unit/controllers/CreateViewInstanceCtrl.js | 4 +-
.../ambari/server/ClusterNotFoundException.java | 4 ++
.../internal/RemoteClusterResourceProvider.java | 35 +++++++++++----
.../internal/ViewInstanceResourceProvider.java | 2 +-
.../server/orm/dao/RemoteAmbariClusterDAO.java | 13 ++++++
.../orm/entities/RemoteAmbariClusterEntity.java | 8 +++-
.../server/orm/entities/ViewInstanceEntity.java | 8 ++--
.../apache/ambari/server/state/Clusters.java | 8 ++++
.../server/state/cluster/ClustersImpl.java | 16 +++++++
.../server/upgrade/UpgradeCatalog240.java | 47 +++++++++++++++++++-
.../view/RemoteAmbariClusterRegistry.java | 12 ++---
.../ambari/server/view/ViewContextImpl.java | 2 +-
.../apache/ambari/server/view/ViewRegistry.java | 13 +++---
.../main/resources/Ambari-DDL-Derby-CREATE.sql | 2 +-
.../main/resources/Ambari-DDL-MySQL-CREATE.sql | 2 +-
.../main/resources/Ambari-DDL-Oracle-CREATE.sql | 2 +-
.../resources/Ambari-DDL-Postgres-CREATE.sql | 2 +-
.../Ambari-DDL-Postgres-EMBEDDED-CREATE.sql | 2 +-
.../resources/Ambari-DDL-SQLAnywhere-CREATE.sql | 2 +-
.../resources/Ambari-DDL-SQLServer-CREATE.sql | 2 +-
.../UserPrivilegeResourceProviderTest.java | 2 +-
.../ViewInstanceResourceProviderTest.java | 4 +-
.../authorization/AuthorizationHelperTest.java | 2 +-
.../server/upgrade/UpgradeCatalog240Test.java | 21 +++++++--
.../ambari/view/ViewInstanceDefinition.java | 6 +--
.../ambari/view/hive/PropertyValidator.java | 2 +-
.../ambari/view/pig/PropertyValidator.java | 2 +-
36 files changed, 228 insertions(+), 75 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/e5474c2f/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/ambariViews/CreateViewInstanceCtrl.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/ambariViews/CreateViewInstanceCtrl.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/ambariViews/CreateViewInstanceCtrl.js
index 034b113..20bd25c 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/ambariViews/CreateViewInstanceCtrl.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/ambariViews/CreateViewInstanceCtrl.js
@@ -105,7 +105,10 @@ angular.module('ambariAdminConsole')
Cluster.getAllClusters().then(function (clusters) {
if(clusters.length >0){
clusters.forEach(function(cluster) {
- $scope.clusters.push(cluster.Clusters.cluster_name)
+ $scope.clusters.push({
+ "name" : cluster.Clusters.cluster_name,
+ "id" : cluster.Clusters.cluster_id
+ })
});
$scope.noLocalClusterAvailible = false;
if($scope.clusterConfigurable){
@@ -122,7 +125,10 @@ angular.module('ambariAdminConsole')
RemoteCluster.listAll().then(function (clusters) {
if(clusters.length >0){
clusters.forEach(function(cluster) {
- $scope.remoteClusters.push(cluster.ClusterInfo.name)
+ $scope.remoteClusters.push({
+ "name" : cluster.ClusterInfo.name,
+ "id" : cluster.ClusterInfo.cluster_id
+ })
});
$scope.noRemoteClusterAvailible = false;
}else{
@@ -153,16 +159,17 @@ angular.module('ambariAdminConsole')
switch($scope.instance.clusterType) {
case 'LOCAL_AMBARI':
console.log($scope.cluster);
- $scope.instance.clusterName = $scope.cluster;
+ $scope.instance.clusterId = $scope.cluster.id;
break;
case 'REMOTE_AMBARI':
console.log($scope.data.remoteCluster);
- $scope.instance.clusterName = $scope.data.remoteCluster;
+ $scope.instance.clusterId = $scope.data.remoteCluster.id;
+
break;
default:
- $scope.instance.clusterName = null;
+ $scope.instance.clusterId = null;
}
- console.log($scope.instance.clusterName);
+ console.log($scope.instance.clusterId);
View.createInstance($scope.instance)
.then(function(data) {
Alert.success($t('views.alerts.instanceCreated', {instanceName: $scope.instance.instance_name}));
http://git-wip-us.apache.org/repos/asf/ambari/blob/e5474c2f/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 6066f74..207ecca 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
@@ -63,12 +63,21 @@ angular.module('ambariAdminConsole')
function initCtrlVariables(instance) {
$scope.data.clusterType = instance.ViewInstanceInfo.cluster_type;
+ var clusterId = instance.ViewInstanceInfo.cluster_handle;
switch($scope.data.clusterType) {
case 'LOCAL_AMBARI':
- $scope.cluster = instance.ViewInstanceInfo.cluster_handle;
+ $scope.clusters.forEach(function(cluster){
+ if(cluster.id == clusterId){
+ $scope.cluster = cluster;
+ }
+ })
break;
case 'REMOTE_AMBARI':
- $scope.data.remoteCluster = instance.ViewInstanceInfo.cluster_handle;
+ $scope.remoteClusters.forEach(function(cluster){
+ if(cluster.id == clusterId){
+ $scope.data.remoteCluster = cluster;
+ }
+ })
break;
}
$scope.originalClusterType = $scope.data.clusterType;
@@ -203,7 +212,10 @@ angular.module('ambariAdminConsole')
Cluster.getAllClusters().then(function (clusters) {
if(clusters.length >0){
clusters.forEach(function(cluster) {
- $scope.clusters.push(cluster.Clusters.cluster_name)
+ $scope.clusters.push({
+ "name" : cluster.Clusters.cluster_name,
+ "id" : cluster.Clusters.cluster_id
+ })
});
$scope.noLocalClusterAvailible = false;
}else{
@@ -218,7 +230,10 @@ angular.module('ambariAdminConsole')
RemoteCluster.listAll().then(function (clusters) {
if(clusters.length >0){
clusters.forEach(function(cluster) {
- $scope.remoteClusters.push(cluster.ClusterInfo.name)
+ $scope.remoteClusters.push({
+ "name" : cluster.ClusterInfo.name,
+ "id" : cluster.ClusterInfo.cluster_id
+ })
});
$scope.noRemoteClusterAvailible = false;
}else{
@@ -319,10 +334,11 @@ angular.module('ambariAdminConsole')
switch($scope.data.clusterType) {
case 'LOCAL_AMBARI':
- data.ViewInstanceInfo.cluster_handle = $scope.cluster;
+ data.ViewInstanceInfo.cluster_handle = $scope.cluster.id;
break;
case 'REMOTE_AMBARI':
- data.ViewInstanceInfo.cluster_handle = $scope.data.remoteCluster;
+ data.ViewInstanceInfo.cluster_handle = $scope.data.remoteCluster.id;
+ break;
break;
default :
data.ViewInstanceInfo.cluster_handle = null;
http://git-wip-us.apache.org/repos/asf/ambari/blob/e5474c2f/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/remoteClusters/RemoteClustersEditCtrl.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/remoteClusters/RemoteClustersEditCtrl.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/remoteClusters/RemoteClustersEditCtrl.js
index 5420ae5..ec2915e 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/remoteClusters/RemoteClustersEditCtrl.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/remoteClusters/RemoteClustersEditCtrl.js
@@ -28,6 +28,9 @@ angular.module('ambariAdminConsole')
var modalInstance = $modal.open({
templateUrl: 'views/remoteClusters/modals/changePassword.html',
resolve: {
+ clusterId: function() {
+ return $scope.cluster.cluster_id;
+ },
clusterName: function() {
return $scope.cluster.cluster_name;
},
@@ -38,7 +41,7 @@ angular.module('ambariAdminConsole')
return $scope.cluster.cluster_user;
}
},
- controller: ['$scope', 'clusterName', 'clusterUrl', 'clusterUser', 'Settings','Alert', function($scope, clusterName, clusterUrl , clusterUser , Settings, Alert) {
+ controller: ['$scope', 'clusterId' ,'clusterName', 'clusterUrl', 'clusterUser', 'Settings','Alert', function($scope, clusterId, clusterName, clusterUrl , clusterUser , Settings, Alert) {
$scope.passwordData = {
password: '',
currentUserName: clusterUser || ''
@@ -46,6 +49,7 @@ angular.module('ambariAdminConsole')
$scope.form = {};
+ $scope.clusterId = clusterId;
$scope.currentUser = clusterUser;
$scope.clusterName = clusterName;
$scope.clusterUrl = clusterUrl;
@@ -58,10 +62,11 @@ angular.module('ambariAdminConsole')
var payload = {
"ClusterInfo" :{
+ "cluster_id" : $scope.clusterId,
"name" : $scope.clusterName,
"url" : $scope.clusterUrl,
"username" : $scope.passwordData.currentUserName,
- "password" : $scope.passwordData.password //This field will go once backend API changes are done.
+ "password" : $scope.passwordData.password
}
};
@@ -125,6 +130,7 @@ angular.module('ambariAdminConsole')
if ($scope.form.$valid){
var payload = {
"ClusterInfo" :{
+ "cluster_id" : $scope.cluster.cluster_id,
"name" : $scope.cluster.cluster_name,
"url" : $scope.cluster.cluster_url,
"username" : $scope.cluster.cluster_user
@@ -157,7 +163,8 @@ angular.module('ambariAdminConsole')
$scope.fetchRemoteClusterDetails = function (clusterName) {
RemoteCluster.getDetails(clusterName).then(function(response) {
- $scope.cluster.cluster_name = response.ClusterInfo.name
+ $scope.cluster.cluster_id = response.ClusterInfo.cluster_id;
+ $scope.cluster.cluster_name = response.ClusterInfo.name;
$scope.cluster.cluster_url = response.ClusterInfo.url;
$scope.cluster.cluster_user = response.ClusterInfo.username;
})
http://git-wip-us.apache.org/repos/asf/ambari/blob/e5474c2f/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/Cluster.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/Cluster.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/Cluster.js
index 0bf73d5..c1cf221 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/Cluster.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/Cluster.js
@@ -82,7 +82,7 @@ angular.module('ambariAdminConsole')
getAllClusters: function() {
var deferred = $q.defer();
- $http.get(Settings.baseUrl + '/clusters', {mock: 'cluster/clusters.json'})
+ $http.get(Settings.baseUrl + '/clusters?fields=Clusters/cluster_id', {mock: 'cluster/clusters.json'})
.then(function(data, status, headers) {
deferred.resolve(data.data.items);
})
http://git-wip-us.apache.org/repos/asf/ambari/blob/e5474c2f/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/RemoteCluster.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/RemoteCluster.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/RemoteCluster.js
index 1c5f588..49c6abc 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/RemoteCluster.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/RemoteCluster.js
@@ -119,7 +119,7 @@ angular.module('ambariAdminConsole')
var deferred = $q.defer();
/* TODO :: Add params like RemoteCluster.matches and &from , &page_size */
- $http.get(Settings.baseUrl + "/remoteclusters?fields=ClusterInfo/services")
+ $http.get(Settings.baseUrl + "/remoteclusters?fields=ClusterInfo/services,ClusterInfo/cluster_id")
.success(function(response) {
deferred.resolve(response.items);
})
http://git-wip-us.apache.org/repos/asf/ambari/blob/e5474c2f/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/View.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/View.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/View.js
index bdee427..fbe0ec1 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/View.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/View.js
@@ -327,8 +327,8 @@ angular.module('ambariAdminConsole')
data.properties = settings;
data.cluster_type = instanceInfo.clusterType;
- if(instanceInfo.clusterName != null) {
- data.cluster_handle = instanceInfo.clusterName;
+ if(instanceInfo.clusterId != null) {
+ data.cluster_handle = instanceInfo.clusterId;
} else {
angular.extend(data.properties, properties);
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/e5474c2f/ambari-admin/src/main/resources/ui/admin-web/app/views/ambariViews/create.html
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/views/ambariViews/create.html b/ambari-admin/src/main/resources/ui/admin-web/app/views/ambariViews/create.html
index 051d720..924885f 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/views/ambariViews/create.html
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/views/ambariViews/create.html
@@ -133,7 +133,7 @@
<label for="" class="control-label col-sm-3 ng-binding not-required" >{{'views.clusterName' | translate}}</label>
<div>
<div class="col-sm-9">
- <select ng-model="cluster" ng-disabled="instance.clusterType != 'LOCAL_AMBARI' || noLocalClusterAvailible" ng-change="onClusterChange()" class="clusters-name-dropdown form-control" ng-options="o as o for o in clusters"></select>
+ <select ng-model="cluster" ng-disabled="instance.clusterType != 'LOCAL_AMBARI' || noLocalClusterAvailible" ng-change="onClusterChange()" class="clusters-name-dropdown form-control" ng-options="o as o.name for o in clusters"></select>
</div>
</div>
</div>
@@ -154,7 +154,7 @@
<label for="" class="control-label col-sm-3 ng-binding not-required" >{{'views.clusterName' | translate}}</label>
<div>
<div class="col-sm-9">
- <select ng-model="data.remoteCluster" ng-disabled="instance.clusterType != 'REMOTE_AMBARI' || noRemoteClusterAvailable" ng-change="onClusterChange()" class="clusters-name-dropdown form-control" ng-options="o as o for o in remoteClusters"></select>
+ <select ng-model="data.remoteCluster" ng-disabled="instance.clusterType != 'REMOTE_AMBARI' || noRemoteClusterAvailable" ng-change="onClusterChange()" class="clusters-name-dropdown form-control" ng-options="o as o.name for o in remoteClusters"></select>
</div>
</div>
</div>
http://git-wip-us.apache.org/repos/asf/ambari/blob/e5474c2f/ambari-admin/src/main/resources/ui/admin-web/app/views/ambariViews/edit.html
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/views/ambariViews/edit.html b/ambari-admin/src/main/resources/ui/admin-web/app/views/ambariViews/edit.html
index 05544d2..7a4ca0b 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/views/ambariViews/edit.html
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/views/ambariViews/edit.html
@@ -177,7 +177,7 @@
<label for="" class="control-label col-sm-3 ng-binding not-required" >{{'views.clusterName' | translate}}</label>
<div>
<div class="col-sm-9">
- <select ng-model="cluster" ng-disabled="(data.clusterType != 'LOCAL_AMBARI') || editConfigurationDisabled" ng-change="onClusterChange()" class="clusters-name-dropdown form-control" ng-options="o as o for o in clusters"></select>
+ <select ng-model="cluster" ng-disabled="(data.clusterType != 'LOCAL_AMBARI') || editConfigurationDisabled" ng-change="onClusterChange()" class="clusters-name-dropdown form-control" ng-options="o as o.name for o in clusters"></select>
</div>
</div>
</div>
@@ -193,7 +193,7 @@
<label for="" class="control-label col-sm-3 ng-binding not-required" >{{'views.clusterName' | translate}}</label>
<div>
<div class="col-sm-9">
- <select ng-model="data.remoteCluster" ng-disabled="(data.clusterType != 'REMOTE_AMBARI') || editConfigurationDisabled" ng-change="onClusterChange()" class="clusters-name-dropdown form-control" ng-options="o as o for o in remoteClusters"></select>
+ <select ng-model="data.remoteCluster" ng-disabled="(data.clusterType != 'REMOTE_AMBARI') || editConfigurationDisabled" ng-change="onClusterChange()" class="clusters-name-dropdown form-control" ng-options="o as o.name for o in remoteClusters"></select>
</div>
</div>
</div>
http://git-wip-us.apache.org/repos/asf/ambari/blob/e5474c2f/ambari-admin/src/main/resources/ui/admin-web/app/views/remoteClusters/editRemoteClusterPage.html
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/views/remoteClusters/editRemoteClusterPage.html b/ambari-admin/src/main/resources/ui/admin-web/app/views/remoteClusters/editRemoteClusterPage.html
index 8979cba..e3fbe9c 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/views/remoteClusters/editRemoteClusterPage.html
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/views/remoteClusters/editRemoteClusterPage.html
@@ -33,7 +33,7 @@
<div class="form-group" ng-class="{'has-error' : form.user_name.$error.required && form.submitted}">
<label for="clustername" class="col-sm-2 control-label">{{'views.clusterName' | translate}}</label>
<div class="col-sm-10">
- <input type="text" id="clustername" disabled class="form-control" name="cluster_name" ng-pattern="/[a-zA-Z0-9\-]*/" placeholder="Cluster Name" ng-model="cluster.cluster_name" required autocomplete="off">
+ <input type="text" id="clustername" class="form-control" name="cluster_name" ng-pattern="/[a-zA-Z0-9\-]*/" placeholder="Cluster Name" ng-model="cluster.cluster_name" required autocomplete="off">
<div class="alert alert-danger top-margin" ng-show="form.cluster_name.$error.required && form.submitted"> {{'common.alerts.fieldIsRequired' | translate}}</div>
</div>
</div>
http://git-wip-us.apache.org/repos/asf/ambari/blob/e5474c2f/ambari-admin/src/main/resources/ui/admin-web/test/unit/controllers/CreateViewInstanceCtrl.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/test/unit/controllers/CreateViewInstanceCtrl.js b/ambari-admin/src/main/resources/ui/admin-web/test/unit/controllers/CreateViewInstanceCtrl.js
index 595fcc0..117021e 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/test/unit/controllers/CreateViewInstanceCtrl.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/test/unit/controllers/CreateViewInstanceCtrl.js
@@ -68,7 +68,7 @@ describe('#CreateViewInstanceCtrl', function () {
scope.version = '1.0.0';
$httpBackend.expectGET('template/modal/backdrop.html');
$httpBackend.expectGET('template/modal/window.html');
- $httpBackend.whenGET(/\/api\/v1\/clusters\?_=\d+/).respond(200, {
+ $httpBackend.whenGET(/\/api\/v1\/clusters\?fields=Clusters\/cluster_id&_=\d+/).respond(200, {
"items" : [
{
"Clusters" : {
@@ -78,7 +78,7 @@ describe('#CreateViewInstanceCtrl', function () {
}
]
});
- $httpBackend.whenGET(/\/api\/v1\/remoteclusters\?fields=ClusterInfo\/services&_=\d+/).respond(200, {
+ $httpBackend.whenGET(/\/api\/v1\/remoteclusters\?fields=ClusterInfo\/services,ClusterInfo\/cluster_id&_=\d+/).respond(200, {
"items" : [
{
"ClusterInfo" : {
http://git-wip-us.apache.org/repos/asf/ambari/blob/e5474c2f/ambari-server/src/main/java/org/apache/ambari/server/ClusterNotFoundException.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ClusterNotFoundException.java b/ambari-server/src/main/java/org/apache/ambari/server/ClusterNotFoundException.java
index cd338a0..62d0714 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ClusterNotFoundException.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ClusterNotFoundException.java
@@ -24,4 +24,8 @@ public class ClusterNotFoundException extends ObjectNotFoundException {
public ClusterNotFoundException(String clusterName) {
super("Cluster not found, clusterName=" + clusterName);
}
+
+ public ClusterNotFoundException(Long clusterId) {
+ super("Cluster not found, clusterId=" + clusterId);
+ }
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/e5474c2f/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RemoteClusterResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RemoteClusterResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RemoteClusterResourceProvider.java
index 413dbff..49892cb 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RemoteClusterResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RemoteClusterResourceProvider.java
@@ -63,6 +63,7 @@ public class RemoteClusterResourceProvider extends AbstractAuthorizedResourcePro
* Remote Cluster property id constants.
*/
public static final String CLUSTER_NAME_PROPERTY_ID = "ClusterInfo/name";
+ public static final String CLUSTER_ID_PROPERTY_ID = "ClusterInfo/cluster_id";
public static final String CLUSTER_URL_PROPERTY_ID = "ClusterInfo/url";
public static final String USERNAME_PROPERTY_ID = "ClusterInfo/username";
public static final String PASSWORD_PROPERTY_ID = "ClusterInfo/password";
@@ -87,6 +88,7 @@ public class RemoteClusterResourceProvider extends AbstractAuthorizedResourcePro
private static Set<String> propertyIds = new HashSet<String>();
static {
propertyIds.add(CLUSTER_NAME_PROPERTY_ID);
+ propertyIds.add(CLUSTER_ID_PROPERTY_ID);
propertyIds.add(CLUSTER_URL_PROPERTY_ID);
propertyIds.add(USERNAME_PROPERTY_ID);
propertyIds.add(PASSWORD_PROPERTY_ID);
@@ -167,6 +169,7 @@ public class RemoteClusterResourceProvider extends AbstractAuthorizedResourcePro
protected Resource toResource(Set<String> requestedIds, RemoteAmbariClusterEntity cluster) {
Resource resource = new ResourceImpl(Resource.Type.RemoteCluster);
setResourceProperty(resource, CLUSTER_NAME_PROPERTY_ID, cluster.getName(), requestedIds);
+ setResourceProperty(resource, CLUSTER_ID_PROPERTY_ID, cluster.getId(), requestedIds);
setResourceProperty(resource, CLUSTER_URL_PROPERTY_ID, cluster.getUrl(), requestedIds);
setResourceProperty(resource, USERNAME_PROPERTY_ID, cluster.getUsername(), requestedIds);
ArrayList<String> services = new ArrayList<String>();
@@ -237,8 +240,14 @@ public class RemoteClusterResourceProvider extends AbstractAuthorizedResourcePro
public Void invoke() throws AmbariException {
String name = (String)properties.get(CLUSTER_NAME_PROPERTY_ID);
- if(StringUtils.isEmpty(name)){
- throw new IllegalArgumentException("Cluster Name cannot ne null or Empty");
+ if (StringUtils.isEmpty(name)) {
+ throw new IllegalArgumentException("Cluster Name cannot be null or Empty");
+ }
+
+ String id = (String)properties.get(CLUSTER_ID_PROPERTY_ID);
+
+ if (StringUtils.isEmpty(id)) {
+ throw new IllegalArgumentException("Cluster Id cannot be null or Empty");
}
saveOrUpdateRemoteAmbariClusterEntity(properties,true);
@@ -261,16 +270,24 @@ public class RemoteClusterResourceProvider extends AbstractAuthorizedResourcePro
String username = (String)properties.get(USERNAME_PROPERTY_ID);
String password = (String)properties.get(PASSWORD_PROPERTY_ID);
- if(StringUtils.isEmpty(url) && StringUtils.isEmpty(username)){
+ if (StringUtils.isEmpty(url) && StringUtils.isEmpty(username)) {
throw new IllegalArgumentException("Url or username cannot be null");
}
- RemoteAmbariClusterEntity entity = remoteAmbariClusterDAO.findByName(name);
+ RemoteAmbariClusterEntity entity ;
+
+ if (update) {
+ Long id = Long.valueOf((String) properties.get(CLUSTER_ID_PROPERTY_ID));
+ entity = remoteAmbariClusterDAO.findById(id);
+ if (entity == null) {
+ throw new IllegalArgumentException(String.format("Cannot find cluster with Id : \"%s\"", id));
+ }
+ } else {
- if(update && entity == null){
- throw new IllegalArgumentException(String.format("Cannot find cluster with name : \"%s\"",name));
- }else if(!update && entity != null){
- throw new DuplicateResourceException(String.format("Cluster with name : \"%s\" already exists",name));
+ entity = remoteAmbariClusterDAO.findByName(name);
+ if (entity != null) {
+ throw new DuplicateResourceException(String.format("Cluster with name : \"%s\" already exists", name));
+ }
}
// Check Password not null for create
@@ -288,7 +305,7 @@ public class RemoteClusterResourceProvider extends AbstractAuthorizedResourcePro
entity.setName(name);
entity.setUrl(url);
try {
- if(password != null) {
+ if (password != null) {
entity.setUsername(username);
entity.setPassword(password);
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/e5474c2f/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProvider.java
index b8ed215..bdb1087 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProvider.java
@@ -352,7 +352,7 @@ public class ViewInstanceResourceProvider extends AbstractAuthorizedResourceProv
}
if (properties.containsKey(CLUSTER_HANDLE_PROPERTY_ID)) {
- viewInstanceEntity.setClusterHandle((String) properties.get(CLUSTER_HANDLE_PROPERTY_ID));
+ viewInstanceEntity.setClusterHandle(Long.valueOf((String) properties.get(CLUSTER_HANDLE_PROPERTY_ID)));
}
if (properties.containsKey(CLUSTER_TYPE_PROPERTY_ID)) {
http://git-wip-us.apache.org/repos/asf/ambari/blob/e5474c2f/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RemoteAmbariClusterDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RemoteAmbariClusterDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RemoteAmbariClusterDAO.java
index 72ab368..e817aff 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RemoteAmbariClusterDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RemoteAmbariClusterDAO.java
@@ -72,6 +72,19 @@ public class RemoteAmbariClusterDAO {
}
/**
+ * Find Cluster by Id
+ * @param clusterId
+ * @return
+ */
+ @RequiresSession
+ public RemoteAmbariClusterEntity findById(Long clusterId) {
+ TypedQuery<RemoteAmbariClusterEntity> query = entityManagerProvider.get().
+ createNamedQuery("remoteAmbariClusterById", RemoteAmbariClusterEntity.class);
+ query.setParameter("clusterId", clusterId);
+ return daoUtils.selectSingle(query);
+ }
+
+ /**
* Save a Cluster entity
* @param entity
*/
http://git-wip-us.apache.org/repos/asf/ambari/blob/e5474c2f/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RemoteAmbariClusterEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RemoteAmbariClusterEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RemoteAmbariClusterEntity.java
index 99c9f2a..48ca3f8 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RemoteAmbariClusterEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RemoteAmbariClusterEntity.java
@@ -53,7 +53,11 @@ import java.util.Collection;
@NamedQuery(name = "remoteAmbariClusterByName", query =
"SELECT remoteAmbariCluster " +
"FROM RemoteAmbariClusterEntity remoteAmbariCluster " +
- "WHERE remoteAmbariCluster.name=:clusterName")})
+ "WHERE remoteAmbariCluster.name=:clusterName"),
+ @NamedQuery(name = "remoteAmbariClusterById", query =
+ "SELECT remoteAmbariCluster " +
+ "FROM RemoteAmbariClusterEntity remoteAmbariCluster " +
+ "WHERE remoteAmbariCluster.id=:clusterId")})
@Entity
public class RemoteAmbariClusterEntity {
@@ -67,7 +71,7 @@ public class RemoteAmbariClusterEntity {
@GeneratedValue(strategy = GenerationType.TABLE, generator = "remote_cluster_id_generator")
private Long id;
- @Column(name = "name", nullable = false, insertable = true, updatable = false)
+ @Column(name = "name", nullable = false, insertable = true, updatable = true)
private String name;
@Column(name = "url", nullable = false, insertable = true, updatable = true)
http://git-wip-us.apache.org/repos/asf/ambari/blob/e5474c2f/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ViewInstanceEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ViewInstanceEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ViewInstanceEntity.java
index 98bafdd..e20db3b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ViewInstanceEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ViewInstanceEntity.java
@@ -121,7 +121,7 @@ public class ViewInstanceEntity implements ViewInstanceDefinition {
* The associated cluster handle.
*/
@Column(name = "cluster_handle", nullable = true)
- private String clusterHandle;
+ private Long clusterHandle;
/**
* Cluster Type for cluster Handle
@@ -360,7 +360,7 @@ public class ViewInstanceEntity implements ViewInstanceDefinition {
}
@Override
- public String getClusterHandle() {
+ public Long getClusterHandle() {
return clusterHandle;
}
@@ -443,11 +443,11 @@ public class ViewInstanceEntity implements ViewInstanceDefinition {
/**
* Set a cluster association for this view instance with the Ambari cluster
* identified by the given cluster handle. For a local cluster reference,
- * the cluster handle is simply the unique cluster name.
+ * the cluster handle is simply the unique cluster id.
*
* @param clusterHandle the cluster identifier
*/
- public void setClusterHandle(String clusterHandle) {
+ public void setClusterHandle(Long clusterHandle) {
this.clusterHandle = clusterHandle;
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/e5474c2f/ambari-server/src/main/java/org/apache/ambari/server/state/Clusters.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/Clusters.java b/ambari-server/src/main/java/org/apache/ambari/server/state/Clusters.java
index e660d20..bd9de13 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/Clusters.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/Clusters.java
@@ -62,6 +62,14 @@ public interface Clusters {
throws AmbariException;
/**
+ * Gets the Cluster given the cluster id
+ * @param clusterId Id of the Cluster to retrieve
+ * @return <code>Cluster</code> identified by the given id
+ */
+ Cluster getCluster(Long clusterId)
+ throws AmbariException;
+
+ /**
* Get all clusters
* @return <code>Map</code> of clusters with cluster name as key
*/
http://git-wip-us.apache.org/repos/asf/ambari/blob/e5474c2f/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
index f78dd95..c26e1e9 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
@@ -297,6 +297,22 @@ public class ClustersImpl implements Clusters {
}
@Override
+ public Cluster getCluster(Long clusterId)
+ throws AmbariException {
+ checkLoaded();
+
+ Cluster cluster = null;
+ if (clusterId != null) {
+ cluster = clustersById.get(clusterId);
+ }
+ if (null == cluster) {
+ throw new ClusterNotFoundException(clusterId);
+ }
+ RetryHelper.addAffectedCluster(cluster);
+ return cluster;
+ }
+
+ @Override
public Cluster getClusterById(long id) throws AmbariException {
checkLoaded();
http://git-wip-us.apache.org/repos/asf/ambari/blob/e5474c2f/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java
index b147a43..3d1f0f2 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java
@@ -136,6 +136,7 @@ public class UpgradeCatalog240 extends AbstractUpgradeCatalog {
public static final String BLUEPRINT_TABLE = "blueprint";
public static final String VIEWINSTANCE_TABLE = "viewinstance";
public static final String SHORT_URL_COLUMN = "short_url";
+ public static final String CLUSTER_HANDLE_COLUMN = "cluster_handle";
protected static final String CLUSTER_VERSION_TABLE = "cluster_version";
protected static final String HOST_VERSION_TABLE = "host_version";
@@ -251,6 +252,7 @@ public class UpgradeCatalog240 extends AbstractUpgradeCatalog {
createViewUrlTableDDL();
updateViewInstanceEntityTable();
createRemoteClusterTable();
+ updateViewInstanceTable();
}
private void createRemoteClusterTable() throws SQLException {
@@ -347,7 +349,7 @@ public class UpgradeCatalog240 extends AbstractUpgradeCatalog {
private void insertClusterInheritedPrincipal(String name) {
PrincipalTypeEntity principalTypeEntity = new PrincipalTypeEntity();
- principalTypeEntity.setName("ALL.CLUSTER.ADMINISTRATOR");
+ principalTypeEntity.setName(name);
principalTypeEntity = principalTypeDAO.merge(principalTypeEntity);
PrincipalEntity principalEntity = new PrincipalEntity();
@@ -2116,4 +2118,47 @@ public class UpgradeCatalog240 extends AbstractUpgradeCatalog {
private void updateTezViewProperty() throws SQLException {
dbAccessor.executeUpdate("UPDATE viewinstanceproperty SET name = 'yarn.ats.url' where name = 'yarn.timeline-server.url'");
}
+
+ /**
+ * Update view instance table's cluster_handle column to have cluster_id
+ * instead of cluster_name
+ */
+ @Transactional
+ private void updateViewInstanceTable() throws SQLException {
+
+ String cluster_handle_dummy = "cluster_handle_dummy";
+
+ dbAccessor.addColumn(VIEWINSTANCE_TABLE,
+ new DBColumnInfo(cluster_handle_dummy, Long.class, null, null, true));
+
+ Statement statement = null;
+ ResultSet resultSet = null;
+
+ try {
+ statement = dbAccessor.getConnection().createStatement();
+ if (statement != null) {
+ String selectSQL = String.format("SELECT cluster_id, cluster_name FROM %s",
+ CLUSTER_TABLE);
+
+ resultSet = statement.executeQuery(selectSQL);
+ while (null != resultSet && resultSet.next()) {
+ final Long clusterId = resultSet.getLong("cluster_id");
+ final String clusterName = resultSet.getString("cluster_name");
+
+ String updateSQL = String.format(
+ "UPDATE %s SET %s = %d WHERE cluster_handle = '%s'",
+ VIEWINSTANCE_TABLE, cluster_handle_dummy, clusterId, clusterName);
+
+ dbAccessor.executeQuery(updateSQL);
+ }
+ }
+ } finally {
+ JdbcUtils.closeResultSet(resultSet);
+ JdbcUtils.closeStatement(statement);
+ }
+
+ dbAccessor.dropColumn(VIEWINSTANCE_TABLE, CLUSTER_HANDLE_COLUMN);
+ dbAccessor.renameColumn(VIEWINSTANCE_TABLE, cluster_handle_dummy,
+ new DBColumnInfo(CLUSTER_HANDLE_COLUMN, Long.class, null, null, true));
+ }
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/e5474c2f/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 38a47a4..c0c887f 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
@@ -46,11 +46,11 @@ public class RemoteAmbariClusterRegistry {
@Inject
private Configuration configuration;
- public RemoteAmbariCluster get(String clusterName){
- RemoteAmbariCluster remoteAmbariCluster = clusterMap.get(clusterName);
+ public RemoteAmbariCluster get(Long clusterId){
+ RemoteAmbariCluster remoteAmbariCluster = clusterMap.get(clusterId);
if(remoteAmbariCluster == null){
- RemoteAmbariCluster cluster = getCluster(clusterName);
- RemoteAmbariCluster oldCluster = clusterMap.putIfAbsent(clusterName, cluster);
+ RemoteAmbariCluster cluster = getCluster(clusterId);
+ RemoteAmbariCluster oldCluster = clusterMap.putIfAbsent(cluster.getName(), cluster);
if(oldCluster == null) remoteAmbariCluster = cluster;
else remoteAmbariCluster = oldCluster;
}
@@ -58,8 +58,8 @@ public class RemoteAmbariClusterRegistry {
}
- private RemoteAmbariCluster getCluster(String clusterName) {
- RemoteAmbariClusterEntity remoteAmbariClusterEntity = remoteAmbariClusterDAO.findByName(clusterName);
+ private RemoteAmbariCluster getCluster(Long clusterId) {
+ RemoteAmbariClusterEntity remoteAmbariClusterEntity = remoteAmbariClusterDAO.findById(clusterId);
RemoteAmbariCluster remoteAmbariCluster = new RemoteAmbariCluster(remoteAmbariClusterEntity, configuration);
return remoteAmbariCluster;
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/e5474c2f/ambari-server/src/main/java/org/apache/ambari/server/view/ViewContextImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/view/ViewContextImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/view/ViewContextImpl.java
index e98a4cd..f1d5c35 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/view/ViewContextImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/view/ViewContextImpl.java
@@ -307,7 +307,7 @@ public class ViewContextImpl implements ViewContext, ViewController {
@Override
public AmbariStreamProvider getAmbariClusterStreamProvider() {
- String clusterHandle = viewInstanceEntity.getClusterHandle();
+ Long clusterHandle = viewInstanceEntity.getClusterHandle();
ClusterType clusterType = viewInstanceEntity.getClusterType();
AmbariStreamProvider clusterStreamProvider = null;
http://git-wip-us.apache.org/repos/asf/ambari/blob/e5474c2f/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 1176c36..bda1079 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
@@ -918,7 +918,7 @@ public class ViewRegistry {
*/
public Cluster getCluster(ViewInstanceDefinition viewInstance) {
if (viewInstance != null) {
- String clusterId = viewInstance.getClusterHandle();
+ Long clusterId = viewInstance.getClusterHandle();
if (clusterId != null && viewInstance.getClusterType() == ClusterType.LOCAL_AMBARI) {
try {
@@ -965,7 +965,7 @@ public class ViewRegistry {
LOG.info("Auto creating instance of view " + viewName + " for cluster " + clusterName + ".");
ViewInstanceEntity viewInstanceEntity = createViewInstanceEntity(viewEntity, viewConfig, autoConfig);
- viewInstanceEntity.setClusterHandle(clusterName);
+ viewInstanceEntity.setClusterHandle(clusterId);
installViewInstance(viewInstanceEntity);
}
} catch (Exception e) {
@@ -1720,6 +1720,7 @@ public class ViewRegistry {
for (org.apache.ambari.server.state.Cluster cluster : allClusters.values()) {
String clusterName = cluster.getClusterName();
+ Long clusterId= cluster.getClusterId();
StackId stackId = cluster.getCurrentStackVersion();
Set<String> serviceNames = cluster.getServices().keySet();
@@ -1729,7 +1730,7 @@ public class ViewRegistry {
if (checkAutoInstanceConfig(autoInstanceConfig, stackId, service, serviceNames)) {
LOG.info("Auto creating instance of view " + viewName + " for cluster " + clusterName + ".");
ViewInstanceEntity viewInstanceEntity = createViewInstanceEntity(viewEntity, viewConfig, autoInstanceConfig);
- viewInstanceEntity.setClusterHandle(clusterName);
+ viewInstanceEntity.setClusterHandle(clusterId);
installViewInstance(viewInstanceEntity);
addClusterInheritedPermissions(viewInstanceEntity, permissions);
}
@@ -1946,11 +1947,11 @@ public class ViewRegistry {
/**
* Get Remote Ambari Cluster Stream provider
*
- * @param clusterName
+ * @param clusterId
* @return
*/
- protected AmbariStreamProvider createRemoteAmbariStreamProvider(String clusterName){
- RemoteAmbariClusterEntity clusterEntity = remoteAmbariClusterDAO.findByName(clusterName);
+ protected AmbariStreamProvider createRemoteAmbariStreamProvider(Long clusterId){
+ RemoteAmbariClusterEntity clusterEntity = remoteAmbariClusterDAO.findById(clusterId);
if(clusterEntity != null) {
return new RemoteAmbariStreamProvider(getBaseurl(clusterEntity.getUrl()),
clusterEntity.getUsername(),clusterEntity.getPassword(),
http://git-wip-us.apache.org/repos/asf/ambari/blob/e5474c2f/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql
index 31dd8f2..2c2d743 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql
@@ -566,7 +566,7 @@ CREATE TABLE viewinstance (
icon64 VARCHAR(255),
xml_driven CHAR(1),
alter_names SMALLINT NOT NULL DEFAULT 1,
- cluster_handle VARCHAR(255),
+ cluster_handle BIGINT,
cluster_type VARCHAR(100) NOT NULL DEFAULT 'LOCAL_AMBARI',
short_url BIGINT,
CONSTRAINT PK_viewinstance PRIMARY KEY (view_instance_id),
http://git-wip-us.apache.org/repos/asf/ambari/blob/e5474c2f/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
index 3c4f1ca..ee87cc5 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
@@ -574,7 +574,7 @@ CREATE TABLE viewinstance (
icon64 VARCHAR(255),
xml_driven CHAR(1),
alter_names TINYINT(1) NOT NULL DEFAULT 1,
- cluster_handle VARCHAR(255),
+ cluster_handle BIGINT,
cluster_type VARCHAR(100) NOT NULL DEFAULT 'LOCAL_AMBARI',
short_url BIGINT,
CONSTRAINT PK_viewinstance PRIMARY KEY (view_instance_id),
http://git-wip-us.apache.org/repos/asf/ambari/blob/e5474c2f/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
index f31af16..a65df9c 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
@@ -565,7 +565,7 @@ CREATE TABLE viewinstance (
icon64 VARCHAR(255),
xml_driven CHAR(1),
alter_names NUMBER(1) DEFAULT 1 NOT NULL,
- cluster_handle VARCHAR(255),
+ cluster_handle BIGINT,
cluster_type VARCHAR(100) DEFAULT 'LOCAL_AMBARI' NOT NULL,
short_url NUMBER,
CONSTRAINT PK_viewinstance PRIMARY KEY (view_instance_id),
http://git-wip-us.apache.org/repos/asf/ambari/blob/e5474c2f/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
index d1147b7..6f38ec8 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
@@ -566,7 +566,7 @@ CREATE TABLE viewinstance (
icon64 VARCHAR(255),
xml_driven CHAR(1),
alter_names SMALLINT NOT NULL DEFAULT 1,
- cluster_handle VARCHAR(255),
+ cluster_handle BIGINT,
cluster_type VARCHAR(100) NOT NULL DEFAULT 'LOCAL_AMBARI',
short_url BIGINT,
CONSTRAINT PK_viewinstance PRIMARY KEY (view_instance_id),
http://git-wip-us.apache.org/repos/asf/ambari/blob/e5474c2f/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql
index 5a7a6a5..ca57de5 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql
@@ -667,7 +667,7 @@ CREATE TABLE ambari.viewinstance (
icon64 VARCHAR(255),
xml_driven CHAR(1),
alter_names SMALLINT NOT NULL DEFAULT 1,
- cluster_handle VARCHAR(255),
+ cluster_handle BIGINT,
cluster_type VARCHAR(100) NOT NULL DEFAULT 'LOCAL_AMBARI',
short_url BIGINT,
CONSTRAINT PK_viewinstance PRIMARY KEY (view_instance_id),
http://git-wip-us.apache.org/repos/asf/ambari/blob/e5474c2f/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
index 2dba3b7..bd2e6d6 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
@@ -563,7 +563,7 @@ CREATE TABLE viewinstance (
icon64 VARCHAR(255),
xml_driven CHAR(1),
alter_names BIT NOT NULL DEFAULT 1,
- cluster_handle VARCHAR(255),
+ cluster_handle BIGINT,
cluster_type VARCHAR(100) NOT NULL DEFAULT 'LOCAL_AMBARI',
short_url NUMERIC,
CONSTRAINT PK_viewinstance PRIMARY KEY (view_instance_id),
http://git-wip-us.apache.org/repos/asf/ambari/blob/e5474c2f/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
index e769e5b..9269b13 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
@@ -573,7 +573,7 @@ CREATE TABLE viewinstance (
icon64 VARCHAR(255),
xml_driven CHAR(1),
alter_names BIT NOT NULL DEFAULT 1,
- cluster_handle VARCHAR(255),
+ cluster_handle BIGINT,
cluster_type VARCHAR(100) NOT NULL DEFAULT 'LOCAL_AMBARI',
short_url BIGINT,
CONSTRAINT PK_viewinstance PRIMARY KEY CLUSTERED (view_instance_id),
http://git-wip-us.apache.org/repos/asf/ambari/blob/e5474c2f/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UserPrivilegeResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UserPrivilegeResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UserPrivilegeResourceProviderTest.java
index 88b00ca..1f3cb52 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UserPrivilegeResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UserPrivilegeResourceProviderTest.java
@@ -360,7 +360,7 @@ public class UserPrivilegeResourceProviderTest extends EasyMockSupport {
ViewInstanceEntity viewInstanceEntity = createMock(ViewInstanceEntity.class);
expect(viewInstanceEntity.getViewEntity()).andReturn(viewEntity).atLeastOnce();
expect(viewInstanceEntity.getName()).andReturn("Test View").atLeastOnce();
- expect(viewInstanceEntity.getClusterHandle()).andReturn("c1").atLeastOnce();
+ expect(viewInstanceEntity.getClusterHandle()).andReturn(1L).atLeastOnce();
expect(viewInstanceEntity.getResource()).andReturn(resourceEntity).atLeastOnce();
PrivilegeEntity privilegeEntityViewWithClusterAdminAccess = createMock(PrivilegeEntity.class);
http://git-wip-us.apache.org/repos/asf/ambari/blob/e5474c2f/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProviderTest.java
index 1044570..f6614dc 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProviderTest.java
@@ -91,7 +91,7 @@ public class ViewInstanceResourceProviderTest {
expect(viewregistry.checkAdmin()).andReturn(true);
expect(viewregistry.checkAdmin()).andReturn(false);
- expect(viewInstanceEntity.getClusterHandle()).andReturn("c1");
+ expect(viewInstanceEntity.getClusterHandle()).andReturn(1L);
replay(viewregistry, viewEntity, viewInstanceEntity);
@@ -102,7 +102,7 @@ public class ViewInstanceResourceProviderTest {
Map<String, Object> props = properties.get("ViewInstanceInfo");
assertNotNull(props);
assertEquals(1, props.size());
- assertEquals("c1", props.get("cluster_handle"));
+ assertEquals(1L, props.get("cluster_handle"));
props = properties.get("ViewInstanceInfo/properties");
assertNotNull(props);
http://git-wip-us.apache.org/repos/asf/ambari/blob/e5474c2f/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AuthorizationHelperTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AuthorizationHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AuthorizationHelperTest.java
index 9c59aab..9f38841 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AuthorizationHelperTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AuthorizationHelperTest.java
@@ -360,7 +360,7 @@ public class AuthorizationHelperTest extends EasyMockSupport {
PrivilegeDAO privilegeDAO = createNiceMock(PrivilegeDAO.class);
ViewInstanceEntity viewInstanceEntity = createNiceMock(ViewInstanceEntity.class);
- expect(viewInstanceEntity.getClusterHandle()).andReturn("c1").anyTimes();
+ expect(viewInstanceEntity.getClusterHandle()).andReturn(1L).anyTimes();
PrivilegeEntity privilegeEntity = createNiceMock(PrivilegeEntity.class);
PrincipalEntity principalEntity = createNiceMock(PrincipalEntity.class);
http://git-wip-us.apache.org/repos/asf/ambari/blob/e5474c2f/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog240Test.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog240Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog240Test.java
index da01109..a8af259 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog240Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog240Test.java
@@ -261,6 +261,17 @@ public class UpgradeCatalog240Test {
expect(dbAccessor.getConnection()).andReturn(connection);
expect(connection.createStatement()).andReturn(statement);
+ // Test viewInstance update
+ dbAccessor.addColumn(eq(UpgradeCatalog240.VIEWINSTANCE_TABLE), anyObject(DBAccessor.DBColumnInfo.class));
+
+ expect(dbAccessor.getConnection()).andReturn(connection);
+ expect(connection.createStatement()).andReturn(statement);
+
+ dbAccessor.dropColumn(UpgradeCatalog240.VIEWINSTANCE_TABLE,UpgradeCatalog240.CLUSTER_HANDLE_COLUMN);
+
+ Capture<DBAccessor.DBColumnInfo> capturedClusterHandleColumn = EasyMock.newCapture();
+ dbAccessor.renameColumn(eq(UpgradeCatalog240.VIEWINSTANCE_TABLE), anyString() , capture(capturedClusterHandleColumn));
+
replay(dbAccessor, configuration, connection, statement, resultSet);
Module module = new Module() {
@@ -418,7 +429,7 @@ public class UpgradeCatalog240Test {
List<DBAccessor.DBColumnInfo> capturedViewUrlColumsValue = capturedViewUrlColums.getValue();
Assert.assertNotNull(capturedViewUrlColumsValue);
- Assert.assertEquals(capturedViewUrlColumsValue.size(),3);
+ Assert.assertEquals(3, capturedViewUrlColumsValue.size());
// Verify cluster_type column
DBAccessor.DBColumnInfo viewInstanceEntityClusterTypeValue = viewInstanceClusterType.getValue();
@@ -428,11 +439,15 @@ public class UpgradeCatalog240Test {
List<DBAccessor.DBColumnInfo> capturedRemoteAmbariClusterColumnsValue = capturedRemoteAmbariClusterColumns.getValue();
Assert.assertNotNull(capturedRemoteAmbariClusterColumnsValue);
- Assert.assertEquals(capturedRemoteAmbariClusterColumnsValue.size(),5);
+ Assert.assertEquals(5, capturedRemoteAmbariClusterColumnsValue.size());
List<DBAccessor.DBColumnInfo> capturedRemoteClusterServiceColumnsValue = capturedRemoteClusterServiceColumns.getValue();
Assert.assertNotNull(capturedRemoteClusterServiceColumnsValue);
- Assert.assertEquals(capturedRemoteClusterServiceColumnsValue.size(),3);
+ Assert.assertEquals(3, capturedRemoteClusterServiceColumnsValue.size());
+
+ DBAccessor.DBColumnInfo clusterHandleColumn = capturedClusterHandleColumn.getValue();
+ Assert.assertEquals(UpgradeCatalog240.CLUSTER_HANDLE_COLUMN, clusterHandleColumn.getName());
+ Assert.assertEquals(Long.class, clusterHandleColumn.getType());
verify(dbAccessor);
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/e5474c2f/ambari-views/src/main/java/org/apache/ambari/view/ViewInstanceDefinition.java
----------------------------------------------------------------------
diff --git a/ambari-views/src/main/java/org/apache/ambari/view/ViewInstanceDefinition.java b/ambari-views/src/main/java/org/apache/ambari/view/ViewInstanceDefinition.java
index cea4c88..6f26cac 100644
--- a/ambari-views/src/main/java/org/apache/ambari/view/ViewInstanceDefinition.java
+++ b/ambari-views/src/main/java/org/apache/ambari/view/ViewInstanceDefinition.java
@@ -54,12 +54,12 @@ public interface ViewInstanceDefinition {
public String getDescription();
/**
- * Get the cluster handle associated with this view instance. For a local cluster reference,
- * the cluster handle is simply the unique cluster name.
+ * Get the Id of cluster associated with this view instance. For a local cluster reference,
+ * the cluster handle is simply the unique cluster id.
*
* @return the associated cluster handle; <code>null</code> if no cluster is associated
*/
- public String getClusterHandle();
+ public Long getClusterHandle();
/**
* Get the type of cluster the view instance is attached to
http://git-wip-us.apache.org/repos/asf/ambari/blob/e5474c2f/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/PropertyValidator.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/PropertyValidator.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/PropertyValidator.java
index ae73bc0..e663017 100644
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/PropertyValidator.java
+++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/PropertyValidator.java
@@ -52,7 +52,7 @@ public class PropertyValidator implements Validator {
}
// if associated with cluster, no need to validate associated properties
- String cluster = viewInstanceDefinition.getClusterHandle();
+ Long cluster = viewInstanceDefinition.getClusterHandle();
if (cluster != null) {
return ValidationResult.SUCCESS;
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/e5474c2f/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/PropertyValidator.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/PropertyValidator.java b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/PropertyValidator.java
index d3c9866..cd54690 100644
--- a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/PropertyValidator.java
+++ b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/PropertyValidator.java
@@ -39,7 +39,7 @@ public class PropertyValidator implements Validator {
// no properties
// 2. if associated with cluster, no need to validate associated properties
- String cluster = viewInstanceDefinition.getClusterHandle();
+ Long cluster = viewInstanceDefinition.getClusterHandle();
if (cluster != null) {
return ValidationResult.SUCCESS;
}