Skip to content

Commit e269006

Browse files
author
root
committed
update to knox 1.2 and fix files permission for user knox
1 parent 85aa7b2 commit e269006

File tree

5 files changed

+147
-22
lines changed

5 files changed

+147
-22
lines changed

knox-csd/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/bash
22

3-
jar -cvf KNOX-1.0.jar *
3+
jar -cvf KNOX-1.2.jar *

knox-parcel/defaults/main.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,8 @@ BASE_DIR: "{{ lookup('env','PWD') }}/work"
1111
WORK_DIR: "{{ BASE_DIR | regex_replace('\\/$', '') }}/{{ WORK_DIRECTORY_NAME | regex_replace('\\/$', '') }}"
1212
OUTPUT_DIR: "{{ BASE_DIR }}/{{ OUTPUT_DIRECTORY_NAME | regex_replace('\\/$', '') }}"
1313
CACHE_DIR: "{{ BASE_DIR }}/{{ CACHE_DIRECTORY_NAME }}"
14-
15-
TARGET_ARCHITECTURES:
16-
- el6
17-
- el7
18-
- sles12
19-
- xenial
14+
MANIFEST_DIR: "{{ BASE_DIR }}/knox-manifest"
2015

2116
PROJECT_NAME_LOWER: "{{ PROJECT_NAME | lower }}"
2217
PROJECT_NAME_UPPER: "{{ PROJECT_NAME | upper }}"
23-
PARCEL_PREFIX: "{{ PROJECT_NAME_UPPER }}-{{ PROJECT_VERSION }}-{{ PARCEL_VERSION }}"
18+
PARCEL_PREFIX: "{{ PROJECT_NAME_UPPER }}-{{ PROJECT_VERSION }}-{{ PARCEL_VERSION }}"

knox-parcel/files/make_manifest.py

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#!/usr/bin/env python
2+
#
3+
# Licensed to Cloudera, Inc. under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. Cloudera, Inc. licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
19+
# This program creates a manifest.json file from a directory of parcels and
20+
# places the file in the same directory as the parcels.
21+
# Once created, the directory can be served over http as a parcel repository.
22+
23+
import hashlib
24+
import json
25+
import os
26+
import re
27+
import sys
28+
import tarfile
29+
import time
30+
31+
def _get_parcel_dirname(parcel_name):
32+
"""
33+
Extract the required parcel directory name for a given parcel.
34+
35+
eg: CDH-5.0.0-el6.parcel -> CDH-5.0.0
36+
"""
37+
parts = re.match(r"^(.*?)-(.*)-(.*?)$", parcel_name).groups()
38+
return parts[0] + '-' + parts[1]
39+
40+
def _safe_copy(key, src, dest):
41+
"""
42+
Conditionally copy a key/value pair from one dictionary to another.
43+
44+
Nothing is done if the key is not present in the source dictionary
45+
"""
46+
if key in src:
47+
dest[key] = src[key]
48+
49+
def make_manifest(path, timestamp=time.time()):
50+
"""
51+
Make a manifest.json document from the contents of a directory.
52+
53+
This function will scan the specified directory, identify any parcel files
54+
in it, and then build a manifest from those files. Certain metadata will be
55+
extracted from the parcel and copied into the manifest.
56+
57+
@param path: The path of the directory to scan for parcels
58+
@param timestamp: Unix timestamp to place in manifest.json
59+
@return: the manifest.json as a string
60+
"""
61+
manifest = {}
62+
manifest['lastUpdated'] = int(timestamp * 1000)
63+
manifest['parcels'] = []
64+
65+
files = os.listdir(path)
66+
for f in files:
67+
if not f.endswith('.parcel'):
68+
continue
69+
70+
print("Found parcel %s" % (f,))
71+
entry = {}
72+
entry['parcelName'] = f
73+
74+
fullpath = os.path.join(path, f)
75+
76+
with open(fullpath, 'rb') as fp:
77+
entry['hash'] = hashlib.sha1(fp.read()).hexdigest()
78+
79+
with tarfile.open(fullpath, 'r') as tar:
80+
try:
81+
json_member = tar.getmember(os.path.join(_get_parcel_dirname(f),
82+
'meta', 'parcel.json'))
83+
except KeyError:
84+
print("Parcel does not contain parcel.json")
85+
continue
86+
try:
87+
parcel = json.loads(tar.extractfile(json_member).read().decode(encoding='UTF-8'))
88+
except:
89+
print("Failed to parse parcel.json")
90+
continue
91+
_safe_copy('depends', parcel, entry)
92+
_safe_copy('replaces', parcel, entry)
93+
_safe_copy('conflicts', parcel, entry)
94+
_safe_copy('components', parcel, entry)
95+
_safe_copy('servicesRestartInfo', parcel, entry)
96+
97+
try:
98+
notes_member = tar.getmember(os.path.join(_get_parcel_dirname(f),
99+
'meta', 'release-notes.txt'))
100+
entry['releaseNotes'] = tar.extractfile(notes_member).read().decode(encoding='UTF-8')
101+
except KeyError:
102+
# No problem if there's no release notes
103+
pass
104+
105+
manifest['parcels'].append(entry)
106+
107+
return json.dumps(manifest, indent=4, separators=(',', ': '))
108+
109+
if __name__ == "__main__":
110+
path = os.path.curdir
111+
if len(sys.argv) > 1:
112+
path = sys.argv[1]
113+
print("Scanning directory: %s" % (path))
114+
115+
manifest = make_manifest(path)
116+
with open(os.path.join(path, 'manifest.json'), 'w') as fp:
117+
fp.write(manifest)
118+

knox-parcel/tasks/main.yml

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
- "{{ OUTPUT_DIR }}"
1717
- "{{ WORK_DIR }}"
1818
- "{{ CACHE_DIR }}"
19+
- "{{ MANIFEST_DIR }}"
1920

2021
- name: Download distribution
2122
get_url:
@@ -51,6 +52,12 @@
5152
dest: "{{ WORK_DIR }}/{{ PARCEL_PREFIX }}/bin/"
5253
mode: 0755
5354

55+
- name: Copy manifest.py file
56+
copy:
57+
src: make_manifest.py
58+
dest: "{{ MANIFEST_DIR }}/make_manifest.py"
59+
mode: 0755
60+
5461
- name: Copy modified gateway.sh script
5562
copy:
5663
src: gateway.sh
@@ -66,6 +73,12 @@
6673
mode: u=rwX,g=rX,o=rX
6774
recurse: yes
6875

76+
- name: Original directories should be accessible by user knox
77+
file:
78+
path: "{{ WORK_DIR }}/{{ PARCEL_PREFIX }}"
79+
mode: u=rwX,g=rX,o=rX
80+
recurse: yes
81+
6982
- name: Create empty conf directory
7083
file:
7184
path: "{{ WORK_DIR }}/{{ PARCEL_PREFIX }}/conf"
@@ -79,18 +92,17 @@
7992
- name: Create parcel
8093
archive:
8194
path: "{{ WORK_DIR }}/"
82-
dest: "{{ OUTPUT_DIR }}/{{ PARCEL_PREFIX }}-universal.parcel"
95+
dest: "{{ OUTPUT_DIR }}/{{ PARCEL_PREFIX }}-el7.parcel"
8396

84-
- name: Symlink parcel to architecture specific parcels
85-
file:
86-
src: "{{ PARCEL_PREFIX }}-universal.parcel"
87-
path: "{{ OUTPUT_DIR }}/{{ PARCEL_PREFIX }}-{{ item }}.parcel"
88-
state: link
89-
with_items: "{{ TARGET_ARCHITECTURES }}"
97+
- name: Create manifest
98+
shell: python {{ MANIFEST_DIR }}/make_manifest.py {{ OUTPUT_DIR }}
9099

91-
- name: Empty working directory
92-
file:
93-
path: "{{ item }}"
94-
state: absent
95-
with_items:
96-
- "{{ WORK_DIR }}"
100+
- name: Create checksum file
101+
shell: sha1sum {{ OUTPUT_DIR }}/{{ PARCEL_PREFIX }}-el7.parcel > {{ OUTPUT_DIR }}/{{ PARCEL_PREFIX }}-el7.parcel.sha1
102+
103+
#- name: Empty working directory
104+
# file:
105+
# path: "{{ item }}"
106+
# state: absent
107+
# with_items:
108+
# - "{{ WORK_DIR }}"

knox-parcel/vars/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
PROJECT_NAME: knox
3-
PROJECT_VERSION: 1.1.0
3+
PROJECT_VERSION: 1.2.0
44
PARCEL_VERSION: 1
55

66
DOWNLOAD_FILE_NAME: knox-{{ PROJECT_VERSION }}.zip

0 commit comments

Comments
 (0)