Skip to content
Permalink
Browse files
AMBARI-24724. Remove ambari-metrics dependency on ambari-commons. (#4)
  • Loading branch information
swagle committed Oct 3, 2018
1 parent dc75b01 commit e8786295d2ee1de803c04241434c0c5eaa2fa99d
Showing 34 changed files with 8,748 additions and 94 deletions.
@@ -54,7 +54,6 @@
<storm.sink.jar>ambari-metrics-storm-sink-with-common-${project.version}.jar</storm.sink.jar>
<flume.sink.jar>ambari-metrics-flume-sink-with-common-${project.version}.jar</flume.sink.jar>
<kafka.sink.jar>ambari-metrics-kafka-sink-with-common-${project.version}.jar</kafka.sink.jar>
<ambari.commons.location>${monitor.dir}/target/ambari-python/site-packages/ambari_commons</ambari.commons.location>
</properties>

<build>
@@ -598,14 +597,6 @@
</source>
</sources>
</mapping>
<mapping>
<directory>${resmonitor.install.dir}/ambari_commons</directory>
<sources>
<source>
<location>${ambari.commons.location}</location>
</source>
</sources>
</mapping>
<mapping>
<directory>/var/lib/ambari-metrics-monitor/lib</directory>
<sources>
@@ -745,14 +736,6 @@
<prefix>${resmonitor.install.dir}/psutil</prefix>
</mapper>
</data>
<data>
<type>directory</type>
<src>${ambari.commons.location}</src>
<mapper>
<type>perm</type>
<prefix>${resmonitor.install.dir}/ambari_commons</prefix>
</mapper>
</data>
<data>
<type>template</type>
<paths>
@@ -30,13 +30,6 @@
<directory>${monitor.dir}/src/main/python</directory>
<outputDirectory>site-packages/resource_monitoring</outputDirectory>
</fileSet>
<fileSet>
<directory>${project.basedir}/../../ambari-common/src/main/python/ambari_commons</directory>
<outputDirectory>site-packages/resource_monitoring/ambari_commons</outputDirectory>
<includes>
<include>**/*</include>
</includes>
</fileSet>
<fileSet>
<directory>${monitor.dir}/conf/unix</directory>
<outputDirectory>conf</outputDirectory>
@@ -36,12 +36,6 @@
<final.name>${project.artifactId}-${project.version}</final.name>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.ambari</groupId>
<artifactId>ambari-python</artifactId>
<version>2.7.1.1</version>
<type>tar.gz</type>
</dependency>
</dependencies>
<build>
<plugins>
@@ -124,7 +118,9 @@
<exclude>conf/unix/metric_groups.conf</exclude>
<exclude>conf/windows/metric_groups.conf</exclude>
<exclude>src/main/python/psutil/**</exclude>
<exclude>.pydevproject</exclude>
<exclude>.pydevproject</exclude>
<!--Python Mock library (BSD license)-->
<exclude>src/test/python/mock/**</exclude>
</excludes>
</configuration>
<executions>
@@ -180,25 +176,6 @@
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<id>unpack-ambari-common</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<includeTypes>tar.gz</includeTypes>
<includeArtifactIds>ambari-python</includeArtifactIds>
<outputDirectory>target/ambari-python</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
@@ -22,9 +22,6 @@
import StringIO
import json
import os
from ambari_commons import OSConst
from ambari_commons.os_family_impl import OsFamilyImpl


#
# Abstraction for OS-dependent configuration defaults
@@ -39,7 +36,6 @@ def get_metric_file_path(self):
def get_ca_certs_file_path(self):
pass

@OsFamilyImpl(os_family=OsFamilyImpl.DEFAULT)
class ConfigDefaultsLinux(ConfigDefaults):
def __init__(self):
self._CONFIG_DIR = "/etc/ambari-metrics-monitor/conf/"
@@ -56,7 +52,7 @@ def get_metric_file_path(self):
def get_ca_certs_file_path(self):
return self._CA_CERTS_FILE_PATH

configDefaults = ConfigDefaults()
configDefaults = ConfigDefaultsLinux()

config = ConfigParser.RawConfigParser()

@@ -19,16 +19,10 @@
'''

import logging
import os
import signal
import threading
import traceback

from ambari_commons import OSConst, OSCheck
from ambari_commons.exceptions import FatalException
from ambari_commons.os_family_impl import OsFamilyImpl


logger = logging.getLogger()

_handler = None
@@ -61,7 +55,6 @@ def debug(sig, frame):
logger.info(message)


@OsFamilyImpl(os_family=OsFamilyImpl.DEFAULT)
class StopHandlerLinux(StopHandler):
def __init__(self, stopEvent=None):
# Event used to gracefully stop the process
@@ -86,10 +79,9 @@ def wait(self, timeout=None):


def bind_signal_handlers(new_handler=None):
if OSCheck.get_os_family() != OSConst.WINSRV_FAMILY:
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
signal.signal(signal.SIGUSR1, debug)
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
signal.signal(signal.SIGUSR1, debug)

if new_handler is None:
global _handler
@@ -23,13 +23,10 @@
import os
import sys
import signal
from ambari_commons.os_utils import remove_file

from core.controller import Controller
from core.config_reader import Configuration, PID_OUT_FILE
from core.stop_handler import bind_signal_handlers


logger = logging.getLogger()

main_config = Configuration()
@@ -38,14 +35,16 @@ def save_pid(pid, pidfile):
"""
Save pid to pidfile.
"""
pfile = None
try:
pfile = open(pidfile, "w")
pfile.write("%s\n" % pid)
except IOError:
pass
finally:
try:
pfile.close()
if pfile:
pfile.close()
except:
pass

@@ -81,7 +80,7 @@ def server_process_main(stop_handler, scmStatus=None):
#The controller thread finishes when the stop event is signaled
controller.join()

remove_file(PID_OUT_FILE)
os.remove(PID_OUT_FILE)
pass

def _init_logging(config):
@@ -18,7 +18,7 @@
limitations under the License.
'''

from ambari_commons.subprocess32 import call
from subprocess import call
import sys
import os
import shutil
@@ -44,7 +44,7 @@
import signal
import warnings
import errno
from ambari_commons import subprocess32
import subprocess
try:
import pwd
except ImportError:
@@ -1163,14 +1163,14 @@ def set_nice(self, value):
# =====================================================================

class Popen(Process):
"""A more convenient interface to stdlib subprocess32 module.
"""A more convenient interface to stdlib subprocess module.
It starts a sub process and deals with it exactly as when using
subprocess32.Popen class but in addition also provides all the
subprocess.Popen class but in addition also provides all the
properties and methods of psutil.Process class as a unified
interface:
>>> import psutil
>>> from ambari_commons.subprocess32 import PIPE
>>> from subprocess import PIPE
>>> p = psutil.Popen(["python", "-c", "print 'hi'"], stdout=PIPE)
>>> p.name()
'python'
@@ -1188,24 +1188,24 @@ class Popen(Process):
For method names common to both classes such as kill(), terminate()
and wait(), psutil.Process implementation takes precedence.
Unlike subprocess32.Popen this class pre-emptively checks wheter PID
Unlike subprocess.Popen this class pre-emptively checks wheter PID
has been reused on send_signal(), terminate() and kill() so that
you don't accidentally terminate another process, fixing
http://bugs.python.org/issue6973.
For a complete documentation refer to:
http://docs.python.org/library/subprocess32.html
http://docs.python.org/library/subprocess.html
"""

def __init__(self, *args, **kwargs):
# Explicitly avoid to raise NoSuchProcess in case the process
# spawned by subprocess32.Popen terminates too quickly, see:
# spawned by subprocess.Popen terminates too quickly, see:
# https://code.google.com/p/psutil/issues/detail?id=193
self.__subproc = subprocess32.Popen(*args, **kwargs)
self.__subproc = subprocess.Popen(*args, **kwargs)
self._init(self.__subproc.pid, _ignore_nsp=True)

def __dir__(self):
return sorted(set(dir(Popen) + dir(subprocess32.Popen)))
return sorted(set(dir(Popen) + dir(subprocess.Popen)))

def __getattribute__(self, name):
try:
@@ -9,7 +9,7 @@
import errno
import os
import socket
from ambari_commons import subprocess32
import subprocess
import sys

from psutil import _common
@@ -91,7 +91,7 @@ def swap_memory():
# usr/src/cmd/swap/swap.c
# ...nevertheless I can't manage to obtain the same numbers as 'swap'
# cmdline utility, so let's parse its output (sigh!)
p = subprocess32.Popen(['swap', '-l', '-k'], stdout=subprocess32.PIPE)
p = subprocess.Popen(['swap', '-l', '-k'], stdout=subprocess.PIPE)
stdout, stderr = p.communicate()
if PY3:
stdout = stdout.decode(sys.stdout.encoding)
@@ -433,8 +433,8 @@ def _get_unix_sockets(self, pid):
# TODO: rewrite this in C (...but the damn netstat source code
# does not include this part! Argh!!)
cmd = "pfiles %s" % pid
p = subprocess32.Popen(cmd, shell=True, stdout=subprocess32.PIPE,
stderr=subprocess32.PIPE)
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
if PY3:
stdout, stderr = [x.decode(sys.stdout.encoding)
@@ -17,7 +17,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

export PYTHONPATH=/usr/lib/python2.6/site-packages:/usr/lib/python2.6/site-packages/ambari_commons:$PYTHONPATH
export PYTHONPATH=/usr/lib/python2.6/site-packages:$PYTHONPATH

# checking for default Python 2
if [ -a /usr/bin/python2 ] && [ -z "$PYTHON" ]; then
@@ -31,7 +31,6 @@
os_distro_value = ('Suse','11','Final')

with patch("platform.linux_distribution", return_value = os_distro_value):
from ambari_commons import OSCheck
from application_metric_map import ApplicationMetricMap
from config_reader import Configuration
from emitter import Emitter
@@ -41,7 +40,6 @@

class TestEmitter(TestCase):

@patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
@patch.object(CachedHTTPConnection, "create_connection", new = MagicMock())
@patch.object(CachedHTTPConnection, "request")
@patch.object(CachedHTTPConnection, "getresponse")
@@ -63,7 +61,6 @@ def test_submit_metrics(self, getresponse_mock, request_mock):
self.assertUrlData(request_mock)


@patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
@patch.object(CachedHTTPConnection, "create_connection", new = MagicMock())
@patch.object(CachedHTTPConnection, "getresponse", new = MagicMock())
@patch.object(CachedHTTPConnection, "request")
@@ -83,7 +80,6 @@ def testRetryFetchAndRoundRobin(self, request_mock):
self.assertEqual(request_mock.call_count, 3)
self.assertUrlData(request_mock)

@patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
@patch.object(CachedHTTPConnection, "create_connection", new = MagicMock())
@patch.object(SPNEGOKerberosAuth, "authenticate_handshake")
@patch.object(CachedHTTPConnection, "getresponse")
@@ -0,0 +1,26 @@
Copyright (c) 2003-2012, Michael Foord
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,2 @@
include LICENSE.txt tox.ini tests/*.py
recursive-include docs *.txt *.py *.png *.css *.html *.js

0 comments on commit e878629

Please sign in to comment.