Create/update project on compute when variables changes

This commit is contained in:
ziajka committed 2018-05-09 15:29:35 +02:00
1 parent 83445214be
commit 7b3d5ae5e3
9 files changed
+98 -11

No files matched your search

+12 -1
View File
@@ -25,13 +25,13 @@ import zipfile
import json
from uuid import UUID, uuid4
from .port_manager import PortManager
from .notification_manager import NotificationManager
from ..config import Config
from ..utils.asyncio import wait_run_in_executor
from ..utils.path import check_path_allowed, get_default_project_directory
import logging
log = logging.getLogger(__name__)
@@ -297,6 +297,17 @@ class Project:
yield from node.delete()
self._nodes.remove(node)
@asyncio.coroutine
def update(self, variables=None, **kwargs):
original_variables = self.variables
self.variables = variables
# we need to update docker nodes when variables changes
if original_variables != variables:
for node in self.nodes:
if hasattr(node, 'update'):
yield from node.update()
@asyncio.coroutine
def close(self):
"""
+4 -3
View File
@@ -16,6 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import aiohttp
import asyncio
import psutil
import platform
from .project import Project
@@ -95,16 +96,16 @@ class ProjectManager:
log.warning(message)
project.emit("log.warning", {"message": message})
def create_project(self, name=None, project_id=None, path=None):
def create_project(self, name=None, project_id=None, path=None, variables=None):
"""
Create a project and keep a references to it in project manager.
See documentation of Project for arguments
"""
if project_id is not None and project_id in self._projects:
return self._projects[project_id]
project = Project(name=name, project_id=project_id, path=path)
project = Project(name=name, project_id=project_id,
path=path, variables=variables)
self._check_available_disk_space(project)
self._projects[project.id] = project
return project
+2 -1
View File
@@ -460,11 +460,12 @@ class Compute:
msg = json.loads(response.data)
action = msg.pop("action")
event = msg.pop("event")
if action == "ping":
self._cpu_usage_percent = event["cpu_usage_percent"]
self._memory_usage_percent = event["memory_usage_percent"]
self._controller.notification.emit("compute.updated", self.__json__())
elif action == 'project.updated':
print(event)
else:
yield from self._controller.notification.dispatch(action, event, compute_id=self.id)
if self._ws:
+12 -1
View File
@@ -136,6 +136,15 @@ class Project:
self.controller.notification.emit("project.updated", self.__json__())
self.dump()
# update on computes
for compute in list(self._project_created_on_compute):
yield from compute.put(
"/projects/{}".format(self._id), {
"variables": self.variables
}
)
def reset(self):
"""
Called when open/close a project. Cleanup internal stuff
@@ -493,12 +502,14 @@ class Project:
yield from compute.post("/projects", data={
"name": self._name,
"project_id": self._id,
"path": self._path
"path": self._path,
"variables": self._variables
})
else:
yield from compute.post("/projects", data={
"name": self._name,
"project_id": self._id,
"variables": self._variables
})
self._project_created_on_compute.add(compute)
@@ -73,11 +73,31 @@ class ProjectHandler:
p = pm.create_project(
name=request.json.get("name"),
path=request.json.get("path"),
project_id=request.json.get("project_id")
project_id=request.json.get("project_id"),
variables=request.json.get("variables", None)
)
response.set_status(201)
response.json(p)
@Route.put(
r"/projects/{project_id}",
description="Update the project on the server",
status_codes={
201: "Project updated",
403: "Forbidden to update a project"
},
output=PROJECT_OBJECT_SCHEMA,
input=PROJECT_UPDATE_SCHEMA)
def update_project(request, response):
pm = ProjectManager.instance()
project = pm.get_project(request.match_info["project_id"])
yield from project.update(
variables=request.json.get("variables", None)
)
response.set_status(200)
response.json(project)
@Route.get(
r"/projects/{project_id}",
description="Get project information",