48 lines
2.0 KiB
Python
Raw Normal View History

2021-08-02 15:08:30 +05:30
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
2021-08-01 14:27:44 -07:00
from datetime import datetime, timedelta
from metadata.generated.schema.api.services.createDatabaseService import CreateDatabaseServiceEntityRequest
from metadata.generated.schema.entity.services.databaseService import DatabaseServiceEntity
from metadata.ingestion.ometa.client import REST
def get_start_and_end(duration):
today = datetime.utcnow()
start = (today + timedelta(0-duration)).replace(hour=0, minute=0, second=0, microsecond=0)
end = (today + timedelta(3)).replace(hour=0, minute=0, second=0, microsecond=0)
return start, end
def snake_to_camel(s):
a = s.split('_')
a[0] = a[0].capitalize()
if len(a) > 1:
a[1:] = [u.title() for u in a[1:]]
return ''.join(a)
def get_service_or_create(config, metadata_config) -> DatabaseServiceEntity:
client = REST(metadata_config)
service = client.get_database_service(config.service_name)
if service is not None:
return service
else:
2021-08-10 15:00:41 -07:00
service = {'jdbc': {'connectionUrl': config.get_connection_url(), 'driverClass': 'jdbc'},
2021-08-01 14:27:44 -07:00
'name': config.service_name, 'description': '', 'serviceType': config.get_service_type()}
created_service = client.create_database_service(CreateDatabaseServiceEntityRequest(**service))
return created_service