new feature: dependency resolver
This commit is contained in:
parent
9551b2422f
commit
252ae5ea56
22 changed files with 271 additions and 45 deletions
|
|
@ -27,9 +27,12 @@ import shutil
|
|||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
import itertools
|
||||
import pprint
|
||||
|
||||
import cdist
|
||||
from cdist import core
|
||||
from cdist import resolver
|
||||
|
||||
|
||||
class ConfigInstall(object):
|
||||
|
|
@ -105,29 +108,12 @@ class ConfigInstall(object):
|
|||
def object_run(self, cdist_object):
|
||||
"""Run gencode and code for an object"""
|
||||
self.log.debug("Trying to run object " + cdist_object.name)
|
||||
if cdist_object.state == core.Object.STATE_RUNNING:
|
||||
# FIXME: resolve dependency circle / show problem source
|
||||
raise cdist.Error("Detected circular dependency in " + cdist_object.name)
|
||||
elif cdist_object.state == core.Object.STATE_DONE:
|
||||
self.log.debug("Ignoring run of already finished object %s", cdist_object)
|
||||
return
|
||||
else:
|
||||
cdist_object.state = core.Object.STATE_RUNNING
|
||||
if cdist_object.state == core.Object.STATE_DONE:
|
||||
# TODO: remove once we are sure that this really never happens.
|
||||
raise cdist.Error("Attempting to run an already finished object: %s", cdist_object)
|
||||
|
||||
cdist_type = cdist_object.type
|
||||
|
||||
for requirement in cdist_object.requirements:
|
||||
self.log.debug("Object %s requires %s", cdist_object, requirement)
|
||||
required_object = cdist_object.object_from_name(requirement)
|
||||
|
||||
# The user may have created dependencies without satisfying them
|
||||
if not required_object.exists:
|
||||
raise cdist.Error(cdist_object.name + " requires non-existing " + required_object.name)
|
||||
else:
|
||||
self.log.debug("Required object %s exists", required_object.name)
|
||||
|
||||
self.object_run(required_object)
|
||||
|
||||
# Generate
|
||||
self.log.info("Generating and executing code for " + cdist_object.name)
|
||||
cdist_object.code_local = self.code.run_gencode_local(cdist_object)
|
||||
|
|
@ -149,7 +135,14 @@ class ConfigInstall(object):
|
|||
def stage_run(self):
|
||||
"""The final (and real) step of deployment"""
|
||||
self.log.info("Generating and executing code")
|
||||
for cdist_object in core.Object.list_objects(self.local.object_path,
|
||||
self.local.type_path):
|
||||
|
||||
objects = core.Object.list_objects(
|
||||
self.local.object_path,
|
||||
self.local.type_path)
|
||||
|
||||
dependency_resolver = resolver.DependencyResolver(objects)
|
||||
self.log.debug(pprint.pformat(dependency_resolver.graph))
|
||||
|
||||
for cdist_object in dependency_resolver:
|
||||
self.log.debug("Run object: %s", cdist_object)
|
||||
self.object_run(cdist_object)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue