Skip to content

Commit 75ce854

Browse files
committed
feat(fusion): add upgrade shared tier command
1 parent e08a6cf commit 75ce854

File tree

2 files changed

+131
-1
lines changed

2 files changed

+131
-1
lines changed

singlestoredb/fusion/handlers/workspace.py

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
from typing import Dict
55
from typing import Optional
66

7+
from singlestoredb.management.workspace import StarterWorkspace
8+
79
from .. import result
810
from ..handler import SQLHandler
911
from ..result import FusionSQLResult
10-
from .utils import dt_isoformat
12+
from .utils import dt_isoformat, get_deployment
1113
from .utils import get_workspace
1214
from .utils import get_workspace_group
1315
from .utils import get_workspace_manager
@@ -889,3 +891,90 @@ def run(self, params: Dict[str, Any]) -> Optional[FusionSQLResult]:
889891

890892

891893
DropWorkspaceHandler.register(overwrite=True)
894+
895+
class UpgradeVirtualWorkspaceHandler(SQLHandler):
896+
"""
897+
UPGRADE SHAREDTIER { virtual_workspace_name | virtual_workspace_id }
898+
[ new_workspace_name ]
899+
[ size ]
900+
[ new_workspace_group_name ]
901+
[ region_id ]
902+
903+
# Name of the virtual workspace to upgrade
904+
virtual_workspace_name = '<virtual-workspace-name>'
905+
906+
# ID of the virtual workspace to upgrade
907+
virtual_workspace_id = ID '<virtual-workspace-id>'
908+
909+
# New name for the upgraded workspace
910+
new_workspace_name = 'AS <new-workspace-name>'
911+
912+
# Runtime size
913+
size = 'WITH SIZE <size>'
914+
915+
# New workspace group name
916+
new_workspace_group_name = 'TO <new-workspace-group-name>'
917+
918+
# Region to create the new workspace group in
919+
region_id = 'IN REGION <region-id>'
920+
921+
Description
922+
-----------
923+
Upgrade a SharedTier Workspace to a dedicated Cluster. Refer to
924+
`Upgrading from SharedTier <TODO: GET LINK/>`_
925+
for more information.
926+
927+
Arguments
928+
---------
929+
* ``<virtual_workspace_name>``: The name of the virtual workspace to upgrade.
930+
* ``<virtual_workspace_id>``: The ID of the virtual workspace to upgrade.
931+
* ``<new_workspace_name>``: The name of the new workspace to create.
932+
* ``<size>``: The size of the new workspace in workspace size notation,
933+
for example "S-1".
934+
* ``<new_workspace_group_name>``: The name of the new workspace group to create.
935+
* ``<region_id>``: The ID of the region in which to create the new workspace group.
936+
937+
Remarks
938+
-------
939+
* By omition the new workspace will be created in the first region available.
940+
941+
Example
942+
-------
943+
The following command upgrades a virtual workspace named **strater-workspace** to a workspace
944+
named **workspace** with size **S-2** in a new workspace group named **wsgroup**::
945+
946+
UPGRADE SHAREDTIER "strater-workspace"
947+
AS "workspace"
948+
WITH SIZE "S-2"
949+
TO "wsgroup"
950+
951+
"""
952+
953+
def run(self, params: Dict[str, Any]) -> Optional[FusionSQLResult]:
954+
955+
search_params = { }
956+
if params['virtual_workspace_name']:
957+
search_params['deployment_name'] = params['virtual_workspace_name']
958+
elif params['virtual_workspace_id']:
959+
search_params['deployment_id'] = params['virtual_workspace_id']
960+
else:
961+
raise ValueError('either virtual_workspace_name or virtual_workspace_id must be specified')
962+
963+
virtual_workspace = get_deployment(search_params)
964+
965+
if not isinstance(virtual_workspace, StarterWorkspace):
966+
raise ValueError(
967+
'Starter workspace not found',
968+
)
969+
970+
virtual_workspace.upgrade(
971+
new_workspace_name=params['new_workspace_name'],
972+
size=params['size'],
973+
new_workspace_group_name=params['new_workspace_group_name'],
974+
region_id=params['region_id'],
975+
)
976+
977+
return None
978+
979+
980+
UpgradeVirtualWorkspaceHandler.register(overwrite=True)

singlestoredb/management/workspace.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,6 +1386,47 @@ def starter_workspaces(self) -> NamedList[StarterWorkspace]:
13861386
[StarterWorkspace.from_dict(item, self._manager) for item in res.json()],
13871387
)
13881388

1389+
def upgrade(
1390+
self,
1391+
new_workspace_name: Optional [str] = None,
1392+
size: Optional [str] = None,
1393+
new_workspace_group_name: Optional[str] = None,
1394+
region_id: Optional[str] = None,
1395+
) -> Workspace:
1396+
"""
1397+
Upgrade the starter workspace to a new workspace in a dedicated cluster.
1398+
1399+
Parameters
1400+
----------
1401+
new_workspace_name : str
1402+
Name of the new workspace
1403+
size : str
1404+
Size of the new workspace in workspace size notation (S-00, S-1, etc.)
1405+
new_workspace_group_name : str
1406+
Name of the new workspace group
1407+
region_id : str
1408+
ID of the region where the new workspace group should be created
1409+
1410+
Returns
1411+
-------
1412+
:class:`Workspace`
1413+
1414+
"""
1415+
if self._manager is None:
1416+
raise ManagementError(
1417+
msg='No workspace manager is associated with this object.',
1418+
)
1419+
return self._manager._post(
1420+
f'sharedtier/virtualWorkspaces/{self.id}/upgrade',
1421+
json={
1422+
'name': new_workspace_name,
1423+
'customWorkspaceSize': size,
1424+
'workspaceGroup': {
1425+
'name': new_workspace_group_name,
1426+
'regionID': region_id,
1427+
},
1428+
},
1429+
).json()
13891430

13901431
class Billing(object):
13911432
"""Billing information."""

0 commit comments

Comments
 (0)