Exemple #1
0
    def actionexecute(self, env):
        Logger.info("Host checks started.")
        config = Script.get_config()
        tmp_dir = Script.get_tmp_dir()
        report_file_handler_dict = {}

        #print "CONFIG: " + str(config)

        check_execute_list = config['commandParams']['check_execute_list']
        if check_execute_list == '*BEFORE_CLEANUP_HOST_CHECKS*':
            check_execute_list = BEFORE_CLEANUP_HOST_CHECKS
        structured_output = {}

        Logger.info("Check execute list: " + str(check_execute_list))

        # check each of the commands; if an unknown exception wasn't handled
        # by the functions, then produce a generic exit_code : 1
        if CHECK_JAVA_HOME in check_execute_list:
            try:
                java_home_check_structured_output = self.execute_java_home_available_check(
                    config)
                structured_output[
                    CHECK_JAVA_HOME] = java_home_check_structured_output
            except Exception, exception:
                Logger.exception(
                    "There was an unexpected error while checking for the Java home location: "
                    + str(exception))
                structured_output[CHECK_JAVA_HOME] = {
                    "exit_code": 1,
                    "message": str(exception)
                }
Exemple #2
0
    def actionexecute(self, env):
        config = Script.get_config()
        tmp_dir = Script.get_tmp_dir()
        report_file_handler_dict = {}

        #print "CONFIG: " + str(config)

        check_execute_list = config['commandParams']['check_execute_list']
        structured_output = {}

        # check each of the commands; if an unknown exception wasn't handled
        # by the functions, then produce a generic exit_code : 1
        if CHECK_JAVA_HOME in check_execute_list:
            try:
                java_home_check_structured_output = self.execute_java_home_available_check(
                    config)
                structured_output[
                    CHECK_JAVA_HOME] = java_home_check_structured_output
            except Exception, exception:
                print "There was an unexpected error while checking for the Java home location: " + str(
                    exception)
                structured_output[CHECK_JAVA_HOME] = {
                    "exit_code": 1,
                    "message": str(exception)
                }
Exemple #3
0
  def actionexecute(self, env):
    config = Script.get_config()
    tmp_dir = Script.get_tmp_dir()

    #print "CONFIG: " + str(config)

    check_execute_list = config['commandParams']['check_execute_list']
    structured_output = {}

    # check each of the commands; if an unknown exception wasn't handled
    # by the functions, then produce a generic exit_code : 1
    if CHECK_JAVA_HOME in check_execute_list:
      try :
        java_home_check_structured_output = self.execute_java_home_available_check(config)
        structured_output[CHECK_JAVA_HOME] = java_home_check_structured_output
      except Exception, exception:
        print "There was an unexpected error while checking for the Java home location: " + str(exception)
        structured_output[CHECK_JAVA_HOME] = {"exit_code" : 1, "message": str(exception)}
Exemple #4
0
        prop_value = curr_hostname + ":" + metadata_port
        additional_props[prop_name] = prop_value
        i += 1

    # This may override the existing property
    if i == 1 or (i > 1 and is_atlas_ha_enabled is False):
        additional_props["atlas.server.ha.enabled"] = "false"
    elif i > 1:
        additional_props["atlas.server.ha.enabled"] = "true"

    return additional_props


# server configurations
config = Script.get_config()
exec_tmp_dir = Script.get_tmp_dir()

# Needed since this is an Atlas Hook service.
cluster_name = config['clusterName']

if security_enabled:
    _hostname_lowercase = config['hostname'].lower()
    _atlas_principal_name = config['configurations']['application-properties'][
        'atlas.authentication.principal']
    atlas_jaas_principal = _atlas_principal_name.replace(
        '_HOST', _hostname_lowercase)
    atlas_keytab_path = config['configurations']['application-properties'][
        'atlas.authentication.keytab']

# New Cluster Stack Version that is defined during the RESTART of a Stack Upgrade
version = default("/commandParams/version", None)
    def service_check_for_single_host(self, metric_collector_host, params):
        random_value1 = random.random()

        current_time = int(time.time()) * 1000
        metric_json = Template('smoketest_metrics.json.j2',
                               hostname=params.hostname,
                               random1=random_value1,
                               current_time=current_time).get_content()
        try:
            if is_spnego_enabled(params):
                header = 'Content-Type: application/json'
                method = 'POST'
                tmp_dir = Script.get_tmp_dir()

                protocol = "http"
                if not callable(params.metric_collector_https_enabled):
                    if params.metric_collector_https_enabled:
                        protocol = "https"
                port = str(params.metric_collector_port)
                uri = '{0}://{1}:{2}{3}'.format(protocol,
                                                metric_collector_host, port,
                                                self.AMS_METRICS_POST_URL)

                call_curl_krb_request(tmp_dir,
                                      params.smoke_user_keytab,
                                      params.smoke_user_princ,
                                      uri,
                                      params.kinit_path_local,
                                      params.smoke_user,
                                      self.AMS_CONNECT_TIMEOUT,
                                      method,
                                      metric_json,
                                      header,
                                      tries=self.AMS_CONNECT_TRIES)
            else:
                headers = {"Content-type": "application/json"}
                ca_certs = os.path.join(params.ams_monitor_conf_dir,
                                        params.metric_truststore_ca_certs)
                post_metrics_to_collector(
                    self.AMS_METRICS_POST_URL, metric_collector_host,
                    params.metric_collector_port,
                    params.metric_collector_https_enabled, metric_json,
                    headers, ca_certs, self.AMS_CONNECT_TRIES,
                    self.AMS_CONNECT_TIMEOUT)

            get_metrics_parameters = {
                "metricNames": "AMBARI_METRICS.SmokeTest.FakeMetric",
                "appId": "amssmoketestfake",
                "hostname": params.hostname,
                "startTime": current_time - 60000,
                "endTime": current_time + 61000,
                "precision": "seconds",
                "grouped": "false",
            }
            encoded_get_metrics_parameters = urllib.urlencode(
                get_metrics_parameters)

            if is_spnego_enabled(params):
                method = 'GET'
                uri = '{0}://{1}:{2}{3}'.format(
                    protocol, metric_collector_host, port,
                    self.AMS_METRICS_GET_URL % encoded_get_metrics_parameters)

                call_curl_krb_request(tmp_dir,
                                      params.smoke_user_keytab,
                                      params.smoke_user_princ,
                                      uri,
                                      params.kinit_path_local,
                                      params.smoke_user,
                                      self.AMS_READ_TIMEOUT,
                                      method,
                                      tries=self.AMS_READ_TRIES,
                                      current_time=current_time,
                                      random_value=random_value1)
            else:
                Logger.info(
                    "Connecting (GET) to %s:%s%s" %
                    (metric_collector_host, params.metric_collector_port,
                     self.AMS_METRICS_GET_URL %
                     encoded_get_metrics_parameters))
                for i in xrange(0, self.AMS_READ_TRIES):
                    conn = network.get_http_connection(
                        metric_collector_host,
                        int(params.metric_collector_port),
                        params.metric_collector_https_enabled,
                        ca_certs,
                        ssl_version=Script.get_force_https_protocol_value())
                    conn.request(
                        "GET", self.AMS_METRICS_GET_URL %
                        encoded_get_metrics_parameters)
                    response = conn.getresponse()
                    Logger.info("Http response for host %s : %s %s" %
                                (metric_collector_host, response.status,
                                 response.reason))

                    data = response.read()
                    Logger.info("Http data: %s" % data)
                    conn.close()

                    if response.status == 200:
                        Logger.info("Metrics were retrieved from host %s" %
                                    metric_collector_host)
                    else:
                        raise Fail(
                            "Metrics were not retrieved from host %s. GET request status: %s %s \n%s"
                            % (metric_collector_host, response.status,
                               response.reason, data))
                    data_json = json.loads(data)

                    def floats_eq(f1, f2, delta):
                        return abs(f1 - f2) < delta

                    values_are_present = False
                    for metrics_data in data_json["metrics"]:
                        if (str(current_time) in metrics_data["metrics"]
                                and str(current_time + 1000)
                                in metrics_data["metrics"] and floats_eq(
                                    metrics_data["metrics"][str(current_time)],
                                    random_value1, 0.0000001)
                                and floats_eq(
                                    metrics_data["metrics"][str(current_time +
                                                                1000)],
                                    current_time, 1)):
                            Logger.info(
                                "Values %s and %s were found in the response from host %s."
                                % (metric_collector_host, random_value1,
                                   current_time))
                            values_are_present = True
                            break
                            pass

                    if not values_are_present:
                        if i < self.AMS_READ_TRIES - 1:  #range/xrange returns items from start to end-1
                            Logger.info(
                                "Values weren't stored yet. Retrying in %s seconds."
                                % (self.AMS_READ_TIMEOUT))
                            time.sleep(self.AMS_READ_TIMEOUT)
                        else:
                            raise Fail(
                                "Values %s and %s were not found in the response."
                                % (random_value1, current_time))
                    else:
                        break
                        pass
        except Fail as ex:
            Logger.warning(
                "Ambari Metrics service check failed on collector host %s. Reason : %s"
                % (metric_collector_host, str(ex)))
            raise Fail(
                "Ambari Metrics service check failed on collector host %s. Reason : %s"
                % (metric_collector_host, str(ex)))
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

"""
import os
from resource_management import Script
from resource_management.libraries.functions import  get_kinit_path, format
from resource_management.libraries.functions.default import default


config = Script.get_config()

conf_dir = os.environ['METADATA_CONF'] if 'METADATA_CONF' in os.environ else '/etc/atlas/conf'
pid_dir = config['configurations']['atlas-env']['metadata_pid_dir']
pid_file = format("{pid_dir}/atlas.pid")
metadata_user = config['configurations']['atlas-env']['metadata_user']

# Security related/required params
hostname = config['hostname']
security_enabled = config['configurations']['cluster-env']['security_enabled']
kinit_path_local = get_kinit_path(default('/configurations/kerberos-env/executable_search_paths', None))
tmp_dir = Script.get_tmp_dir()