def cleanup():
    cm = ClusterManager.get_instance()
    all_routes = set(cm._get_inactive_routes(0))
    for name, timestamp in get_apps():
        if (name not in all_routes) and app_re.match(name):
            print "going to delete app: {0}".format(name)
            subprocess.check_output(['kubectl.sh', 'delete', 'namespace', name])
Exemple #2
0
    def deploy(self, mode):
        # every service must be deployable in single-node mode, so this is valid even if there
        # aren't any services
        if not mode:
            mode = "single-node"

        success = True

        # clean up the old deployment
        deploy_path = os.path.join(self.path, "deploy")
        if os.path.isdir(deploy_path):
            shutil.rmtree(deploy_path)
        os.mkdir(deploy_path)

        services = self.services
        app_params = self.get_app_params()

        # load all the template strings
        templates_path = os.path.join(MainSettings.ROOT, "templates")
        template_names = ["namespace.json", "pod.json", "service-pod.json", "notebook.json",
                          "controller.json", "service.json"]
        templates = {}
        for name in template_names:
            with open(os.path.join(templates_path, name), 'r') as tf:
                templates[name] = tf.read()

        # insert the notebooks container into the pod.json template
        with open(os.path.join(deploy_path, "notebook.json"), 'w+') as nb_file:
            nb_string = fill_template_string(templates["notebook.json"], app_params)
            nb_file.write(nb_string)

        # insert the namespace file into the deployment folder
        with open(os.path.join(deploy_path, "namespace.json"), 'w+') as ns_file:
            ns_string = fill_template_string(templates["namespace.json"], app_params)
            ns_file.write(ns_string)

        # write deployment files for every service (by passing app parameters down to each service)
        for service in services:
            deployed_service = service.deploy(mode, deploy_path, self, templates)
            if not deployed_service:
                success = False

        # use the cluster manager to deploy each file in the deploy/ folder
        redirect_url = ClusterManager.get_instance().deploy_app(self.app_id, deploy_path)
        if not redirect_url:
            success = False

        if success:
            app_id = app_params["app.id"]
            msg = "Successfully deployed app {0} in {1} mode with ID {2}".format(self.name, mode, app_id)
            info_log(self.TAG, msg)
            return redirect_url
        else:
            error_log(self.TAG, "Failed to deploy app {0} in {1} mode.".format(self.name, mode))
            return None
Exemple #3
0
 def get(self):
     super(CapacityHandler, self).get()
     cm = ClusterManager.get_instance()
     # don't count the default and kube-system namespaces
     running = len(cm.get_running_apps()) - 3
     if not self.last_poll or not self.cached_capacity or\
             time.time() - self.last_poll > CapacityHandler.POLL_PERIOD:
         capacity = yield self._get_capacity(cm)
         CapacityHandler.cached_capacity = capacity
         CapacityHandler.last_poll = time.time()
     self.write({"capacity": self.cached_capacity, "running": running})
Exemple #4
0
 def get(self):
     super(CapacityHandler, self).get()
     cm = ClusterManager.get_instance()
     # don't count the default and kube-system namespaces
     running = len(cm.get_running_apps()) - 3
     if not self.last_poll or not self.cached_capacity or\
             time.time() - self.last_poll > CapacityHandler.POLL_PERIOD:
         capacity = yield self._get_capacity(cm)
         CapacityHandler.cached_capacity = capacity
         CapacityHandler.last_poll = time.time()
     self.write({"capacity": self.cached_capacity, "running": running})
Exemple #5
0
 def preload_all_apps():
     apps = App.get_app()
     cm = ClusterManager.get_instance()
     cm.preload_image("binder-base")
     for app in apps:
         cm.preload_image(app.name)
Exemple #6
0
 def _preload_image(self):
     print("Preloading app image onto all nodes...")
     cm = ClusterManager.get_instance().preload_image(self.name)
Exemple #7
0
 def _get_running_apps(self):
     cm = ClusterManager.get_instance()
     return cm.get_running_apps()
Exemple #8
0
 def _get_running_apps(self):
     cm = ClusterManager.get_instance()
     return cm.get_running_apps()
Exemple #9
0
 def preload_all_apps():
     apps = App.get_app()
     cm = ClusterManager.get_instance()
     cm.preload_image("binder-base")
     for app in apps:
         cm.preload_image(app.name)
Exemple #10
0
 def _preload_image(self):
     info_log(self.TAG, "Preloading app image onto all nodes...", app=self.name)
     cm = ClusterManager.get_instance().preload_image(self.name)
Exemple #11
0
 def _preload_image(self):
     print("Preloading app image onto all nodes...")
     cm = ClusterManager.get_instance().preload_image(self.name)