Search in sources :

Example 11 with RecipeDescriptor

use of org.eclipse.che.api.machine.shared.dto.recipe.RecipeDescriptor in project che by eclipse.

the class CreateWorkspaceViewImpl method addRecipesToPanel.

private void addRecipesToPanel(List<RecipeDescriptor> recipes) {
    tagsPanel.clear();
    for (RecipeDescriptor descriptor : recipes) {
        RecipeWidget tag = tagFactory.create(descriptor);
        tag.setDelegate(this);
        tagsPanel.add(tag);
    }
    popupPanel.setWidget(tagsPanel);
}
Also used : RecipeDescriptor(org.eclipse.che.api.machine.shared.dto.recipe.RecipeDescriptor) RecipeWidget(org.eclipse.che.ide.workspace.create.recipewidget.RecipeWidget)

Example 12 with RecipeDescriptor

use of org.eclipse.che.api.machine.shared.dto.recipe.RecipeDescriptor in project che by eclipse.

the class GdbConfigurationPagePresenter method setHosts.

private void setHosts(List<Machine> machines) {
    List<Promise<RecipeDescriptor>> recipePromises = new ArrayList<>(machines.size());
    for (Machine machine : machines) {
        String location = machine.getConfig().getSource().getLocation();
        String recipeId = getRecipeId(location);
        recipePromises.add(recipeServiceClient.getRecipe(recipeId));
    }
    @SuppressWarnings("unchecked") final Promise<RecipeDescriptor>[] recipePromisesArray = (Promise<RecipeDescriptor>[]) recipePromises.toArray();
    setHostsList(recipePromisesArray, machines);
}
Also used : Promise(org.eclipse.che.api.promises.client.Promise) ArrayList(java.util.ArrayList) RecipeDescriptor(org.eclipse.che.api.machine.shared.dto.recipe.RecipeDescriptor) Machine(org.eclipse.che.api.core.model.machine.Machine)

Example 13 with RecipeDescriptor

use of org.eclipse.che.api.machine.shared.dto.recipe.RecipeDescriptor in project che by eclipse.

the class RecipeServiceTest method shouldCreateNewRecipe.

@Test
public void shouldCreateNewRecipe() throws Exception {
    final NewRecipe newRecipe = newDto(NewRecipe.class).withType("docker").withName("name").withScript("FROM ubuntu\n").withTags(asList("java", "mongo"));
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(newRecipe).when().post(SECURE_PATH + "/recipe");
    assertEquals(response.getStatusCode(), 201);
    verify(recipeDao).create(any(RecipeImpl.class));
    final RecipeDescriptor descriptor = unwrapDto(response, RecipeDescriptor.class);
    assertNotNull(descriptor.getId());
    assertEquals(descriptor.getName(), newRecipe.getName());
    assertEquals(descriptor.getCreator(), USER_ID);
    assertEquals(descriptor.getScript(), newRecipe.getScript());
    assertEquals(descriptor.getTags(), newRecipe.getTags());
}
Also used : Response(com.jayway.restassured.response.Response) RecipeDescriptor(org.eclipse.che.api.machine.shared.dto.recipe.RecipeDescriptor) NewRecipe(org.eclipse.che.api.machine.shared.dto.recipe.NewRecipe) Test(org.testng.annotations.Test)

Example 14 with RecipeDescriptor

use of org.eclipse.che.api.machine.shared.dto.recipe.RecipeDescriptor 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)

Example 15 with RecipeDescriptor

use of org.eclipse.che.api.machine.shared.dto.recipe.RecipeDescriptor in project che by eclipse.

the class SshViewImpl method restoreTargetFields.

@Override
public boolean restoreTargetFields(SshMachineTarget target) {
    if (target == null) {
        return false;
    }
    final RecipeDescriptor targetRecipe = target.getRecipe();
    if (targetRecipe == null) {
        return false;
    }
    try {
        final JSONObject json = JSONParser.parseStrict(targetRecipe.getScript()).isObject();
        String name = targetRecipe.getName();
        target.setName(name);
        if (json.get("host") != null) {
            String host = json.get("host").isString().stringValue();
            target.setHost(host);
        }
        if (json.get("port") != null) {
            String port = json.get("port").isString().stringValue();
            target.setPort(port);
        }
        if (json.get("username") != null) {
            String username = json.get("username").isString().stringValue();
            target.setUserName(username);
        }
        if (json.get("password") != null) {
            String password = json.get("password").isString().stringValue();
            target.setPassword(password);
        }
        target.setDirty(false);
    } catch (Exception e) {
        Log.error(this.getClass(), "Unable to parse recipe JSON. " + e.getMessage());
        return false;
    }
    return true;
}
Also used : JSONObject(com.google.gwt.json.client.JSONObject) RecipeDescriptor(org.eclipse.che.api.machine.shared.dto.recipe.RecipeDescriptor)

Aggregations

RecipeDescriptor (org.eclipse.che.api.machine.shared.dto.recipe.RecipeDescriptor)15 OperationException (org.eclipse.che.api.promises.client.OperationException)6 ArrayList (java.util.ArrayList)4 NewRecipe (org.eclipse.che.api.machine.shared.dto.recipe.NewRecipe)3 PromiseError (org.eclipse.che.api.promises.client.PromiseError)3 Response (com.jayway.restassured.response.Response)2 List (java.util.List)2 RecipeUpdate (org.eclipse.che.api.machine.shared.dto.recipe.RecipeUpdate)2 RecipeEditorPanel (org.eclipse.che.ide.extension.machine.client.perspective.widgets.recipe.editor.RecipeEditorPanel)2 Test (org.testng.annotations.Test)2 JSONObject (com.google.gwt.json.client.JSONObject)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.singletonList (java.util.Collections.singletonList)1 HashSet (java.util.HashSet)1 UriBuilder (javax.ws.rs.core.UriBuilder)1 Machine (org.eclipse.che.api.core.model.machine.Machine)1 MachineConfig (org.eclipse.che.api.core.model.machine.MachineConfig)1 GenerateLink (org.eclipse.che.api.core.rest.annotations.GenerateLink)1 Link (org.eclipse.che.api.core.rest.shared.dto.Link)1 Operation (org.eclipse.che.api.promises.client.Operation)1