Skip to content
Snippets Groups Projects
Commit becc7051 authored by garciadeblas's avatar garciadeblas
Browse files

Move cluster, KSU, profile and OKA operation initialization logic to LCM


Change-Id: I57cef96c6e8c99b7278ee9969580e28f40d0c8a7
Signed-off-by: default avatargarciadeblas <gerardo.garciadeblas@telefonica.com>
parent 99122b88
No related branches found
No related tags found
No related merge requests found
Pipeline #17561 passed with warnings with stage
in 2 seconds
......@@ -411,14 +411,8 @@ class BaseTopic:
return None
@staticmethod
def format_on_operation(
content, operation_type, operation_params=None, launch_workflow=True
):
if content["current_operation"] is None:
op_id = str(uuid4())
content["current_operation"] = op_id
else:
op_id = content["current_operation"]
def format_on_operation(content, operation_type, operation_params=None):
op_id = str(uuid4())
now = time()
if "operationHistory" not in content:
content["operationHistory"] = []
......@@ -429,16 +423,10 @@ class BaseTopic:
operation["result"] = None
operation["creationDate"] = now
operation["endDate"] = None
if launch_workflow:
operation["workflowState"] = "PROCESSING"
operation["resourceState"] = "NOT_READY"
operation["operationState"] = "IN_PROGRESS"
operation["gitOperationInfo"] = None
operation["operationParams"] = operation_params
else:
operation["workflowState"] = operation["resourceState"] = operation[
"operationState"
] = operation["gitOperationInfo"] = operation["operationParams"] = None
operation["workflowState"] = operation["resourceState"] = operation[
"operationState"
] = operation["gitOperationInfo"] = None
operation["operationParams"] = operation_params
content["operationHistory"].append(operation)
return op_id
......
......@@ -190,6 +190,11 @@ class K8sTopic(BaseTopic):
self.resource_topic = ResourceTopic(db, fs, msg, auth)
self.app_topic = AppTopic(db, fs, msg, auth)
@staticmethod
def format_on_new(content, project_id=None, make_public=False):
BaseTopic.format_on_new(content, project_id=project_id, make_public=make_public)
content["current_operation"] = None
def new(self, rollback, session, indata=None, kwargs=None, headers=None):
"""
Creates a new k8scluster into database.
......@@ -222,7 +227,6 @@ class K8sTopic(BaseTopic):
self.format_on_new(
cls_create, session["project_id"], make_public=session["public"]
)
cls_create["current_operation"] = None
op_id = self.format_on_operation(
cls_create,
"create",
......@@ -406,7 +410,6 @@ class K8sTopic(BaseTopic):
if profile_id not in profile_list:
content["operatingState"] = "PROCESSING"
content["current_operation"] = None
op_id = self.format_on_operation(
content,
"add",
......@@ -453,8 +456,6 @@ class K8sTopic(BaseTopic):
"Cannot remove default profile", HTTPStatus.UNPROCESSABLE_ENTITY
)
if profile_id in profile_list:
content["operatingState"] = "PROCESSING"
content["current_operation"] = None
op_id = self.format_on_operation(
content,
"remove",
......@@ -481,11 +482,9 @@ class K8sTopic(BaseTopic):
else:
filter_db = self._get_project_filter(session)
filter_db[BaseTopic.id_field(self.topic, _id)] = _id
operation_params = {}
operation_params = None
data = self.db.get_one(self.topic, filter_db)
op_id = self.format_on_operation(
data, item, operation_params, launch_workflow=False
)
op_id = self.format_on_operation(data, item, operation_params)
self.db.set_one(self.topic, {"_id": data["_id"]}, data)
self._send_msg("get_creds", {"cluster_id": _id, "operation_id": op_id})
return op_id
......@@ -569,6 +568,11 @@ class K8saddTopic(BaseTopic):
def __init__(self, db, fs, msg, auth):
BaseTopic.__init__(self, db, fs, msg, auth)
@staticmethod
def format_on_new(content, project_id=None, make_public=False):
BaseTopic.format_on_new(content, project_id=project_id, make_public=make_public)
content["current_operation"] = None
def add(self, rollback, session, indata, kwargs=None, headers=None):
step = "checking quotas"
try:
......@@ -590,7 +594,6 @@ class K8saddTopic(BaseTopic):
self.format_on_new(
cls_add_request, session["project_id"], make_public=session["public"]
)
cls_add_request["current_operation"] = None
op_id = self.format_on_operation(
cls_add_request,
"register",
......@@ -653,8 +656,6 @@ class K8saddTopic(BaseTopic):
filter_q[self.id_field(self.topic, _id)] = _id
item_content = self.db.get_one(self.topic, filter_q)
item_content["operatingState"] = "PROCESSING"
item_content["current_operation"] = None
op_id = self.format_on_operation(
item_content,
"deregister",
......@@ -728,6 +729,7 @@ class KsusTopic(BaseTopic):
@staticmethod
def format_on_new(content, project_id=None, make_public=False):
BaseTopic.format_on_new(content, project_id=project_id, make_public=make_public)
content["current_operation"] = None
content["state"] = "IN_CREATION"
content["operatingState"] = "PROCESSING"
content["resourceState"] = "IN_PROGRESS"
......@@ -776,7 +778,6 @@ class KsusTopic(BaseTopic):
self.format_on_new(
content, project_id=session["project_id"], make_public=session["public"]
)
content["current_operation"] = None
op_id = self.format_on_operation(
content,
operation_type="create",
......@@ -791,9 +792,6 @@ class KsusTopic(BaseTopic):
_id = self.db.create(self.topic, content)
rollback.append({"topic": self.topic, "_id": _id})
if not op_id:
op_id = content["current_operation"]
_id_list.append(_id)
data = {"ksus_list": _id_list, "operation_id": op_id}
self._send_msg("create", data)
......@@ -804,7 +802,6 @@ class KsusTopic(BaseTopic):
filter_db[BaseTopic.id_field(self.topic, _id)] = _id
data = self.db.get_one(self.topic, filter_db)
data["current_operation"] = None
op_id = self.format_on_operation(
data,
"clone",
......@@ -851,7 +848,6 @@ class KsusTopic(BaseTopic):
# To allow project addressing by name AS WELL AS _id. Get the _id, just in case the provided one is a name
_id = content.get("_id") or _id
content["current_operation"] = None
op_id = self.format_on_operation(
content,
"move",
......@@ -1020,6 +1016,7 @@ class OkaTopic(DescriptorTopic):
DescriptorTopic.format_on_new(
content, project_id=project_id, make_public=make_public
)
content["current_operation"] = None
content["state"] = "PENDING_CONTENT"
content["operatingState"] = "PROCESSING"
content["resourceState"] = "IN_PROGRESS"
......@@ -1116,7 +1113,6 @@ class OkaTopic(DescriptorTopic):
self.format_on_new(
content, session["project_id"], make_public=session["public"]
)
content["current_operation"] = None
op_id = self.format_on_operation(
content,
operation_type="create",
......@@ -1252,9 +1248,10 @@ class OkaTopic(DescriptorTopic):
kwargs["package"] = filename
if headers["Method"] == "POST":
current_desc["state"] = "IN_CREATION"
op_id = current_desc["current_operation"]
op_id = current_desc.get("operationHistory", [{"op_id": None}])[-1].get(
"op_id"
)
elif headers["Method"] in ("PUT", "PATCH"):
current_desc["current_operation"] = None
op_id = self.format_on_operation(
current_desc,
"update",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment