Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
JosepSampe committed Oct 7, 2017
2 parents 3afe030 + aa102e0 commit 734b161
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 17 deletions.
69 changes: 53 additions & 16 deletions api/filters/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,38 @@ def put(self, request, filter_id, format=None):
md5_etag = md5(path)

try:
r.hset(filter_name, "filter_name", os.path.basename(path))
r.hset(filter_name, "path", str(path))
r.hset(filter_name, "content_length", os.stat(path).st_size)
r.hset(filter_name, "etag", str(md5_etag))
filter_basename = os.path.basename(path)
content_length = os.stat(path).st_size
etag = str(md5_etag)
path = str(path)
r.hset(filter_name, "filter_name", filter_basename)
r.hset(filter_name, "path", path)
r.hset(filter_name, "content_length", content_length)
r.hset(filter_name, "etag", etag)
except RedisError:
return JSONResponse('Problems connecting with DB', status=status.HTTP_500_INTERNAL_SERVER_ERROR)

if filter_type == 'storlet':
# Redeploy already deployed storlet filters
filter_data = r.hgetall(filter_name)
main = filter_data['main']
token = get_token_connection(request)
pipelines = r.keys('pipeline:*')
for pipeline in pipelines:
target = pipeline.replace('pipeline:', '')
filters_data = r.hgetall(pipeline)
for policy_id in filters_data:
parameters = {}
parameters["policy_id"] = policy_id
cfilter = eval(filters_data[policy_id].replace('true', '"True"').replace('false', '"False"'))
if cfilter['dsl_name'] == filter_id:
cfilter['filter_name'] = filter_basename
cfilter['content_length'] = content_length
cfilter['etag'] = etag
cfilter['path'] = path
cfilter['main'] = main
set_filter(r, target, cfilter, parameters, token)

if filter_type == 'native':
# synchronize metrics directory with all nodes
try:
Expand Down Expand Up @@ -482,22 +507,33 @@ def set_filter(r, target, filter_data, parameters, token):

try:
project_id = target.split('/', 3)[0]
swift_response = dict()
url = settings.SWIFT_URL + settings.SWIFT_API_VERSION + "/AUTH_" + project_id
storlet_file = open(filter_data["path"], 'r')
swift_client.put_object(url, token, "storlet",
filter_data["filter_name"],
storlet_file, None,
None, None, "application/octet-stream",
metadata, None, None, None, swift_response)

if project_id == 'global':
projects_crystal_enabled = r.lrange('projects_crystal_enabled', 0, -1)
for project_id in projects_crystal_enabled:
swift_response = dict()
url = settings.SWIFT_URL + settings.SWIFT_API_VERSION + "/AUTH_" + project_id
storlet_file = open(filter_data["path"], 'r')
swift_client.put_object(url, token, "storlet",
filter_data["filter_name"],
storlet_file, None,
None, None, "application/octet-stream",
metadata, None, None, None, swift_response)
else:
swift_response = dict()
url = settings.SWIFT_URL + settings.SWIFT_API_VERSION + "/AUTH_" + project_id
storlet_file = open(filter_data["path"], 'r')
swift_client.put_object(url, token, "storlet",
filter_data["filter_name"],
storlet_file, None,
None, None, "application/octet-stream",
metadata, None, None, None, swift_response)
storlet_file.close()

except Exception as e:
logging.error(str(e))
raise SwiftClientError("A problem occurred accessing Swift")

finally:
storlet_file.close()

swift_status = swift_response.get("status")

if swift_status != status.HTTP_201_CREATED:
Expand All @@ -508,7 +544,8 @@ def set_filter(r, target, filter_data, parameters, token):

target = str(target).replace('/', ':')
# Change 'id' key of filter
filter_data["filter_id"] = filter_data.pop("id")
if 'filter_id' not in filter_data:
filter_data["filter_id"] = filter_data.pop("id")
# Get policy id
policy_id = parameters["policy_id"]

Expand Down
1 change: 0 additions & 1 deletion api/policies/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ def deploy_static_policy(request, r, parsed_rule):
token = get_token_connection(request)
container = None
rules_to_parse = dict()
# TODO: get only the Crystal enabled projects
projects_crystal_enabled = r.lrange('projects_crystal_enabled', 0, -1)
project_list = get_project_list()

Expand Down

0 comments on commit 734b161

Please sign in to comment.