Ejemplo n.º 1
0
 def test_caching(self, getfqdn_mock):
   hostname.cached_hostname = None
   hostname.cached_public_hostname = None
   getfqdn_mock.side_effect = ["test.example.com", "test2.example.com'"]
   self.assertEquals(hostname.hostname(), "test.example.com")
   self.assertEquals(hostname.hostname(), "test.example.com")
   self.assertEqual(getfqdn_mock.call_count, 1)
   pass
Ejemplo n.º 2
0
 def test_caching(self, getfqdn_mock):
     hostname.cached_hostname = None
     hostname.cached_public_hostname = None
     getfqdn_mock.side_effect = ["test.example.com", "test2.example.com'"]
     self.assertEquals(hostname.hostname(), "test.example.com")
     self.assertEquals(hostname.hostname(), "test.example.com")
     self.assertEqual(getfqdn_mock.call_count, 1)
     pass
Ejemplo n.º 3
0
 def test_hostname(self):
   hostname.cached_hostname = None
   hostname.cached_public_hostname = None
   config = AmbariConfig()
   self.assertEquals(hostname.hostname(config), socket.getfqdn().lower(),
                     "hostname should equal the socket-based hostname")
   pass
Ejemplo n.º 4
0
 def test_hostname(self):
   hostname.cached_hostname = None
   hostname.cached_public_hostname = None
   config = AmbariConfig()
   self.assertEquals(hostname.hostname(config), socket.getfqdn().lower(),
                     "hostname should equal the socket-based hostname")
   pass
Ejemplo n.º 5
0
  def build(self, id='-1', add_state=False, componentsMapped=False):
    global clusterId, clusterDefinitionRevision, firstContact
    timestamp = int(time.time()*1000)
    queueResult = self.actionQueue.result()
    recovery_timestamp = self.actionQueue.controller.recovery_manager.recovery_timestamp

    nodeStatus = { "status" : "HEALTHY",
                   "cause" : "NONE" }

    heartbeat = { 'responseId'        : int(id),
                  'timestamp'         : timestamp,
                  'hostname'          : hostname(self.config),
                  'nodeStatus'        : nodeStatus,
                  'recoveryTimestamp' : recovery_timestamp
                }

    rec_status = self.actionQueue.controller.recovery_manager.get_recovery_status()
    heartbeat['recoveryReport'] = rec_status

    commandsInProgress = False
    if not self.actionQueue.commandQueue.empty():
      commandsInProgress = True

    if len(queueResult) != 0:
      heartbeat['reports'] = queueResult['reports']
      heartbeat['componentStatus'] = queueResult['componentStatus']
      if len(heartbeat['reports']) > 0:
        # There may be IN_PROGRESS tasks
        commandsInProgress = True
      pass

    # For first request/heartbeat assume no components are mapped
    if int(id) == 0:
      componentsMapped = False

    logger.debug("Building Heartbeat: {responseId = %s, timestamp = %s, "
                "commandsInProgress = %s, componentsMapped = %s,"
                "recoveryTimestamp = %s}",
        str(id), str(timestamp), repr(commandsInProgress), repr(componentsMapped), str(recovery_timestamp))

    logger.debug("Heartbeat: %s", pformat(heartbeat))

    hostInfo = HostInfo(self.config)
    if add_state:
      logger.info("Adding host info/state to heartbeat message.")
      nodeInfo = { }
      # for now, just do the same work as registration
      # this must be the last step before returning heartbeat
      hostInfo.register(nodeInfo, componentsMapped, commandsInProgress)
      heartbeat['agentEnv'] = nodeInfo
      mounts = Hardware(config=self.config, cache_info=False).osdisks()
      heartbeat['mounts'] = mounts

      logger.debug("agentEnv: %s", str(nodeInfo))
      logger.debug("mounts: %s", str(mounts))

    if self.collector is not None:
      heartbeat['alerts'] = self.collector.alerts()
    
    return heartbeat
Ejemplo n.º 6
0
  def build(self, id='-1', state_interval=-1, componentsMapped=False):
    global clusterId, clusterDefinitionRevision, firstContact
    timestamp = int(time.time()*1000)
    queueResult = self.actionQueue.result()


    nodeStatus = { "status" : "HEALTHY",
                   "cause" : "NONE" }

    heartbeat = { 'responseId'        : int(id),
                  'timestamp'         : timestamp,
                  'hostname'          : hostname(self.config),
                  'nodeStatus'        : nodeStatus
                }

    rec_status = self.actionQueue.controller.recovery_manager.get_recovery_status()
    heartbeat['recoveryReport'] = rec_status

    commandsInProgress = False
    if not self.actionQueue.commandQueue.empty():
      commandsInProgress = True

    if len(queueResult) != 0:
      heartbeat['reports'] = queueResult['reports']
      heartbeat['componentStatus'] = queueResult['componentStatus']
      if len(heartbeat['reports']) > 0:
        # There may be IN_PROGRESS tasks
        commandsInProgress = True
      pass

    # For first request/heartbeat assume no components are mapped
    if int(id) == 0:
      componentsMapped = False

    logger.info("Building Heartbeat: {responseId = %s, timestamp = %s, commandsInProgress = %s, componentsMapped = %s}",
        str(id), str(timestamp), repr(commandsInProgress), repr(componentsMapped))

    if logger.isEnabledFor(logging.DEBUG):
      logger.debug("Heartbeat: %s", pformat(heartbeat))

    hostInfo = HostInfo(self.config)
    if (int(id) >= 0) and state_interval > 0 and (int(id) % state_interval) == 0:
      nodeInfo = { }
      # for now, just do the same work as registration
      # this must be the last step before returning heartbeat
      hostInfo.register(nodeInfo, componentsMapped, commandsInProgress)
      heartbeat['agentEnv'] = nodeInfo
      mounts = Hardware.osdisks(self.config)
      heartbeat['mounts'] = mounts

      if logger.isEnabledFor(logging.DEBUG):
        logger.debug("agentEnv: %s", str(nodeInfo))
        logger.debug("mounts: %s", str(mounts))

    if self.collector is not None:
      heartbeat['alerts'] = self.collector.alerts()
    
    return heartbeat
Ejemplo n.º 7
0
    def build(self, id='-1', state_interval=-1, componentsMapped=False):
        global clusterId, clusterDefinitionRevision, firstContact
        timestamp = int(time.time() * 1000)
        queueResult = self.actionQueue.result()

        nodeStatus = {"status": "HEALTHY", "cause": "NONE"}

        heartbeat = {
            'responseId': int(id),
            'timestamp': timestamp,
            'hostname': hostname(self.config),
            'nodeStatus': nodeStatus
        }

        commandsInProgress = False
        if not self.actionQueue.commandQueue.empty():
            commandsInProgress = True

        if len(queueResult) != 0:
            heartbeat['reports'] = queueResult['reports']
            heartbeat['componentStatus'] = queueResult['componentStatus']
            if len(heartbeat['reports']) > 0:
                # There may be IN_PROGRESS tasks
                commandsInProgress = True
            pass

        # For first request/heartbeat assume no components are mapped
        if int(id) == 0:
            componentsMapped = False

        logger.info(
            "Building Heartbeat: {responseId = %s, timestamp = %s, commandsInProgress = %s, componentsMapped = %s}",
            str(id), str(timestamp), repr(commandsInProgress),
            repr(componentsMapped))

        if logger.isEnabledFor(logging.DEBUG):
            logger.debug("Heartbeat: %s", pformat(heartbeat))

        hostInfo = HostInfo(self.config)
        if (int(id) >= 0) and state_interval > 0 and (int(id) %
                                                      state_interval) == 0:
            nodeInfo = {}
            # for now, just do the same work as registration
            # this must be the last step before returning heartbeat
            hostInfo.register(nodeInfo, componentsMapped, commandsInProgress)
            heartbeat['agentEnv'] = nodeInfo
            mounts = Hardware.osdisks()
            heartbeat['mounts'] = mounts

            if logger.isEnabledFor(logging.DEBUG):
                logger.debug("agentEnv: %s", str(nodeInfo))
                logger.debug("mounts: %s", str(mounts))

        if self.collector is not None:
            heartbeat['alerts'] = self.collector.alerts()

        return heartbeat
Ejemplo n.º 8
0
 def __init__(self, cluster_cache_dir, config):
     """
 Initializes the topology cache.
 :param cluster_cache_dir:
 :return:
 """
     self.hosts_to_id = ImmutableDictionary({})
     self.components_by_key = ImmutableDictionary({})
     self.hostname = hostname.hostname(config)
     self.current_host_ids_to_cluster = {}
     self.cluster_local_components = {}
     self.cluster_host_info = None
     super(ClusterTopologyCache, self).__init__(cluster_cache_dir)
  def test_hostname_override(self):
    fd = tempfile.mkstemp(text=True)
    tmpname = fd[1]
    os.close(fd[0])
    os.chmod(tmpname, os.stat(tmpname).st_mode | stat.S_IXUSR)

    tmpfile = file(tmpname, "w+")
    config = AmbariConfig.config
    try:
      tmpfile.write("#!/bin/sh\n\necho 'test.example.com'")
      tmpfile.close()

      config.set('agent', 'hostname_script', tmpname)

      self.assertEquals(hostname.hostname(), 'test.example.com', "expected hostname 'test.example.com'")
    finally:
      os.remove(tmpname)
      config.remove_option('agent', 'hostname_script')

    pass
Ejemplo n.º 10
0
    def test_hostname_override(self):
        fd = tempfile.mkstemp(text=True)
        tmpname = fd[1]
        os.close(fd[0])
        os.chmod(tmpname, os.stat(tmpname).st_mode | stat.S_IXUSR)

        tmpfile = file(tmpname, "w+")
        config = AmbariConfig.config
        try:
            tmpfile.write("#!/bin/sh\n\necho 'test.example.com'")
            tmpfile.close()

            config.set('agent', 'hostname_script', tmpname)

            self.assertEquals(hostname.hostname(), 'test.example.com',
                              "expected hostname 'test.example.com'")
        finally:
            os.remove(tmpname)
            config.remove_option('agent', 'hostname_script')

        pass
Ejemplo n.º 11
0
    def build(self, response_id='-1'):
        timestamp = int(time.time() * 1000)

        hostInfo = HostInfo(self.config)
        agentEnv = {}
        hostInfo.register(agentEnv, runExpensiveChecks=True)

        current_ping_port = self.config.get('agent', 'ping_port')

        register = {
            'id': int(response_id),
            'timestamp': timestamp,
            'hostname': hostname.hostname(self.config),
            'currentPingPort': int(current_ping_port),
            'publicHostname': hostname.public_hostname(self.config),
            'hardwareProfile': self.hardware.get(),
            'agentEnv': agentEnv,
            'agentVersion': Utils.read_agent_version(self.config),
            'prefix': self.config.get('agent', 'prefix')
        }
        return register
Ejemplo n.º 12
0
    def test_hostname_override(self):
        hostname.cached_hostname = None
        hostname.cached_public_hostname = None
        fd = tempfile.mkstemp(text=True)
        tmpname = fd[1]
        os.close(fd[0])
        os.chmod(tmpname, os.stat(tmpname).st_mode | stat.S_IXUSR)

        tmpfile = file(tmpname, "w+")
        config = AmbariConfig()
        try:
            tmpfile.write("#!/bin/sh\n\necho 'test.example.com'")
            tmpfile.close()

            config.set("agent", "hostname_script", tmpname)

            self.assertEquals(hostname.hostname(config), "test.example.com", "expected hostname 'test.example.com'")
        finally:
            os.remove(tmpname)
            config.remove_option("agent", "hostname_script")
        pass
Ejemplo n.º 13
0
 def test_hostname(self):
     self.assertEquals(hostname.hostname(), socket.getfqdn(),
                       "hostname should equal the socket-based hostname")
     pass
 def test_hostname(self):
   self.assertEquals(hostname.hostname(), socket.getfqdn(), 
                     "hostname should equal the socket-based hostname")
   pass
Ejemplo n.º 15
0
 def test_hostname(self):
     hostname.cached_hostname = None
     hostname.cached_public_hostname = None
     self.assertEquals(hostname.hostname(), socket.getfqdn(),
                       "hostname should equal the socket-based hostname")
     pass
Ejemplo n.º 16
0
 def test_hostname(self):
   hostname.cached_hostname = None
   hostname.cached_public_hostname = None
   self.assertEquals(hostname.hostname(), socket.getfqdn(), 
                     "hostname should equal the socket-based hostname")
   pass