<commit_before>import VolumeTypes from '../constants/VolumeTypes';
import VolumeStatus from '../constants/VolumeStatus';

function parseApp(app) {
  let {id, tasks = [], container = {}} = app;
  app._type = 'app';

  if (id == null || !id.startsWith('/') || id.endsWith('/')) {
    throw new Error(`Id (${id}) must start with a leading slash ("/") ` +
      'and should not end with a slash.');
  }

  if (container == null || !Array.isArray(container.volumes)) {
    return app;
  }

  let volumeDefinitionMap = new Map();
  let volumes = [];

  // Parse container volumes to extract external volumes
  // and persistent volume definitions
  container.volumes.forEach(
    function ({containerPath, external, mode, persistent}) {
      if (external != null) {
        volumes.push(Object.assign({
          containerPath,
          id: external.name,
          mode,
          status: VolumeStatus.UNAVAILABLE,
          type: VolumeTypes.EXTERNAL
        }, external));
      }

      if (persistent != null) {
        volumeDefinitionMap.set(containerPath,
          Object.assign({type: VolumeTypes.PERSISTENT, mode}, persistent)
        );
      }
    }
  );

  if (tasks == null || !Array.isArray(tasks)) {
    return Object.assign({volumes}, app);
  }

  tasks.forEach(function ({host, id:taskID, localVolumes, startedAt}) {
    let status = VolumeStatus.DETACHED;
    if (startedAt != null) {
      status = VolumeStatus.ATTACHED;
    }

    if (!Array.isArray(localVolumes)) {
      return;
    }

    localVolumes.forEach(function ({containerPath, persistenceId:id}) {
      let volumeDefinition = volumeDefinitionMap.get(containerPath);
      let volume = Object.assign({}, volumeDefinition,
        {status, host, containerPath, id, taskID});

      volumes.push(volume);
    });
  });

  return Object.assign({volumes}, app);
}

function parsePod(pod) {
  let {id} = pod;

  if (id == null || !id.startsWith('/') || id.endsWith('/')) {
    throw new Error(`Id (${id}) must start with a leading slash ("/") ` +
      'and should not end with a slash.');
  }

  pod._type = 'pod';
  return pod;
}

const MarathonUtil = {
  parseGroups({id = '/', groups = [], apps = [], pods = []}) {
    if (id !== '/' && (!id.startsWith('/') || id.endsWith('/'))) {
      throw new Error(`Id (${id}) must start with a leading slash ("/") ` +
        'and should not end with a slash, except for root id which is only ' +
        'a slash.');
    }

    // Parse items
    let items = [].concat(<commit_msg>Making service _type property non-enumerable<commit_after>import VolumeTypes from '../constants/VolumeTypes';
import VolumeStatus from '../constants/VolumeStatus';

function parseApp(app) {
  let {id, tasks = [], container = {}} = app;
  Object.defineProperty(app, '_type', {
    enumerable: false,
    configurable: false,
    writable: false,
    value: 'app'
  });

  if (id == null || !id.startsWith('/') || id.endsWith('/')) {
    throw new Error(`Id (${id}) must start with a leading slash ("/") ` +
      'and should not end with a slash.');
  }

  if (container == null || !Array.isArray(container.volumes)) {
    return app;
  }

  let volumeDefinitionMap = new Map();
  let volumes = [];

  // Parse container volumes to extract external volumes
  // and persistent volume definitions
  container.volumes.forEach(
    function ({containerPath, external, mode, persistent}) {
      if (external != null) {
        volumes.push(Object.assign({
          containerPath,
          id: external.name,
          mode,
          status: VolumeStatus.UNAVAILABLE,
          type: VolumeTypes.EXTERNAL
        }, external));
      }

      if (persistent != null) {
        volumeDefinitionMap.set(containerPath,
          Object.assign({type: VolumeTypes.PERSISTENT, mode}, persistent)
        );
      }
    }
  );

  if (tasks == null || !Array.isArray(tasks)) {
    return Object.assign({volumes}, app);
  }

  tasks.forEach(function ({host, id:taskID, localVolumes, startedAt}) {
    let status = VolumeStatus.DETACHED;
    if (startedAt != null) {
      status = VolumeStatus.ATTACHED;
    }

    if (!Array.isArray(localVolumes)) {
      return;
    }

    localVolumes.forEach(function ({containerPath, persistenceId:id}) {
      let volumeDefinition = volumeDefinitionMap.get(containerPath);
      let volume = Object.assign({}, volumeDefinition,
        {status, host, containerPath, id, taskID});

      volumes.push(volume);
    });
  });

  return Object.assign({volumes}, app);
}

function parsePod(pod) {
  let {id} = pod;
  Object.defineProperty(app, '_type', {
    enumerable: false,
    configurable: false,
    writable: false,
    value: 'pod'
  });

  if (id == null || !id.startsWith('/') || id.endsWith('/')) {
    throw new Error(`Id (${id}) must start with a leading slash ("/") ` +
      'and should not end with a slash.');
  }

  return pod;
}

const MarathonUtil = {
  parseGroups({id = '/', groups = [], apps = [], pods = []}) {
    if (id !== '/' && (!id.startsWith('/') || id.endsWith('/'))) {
      throw new Error(`Id (${id}) must start with a leading slash ("/") ` +
        'and should not end with a slash, except for root id which is only ' +
        'a slash.');
    }

    // Parse items
    let items = [].concat(
{'fraction_non_alphanumeric': 0.1580749476887959, 'fraction_numerical': 0.0, 'mean_word_length': 2.755714285714286, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1181414', 'n_tokens_mistral': 1599, 'n_tokens_neox': 1573, 'n_words': 425}