Quellcode durchsuchen

AMBARI-855. Create the skeleton for a custom data adapter in Ambari Web. (yusaku)

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/branches/AMBARI-666@1397901 13f79535-47bb-0310-9956-ffa450edef68
Yusaku Sako vor 12 Jahren
Ursprung
Commit
15cf212b05
3 geänderte Dateien mit 81 neuen und 30 gelöschten Zeilen
  1. 3 0
      AMBARI-666-CHANGES.txt
  2. 2 30
      ambari-web/app/app.js
  3. 76 0
      ambari-web/app/data_adapter.js

+ 3 - 0
AMBARI-666-CHANGES.txt

@@ -12,6 +12,9 @@ AMBARI-666 branch (unreleased changes)
 
   NEW FEATURES
 
+  AMBARI-855. Create the skeleton for a custom data adapter in Ambari Web.
+  (yusaku)
+
   AMBARI-854. Serve ambari-web from jetty. (Jaimin Jely via yusaku)
  
   AMBARI-850. Flatten ExecutionCommand structure. (jitendra)

+ 2 - 30
ambari-web/app/app.js

@@ -25,36 +25,8 @@ module.exports = Em.Application.create({
   store: DS.Store.create({
     revision: 4,
     adapter: DS.FixtureAdapter.create()
-    //adapter: DS.RESTAdapter.create({
-    // bulkCommit: false
-    // namespace: '/api/v1'
-    // })
-    /*
-     adapter: DS.Adapter.create({
-     find: function(store, type, id) {
-     //var url = type.url;
-     //url = url.fmt(id);
-
-     if (type.toString() === 'App.Cluster') {
-     store.load(type, { id: id, hosts: [ { hostname: 'host1' }, { hostname: 'host2' } ], services: []});
-     }
-     debugger;
-
-     //jQuery.getJSON(url, function(data) {
-     // data is a Hash of key/value pairs. If your server returns a
-     // root, simply do something like:
-     // store.load(type, id, data.person)
-     //    store.load(type, id, data);
-     //});
-     },
-     findAll: function(store, type, id) {
-     debugger;
-     },
-     findMany: function(store, type, id) {
-     debugger;
-     }
-     })
-     */
+    // comment out the line above and uncomment the line below for backend integration
+    // adapter: require('data_adapter')
   })
 
 });

+ 76 - 0
ambari-web/app/data_adapter.js

@@ -0,0 +1,76 @@
+/**
+ * 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.
+ */
+
+/**
+ * The data adapter that performs data exchange with Ambari Server's REST interface and other backend servers.
+ *
+ * To allow for mixture of mock data via Fixture and actual data exchange with backend servers while we iteratively
+ * integrate, we are composing an instance of the fixture adapter.
+ * The idea is to conditionally use the fixture adapter for model types that have not been integrated yet,
+ * and to use a custom, modified implementation of DS.RESTAdapter for model types that have been integrated.
+ */
+var fixtureAdapter = DS.FixtureAdapter.create();
+
+var adapter = DS.RESTAdapter.extend({
+  find: function(store, type, id) {
+    /*
+     var url = type.url;
+     url = url.fmt(id);
+
+     if (type.toString() === 'App.Cluster') {
+     store.load(type, { id: id, hosts: [ { hostname: 'host1' }, { hostname: 'host2' } ], services: []});
+     }
+
+     jQuery.getJSON(url, function(data) {
+     // data is a Hash of key/value pairs. If your server returns a
+     // root, simply do something like:
+     // store.load(type, id, data.person)
+     store.load(type, id, data);
+     });
+     */
+    // return this._super(store, type, id);
+    return fixtureAdapter.find(store, type, id);
+  },
+  findMany: function(store, type, id) {
+    // return this._super(store, type, id);
+    return fixtureAdapter.findMany(store, type, id);
+  },
+  findAll: function(store, type, id) {
+    // return this._super(store, type, id);
+    return fixtureAdapter.findAll(store, type, id);
+  },
+  findQuery: function(store, type, id) {
+    // return this._super(store, type, id);
+    return fixtureAdapter.findQuery(store, type, id);
+  },
+  createRecord: function(store, type, record) {
+    //return this._super(store, type, id);
+    return fixtureAdapter.createRecord(store, type, record);
+  },
+  updateRecord: function(store, type, record) {
+    //return this._super(store, type, id);
+    return fixtureAdapter.updateRecord(store, type, record);
+  },
+  deleteRecord: function(store, type, record) {
+    //return this._super(store, type, id);
+    return fixtureAdapter.deleteRecord(store, type, record);
+  }
+
+});
+
+module.exports = adapter.create();