diff --git a/atomicapp/nulecule/base.py b/atomicapp/nulecule/base.py index 09016c79..83689333 100644 --- a/atomicapp/nulecule/base.py +++ b/atomicapp/nulecule/base.py @@ -10,6 +10,7 @@ from atomicapp.constants import (APP_ENT_PATH, EXTERNAL_APP_DIR, GLOBAL_CONF, + LOGGER_COCKPIT, LOGGER_DEFAULT, MAIN_FILE, RESOURCE_KEY, @@ -28,6 +29,7 @@ from jsonpointer import resolve_pointer, set_pointer, JsonPointerException +cockpitlogger = logging.getLogger(LOGGER_COCKPIT) logger = logging.getLogger(LOGGER_DEFAULT) @@ -101,6 +103,7 @@ def unpack(cls, image, dest, config=None, namespace=GLOBAL_CONF, docker_handler = DockerHandler(dryrun=dryrun) docker_handler.pull(image) docker_handler.extract(image, APP_ENT_PATH, dest, update) + cockpitlogger.info("All dependencies installed successfully.") return cls.load_from_path( dest, config=config, namespace=namespace, nodeps=nodeps, dryrun=dryrun, update=update) @@ -160,6 +163,7 @@ def run(self, provider_key=None, dryrun=False): # Process components for component in self.components: component.run(provider_key, dryrun) + cockpitlogger.info("Component %s installed successfully" % provider_key) def stop(self, provider_key=None, dryrun=False): """ @@ -272,6 +276,7 @@ def load(self, nodeps=False, dryrun=False): """ Load external application of the Nulecule component. """ + cockpitlogger.info("Loading app %s ." % self.name) if self.source: if nodeps: logger.info( @@ -283,6 +288,7 @@ def run(self, provider_key, dryrun=False): """ Run the Nulecule component with the specified provider, """ + cockpitlogger.info("Deploying component %s ..." % self.name) if self._app: self._app.run(provider_key, dryrun) return @@ -347,6 +353,7 @@ def load_external_application(self, dryrun=False, update=False): update=update ) self._app = nulecule + cockpitlogger.info("Copied app successfully.") @property def components(self): diff --git a/atomicapp/nulecule/container.py b/atomicapp/nulecule/container.py index 29126c10..20389cbc 100644 --- a/atomicapp/nulecule/container.py +++ b/atomicapp/nulecule/container.py @@ -4,11 +4,13 @@ import logging from atomicapp.constants import (APP_ENT_PATH, + LOGGER_COCKPIT, LOGGER_DEFAULT, MAIN_FILE) from atomicapp.utils import Utils from atomicapp.nulecule.exceptions import NuleculeException +cockpitlogger = logging.getLogger(LOGGER_COCKPIT) logger = logging.getLogger(LOGGER_DEFAULT) @@ -48,6 +50,7 @@ def pull(self, image, update=False): """ if not self.is_image_present(image) or update: logger.info('Pulling Docker image: %s' % image) + cockpitlogger.info('Pulling Docker image: %s' % image) pull_cmd = [self.docker_cli, 'pull', image] logger.debug(' '.join(pull_cmd)) else: @@ -59,6 +62,8 @@ def pull(self, image, update=False): elif subprocess.call(pull_cmd) != 0: raise Exception("Could not pull Docker image %s" % image) + cockpitlogger.info('Skipping pulling Docker image: %s' % image) + def extract(self, image, source, dest, update=False): """ Extracts content from a directory in a Docker image to specified @@ -110,6 +115,7 @@ def extract(self, image, source, dest, update=False): if os.path.exists(mainfile): existing_id = Utils.getAppId(mainfile) new_id = Utils.getAppId(tmpmainfile) + cockpitlogger.info("Loading app_id %s ." % new_id) if existing_id != new_id: raise NuleculeException( "Existing app (%s) and requested app (%s) differ" % diff --git a/atomicapp/nulecule/lib.py b/atomicapp/nulecule/lib.py index 4dd41f39..904fa28b 100644 --- a/atomicapp/nulecule/lib.py +++ b/atomicapp/nulecule/lib.py @@ -1,11 +1,16 @@ # -*- coding: utf-8 -*- +import logging + from atomicapp.constants import (GLOBAL_CONF, + LOGGER_COCKPIT, NAME_KEY, DEFAULTNAME_KEY, PROVIDER_KEY) from atomicapp.utils import Utils from atomicapp.plugin import Plugin +cockpitlogger = logging.getLogger(LOGGER_COCKPIT) + class NuleculeBase(object): @@ -44,6 +49,7 @@ def load_config(self, config, ask=False, skip_asking=False): config.get(GLOBAL_CONF, {}).get(param[NAME_KEY]) if value is None and (ask or ( not skip_asking and param.get(DEFAULTNAME_KEY) is None)): + cockpitlogger.info("%s is missing in answers.conf." % param[NAME_KEY]) value = Utils.askFor(param[NAME_KEY], param) elif value is None: value = param.get(DEFAULTNAME_KEY) diff --git a/atomicapp/nulecule/main.py b/atomicapp/nulecule/main.py index 88cd8a62..1bd18b7d 100644 --- a/atomicapp/nulecule/main.py +++ b/atomicapp/nulecule/main.py @@ -14,6 +14,7 @@ ANSWERS_FILE_SAMPLE, ANSWERS_RUNTIME_FILE, DEFAULT_ANSWERS, + LOGGER_COCKPIT, LOGGER_DEFAULT, MAIN_FILE, PROVIDER_KEY) @@ -21,6 +22,7 @@ from atomicapp.nulecule.exceptions import NuleculeException from atomicapp.utils import Utils +cockpitlogger = logging.getLogger(LOGGER_COCKPIT) logger = logging.getLogger(LOGGER_DEFAULT) @@ -192,6 +194,8 @@ def fetch(self, nodeps=False, update=False, dryrun=False, os.path.join(self.app_path, ANSWERS_FILE_SAMPLE), runtime_answers, answers_format) + cockpitlogger.info("Install Successful.") + def run(self, cli_provider, answers_output, ask, answers_format=ANSWERS_FILE_SAMPLE_FORMAT, **kwargs): """ diff --git a/atomicapp/providers/kubernetes.py b/atomicapp/providers/kubernetes.py index 9d6545b7..1eb45c53 100644 --- a/atomicapp/providers/kubernetes.py +++ b/atomicapp/providers/kubernetes.py @@ -22,10 +22,12 @@ import os from string import Template -from atomicapp.constants import LOGGER_DEFAULT +from atomicapp.constants import (LOGGER_COCKPIT, + LOGGER_DEFAULT) from atomicapp.plugin import Provider, ProviderFailedException -from atomicapp.utils import printErrorStatus, Utils +from atomicapp.utils import Utils +cockpitlogger = logging.getLogger(LOGGER_COCKPIT) logger = logging.getLogger(LOGGER_DEFAULT) @@ -124,7 +126,7 @@ def process_k8s_artifacts(self): except Exception: msg = "Error processing %s artifcats, Error:" % os.path.join( self.path, artifact) - printErrorStatus(msg) + cockpitlogger.error(msg) raise if "kind" in data: self.k8s_manifests.append((data["kind"].lower(), artifact)) diff --git a/atomicapp/providers/marathon.py b/atomicapp/providers/marathon.py index e98bc3ae..0653db21 100644 --- a/atomicapp/providers/marathon.py +++ b/atomicapp/providers/marathon.py @@ -21,12 +21,13 @@ import urlparse import logging import os -from atomicapp.constants import LOGGER_DEFAULT +from atomicapp.constants import (LOGGER_COCKPIT, + LOGGER_DEFAULT) from atomicapp.plugin import Provider, ProviderFailedException -from atomicapp.utils import printErrorStatus from atomicapp.utils import Utils from atomicapp.constants import PROVIDER_API_KEY +cockpitlogger = logging.getLogger(LOGGER_COCKPIT) logger = logging.getLogger(LOGGER_DEFAULT) @@ -116,10 +117,10 @@ def _process_artifacts(self): # every marathon app has to have id. 'id' key is also used for showing messages if "id" not in data.keys(): msg = "Error processing %s artifact. There is no id" % artifact - printErrorStatus(msg) + cockpitlogger.error(msg) raise ProviderFailedException(msg) except anymarkup.AnyMarkupError, e: msg = "Error processing artifact - %s" % e - printErrorStatus(msg) + cockpitlogger.error(msg) raise ProviderFailedException(msg) self.marathon_artifacts.append(data) diff --git a/atomicapp/utils.py b/atomicapp/utils.py index 7808aedb..10581354 100644 --- a/atomicapp/utils.py +++ b/atomicapp/utils.py @@ -36,29 +36,19 @@ CACHE_DIR, EXTERNAL_APP_DIR, HOST_DIR, + LOGGER_COCKPIT, LOGGER_DEFAULT, WORKDIR) __all__ = ('Utils') +cockpitlogger = logging.getLogger(LOGGER_COCKPIT) logger = logging.getLogger(LOGGER_DEFAULT) class AtomicAppUtilsException(Exception): pass -# Following Methods(printStatus, printErrorStatus) -# are required for Cockpit or thirdparty management tool integration -# DONOT change the atomicapp.status.* prefix in the logger method. - - -def printStatus(message): - logger.info("atomicapp.status.info.message=" + str(message)) - - -def printErrorStatus(message): - logger.info("atomicapp.status.error.message=" + str(message)) - def find_binary(executable, path=None): """Tries to find 'executable' in the directories listed in 'path'. @@ -271,7 +261,7 @@ def run_cmd(cmd, checkexitcode=True, stdin=None): # we were asked not to. if checkexitcode: if ec != 0: - printErrorStatus("cmd failed: %s" % str(cmd)) # For cockpit + cockpitlogger.error("cmd failed: %s" % str(cmd)) raise AtomicAppUtilsException( "cmd: %s failed: \n%s" % (str(cmd), stderr))