Skip to content

Commit

Permalink
merge master into add-getters-for-pricing-plan-and-unit
Browse files Browse the repository at this point in the history
  • Loading branch information
bisgaard-itis committed Oct 18, 2023
2 parents 667b60a + 1d2dc5a commit cc7e543
Show file tree
Hide file tree
Showing 188 changed files with 4,895 additions and 2,202 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ exclude_lines =
if __name__ == .__main__.:

# Don't complain about abstract methods, they aren't run:
@(abc\.)?abstractmethod
@(abc\.)?abstract(((class|static)?method)|property)

ignore_errors = True
show_missing = True
5 changes: 4 additions & 1 deletion .env-devel
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ REGISTRY_USER=admin

# NOTE: 172.17.0.1 is the docker0 interface, which redirect from inside a container onto the host network interface.
R_CLONE_PROVIDER=MINIO
R_CLONE_OPTION_TRANSFERS=5
R_CLONE_OPTION_RETRIES=3
R_CLONE_OPTION_BUFFER_SIZE=0M
S3_ACCESS_KEY=12345678
S3_BUCKET_NAME=simcore
S3_ENDPOINT=172.17.0.1:9001
Expand All @@ -117,7 +120,7 @@ S3_SECURE=0
SCICRUNCH_API_BASE_URL=https://scicrunch.org/api/1
SCICRUNCH_API_KEY=REPLACE_ME_with_valid_api_key

SMTP_HOST=mail.speag.com
SMTP_HOST=fake.mail.server.com
SMTP_PORT=25
SMTP_USERNAME=it_doesnt_matter
SMTP_PASSWORD=it_doesnt_matter
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci-testing-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@ jobs:
with:
version: ${{ matrix.docker_buildx }}
driver: docker-container
- uses: actions/[email protected].0
- uses: actions/[email protected].1
with:
node-version: ${{ matrix.node }}
cache: "npm"
Expand Down Expand Up @@ -1993,7 +1993,7 @@ jobs:
python-version: ${{ matrix.python }}
cache: "pip"
cache-dependency-path: "tests/e2e/requirements/requirements.txt"
- uses: actions/[email protected].0
- uses: actions/[email protected].1
with:
node-version: ${{ matrix.node }}
cache: "npm"
Expand Down
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,17 @@ CPU_COUNT = $(shell cat /proc/cpuinfo | grep processor | wc -l )
services/docker-compose.local.yml \
> $@


.stack-simcore-development-frontend.yml: .env $(docker-compose-configs)
# Creating config for stack with 'local/{service}:production' (except of static-webserver -> static-webserver:development) to $@
@export DOCKER_REGISTRY=local && \
export DOCKER_IMAGE_TAG=production && \
scripts/docker/docker-compose-config.bash -e $< \
services/docker-compose.yml \
services/docker-compose.local.yml \
services/docker-compose.devel-frontend.yml \
> $@

.stack-simcore-version.yml: .env $(docker-compose-configs)
# Creating config for stack with '$(DOCKER_REGISTRY)/{service}:${DOCKER_IMAGE_TAG}' to $@
@scripts/docker/docker-compose-config.bash -e .env \
Expand Down Expand Up @@ -342,6 +353,15 @@ up-devel: .stack-simcore-development.yml .init-swarm $(CLIENT_WEB_OUTPUT) ## Dep
@$(_show_endpoints)
@$(MAKE_C) services/static-webserver/client follow-dev-logs

up-devel-frontend: .stack-simcore-development-frontend.yml .init-swarm ## Every service in production except static-webserver. For front-end development
# Start compile+watch front-end container [front-end]
@$(MAKE_C) services/static-webserver/client down compile-dev flags=--watch
# Deploy stack $(SWARM_STACK_NAME) [back-end]
@docker stack deploy --with-registry-auth -c $< $(SWARM_STACK_NAME)
@$(MAKE) .deploy-ops
@$(_show_endpoints)
@$(MAKE_C) services/static-webserver/client follow-dev-logs


up-prod: .stack-simcore-production.yml .init-swarm ## Deploys local production stack and ops stack (pass 'make ops_disabled=1 ops_ci=1 up-...' to disable or target=<service-name> to deploy a single service)
ifeq ($(target),)
Expand Down
32 changes: 19 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@
<!------------------------------------------------------------------------------------------>





The SIM-CORE, named **o<sup>2</sup>S<sup>2</sup>PARC****O**pen **O**nline **S**imulations for **S**timulating **P**eripheral **A**ctivity to **R**elieve **C**onditions – is one of the three integrative cores of the SPARC program’s Data Resource Center (DRC).
The aim of o<sup>2</sup>S<sup>2</sup>PARC is to establish a comprehensive, freely accessible, intuitive, and interactive online platform for simulating peripheral nerve system neuromodulation/ stimulation and its impact on organ physiology in a precise and predictive manner.
To achieve this, the platform will comprise both state-of-the art and highly detailed animal and human anatomical models with realistic tissue property distributions that make it possible to perform simulations ranging from the molecular scale up to the complexity of the human body.

## Getting Started

This is the common workflow to build and deploy locally:
A production instance of **o<sup>2</sup>S<sup>2</sup>PARC** is running at [oSPARC.io](https://osparc.io).

If you want to spin up your own instance, you can follow the common workflow to build and deploy locally using the **Linux commandline** (Ubuntu recommended).
Make sure you first install all the [requirements](#Requirements) mentioned in the section below.

```bash
# clone repo
# clone code repository
git clone https://github.com/ITISFoundation/osparc-simcore.git
cd osparc-simcore

Expand Down Expand Up @@ -69,12 +69,9 @@ Services are deployed in two stacks:``simcore-stack`` comprises all core-service

### Requirements

To verify current base OS, Docker and Python build versions have a look at:

- GitHub Actions [config](.github/workflows/ci-testing-deploy.yml)

To build and run:

- git
- docker
- make >=4.2
- awk, jq (optional tools within makefiles)
Expand All @@ -86,17 +83,26 @@ To develop, in addition:
- swagger-cli (make sure to have a recent version of nodejs)
- [vscode] (highly recommended)

This project works and is developed under **linux (Ubuntu recommended)**.
To verify current base OS, Docker and Python build versions have a look at:

- GitHub Actions [config](.github/workflows/ci-testing-deploy.yml)

If you want to verify if your system has all the necessary requirements:

```bash
make info
```


#### Setting up Other Operating Systems
#### Setting up other Operating Systems

When developing on these platforms you are on your own.

In **windows**, it works under [WSL2] (windows subsystem for linux **version2**). Some details on the setup:
On **Windows**, it works under [WSL2] (Windows Subsystem for Linux **version2**). Some details on the setup:

- Follow **all details** on [how to setup WSL2 with docker and ZSH](https://nickymeuleman.netlify.app/blog/linux-on-windows-wsl2-zsh-docker) docker for windows and [WSL2]

In **MacOS**, [replacing the MacOS utilities with GNU utils](https://apple.stackexchange.com/a/69332) might be required.
**MacOS** is currently not supported.

#### Upgrading services requirements

Expand Down
18 changes: 15 additions & 3 deletions api/specs/web-server/_products.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
# pylint: disable=unused-variable


from fastapi import APIRouter
from typing import Annotated

from fastapi import APIRouter, Depends
from models_library.api_schemas_webserver.product import (
CreditPriceGet,
GenerateInvitation,
GetCreditPrice,
GetProduct,
InvitationGenerated,
)
from models_library.generics import Envelope
from simcore_service_webserver._meta import API_VTAG
from simcore_service_webserver.products._handlers import _ProductsRequestParams

router = APIRouter(
prefix=f"/{API_VTAG}",
Expand All @@ -24,12 +28,20 @@

@router.get(
"/credits-price",
response_model=Envelope[CreditPriceGet],
response_model=Envelope[GetCreditPrice],
)
async def get_current_product_price():
...


@router.get(
"/products/{product_name}",
response_model=Envelope[GetProduct],
)
async def get_product(_params: Annotated[_ProductsRequestParams, Depends()]):
...


@router.post(
"/invitation:generate",
response_model=Envelope[InvitationGenerated],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Any, ClassVar, TypeAlias

from models_library.resource_tracker import HardwareInfo, PricingInfo
from pydantic import BaseModel, ByteSize, Field

from ..services import ServicePortKey
Expand Down Expand Up @@ -46,6 +47,14 @@ class DynamicServiceCreate(ServiceDetails):
default=None,
description="contains information about the wallet used to bill the running service",
)
pricing_info: PricingInfo | None = Field(
default=None,
description="contains pricing information (ex. pricing plan and unit ids)",
)
hardware_info: HardwareInfo | None = Field(
default=None,
description="contains harware information (ex. aws_ec2_instances)",
)

class Config:
schema_extra: ClassVar[dict[str, Any]] = {
Expand All @@ -62,6 +71,8 @@ class Config:
"examples"
][0],
"wallet_info": WalletInfo.Config.schema_extra["examples"][0],
"pricing_info": PricingInfo.Config.schema_extra["examples"][0],
"hardware_info": HardwareInfo.Config.schema_extra["examples"][0],
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from ._base import InputSchema, OutputSchema


class CreditPriceGet(OutputSchema):
class GetCreditPrice(OutputSchema):
product_name: str
usd_per_credit: NonNegativeDecimal | None = Field(
...,
Expand All @@ -26,18 +26,40 @@ class Config(OutputSchema.Config):
}


class GetProduct(OutputSchema):
name: ProductName
display_name: str
short_name: str | None = Field(
default=None, description="Short display name for SMS"
)

vendor: dict | None = Field(default=None, description="vendor attributes")
issues: list[dict] | None = Field(
default=None, description="Reference to issues tracker"
)
manuals: list[dict] | None = Field(default=None, description="List of manuals")
support: list[dict] | None = Field(
default=None, description="List of support resources"
)

login_settings: dict
max_open_studies_per_user: PositiveInt | None
is_payment_enabled: bool
credits_per_usd: NonNegativeDecimal | None


class GenerateInvitation(InputSchema):
guest: LowerCaseEmailStr
trial_account_days: PositiveInt | None = None
extra_credits: PositiveInt | None = None
extra_credits_in_usd: PositiveInt | None = None


class InvitationGenerated(OutputSchema):
product_name: ProductName
issuer: LowerCaseEmailStr
guest: LowerCaseEmailStr
trial_account_days: PositiveInt | None = None
extra_credits: PositiveInt | None = None
extra_credits_in_usd: PositiveInt | None = None
created: datetime
invitation_link: HttpUrl

Expand All @@ -49,7 +71,7 @@ class Config(OutputSchema.Config):
"issuer": "[email protected]",
"guest": "[email protected]",
"trialAccountDays": 7,
"extraCredits": 30,
"extraCreditsInUsd": 30,
"created": "2023-09-27T15:30:00",
"invitationLink": "https://example.com/invitation#1234",
},
Expand Down
4 changes: 2 additions & 2 deletions packages/models-library/src/models_library/invitations.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class InvitationInputs(BaseModel):
description="If set, this invitation will activate a trial account."
"Sets the number of days from creation until the account expires",
)
extra_credits: PositiveInt | None = Field(
extra_credits_in_usd: PositiveInt | None = Field(
None,
description="If set, the account's primary wallet will add these extra credits",
description="If set, the account's primary wallet will add extra credits corresponding to this ammount in USD",
)


Expand Down
38 changes: 36 additions & 2 deletions packages/models-library/src/models_library/resource_tracker.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import auto
from typing import TypeAlias
from typing import Any, ClassVar, NamedTuple, TypeAlias

from pydantic import PositiveInt
from pydantic import BaseModel, PositiveInt

from .utils.enums import StrAutoEnum

Expand Down Expand Up @@ -37,3 +37,37 @@ class CreditClassification(StrAutoEnum):

class PricingPlanClassification(StrAutoEnum):
TIER = auto()


class PricingInfo(BaseModel):
pricing_plan_id: PricingPlanId
pricing_unit_id: PricingUnitId
pricing_unit_cost_id: PricingUnitCostId

class Config:
schema_extra: ClassVar[dict[str, Any]] = {
"examples": [
{"pricing_plan_id": 1, "pricing_unit_id": 1, "pricing_unit_cost_id": 1}
]
}


class HardwareInfo(BaseModel):
aws_ec2_instances: list[str]

class Config:
schema_extra: ClassVar[dict[str, Any]] = {
"examples": [{"aws_ec2_instances": ["c6a.4xlarge"]}]
}


class PricingAndHardwareInfoTuple(NamedTuple):
pricing_plan_id: PricingPlanId
pricing_unit_id: PricingUnitId
current_cost_per_unit_id: PricingUnitCostId
aws_ec2_instances: list[str]


class PricingPlanAndUnitIdsTuple(NamedTuple):
pricing_plan_id: PricingPlanId
pricing_unit_id: PricingUnitId
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""migration of aws_ec2_instances data in pricing units
Revision ID: 5c62b190e124
Revises: 7777d181dc1f
Create Date: 2023-10-17 05:15:29.780925+00:00
"""
from alembic import op
from simcore_postgres_database.models.resource_tracker_pricing_units import (
resource_tracker_pricing_units,
)

# revision identifiers, used by Alembic.
revision = "5c62b190e124"
down_revision = "7777d181dc1f"
branch_labels = None
depends_on = None


def upgrade():
# One time migration to populate specific info with some reasonable value, it will be changed manually based on concrete needs
op.execute(
resource_tracker_pricing_units.update().values(
specific_info={"aws_ec2_instances": ["t3.medium"]}
)
)


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
pass
# ### end Alembic commands ###
Loading

0 comments on commit cc7e543

Please sign in to comment.