Search in sources :

Example 6 with MachineConfig

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));
                }
            });
        }
    });
}
Also used : MachineEntity(org.eclipse.che.ide.api.machine.MachineEntity) MachineConfig(org.eclipse.che.api.core.model.machine.MachineConfig) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Operation(org.eclipse.che.api.promises.client.Operation) RecipeDescriptor(org.eclipse.che.api.machine.shared.dto.recipe.RecipeDescriptor) OperationException(org.eclipse.che.api.promises.client.OperationException)

Aggregations

MachineConfig (org.eclipse.che.api.core.model.machine.MachineConfig)6 Machine (org.eclipse.che.api.core.model.machine.Machine)2 Instance (org.eclipse.che.api.machine.server.spi.Instance)2 MachineEntity (org.eclipse.che.ide.api.machine.MachineEntity)2 Element (elemental.dom.Element)1 Node (elemental.dom.Node)1 Event (elemental.events.Event)1 EventListener (elemental.events.EventListener)1 DivElement (elemental.html.DivElement)1 SpanElement (elemental.html.SpanElement)1 ArrayList (java.util.ArrayList)1 Collections.emptyList (java.util.Collections.emptyList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 ConflictException (org.eclipse.che.api.core.ConflictException)1 NotFoundException (org.eclipse.che.api.core.NotFoundException)1 ExtendedMachine (org.eclipse.che.api.core.model.workspace.ExtendedMachine)1 NoOpMachineInstance (org.eclipse.che.api.environment.server.NoOpMachineInstance)1