コード例 #1
0
 def test_service_request_start(self, mock1, mock2, mock3, mock4):
   client = Ambari(self.un, self.pw, self.proto, self.server, self.port)
   
   try:
     client.service_action('Sandbox', 'YARN', 'BAD_ACTION')
     self.fail('Should have thrown value error on BAD_ACTION')
   except ValueError as e:
     assert str(e) == 'Service action must be one of: START, STOP, or RESTART'
 
   val = client.service_action('Sandbox', 'YARN', 'START')
   assert val == False
コード例 #2
0
 def test_bad_config_ambari_service(self, mock1):
   conf = {
     'b': 'test_username',
     'a': 'test_password',
     'c': 'https',
     'd': 'sandbox_server',
     'e': 12309
   }
   
   amc = Ambari(config=conf)
             
   amc.service_action('KAFKA', 'Sandbox', 'START')
コード例 #3
0
    def test_service_request_start(self, mock1, mock2, mock3, mock4):
        client = Ambari(self.un, self.pw, self.proto, self.server, self.port)

        try:
            client.service_action('Sandbox', 'YARN', 'BAD_ACTION')
            self.fail('Should have thrown value error on BAD_ACTION')
        except ValueError as e:
            assert str(
                e) == 'Service action must be one of: START, STOP, or RESTART'

        val = client.service_action('Sandbox', 'YARN', 'START')
        assert val == False
コード例 #4
0
    def test_bad_config_ambari_service(self, mock1):
        conf = {
            'b': 'test_username',
            'a': 'test_password',
            'c': 'https',
            'd': 'sandbox_server',
            'e': 12309
        }

        amc = Ambari(config=conf)

        amc.service_action('KAFKA', 'Sandbox', 'START')
コード例 #5
0
def get_kafka_topics():
  '''List the kafka topics on the current installation.
  
  Requires that Kafka is installed on the same machine and Ambari is up and running. Will start the service and use the Kafka scripts to list out all of the topics.
  
  
  Args:
    N/A
    
  Returns:
    list: [0] will contain the list of all the topics in a string, typically separated by newlines. [1] will contain any errors when retrieving the topics.
  
  '''
  conf = config.read_config('global.conf')
  am_conf = conf['AMBARI']
  amc = Ambari(am_conf['username'], am_conf['password'], am_conf['proto'], am_conf['server'], am_conf['port']);
  
  logger.info('Starting Kafka Broker')
  
  if amc.service_action('Sandbox', 'KAFKA', 'START'):
    sh = Shell()
    topics_script = conf['DEMO']['kafka_topics_script']
    zk = conf['DEMO']['zk_connection']
    logger.info('Attempting to create new Kafka Topic')
    out = sh.run(topics_script + ' --list --zookeeper ' + zk)
    
    if len(out[1]) == 0:
      topics = out[0]
      topics = topics.strip().split('\n')
      logger.info('Kafka topics output: ' + str(topics))
      return topics
    
  return ['', 'Unable to get topics. Could not start Kafka Broker']
コード例 #6
0
def create_demo_kafka_topic():
  '''Creates a kafka topic for the demo if it doesn't already exist.
  
  The caveat here in using this is that Kafka must be installed on the same machine as the demo, and thus the same machine as Ambari as well. The function will try to start the Kafka service through Ambari and then once the service is started is will use the location of the Kafka topics script to create the topic
  
  The name for the topic is specified in ``global.conf``.
  
  
  Args:
    N/A
    
  Returns:
    bool: True if the creation is successful. False otherwise.
  '''
  conf = config.read_config('global.conf')
  am_conf = conf['AMBARI']
  amc = Ambari(am_conf['username'], am_conf['password'], am_conf['proto'], am_conf['server'], am_conf['port']);
  
  logger.info('Starting Kafka Broker')
  
  if amc.service_action('Sandbox', 'KAFKA', 'START'):
    sh = Shell()
    topics_script = conf['DEMO']['kafka_topics_script']
    zk = conf['DEMO']['zk_connection']
    topic_name = conf['DEMO']['kafka_topic_name']
    logger.info('Attempting to create new Kafka Topic')
    out = sh.run(topics_script + ' --create --zookeeper ' + zk + ' --replication-factor 1 --partitions 1 --topic ' + topic_name)
    logger.debug(str(out))
    if len(out[1]) == 0:
      return True
    else:
      return False
コード例 #7
0
def create_demo_kafka_topic():
    '''Creates a kafka topic for the demo if it doesn't already exist.
  
  The caveat here in using this is that Kafka must be installed on the same machine as the demo, and thus the same machine as Ambari as well. The function will try to start the Kafka service through Ambari and then once the service is started is will use the location of the Kafka topics script to create the topic
  
  The name for the topic is specified in ``global.conf``.
  
  
  Args:
    N/A
    
  Returns:
    bool: True if the creation is successful. False otherwise.
  '''
    conf = config.read_config('global.conf')
    am_conf = conf['AMBARI']
    amc = Ambari(am_conf['username'], am_conf['password'], am_conf['proto'],
                 am_conf['server'], am_conf['port'])

    logger.info('Starting Kafka Broker')

    if amc.service_action('Sandbox', 'KAFKA', 'START'):
        sh = Shell()
        topics_script = conf['DEMO']['kafka_topics_script']
        zk = conf['DEMO']['zk_connection']
        topic_name = conf['DEMO']['kafka_topic_name']
        logger.info('Attempting to create new Kafka Topic')
        out = sh.run(topics_script + ' --create --zookeeper ' + zk +
                     ' --replication-factor 1 --partitions 1 --topic ' +
                     topic_name)
        logger.debug(str(out))
        if len(out[1]) == 0:
            return True
        else:
            return False
コード例 #8
0
def get_kafka_topics():
    '''List the kafka topics on the current installation.
  
  Requires that Kafka is installed on the same machine and Ambari is up and running. Will start the service and use the Kafka scripts to list out all of the topics.
  
  
  Args:
    N/A
    
  Returns:
    list: [0] will contain the list of all the topics in a string, typically separated by newlines. [1] will contain any errors when retrieving the topics.
  
  '''
    conf = config.read_config('global.conf')
    am_conf = conf['AMBARI']
    amc = Ambari(am_conf['username'], am_conf['password'], am_conf['proto'],
                 am_conf['server'], am_conf['port'])

    logger.info('Starting Kafka Broker')

    if amc.service_action('Sandbox', 'KAFKA', 'START'):
        sh = Shell()
        topics_script = conf['DEMO']['kafka_topics_script']
        zk = conf['DEMO']['zk_connection']
        logger.info('Attempting to create new Kafka Topic')
        out = sh.run(topics_script + ' --list --zookeeper ' + zk)

        if len(out[1]) == 0:
            topics = out[0]
            topics = topics.strip().split('\n')
            logger.info('Kafka topics output: ' + str(topics))
            return topics

    return ['', 'Unable to get topics. Could not start Kafka Broker']
コード例 #9
0
def on_service_start():
    '''This method will run every time the service start
  
  Fill in this method with any necessary commands to set up and start other services for the demo
  
  Note that this method will always be the very last thing to be executed upon starting the demo service
  '''
    print 'Running on_service_start'
    cfg = config.read_config('global.conf')

    # Ambari Client
    amc = Ambari(config=cfg['AMBARI'])

    #Queue  Services
    amc.service_action('Sandbox', 'KAFKA', 'START', queue=True)
    amc.service_action('Sandbox', 'ZEPPELIN', 'START', queue=True)
    try:
        # Not guaranteed to be installed
        amc.service_action('Sandbox', 'NIFI', 'START', queue=True)
    except:
        log.warn('Failed to start NiFi')

    service_installer.add_zeppelin_notebooks()
    # Add anything else below that might be necessary for when the demo starts

    pass
コード例 #10
0
def on_service_start():
  '''This method will run every time the service start
  
  Fill in this method with any necessary commands to set up and start other services for the demo
  
  Note that this method will always be the very last thing to be executed upon starting the demo service
  '''
  print 'Running on_service_start'
  cfg = config.read_config('global.conf')
  
  # Ambari Client
  amc = Ambari(config=cfg['AMBARI'])
  
  #Queue  Services
  amc.service_action('Sandbox', 'KAFKA', 'START', queue=True)
  amc.service_action('Sandbox', 'ZEPPELIN', 'START', queue=True)
  try:
    # Not guaranteed to be installed
    amc.service_action('Sandbox', 'NIFI', 'START', queue=True)
  except:
    log.warn('Failed to start NiFi')
  
  service_installer.add_zeppelin_notebooks()
  # Add anything else below that might be necessary for when the demo starts
  
  
  
  
  pass
コード例 #11
0
	def test_service_request_bad_req(self, mock1, mock2, mock3, mock4):
		client = Ambari(self.un, self.pw, self.proto, self.server, self.port)
		
		val = client.service_action('Sandbox', 'YARN', 'STOP')
		assert val == False
				
		
		
		
		
		
		
		
		
		
		
		
		
コード例 #12
0
 def test_service_request_started(self, mock1, mock2, mock3):
   client = Ambari(self.un, self.pw, self.proto, self.server, self.port)
   
   val = client.service_action('Sandbox', 'YARN', 'START')
   assert val == True
コード例 #13
0
    def test_service_request_bad_req(self, mock1, mock2, mock3, mock4):
        client = Ambari(self.un, self.pw, self.proto, self.server, self.port)

        val = client.service_action('Sandbox', 'YARN', 'STOP')
        assert val == False
コード例 #14
0
    def test_service_request_started(self, mock1, mock2, mock3):
        client = Ambari(self.un, self.pw, self.proto, self.server, self.port)

        val = client.service_action('Sandbox', 'YARN', 'START')
        assert val == True