def post(self): artifact = request.get_json(force=True) RethinkDbHelper.ensure_database_and_table(rethinkdb_host, rethinkdb_port, rethinkdb_db, "artifacts") try: insert_obj = { "commit_id": artifact['commit_id'], "package_name": artifact['package_name'], "package_version": artifact['package_version'], "branch_name": artifact['branch_name'], "commit_author": artifact['commit_author'], "commit_message": artifact['commit_message'], "commit_tag": artifact['commit_tag'], "artifact_url": artifact['artifact_url'], "artifact_type": artifact['artifact_type'] } existing_record = \ r.db(rethinkdb_db).table("artifacts").filter({'commit_id': artifact['commit_id'], 'package_name': artifact['package_name'], 'package_version': artifact['package_version']}).run() if existing_record.items.__len__() == 0: result = r.db(rethinkdb_db).table("artifacts").insert( insert_obj).run() elif existing_record.items.__len__() == 1: insert_obj['id'] = existing_record.items[0]['id'] result = r.db(rethinkdb_db).table("artifacts").insert( insert_obj, conflict="replace").run() return result except Exception, e: raise ValueError(str.format("error {0}", str(e)))
def post(self, deployment_name): deployment = json.loads(request.data) deployments_table = "deployments" unique_ness = deployment['server'] + str(deployment['local_port']) unique_ness = unique_ness.lower() #make sure the incoming deployment name is unused r.connect(rethinkdb_host, rethinkdb_port).repl() RethinkDbHelper.ensure_database_and_table(rethinkdb_host, rethinkdb_port, rethinkdb_db, deployments_table) keys = r.db(rethinkdb_db).table(deployments_table).run() db_deployments = list(keys) for dep in db_deployments: db_uniqueness = dep['server'] + str(dep['local_port']) db_uniqueness = db_uniqueness.lower() if unique_ness == db_uniqueness: raise ValueError("Already exists") result = r.db(rethinkdb_db).table(deployments_table).insert( deployment).run() return result
def get(self): appmaps_table = "applicationmaps" r.connect(rethinkdb_host, rethinkdb_port).repl() RethinkDbHelper.ensure_database_and_table(rethinkdb_host, rethinkdb_port, rethinkdb_db, appmaps_table) keys = r.db(rethinkdb_db).table(appmaps_table).run() db_appmaps = list(keys) return db_appmaps
def get(self, appmap_name): appmaps_table = "applicationmaps" r.connect(rethinkdb_host, rethinkdb_port).repl() RethinkDbHelper.ensure_database_and_table(rethinkdb_host, rethinkdb_port, rethinkdb_db, appmaps_table) keys = r.db(rethinkdb_db).table(appmaps_table).run() db_appmaps = list(keys) if db_appmaps.__len__() == 0: #not found pass if db_appmaps.__len__() < 1: #too many pass appmap = db_appmaps[0] desired_instancecount = appmap['instancecount'] #figure out the existing number of deployments url = request.url_root + "api/deployments/appmap/" + appmap_name result = requests.get(url) result_data = json.loads(result.content) current_deployments = [ x for x in result_data if x['package_version'] == appmap['gitfilter']['version'] and x['package_branch'] == appmap['gitfilter']['branch'] ] current_deployments_count = current_deployments.__len__() resultobj = {} resultobj['current_deployments'] = current_deployments_count resultobj['desired_deployments'] = desired_instancecount deployment_candidates = [] if current_deployments_count < desired_instancecount: needed_deployments = desired_instancecount - current_deployments_count deployment_candidates = ServerSelector.get_deployment_candidates( rethinkdb_host, rethinkdb_port, rethinkdb_db, appmap['targettags'], needed_deployments, current_deployments) for candidate in deployment_candidates: port = ServerSelector.get_free_port(candidate['name'], request.url_root, serverpool_port_start) candidate['port'] = port result = ServerSelector.create_reservation( candidate, appmap, request.url_root) return deployment_candidates
def get(self): servers_table = "servers" r.connect(rethinkdb_host, rethinkdb_port).repl() RethinkDbHelper.ensure_database_and_table(rethinkdb_host, rethinkdb_port, rethinkdb_db, servers_table) keys = r.db(rethinkdb_db).table(servers_table).run() db_servers = list(keys) return db_servers
def get(self): RethinkDbHelper.ensure_database_and_table(rethinkdb_host, rethinkdb_port, rethinkdb_db, "artifacts") keys = r.db(rethinkdb_db).table("artifacts").run() db_artifacts = list(keys) artifacts = [] for af in db_artifacts: artifacts.append(af) return artifacts
def get(self, name, branch="any", version="latest", ): r.connect(rethinkdb_host, rethinkdb_port).repl() RethinkDbHelper.ensure_database_and_table(rethinkdb_host, rethinkdb_port, rethinkdb_db, "artifacts") if version == 'latest' and branch == 'any': existing_record = \ r.db(rethinkdb_db).table("artifacts").filter({'package_name': name}).run() all_records = existing_record.items current_highest = None for rec in all_records: try: v = semantic_version.Version(rec['package_version']) except: v = semantic_version.Version('0.0.0') rec['semantic_version'] = v if current_highest is None: current_highest = rec else: this_wins = current_highest['semantic_version'] < v if this_wins: rec['semantic_version'] = v current_highest = rec #remove the semantic version from the object before returning, since it's not json serializable del current_highest['semantic_version'] return current_highest elif version == 'latest': #we need to query for branch since it was specified existing_record = \ r.db(rethinkdb_db).table("artifacts").filter({'package_name': name, 'branch_name': branch}).run() recordset = [] for item in existing_record.items: recordset.append(item) if recordset.__len__() == 1: return recordset[0] return None
def get(self, server=None, appmap=None): deployments_table = "deployments" r.connect(rethinkdb_host, rethinkdb_port).repl() RethinkDbHelper.ensure_database_and_table(rethinkdb_host, rethinkdb_port, rethinkdb_db, deployments_table) keys = r.db(rethinkdb_db).table(deployments_table).run() db_deployments = list(keys) if server: db_deployments = [ x for x in db_deployments if x['server'] == server ] if appmap: db_deployments = [ x for x in db_deployments if x['deployment_name'] == appmap ] return db_deployments