def test_delete(self): result = False appConfig = AppConfig(None, development) appConfig.manual_config(test_config['host'], test_config['dbName'], test_config['username'], test_config['password'], test_config['collection']) repo = DocDbRepo(appConfig) repoCount = repo.get_collection_count(appConfig.collectionName) docId = repo.insert_one(mock_order) print("DocumentId = {}".format(docId)) self.assertIsNotNone(docId) count = repo.get_collection_count(appConfig.collectionName) self.assertTrue(count == repoCount + 1) doc = repo.find({"orderId": "8808018297"}) self.assertIsNotNone(doc) self.assertTrue(doc["orderId"] == "8808018297") self.assertTrue(doc["PageID"] == "2939293999999999") delete_count = repo.delete({"PageID": "2939293999999999"}) print("Repo.delete() returned : {}".format(delete_count)) self.assertTrue(delete_count == 1) count = repo.get_collection_count(appConfig.collectionName) self.assertTrue(count == repoCount) return result
def test_collection_count(self): appConfig = AppConfig(None, development) appConfig.manual_config(test_config['host'], test_config['dbName'], test_config['username'], test_config['password'], test_config['collection']) repo = DocDbRepo(appConfig) count = repo.get_collection_count(appConfig.collectionName) self.assertTrue(count > 0) return count
def test_find_all(self): result = False appConfig = AppConfig(None, development) appConfig.manual_config(test_config['host'], test_config['dbName'], test_config['username'], test_config['password'], test_config['collection']) repo = DocDbRepo(appConfig) search_results = repo.findAll(appConfig.collectionName) print(search_results) self.assertIsNotNone(search_results) return result
def test_startBillingDate(self): result = False appConfig = AppConfig(None, development) appConfig.manual_config(test_config['host'], test_config['dbName'], test_config['username'], test_config['password'], test_config['collection']) repo = DocDbRepo(appConfig) repo.validate_parameters = disable_parameter_validation search_results = repo.find({"startBillingDate": "2019/11/01"}) print(search_results) self.assertIsNotNone(search_results) self.assertTrue(len(search_results) > 0) return
def test_find_by_orderId(self): result = False appConfig = AppConfig(None, development) appConfig.manual_config(test_config['host'], test_config['dbName'], test_config['username'], test_config['password'], test_config['collection']) repo = DocDbRepo(appConfig) repo.validate_parameters = disable_parameter_validation doc = repo.find({"orderId": "7800018684"}) print(doc) self.assertIsNotNone(doc) self.assertTrue(doc["orderId"] == "7800018684") return result
def test_find_by_pageId(self): result = False appConfig = AppConfig(None, development) appConfig.manual_config(test_config['host'], test_config['dbName'], test_config['username'], test_config['password'], test_config['collection']) repo = DocDbRepo(appConfig) repo.validate_parameters = disable_parameter_validation search_results = repo.find({"PageID": "911"}) print(search_results) self.assertIsNotNone(search_results) return result
def test_find_by_start_and_end_date_range(self): result = False appConfig = AppConfig(None, development) appConfig.manual_config(test_config['host'], test_config['dbName'], test_config['username'], test_config['password'], test_config['collection']) appConfig.logging_level = appConfig.debug repo = DocDbRepo(appConfig) repo.validate_parameters = disable_parameter_validation criteria = {"startDate": "2019/12/30", "endDate": "2020/01/05"} search_results = repo.find(criteria) print("REsults = {}".format(search_results)) self.assertIsNotNone(len(search_results) > 0) return result
def test_find_by_endDateDoc(self): result = False appConfig = AppConfig(None, development) appConfig.manual_config(test_config['host'], test_config['dbName'], test_config['username'], test_config['password'], test_config['collection']) repo = DocDbRepo(appConfig) repo.validate_parameters = disable_parameter_validation query = {"endDateDoc": "2020/01/05"} search_results = repo.find(query) print("Results = {}".format(search_results)) self.assertIsNotNone(search_results) self.assertTrue(len(search_results) > 0) return result
class TestConfig: config = AppConfig(None, development) config.manual_config(test_config['host'], test_config['dbName'], test_config['username'], test_config['password'], test_config['collection']) config.environment = config.unit_test config.logging_level = config.debug
def lambda_handler(event, context): results = [] status_code = 200 message = "" response = Response(500, "No message", None) try: print('progGetLambda: ENVIRONMENT VARIABLES: ') print(os.environ) print("progGetLambda: event = " + str(event)) validate_get_request(event) config = AppConfig(context, None) repo = DocDbRepo(config) if repo is not None: if parameters_contain_start_and_end_dates(event["queryStringParameters"]): data = reorder_parameter_start_and_end_dates(event["queryStringParameters"]) print("progGetLambda: reordered input parameter start and end dates....") else: data = event["queryStringParameters"] print("progGetLambda: input parameters: {}".format(data)) # submit query results = repo.find(data) # build the response rsp_data = results[0] if len(results) == 1 else results response = Response(200, rsp_data, "Query returned {} document(s).".format(len(results))) if config.logging_level == config.debug: print("progGetLambda: results count = {}".format(len(results))) else: print("progGetLambda: Error configuring Order Repository!") status_code = 500 message = "progGetLambda: Error configuring Repository connection" response = Response(status_code, message, message) if repo is not None: print('progGetLambda: Finished. Closing repository object...') repo = None except DateFormatException as dfe: print("progGetLambda: Exception {}".format(dfe)) print(dfe) response = Response(400, dfe.message, dfe.message) except MissingParameterException as mpe: print("progGetLambda: Exception {}".format(mpe)) print(mpe) response = Response(400, mpe.message, mpe.message) except Exception as e: print("progGetLambda: Exception {}".format(e)) status_code = 500 message = "Unable to complete GET Request" response = Response(status_code, message, message) return { "statusCode": response.status_code, "body": json.dumps(response.body) }
def test_find_by_stationId(self): result = False appConfig = AppConfig(None, development) appConfig.manual_config(test_config['host'], test_config['dbName'], test_config['username'], test_config['password'], test_config['collection']) repo = DocDbRepo(appConfig) repo.validate_parameters = disable_parameter_validation search_results = repo.find({"Station ID": "WGIR-FM"}) print(search_results) self.assertIsNotNone(search_results) for doc in search_results: fulfillments = doc["fulfillmentList"] for f in fulfillments: if "Station ID" in f.keys(): self.assertTrue(f["Station ID"] == "WGIR-FM") return result
def submitJob(): app_obj = request.get_json() #print app_obj['name'] #appdict = json.dumps(app_obj) #print appdict #print appdict['name'] #print app_obj global application_list application_list.update({app_obj['name'] : app_obj }) app = AppConfig(app_obj) mesosScheduler.addApp(app) #print "APP LIST :",application_list return "Successfully submitted job"
def test_config(self): result = False appConfig = AppConfig(None, development) appConfig.manual_config(test_config['host'], test_config['dbName'], test_config['username'], test_config['password'], test_config['collection']) appConfig.display_config() self.assertEqual(appConfig.host, test_config['host']) return result
def main(): start_time = time.time() app_path = Path(__file__) try: # Configure logging start_datetime = datetime.fromtimestamp(start_time) _logger.info( f'Now: {start_datetime.strftime("%a %d-%b-%y %I:%M:%S %p")}') # Run application process(AppConfig(app_path, app_path.parents[1])) except Exception as ex: _logger.exception('Catch all exception') finally: mins, secs = divmod( timedelta(seconds=time.time() - start_time).total_seconds(), 60) _logger.info(f'Run time: {int(mins)}:{secs:0.1f}s')
def scaleUp(self): ScaleManager.id += 1 app_obj = { 'name': 'test-app1', 'cpu': '4', 'ram': '8192', 'command': 'cd cassandra;./nonseed.sh;./startcassandra.sh;while sleep 5; do ps aux | grep java; done', 'docker_image': 'yasaswikishore/cassandra:initial', 'storage': 'False' } app = AppConfig(app_obj) task_list_size = len(self.mesosObj.getTaskList()) print task_list_size if (task_list_size > 1): # we don't need to submit since there is already one pending return self.mesosObj.addApp(app) print "Submitted Non Seed Node"
executor.executor_id.value = "mydocker" executor.name = "My docker example executor" framework = mesos_pb2.FrameworkInfo() framework.user = "" # Have Mesos fill in the current user. framework.name = "MyMesosDockerExample" implicitAcknowledgements = 1 logging.basicConfig(level=logging.DEBUG) framework.principal = "docker-mesos-example-framework" mesosScheduler = MyMesosScheduler(implicitAcknowledgements, executor) # adding a custom application - this should be done by the REST API diction = {} diction["name"] = "test-app" diction["cpu"] = 1 diction["ram"] = 4096 diction["command"] = "cd cassandra ; ./script.sh ; ./startcassandra.sh ; while sleep 5;do ps aux | grep java;done" diction["docker_image"] = "yasaswikishore/cassandra:initialcommit" diction["storage"] = False app = AppConfig(diction) mesosScheduler.addApp(app) print mesosScheduler.app_list driver = mesos.native.MesosSchedulerDriver( mesosScheduler, framework, 'localhost:5050') # I suppose here that mesos master url is local driver.run()