removed bugs
This commit is contained in:
parent
8bff435ef3
commit
8a1ad07e30
@ -11,7 +11,7 @@ from marshm import ma
|
||||
from errorhandlers import register_all_error_handlers
|
||||
from healthchecks import redis_available
|
||||
from resources import ServiceDiscoveryResource, ServiceLocationResource, ServiceDatabaseResource, \
|
||||
ServiceDatabaseItemResource
|
||||
ServiceDatabaseItemResource, ResetApplicationResource
|
||||
|
||||
"""
|
||||
Main Flask RESTful API
|
||||
@ -43,6 +43,7 @@ redis_client.init_app(app)
|
||||
api.add_resource(ServiceDiscoveryResource, "/service/directory")
|
||||
api.add_resource(ServiceLocationResource, "/service/location/<serviceid>")
|
||||
api.add_resource(ServiceDatabaseResource, "/service")
|
||||
api.add_resource(ResetApplicationResource, "/reset_app")
|
||||
api.add_resource(ServiceDatabaseItemResource, "/service/<serviceid>")
|
||||
|
||||
health.add_check(redis_available)
|
||||
|
@ -19,4 +19,4 @@ class Config:
|
||||
RELEASE_ID = os.environ.get("RELEASE_ID", "test")
|
||||
RELEASEMODE = os.environ.get("RELEASEMODE", "dev")
|
||||
|
||||
REDIS_URL = os.environ['REDIS_URL']
|
||||
REDIS_URL = os.environ.get("REDIS_URL", "redis://127.0.0.1:6379/0")
|
||||
|
@ -25,7 +25,7 @@ class ServiceDiscoveryResource(Resource):
|
||||
|
||||
def get(self):
|
||||
try:
|
||||
servicelist = self.servicedirectoryschema.load(json.load(redis_client.get('servicelist').decode('UTF-8')))
|
||||
servicelist = self.servicedirectoryschema.load(json.loads(redis_client.get('servicelist').decode('UTF-8')))
|
||||
except Exception as e:
|
||||
current_app.logger.info(e)
|
||||
abort(404, "not found")
|
||||
@ -40,7 +40,7 @@ class ServiceLocationResource(Resource):
|
||||
|
||||
def get(self, serviceid: str):
|
||||
try:
|
||||
serviceobject: dict = self.servicelocatorschema.load(json.load(redis_client.get(serviceid).decode('UTF-8')))
|
||||
serviceobject: dict = self.servicelocatorschema.load(json.loads(redis_client.get(serviceid).decode('UTF-8')))
|
||||
servicelocation: str = random.choice(serviceobject['servicearray'])['location']
|
||||
except Exception as e:
|
||||
current_app.logger.info(e)
|
||||
@ -67,10 +67,10 @@ class ServiceDatabaseResource(Resource):
|
||||
current_app.logger.info(e)
|
||||
abort(417, "invalid JSON schema")
|
||||
try:
|
||||
redis_client.set(servicelocation['id'], self.servicelocatorschema.dump(servicelocation).encode('UTF-8'))
|
||||
servicelist = self.servicedirectoryschema.load(json.load(redis_client.get('servicelist').decode('UTF-8')))
|
||||
redis_client.set(servicelocation['id'], json.dumps(self.servicelocatorschema.dump(servicelocation)).encode('UTF-8'))
|
||||
servicelist = self.servicedirectoryschema.load(json.loads(redis_client.get('servicelist').decode('UTF-8')))
|
||||
servicelist.append({"name": servicelocation['name'], "id": servicelocation['id']})
|
||||
redis_client.set('servicelist', self.servicedirectoryschema.dump(servicelist).encode('UTF-8'))
|
||||
redis_client.set('servicelist', json.dumps(self.servicedirectoryschema.dump(servicelist)).encode('UTF-8'))
|
||||
except Exception as e:
|
||||
current_app.logger.info(e)
|
||||
abort(404, "not found")
|
||||
@ -97,7 +97,7 @@ class ServiceDatabaseItemResource(Resource):
|
||||
abort(417, "invalid JSON schema")
|
||||
try:
|
||||
redis_client.get(serviceid)
|
||||
redis_client.set(serviceid, self.servicelocatorschema.dump(servicelocation).encode('UTF-8'))
|
||||
redis_client.set(serviceid, json.dumps(self.servicelocatorschema.dump(servicelocation)).encode('UTF-8'))
|
||||
except Exception as e:
|
||||
current_app.logger.info(e)
|
||||
abort(404, "not found")
|
||||
@ -105,8 +105,35 @@ class ServiceDatabaseItemResource(Resource):
|
||||
|
||||
def get(self, serviceid: str):
|
||||
try:
|
||||
servicelocation = self.servicelocatorschema.load(json.load(redis_client.get(serviceid).decode('UTF-8')))
|
||||
servicelocation = self.servicelocatorschema.load(json.loads(redis_client.get(serviceid).decode('UTF-8')))
|
||||
except Exception as e:
|
||||
current_app.logger.info(e)
|
||||
abort(404, "not found")
|
||||
return servicelocation, 200
|
||||
|
||||
|
||||
class ResetApplicationResource(Resource):
|
||||
"""
|
||||
Reset the application
|
||||
"""
|
||||
servicedirectoryschema = ServiceDirectorySchema(many=True)
|
||||
servicelocatorschema = ServiceLocatorSchema(many=False)
|
||||
|
||||
def get(self):
|
||||
try:
|
||||
redis_client.set('servicelist', json.dumps(self.servicedirectoryschema.dump(
|
||||
[{"name": "Test App", "id": "c03b5706-5ea3-46c9-a2cb-e1442f3528e3"}])).encode('UTF-8'))
|
||||
redis_client.set('c03b5706-5ea3-46c9-a2cb-e1442f3528e3',
|
||||
json.dumps(self.servicelocatorschema.dump({"name": "Test App",
|
||||
"id": "c03b5706-5ea3-46c9-a2cb-e1442f3528e3",
|
||||
"servicearray": [
|
||||
{
|
||||
"location": "198.51.100.42",
|
||||
"zone": "string"
|
||||
}
|
||||
]})).encode(
|
||||
'UTF-8'))
|
||||
except Exception as e:
|
||||
current_app.logger.info(e)
|
||||
abort(404, e)
|
||||
return 200
|
||||
|
@ -21,7 +21,7 @@ class ServiceSchema(ma.Schema):
|
||||
- zone (string)
|
||||
"""
|
||||
|
||||
location = fields.IPv4(required=True)
|
||||
location = fields.String(required=True)
|
||||
zone = fields.String(required=True)
|
||||
|
||||
|
||||
@ -33,7 +33,7 @@ class ServiceDirectorySchema(ma.Schema):
|
||||
"""
|
||||
|
||||
name = fields.String(required=True)
|
||||
id = fields.UUID(required=True)
|
||||
id = fields.String(required=True)
|
||||
|
||||
|
||||
class ServiceLocatorSchema(ma.Schema):
|
||||
@ -45,5 +45,5 @@ class ServiceLocatorSchema(ma.Schema):
|
||||
"""
|
||||
|
||||
name = fields.String(required=True)
|
||||
id = fields.UUID(required=True)
|
||||
id = fields.String(required=True)
|
||||
servicearray = fields.Nested(ServiceSchema, many=True, required=True)
|
||||
|
Loading…
Reference in New Issue
Block a user