def build_app(spec, log_dir, preload=False): name = spec["name"] app = App.get_app(name) if app and app.build_state == App.BuildState.BUILDING: print("App {} already building. Wait for build to complete before resubmitting.".format(name)) return new_app = App.create(spec) try: new_app.build(preload=preload) except Exception as e: # the "catch-all" clause print("Could not build app {}: {}".format(new_app.name, e)) App.index.update_build_state(App.BuildState.FAILED)
def _configure_app_loggers(self): make_dir(LogSettings.APPS_DIRECTORY) apps = App.get_app() for app in apps: if not app in self._app_loggers: logger = self._make_app_logger(app.name) self._app_loggers[app.name] = logger
def build_app(spec, log_dir, preload=False): name = spec["name"] sys.stdout = open(os.path.join(log_dir, name + "-" + str(os.getpid()) + ".out"), "w", buffering=0) sys.stderr = open(os.path.join(log_dir, name + "-" + str(os.getpid()) + ".err"), "w", buffering=0) app = App.get_app(name) print("In build_app") if app and app.build_state == App.BuildState.BUILDING: print("App {} already building. Wait for build to complete before resubmitting.".format(name)) return new_app = App.create(spec) try: new_app.build(preload=preload) except Exception as e: # the "catch-all" clause print("Could not build app {}: {}".format(new_app.name, e)) App.index.update_build_state(App.BuildState.FAILED)
def get(self, organization, repo): super(StaticLogsHandler, self).get() app_name = App.make_app_name(organization, repo) app = yield self._get_app(app_name) time_string = datetime.datetime.strftime(app.last_build_time, LogSettings.TIME_FORMAT) logs = yield self._get_app_logs(app_name, time_string) self.write({"logs": logs})
def get(self, organization, repo): super(StaticLogsHandler, self).get() app_name = App.make_app_name(organization, repo) app = yield self._get_app(app_name) time_string = datetime.datetime.strftime(app.last_build_time, LogSettings.TIME_FORMAT) filtered = self.get_query_argument('filtered', default='false').lower() == 'true' logs = yield self._get_app_logs(app_name, time_string, filtered) self.write({"logs": logs})
def get(self, organization, repo): super(GithubStatusHandler, self).get() app_name = App.make_app_name(organization, repo) app = yield self._get_app(app_name) if not app: self.set_status(404) self.write({"error": "app does not exist"}) else: self._write_build_state(app)
def open(self, organization, repo): super(LiveLogsHandler, self).open() print("Opening websocket for {}/{}".format(organization, repo)) app_name = App.make_app_name(organization, repo) ws_handlers.append(self) self._thread = LiveLogsHandler.LogsThread(app_name, self) self._thread.start()
def get(self, organization, repo): # if the app is still building, return an error. If the app is built, deploy it and return # the redirect url super(GithubHandler, self).get() app_name = App.make_app_name(organization, repo) app = yield self._get_app(app_name) if app and app.build_state == App.BuildState.COMPLETED: redirect_url = yield self._deploy_app(app, "single-node") self.write({"redirect_url": redirect_url}) else: self.set_status(404) self.write({"error": "no app available to deploy"})
def run(self): app = App.get_app(self._app_name) time_string = datetime.datetime.strftime(app.last_build_time, LogSettings.TIME_FORMAT) self._stream = AppLogStreamer(self._app_name, time_string).get_stream() while not self._stopped: time.sleep(0.05) try: msg = self._stream.next() if msg: self._ioloop.add_callback(self._handler.write_message, msg) except StopIteration: self.stop()
def build_app(spec, log_dir, preload=False): name = spec["name"] sys.stdout = open(os.path.join(log_dir, name + "-" + str(os.getpid()) + ".out"), "w", buffering=0) sys.stderr = open(os.path.join(log_dir, name + "-" + str(os.getpid()) + ".err"), "w", buffering=0) app = App.get_app(name) print("In build_app") if app and app.build_state == App.BuildState.BUILDING: print( "App {} already building. Wait for build to complete before resubmitting." .format(name)) return new_app = App.create(spec) try: new_app.build(preload=preload) except Exception as e: # the "catch-all" clause print("Could not build app {}: {}".format(new_app.name, e)) App.index.update_build_state(App.BuildState.FAILED)
def post(self, organization, repo): # if the spec is properly formed, create/build the app super(GithubBuildHandler, self).post() print("request.body: {}".format(self.request.body)) spec = json.loads(self.request.body) if self._is_malformed(spec): self.set_status(400) self.write({"error": "malformed app specification"}) else: try: spec["name"] = App.make_app_name(organization, repo).lower() spec["repo"] = "https://www.github.com/{0}/{1}".format(organization, repo) build_queue.put(spec) self.write({"success": "app submitted to build queue"}) except Queue.Full: self.write({"error": "build queue full"})
def post(self, organization, repo): # if the spec is properly formed, create/build the app super(GithubBuildHandler, self).post() print("request.body: {}".format(self.request.body)) spec = json.loads(self.request.body) if self._is_malformed(spec): self.set_status(400) self.write({"error": "malformed app specification"}) else: try: spec["name"] = App.make_app_name(organization, repo).lower() spec["repo"] = "https://www.github.com/{0}/{1}".format( organization, repo) build_queue.put(spec) self.write({"success": "app submitted to build queue"}) except Queue.Full: self.write({"error": "build queue full"})
def get(self): super(AppsHandler, self).get() apps = App.get_app() self.write({"apps": [app.name for app in apps]})
def _get_apps(self): return App.get_app()
def _get_app(self, app_name): return App.get_app(app_name)
def _configure_app_loggers(self): make_dir(LogSettings.APPS_DIRECTORY) apps = App.get_app() for app in apps: if not app.name in self._app_loggers: self._make_app_loggers(app.name)