/** The default constructor. */ public InstanceJob( ClusterInfo target_cluster, ClusterInfo source_cluster, int machineId, ResultListener listener) { this.listener = listener; MachineService machineService = CloudBackup.getInstance().getMachineService(); if (machineService != null) { Machine machine = machineService.getMachine(machineId); this.hostname = machine.getDnsName(); this.username = machine.getUserName(); } else { logger.warn("machineService is null"); } this.virtualCluster = target_cluster; this.storageCluster = source_cluster; this.logicalMachineName = decideLogicalHostname(machineId); this.setJobName("cluster-" + source_cluster.getClusterId() + "_" + logicalMachineName); // Use cipher default from application context this.cipher = CloudBackup.getBackupProperties().isCipher(); }
/** Decide logical machine name, which is used on store and restore */ private static String decideLogicalHostname(int machineId) { if (CloudBackup.getInstance().getMachineService() == null) return "test"; // Get Machine MachineService machineService = CloudBackup.getInstance().getMachineService(); Machine machine = machineService.getMachine(machineId); // We use machine type as base String machine_type = machine.getType(); // Get cluster machine list and ensure, that it's ordered by machine id Collection<Machine> machines_unordered = machineService.getMachinesInCluster(machine.getClusterId()); Set<Machine> machines = new TreeSet<Machine>( new Comparator<Machine>() { public int compare(Machine m1, Machine m2) { if (m1.getId() < m2.getId()) return -1; if (m1.getId() > m2.getId()) return 1; return 0; } public boolean equals(Object o) { if (o != null) return (this.getClass().equals(o.getClass())); else return false; } }); for (Machine m : machines_unordered) { // Add only machines of same type if (m.getType().equals(machine.getType())) { machines.add(m); } } // Find machine number int num = 1; for (Machine m : machines) { if (m.getId() == machine.getId()) { break; } num++; } // Combine machine type and order number return machine_type + "-" + num; }