// calculate if an App fits to a pm // TODO: gst: use WEKA to calc fit factor!! private int calculateFit(App app2, VirtualMachine vm) { int output = 0; if (Action.isOnlyLearning() == false && CreateAppInsertIntoVm.evaluation != null) { // is free space available in the VM if (app2.getCpu() + vm.getCurrentCpuUsage() < vm.getCurrentCpuAllocation() && app2.getMemory() + vm.getCurrentMemoryUsage() < vm.getCurrentMemoryAllocation() && app2.getStorage() + vm.getCurrentStorageUsage() < vm.getCurrentCpuAllocation()) { Instance instance = createInstance(Instance.missingValue(), vm); instance.setDataset(CreateAppInsertIntoVm.getKnowledgeBase()); try { output = (int) (evaluation.evaluateModelOnce(classifier, instance) * 100); } catch (Exception e) { e.printStackTrace(); } } } else { if (app2.getCpu() + vm.getCurrentCpuUsage() < vm.getCurrentCpuAllocation() && app2.getMemory() + vm.getCurrentMemoryUsage() < vm.getCurrentMemoryAllocation() && app2.getStorage() + vm.getCurrentStorageUsage() < vm.getCurrentCpuAllocation()) { output = randomData.nextInt(1, 100); } } return output; }
// create an instance in the format of CreateAppInsertIntoVm.arff // eval can either be a Instance - MissingValue or the evaluation value private Instance createInstance(double eval, VirtualMachine vm) { Instance instance = new Instance(64); LinkedList<Integer> cpuallhist = vm.getCpuAllocationHistory(10); LinkedList<Integer> cpuusehist = vm.getCpuUsageHistory(10); LinkedList<Integer> memallhist = vm.getMemoryAllocationHistory(10); LinkedList<Integer> memusehist = vm.getMemoryUsageHistory(10); LinkedList<Integer> storageallhist = vm.getStorageAllocationHistory(10); LinkedList<Integer> storageusehist = vm.getStorageUsageHistory(10); // CPU/Memory/Storage - Allocation history before the new vm was created for (int i = 0; i < 10; i++) { // cpu allocation instance.setValue(getKnowledgeBase().attribute(i), clusterValue(cpuallhist.get(i))); // cpu usage instance.setValue(getKnowledgeBase().attribute(i + 10), clusterValue(cpuusehist.get(i))); // memory allocation instance.setValue(getKnowledgeBase().attribute(i + 20), clusterValue(memallhist.get(i))); // memory usage instance.setValue(getKnowledgeBase().attribute(i + 30), clusterValue(memusehist.get(i))); // storage allocation instance.setValue(getKnowledgeBase().attribute(i + 40), clusterValue(storageallhist.get(i))); // storage usage instance.setValue(getKnowledgeBase().attribute(i + 50), clusterValue(storageusehist.get(i))); } // SLAs // CPU instance.setValue(getKnowledgeBase().attribute(60), clusterValue(app.getCpu())); // Memory instance.setValue(getKnowledgeBase().attribute(61), clusterValue(app.getMemory())); // Storage instance.setValue(getKnowledgeBase().attribute(62), clusterValue(app.getStorage())); // Evaluation instance.setValue(getKnowledgeBase().attribute(63), eval); return instance; }