/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package se.kth.karamel.backend.mocking;

import java.util.ArrayList;
import java.util.List;
import se.kth.karamel.backend.converter.UserClusterDataExtractor;
import se.kth.karamel.backend.running.model.ClusterRuntime;
import se.kth.karamel.backend.running.model.GroupRuntime;
import se.kth.karamel.backend.running.model.MachineRuntime;
import se.kth.karamel.common.clusterdef.Ec2;
import se.kth.karamel.common.clusterdef.json.JsonCluster;
import se.kth.karamel.common.clusterdef.json.JsonGroup;

/**
 *
 * @author kamal
 */
public class MockingUtil {

  public static ClusterRuntime dummyRuntime(JsonCluster definition) {
    ClusterRuntime clusterRuntime = new ClusterRuntime(definition);
    for (GroupRuntime group : clusterRuntime.getGroups()) {
      //TODO: should add suport for other providers as well, GCE and baremetal machine type
      Ec2 ec2 = (Ec2) UserClusterDataExtractor.getGroupProvider(definition, group.getName());
      JsonGroup definedGroup = UserClusterDataExtractor.findGroup(definition, group.getName());
      List<MachineRuntime> mcs = new ArrayList<>();
//      String ippref = "192.168.0.";
      String ippref = group.getName();
      for (int i = 1; i <= definedGroup.getSize(); i++) {
        String name = group.getName() + "-" + i;
        MachineRuntime ma = new MachineRuntime(group);
        //other machine types from GCE and BareMetal should be added
        ma.setMachineType("ec2/" + ec2.getRegion() + "/" + ec2.getType() + "/" + ec2.getAmi() + "/"
            + ec2.getVpc() + "/" + ec2.getPrice());
        ma.setName(name);
        ma.setPublicIp(ippref + i);
        ma.setPrivateIp(ippref + i);
        ma.setSshUser("ubuntu");
        mcs.add(ma);
      }
      group.setMachines(mcs);
    }

    return clusterRuntime;
  }
}

@@ -554,19 +554,165 @@
 sterdef.
-Ec2
+Baremetal;%0Aimport se.kth.karamel.common.clusterdef.Ec2;%0Aimport se.kth.karamel.common.clusterdef.Gce;%0Aimport se.kth.karamel.common.clusterdef.Provider
 ;%0Aimport
@@ -1084,88 +1084,219 @@
     
-//TODO: should add suport for other providers as well, GCE and baremetal
+Provider provider = UserClusterDataExtractor.getGroupProvider(definition, group.getName());%0A      String machineType = null;%0A      if (provider instanceof Ec2) %7B%0A        Ec2 ec2 = (Ec2) provider;%0A       
  machine
  typ
@@ -1295,108 +1295,455 @@
 hine
- type%0A      Ec2 ec2 = (Ec2) UserClusterDataExtractor.getGroupProvider(definition, group.getNam
+Type = %22ec2/%22 + ec2.getRegion() + %22/%22 + ec2.getType() + %22/%22 + ec2.getAmi() + %22/%22%0A            + ec2.getVpc() + %22/%22 + ec2.getPrice();%0A      %7D else if (provider instanceof Baremetal) %7B%0A        Baremetal baremetal = (Baremetal) provider;%0A        machineType = %22baremetal%22;%0A      %7D else if (provider instanceof Gce) %7B%0A        Gce gce = (Gce) provider;%0A        machineType = %22gce/%22 + gce.getZone() + %22/%22 + gce.getType() + %22/%22 + gce.getImag
 e()
-)
 ;%0A
+      %7D%0A%0A
     
@@ -2137,218 +2137,37 @@
     
-//other machine types from GCE and BareMetal should be added%0A        ma.setMachineType(%22ec2/%22 + ec2.getRegion() + %22/%22 + ec2.getType() + %22/%22 + ec2.getAmi() + %22/%22%0A            + ec2.getVpc() + %22/%22 + ec2.getPrice()
+ma.setMachineType(machineType
 );%0A 

Add GCE and Baremetal support in MockingUtil