Skip to content

Commit

Permalink
initialized a lot
Browse files Browse the repository at this point in the history
  • Loading branch information
jhnnsrs committed Jun 24, 2024
1 parent 88a4931 commit 959639f
Show file tree
Hide file tree
Showing 26 changed files with 411 additions and 125 deletions.
4 changes: 4 additions & 0 deletions bridge/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ class HistoryAdmin(SimpleHistoryAdmin): # type: ignore


admin.site.register(models.Repo, HistoryAdmin)
admin.site.register(models.Definition)
admin.site.register(models.Release)
admin.site.register(models.Deployment)
admin.site.register(models.Pod)
57 changes: 46 additions & 11 deletions bridge/inputs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from pydantic import BaseModel
import datetime
from pydantic import BaseModel, Field
from strawberry.experimental import pydantic
from .enums import PodStatus, ContainerType
import strawberry
from rekuest_core.scalars import NodeHash
from typing import Dict, Optional
from bridge import scalars


class ScanRepoInputModel(BaseModel):
Expand Down Expand Up @@ -95,9 +99,25 @@ class DeploySetupInput:
setup: strawberry.ID





class DeviceFeatureModel(BaseModel):
kind: str
cpu_count: str


class EnvironmentInputModel(BaseModel):
container_type: ContainerType
nodes: Optional[list[str]]
release: Optional[str] = None
fits: list[DeviceFeatureModel]


@pydantic.input(DeviceFeatureModel, description="The Feature you are trying to match")
class DeviceFeature:
kind: str
cpu_count: str

@pydantic.input(
EnvironmentInputModel, description="Which environment do you want to match against?"
Expand All @@ -106,13 +126,15 @@ class EnvironmentInput:
"""Which environment do you want to match against?"""

container_type: ContainerType
features: Optional[list[DeviceFeature]]


class MatchFlavoursInputModel(BaseModel):
"""Create a new Github repository input model"""

environment: EnvironmentInputModel
environment: EnvironmentInputModel | None = None
release: strawberry.ID | None = None
nodes: Optional[list[str]]


@pydantic.input(
Expand All @@ -121,12 +143,14 @@ class MatchFlavoursInputModel(BaseModel):
class MatchFlavoursInput:
"""Create a new Github repository input"""

environment: strawberry.ID
release: strawberry.ID | None = None
environment: EnvironmentInput | None = None
nodes: Optional[list[NodeHash]]
release: Optional[strawberry.ID]


class CreatePodInputModel(BaseModel):
deployment: strawberry.ID
local_id: strawberry.ID
instance_id: str


Expand All @@ -135,39 +159,50 @@ class CreatePodInput:
"""Create a new Github repository input"""

deployment: strawberry.ID
local_id: strawberry.ID
instance_id: str


class UpdatePodInputModel(BaseModel):
"""Create a new Github repository input model"""

pod: strawberry.ID
pod: strawberry.ID | None
local_id: strawberry.ID | None
status: str
instance_id: str



@pydantic.input(UpdatePodInputModel, description="Create a new Github repository input")
class UpdatePodInput:
"""Create a new Github repository input"""

pod: strawberry.ID
pod: strawberry.ID | None
local_id: strawberry.ID | None
status: PodStatus
instance_id: str



class CreateDeploymentInputModel(BaseModel):
"""Create a new Github repository input model"""
instance_id: strawberry.ID
flavour: strawberry.ID
pulled: bool = False
instance_id: str
local_id: str
flavour: str
last_pulled: datetime.datetime | None = None
secret_params: Dict[str, str] | None


@pydantic.input(
CreateDeploymentInputModel, description="Create a new Github repository input"
)
class CreateDeploymentInput:
"""Create a new Github repository input"""
instance_id: strawberry.ID
instance_id: str
local_id: strawberry.ID
flavour: strawberry.ID
pulled: bool | None = False
last_pulled: datetime.datetime | None = None
secret_params: scalars.UntypedParams | None = None


class UpdateDeploymentInputModel(BaseModel):
Expand Down
16 changes: 16 additions & 0 deletions bridge/migrations/0002_remove_flavour_build_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated by Django 4.2.9 on 2024-06-24 10:17

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("bridge", "0001_initial"),
]

operations = [
migrations.RemoveField(
model_name="flavour",
name="build_id",
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 4.2.9 on 2024-06-24 13:47

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("bridge", "0002_remove_flavour_build_id"),
]

operations = [
migrations.RemoveField(
model_name="deployment",
name="api_token",
),
migrations.AddField(
model_name="deployment",
name="secret_params",
field=models.JSONField(default=dict),
),
migrations.AddField(
model_name="deployment",
name="untyped_params",
field=models.JSONField(default=dict),
),
]
20 changes: 20 additions & 0 deletions bridge/migrations/0004_deployment_local_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 4.2.9 on 2024-06-24 13:48

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
(
"bridge",
"0003_remove_deployment_api_token_deployment_secret_params_and_more",
),
]

operations = [
migrations.AddField(
model_name="deployment",
name="local_id",
field=models.CharField(default="unset", max_length=2000),
),
]
21 changes: 14 additions & 7 deletions bridge/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,19 @@ def manifest_url(self) -> str:
return f"https://raw.githubusercontent.com/{self.user}/{self.repo}/{self.branch}/.arkitekt/manifest.yaml"

@property
def deployments_url(self) -> str:
return self.build_deployments_url(self.user, self.repo, self.branch)
def kabinet_url(self) -> str:
return self.build_kabinet_url(self.user, self.repo, self.branch)

@classmethod
def build_deployments_url(cls, user: str, repo: str, branch: str) -> str:
return f"https://raw.githubusercontent.com/{user}/{repo}/{branch}/.arkitekt/deployments.yaml"
def build_kabinet_url(cls, user: str, repo: str, branch: str) -> str:
return f"https://raw.githubusercontent.com/{user}/{repo}/{branch}/.arkitekt/kabinet.yaml"

class Config:
constraints = [
models.UniqueConstraint(
fields=["repo", "user", "branch"], name="Unique repo for url"
)
]


class App(models.Model):
Expand Down Expand Up @@ -77,7 +84,6 @@ class Flavour(models.Model):
)
name = models.CharField(max_length=400)
deployment_id = models.CharField(max_length=400, unique=True, default=uuid.uuid4)
build_id = models.CharField(max_length=400, default=uuid.uuid4)
flavour = models.CharField(max_length=400, default="vanilla")
selectors = models.JSONField(default=list)
repo = models.ForeignKey(Repo, on_delete=models.CASCADE, related_name="flavours")
Expand Down Expand Up @@ -218,9 +224,10 @@ class Deployment(models.Model):
)
backend = models.ForeignKey(Backend, on_delete=models.CASCADE)
pulled = models.BooleanField(default=False)
api_token = models.CharField(max_length=1000)

secret_params = models.JSONField(default=dict)
untyped_params = models.JSONField(default=dict)
created_at = models.DateTimeField(auto_now=True)
local_id = models.CharField(max_length=2000, default="unset")


class Pod(models.Model):
Expand Down
7 changes: 6 additions & 1 deletion bridge/mutations/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ async def create_deployment(

flavour = await models.Flavour.objects.aget(id=input.flavour)

deployment = await models.Deployment.objects.acreate(
deployment, _ = await models.Deployment.objects.aupdate_or_create(
flavour=flavour,
backend=backend,
local_id=input.local_id,
defaults={
"secret_params": input.secret_params or {}
}

)

return deployment
Expand Down
33 changes: 25 additions & 8 deletions bridge/mutations/pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@
import logging
from typing import List

from bridge.utils import get_backend_for_info
from bridge.utils import aget_backend_for_info

async def create_pod(info: Info, input: inputs.CreatePodInput) -> types.Pod:
"""Create a new dask cluster on a bridge server"""

backend = get_backend_for_info(info, input.instance_id)
backend = await aget_backend_for_info(info, input.instance_id)


flavour = models.Deployment.objects.get(id=input.deployment)
deployment = await models.Deployment.objects.aget(id=input.deployment)

pod = await models.Pod.objects.acreate(
pod, _ = await models.Pod.objects.aupdate_or_create(
backend=backend,
flavour=flavour,
pod_id=input.local_id,
defaults=dict(
deployment=deployment,
)
)

return pod
Expand All @@ -24,11 +27,25 @@ async def create_pod(info: Info, input: inputs.CreatePodInput) -> types.Pod:
async def update_pod(info: Info, input: inputs.UpdatePodInput) -> types.Pod:
"""Create a new dask cluster on a bridge server"""

pod = await models.Pod.objects.get(id=input.id)
backend = await aget_backend_for_info(info, input.instance_id)

pod.status = input.status
if not input.pod and not input.local_id:
raise ValueError("Either pod or local_id must be set")

if input.local_id:
pod = await models.Pod.objects.aget(
backend=backend,
pod_id=input.local_id,
)

if input.pod:
pod = await models.Pod.objects.aget(
id=input.pod
)

await pod.save()

pod.status = input.status
await pod.asave()

return pod

Expand Down
Loading

0 comments on commit 959639f

Please sign in to comment.