-
-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add abstract orchestration modeling #45
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
875d14d
Add abstract orchestration modeling
chrisroberts 4a2e5cb
Remove #find_by_id methods and aliases. Update with #get where required.
chrisroberts 3c070a9
Fix exception name
chrisroberts ab33ff9
Search by name or id
chrisroberts f5abfc2
Load orchestration specific errors
chrisroberts ad8e6c2
Add customized errors
chrisroberts f667f9b
Fill in method documentation for orchestration model abstracts
chrisroberts 8a73bfa
Add note on events abstract about collection sorting
chrisroberts bf00b96
Define required methods
chrisroberts File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require 'fog/core/errors' | ||
|
||
module Fog | ||
module Errors | ||
|
||
# Orchestration related errors | ||
class OrchestrationError < Error | ||
|
||
# Invalid template error | ||
class InvalidTemplate < OrchestrationError | ||
end | ||
|
||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require 'fog/core/model' | ||
|
||
module Fog | ||
module Orchestration | ||
# Stack event | ||
class Event < Fog::Model | ||
|
||
# Load common attributes into subclass | ||
# | ||
# @param klass [Class] | ||
def self.inherited(klass) | ||
klass.class_eval do | ||
identity :id | ||
|
||
attribute :id | ||
attribute :event_time | ||
attribute :links | ||
attribute :logical_resource_id | ||
attribute :physical_resource_id | ||
attribute :resource_name | ||
attribute :resource_status | ||
attribute :resource_status_reason | ||
end | ||
end | ||
|
||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require 'fog/core/collection' | ||
|
||
module Fog | ||
module Orchestration | ||
# Stack events | ||
class Events < Fog::Collection | ||
|
||
# @return [Fog::Orchestration::Stack] | ||
attr_accessor :stack | ||
|
||
# Load all events for stack | ||
# | ||
# @param stack [Fog::Orchestration::Stack] | ||
# @return [self] | ||
# @note events should be ordered by timestamp | ||
# in ascending order | ||
def all(stack=nil) | ||
raise NotImplementedError | ||
end | ||
|
||
# Fetch event by ID | ||
# | ||
# @param id [String] | ||
# @return [Fog::Orchestration::Event] | ||
def get(id) | ||
self.find {|event| event.id == id} | ||
end | ||
|
||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'fog/core/model' | ||
|
||
module Fog | ||
module Orchestration | ||
# Stack output | ||
class Output < Fog::Model | ||
|
||
# Load common attributes into subclass | ||
# | ||
# @param klass [Class] | ||
def self.inherited(klass) | ||
klass.class_eval do | ||
identity :key | ||
|
||
attribute :key | ||
attribute :value | ||
attribute :description | ||
end | ||
end | ||
|
||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require 'fog/core/collection' | ||
|
||
module Fog | ||
module Orchestration | ||
# Stack outputs | ||
class Outputs < Fog::Collection | ||
|
||
# @return [Fog::Orchestration::Stack] | ||
attr_accessor :stack | ||
|
||
# Load all outputs for stack | ||
# | ||
# @param stack [Fog::Orchestration::Stack] | ||
# @return [self] | ||
def all(stack=nil) | ||
raise NotImplemented | ||
end | ||
|
||
# Fetch output by key | ||
# | ||
# @param key [String] | ||
# @return [Fog::Orchestration::Output] | ||
def get(key) | ||
self.find {|output| output.key == key} | ||
end | ||
|
||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require 'fog/core/model' | ||
|
||
module Fog | ||
module Orchestration | ||
# Stack resource | ||
class Resource < Fog::Model | ||
|
||
# Load common attributes into subclass | ||
# | ||
# @param klass [Class] | ||
def self.inherited(klass) | ||
klass.class_eval do | ||
identity :physical_resource_id | ||
|
||
attribute :resource_name | ||
attribute :links | ||
attribute :logical_resource_id | ||
attribute :physical_resource_id | ||
attribute :resource_type | ||
attribute :resource_status | ||
attribute :resource_status_reason | ||
attribute :updated_time | ||
end | ||
end | ||
|
||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require 'fog/core/collection' | ||
|
||
module Fog | ||
module Orchestration | ||
# Stack resources | ||
class Resources < Fog::Collection | ||
|
||
# @return [Fog::Orchestration::Stack] | ||
attr_accessor :stack | ||
|
||
# Load all resources for stack | ||
# | ||
# @param stack [Fog::Orchestration::Stack] | ||
# @return [self] | ||
def all(stack=nil) | ||
raise NotImplemented | ||
end | ||
|
||
# Fetch resource by physical ID | ||
# | ||
# @param id [String] | ||
# @return [Fog::Orchestration::Resource] | ||
def find_by_physical_id(id) | ||
self.find {|resource| resource.physical_resource_id == id} | ||
end | ||
alias_method :get, :find_by_physical_id | ||
|
||
# Fetch resource by logical ID | ||
# | ||
# @param id [String] | ||
# @return [Fog::Orchestration::Resource] | ||
def find_by_logical_id(id) | ||
self.find {|resource| resource.logical_resource_id == id} | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
require 'fog/core/model' | ||
|
||
module Fog | ||
module Orchestration | ||
# Stack model | ||
class Stack < Fog::Model | ||
|
||
class << self | ||
|
||
# Register resources collection class | ||
# | ||
# @param model_klass [Class] | ||
# @return [Class] | ||
def resources(model_klass=nil) | ||
if(model_klass) | ||
@resources_model = model_klass | ||
end | ||
@resources_model | ||
end | ||
|
||
# Register events collection class | ||
# | ||
# @param model_klass [Class] | ||
# @return [Class] | ||
def events(model_klass=nil) | ||
if(model_klass) | ||
@events_model = model_klass | ||
end | ||
@events_model | ||
end | ||
|
||
# Register outputs collection class | ||
# | ||
# @param model_klass [Class] | ||
# @return [Class] | ||
def outputs(model_klass=nil) | ||
if(model_klass) | ||
@outputs_model = model_klass | ||
end | ||
@outputs_model | ||
end | ||
|
||
# Load common attributes into subclass | ||
# | ||
# @param klass [Class] | ||
def inherited(klass) | ||
klass.class_eval do | ||
identity :id | ||
|
||
attribute :stack_name | ||
attribute :stack_status | ||
attribute :stack_status_reason | ||
attribute :creation_time | ||
attribute :updated_time | ||
attribute :id | ||
|
||
attribute :template_url | ||
attribute :template | ||
attribute :parameters | ||
attribute :timeout_in_minutes | ||
attribute :disable_rollback | ||
attribute :capabilities | ||
attribute :notification_topics | ||
attribute :template_description | ||
end | ||
end | ||
|
||
end | ||
|
||
# Save the stack | ||
# | ||
# @return [self] | ||
def save | ||
requires :stack_name | ||
identity ? update : create | ||
end | ||
|
||
# Create the stack | ||
# | ||
# @return [self] | ||
def create | ||
raise NotImlemented | ||
end | ||
|
||
# Update the stack | ||
# | ||
# @return [self] | ||
def update | ||
raise NotImlemented | ||
end | ||
|
||
# Destroy the stack | ||
# | ||
# @return [self] | ||
def destroy | ||
raise NotImlemented | ||
end | ||
|
||
# @return [Fog::Orchestration::Resources] | ||
def resources | ||
if(self.class.resources) | ||
self.class.resources.new(:service => service).all(self) | ||
else | ||
raise NotImplemented | ||
end | ||
end | ||
|
||
# @return [Fog::Orchestration::Events] | ||
def events | ||
if(self.class.events) | ||
self.class.events.new(:service => service).all(self) | ||
else | ||
raise NotImplemented | ||
end | ||
end | ||
|
||
# @return [Fog::Orchestration::Outputs] | ||
def outputs | ||
if(self.class.outputs) | ||
self.class.outputs.new(:service => service).all(self) | ||
else | ||
raise NotImplemented | ||
end | ||
end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @geemus @tokengeek This PR has added a DSL to help facilitate adding a common abstraction for providers while keeping the high level logic at more generic level. You can see the concrete implementation in fog/fog#2971. What are your thoughts on this approach? |
||
# Validate the stack template | ||
# | ||
# @return [TrueClass] | ||
# @raises [Fog::Errors::OrchestationError::InvalidTemplate] | ||
def validate | ||
raise NotImplemented | ||
end | ||
|
||
end | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a very good question!
I dug around in an older version of fog before fog-core was split out and found this commit.
Glancing through the code, I don't see a reason why you would want networking. My guess is that this was a copy/paste fail, but let's leave this in here for now and we can create a separate PR at a later date to remove this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍