Skip to content

Commit

Permalink
update dockerfile to python 3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
ck-c8y committed Jan 27, 2025
1 parent ef96986 commit dbd7155
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
5 changes: 3 additions & 2 deletions analytics-service/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ RUN git clone --depth 1 https://github.com/Cumulocity-IoT/apama-analytics-builde

# Install Python dependencies
COPY requirements.txt /apama_work/
RUN pip3 install --no-cache-dir -r requirements.txt
# RUN pip3 install --no-cache-dir -r requirements.txt
RUN /usr/local/bin/pip3.10 install --no-cache-dir -r requirements.txt

# Copy application files
COPY flask_wrapper.py c8y_agent.py /apama_work/

# Set the default command
CMD ["python3", "flask_wrapper.py"]
CMD ["/usr/local/bin/python3.10", "flask_wrapper.py"]
49 changes: 35 additions & 14 deletions analytics-service/c8y_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,24 +119,36 @@ def get_cep_ctrl_status(self, request) -> Dict:
return self._get_tenant_instance(headers).get(
resource=self.PATHS['CEP_DIAGNOSTICS']
)
def _process_repository_data(self, repo_data: Union[Dict, str], repository_id: str = None) -> Dict:

def _process_repository_data(self, repo_data: Union[Dict, str, 'TenantOption'], repository_id: str = None) -> Dict:
"""
Process repository data into standard format.
Args:
repo_data: Repository data as either a dictionary or JSON string
repo_data: Repository data as either a dictionary, JSON string, or TenantOption
repository_id: Optional repository ID
Returns:
Dictionary containing processed repository data
"""
try:
# Handle TenantOption input
if hasattr(repo_data, 'value'):
try:
value_dict = json.loads(repo_data.value)
except json.JSONDecodeError:
return {
"id": repository_id or repo_data.key,
"name": repo_data.value, # Use the value as name
"url": "",
"accessToken": "",
"enabled": False
}
# Handle string input
if isinstance(repo_data, str):
elif isinstance(repo_data, str):
try:
value_dict = json.loads(repo_data)
except json.JSONDecodeError:
# If the string is not valid JSON, return a basic dict with default values
return {
"id": repository_id,
"name": repo_data, # Use the string as name
Expand Down Expand Up @@ -171,22 +183,31 @@ def _process_repository_data(self, repo_data: Union[Dict, str], repository_id: s

def load_repositories(self, request) -> List[Dict]:
headers = self.prepare_header(request)
# tenant_options = self.c8yapp.get_tenant_instance(headers).tenant_options.get_all(category=self.ANALYTICS_MANAGEMENT_REPOSITORIES)

response = self._get_tenant_instance(headers).get(
f"{self.PATHS['TENANT_OPTIONS']}/{self.ANALYTICS_MANAGEMENT_REPOSITORIES}"
)
tenant = self._get_tenant_instance(headers)
tenant_options = tenant.tenant_options.get_all(
category=self.ANALYTICS_MANAGEMENT_REPOSITORIES
)
return [
self._process_repository_data(response[repo_id], repo_id)
for repo_id in response
self._process_repository_data(option, option.key)
for option in tenant_options
]

def load_repository(self, request, repository_id: str) -> Dict:
headers = self.prepare_header(request)
response = self._get_tenant_instance(headers).get(
f"{self.PATHS['TENANT_OPTIONS']}/{self.ANALYTICS_MANAGEMENT_REPOSITORIES}/{repository_id}"
tenant = self._get_tenant_instance(headers)
tenant_option = tenant.tenant_options.get(
category=self.ANALYTICS_MANAGEMENT_REPOSITORIES,
key=repository_id
)
return self._process_repository_data(response, repository_id)
# Print various attributes of the TenantOption object
print(f"TenantOption contents:")
print(f"Category: {tenant_option.category}")
print(f"Key: {tenant_option.key}")
print(f"Value: {tenant_option.value}")

# Print the entire object
print(f"Complete TenantOption object: {vars(tenant_option)}")
return self._process_repository_data(tenant_option, repository_id)

def update_repositories(self, request, repositories: List[Dict]) -> Tuple[Dict, int]:
try:
Expand Down

0 comments on commit dbd7155

Please sign in to comment.