-
Notifications
You must be signed in to change notification settings - Fork 1k
Ranger-5081: CI: Add check to verify plugin installation in ranger-service containers #583
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
Open
ChinmayHegde24
wants to merge
13
commits into
apache:master
Choose a base branch
from
ChinmayHegde24:RANGER-5081
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d75acb7
RANGER-5081:CI-Add check to verify plugin installation in ranger-serv…
ChinmayHegde24 c1fce72
RANGER-5081: Added new plugin check in docker build job in maven.yml
ChinmayHegde24 3a1b6a2
RANGER-5081:Update ranger-plugin-status.sh
ChinmayHegde24 b05585d
RANGER-5081:Replaced script file to Python file for plugin status check
ChinmayHegde24 3feda2b
RANGER-5081:Increased waiting time before checking plugin status
ChinmayHegde24 b72acf1
RANGER-5081:Add retry logic to check plugin status for up to 2 minutes
ChinmayHegde24 b16078e
Changed sequence of steps while checking container and plugin status …
ChinmayHegde24 1a688fa
Changed sequence of steps in docker build job in maven file
ChinmayHegde24 8c962e1
Changed wait for status update to 3min in ranger-plugin-status file
ChinmayHegde24 1fcf355
Used apache-ranger python client instead of requests library and made…
ChinmayHegde24 4e3eaee
RANGER-5081:Set PLUGIN_RETRY_COUNT to 10 as ozone plugin was not acti…
ChinmayHegde24 b4e1278
RANGER-5081: env file and some log statements have been changed
ChinmayHegde24 24f0f4f
RANGER-5081: Increased sleep time in check status of containers step …
ChinmayHegde24 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
142 changes: 142 additions & 0 deletions
142
dev-support/ranger-docker/scripts/ranger-plugin-status.py
This file contains hidden or 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,142 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# 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. | ||
|
||
import os | ||
import requests | ||
import time | ||
import json | ||
from dotenv import load_dotenv | ||
|
||
# Load environment variables from .env | ||
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | ||
|
||
# Path to the .env file in the parent directory | ||
ENV_PATH = os.path.join(SCRIPT_DIR, "..", ".env") | ||
|
||
# Load it | ||
load_dotenv(dotenv_path=ENV_PATH) | ||
|
||
RANGER_HOST = "http://localhost:6080" | ||
ENDPOINT = f"{RANGER_HOST}/service/public/v2/api/plugins/info" | ||
KNOX_ENDPOINT = "https://localhost:8443/gateway/sandbox/webhdfs/v1/?op=LISTSTATUS" | ||
|
||
RANGER_ADMIN_USER = os.getenv("RANGER_ADMIN_USER") | ||
RANGER_ADMIN_PASS = os.getenv("RANGER_ADMIN_PASS") | ||
KNOX_USER = os.getenv("KNOX_USER") | ||
KNOX_PASS = os.getenv("KNOX_PASS") | ||
|
||
expected_services = ["hdfs", "hbase", "kms", "yarn", "kafka", "ozone", "knox", "hive"] | ||
|
||
|
||
def trigger_knox_activity(): | ||
print("\nTriggering Knox activity to ensure plugin status is updated...") | ||
ChinmayHegde24 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
try: | ||
response = requests.get( | ||
ChinmayHegde24 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
KNOX_ENDPOINT, | ||
auth=(KNOX_USER,KNOX_PASS), | ||
verify=False, | ||
timeout=10 | ||
) | ||
print("Knox activity triggered.") | ||
except requests.RequestException as e: | ||
print(f"Failed to trigger Knox activity: {e}") | ||
ChinmayHegde24 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def fetch_plugin_info(): | ||
print(f"\nFetching plugin info from {ENDPOINT} ...") | ||
try: | ||
response = requests.get( | ||
ChinmayHegde24 marked this conversation as resolved.
Show resolved
Hide resolved
ChinmayHegde24 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ENDPOINT, | ||
auth=(RANGER_ADMIN_USER,RANGER_ADMIN_PASS), | ||
timeout=10 | ||
) | ||
response.raise_for_status() | ||
return response.json() | ||
except requests.RequestException as e: | ||
print(f"Error fetching plugin info: {e}") | ||
exit(1) | ||
|
||
def check_plugins(plugin_data): | ||
|
||
failed_services = [] | ||
print("\n<--------- Plugin Status ---------->") | ||
for svc in expected_services: | ||
print(f"\nChecking service type: {svc}") | ||
entries = [entry for entry in plugin_data if entry.get("serviceType") == svc] | ||
|
||
if not entries: | ||
print(f"MISSING: No plugins found for service type '{svc}'.") | ||
failed_services.append(svc) | ||
continue | ||
|
||
active_plugins = [ | ||
entry for entry in entries | ||
if entry.get("info", {}).get("policyActiveVersion") | ||
] | ||
print(f"🟢 Active plugins: {len(active_plugins)} / {len(entries)} total plugins found.") | ||
|
||
if not active_plugins: | ||
print(f"WARNING: Plugins present but NONE are active for '{svc}'.") | ||
failed_services.append(svc) | ||
|
||
print("Details:") | ||
for entry in entries: | ||
host = entry.get("hostName", "unknown") | ||
app_type = entry.get("appType", "unknown") | ||
version = entry.get("info", {}).get("policyActiveVersion", "null") | ||
print(f"- Host: {host}, AppType: {app_type}, PolicyActiveVersion: {version}") | ||
return failed_services | ||
|
||
|
||
def main(): | ||
|
||
print("Checking Ranger plugin status via Ranger Admin API") | ||
|
||
# Trigger knox activity | ||
trigger_knox_activity() | ||
|
||
# wait for status update | ||
for i in range(6): # Retry up to 3 minutes total | ||
ChinmayHegde24 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
plugin_data = fetch_plugin_info() | ||
if all(any(entry.get("info", {}).get("policyActiveVersion") for entry in plugin_data if entry["serviceType"] == svc) for svc in expected_services): | ||
break | ||
print("Some plugins not active yet, retrying in 30s...") | ||
time.sleep(30) | ||
|
||
else: | ||
print("Timed out waiting for plugins to become active.") | ||
|
||
# fetch plugin info through admin API | ||
plugin_data = fetch_plugin_info() | ||
|
||
if not plugin_data: | ||
print("No plugin info returned from API.") | ||
exit(1) | ||
|
||
# get plugin details | ||
failed_services = check_plugins(plugin_data) | ||
|
||
print() | ||
if failed_services: | ||
print(f"❌ The following plugins are missing or inactive: {', '.join(failed_services)}") | ||
exit(1) | ||
else: | ||
print("✅ All expected plugins are present and active.") | ||
|
||
if __name__ == "__main__": | ||
main() | ||
|
This file contains hidden or 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,86 @@ | ||
#!/bin/bash | ||
|
||
# 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. | ||
|
||
set -e | ||
|
||
echo "Checking Ranger plugin status via Ranger Admin API" | ||
|
||
# Load environment variables from .env file | ||
SCRIPT_DIR=$(dirname "$0") | ||
source "$SCRIPT_DIR/../.env" | ||
|
||
RANGER_HOST="http://localhost:6080" | ||
ENDPOINT="$RANGER_HOST/service/public/v2/api/plugins/info" | ||
|
||
# Trigger activity for KNOX to make plugin active | ||
echo | ||
echo "Triggering Knox activity to ensure plugin status is updated..." | ||
KNOX_ENDPOINT="https://localhost:8443/gateway/sandbox/webhdfs/v1/?op=LISTSTATUS" | ||
|
||
curl -k -u "$KNOX_USER:$KNOX_PASS" "$KNOX_ENDPOINT" > /dev/null 2>&1 | ||
echo "Knox activity triggered." | ||
|
||
sleep 60 | ||
|
||
echo "Fetching plugin info from $ENDPOINT ..." | ||
response=$(curl -s -u "$RANGER_ADMIN_USER:$RANGER_ADMIN_PASS" "$ENDPOINT") | ||
|
||
if [[ -z "$response" || "$response" == "[]" ]]; then | ||
echo "No plugin info returned from API." | ||
exit 1 | ||
fi | ||
|
||
expected_services=("hdfs" "hbase" "kms" "yarn" "kafka" "ozone" "knox" "hive") | ||
failed=false | ||
|
||
echo | ||
echo "<--------- Plugin Status ----------> " | ||
for svc in "${expected_services[@]}"; do | ||
echo | ||
echo "Checking service type: $svc" | ||
|
||
entries=$(echo "$response" | jq --arg svc "$svc" '[.[] | select(.serviceType == $svc)]') | ||
count=$(echo "$entries" | jq 'length') | ||
|
||
if (( count == 0 )); then | ||
echo "MISSING: No plugins found for service type '$svc'." | ||
failed=true | ||
continue | ||
fi | ||
|
||
active_count=$(echo "$entries" | jq '[.[] | select(.info.policyActiveVersion != null and .info.policyActiveVersion != "")] | length') | ||
|
||
echo "🟢 Active plugins: $active_count / $count total plugins found." | ||
|
||
if (( active_count == 0 )); then | ||
echo "WARNING: Plugins present but NONE are active for '$svc'." | ||
failed=true | ||
fi | ||
|
||
# List hostnames and plugin statuses for this service type | ||
echo "Details:" | ||
echo "$entries" | jq -r '.[] | "- Host: \(.hostName), AppType: \(.appType), PolicyActiveVersion: \(.info.policyActiveVersion // "null")"' | ||
done | ||
|
||
echo | ||
if $failed; then | ||
echo "❌ One or more plugins are missing or inactive." | ||
exit 1 | ||
else | ||
echo "✅ All expected plugins are present and active." | ||
fi |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.