<commit_before>package org.project.neutrino.nfvo.vim.broker;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

/**
 * Created by lto on 20/05/15.
 */
@Service
@Scope
public class VimBroker<T> implements org.project.neutrino.nfvo.vim_interfaces.VimBroker<T> {

    @Autowired
    private ConfigurableApplicationContext context;

    @Override
    public T getVim(String type) {
        switch (type) {
            case "test":
                return (T) context.getBean("testVIM");
            case "openstack":
                return (T) context.getBean("openstackVIM");
            case "amazon":
                return (T) context.getBean("amazonVIM");
            default:
                throw new UnsupportedOperationException();
        }
    }
}<commit_msg>implemented getLeftQuota() and updated the code<commit_after>package org.project.neutrino.nfvo.vim.broker;

import org.project.neutrino.nfvo.catalogue.mano.common.DeploymentFlavour;
import org.project.neutrino.nfvo.catalogue.nfvo.Quota;
import org.project.neutrino.nfvo.catalogue.nfvo.Server;
import org.project.neutrino.nfvo.catalogue.nfvo.VimInstance;
import org.project.neutrino.nfvo.common.exceptions.VimException;
import org.project.neutrino.nfvo.vim_interfaces.vim.Vim;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by lto on 20/05/15.
 */
@Service
@Scope
public class VimBroker implements org.project.neutrino.nfvo.vim_interfaces.vim.VimBroker {

    @Autowired
    private ConfigurableApplicationContext context;

    @Override
    public Vim getVim(String type) {
        switch (type) {
            case "test":
                return (Vim) context.getBean("testVIM");
            case "openstack":
                return (Vim) context.getBean("openstackVIM");
            case "amazon":
                return (Vim) context.getBean("amazonVIM");
            default:
                throw new UnsupportedOperationException();
        }
    }

    @Override
    public Quota getLeftQuota(VimInstance vimInstance) throws VimException{
        Vim vim;
        switch (vimInstance.getType()) {
            case "test":
                vim = (Vim) context.getBean("testVIM");
                break;
            case "openstack":
                vim = (Vim) context.getBean("openstackVIM");
                break;
            case "amazon":
                vim = (Vim) context.getBean("amazonVIM");
                break;
            default:
                throw new UnsupportedOperationException();
        }
        Quota maximalQuota = vim.getQuota(vimInstance);
        Quota leftQuota = maximalQuota;

        List<Server> servers = vim.queryResources(vimInstance);
        //Calculate used resource by servers (cpus, ram)
        for (Server server : servers) {
            //Subtract floatingIps

            //Subtract instances
            leftQuota.setInstances(leftQuota.getInstances()-1);
            //Subtract used ram and cpus
            DeploymentFlavour flavor = server.getFlavor();
            leftQuota.setRam(leftQuota.getRam()-flavor.getRam());
            leftQuota.setCores(leftQuota.getCores()-flavor.getVcpus());
        }
        return leftQuota;
    }
}
{'fraction_non_alphanumeric': 0.10196629213483147, 'fraction_numerical': 0.003651685393258427, 'mean_word_length': 2.550348953140578, 'pattern_counts': {'":': 9, '<': 6, '<?xml version=': 0, '>': 6, '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': '4362998', 'n_tokens_mistral': 1056, 'n_tokens_neox': 1015, 'n_words': 193}