<commit_before>(function() {
    // A sort of abstract superclass defining methods common to all subclasses.
    function VMModel(vm, provider, project, expiration) {
        this.vm = vm;
        this.provider = provider;
        this.project = project;
        this.expiration = expiration;
    }

    // Returns a string.
    VMModel.prototype.getExpiryDate = function() {
        return this.expiration.expires_at;
    };

    VMModel.prototype.getProjectName = function() {
        return this.project.name;
    };

    VMModel.prototype.isDestroyed = function() {
        return this.vm.destroyed_at !== null;
    };

    [
        'getName',
        'isOn',
    ].forEach(function(name) {
        VMModel.prototype[name] = function() {
            throw new Error('Not implemented');
        };
    });


    function DummyVMModel(vm, provider, project, expiration, dummy_vm) {
        VMModel.call(this, vm, provider, project, expiration);
        this.dummy_vm = dummy_vm;
    }
    DummyVMModel.prototype = Object.create(VMModel.prototype);

    DummyVMModel.prototype.getName = function() {
        return this.dummy_vm.name;
    };

    DummyVMModel.prototype.isOn = function() {
        return this.dummy_vm.poweredon;
    };


    function AWSVMModel(vm, provider, project, expiration, aws_vm) {
        VMModel.call(this, vm, provider, project, expiration);
        this.aws_vm = aws_vm;
    }
    AWSVMModel.prototype = Object.create(VMModel.prototype);

    AWSVMModel.prototype.getName = function() {
        return this.aws_vm.name;
    };

    AWSVMModel.prototype.isOn = function() {
        // Keep this in sync with aws.py
        switch (this.aws_vm.state) {
            case 'pending':
            case 'running':
            case 'stopping':
            case 'shutting-down':
                return true;

            case 'stopped':
            case 'terminated':
                return false;
        }

        console.warn('Unknown AWS VM state: ‘' + this.aws_vm.state + '’');
        return false;
    };


    /* Load the data model for the VM with vmid.
     * If anything fails, call errCallback(errorText).
     * Else call successCallback(vmDataModel).
     */
    function loadVM(vmid, successCallback, errCallback) {
        apiGet([vimmaApiVMDetailRoot + vmid + '/'], function(resArr) {
            loadProvPrjVmExp(resArr[0]);
        }, errCallback);

        function loadProvPrjVmExp(vm) {
            var provUrl = vimmaApiProviderDetailRoot + vm.provider + '/',
                prjUrl = vimmaApiProjectDetailRoot + vm.project + '/',
                vmExpUrl = vimmaApiVMExpirationDetailRoot + '?vm=' + vm.id;
            apiGet([provUrl, prjUrl, vmExpUrl], function(resArr) {
                var prov = resArr[0], prj = resArr[1],
                    vmExp = resArr[2].results[0];
                loadExp(vm, prov, prj, vmExp);
            }, errCallback);
        }

        function loadExp(vm, provider, project, vm_expiration) {
            var url = vimmaApiExpirationDetailRoot +
                vm_expiration.expiration + '/';
            apiGet([url], function(resArr) {
                makeVMModel(vm, provider, project, resArr[0]);
            }, errCallback);
        }

        function makeVMModel(vm, provider, project, expiration) {
            switch (provider.type) {
                case 'dummy':
                    makeDummyVMModel(vm, provider, project, expiration);
                    return;
                case 'aws':
                    makeAWSVMModel(vm, provider, project, expiration);
                    return;
                default:
                    errCallback('Unknown Provider type: ' + provider.type);
                    return;
            }
        }

        function makeDummyVMModel(vm, provider, project, expiration) {
            var url = vimmaApiDummyVMDetailRoot + '?vm=' + vm.id;
            apiGet([url], function(resArr) {
                var dummy_vm = resArr[0].results[0],
                    model = new DummyVMModel(vm, provider, project, expiration,
                            dummy_vm);
                successCallback(model);
            }, errCallback);
        }

        function makeAWSVMModel(vm, provider, project, expiration) {
            var url = vimmaApiAWSVMDetailRoot + '?vm=' + vm.id;
            apiGet([url], function(resArr) {
                var aws_vm = resArr[0].results[0],
                    model = new AWSVMModel(vm, provider, project, expiration,
                            aws_vm);<commit_msg><vm-data-model>: show the full DNS name for AWS VMs<commit_after>(function() {
    // A sort of abstract superclass defining methods common to all subclasses.
    function VMModel(vm, provider, project, expiration) {
        this.vm = vm;
        this.provider = provider;
        this.project = project;
        this.expiration = expiration;
    }

    // Returns a string.
    VMModel.prototype.getExpiryDate = function() {
        return this.expiration.expires_at;
    };

    VMModel.prototype.getProjectName = function() {
        return this.project.name;
    };

    VMModel.prototype.isDestroyed = function() {
        return this.vm.destroyed_at !== null;
    };

    [
        'getName',
        'isOn',
    ].forEach(function(name) {
        VMModel.prototype[name] = function() {
            throw new Error('Not implemented');
        };
    });


    function DummyVMModel(vm, provider, project, expiration, dummy_vm) {
        VMModel.call(this, vm, provider, project, expiration);
        this.dummy_vm = dummy_vm;
    }
    DummyVMModel.prototype = Object.create(VMModel.prototype);

    DummyVMModel.prototype.getName = function() {
        return this.dummy_vm.name;
    };

    DummyVMModel.prototype.isOn = function() {
        return this.dummy_vm.poweredon;
    };


    function AWSVMModel(vm, provider, project, expiration,
            aws_vm, aws_provider) {
        VMModel.call(this, vm, provider, project, expiration);
        this.aws_vm = aws_vm;
        this.aws_provider = aws_provider;
    }
    AWSVMModel.prototype = Object.create(VMModel.prototype);

    AWSVMModel.prototype.getName = function() {
        return this.aws_vm.name + '.' + this.aws_provider.route_53_zone;
    };

    AWSVMModel.prototype.isOn = function() {
        // Keep this in sync with aws.py
        switch (this.aws_vm.state) {
            case 'pending':
            case 'running':
            case 'stopping':
            case 'shutting-down':
                return true;

            case 'stopped':
            case 'terminated':
                return false;
        }

        console.warn('Unknown AWS VM state: ‘' + this.aws_vm.state + '’');
        return false;
    };


    /* Load the data model for the VM with vmid.
     * If anything fails, call errCallback(errorText).
     * Else call successCallback(vmDataModel).
     */
    function loadVM(vmid, successCallback, errCallback) {
        apiGet([vimmaApiVMDetailRoot + vmid + '/'], function(resArr) {
            loadProvPrjVmExp(resArr[0]);
        }, errCallback);

        function loadProvPrjVmExp(vm) {
            var provUrl = vimmaApiProviderDetailRoot + vm.provider + '/',
                prjUrl = vimmaApiProjectDetailRoot + vm.project + '/',
                vmExpUrl = vimmaApiVMExpirationDetailRoot + '?vm=' + vm.id;
            apiGet([provUrl, prjUrl, vmExpUrl], function(resArr) {
                var prov = resArr[0], prj = resArr[1],
                    vmExp = resArr[2].results[0];
                loadExp(vm, prov, prj, vmExp);
            }, errCallback);
        }

        function loadExp(vm, provider, project, vm_expiration) {
            var url = vimmaApiExpirationDetailRoot +
                vm_expiration.expiration + '/';
            apiGet([url], function(resArr) {
                makeVMModel(vm, provider, project, resArr[0]);
            }, errCallback);
        }

        function makeVMModel(vm, provider, project, expiration) {
            switch (provider.type) {
                case 'dummy':
                    makeDummyVMModel(vm, provider, project, expiration);
                    return;
                case 'aws':
                    makeAWSVMModel(vm, provider, project, expiration);
                    return;
                default:
                    errCallback('Unknown Provider type: ' + provider.type);
                    return;
            }
        }

        function makeDummyVMModel(vm, provider, project, expiration) {
            var url = vimmaApiDummyVMDetailRoot + '?vm=' + vm.id;
            apiGet([url], function(resArr) {
                var dummy_vm = resArr[0].results[0],
                    model = new DummyVMModel(vm, provider, project, expiration,
                            dummy_vm);
                successCallback(model);
            }, errCallback);
        }

        function makeAWSVMModel(vm, provider, project, expiration) {
            var aws_vm_url = vimmaApiAWSVMDetailRoot + '?vm=' + vm.id,
                aws_prov_url = vimmaApiAWSProviderDetailRoot +
                    '?provider=' + provider.id;
            apiGet([aws_vm_url, aws_prov_url], function(resArr) {
                var aws_vm = resArr[0].results[0],
                    aws_provider = resArr[1].results[0],
                    model = new AWSVMModel(vm, provider, project, expiration,
                            aws_vm, aws_provider);
{'fraction_non_alphanumeric': 0.10936504565725207, 'fraction_numerical': 0.002548311743469951, 'mean_word_length': 1.8585735963581183, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '6203965', 'n_tokens_mistral': 2717, 'n_tokens_neox': 2606, 'n_words': 557}