Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env python
"""
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.

Ambari Agent

"""


def get_mpack_name(config):
return config['hostLevelParams']['stack_name']


def get_mpack_version(config):
return config['hostLevelParams']['stack_version']


def get_mpack_instance_name(config):
return config['serviceGroupName']


def get_module_name(config):
return config['serviceName']


def get_component_type(config):
return config['role']


def get_component_instance_name(config):
return "default"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now this is ok. But for multiple host component instances we will have to update the ExecutionCommand to pass down the component name and component instance name.

Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
"""
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.

Ambari Agent

"""

import os
from instance_manager import create_mpack, set_mpack_instance, get_conf_dir, list_instances

CONFIG_DIR_KEY_NAME = 'config_dir'
PATH_KEY_NAME = 'path'
COMPONENTS_PLURAL_KEY_NAME = 'components'
COMPONENT_INSTANCES_PLURAL_KEY_NAME = 'component-instances'


def get_component_conf_path(mpack_name, instance_name, module_name, components_instance_type,
subgroup_name='default', component_instance_name='default'):
"""
:returns the single string that contains the path to the configuration folder of given component instance
:raises ValueError if the parameters doesn't match the mpack or instances structure
"""

conf_json = get_conf_dir(mpack_name, instance_name, subgroup_name, module_name,
{components_instance_type: [component_instance_name]})

return conf_json[COMPONENTS_PLURAL_KEY_NAME][components_instance_type.lower()][COMPONENT_INSTANCES_PLURAL_KEY_NAME][
component_instance_name][CONFIG_DIR_KEY_NAME]


def get_component_target_path(mpack_name, instance_name, module_name, components_instance_type,
subgroup_name='default', component_instance_name='default'):
"""
:returns the single string that contains the path to the mpack component folder of given component instance
:raises ValueError if the parameters doesn't match the mpack or instances structure
"""

instances_json = list_instances(mpack_name, instance_name, subgroup_name, module_name,
{components_instance_type: [component_instance_name]})

return instances_json[COMPONENTS_PLURAL_KEY_NAME][components_instance_type.lower()][
COMPONENT_INSTANCES_PLURAL_KEY_NAME][component_instance_name][PATH_KEY_NAME]


def get_component_home_path(mpack_name, instance_name, module_name, components_instance_type,
subgroup_name='default', component_instance_name='default'):
"""
:returns the single string that contains the path to the module component folder of given component instance
:raises ValueError if the parameters doesn't match the mpack or instances structure
"""

component_path = get_component_target_path(mpack_name=mpack_name, instance_name=instance_name,
subgroup_name=subgroup_name,
module_name=module_name, components_instance_type=components_instance_type,
component_instance_name=component_instance_name)

return os.readlink(component_path)


def create_component_instance(mpack_name, mpack_version, instance_name, module_name, components_instance_type,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit-picking rename components_instance_type to component_name

Copy link
Contributor Author

@d0zen1 d0zen1 Mar 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the "component_type" fits better than "component_name" since we also have component_instance_name

subgroup_name='default', component_instance_name='default'):
"""
creates the single component instance according to the parameters
:raises ValueError if the parameters doesn't match the mpack or instances structure
"""
create_mpack(mpack_name, mpack_version, instance_name, subgroup_name, module_name,
None, {components_instance_type: [component_instance_name]})


def set_component_instance_version(mpack_name, mpack_version, instance_name, module_name, components_instance_type,
subgroup_name='default', component_instance_name='default'):
"""
changes the version of the single component instance according to the parameters
:raises ValueError if the parameters doesn't match the mpack or instances structure
"""
set_mpack_instance(mpack_name, mpack_version, instance_name, subgroup_name, module_name,
None, {components_instance_type: [component_instance_name]})
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
from resource_management.libraries.functions.show_logs import show_logs
from resource_management.core.providers import get_provider
from resource_management.libraries.functions.fcntl_based_process_lock import FcntlBasedProcessLock
from resource_management.libraries.functions.mpack_manager_helper import create_component_instance
from resource_management.libraries.functions.config_helper import get_mpack_name, get_mpack_version, \
get_mpack_instance_name, get_module_name, get_component_type, get_component_instance_name

import ambari_simplejson as json # simplejson is much faster comparing to Python 2.6 json module and has the same functions set.

Expand Down Expand Up @@ -791,6 +794,19 @@ def load_available_packages(self):
Logger.exception("Unable to load available packages")
self.available_packages_in_repos = []

def create_component_instance(self):
config = self.get_config()
mpack_name = get_mpack_name(config)
mpack_version = get_mpack_version(config)
mpack_instance_name = get_mpack_instance_name(config)
module_name = get_module_name(config)
component_type = get_component_type(config)
component_instance_name = get_component_instance_name(config)

create_component_instance(mpack_name=mpack_name, mpack_version=mpack_version, instance_name=mpack_instance_name,
module_name=module_name, components_instance_type=component_type,
component_instance_name=component_instance_name)


def install_packages(self, env):
"""
Expand Down