Example #1
0
  private Map<String, List<Dependency>> specifyDeps(List<CloudApplication> apps) {
    Map<String, List<Dependency>> deps = new HashMap<String, List<Dependency>>();

    Scanner reader = new Scanner(System.in);

    while (true) {
      // System.out.println("Specify Dependency Using format A->B  (A depends on B)?(Y/N)");
      // FIXME: more robust input handling
      String line = reader.nextLine();
      if (line.isEmpty()) {
        break;
      }
      String[] ab = line.split("->");

      Dependency dep = new Dependency();
      CloudApplication sourceApp = apps.get(Integer.parseInt(ab[0]) - 1);

      dep.setSource(sourceApp);
      dep.setTarget(apps.get(Integer.parseInt(ab[1]) - 1));

      List<Dependency> list = deps.get(sourceApp.getName());
      if (list == null) {
        list = new ArrayList<Dependency>();
        deps.put(sourceApp.getName(), list);
      }
      list.add(dep);
      System.out.println(
          "Generate the depends-on relationship in application model according to the manually-defined dependency");
    }

    return deps;
  }