<commit_before>var Promise = require("bluebird");
var Sdk = require('./../lib/clc-sdk.js');
var _ = require('underscore');

var sdk = new Sdk();
var compute = sdk.computeServices();
var dataCenters = sdk.baseServices().dataCenters();

var Group = compute.Group;

function clearAccount() {
    console.log('clear environment');
    return dataCenters.find()
        .then(deleteServers, errorLog)
        .then(deleteGroups, errorLog)
        .finally(clearDone);
}

function errorLog(err) {
    console.error(err);
}

function deleteServers(dataCenters) {
    console.log('delete all servers');
    return compute.servers().delete({
            group: {
                dataCenter: dataCenters,
                nameContains: [Group.ARCHIVE, Group.TEMPLATES, Group.DEFAULT]
            }
        })
        .finally(function() {
            return dataCenters;
        });
}

function deleteGroups(dataCenters) {
    console.log('delete all groups, except Archive, Default Group, Templates');

    return compute.groups().find(
            {
                dataCenter: dataCenters,
                name: [Group.DEFAULT, Group.ARCHIVE, Group.TEMPLATES]
            }
        ).then(function(groups) {
            var subGroups = _.chain(groups)
                    .map(function(group) {
                        return group.getGroups();
                    })
                    .flatten()
                    .value();

            if (subGroups.length > 0) {
                compute.groups().delete(subGroups);
            }
            return;
        });
}

function clearDone() {
    console.log('Finished!');
}

function run() {<commit_msg>#116 Implement Sample Application for Power Operations Milestone. Clean account before samples running<commit_after>var Promise = require("bluebird");
var Sdk = require('./../lib/clc-sdk.js');
var _ = require('underscore');

var sdk = new Sdk();
var compute = sdk.computeServices();
var dataCenters = sdk.baseServices().dataCenters();

var Group = compute.Group;

function clearAccount() {
    console.log('clear environment');
    return dataCenters.find()
        .then(deleteServers)
        .then(deleteGroups)
        .then(clearDone);
}

function errorLog(err) {
    console.error(err);
}

function deleteServers(dataCenters) {
    console.log('delete all servers');
    return compute.servers().delete({
            group: {
                dataCenter: dataCenters,
                nameContains: [Group.ARCHIVE, Group.TEMPLATES, Group.DEFAULT]
            }
        })
        .catch(function() {
            return dataCenters;
        });
}

function deleteGroups(dataCenters) {
    console.log('delete all groups, except Archive, Default Group, Templates');

    return compute.groups().find(
            {
                dataCenter: dataCenters,
                name: [Group.DEFAULT, Group.ARCHIVE, Group.TEMPLATES]
            }
        ).then(function(groups) {
            var subGroups = _.chain(groups)
                    .map(function(group) {
                        return group.getGroups();
                    })
                    .flatten()
                    .value();

            if (subGroups.length > 0) {
                compute.groups().delete(subGroups);
            }
            return;
        })
        .catch(errorLog);
}

function clearDone() {
    console.log('Finished!');
}

function run() {
{'fraction_non_alphanumeric': 0.12562814070351758, 'fraction_numerical': 0.0014779781259237363, 'mean_word_length': 1.9580419580419581, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2232456', 'n_tokens_mistral': 942, 'n_tokens_neox': 908, 'n_words': 189}