# See the License for the specific language governing permissions and\r
# limitations under the License.\r
\r
-from sqlalchemy import select\r
+import uuid\r
\r
-from o2ims.adapter.orm import ocloud, resource, resourcetype, \\r
- resourcepool, deploymentmanager, subscription\r
-from o2ims.adapter import unit_of_work\r
+from o2common.service import unit_of_work\r
+from o2ims.views.ocloud_dto import SubscriptionDTO\r
from o2ims.domain.ocloud import Subscription\r
\r
\r
-def oclouds(uow: unit_of_work.SqlAlchemyUnitOfWork):\r
+def oclouds(uow: unit_of_work.AbstractUnitOfWork):\r
with uow:\r
- res = uow.session.execute(select(ocloud))\r
- return [dict(r) for r in res]\r
+ li = uow.oclouds.list()\r
+ return [r.serialize() for r in li]\r
\r
\r
def ocloud_one(ocloudid: str, uow: unit_of_work.AbstractUnitOfWork):\r
with uow:\r
- res = uow.session.execute(\r
- select(ocloud).where(ocloud.c.oCloudId == ocloudid))\r
- first = res.first()\r
- return None if first is None else dict(first)\r
+ first = uow.oclouds.get(ocloudid)\r
+ return first.serialize() if first is not None else None\r
\r
\r
-def resource_types(uow: unit_of_work.SqlAlchemyUnitOfWork):\r
+def resource_types(uow: unit_of_work.AbstractUnitOfWork):\r
with uow:\r
- res = uow.session.execute(select(resourcetype))\r
- return [dict(r) for r in res]\r
+ li = uow.resource_types.list()\r
+ return [r.serialize() for r in li]\r
\r
\r
def resource_type_one(resourceTypeId: str,\r
- uow: unit_of_work.SqlAlchemyUnitOfWork):\r
+ uow: unit_of_work.AbstractUnitOfWork):\r
with uow:\r
- res = uow.session.execute(select(resourcetype).where(\r
- resourcetype.c.resourceTypeId == resourceTypeId))\r
- first = res.first()\r
- return None if first is None else dict(first)\r
+ first = uow.resource_types.get(resourceTypeId)\r
+ print(first)\r
+ return first.serialize() if first is not None else None\r
\r
\r
-def resource_pools(uow: unit_of_work.SqlAlchemyUnitOfWork):\r
+def resource_pools(uow: unit_of_work.AbstractUnitOfWork):\r
with uow:\r
- res = uow.session.execute(select(resourcepool))\r
- return [dict(r) for r in res]\r
+ li = uow.resource_pools.list()\r
+ return [r.serialize() for r in li]\r
\r
\r
def resource_pool_one(resourcePoolId: str,\r
- uow: unit_of_work.SqlAlchemyUnitOfWork):\r
+ uow: unit_of_work.AbstractUnitOfWork):\r
with uow:\r
- res = uow.session.execute(select(resourcepool).where(\r
- resourcepool.c.resourcePoolId == resourcePoolId))\r
- first = res.first()\r
- return None if first is None else dict(first)\r
+ first = uow.resource_pools.get(resourcePoolId)\r
+ return first.serialize() if first is not None else None\r
\r
\r
-def resources(resourcePoolId: str, uow: unit_of_work.SqlAlchemyUnitOfWork):\r
+def resources(resourcePoolId: str, uow: unit_of_work.AbstractUnitOfWork):\r
with uow:\r
- res = uow.session.execute(select(resource).where(\r
- resource.c.resourcePoolId == resourcePoolId))\r
- return [dict(r) for r in res]\r
+ li = uow.resources.list(resourcePoolId)\r
+ return [r.serialize() for r in li]\r
\r
\r
-def resource_one(resourceId: str, uow: unit_of_work.SqlAlchemyUnitOfWork):\r
+def resource_one(resourceId: str, uow: unit_of_work.AbstractUnitOfWork):\r
with uow:\r
- # topq = uow.session.query(resource).filter(\r
- # resource.c.resourceId == resourceId).cte('cte', recursive=True)\r
- # bootomq = uow.session.query(resource).join(\r
- # topq, resource.c.parentId == topq.c.resourceId)\r
- # res = uow.session.query(topq.union(bootomq))\r
- # print(res)\r
- res = uow.session.execute(select(resource).where(\r
- resource.c.resourceId == resourceId))\r
- first = res.first()\r
- return None if first is None else dict(first)\r
-\r
-\r
-def deployment_managers(uow: unit_of_work.SqlAlchemyUnitOfWork):\r
+ first = uow.resources.get(resourceId)\r
+ return first.serialize() if first is not None else None\r
+\r
+\r
+def deployment_managers(uow: unit_of_work.AbstractUnitOfWork):\r
with uow:\r
- res = uow.session.execute(select(deploymentmanager))\r
- return [dict(r) for r in res]\r
+ li = uow.deployment_managers.list()\r
+ return [r.serialize() for r in li]\r
\r
\r
def deployment_manager_one(deploymentManagerId: str,\r
- uow: unit_of_work.SqlAlchemyUnitOfWork):\r
+ uow: unit_of_work.AbstractUnitOfWork):\r
with uow:\r
- res = uow.session.execute(select(deploymentmanager).where(\r
- deploymentmanager.c.deploymentManagerId == deploymentManagerId))\r
- first = res.first()\r
- return None if first is None else dict(first)\r
+ first = uow.deployment_managers.get(deploymentManagerId)\r
+ return first.serialize() if first is not None else None\r
\r
\r
-def subscriptions(uow: unit_of_work.SqlAlchemyUnitOfWork):\r
+def subscriptions(uow: unit_of_work.AbstractUnitOfWork):\r
with uow:\r
- res = uow.session.execute(select(subscription))\r
- return [dict(r) for r in res]\r
+ li = uow.subscriptions.list()\r
+ return [r.serialize() for r in li]\r
\r
\r
def subscription_one(subscriptionId: str,\r
- uow: unit_of_work.SqlAlchemyUnitOfWork):\r
+ uow: unit_of_work.AbstractUnitOfWork):\r
with uow:\r
- res = uow.session.execute(select(subscription).where(\r
- subscription.c.subscriptionId == subscriptionId))\r
- first = res.first()\r
- return None if first is None else dict(first)\r
+ first = uow.subscriptions.get(subscriptionId)\r
+ return first.serialize() if first is not None else None\r
+\r
\r
+def subscription_create(subscriptionDto: SubscriptionDTO.subscription,\r
+ uow: unit_of_work.AbstractUnitOfWork):\r
\r
-def subscription_create(subscription: Subscription,\r
- uow: unit_of_work.SqlAlchemyUnitOfWork):\r
+ sub_uuid = str(uuid.uuid4())\r
+ subscription = Subscription(\r
+ sub_uuid, subscriptionDto['callback'],\r
+ subscriptionDto['consumerSubscriptionId'],\r
+ subscriptionDto['filter'])\r
with uow:\r
uow.subscriptions.add(subscription)\r
uow.commit()\r
+ return {"subscriptionId": sub_uuid}\r
\r
\r
def subscription_delete(subscriptionId: str,\r
- uow: unit_of_work.SqlAlchemyUnitOfWork):\r
+ uow: unit_of_work.AbstractUnitOfWork):\r
with uow:\r
uow.subscriptions.delete(subscriptionId)\r
uow.commit()\r