forked from apache/ambari
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AMBARI-21722 - Begin Using Service Versions In Python stack_feature C…
…ode (jonathanhurley)
- Loading branch information
Jonathan Hurley
committed
Aug 16, 2017
1 parent
12c0588
commit 330a61c
Showing
73 changed files
with
1,578 additions
and
1,013 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
ambari-common/src/main/python/resource_management/libraries/functions/component_version.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/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. | ||
""" | ||
|
||
from resource_management.libraries.script.script import Script | ||
|
||
def get_component_repository_version(service_name, component_name = None): | ||
""" | ||
Gets the version associated with the specified component from the structure in the command. | ||
Every command should contain a mapping of service/component to the desired repository it's set | ||
to. | ||
:service_name: the name of the service | ||
:component_name: the name of the component | ||
""" | ||
versions = _get_component_repositories() | ||
if versions is None: | ||
return None | ||
|
||
if service_name not in versions: | ||
return None | ||
|
||
component_versions = versions[service_name] | ||
if len(component_versions) == 0: | ||
return None | ||
|
||
if component_name is None: | ||
for component in component_versions: | ||
return component_versions[component] | ||
|
||
if not component_name in component_versions: | ||
return None | ||
|
||
return component_versions[component_name] | ||
|
||
|
||
def _get_component_repositories(): | ||
""" | ||
Gets an initialized dictionary from the value in componentVersionMap. This structure is | ||
sent on every command by Ambari and should contain each service & component's desired repository. | ||
:return: | ||
""" | ||
config = Script.get_config() | ||
if "componentVersionMap" not in config or config["componentVersionMap"] is "": | ||
return None | ||
|
||
return config["componentVersionMap"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
ambari-common/src/main/python/resource_management/libraries/functions/upgrade_summary.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
#!/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. | ||
""" | ||
|
||
from collections import namedtuple | ||
from resource_management.libraries.script.script import Script | ||
from resource_management.libraries.functions.constants import Direction | ||
|
||
UpgradeSummary = namedtuple("UpgradeSummary", "type direction orchestration is_revert services") | ||
UpgradeServiceSummary = namedtuple("UpgradeServiceSummary", "service_name source_stack source_version target_stack target_version") | ||
|
||
def get_source_version(service_name = None, default_version=None): | ||
""" | ||
Gets the source (from) version of a service participating in an upgrade. If there is no | ||
upgrade or the specific service is not participating, this will return None. | ||
:param service_name: the service name to check for, or None to extract it from the command | ||
:param default_version: if the version of the service can't be calculated, this optional | ||
default value is returned | ||
:return: the version that the service is upgrading from or None if there is no upgrade or | ||
the service is not included in the upgrade. | ||
""" | ||
service_summary = _get_service_summary(service_name) | ||
if service_summary is None: | ||
return default_version | ||
|
||
return service_summary.source_version | ||
|
||
|
||
def get_target_version(service_name = None, default_version=None): | ||
""" | ||
Gets the target (to) version of a service participating in an upgrade. If there is no | ||
upgrade or the specific service is not participating, this will return None. | ||
:param service_name: the service name to check for, or None to extract it from the command | ||
:param default_version: if the version of the service can't be calculated, this optional | ||
default value is returned | ||
:return: the version that the service is upgrading to or None if there is no upgrade or | ||
the service is not included in the upgrade. | ||
""" | ||
service_summary = _get_service_summary(service_name) | ||
if service_summary is None: | ||
return default_version | ||
|
||
return service_summary.target_version | ||
|
||
|
||
|
||
def get_upgrade_summary(): | ||
""" | ||
Gets a summary of an upgrade in progress, including type, direction, orchestration and from/to | ||
repository versions. | ||
""" | ||
config = Script.get_config() | ||
if "upgradeSummary" not in config or not config["upgradeSummary"]: | ||
return None | ||
|
||
upgrade_summary = config["upgradeSummary"] | ||
service_summary_dict = {} | ||
|
||
service_summary = upgrade_summary["services"] | ||
for service_name, service_summary_json in service_summary.iteritems(): | ||
service_summary = UpgradeServiceSummary(service_name = service_name, | ||
source_stack = service_summary_json["sourceStackId"], | ||
source_version = service_summary_json["sourceVersion"], | ||
target_stack = service_summary_json["targetStackId"], | ||
target_version = service_summary_json["targetVersion"]) | ||
|
||
service_summary_dict[service_name] = service_summary | ||
|
||
return UpgradeSummary(type=upgrade_summary["type"], direction=upgrade_summary["direction"], | ||
orchestration=upgrade_summary["orchestration"], is_revert = upgrade_summary["isRevert"], | ||
services = service_summary_dict) | ||
|
||
|
||
def get_downgrade_from_version(service_name = None): | ||
""" | ||
Gets the downgrade-from-version for the specificed service. If there is no downgrade or | ||
the service isn't participating in the downgrade, then this will return None | ||
:param service_name: the service, or optionally onmitted to infer it from the command. | ||
:return: the downgrade-from-version or None | ||
""" | ||
upgrade_summary = get_upgrade_summary() | ||
if upgrade_summary is None: | ||
return None | ||
|
||
if Direction.DOWNGRADE.lower() != upgrade_summary.direction.lower(): | ||
return None | ||
|
||
service_summary = _get_service_summary(service_name) | ||
if service_summary is None: | ||
return None | ||
|
||
return service_summary.source_version | ||
|
||
|
||
def _get_service_summary(service_name): | ||
""" | ||
Gets the service summary for the upgrade/downgrade for the given service, or None if | ||
the service isn't participating. | ||
:param service_name: the service name | ||
:return: the service summary or None | ||
""" | ||
upgrade_summary = get_upgrade_summary() | ||
if upgrade_summary is None: | ||
return None | ||
|
||
if service_name is None: | ||
config = Script.get_config() | ||
service_name = config['serviceName'] | ||
|
||
service_summary = upgrade_summary.services | ||
if service_name not in service_summary: | ||
return None | ||
|
||
return service_summary[service_name] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.