This repository has been archived by the owner on Oct 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
Assets download fix for running from profiles #32
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9df5250
Find assets service name based on type and add it to the end of a pro…
83ff4a6
Only download required versions of assets-frontend when starting a pr…
f5e2fb8
Log assets-frontend versions being started
f5bb15c
Accept dot notation in .conf
8ee1674
Append assets versions instead of clobbering them
752b86d
Remove stray print
8caed41
remove pyhocon import
anthonymunene 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 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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
#!/usr/bin/env python | ||
import glob | ||
|
||
import os | ||
import re | ||
import shutil | ||
import zipfile | ||
import stat | ||
|
@@ -24,12 +26,6 @@ class SmPlayServiceStarter(SmJvmServiceStarter): | |
|
||
PLAY_PROCESS_STARTUP_TIMEOUT_SECONDS = 120 | ||
|
||
def __init__(self, context, service_name, run_from, port, classifier, service_mapping_ports, version, proxy, append_args): | ||
SmMicroServiceStarter.__init__(self, context, service_name, "play", run_from, port, classifier, service_mapping_ports, version, proxy, append_args) | ||
|
||
if not self.port: | ||
self.port = self.service_data["defaultPort"] | ||
|
||
def _build_extra_params(self): | ||
extra_params = ["-Dhttp.port=%d" % self.port] | ||
extra_params += self.process_arguments() | ||
|
@@ -70,6 +66,12 @@ def _build_extra_params(self): | |
|
||
return extra_params | ||
|
||
def __init__(self, context, service_name, run_from, port, classifier, service_mapping_ports, version, proxy, append_args): | ||
SmMicroServiceStarter.__init__(self, context, service_name, "play", run_from, port, classifier, service_mapping_ports, version, proxy, append_args) | ||
|
||
if not self.port: | ||
self.port = self.service_data["defaultPort"] | ||
|
||
def supports_append_args(self): | ||
return True | ||
|
||
|
@@ -95,6 +97,10 @@ def start_from_binary(self): | |
parent, _ = os.path.split(unzip_dir) | ||
force_pushdir(parent) | ||
|
||
if "frontend" in self.service_data and self.service_data["frontend"]: | ||
assets_versions = self._get_assets_version(unzip_dir) | ||
self.context.assets_versions_to_start(assets_versions) | ||
|
||
cmd_with_params = self.get_start_command("BINARY") | ||
if os.path.exists(cmd_with_params[0]): | ||
os.chmod(cmd_with_params[0], stat.S_IRWXU) | ||
|
@@ -156,6 +162,15 @@ def start_from_sources(self): | |
print b.fail + "ERROR: could not start '" + self.service_name + "' " + b.endc | ||
return process.pid # Note: This is the parent pid | ||
|
||
def _get_assets_version(self, unzip_dir): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have unit tests that test happy and sad paths for this function? |
||
assets_versions = [] | ||
for conf_file in glob.glob(unzip_dir + "/conf/*.conf"): | ||
with file(conf_file) as conf: | ||
conf = conf.read() | ||
conf_string = "".join(conf.split()) | ||
pattern = re.compile(ur'Prod.*assets.*version="([0-9.]*)"') | ||
assets_versions = assets_versions + re.findall(pattern, conf_string) | ||
return assets_versions | ||
|
||
class SmPlayService(SmJvmService): | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ def resolve_services(self, service_name): | |
def resolve_services_from_array(self, services): | ||
services_to_start = [] | ||
services_to_not_start = [] | ||
|
||
for service_name in services: | ||
if service_name.startswith('-'): | ||
services_to_not_start += self.resolve_services(service_name[1:]) | ||
|
@@ -28,9 +29,19 @@ def resolve_services_from_array(self, services): | |
services_to_start.remove(not_start) | ||
return services_to_start | ||
|
||
def _find_assets_service_name(self, service_name): | ||
assets_service_name = '' | ||
for service_name in self.application.services: | ||
if self.application.services[service_name]['type'] == 'assets': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we make these strings constants? and perhaps make generic, for example the function could be "find_assets_of_type(self, service_name, type):" this can then be re-used... |
||
assets_service_name = service_name | ||
return assets_service_name | ||
|
||
def _get_all_in_profile(self, profile_name): | ||
services = [] | ||
services_to_not_start = [] | ||
|
||
assets_service_name = self._find_assets_service_name(profile_name) | ||
|
||
for service_name in self.application.services_for_profile(profile_name): | ||
if service_name.startswith('-'): | ||
services_to_not_start += self._all_matching(service_name[1:]) | ||
|
@@ -43,6 +54,9 @@ def _get_all_in_profile(self, profile_name): | |
for not_start in services_to_not_start: | ||
if not_start in services: | ||
services.remove(not_start) | ||
if assets_service_name in services: | ||
services.remove(assets_service_name) | ||
services.append(assets_service_name) | ||
return services | ||
|
||
def _all_matching(self, wildcard): | ||
|
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we rename this to be "is_frontend", you can also do "if self.service_data.get("is_frontend", False):"