@@ -0,0 +1,3168 @@
+package org.project.openbaton.nfvo.core.core;%0A%0Aimport org.project.openbaton.common.catalogue.mano.common.DeploymentFlavour;%0Aimport org.project.openbaton.common.catalogue.mano.descriptor.VirtualDeploymentUnit;%0Aimport org.project.openbaton.common.catalogue.mano.record.VirtualNetworkFunctionRecord;%0Aimport org.project.openbaton.common.catalogue.nfvo.Quota;%0Aimport org.project.openbaton.common.catalogue.nfvo.VimInstance;%0Aimport org.project.openbaton.nfvo.common.exceptions.VimException;%0Aimport org.project.openbaton.nfvo.vim_interfaces.vim.VimBroker;%0Aimport org.springframework.beans.factory.annotation.Autowired;%0Aimport org.springframework.context.annotation.Scope;%0Aimport org.springframework.stereotype.Service;%0A%0Aimport java.util.HashMap;%0A%0A/**%0A * Created by lto on 11/06/15.%0A */%0A@Service%0A@Scope%0Apublic class VNFLifecycleOperationGranting implements org.project.openbaton.nfvo.core.interfaces.VNFLifecycleOperationGranting %7B%0A    @Autowired%0A    private VimBroker vimBroker;%0A%0A    @Override%0A    public boolean grantLifecycleOperation(VirtualNetworkFunctionRecord virtualNetworkFunctionRecord) throws VimException%7B%0A        //HashMap holds how many VDUs are deployed on a specific VimInstance%0A        HashMap%3CVimInstance,Integer%3E countVDUsOnVimInstances = new HashMap%3C%3E();%0A        //Count VDUs on a specific VimInstance%0A        for (VirtualDeploymentUnit vdu : virtualNetworkFunctionRecord.getVdu()) %7B%0A            if (vdu.getExtId() != null)%0A                break;%0A            if (countVDUsOnVimInstances.containsKey(vdu.getVimInstance())) %7B%0A                countVDUsOnVimInstances.put(vdu.getVimInstance(), countVDUsOnVimInstances.get(vdu.getVimInstance()) + 1);%0A            %7D else %7B%0A                countVDUsOnVimInstances.put(vdu.getVimInstance(), 1);%0A            %7D%0A        %7D%0A        //Check if enough resources are available for the deployment%0A        for (VimInstance vimInstance : countVDUsOnVimInstances.keySet()) %7B%0A            Quota leftQuota = vimBroker.getLeftQuota(vimInstance);%0A            //Fetch the Flavor for getting allocated resources needed%0A            DeploymentFlavour flavor = null;%0A            for (DeploymentFlavour currentFlavor : vimInstance.getFlavours()) %7B%0A                if (currentFlavor.getFlavour_key().equals(virtualNetworkFunctionRecord.getDeployment_flavour_key())) %7B%0A                    flavor = currentFlavor;%0A                    break;%0A                %7D%0A            %7D%0A            //Subtract needed resources from the left resources%0A            for (int i = 1; i %3C= countVDUsOnVimInstances.get(vimInstance); i++) %7B%0A                leftQuota.setInstances(leftQuota.getInstances() - 1);%0A                leftQuota.setCores(leftQuota.getCores() - flavor.getVcpus());%0A                leftQuota.setRam(leftQuota.getRam() - flavor.getRam());%0A            %7D%0A            //If one value is negative, it is not possible to deploy the VNFR on (at least on one VimInstance) -%3E return false%0A            if (leftQuota.getInstances() %3C 0 %7C%7C leftQuota.getRam() %3C 0 %7C%7C leftQuota.getCores() %3C 0)%0A                return false;%0A        %7D%0A        //If there are enough resources to deploy the VNFR on the VimInstance, return true%0A        return true;%0A    %7D%0A%7D%0A

implement Granting -> needs to be tested