-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[AMBARI-23120] Create helper functions for using new instance manager library from the agent scripts (dsen) #517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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" | ||
| 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, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit-picking rename components_instance_type to component_name
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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]}) | ||
There was a problem hiding this comment.
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.