Optimizer { public String[] optimize(String appModel, String suitableCloudOffer, String benchmarkPlatforms) { String[] outputPlans = new String[NUMBER_OF_PLANS_GENERATED]; outputPlans[0] = "Plan generation was not possible"; if (previousPlans == null) { OptimizerInitialDeployment initialOptimizer = new OptimizerInitialDeployment(searchName); try { outputPlans = initialOptimizer.optimize(appModel, MMtoOptModelTransformer.transformModel(suitableCloudOffer), benchmarkPlatforms, NUMBER_OF_PLANS_GENERATED,HYSTERESIS_PROPORTION); previousPlans = outputPlans; } catch (Exception exc) { log.warn( "Optimizer did not work in its expected input. Exception name was " + exc.getClass().getName() +" Trying with the assumption of former versions of Input "); outputPlans = initialOptimizer.optimize(appModel, suitableCloudOffer, benchmarkPlatforms, NUMBER_OF_PLANS_GENERATED,HYSTERESIS_PROPORTION); previousPlans = outputPlans; } catch (Error E) { log.error("Error optimizing the initial deployment"); E.printStackTrace(); } } else { } return outputPlans; } Optimizer();  Optimizer(int num);  Optimizer(SearchMethodName name);  Optimizer(int num, SearchMethodName name);  Optimizer(int num, SearchMethodName name, double hysteresis); String[] optimize(String appModel, String suitableCloudOffer, String benchmarkPlatforms); String[] optimize(String appModel, String suitableCloudOffer);  }
@Test(enabled = TestConstants.EnabledTest) public void testPresenceSolutionBlind() { log.info("=== TEST for SOLUTION GENERATION of BLIND optimizer STARTED ==="); optimizer = new Optimizer(TestConstants.NUM_PLANS_TO_GENERATE, SearchMethodName.BLINDSEARCH); String[] arrayDam = optimizer.optimize(appModel, suitableCloudOffer); for (int damnum = 0; damnum < arrayDam.length; damnum++) { try { checkCorrectness(arrayDam[damnum]); } catch (Exception e) { log.error("There was an error in the check of correctness. Solution was: " + arrayDam[damnum]); throw e; } saveFile(TestConstants.OUTPUT_FILENAME + SearchMethodName.BLINDSEARCH + damnum + ".yaml", arrayDam[damnum]); } log.info("=== TEST for SOLUTION GENERATION of BLIND optimizer FINISEHD ==="); }
@Test(enabled = TestConstants.EnabledTest) public void testPresenceSolutionHillClimb() { log.info("=== TEST for SOLUTION GENERATION of HILLCLIMB optimizer STARTED ==="); optimizer = new Optimizer(TestConstants.NUM_PLANS_TO_GENERATE, SearchMethodName.HILLCLIMB); String[] arrayDam = optimizer.optimize(appModel, suitableCloudOffer); for (int damnum = 0; damnum < arrayDam.length; damnum++) { try { checkCorrectness(arrayDam[damnum]); } catch (Exception e) { log.error("There was an error in the check of correctness. Solution was: " + arrayDam[damnum]); throw e; } saveFile(TestConstants.OUTPUT_FILENAME + SearchMethodName.HILLCLIMB + damnum + ".yaml", arrayDam[damnum]); } log.info("=== TEST for SOLUTION GENERATION of HILLCLIMB optimizer FINISEHD ==="); }
@Test(enabled = TestConstants.EnabledTest) public void testPresenceSolutionAnneal() { log.info("=== TEST for SOLUTION GENERATION of ANNEAL optimizer STARTED ==="); optimizer = new Optimizer(TestConstants.NUM_PLANS_TO_GENERATE, SearchMethodName.ANNEAL); String[] arrayDam = optimizer.optimize(appModel, suitableCloudOffer); for (int damnum = 0; damnum < arrayDam.length; damnum++) { try { checkCorrectness(arrayDam[damnum]); } catch (Exception e) { log.error("There was an error in the check of correctness. Solution was: " + arrayDam[damnum]); throw e; } saveFile(TestConstants.OUTPUT_FILENAME + SearchMethodName.ANNEAL + damnum + ".yaml", arrayDam[damnum]); } log.info("=== TEST for SOLUTION GENERATION of ANNEAL optimizer FINISEHD ==="); }
@Test(enabled = TestConstants.EnabledTest) public void testPerformanceComplete() { optimizer = new Optimizer(); log.info("=== TEST for PERFORMANCE of optimizer STARTED ==="); long startTime = System.currentTimeMillis(); optimizer.optimize(appModel, suitableCloudOffer); long finishTime = System.currentTimeMillis(); log.debug("Optimizer execution time= " + (((double) (finishTime - startTime)) / 1000.0) + " seconds"); Assert.assertTrue( "Otimizer does not have good Performance. More than " + ((double) TestConstants.MAX_MILLIS_EXECUTING) / 1000.1 + " seconds", (finishTime - startTime) < TestConstants.MAX_MILLIS_EXECUTING); log.info("=== TEST for PERFORMANCE of optimizer FINISHED==="); }