ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nc...@apache.org
Subject [05/21] ambari git commit: AMBARI-18378. View instance cloning functionality (alexantonenko)
Date Wed, 21 Sep 2016 13:29:27 GMT
AMBARI-18378. View instance cloning functionality (alexantonenko)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/5d31b70c
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/5d31b70c
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/5d31b70c

Branch: refs/heads/branch-dev-patch-upgrade
Commit: 5d31b70cf76789e2744ada68a547f71d87addbb8
Parents: b4f3809
Author: Alex Antonenko <hiveww@gmail.com>
Authored: Mon Sep 19 21:32:18 2016 +0300
Committer: Alex Antonenko <hiveww@gmail.com>
Committed: Mon Sep 19 21:32:18 2016 +0300

----------------------------------------------------------------------
 .../ambariViews/CreateViewInstanceCtrl.js       | 35 ++++++++++++++++-
 .../ui/admin-web/app/scripts/i18n.config.js     |  2 +
 .../ui/admin-web/app/scripts/routes.js          |  5 +++
 .../admin-web/app/views/ambariViews/create.html |  2 +-
 .../app/views/ambariViews/listTable.html        |  3 ++
 .../unit/controllers/CreateViewInstanceCtrl.js  | 40 ++++++++++++++++++++
 6 files changed, 85 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/5d31b70c/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 20bd25c..94b8cc1 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
@@ -24,6 +24,7 @@ angular.module('ambariAdminConsole')
   $scope.constants = {
     props: $t('views.properties')
   };
+  $scope.isClone = $routeParams.instanceId ? true : false;
   var targetUrl = '';
 
   function loadMeta(){
@@ -56,11 +57,42 @@ angular.module('ambariAdminConsole')
         description: '',
         clusterType: 'NONE'
       };
+
+      //if cloning view instance, then get the instance data and populate settings and properties
+      if($scope.isClone) {
+        View.getInstance($routeParams.viewId, $routeParams.version, $routeParams.instanceId)
+        .then(function(instance) {
+          $scope.instanceClone = instance;
+          $scope.instance.version = instance.ViewInstanceInfo.version;
+          $scope.version =  instance.ViewInstanceInfo.version;
+          $scope.instance.instance_name = instance.ViewInstanceInfo.instance_name + $t('common.copy');
+          $scope.instance.label = instance.ViewInstanceInfo.label + $t('common.copy');
+          $scope.instance.visible = instance.ViewInstanceInfo.visible;
+          $scope.instance.description = instance.ViewInstanceInfo.description;
+          $scope.instance.clusterType=instance.ViewInstanceInfo.cluster_type;
+          
+          initConfigurations(parameters);
+        })
+        .catch(function(data) {
+          Alert.error($t('views.alerts.cannotLoadInstanceInfo'), data.data.message);
+        });
+      }
+
       loadClusters();
       loadRemoteClusters();
+
     });
   }
 
+   function initConfigurations(parameters) {
+      var configuration = angular.copy($scope.instanceClone.ViewInstanceInfo.properties);
+
+      //iterate through the view parameters and get the values from the instance being cloned
+      for (var i = 0; i < parameters.length; i++) {
+        parameters[i].value = configuration[parameters[i].name];
+        parameters[i].clusterConfig = !!parameters[i].clusterConfig;
+      }
+    }
 
   $scope.$watch(function(scope) {
     return scope.version;
@@ -111,7 +143,8 @@ angular.module('ambariAdminConsole')
              })
            });
            $scope.noLocalClusterAvailible = false;
-           if($scope.clusterConfigurable){
+           //do not set to default Local Cluster configuration when cloning instance
+           if($scope.clusterConfigurable && !$scope.isClone){
              $scope.instance.clusterType = "LOCAL_AMBARI";
            }
          }else{

http://git-wip-us.apache.org/repos/asf/ambari/blob/5d31b70c/ambari-admin/src/main/resources/ui/admin-web/app/scripts/i18n.config.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/i18n.config.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/i18n.config.js
index bc16f0e..af22d7f 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/i18n.config.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/i18n.config.js
@@ -95,6 +95,7 @@ angular.module('ambariAdminConsole')
       'important': 'Important',
       'undo': 'Undo',
       'fromGroupMark': '(from group)',
+      'copy': '_Copy',
 
       'clusterNameChangeConfirmation': {
         'title': 'Confirm Cluster Name Change',
@@ -198,6 +199,7 @@ angular.module('ambariAdminConsole')
       'instance': 'Instance',
       'viewInstance': 'View Instance',
       'create': 'Create Instance',
+      'clone': 'Clone Instance',
       'createViewInstance': 'Create View Instance',
       'edit': 'Edit',
       'viewName': 'View Name',

http://git-wip-us.apache.org/repos/asf/ambari/blob/5d31b70c/ambari-admin/src/main/resources/ui/admin-web/app/scripts/routes.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/routes.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/routes.js
index 239e39e..a1ca59c 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/routes.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/routes.js
@@ -108,6 +108,11 @@ angular.module('ambariAdminConsole')
       templateUrl: 'views/urls/edit.html',
       controller: 'ViewUrlEditCtrl'
     },
+    clone: {
+      url: '/views/:viewId/versions/:version/instances/:instanceId/clone',
+      templateUrl: 'views/ambariViews/create.html',
+      controller: 'CreateViewInstanceCtrl'
+    },
     edit: {
       url: '/views/:viewId/versions/:version/instances/:instanceId/edit',
       templateUrl: 'views/ambariViews/edit.html',

http://git-wip-us.apache.org/repos/asf/ambari/blob/5d31b70c/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 924885f..25f1487 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
@@ -17,7 +17,7 @@
 -->
 <ol class="breadcrumb">
   <li><a href="#/views">{{'common.views' | translate}}</a></li>
-  <li class="active">{{'views.create' | translate}}</li>
+  <li class="active"> {{isClone ? 'views.clone' : 'views.create' | translate}}</li>
 </ol>
 <hr>
 <form class="form-horizontal create-view-form" role="form" name="form.instanceCreateForm"
novalidate>

http://git-wip-us.apache.org/repos/asf/ambari/blob/5d31b70c/ambari-admin/src/main/resources/ui/admin-web/app/views/ambariViews/listTable.html
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/views/ambariViews/listTable.html
b/ambari-admin/src/main/resources/ui/admin-web/app/views/ambariViews/listTable.html
index bc441cd..e03f035 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/views/ambariViews/listTable.html
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/views/ambariViews/listTable.html
@@ -78,6 +78,9 @@
                     <td class="col-sm-5">{{instance.ViewInstanceInfo.version}}</td>
                     <td class="col-sm-5 " ><div class="description-column" tooltip="{{instance.ViewInstanceInfo.description}}">{{instance.ViewInstanceInfo.description
|| 'No description'}}</div>
                     </td>
+                    <td class="col-sm-1">
+                        <a class="instance-link ng-scope ng-binding" href="#/views/{{view.view_name}}/versions/{{instance.ViewInstanceInfo.version}}/instances/{{instance.ViewInstanceInfo.instance_name}}/clone"><i
class="fa fa-copy"></i></a>
+                    </td>
                 </tr>
                 </tbody>
                 <tfoot>

http://git-wip-us.apache.org/repos/asf/ambari/blob/5d31b70c/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 117021e..f8ccc24 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
@@ -31,6 +31,7 @@ describe('#CreateViewInstanceCtrl', function () {
   beforeEach(inject(function (_$httpBackend_, $rootScope, $controller, _View_, $q) {
     View = _View_;
     spyOn(View, 'createInstance').andReturn($q.defer().promise);
+    spyOn(View, 'getInstance').andReturn($q.defer().promise);
 
     $httpBackend = _$httpBackend_;
     $httpBackend.whenGET(/\/api\/v1\/views\/TestView\?.+/).respond(200, {
@@ -66,6 +67,7 @@ describe('#CreateViewInstanceCtrl', function () {
     };
     scope.instance = {};
     scope.version = '1.0.0';
+    scope.isClone=false;
     $httpBackend.expectGET('template/modal/backdrop.html');
     $httpBackend.expectGET('template/modal/window.html');
     $httpBackend.whenGET(/\/api\/v1\/clusters\?fields=Clusters\/cluster_id&_=\d+/).respond(200,
{
@@ -91,5 +93,43 @@ describe('#CreateViewInstanceCtrl', function () {
     scope.$digest();
     $httpBackend.flush();
     chai.expect(scope.view.ViewVersionInfo.parameters[0].value).to.equal('d');
+    expect(View.getInstance).not.toHaveBeenCalled();
   });
+
+  it('before cloning view instance confirm that View.getInstance is called', function ()
{
+    scope.form = {
+      instanceCreateForm: {
+        $dirty: true
+      }
+    };
+    scope.instance = {};
+    scope.version = '1.0.0';
+    scope.isClone=true;
+    $httpBackend.expectGET('template/modal/backdrop.html');
+    $httpBackend.expectGET('template/modal/window.html');
+    $httpBackend.whenGET(/\/api\/v1\/clusters\?fields=Clusters\/cluster_id&_=\d+/).respond(200,
{
+      "items" : [
+        {
+          "Clusters" : {
+            "cluster_name" : "c1",
+            "version" : "HDP-2.2"
+          }
+        }
+      ]
+    });
+    $httpBackend.whenGET(/\/api\/v1\/remoteclusters\?fields=ClusterInfo\/services,ClusterInfo\/cluster_id&_=\d+/).respond(200,
{
+      "items" : [
+         {
+           "ClusterInfo" : {
+            "name" : "c1",
+            "services" : ["HDFS"]
+          }
+        }
+      ]
+    });
+    scope.$digest();
+    $httpBackend.flush();
+    expect(View.getInstance).toHaveBeenCalled(); 
+  });
+
 });


Mime
View raw message