def test(self):
   topology = {
     'infrastructure': {
       'cpu_cores': 2,
       'mem_units': 8
     }
   }
   i = 1
   while True:
     plan_file = 'tests/plan{0}.json'.format(i)
     if isfile(plan_file):
       plan = self.read_json(plan_file)
       solver = AllocationSolver(topology)
       allocation = self.read_json('tests/allocation{0}.json'.format(i))
       if i == 2 or i == 10:
         try:
           new_allocation = solver.solve(plan, allocation)
         except Exception as e:
           if ((i == 2 and str(e) == 'No solution needed') or
               (i == 10 and str(e) == 'No solution found')):
             pass
           else:
             raise e
       else:
         new_allocation = solver.solve(plan, allocation)
         expected = self.read_json('tests/result{0}.json'.format(i))
         print i
         print 'old_allocation=', allocation
         print 'plan=', plan
         print 'new_allocation=', new_allocation
         print 'expected=', expected
         self.assertEquals(new_allocation, expected)
     else:
       break
     i += 1
示例#2
0
def translate(plan):
  solver = AllocationSolver(_topology)
  flat_plan = flatten(plan)
  not_scalable_arr = get_not_scalable_tiers(_topology)
  new_allocation = solver.solve(flat_plan, _allocation, not_scalable_arr)
  logging.debug('new_allocation={}'.format(new_allocation))
  flat_topology = flatten_topology(_topology)
  return translator.translate(_allocation, new_allocation, flat_topology)
示例#3
0
def execute(plan):
  global _allocation, _topology
  solver = AllocationSolver(_topology)
  flat_plan = flatten(plan)
  
  _allocation.pop('time', None)
  if solver.need_solution(flat_plan, _allocation):
    not_scalable_arr = get_not_scalable_tiers(_topology)
    new_allocation = solver.solve(flat_plan, _allocation, not_scalable_arr)
    logging.debug('new_allocation={}'.format(new_allocation))
    flat_topology = flatten_topology(_topology)
    actions =  translator.translate(_allocation, new_allocation, flat_topology)

    _allocation = executor.aws_execute(actions, new_allocation, _topology, _allocation)
  return _allocation