use of org.eclipse.che.api.core.model.machine.MachineConfig in project che by eclipse.
the class TargetsPresenter method updateTargets.
/**
* Fetches all recipes from the server, makes a list of targets and selects specified target.
*/
@Override
public void updateTargets(final String preselectTargetName) {
targets.clear();
machines.clear();
getMachines(appContext.getWorkspaceId()).then(new Operation<List<MachineEntity>>() {
@Override
public void apply(List<MachineEntity> machineList) throws OperationException {
//create Target objects from all machines
for (MachineEntity machine : machineList) {
final MachineConfig machineConfig = machine.getConfig();
machines.put(machineConfig.getName(), machine);
final String targetCategory = machineConfig.isDev() ? machineLocale.devMachineCategory() : machineConfig.getType();
final Target target = createTarget(machineConfig.getName(), targetCategory);
target.setConnected(isMachineRunning(machine));
targets.put(target.getName(), target);
}
//create Target objects from recipe with ssh type
recipeServiceClient.getAllRecipes().then(new Operation<List<RecipeDescriptor>>() {
@Override
public void apply(List<RecipeDescriptor> recipeList) throws OperationException {
for (RecipeDescriptor recipe : recipeList) {
//only for SSH recipes
if (!machineLocale.targetsViewCategorySsh().equalsIgnoreCase(recipe.getType())) {
continue;
}
Target target = targets.get(recipe.getName());
if (target == null) {
target = createTarget(recipe.getName(), recipe.getType());
}
target.setRecipe(recipe);
categoryPageRegistry.getCategoryPage(target.getCategory()).getTargetManager().restoreTarget(target);
targets.put(target.getName(), target);
}
view.showTargets(new ArrayList<>(targets.values()));
selectTarget(preselectTargetName == null ? selectedTarget : targets.get(preselectTargetName));
}
});
}
});
}
Aggregations