Search in sources :

Example 1 with Recipe

use of org.eclipse.che.api.core.model.machine.Recipe in project che by eclipse.

the class SshMachineInstanceProvider method createInstance.

/**
     * Creates instance from scratch or by reusing a previously one by using specified {@link MachineSource}
     * data in {@link MachineConfig}.
     *
     * @param machine
     *         machine description
     * @param lineConsumer
     *         output for instance creation logs
     * @return newly created {@link SshMachineInstance}
     * @throws UnsupportedRecipeException
     *         if specified {@code recipe} is not supported
     * @throws InvalidRecipeException
     *         if {@code recipe} is invalid
     * @throws NotFoundException
     *         if instance described by {@link MachineSource} doesn't exists
     * @throws MachineException
     *         if other error occurs
     */
public SshMachineInstance createInstance(Machine machine, LineConsumer lineConsumer) throws NotFoundException, MachineException {
    requireNonNull(machine, "Non null machine required");
    requireNonNull(lineConsumer, "Non null logs consumer required");
    requireNonNull(machine.getConfig().getSource().getLocation(), "Location in machine source is required");
    if (machine.getConfig().isDev()) {
        throw new MachineException("Dev machine is not supported for Ssh machine implementation");
    }
    Recipe recipe = recipeDownloader.getRecipe(machine.getConfig());
    SshMachineRecipe sshMachineRecipe = GSON.fromJson(recipe.getScript(), SshMachineRecipe.class);
    SshClient sshClient = sshMachineFactory.createSshClient(sshMachineRecipe, machine.getConfig().getEnvVariables());
    sshClient.start();
    SshMachineInstance instance = sshMachineFactory.createInstance(machine, sshClient, lineConsumer);
    instance.setStatus(MachineStatus.RUNNING);
    return instance;
}
Also used : Recipe(org.eclipse.che.api.core.model.machine.Recipe) MachineException(org.eclipse.che.api.machine.server.exception.MachineException)

Example 2 with Recipe

use of org.eclipse.che.api.core.model.machine.Recipe in project che by eclipse.

the class RecipeRetrieverTest method checkWithContent.

/**
     * Check that when content is set in machine source, recipe is based on this content.
     * @throws MachineException if recipe is not retrieved
     */
@Test
public void checkWithContent() throws MachineException {
    String RECIPE = "FROM TOTO";
    when(machineSource.getContent()).thenReturn(RECIPE);
    Recipe recipe = recipeRetriever.getRecipe(machineConfig);
    Assert.assertNotNull(recipe);
    assertEquals(recipe.getType(), RECIPE_TYPE);
    assertEquals(recipe.getScript(), RECIPE);
}
Also used : Recipe(org.eclipse.che.api.core.model.machine.Recipe) Test(org.testng.annotations.Test)

Aggregations

Recipe (org.eclipse.che.api.core.model.machine.Recipe)2 MachineException (org.eclipse.che.api.machine.server.exception.MachineException)1 Test (org.testng.annotations.Test)1