1 # Copyright (C) 2021 Wind River Systems, Inc.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 from retry import retry
16 from sqlalchemy import (
31 from sqlalchemy.orm import mapper
32 from o2dms.domain import dms as dmsModel
34 from o2common.helper import o2logging
35 logger = o2logging.get_logger(__name__)
39 nfDeploymentDesc = Table(
42 Column("updatetime", DateTime),
43 Column("createtime", DateTime),
44 Column("hash", String(255)),
45 Column("version_number", Integer),
47 Column("id", String(255), primary_key=True),
48 Column("deploymentManagerId", String(255)),
49 Column("name", String(255)),
50 Column("description", String(255)),
51 Column("inputParams", Text()),
52 Column("outputParams", String(255)),
53 Column("artifactRepoUrl", String(255)),
54 Column("artifactName", String(255)),
55 # Column("extensions", String(1024))
61 Column("updatetime", DateTime),
62 Column("createtime", DateTime),
63 Column("hash", String(255)),
64 Column("version_number", Integer),
66 Column("id", String(255), primary_key=True),
67 Column("deploymentManagerId", String(255)),
68 Column("name", String(255)),
69 Column("description", String(255)),
70 Column("descriptorId", String(255)),
71 Column("parentDeploymentId", String(255)),
72 Column("status", Integer)
75 nfOCloudVResource = Table(
78 Column("updatetime", DateTime),
79 Column("createtime", DateTime),
80 Column("hash", String(255)),
81 Column("version_number", Integer),
83 Column("id", String(255), primary_key=True),
84 Column("deploymentManagerId", String(255)),
85 Column("name", String(255)),
86 Column("description", String(255)),
87 Column("descriptorId", String(255)),
88 Column("vresourceType", String(255)),
89 Column("status", Integer),
90 Column("metadata", String(2048)),
91 Column("nfDeploymentId", String(255))
95 @retry((exc.IntegrityError), tries=3, delay=2)
96 def wait_for_metadata_ready(engine):
97 # wait for mapper ready
98 metadata.create_all(engine, checkfirst=True)
99 logger.info("metadata is ready")
102 def start_o2dms_mappers(engine=None):
103 logger.info("Starting O2 DMS mappers")
105 mapper(dmsModel.NfDeploymentDesc, nfDeploymentDesc)
106 mapper(dmsModel.NfDeployment, nfDeployment)
107 mapper(dmsModel.NfOCloudVResource, nfOCloudVResource)
109 if engine is not None:
110 wait_for_metadata_ready(engine)