You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by lu...@apache.org on 2012/09/25 01:52:48 UTC

[2/10] git commit: CIMI: rename entityMetadata to resourceMetadata

CIMI: rename entityMetadata to resourceMetadata


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

Branch: refs/heads/master
Commit: dc7053a444ee43857da8b1c1dfad5687b920a689
Parents: bb9e4c5
Author: David Lutterkort <lu...@redhat.com>
Authored: Tue Sep 18 17:37:42 2012 -0700
Committer: David Lutterkort <lu...@redhat.com>
Committed: Mon Sep 24 16:52:15 2012 -0700

----------------------------------------------------------------------
 server/lib/cimi/collections/entity_metadata.rb   |   46 ---------
 server/lib/cimi/collections/resource_metadata.rb |   46 +++++++++
 server/lib/cimi/models.rb                        |    3 +-
 server/lib/cimi/models/cloud_entry_point.rb      |   11 +--
 server/lib/cimi/models/entity_metadata.rb        |   83 ----------------
 server/lib/cimi/models/machine.rb                |    6 +-
 server/lib/cimi/models/resource_metadata.rb      |   85 +++++++++++++++++
 server/tests/cimi/collections/url_helper_test.rb |    8 +-
 8 files changed, 142 insertions(+), 146 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/dc7053a4/server/lib/cimi/collections/entity_metadata.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/entity_metadata.rb b/server/lib/cimi/collections/entity_metadata.rb
deleted file mode 100644
index 0bca4e3..0000000
--- a/server/lib/cimi/collections/entity_metadata.rb
+++ /dev/null
@@ -1,46 +0,0 @@
-# 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.
-
-module CIMI::Collections
-  class EntityMetadata < Base
-
-    collection :entity_metadata do
-
-      operation :index do
-        description "List all entity metadata defined for this provider"
-        control do
-          entity_metadata = CIMI::Model::EntityMetadataCollection.default(self)
-          respond_to do |format|
-            format.xml{entity_metadata.to_xml}
-            format.json{entity_metadata.to_json}
-          end
-        end
-      end
-
-      operation :show do
-        description "Get the entity metadata for a specific collection"
-        control do
-          entity_metadata = EntityMetadata.find(params[:id], self)
-          respond_to do |format|
-            format.xml{entity_metadata.to_xml}
-            format.json{entity_metadata.to_json}
-          end
-        end
-      end
-
-    end
-
-  end
-end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/dc7053a4/server/lib/cimi/collections/resource_metadata.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/resource_metadata.rb b/server/lib/cimi/collections/resource_metadata.rb
new file mode 100644
index 0000000..302f868
--- /dev/null
+++ b/server/lib/cimi/collections/resource_metadata.rb
@@ -0,0 +1,46 @@
+# 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.
+
+module CIMI::Collections
+  class ResourceMetadata < Base
+
+    collection :resource_metadata do
+
+      operation :index do
+        description "List all resource metadata defined for this provider"
+        control do
+          resource_metadata = CIMI::Model::ResourceMetadataCollection.default(self)
+          respond_to do |format|
+            format.xml{resource_metadata.to_xml}
+            format.json{resource_metadata.to_json}
+          end
+        end
+      end
+
+      operation :show do
+        description "Get the resource metadata for a specific collection"
+        control do
+          resource_metadata = ResourceMetadata.find(params[:id], self)
+          respond_to do |format|
+            format.xml{resource_metadata.to_xml}
+            format.json{resource_metadata.to_json}
+          end
+        end
+      end
+
+    end
+
+  end
+end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/dc7053a4/server/lib/cimi/models.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models.rb b/server/lib/cimi/models.rb
index a81abff..e0a9544 100644
--- a/server/lib/cimi/models.rb
+++ b/server/lib/cimi/models.rb
@@ -23,9 +23,8 @@ require_relative './models/schema'
 require_relative './models/base'
 require_relative './models/collection'
 require_relative './models/errors'
-require_relative './models/entity_metadata'
-require_relative './models/entity_metadata_collection'
 require_relative './models/cloud_entry_point'
+require_relative './models/resource_metadata'
 require_relative './models/machine_template'
 require_relative './models/machine_image'
 require_relative './models/machine_configuration'

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/dc7053a4/server/lib/cimi/models/cloud_entry_point.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/cloud_entry_point.rb b/server/lib/cimi/models/cloud_entry_point.rb
index f623798..38b5a88 100644
--- a/server/lib/cimi/models/cloud_entry_point.rb
+++ b/server/lib/cimi/models/cloud_entry_point.rb
@@ -17,18 +17,13 @@ class CIMI::Model::CloudEntryPoint < CIMI::Model::Base
 
   text  :base_uri, :xml_name => "baseURI", :json_name => "baseURI"
 
-  array :entity_metadata do
-    scalar :href
-  end
-
   def self.create(context)
     self.new(entities(context).merge({
       :name => context.driver.name,
       :description => "Cloud Entry Point for the Deltacloud #{context.driver.name} driver",
       :id => context.cloudEntryPoint_url,
       :base_uri => context.base_uri,
-      :created => Time.now,
-      :entity_metadata => CIMI::Model::EntityMetadata.all_uri(context)
+      :created => Time.now
     }))
   end
 
@@ -46,8 +41,8 @@ class CIMI::Model::CloudEntryPoint < CIMI::Model::Base
 
   private
 
-  def self.href_defined?(entity)
-    true if schema.attribute_names.include? entity.underscore
+  def self.href_defined?(resource)
+    true if schema.attribute_names.include? resource.underscore
   end
 
 end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/dc7053a4/server/lib/cimi/models/entity_metadata.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/entity_metadata.rb b/server/lib/cimi/models/entity_metadata.rb
deleted file mode 100644
index 2379e7d..0000000
--- a/server/lib/cimi/models/entity_metadata.rb
+++ /dev/null
@@ -1,83 +0,0 @@
-# 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.
-
-
-class CIMI::Model::EntityMetadata < CIMI::Model::Base
-
-  text :type_uri
-
-  array :attributes do
-    scalar :name
-    scalar :namespace
-    scalar :type
-    scalar :required
-    scalar :constraints
-  end
-
-  array :operations do
-    scalar :name
-    scalar :uri
-    scalar :description
-    scalar :method
-    scalar :input_message
-    scalar :output_message
-  end
-
-  def self.find(id, context)
-    entity_metadata = []
-    if id == :all
-      CIMI::Model.root_entities.each do |entity_class|
-        entity_metadata << entity_class.create_entity_metadata(context) if entity_class.respond_to?(:create_entity_metadata)
-      end
-      return entity_metadata
-    else
-      entity_class = CIMI::Model.const_get("#{id.camelize}")
-      if entity_class.respond_to?(:create_entity_metadata)
-        entity_class.create_entity_metadata(context)
-      end
-    end
-  end
-
-  def self.metadata_from_deltacloud_features(cimi_entity, dcloud_entity, context)
-    deltacloud_features = context.driver.class.features[dcloud_entity]
-    metadata_attributes = deltacloud_features.map{|f| attributes_from_feature(f)}
-    from_feature(cimi_entity, context, metadata_attributes.flatten!)
-  end
-
-  def includes_attribute?(attribute)
-    self.attributes.any?{|attr| attr[:name] == attribute}
-  end
-
-  private
-
-  def self.attributes_from_feature(feature)
-    feature = CIMI::FakeCollection.feature(feature)
-    feature.operations.first.params_array.map do |p|
-      {
-        :name=> p.name,
-        :type=> "xs:string",
-        :required=> p.required? ? "true" : "false",
-        :constraints=> (feature.constraints.empty? ? (feature.description.nil? ? "" : feature.description): feature.constraints)
-      }
-    end
-  end
-
-  def self.from_feature(cimi_entity, context, metadata_attributes)
-    self.new(:name => cimi_entity, :uri=>"#{context.entity_metadata_url}/#{cimi_entity.underscore}",
-             :type_uri=> context.send("#{cimi_entity.pluralize.underscore}_url"),
-             :attributes => metadata_attributes)
-  end
-
-end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/dc7053a4/server/lib/cimi/models/machine.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/machine.rb b/server/lib/cimi/models/machine.rb
index 41b6b6b..da67eb7 100644
--- a/server/lib/cimi/models/machine.rb
+++ b/server/lib/cimi/models/machine.rb
@@ -90,9 +90,9 @@ class CIMI::Model::Machine < CIMI::Model::Base
     context.driver.destroy_instance(context.credentials, id)
   end
 
-  def self.create_entity_metadata(context)
-    cimi_entity = self.name.split("::").last
-    metadata = CIMI::Model::EntityMetadata.metadata_from_deltacloud_features(cimi_entity, :instances, context)
+  def self.create_resource_metadata(context)
+    cimi_resource = self.name.split("::").last
+    metadata = CIMI::Model::ResourceMetadata.metadata_from_deltacloud_features(cimi_resource, :instances, context)
     unless metadata.includes_attribute?(:name)
       metadata.attributes << {:name=>"name", :required=>"false",
                    :constraints=>"Determined by the cloud provider", :type=>"xs:string"}

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/dc7053a4/server/lib/cimi/models/resource_metadata.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/resource_metadata.rb b/server/lib/cimi/models/resource_metadata.rb
new file mode 100644
index 0000000..5e62061
--- /dev/null
+++ b/server/lib/cimi/models/resource_metadata.rb
@@ -0,0 +1,85 @@
+# 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.
+
+
+class CIMI::Model::ResourceMetadata < CIMI::Model::Base
+
+  acts_as_root_entity
+
+  text :type_uri
+
+  array :attributes do
+    scalar :name
+    scalar :namespace
+    scalar :type
+    scalar :required
+    scalar :constraints
+  end
+
+  array :operations do
+    scalar :name
+    scalar :uri
+    scalar :description
+    scalar :method
+    scalar :input_message
+    scalar :output_message
+  end
+
+  def self.find(id, context)
+    resource_metadata = []
+    if id == :all
+      CIMI::Model.root_entities.each do |resource_class|
+        resource_metadata << resource_class.create_resource_metadata(context) if resource_class.respond_to?(:create_resource_metadata)
+      end
+      return resource_metadata
+    else
+      resource_class = CIMI::Model.const_get("#{id.camelize}")
+      if resource_class.respond_to?(:create_resource_metadata)
+        resource_class.create_resource_metadata(context)
+      end
+    end
+  end
+
+  def self.metadata_from_deltacloud_features(cimi_resource, dcloud_resource, context)
+    deltacloud_features = context.driver.class.features[dcloud_resource]
+    metadata_attributes = deltacloud_features.map{|f| attributes_from_feature(f)}
+    from_feature(cimi_resource, context, metadata_attributes.flatten!)
+  end
+
+  def includes_attribute?(attribute)
+    self.attributes.any?{|attr| attr[:name] == attribute}
+  end
+
+  private
+
+  def self.attributes_from_feature(feature)
+    feature = CIMI::FakeCollection.feature(feature)
+    feature.operations.first.params_array.map do |p|
+      {
+        :name=> p.name,
+        :type=> "xs:string",
+        :required=> p.required? ? "true" : "false",
+        :constraints=> (feature.constraints.empty? ? (feature.description.nil? ? "" : feature.description): feature.constraints)
+      }
+    end
+  end
+
+  def self.from_feature(cimi_resource, context, metadata_attributes)
+    self.new(:name => cimi_resource, :uri=>"#{context.resource_metadata_url}/#{cimi_resource.underscore}",
+             :type_uri=> context.send("#{cimi_resource.pluralize.underscore}_url"),
+             :attributes => metadata_attributes)
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/dc7053a4/server/tests/cimi/collections/url_helper_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/cimi/collections/url_helper_test.rb b/server/tests/cimi/collections/url_helper_test.rb
index eed7ac2..d6a5971 100644
--- a/server/tests/cimi/collections/url_helper_test.rb
+++ b/server/tests/cimi/collections/url_helper_test.rb
@@ -22,10 +22,10 @@ describe CIMI do
     @api.machines_url(:format => 'json').must_equal '/cimi/machines?format=json'
   end
 
-  it 'generate proper url for EntityMetadata' do
-    @api.entity_metadata_url.must_equal '/cimi/entity_metadata'
-    @api.entity_metadata_url('123').must_equal '/cimi/entity_metadata/123'
-    @api.entity_metadata_url(:format => 'json').must_equal '/cimi/entity_metadata/?format=json'
+  it 'generate proper url for ResourceMetadata' do
+    @api.resource_metadata_url.must_equal '/cimi/resource_metadata'
+    @api.resource_metadata_url('123').must_equal '/cimi/resource_metadata/123'
+    @api.resource_metadata_url(:format => 'json').must_equal '/cimi/resource_metadata/?format=json'
   end
 
 end