<commit_before>import Ember from 'ember';

export default Ember.Service.extend({

  ajax: Ember.inject.service(),

  canConnect() {
    return this.get('ajax').request('/api/v1/').then(() => {
      return true;
    }).catch((error) => {
      if (error.errors && error.errors[0].status === '0') {
        return false;
      }
      return true;
    });
  },

  findAll(kind) {
    let kinds = Ember.Inflector.inflector.pluralize(kind);
    return this.get('ajax').request(`/api/v1/${kinds}`);
  },

  findRecord(kind, ns, name) {
    let kinds = Ember.Inflector.inflector.pluralize(kind);
    return this.get('ajax').request(`/api/v1/namespaces/${ns}/${kinds}/${name}`);
  },

  query(kind, query) {
    let kinds = Ember.Inflector.inflector.pluralize(kind);
    if (query) {
      let ns = query.filter.namespace;
      return this.get('ajax').request(`/api/v1/namespaces/${ns}/${kinds}`);

    }
    return this.findAll(kind);
  },

  getNamespacedUrl(manifest) {
    let url = '/api/v1/namespaces';
    if ( manifest.kind !== 'Namespace') {
      let namespace = 'default';
      if ( manifest.metadata.namespace && manifest.metadata.namespace !== '' ) {
        namespace = manifest.metadata.namespace;
      }
      url = `${url}/${namespace}/${manifest.kind.toLowerCase()}s`;
    }
    return url;
  },

  create(manifest) {
    let url = this.getNamespacedUrl(manifest);
    let data = {
      data: JSON.stringify(manifest),
      headers: {'Content-Type': 'application/json'}
    };
    return this.get('ajax').post(url, data );
  },

  replace(manifest) {
    let url = this.getNamespacedUrl(manifest);
    let data = {
      data: JSON.stringify(manifest),
      headers: {'Content-Type': 'application/json'}
    };
    url = `${url}/${manifest.metadata.name}`;
    return this.get('ajax').put(url, data );
  },

  getLogOrThrow(error) {
    if (error.errors) {
      throw error;
    }
    if (!error.search) {
      return null;
    }
    if (error.search(/pod is not in .*state/) > -1) {
      return null;
    }
    if (error.search && error.search(/^Container.*not found/) > -1) {
      throw { message: error };
    }
    return error;
  },

  getLog(params, tailLines = 200) {
    let queryParams = `?container=${params.container}&tailLines=${tailLines}`;
    return this.get('ajax').request(
      `/api/v1/namespaces/${params.namespace}/pods/${params.name}/log${queryParams}`
    ).then((log) => {
      return log;
    }).catch((error) => {
      // TODO: Remove this ugly workaround.
      // See #38 for an explanation on why we need this catch
      return this.getLogOrThrow(error);
    });
  },

  getStat(node) {
    let port = '4194';
    let url = `/api/v1/proxy/nodes/${node}:${port}'/api/v1.0/containers`;
    return this.get('ajax').request(url);
  }

});
<commit_msg>gh-8 Fixed url for stats<commit_after>import Ember from 'ember';

export default Ember.Service.extend({

  ajax: Ember.inject.service(),

  canConnect() {
    return this.get('ajax').request('/api/v1/').then(() => {
      return true;
    }).catch((error) => {
      if (error.errors && error.errors[0].status === '0') {
        return false;
      }
      return true;
    });
  },

  findAll(kind) {
    let kinds = Ember.Inflector.inflector.pluralize(kind);
    return this.get('ajax').request(`/api/v1/${kinds}`);
  },

  findRecord(kind, ns, name) {
    let kinds = Ember.Inflector.inflector.pluralize(kind);
    return this.get('ajax').request(`/api/v1/namespaces/${ns}/${kinds}/${name}`);
  },

  query(kind, query) {
    let kinds = Ember.Inflector.inflector.pluralize(kind);
    if (query) {
      let ns = query.filter.namespace;
      return this.get('ajax').request(`/api/v1/namespaces/${ns}/${kinds}`);

    }
    return this.findAll(kind);
  },

  getNamespacedUrl(manifest) {
    let url = '/api/v1/namespaces';
    if ( manifest.kind !== 'Namespace') {
      let namespace = 'default';
      if ( manifest.metadata.namespace && manifest.metadata.namespace !== '' ) {
        namespace = manifest.metadata.namespace;
      }
      url = `${url}/${namespace}/${manifest.kind.toLowerCase()}s`;
    }
    return url;
  },

  create(manifest) {
    let url = this.getNamespacedUrl(manifest);
    let data = {
      data: JSON.stringify(manifest),
      headers: {'Content-Type': 'application/json'}
    };
    return this.get('ajax').post(url, data );
  },

  replace(manifest) {
    let url = this.getNamespacedUrl(manifest);
    let data = {
      data: JSON.stringify(manifest),
      headers: {'Content-Type': 'application/json'}
    };
    url = `${url}/${manifest.metadata.name}`;
    return this.get('ajax').put(url, data );
  },

  getLogOrThrow(error) {
    if (error.errors) {
      throw error;
    }
    if (!error.search) {
      return null;
    }
    if (error.search(/pod is not in .*state/) > -1) {
      return null;
    }
    if (error.search && error.search(/^Container.*not found/) > -1) {
      throw { message: error };
    }
    return error;
  },

  getLog(params, tailLines = 200) {
    let queryParams = `?container=${params.container}&tailLines=${tailLines}`;
    return this.get('ajax').request(
      `/api/v1/namespaces/${params.namespace}/pods/${params.name}/log${queryParams}`
    ).then((log) => {
      return log;
    }).catch((error) => {
      // TODO: Remove this ugly workaround.
      // See #38 for an explanation on why we need this catch
      return this.getLogOrThrow(error);
    });
  },

  getStat(node) {
    let port = '4194';
    let url = `/api/v1/proxy/nodes/${node}:${port}/api/v1.0/containers`;
    return this.get('ajax').request(url);
  }

});

{'fraction_non_alphanumeric': 0.18525115781973636, 'fraction_numerical': 0.008015675097969362, 'mean_word_length': 2.743333333333333, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7217441', 'n_tokens_mistral': 1899, 'n_tokens_neox': 1879, 'n_words': 340}