Skip to content

Commit

Permalink
changed incremental deploy to have more natural UI (#1007)
Browse files Browse the repository at this point in the history
* changed incremental deploy to have more natural UI
  • Loading branch information
wouterdb committed Mar 8, 2019
1 parent 4275c38 commit d3935eb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 29 deletions.
7 changes: 3 additions & 4 deletions src/inmanta/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1647,7 +1647,7 @@ def mark_done(self):
yield self.update_fields(deployed=True, result=result)

@gen.coroutine
def get_increment(self, negative: bool=False):
def get_increment(self):
"""
Find resources incremented by this version compared to deployment state transitions per resource
Expand Down Expand Up @@ -1740,8 +1740,7 @@ def get_increment(self, negative: bool=False):
if work:
increment.extend(work)

if negative:
return [res["resource_version_id"] for res in not_incrememt]
negative = [res["resource_version_id"] for res in not_incrememt]

# patch up the graph
# 1-include stuff for send-events.
Expand Down Expand Up @@ -1775,7 +1774,7 @@ def get_increment(self, negative: bool=False):
work.extend(provides)
outset.update(provides)

return outset
return set(outset), negative


class Code(BaseDocument):
Expand Down
60 changes: 35 additions & 25 deletions src/inmanta/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
class ResourceActionLogLine(logging.LogRecord):
""" A special log record that is used to report log lines that come from the agent
"""

def __init__(self, logger_name: str, level: str, msg: str, created: datetime.datetime) -> None:
super().__init__(
name=logger_name,
Expand Down Expand Up @@ -805,14 +806,36 @@ def get_resource_increment_for_agent(self, env: Environment, agent: str) -> Dict

version = cm.version

increment_ids = self._increment_cache.get(env.id, None)
if increment_ids is None:
increment = self._increment_cache.get(env.id, None)
if increment is None:
with (yield self._increment_cache_locks[env.id].acquire()):
increment_ids = self._increment_cache.get(env.id)
if increment_ids is None:
increment_ids_list = yield cm.get_increment()
increment_ids = set(increment_ids_list)
self._increment_cache[env.id] = increment_ids
increment = self._increment_cache.get(env.id, None)
if increment is None:
increment = yield cm.get_increment()
self._increment_cache[env.id] = increment

increment_ids, neg_increment = increment

# set already done to deployed
now = datetime.datetime.now()

def on_agent(res):
idr = Id.parse_id(res)
return idr.get_agent_name() == agent

neg_increment = [res_id for res_id in neg_increment if on_agent(res_id)]

logline = {
"level": "INFO",
"msg": "Setting deployed due to known good status",
"timestamp": now.isoformat(),
"args": []
}
self.add_future(self.resource_action_update(env, neg_increment, action_id=uuid.uuid4(),
started=now, finished=now, status=const.ResourceState.deployed,
# does this require a different ResourceAction?
action=const.ResourceAction.deploy, changes={}, messages=[logline],
change=const.Change.nochange, send_events=False, keep_increment_cache=True))

resources = yield data.Resource.get_resources_for_version(env.id, version, agent)

Expand All @@ -833,7 +856,6 @@ def in_requires(req):
deploy_model.append(rv.to_dict())
resource_ids.append(rv.resource_version_id)

now = datetime.datetime.now()
ra = data.ResourceAction(environment=env.id, resource_version_ids=resource_ids, action=const.ResourceAction.pull,
action_id=uuid.uuid4(), started=started, finished=now,
messages=[data.LogLine.log(logging.INFO,
Expand Down Expand Up @@ -1097,20 +1119,6 @@ def release_version(self, env, version_id, push, agent_trigger_method=None):
action=const.ResourceAction.deploy, changes={}, messages=[],
change=const.Change.nochange, send_events=False)

# all resources already deployed
deployed = yield model.get_increment(negative=True)
logline = {
"level": "INFO",
"msg": "Setting deployed due to known good status",
"timestamp": now.isoformat(),
"args": []
}
yield self.resource_action_update(env, deployed, action_id=uuid.uuid4(),
started=now, finished=now, status=const.ResourceState.deployed,
# does this require a different ResourceAction?
action=const.ResourceAction.deploy, changes={}, messages=[logline],
change=const.Change.nochange, send_events=False)

if push:
# fetch all resource in this cm and create a list of distinct agents
agents = yield data.ConfigurationModel.get_agents(env.id, version_id)
Expand Down Expand Up @@ -1315,7 +1323,7 @@ def get_code(self, env, code_id, resource):
@protocol.handle(methods.resource_action_update, env="tid")
@gen.coroutine
def resource_action_update(self, env, resource_ids, action_id, action, started, finished, status, messages, changes,
change, send_events):
change, send_events, keep_increment_cache=False):
resources = yield data.Resource.get_resources(env.id, resource_ids)
if len(resources) == 0 or (len(resources) != len(resource_ids)):
return 404, {"message": "The resources with the given ids do not exist in the given environment. "
Expand Down Expand Up @@ -1379,9 +1387,11 @@ def resource_action_update(self, env, resource_ids, action_id, action, started,
return 500, {"message": "Cannot perform state update without a status."}
for res in resources:
yield res.update_fields(status=status)
self.clear_env_cache(env)
if not keep_increment_cache:
self.clear_env_cache(env)
elif action in const.STATE_UPDATE and done:
self.clear_env_cache(env)
if not keep_increment_cache:
self.clear_env_cache(env)
model_version = None
for res in resources:
yield res.update_fields(last_deploy=finished, status=status)
Expand Down

0 comments on commit d3935eb

Please sign in to comment.