Commit 25493b85 authored by arjun.b's avatar arjun.b

first commit

parent 64302ca5
\
,.idea/inspectionProfiles/Project_Default.xml,4\9\496a238a6afa168dbaf6efd37bb459331589579c
^
..idea/inspectionProfiles/profiles_settings.xml,1\e\1e9075f5bf079c01ef2c910709e91a497d262080
L
scripts/utils/mongo_utils.py,0\2\028245be183e97120b9832f8912cad7b0f292d72
7
main.py,f\1\f1bdda93d9a278e358509d498e17d97764c1fb29
6
app.py,1\3\13cce7fd076299c81b4986166f3d822791c9490e
:
Dockerfile,6\6\6651ddff6eb82c840ced7c1dddee15c6e1913dd4
<
update_db.py,b\e\bed2b5a444c481de1fb8954f4017582ec23f989e
?
requirments.txt,6\3\63ca6d3cb5645a462d48767fff3c8b7de2fad47f
n
>scripts/database/mongodb/asset_manager/collections/__init__.py,8\5\85662d542fe3a35fddc27f559d6e72183c0c7c60
I
scripts/logging/logger.py,2\a\2a7cfbe29f4cfc67ff2d5340ee99290abe2b82f7
\ No newline at end of file
......@@ -131,3 +131,73 @@ Traceback (most recent call last):
bson.errors.InvalidDocument: cannot encode object: TestUpdate(mac='b8:27:eb:4f:5e:87'), of type: <class 'scripts.schemas.test_schema.TestUpdate'>
2023-05-12 18:51:58 - ERROR - [MainThread:update_db(): 31] - error from asset management.py cannot encode object: TestUpdate(mac='b8:27:eb:4f:5e:87'), of type: <class 'scripts.schemas.test_schema.TestUpdate'>
2023-05-12 18:58:27 - INFO - [MainThread:update_db(): 27] - update method called
2023-05-15 10:32:09 - INFO - [MainThread:update_db(): 29] - update method called
2023-05-15 10:32:09 - INFO - [MainThread:create_tag(): 11] - create tags called
2023-05-15 10:32:09 - INFO - [MainThread:update_name(): 24] - Update name method called
2023-05-15 10:32:09 - INFO - [MainThread:create_tag(): 18] - database updated
2023-05-15 10:49:50 - INFO - [MainThread:update_db(): 29] - update method called
2023-05-15 10:49:50 - INFO - [MainThread:create_tag(): 11] - create tags called
2023-05-15 10:49:50 - INFO - [MainThread:update_name(): 24] - Update name method called
2023-05-15 10:49:50 - ERROR - [MainThread:update_one(): 147] - cannot encode object: TestUpdate(mac='string', country='string', state='string', vendor='string', customer='string'), of type: <class 'scripts.schemas.tag_schema.TestUpdate'>
Traceback (most recent call last):
File "E:\Asset Manager V2\scripts\utils\mongo_tools\mongo_sync.py", line 145, in update_one
return collection.update_one(query, {strategy: data}, upsert=upsert)
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 1028, in update_one
self._update_retryable(
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 877, in _update_retryable
return self.__database.client._retryable_write(
File "E:\Anaconda\lib\site-packages\pymongo\mongo_client.py", line 1552, in _retryable_write
return self._retry_with_session(retryable, func, s, None)
File "E:\Anaconda\lib\site-packages\pymongo\mongo_client.py", line 1438, in _retry_with_session
return self._retry_internal(retryable, func, session, bulk)
File "E:\Anaconda\lib\site-packages\pymongo\mongo_client.py", line 1470, in _retry_internal
return func(session, sock_info, retryable)
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 869, in _update
return self._update(
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 838, in _update
result = sock_info.command(
File "E:\Anaconda\lib\site-packages\pymongo\pool.py", line 726, in command
self._raise_connection_failure(error)
File "E:\Anaconda\lib\site-packages\pymongo\pool.py", line 710, in command
return command(self, dbname, spec, secondary_ok,
File "E:\Anaconda\lib\site-packages\pymongo\network.py", line 118, in command
request_id, msg, size, max_doc_size = message._op_msg(
File "E:\Anaconda\lib\site-packages\pymongo\message.py", line 742, in _op_msg
return _op_msg_uncompressed(
bson.errors.InvalidDocument: cannot encode object: TestUpdate(mac='string', country='string', state='string', vendor='string', customer='string'), of type: <class 'scripts.schemas.tag_schema.TestUpdate'>
2023-05-15 10:49:50 - ERROR - [MainThread:update_name(): 32] - error from device.py cannot encode object: TestUpdate(mac='string', country='string', state='string', vendor='string', customer='string'), of type: <class 'scripts.schemas.tag_schema.TestUpdate'>
2023-05-15 10:50:30 - INFO - [MainThread:update_db(): 29] - update method called
2023-05-15 10:50:30 - INFO - [MainThread:create_tag(): 11] - create tags called
2023-05-15 10:50:30 - INFO - [MainThread:update_name(): 24] - Update name method called
2023-05-15 10:50:30 - ERROR - [MainThread:update_one(): 147] - cannot encode object: TestUpdate(mac='string', country='string', state='string', vendor='string', customer='string'), of type: <class 'scripts.schemas.tag_schema.TestUpdate'>
Traceback (most recent call last):
File "E:\Asset Manager V2\scripts\utils\mongo_tools\mongo_sync.py", line 145, in update_one
return collection.update_one(query, {strategy: data}, upsert=upsert)
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 1028, in update_one
self._update_retryable(
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 877, in _update_retryable
return self.__database.client._retryable_write(
File "E:\Anaconda\lib\site-packages\pymongo\mongo_client.py", line 1552, in _retryable_write
return self._retry_with_session(retryable, func, s, None)
File "E:\Anaconda\lib\site-packages\pymongo\mongo_client.py", line 1438, in _retry_with_session
return self._retry_internal(retryable, func, session, bulk)
File "E:\Anaconda\lib\site-packages\pymongo\mongo_client.py", line 1470, in _retry_internal
return func(session, sock_info, retryable)
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 869, in _update
return self._update(
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 838, in _update
result = sock_info.command(
File "E:\Anaconda\lib\site-packages\pymongo\pool.py", line 726, in command
self._raise_connection_failure(error)
File "E:\Anaconda\lib\site-packages\pymongo\pool.py", line 710, in command
return command(self, dbname, spec, secondary_ok,
File "E:\Anaconda\lib\site-packages\pymongo\network.py", line 118, in command
request_id, msg, size, max_doc_size = message._op_msg(
File "E:\Anaconda\lib\site-packages\pymongo\message.py", line 742, in _op_msg
return _op_msg_uncompressed(
bson.errors.InvalidDocument: cannot encode object: TestUpdate(mac='string', country='string', state='string', vendor='string', customer='string'), of type: <class 'scripts.schemas.tag_schema.TestUpdate'>
2023-05-15 10:50:30 - ERROR - [MainThread:update_name(): 32] - error from device.py cannot encode object: TestUpdate(mac='string', country='string', state='string', vendor='string', customer='string'), of type: <class 'scripts.schemas.tag_schema.TestUpdate'>
2023-05-15 10:55:37 - INFO - [MainThread:update_db(): 29] - update method called
2023-05-15 10:55:37 - INFO - [MainThread:create_tag(): 11] - create tags called
2023-05-15 10:55:37 - INFO - [MainThread:update_name(): 24] - Update name method called
2023-05-15 10:55:37 - INFO - [MainThread:create_tag(): 22] - database updated
......@@ -2,6 +2,7 @@ class _APIEndPoints:
root: str = "/asset_manager_api"
api_create: str = "/create"
db_test: str = "/update"
create_tag: str = "/create_tag"
APIEndPoints = _APIEndPoints()
def db_test(self):
self.insert_one()
\ No newline at end of file
from scripts.database.mongodb.asset_manager.collections.device import Devices
from scripts.logging.logger import logger
obj = Devices()
class AssetHandler:
@staticmethod
def update_db(data):
try:
logger.info("create tags called")
# Construct the filter to match the document with the given _id
filter = {"mac_address": data.mac}
# Construct the update document to set the customer field to "ARJUN B"
update = {"site_location.country": data.country,
"site_location.state": data.state,
"vendor": data.vendor,
"customer": data.customer
}
data = obj.update_details(filter, update)
if data:
logger.info("database updated")
else:
return None
except Exception as e:
logger.error(f"error from handler {e}")
return None
@staticmethod
def fetch_tag_details(details):
try:
logger.info("fetching the tag details.....")
# fetching the tag details
except Exception as e:
logger.error(f"error from handler {e}")
......@@ -4,7 +4,7 @@ from scripts.constants.db_constants import DatabaseConstants
from scripts.database.mongodb import CollectionBaseClass, mongo_client
from scripts.database.mongodb.asset_manager import database
from scripts.logging.logger import logger
from scripts.schemas.test_schema import TestUpdate
from scripts.schemas.tag_schema import TestUpdate
from scripts.utils.mongo_utils import MongoStageCreator
collection_name = DatabaseConstants.collection
......@@ -19,32 +19,25 @@ class Devices(CollectionBaseClass):
collection=collection_name
)
def update_name(self, mac):
# Construct the filter to match the document with the given _id
filter = {"mac_address": mac}
# Construct the update document to set the customer field to "ARJUN B"
update = {"customer": "ARJUN B"}
# Call the update_one method to update the document
result = self.update_one(filter, update)
# Print the number of documents updated
print(result.modified_count)
# def update_db(self, data: TestUpdate) -> Any:
# """
# :param mac_address:
# :return:
# """
# try:
# logger.info("entered check_mac_address function. devices.py")
# # self.update_one({"mac_address": mac_address}, {"$set":
# # {"customer": "Arjun B"}})
# self.update_one(query={"mac_address": data.mac}, data={"customer": "Arjun B"})
# # Device with mac_address already exists
#
# except Exception as e:
# logger.error(f"error from check_mac_address() - {e}")
# return False
def update_details(self, filter, update):
try:
logger.info("Update name method called")
# Call the update_one method to update the document
result = self.update_one(filter, update)
if result:
return result.modified_count
return None
except Exception as e:
logger.error(f"error from device.py {e}")
return None
def create_tag(self, filter, update):
try:
logger.info("creating new tag")
result = self.update_one(filter, update)
if result:
return result.modified_count
return None
except Exception as e:
logger.error(f"error from creating new tag {e}")
......@@ -3,3 +3,7 @@ from pydantic import BaseModel
class TestUpdate(BaseModel):
mac: str
country: str
state: str
vendor: str
customer: str
......@@ -2,12 +2,14 @@ import logging
from fastapi import APIRouter, Request
from scripts.constants.api import APIEndPoints
from scripts.core.handlers.device_handler import AssetHandler
from scripts.database.mongodb.asset_manager.collections.device import Devices
from scripts.logging.logger import logger
from scripts.schemas.test_schema import TestUpdate
from scripts.schemas.tag_schema import TestUpdate
router = APIRouter()
obj = Devices()
Asset_obj = AssetHandler()
@router.post(APIEndPoints.api_create, tags=["tag api"])
......@@ -25,7 +27,20 @@ async def store_tag():
async def update_db(data: TestUpdate):
try:
logger.info("update method called")
obj.update_name(data.mac)
print(data)
Asset_obj.update_db(data)
return {"data": "updated"}
except Exception as e:
logger.error(f"error from asset management.py {e}")
return None
@router.post(APIEndPoints.create_tag, tags=["creating tags"])
async def tag_creation():
try:
logger.info("creating new tag api called")
Asset_obj.fetch_tag_details()
return {"data": "tag created"}
except Exception as e:
logger.error(f"error from tag creation api {e}")
return None
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment