def on_delete(self, req, res, id, version_id): module_id = self.validated_params['id'] module_version_id = self.validated_params['version_id'] compiler = None try: module = MongodbFactory.get_module(module_id) module_version = MongodbFactory.get_module_version( module_version_id) if not module or not module_version: return ResponsesHandler.handle_404(res, 'Module not found') m_name = module[ModuleConst.FIELD_NAME] m_version = module_version[ModuleVersionConst.FIELD_VERSION_CODE] compiler = Compiler.delete_module(m_name, m_version) except ModuleVersionInvalidId as Ex: logger.error(Ex.message) return ResponsesHandler.handle_404(res, msg=Ex.message) except MissingMandatoryFields as Ex: logger.error(Ex.message) return ResponsesHandler.handle_409(res) except Error as Ex: logger.error(Ex.message) return ResponsesHandler.handle_400(res) except Exception as e: logger.critical(e.message) return ResponsesHandler.handle_500(res) finally: if compiler: compiler.remove() return ResponsesHandler.handle_200(res)
def on_post(self, req, resp, id): topology_id = self.validated_params['id'] builder = None try: topology = MongodbFactory.get_topology(topology_id) if not topology: return ResponsesHandler.handle_404(resp, 'Topology not found') topology_name = topology[TopologyConst.FIELD_NAME] try: StormUI.kill_topology_by_name(topology_name) except TopologyNotInCluster: pass logger.debug('Creating topology project...') builder = TopologyBuilder(topology) logger.debug('Building topology jar...') builder.build_jar_with_dependencies() logger.debug('Uploading topology to storm...') result = StormProcess.launch_topology_cmd( topology_name, os.path.join(builder.base_path, 'target', builder.jar_name)) logger.debug(result.stdout) MongodbFactory.update_running_state(topology_id) return ResponsesHandler.handle_200( resp, { 'id': topology_id, 'status': TopologyConst.STATUS_RUNNING }) except TopologyInvalidId as Ex: logger.error(Ex.message) return ResponsesHandler.handle_404(resp) except CommandException as Ex: logger.error(Ex.message) logger.debug(Ex.log()) return ResponsesHandler.handle_500(resp) except Error as Ex: logger.error(Ex.message) return ResponsesHandler.handle_500(resp) except Exception as e: logger.critical(e.message) return ResponsesHandler.handle_500(resp) finally: if builder is not None: builder.remove()
def on_get(self, req, resp, id): topology_id = self.validated_params['id'] try: topology = MongodbFactory.get_topology(topology_id) if topology is None: return ResponsesHandler.handle_404(resp, 'Topology not found') text = LogViewer.get_log(topology[TopologyConst.FIELD_NAME]) return ResponsesHandler.handle_200(resp, { 'id': topology_id, 'log': text }) except TopologyInvalidId as Ex: logger.error(Ex.message) return ResponsesHandler.handle_404(resp, Ex.message) except MissingMandatoryFields as Ex: logger.error(Ex.message) return ResponsesHandler.handle_409(resp) except Error as Ex: logger.critical(Ex.message) return ResponsesHandler.handle_500(resp) except Exception as Ex: logger.critical(Ex.message) return ResponsesHandler.handle_500(resp)
def on_post(self, req, resp, id): topology_id = self.validated_params['id'] try: topology = MongodbFactory.get_topology(topology_id) if not topology: return ResponsesHandler.handle_404(resp, 'Topology not found') info = StormUI.kill_topology_by_name( topology[TopologyConst.FIELD_NAME]) if info['status'] == 'success': MongodbFactory.update_stopped_state(topology_id) return ResponsesHandler.handle_200( resp, { 'id': topology_id, 'status': TopologyConst.STATUS_STOPPED }) else: return ResponsesHandler.handle_409(resp, { 'id': topology_id, 'status': info['status'] }) except TopologyInvalidId as Ex: logger.error(Ex.message) return ResponsesHandler.handle_404(resp) except MissingMandatoryFields as Ex: logger.error(Ex.message) return ResponsesHandler.handle_409(resp) except TopologyNotInCluster as Ex: MongodbFactory.update_stopped_state(topology_id) logger.error(Ex.message) return ResponsesHandler.handle_409(resp) except Error as Ex: logger.error(Ex.message) return ResponsesHandler.handle_500(resp) except Exception as Ex: logger.critical(Ex.message) return ResponsesHandler.handle_500(resp)
def build_dependencies(self): dependencies, ids = [], dict() for module in self.topology[TopologyConsts.FIELD_CONFIG][ TopologyConsts.FIELD_MODULES]: _module_id = module[ModuleConsts.FIELD_MODULE_ID] _module_version_code = module[ModuleConsts.FIELD_VERSION_CODE] if not ids.get(_module_id): ids.setdefault(module[ModuleConsts.FIELD_MODULE_ID], [_module_version_code]) elif not ids.get(_module_id) and not ids.__contains__( _module_version_code): _module_versions_codes = ids.get(_module_id) _module_versions_codes.append(_module_version_code) ids.setdefault(module[ModuleConsts.FIELD_MODULE_ID], _module_versions_codes) _modules = MongodbFactory.get_modules(ids.keys()) for module in _modules: if module is not None: _versions = ids.get( module.get(ModuleVersionConst.FIELD_ID).__str__()) dependencies.extend( map( lambda v: MvnDependency(group_id='com.sinfonier', artifact_id=module[ ModuleConsts.FIELD_NAME], version=str(v)), _versions)) m_libraries = module.get(ModuleVersionConst.FIELD_LIBRARIES) if m_libraries is not None: m_deps = list( map(Compiler.build_mvn_dependency_from_url, [ l[ModuleVersionConst.FIELD_LIBRARY_URL] for l in m_libraries ])) dependencies.extend(m_deps) return dependencies
def on_post(self, req, res, id, version_id): module_id = self.validated_params['id'] module_version_id = self.validated_params['version_id'] compiler = None try: module = MongodbFactory.get_module(module_id) module_version = MongodbFactory.get_module_version( module_version_id) if not module_version or not module: return ResponsesHandler.handle_404(res, 'Module not found') if not module_version[ModuleVersionConst.FIELD_SOURCE_CODE]: raise ModuleException('The module\'s ' + ModuleVersionConst.FIELD_SOURCE_CODE + ' is mandatory.') m_name = module[ModuleConst.FIELD_NAME] m_type = module.get(ModuleConst.FIELD_TYPE) if not m_type and not module['container']: raise ModuleException('We can not found the module\'s type') elif not m_type: m_type = module['container'][ModuleConst.FIELD_TYPE] m_lang = module[ModuleConst.FIELD_LANG].lower() m_code = module_version[ModuleVersionConst.FIELD_SOURCE_CODE] m_version = str( module_version[ModuleVersionConst.FIELD_VERSION_CODE]) m_libraries = module_version.get( ModuleVersionConst.FIELD_LIBRARIES) if m_libraries is not None: dependencies = list( map(Compiler.build_mvn_dependency_from_url, [ l[ModuleVersionConst.FIELD_LIBRARY_URL] for l in m_libraries ])) else: dependencies = list() compiler = Compiler(m_name, m_version, m_type, m_lang, m_code, dependencies=dependencies) MongodbFactory.update_status_builder_module( module_version_id, ModuleVersionConst.BUILD_STATUS_SUCCESS) MongodbFactory.update_module_last_modify(module_id) compiler.install_jar() except ModuleInvalidId as Ex: logger.error(Ex.message) return ResponsesHandler.handle_404(res, msg=Ex.message) except ModuleVersionInvalidId as Ex: logger.error(Ex.message) return ResponsesHandler.handle_404(res, msg=Ex.message) except MissingMandatoryFields as Ex: logger.error(Ex.message) return ResponsesHandler.handle_409(res, Ex.message) except ModuleException as Ex: logger.error(Ex.message) return ResponsesHandler.handle_803(res, data=Ex.message) except ModuleInvalidLanguage as Ex: logger.error(Ex.message) return ResponsesHandler.handle_803(res, data=Ex.message) except ModuleErrorCompilingException as Ex: logger.error(Ex.message) MongodbFactory.update_status_builder_module( module_version_id, ModuleVersionConst.BUILD_STATUS_FAILURE) MongodbFactory.update_module_last_modify(module_id) return ResponsesHandler.handle_804(res, trace=Ex.message) except CommandException as Ex: logger.error(Ex.log()) return ResponsesHandler.handle_500(res) except Error as Ex: logger.error(Ex.message) return ResponsesHandler.handle_500(res) except Exception as e: logger.critical(e.message) return ResponsesHandler.handle_500(res) finally: if compiler: compiler.remove() return ResponsesHandler.handle_200(res)
def get_topology_json(self): # get topology mongo json topologyMongoInfo = MongodbFactory.get_topology(self.topology.FIELD_ID) return self.build_backend_json(topologyMongoInfo)