Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions components/stage/scripts/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from cloudify import ctx

ctx.download_resource(
join('components', 'utils.py'),
join(dirname(__file__), 'utils.py'))
join('components', 'utils.py'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change the indentation?

join(dirname(__file__), 'utils.py'))
import utils # NOQA

STAGE_SERVICE_NAME = 'stage'
Expand All @@ -22,6 +22,7 @@ def install_stage():

nodejs_source_url = ctx_properties['nodejs_tar_source_url']
stage_source_url = ctx_properties['stage_tar_source_url']
ctx.instance.runtime_properties['skip_stage_installation'] = 'False'

# injected as an input to the script
ctx.instance.runtime_properties['influxdb_endpoint_ip'] = \
Expand All @@ -34,26 +35,25 @@ def install_stage():
stage_user = 'stage'
stage_group = 'stage'

utils.set_selinux_permissive()
ctx.logger.info('Installing Cloudify Stage (UI)...')
stage = utils.download_cloudify_resource(
stage_source_url, STAGE_SERVICE_NAME, skip_stage_installation=True)
if stage is None:
ctx.instance.runtime_properties['skip_stage_installation'] = 'True'
ctx.logger.info("Skipping Stage installation")
return

utils.set_selinux_permissive()
utils.copy_notice(STAGE_SERVICE_NAME)

utils.mkdir(nodejs_home)
utils.mkdir(stage_home)
utils.mkdir(stage_log_path)

utils.create_service_user(stage_user, stage_home)

ctx.logger.info('Installing NodeJS...')
nodejs = utils.download_cloudify_resource(nodejs_source_url,
STAGE_SERVICE_NAME)
utils.untar(nodejs, nodejs_home)

ctx.logger.info('Installing Cloudify Stage (UI)...')
stage = utils.download_cloudify_resource(stage_source_url,
STAGE_SERVICE_NAME)
utils.untar(stage, stage_home)

ctx.logger.info('Fixing permissions...')
utils.chown(stage_user, stage_group, stage_home)
utils.chown(stage_user, stage_group, nodejs_home)
Expand Down
12 changes: 7 additions & 5 deletions components/stage/scripts/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
from cloudify import ctx

ctx.download_resource(
join('components', 'utils.py'),
join(dirname(__file__), 'utils.py'))
join('components', 'utils.py'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

join(dirname(__file__), 'utils.py'))
import utils # NOQA

STAGE_SERVICE_NAME = 'stage'


ctx.logger.info('Starting Stage (UI) Service...')
utils.start_service(STAGE_SERVICE_NAME)
skip_stage_installation = ctx.instance.runtime_properties['skip_stage_installation']
print "skip_stage_installation={0}".format(skip_stage_installation)
if skip_stage_installation != 'True':
ctx.logger.info('Starting Stage (UI) Service...')
utils.start_service(STAGE_SERVICE_NAME)
12 changes: 7 additions & 5 deletions components/stage/scripts/stop.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
from cloudify import ctx

ctx.download_resource(
join('components', 'utils.py'),
join(dirname(__file__), 'utils.py'))
join('components', 'utils.py'),
join(dirname(__file__), 'utils.py'))
import utils # NOQA

STAGE_SERVICE_NAME = 'stage'


ctx.logger.info('Stopping Stage (UI) Service...')
utils.systemd.stop(STAGE_SERVICE_NAME)
skip_stage_installation = ctx.instance.runtime_properties['skip_stage_installation']
print "skip_stage_installation={0}".format(skip_stage_installation)
if skip_stage_installation != 'True':
ctx.logger.info('Stopping Stage (UI) Service...')
utils.systemd.stop(STAGE_SERVICE_NAME)
42 changes: 32 additions & 10 deletions components/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,26 +405,33 @@ def get_file_name_from_url(url):
return os.path.basename(disassembled.path)


def download_cloudify_resource(url, service_name, destination=None):
def download_cloudify_resource(
url, service_name, destination=None, skip_stage_installation=False):
"""Downloads a resource and saves it as a cloudify resource.

The resource will be saved under the appropriate service resource path and
will be used in case of operation execution failure after the resource has
already been downloaded.
"""
if destination:

source_res_path, _ = resource_factory.create(url,
destination,
service_name,
skip_stage_installation,
source_resource=True,
render=False)
if source_res_path is None and skip_stage_installation:
return None
copy(source_res_path, destination)
else:

res_name = os.path.basename(url)
source_res_path, _ = resource_factory.create(url, res_name,
service_name,
source_resource=True,
render=False)

return source_res_path


Expand Down Expand Up @@ -563,13 +570,16 @@ def yum_install(source, service_name):
sudo(['yum', 'install', '-y', source_path])


def get_filepath_from_pkg_name(filename):
def get_filepath_from_pkg_name(filename, skip_stage_installation=False):
local_filepath_list = \
[fn for fn in glob.glob(os.path.join(CLOUDIFY_SOURCES_PATH, filename))
if not os.path.basename(fn).startswith(SINGLE_TAR_PREFIX)]
if not local_filepath_list:
ctx.abort_operation("File: {0} does not exist in sources path: {1}".
format(filename, CLOUDIFY_SOURCES_PATH))
if skip_stage_installation:
return None
else:
ctx.abort_operation("File: {0} does not exist in sources path: {1}".
format(filename, CLOUDIFY_SOURCES_PATH))
if len(local_filepath_list) > 1:
ctx.abort_operation("More than one file: {0} found in sources path:"
" {1}".format(filename, CLOUDIFY_SOURCES_PATH))
Expand Down Expand Up @@ -1069,7 +1079,8 @@ class BlueprintResourceFactory(object):
RESOURCES_JSON_FILE = '__resources.json'

def create(self, source, destination, service_name, user_resource=False,
source_resource=False, render=True, load_ctx=True):
source_resource=False, skip_stage_installation=False,
render=True, load_ctx=True):
"""A Factory used to create a local copy of a resource upon deployment.
This copy allows to later reuse the resource for upgrade/rollback
purposes.
Expand All @@ -1089,6 +1100,9 @@ def create(self, source, destination, service_name, user_resource=False,
context of the script.
:return: The local resource file path and destination.
"""
print "***source={0}, destination={1}, service_name={2}, user_resource=={3}," \
"source_resource={4}, render={5}, load_ctx={6}".format(
source, destination, service_name, user_resource, source_resource, render, load_ctx)
resource_name = os.path.basename(destination)
if is_upgrade:
self._archive_resources(service_name)
Expand All @@ -1103,7 +1117,7 @@ def create(self, source, destination, service_name, user_resource=False,
# The local path is decided according to whether we are in upgrade
local_resource_path = self._get_local_file_path(service_name,
resource_name)

print "***local_resource_path={0}".format(local_resource_path)
if self._is_download_required(local_resource_path, render):
mkdir(os.path.dirname(local_resource_path))
if user_resource:
Expand All @@ -1114,8 +1128,12 @@ def create(self, source, destination, service_name, user_resource=False,
render=render,
load_ctx=load_ctx)
elif source_resource:
self._download_source_resource(source,
local_resource_path)
res = True
res = self._download_source_resource(source,
local_resource_path,
skip_stage_installation)
if not res:
return None, None
elif render:
self._download_resource_and_render(source,
local_resource_path,
Expand Down Expand Up @@ -1189,15 +1207,19 @@ def _download_resource_and_render(self, source, dest, service_name,
move(tmp_file, dest)

@staticmethod
def _download_source_resource(source, local_resource_path):
def _download_source_resource(source, local_resource_path,
skip_stage_installation=False):
is_url = source.startswith(('http://', 'https://', 'ftp://',
'file://'))
filename = get_file_name_from_url(source) if is_url else source
is_manager_package = filename.startswith(SINGLE_TAR_PREFIX)
if is_manager_package:
local_filepath = os.path.join(CLOUDIFY_SOURCES_PATH, filename)
else:
local_filepath = get_filepath_from_pkg_name(filename)
local_filepath = get_filepath_from_pkg_name(
filename, skip_stage_installation)
if local_filepath is None and skip_stage_installation:
return None

if is_url:
if not os.path.isfile(local_filepath):
Expand Down