Skip to content

Commit

Permalink
new system updater version
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.hive.pt/hive-main/pt.hive.colony.plugins/trunk@17724 89aa9a68-8201-4d56-8cc5-2cc230aca7a0
  • Loading branch information
joamag committed Nov 10, 2011
1 parent e5f3f09 commit 71bddfe
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 46 deletions.
Expand Up @@ -247,6 +247,24 @@ def rollback_transaction(self, transaction_properties):

return self.colony_packing_installer_deployer.rollback_transaction(transaction_properties)







def add_commit_callback(self, callback, transaction_properties):
return self.colony_packing_installer_deployer.add_commit_callback(callback, transaction_properties)

def add_rollback_callback(self, callback, transaction_properties):
return self.colony_packing_installer_deployer.add_rollback_callback(callback, transaction_properties)







def get_colony_packing_installer_plugin(self):
return self.colony_packing_installer_plugin

Expand Down
Expand Up @@ -280,6 +280,31 @@ def commit_transaction(self, transaction_properties):
# commits the transaction
colony_packing_installer_plugin.commit_transaction(transaction_properties)







def add_commit_callback(self, callback, transaction_properties):
# retrieves the colony packing installer plugin
colony_packing_installer_plugin = self.colony_packing_installer_deployer_plugin.colony_packing_installer_plugin

# adds a commit callback
colony_packing_installer_plugin.add_commit_callback(callback, transaction_properties)

def add_rollback_callback(self, callback, transaction_properties):
# retrieves the colony packing installer plugin
colony_packing_installer_plugin = self.colony_packing_installer_deployer_plugin.colony_packing_installer_plugin

# adds a rollback callback
colony_packing_installer_plugin.add_rollback_callback(callback, transaction_properties)






def rollback_transaction(self, transaction_properties):
"""
"Rollsback" the transaction described by the given
Expand Down
Expand Up @@ -73,6 +73,32 @@ def __str__(self):

return "Missing deployer: %s" % self.message

class UpgradeException(SystemUpdaterException):
"""
The upgrade exception class.
"""

def __init__(self, message):
"""
Constructor of the class.
@type message: String
@param message: The message to be printed.
"""

SystemUpdaterException.__init__(self)
self.message = message

def __str__(self):
"""
Returns the string representation of the class.
@rtype: String
@return: The string representation of the class.
"""

return "Upgrade exception: %s" % self.message

class InvalidPackageException(SystemUpdaterException):
"""
The invalid package exception class.
Expand Down
Expand Up @@ -960,6 +960,9 @@ def __repr__(self):
self.version
)

def get_type(self):
return self.package_type

class PackagePluginDescriptor:
"""
The package plugin descriptor class.
Expand Down Expand Up @@ -1043,6 +1046,9 @@ def __repr__(self):
self.version
)

def get_type(self):
return self.bundle_type

class BundleDependency:
"""
The bundle dependency class.
Expand Down Expand Up @@ -1132,6 +1138,9 @@ def __repr__(self):
self.version
)

def get_type(self):
return self.plugin_type

class PluginDependency:
"""
The plugin dependency class.
Expand Down Expand Up @@ -1221,6 +1230,9 @@ def __repr__(self):
self.version
)

def get_type(self):
return self.container_type

class ContainerDependency:
"""
The container dependency class.
Expand Down
Expand Up @@ -194,9 +194,10 @@ def load_system_updater(self):
self.load_repositories_cache()

def upgrade(self, transaction_properties = None):
# creates the list that holds all the descriptors
# set for upgrading
upgrade_descriptors = []


# iterates over the repository list to creates the list
# of descriptors for upgrading
for repository in self.repository_list:
Expand All @@ -212,45 +213,41 @@ def upgrade(self, transaction_properties = None):
_upgrade_descriptors = [descriptor for descriptor in descriptors if descriptor.status in (NEWER_VERSION_STATUS, DIFFERENT_DIGEST_STATUS)]
upgrade_descriptors.extend(_upgrade_descriptors)

# in case the re are no descriptors to be
# upgraded (no upgrade to be done)
if not upgrade_descriptors:
# returns immediately
return

# TENHO DE FAZER CHECKING QUE TODOS SAO DO MESMO TIPO

#if not lista:
# return

#a = lista[0]

# ASSUMES THAT EVERYONE IS OF THIS TYPE
# OF DEPLOYER (MOST OF THE TIMES IS OK)

# TENHO DE CIRAR UM MAPARA PARA VER O
# ATTRIBUTO DE TIPO ASSOCIADO




# retrieves the bundle type
#bundle_type = bundle_descriptor.bundle_type

# retrieves a deployer for the given plugin type
#plugin_deployer = self._get_deployer_plugin_by_deployer_type(bundle_type)
# retrieves the first descriptor to set the base value
# for the descriptor type
first_descriptor = upgrade_descriptors[0]
first_descriptor_type = first_descriptor.get_type()

# iterates over all the upgrade descriptors
for descriptor in upgrade_descriptors:
descriptor_type = descriptor.get_type()

plugin_deployer = self._get_deployer_plugin_by_deployer_type("colony_packing")
# in case the type of the current descriptor
# does not match the verification one
if descriptor_type == first_descriptor_type:
# raises upgrade exception
raise system_updater_exceptions.UpgradeException("invalid descriptor type")

# retrieves the deployer plugin for the first descriptor type (the
# valid descriptor type)
plugin_deployer = self._get_deployer_plugin_by_deployer_type(first_descriptor_type)

# retrieves the current transaction properties or creates a new transaction
transaction_properties = plugin_deployer.open_transaction(transaction_properties)

try:
# iterates over all the descriptors to be upgraded
# to install the associated object
for descriptor in upgrade_descriptors:
# installs the object represented by the descriptor
self.install_object(descriptor.id, descriptor.version, transaction_properties)

for descriptor in upgrade_descriptors:
descriptor.status = SAME_VERSION_STATUS

self.save_repositories_cache()

# commits the transaction represented in the
# transaction properties
plugin_deployer.commit_transaction(transaction_properties)
Expand All @@ -263,6 +260,8 @@ def upgrade(self, transaction_properties = None):
raise




def update_repositories(self):
"""
Updates the repositories information, flushing it for the
Expand Down Expand Up @@ -383,6 +382,10 @@ def save_repositories_cache(self):
file for the current plugin context.
"""


print "SALVANDO REPOsITORY CAHCE"


# retrieves the plugin manager
plugin_manager = self.system_updater_plugin.manager

Expand Down Expand Up @@ -1200,6 +1203,13 @@ def _install_bundle(self, bundle_id, bundle_version = None, transaction_properti
# deletes the contents file
self._delete_contents_file(contents_file)

# creates the method to handle the descriptor status update
def descriptor_status_update(): bundle_descriptor.status = SAME_VERSION_STATUS

# adds the callback to be called uppon the commit
plugin_deployer.add_commit_callback(descriptor_status_update, transaction_properties)
plugin_deployer.add_commit_callback(self.save_repositories_cache, transaction_properties)

# commits the transaction represented in the
# transaction properties
plugin_deployer.commit_transaction(transaction_properties)
Expand All @@ -1211,9 +1221,6 @@ def _install_bundle(self, bundle_id, bundle_version = None, transaction_properti
# re-raises the exception
raise

# updates the bundle descriptor status
bundle_descriptor.status = SAME_VERSION_STATUS

def _install_plugin(self, plugin_id, plugin_version = None, transaction_properties = None):
"""
Installs the plugin with the given id and version from
Expand Down Expand Up @@ -1267,6 +1274,13 @@ def _install_plugin(self, plugin_id, plugin_version = None, transaction_properti
# deletes the contents file
self._delete_contents_file(contents_file)

# creates the method to handle the descriptor status update
def descriptor_status_update(): plugin_descriptor.status = SAME_VERSION_STATUS

# adds the callback to be called uppon the commit
plugin_deployer.add_commit_callback(descriptor_status_update, transaction_properties)
plugin_deployer.add_commit_callback(self.save_repositories_cache, transaction_properties)

# commits the transaction represented in the
# transaction properties
plugin_deployer.commit_transaction(transaction_properties)
Expand All @@ -1278,9 +1292,6 @@ def _install_plugin(self, plugin_id, plugin_version = None, transaction_properti
# re-raises the exception
raise

# updates the plugin descriptor status
plugin_descriptor.status = SAME_VERSION_STATUS

def _install_container(self, container_id, container_version = None, transaction_properties = None):
"""
Installs the container with the given id and version from
Expand Down Expand Up @@ -1334,6 +1345,13 @@ def _install_container(self, container_id, container_version = None, transaction
# deletes the contents file
self._delete_contents_file(contents_file)

# creates the method to handle the descriptor status update
def descriptor_status_update(): container_descriptor.status = SAME_VERSION_STATUS

# adds the callback to be called uppon the commit
plugin_deployer.add_commit_callback(descriptor_status_update, transaction_properties)
plugin_deployer.add_commit_callback(self.save_repositories_cache, transaction_properties)

# commits the transaction represented in the
# transaction properties
plugin_deployer.commit_transaction(transaction_properties)
Expand All @@ -1345,9 +1363,6 @@ def _install_container(self, container_id, container_version = None, transaction
# re-raises the exception
raise

# updates the container descriptor status
container_descriptor.status = SAME_VERSION_STATUS

def _uninstall_package(self, package_id, package_version = None, transaction_properties = None):
"""
Uninstalls the package with the given id and version
Expand Down Expand Up @@ -1414,6 +1429,13 @@ def _uninstall_bundle(self, bundle_id, bundle_version = None, transaction_proper
# also sent for transaction control
plugin_deployer.undeploy_bundle(bundle_descriptor.id, bundle_descriptor.version, transaction_properties)

# creates the method to handle the descriptor status update
def descriptor_status_update(): bundle_descriptor.status = NOT_INSTALLED_STATUS

# adds the callback to be called uppon the commit
plugin_deployer.add_commit_callback(descriptor_status_update, transaction_properties)
plugin_deployer.add_commit_callback(self.save_repositories_cache, transaction_properties)

# commits the transaction represented in the
# transaction properties
plugin_deployer.commit_transaction(transaction_properties)
Expand All @@ -1425,9 +1447,6 @@ def _uninstall_bundle(self, bundle_id, bundle_version = None, transaction_proper
# re-raises the exception
raise

# updates the bundle descriptor status
bundle_descriptor.status = NOT_INSTALLED_STATUS

def _uninstall_plugin(self, plugin_id, plugin_version = None, transaction_properties = None):
"""
Uninstalls the plugin with the given id and version from
Expand Down Expand Up @@ -1465,6 +1484,13 @@ def _uninstall_plugin(self, plugin_id, plugin_version = None, transaction_proper
# also sent for transaction control
plugin_deployer.undeploy_bundle(plugin_descriptor.id, plugin_descriptor.version, transaction_properties)

# creates the method to handle the descriptor status update
def descriptor_status_update(): plugin_descriptor.status = NOT_INSTALLED_STATUS

# adds the callback to be called uppon the commit
plugin_deployer.add_commit_callback(descriptor_status_update, transaction_properties)
plugin_deployer.add_commit_callback(self.save_repositories_cache, transaction_properties)

# commits the transaction represented in the
# transaction properties
plugin_deployer.commit_transaction(transaction_properties)
Expand All @@ -1476,9 +1502,6 @@ def _uninstall_plugin(self, plugin_id, plugin_version = None, transaction_proper
# re-raises the exception
raise

# updates the plugin descriptor status
plugin_descriptor.status = NOT_INSTALLED_STATUS

def _uninstall_container(self, container_id, container_version = None, transaction_properties = None):
"""
Uninstalls the container with the given id and version from
Expand Down Expand Up @@ -1516,6 +1539,13 @@ def _uninstall_container(self, container_id, container_version = None, transacti
# also sent for transaction control
plugin_deployer.undeploy_bundle(container_descriptor.id, container_descriptor.version, transaction_properties)

# creates the method to handle the descriptor status update
def descriptor_status_update(): container_descriptor.status = NOT_INSTALLED_STATUS

# adds the callback to be called uppon the commit
plugin_deployer.add_commit_callback(descriptor_status_update, transaction_properties)
plugin_deployer.add_commit_callback(self.save_repositories_cache, transaction_properties)

# commits the transaction represented in the
# transaction properties
plugin_deployer.commit_transaction(transaction_properties)
Expand All @@ -1527,9 +1557,6 @@ def _uninstall_container(self, container_id, container_version = None, transacti
# re-raises the exception
raise

# updates the container descriptor status
container_descriptor.status = NOT_INSTALLED_STATUS

def get_object_type(self, object_id, object_version = None):
"""
Retrieves the object type as a string for the given
Expand Down

0 comments on commit 71bddfe

Please sign in to comment.