def getActiveNN(cls, host, component, cluster=None):
     if cluster == None:
         cluster = 'cl1'
     weburl = cls.getweburl(host)
     count = 5
     length = 1
     while count > 0 and length >= 1:
         url = "%s/api/v1/clusters/%s/host_components?HostRoles/component_name=%s&metrics/dfs/FSNamesystem/HAState=active" % (
             weburl, cluster, component)
         auth = HTTPBasicAuth(Ambari.getAdminUsername(),
                              Ambari.getAdminPassword())
         head = {'X-Requested-By': 'ambari', 'Content-Type': 'text/plain'}
         response = requests.get(url=url,
                                 headers=head,
                                 auth=auth,
                                 verify=False)
         assert response.status_code == 200, "Failed to get config versions."
         json = response.json()
         items = json['items']
         length = len(items)
         count = count - 1
         time.sleep(10)
     last = items[-1]
     active_nn = last['HostRoles']['host_name']
     return active_nn
 def stopComponent(cls, host, component, component_host, cluster=None):
     if cluster == None:
         cluster = 'cl1'
     weburl = cls.getweburl(host)
     url = "%s/api/v1/clusters/%s/hosts/%s/host_components/%s" % (
         weburl, cluster, component_host, component)
     head = {'X-Requested-By': 'ambari', 'Content-Type': 'text/plain'}
     data = '{ "HostRoles": { "state": "INSTALLED" } }'
     auth = HTTPBasicAuth(Ambari.getAdminUsername(),
                          Ambari.getAdminPassword())
     response = requests.put(url,
                             data=data,
                             headers=head,
                             auth=auth,
                             verify=False)
     assert (response.status_code == 200 or response.status_code == 202
             ), "Failed to stop component %s on host %s, status=%d" % (
                 component, host, response.status_code)
     if response.status_code is 202:
         json_data = json.loads(response._content)
         request_id = json_data['Requests']['id']
         logger.info("Waiting for the service " + component + " to stop..")
         while not cls.get_request_current_state(host, request_id,
                                                 cluster) == 'COMPLETED':
             if cls.get_request_current_state(host, request_id,
                                              cluster) == 'FAILED':
                 break
             time.sleep(10)
Exemple #3
0
 def get_request_current_state(cls, request_id, cluster=None):
     if cluster == None:
         cluster = 'cl1'
     weburl = Ambari.getWebUrl()
     url = "%s/api/v1/clusters/%s/requests/%s" % (weburl, cluster, request_id)
     auth = HTTPBasicAuth(Ambari.getAdminUsername(), Ambari.getAdminPassword())
     head = {'X-Requested-By': 'ambari', 'Content-Type': 'text/plain'}
     response = requests.get(url=url, headers=head, auth=auth, verify=False)
     json_data = json.loads(response._content)
     return json_data['Requests']['request_status']
Exemple #4
0
 def start_stop_service(cls, service, state, cluster=None):
     if cluster == None:
         cluster = 'cl1'
     weburl = Ambari.getWebUrl()
     url = "%s/api/v1/clusters/%s/services/%s" % (weburl, cluster, service)
     auth = HTTPBasicAuth(Ambari.getAdminUsername(), Ambari.getAdminPassword())
     head = {'X-Requested-By': 'ambari', 'Content-Type': 'text/plain'}
     data = '{"RequestInfo": {"context": "DRUID API ' + state + ' ' + service + '"}, "Body" : {"ServiceInfo": {"state": "' + state + '"}}}'
     response = requests.put(url, data=data, headers=head, auth=auth, verify=False)
     assert ( response.status_code == 200 or response.status_code == 202 ),\
         "Failed to start/stop service %s , status=%d" % ( service, response.status_code )
     return response
Exemple #5
0
 def setConfig(cls, type, config, cluster=None):
     if cluster == None:
         cluster = 'cl1'
     weburl = Ambari.getWebUrl()
     tag = "version-%s" % str(uuid.uuid1())
     data = {'Clusters': {'desired_config': {'type': type, 'tag': tag, 'properties': config}}}
     json = jsonlib.dumps(data)
     url = "%s/api/v1/clusters/%s" % (weburl, cluster)
     auth = HTTPBasicAuth(Ambari.getAdminUsername(), Ambari.getAdminPassword())
     head = {'X-Requested-By': 'ambari', 'Content-Type': 'text/plain'}
     response = requests.put(url=url, headers=head, auth=auth, data=json, verify=False)
     assert response.status_code == 200, "Failed to set config."
Exemple #6
0
 def getDruidComponentHost(cls, component, service='DRUID', cluster=None):
     if cluster == None:
         cluster = 'cl1'
     host_names = []
     url = "%s/api/v1/clusters/%s/services/%s/components/%s" % (Ambari.getWebUrl(), cluster, service, component)
     auth = HTTPBasicAuth(Ambari.getAdminUsername(), Ambari.getAdminPassword())
     head = {'X-Requested-By': 'ambari', 'Content-Type': 'text/plain'}
     response = requests.get(url=url, headers=head, auth=auth, verify=False)
     assert response.status_code == 200, "Failed to get config versions."
     json = response.json()
     host_components = json['host_components']
     for i in range(0, len(host_components)):
         host_names.append(host_components[i]['HostRoles']['host_name'])
     return host_names
 def restart_all_services(cls, host, type, cluster=None):
     if cluster == None:
         cluster = 'cl1'
     weburl = cls.getweburl(host)
     url = "%s/api/v1/clusters/%s/services" % (weburl, cluster)
     auth = HTTPBasicAuth(Ambari.getAdminUsername(),
                          Ambari.getAdminPassword())
     head = {'X-Requested-By': 'ambari', 'Content-Type': 'text/plain'}
     response = requests.get(url=url, headers=head, auth=auth, verify=False)
     json_data = json.loads(response._content)
     for i in range(0, len(json_data['items'])):
         service = json_data['items'][i]['ServiceInfo']['service_name']
         logger.info("Restarting service : %s " % service)
         cls.restart_service(service, host)
Exemple #8
0
 def getConfig(cls, type, property_name, cluster=None):
     if cluster == None:
         cluster = 'cl1'
     weburl = Ambari.getWebUrl()
     url = "%s/api/v1/clusters/%s/configurations?type=%s" % (weburl, cluster, type)
     auth = HTTPBasicAuth(Ambari.getAdminUsername(), Ambari.getAdminPassword())
     head = {'X-Requested-By': 'ambari', 'Content-Type': 'text/plain'}
     response = requests.get(url=url, headers=head, auth=auth, verify=False)
     assert response.status_code == 200, "Failed to get config versions."
     json = response.json()
     items = json['items']
     last = items[len(items) - 1]
     tag = last['tag']
     url = "%s/api/v1/clusters/%s/configurations?type=%s&tag=%s" % (weburl, cluster, type, tag)
     response = requests.get(url=url, headers=head, auth=auth, verify=False)
     assert response.status_code == 200, "Failed to get config."
     json = response.json()
     items = json['items']
     last = items[len(items) - 1]
     config = last['properties'][property_name]
     return config