Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
ARIA-438 : Support for storing the common TOSCA YAML files in the res…
…ource storage
  • Loading branch information
VenkatesanVenugopal authored and djay87 committed Mar 13, 2018
1 parent dee7791 commit 404690580145a1eaefa5f64b65672395f6d43d23
Showing 55 changed files with 1,480 additions and 3 deletions.
@@ -84,6 +84,7 @@ def application_resource_storage(api, api_kwargs=None, initiator=None, initiator

return storage.ResourceStorage(api_cls=api,
api_kwargs=api_kwargs,
items=['service_template', 'service', 'plugin'],
items=['type_definition', 'service_template', 'service',\
'plugin'],
initiator=initiator,
initiator_kwargs=initiator_kwargs)
@@ -18,6 +18,7 @@
"""

from . import (
type_definitions,
executions,
logs,
node_templates,
@@ -0,0 +1,136 @@
# 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.

"""
CLI ``type-definitions`` sub-commands.
"""
from aria import exceptions
from ..core import aria
from .. import service_template_utils
from .. import table

TYPE_DEFINITION_COLUMNS = \
('id', 'name', 'version', 'main_file_name', 'uploaded_at')


@aria.group(name='type-definitions')
@aria.options.verbose()
def type_definitions():
"""
Manage type definitions
"""
pass

@type_definitions.command(name='load',
short_help='Parse and load a type definition archive')
@aria.argument('type-definition-path')
@aria.options.verbose()
@aria.pass_type_definition_manager
@aria.pass_logger
def load(type_definition_path, type_definition_manager, logger):
"""
Parse and store a type definition archive
TYPE_DEFINITION_PATH is the path to the type definition archive.
"""
logger.info('Loading type definition {0}...'.format(type_definition_path))
valid_extension = ('.yaml', '.csar')
if not type_definition_path.endswith(valid_extension):
raise exceptions.\
TypeDefinitionException('Type definition file has invalid extension')

type_definition_file_path = service_template_utils.get(type_definition_path, None)
type_definition = type_definition_manager.load_type_definition(type_definition_file_path)
logger.info("Type definition loaded. The type definition's name is {0} and version is {1}".\
format(type_definition.name, type_definition.version))

@type_definitions.command(name='list',
short_help='List all stored type definitions')
@aria.options.sort_by('uploaded_at')
@aria.options.descending
@aria.options.verbose()
@aria.pass_type_definition_manager
@aria.pass_logger
def list(sort_by, descending, type_definition_manager, logger):
"""
List all stored type definitions
"""

logger.info('Listing all type definitions...')
type_definitions_list = type_definition_manager.list_type_definition(sort_by, descending)
table.print_data(TYPE_DEFINITION_COLUMNS, type_definitions_list, 'Type definitions:')

@type_definitions.command(name='show',
short_help='Show information for a stored type definition')
@aria.argument('type-definition-name')
@aria.argument('type-definition-version')
@aria.options.verbose()
@aria.pass_type_definition_manager
@aria.pass_logger
def show(type_definition_name, type_definition_version, type_definition_manager, logger):
"""
Show information for a stored type definition
TYPE_DEFINITION_NAME is name of the stored type definition
TYPE_DEFINITION_VERSION is version of the stored type definition
"""
logger.info("Showing type definition name '{0}' version '{1}'...".\
format(type_definition_name, type_definition_version))
type_definition = type_definition_manager.get_type_definition(type_definition_name,\
type_definition_version)
table.print_data(TYPE_DEFINITION_COLUMNS, type_definition, 'Type definition:')

@type_definitions.command(name='delete',
short_help='Delete a stored type definition')
@aria.argument('type-definition-name')
@aria.argument('type-definition-version')
@aria.options.verbose()
@aria.pass_type_definition_manager
@aria.pass_logger
def delete(type_definition_name, type_definition_version, type_definition_manager, logger):
"""
Delete a stored type definition
TYPE_DEFINITION_NAME is name of the stored type definition
TYPE_DEFINITION_VERSION is version of the stored type definition
"""
logger.info("Deleting type definition name '{0}' version '{1}'...".\
format(type_definition_name, type_definition_version))
type_definition_manager.delete_type_definition(type_definition_name, type_definition_version)
logger.info("Type definition name '{0}' version '{1}' deleted".\
format(type_definition_name, type_definition_version))

@type_definitions.command(name='validate',
short_help='Validate a type definition archive')
@aria.argument('type-definition-path')
@aria.options.verbose()
@aria.pass_type_definition_manager
@aria.pass_logger
def validate(type_definition_path, type_definition_manager, logger):
"""
Validate a type definition archive
TYPE_DEFINITION_PATH is the path to the type definition archive.
"""
logger.info('Validating type definition: {0}'.format(type_definition_path))
valid_extension = ('.yaml', '.csar')
if not type_definition_path.endswith(valid_extension):
raise exceptions.\
TypeDefinitionException('Type definition file has invalid extension')

type_definition_file_path = service_template_utils.get(type_definition_path, None)
type_definition_manager.validate_type_definition(type_definition_file_path)
logger.info('Type definition validated successfully')
@@ -176,6 +176,17 @@ def wrapper(*args, **kwargs):

return wrapper

def pass_type_definition_manager(func):
"""
Simply passes the type definition manager to a command.
"""
# Wraps here makes sure the original docstring propagates to click
@wraps(func)
def wrapper(*args, **kwargs):
return func(type_definition_manager=env.type_definition_manager, *args, **kwargs)

return wrapper


def pass_model_storage(func):
"""
@@ -19,7 +19,7 @@

import os
import shutil

from aria.type_definition_manager import TypeDefinitionManager
from .config import config
from .logger import Logging
from .. import (application_model_storage, application_resource_storage)
@@ -44,11 +44,13 @@ def __init__(self, workdir):
self._model_storage_dir = os.path.join(workdir, 'models')
self._resource_storage_dir = os.path.join(workdir, 'resources')
self._plugins_dir = os.path.join(workdir, 'plugins')
self._type_definitions_dir = os.path.join(workdir, 'type_definitions')

# initialized lazily
self._model_storage = None
self._resource_storage = None
self._plugin_manager = None
self._type_definition_manager = None

@property
def workdir(self):
@@ -80,6 +82,12 @@ def plugin_manager(self):
self._plugin_manager = self._init_plugin_manager()
return self._plugin_manager

@property
def type_definition_manager(self):
if not self._type_definition_manager:
self._type_definition_manager = self._init_type_definition_manager()
return self._type_definition_manager

def reset(self, reset_config):
if reset_config:
shutil.rmtree(self._workdir)
@@ -120,6 +128,11 @@ def _init_plugin_manager(self):

return PluginManager(self.model_storage, self._plugins_dir)

def _init_type_definition_manager(self):
if not os.path.exists(self._type_definitions_dir):
os.makedirs(self._type_definitions_dir)

return TypeDefinitionManager(self.model_storage, self._type_definitions_dir)

env = _Environment(os.path.join(
os.environ.get('ARIA_WORKDIR', os.path.expanduser('~')), ARIA_DEFAULT_WORKDIR_NAME))
@@ -44,6 +44,7 @@ def _register_commands():
Register the CLI's commands.
"""

_aria.add_command(commands.type_definitions.type_definitions)
_aria.add_command(commands.service_templates.service_templates)
_aria.add_command(commands.node_templates.node_templates)
_aria.add_command(commands.services.services)
@@ -71,3 +71,27 @@ class ParsingError(AriaError):

class InstantiationError(AriaError):
pass


class TypeDefinitionException(AriaError):
"""The base exception class of the type definition"""
pass


class TypeDefinitionNotFoundException(TypeDefinitionException):
"""The exception class of the type definition thrown
if type definition does not exists"""
pass


class TypeDefinitionAlreadyExistsException(TypeDefinitionException):
"""The exception class of the type definition thrown
if type definition already exists"""
pass


class InvalidTypeDefinitionException(TypeDefinitionException):
"""The exception class of the type definition thrown
if type definition is not a valid archive or validation error
exists during the type definition load"""
pass
@@ -16,6 +16,14 @@
"""
Data models.
Type definition models
-----------------------
.. autosummary::
:nosignatures:
aria.modeling.models.TypeDefinition
Service template models
-----------------------
@@ -90,6 +98,7 @@
)

from . import (
type_definition,
service_template,
service_instance,
service_changes,
@@ -107,6 +116,9 @@
__all__ = (
'models_to_register',

# Type definition models
'TypeDefinition',

# Service template models
'ServiceTemplate',
'NodeTemplate',
@@ -157,6 +169,11 @@
'Argument'
)

# region type definition models

@utils.fix_doc
class TypeDefinition(aria_declarative_base, type_definition.TypeDefinitionBase):
pass

# region service template models

@@ -376,6 +393,9 @@ class Argument(aria_declarative_base, orchestration.ArgumentBase):

# See also __all__ at the top of this file
models_to_register = (
# Type definition models
TypeDefinition,

# Service template models
ServiceTemplate,
NodeTemplate,
@@ -0,0 +1,65 @@
# 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.

"""
ARIA modeling type definition module
"""

# pylint: disable=too-many-lines, no-self-argument, no-member, abstract-method

from sqlalchemy import (
Column,
Text,
DateTime,
UniqueConstraint
)
from . import mixins

class TypeDefinitionBase(mixins.ModelMixin):
"""
Loaded TypeDefinition.
Usually created by various DSL parsers, such as ARIA's TOSCA extension. However, it can also be
created programmatically.
"""

__tablename__ = 'type_definition'

name = Column(Text, nullable=False, index=True, doc="""
Name of the type definition
:type: :obj:`basestring`
""")

version = Column(Text, nullable=False, doc="""
Version for the type definition
:type: :obj:`basestring`
""")

main_file_name = Column(Text, nullable=False, doc="""
Filename of CSAR or YAML file from which this type definition was parsed.
:type: :obj:`basestring`
""")

uploaded_at = Column(DateTime, nullable=False, doc="""
Timestamp for when the type definition was loaded.
:type: :class:`~datetime.datetime`
""")

__table_args__ = (UniqueConstraint('name', 'version',
name='_type_definition_name_version_unique'),)

0 comments on commit 4046905

Please sign in to comment.