Skip to content

Commit

Permalink
Prep release 0.1.3 (#495)
Browse files Browse the repository at this point in the history
# Description

Cherry-picked the Function.schedule fix and  one-shot fix.


Changed CI to trigger for release to pypi on `release-0.1.3` so we do
not have to merge this one into the `release` branch.

**CAVEAT** Merging this branch will release `0.1.3` to pypi

## Checklist

- [ ] Tests added/updated.
- [ ] Run Demo Job Locally.
- [ ] Documentation updated.
- [ ] Changelogs updated in
[CHANGELOG.cdf-tk.md](https://github.com/cognitedata/cdf-project-templates/blob/main/CHANGELOG.cdf-tk.md).
- [ ] Template changelogs updated in
[CHANGELOG.templates.md](https://github.com/cognitedata/cdf-project-templates/blob/main/CHANGELOG.templates.md).
- [ ] Version bumped.

[_version.py](https://github.com/cognitedata/cdf-project-templates/blob/main/cognite/cognite_toolkit/_version.py)
and

[pyproject.toml](https://github.com/cognitedata/cdf-project-templates/blob/main/pyproject.toml)
per [semantic versioning](https://semver.org/).
  • Loading branch information
doctrino authored Apr 29, 2024
2 parents f01c8e1 + ce0bea7 commit 1da5f87
Show file tree
Hide file tree
Showing 29 changed files with 2,126 additions and 1,969 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name: Lint and test
on:
pull_request:
branches: [main, privatization]

env:
PYTHON_VERSION: '3.9'
jobs:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ on:
push:
branches:
- release
- release-0.1.3

env:
PYTHON_VERSION: '3.11'
jobs:
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.cdf-tk.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ Changes are grouped as follows:
- `Fixed` for any bug fixes.
- `Security` in case of vulnerabilities.

## [0.1.3] - 2024-04-28

### Fixed

- Functions that are deployed with schedules no longer uses a short-lived session (before: failed after ~an hour).
- When deploying a `FunctionSchedule` that requires an update, the `cdf-tk` would fail with error
`Failed to update functions.schedules. Error 'FunctionSchedulesAPI' object has no attribute 'update'.`.
This is now fixed.
- The dependency `cognite-sdk` must now be `>=7.37.0` to use the `cdf-tk`.

## [0.1.2] - 2024-03-18

### Fixed
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ Changes are grouped as follows:
- `Fixed` for any bug fixes.
- `Security` in case of vulnerabilities.

## [0.1.3] - 2024-04-29

### Fixed

- Updated module `apm_simple_data_model` for `cognite-sdk>=7.37`, i.e., container properties
of type `direct` have now `list: false` explicitly set.
- In `example_pump_data_model`, in the `Pump.view.yaml` the property `source` used `external_id` instead of `externalId`.

## [0.1.2] - 2024-03-18

No changes to templates.
Expand Down
68 changes: 24 additions & 44 deletions cognite_toolkit/_cdf_tk/load/_resource_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import itertools
import json
import re
from collections.abc import Iterable, Sequence
from collections.abc import Iterable, Sequence, Sized
from numbers import Number
from pathlib import Path
from time import sleep
Expand All @@ -25,8 +25,8 @@

import yaml
from cognite.client import CogniteClient
from cognite.client.credentials import OAuthClientCredentials
from cognite.client.data_classes import (
ClientCredentials,
DatapointsList,
DataSet,
DataSetList,
Expand Down Expand Up @@ -121,7 +121,6 @@
from cognite_toolkit._cdf_tk.utils import (
CDFToolConfig,
calculate_directory_hash,
get_oneshot_session,
load_yaml_inject_variables,
retrieve_view_ancestors,
)
Expand Down Expand Up @@ -638,50 +637,31 @@ def retrieve(self, ids: SequenceNotStr[str]) -> FunctionSchedulesList:

def create(self, items: FunctionScheduleWriteList) -> FunctionSchedulesList:
items = self._resolve_functions_ext_id(items)
(_, bearer) = self.client.config.credentials.authorization_header()
created = FunctionSchedulesList([])
created = []
for item in items:
if (
authentication := self.extra_configs.get(f"{item.function_external_id}:{item.cron_expression}", {}).get(
"authentication"
)
) is not None and len(authentication) > 0:
new_tool_config = CDFToolConfig()
old_credentials = cast(OAuthClientCredentials, new_tool_config.client.config.credentials)
new_tool_config.client.config.credentials = OAuthClientCredentials(
client_id=authentication.get("clientId"),
client_secret=authentication.get("clientSecret"),
scopes=old_credentials.scopes,
token_url=old_credentials.token_url,
)
session = get_oneshot_session(new_tool_config.client)
key = f"{item.function_external_id}:{item.cron_expression}"
auth_config = self.extra_configs.get(key, {}).get("authentication", {})
if "clientId" in auth_config and "clientSecret" in auth_config:
client_credentials = ClientCredentials(auth_config["clientId"], auth_config["clientSecret"])
else:
session = get_oneshot_session(self.client)
nonce = session.nonce if session is not None else ""
try:
ret = self.client.post(
url=f"/api/v1/projects/{self.client.config.project}/functions/schedules",
json={
"items": [
{
"name": item.name,
"description": item.description,
"cronExpression": item.cron_expression,
"functionId": item.function_id,
"data": item.data,
"nonce": nonce,
}
],
},
headers={"Authorization": bearer},
client_credentials = None

created.append(
self.client.functions.schedules.create(
name=item.name or "",
description=item.description or "",
cron_expression=cast(str, item.cron_expression),
function_id=cast(int, item.function_id),
data=item.data,
client_credentials=client_credentials,
)
except CogniteAPIError as e:
if e.code == 400 and "Failed to bind session" in e.message:
print(" [bold yellow]WARNING:[/] Failed to bind session because function is not ready.")
continue
if ret.status_code == 201:
created.append(FunctionSchedule.load(ret.json()["items"][0]))
return created
)
return FunctionSchedulesList(created)

def update(self, items: FunctionScheduleWriteList) -> Sized:
# Function schedule does not have an update, so we delete and recreate
self.delete(self.get_ids(items))
return self.create(items)

def delete(self, ids: SequenceNotStr[str]) -> int:
schedules = self.retrieve(ids)
Expand Down
2 changes: 1 addition & 1 deletion cognite_toolkit/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.2"
__version__ = "0.1.3"
2 changes: 1 addition & 1 deletion cognite_toolkit/cognite_modules/_system.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ packages:
- example_pump_data_model

# This part is used by cdf-toolkit to keep track of the version and help you upgrade.
cdf_toolkit_version: 0.1.2
cdf_toolkit_version: 0.1.3
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ properties:
nullable: true
type:
type: direct
list: false
sourceDb:
autoIncrement: false
defaultValue: null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,6 @@ properties:
type:
container: null
type: direct
list: false
space: '{{space}}'
usedFor: node
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ properties:
containerPropertyIdentifier: parent
name: liftStation
source:
external_id: LiftStation
externalId: LiftStation
space: '{{model_space}}'
version: '{{view_LiftStation_version}}'
DesignPointFlowGPM:
Expand Down
Loading

0 comments on commit 1da5f87

Please sign in to comment.