-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1717 from eclipse/CODENVY-556-2
CODENVY-556 Add service for fetching recipe script
- Loading branch information
Showing
12 changed files
with
212 additions
and
38 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
.../java/org/eclipse/che/ide/extension/machine/client/RecipeScriptDownloadServiceClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2012-2016 Codenvy, S.A. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Codenvy, S.A. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.che.ide.extension.machine.client; | ||
|
||
import org.eclipse.che.api.promises.client.Promise; | ||
import org.eclipse.che.ide.extension.machine.client.machine.Machine; | ||
|
||
/** | ||
* @author Mihail Kuznyetsov. | ||
*/ | ||
public interface RecipeScriptDownloadServiceClient { | ||
|
||
/** | ||
* Fetch recipe script for machine source location | ||
* | ||
* @param machine | ||
* machine to fetch script for | ||
* @return content of the recipe script | ||
*/ | ||
Promise<String> getRecipeScript(Machine machine); | ||
} |
41 changes: 41 additions & 0 deletions
41
...a/org/eclipse/che/ide/extension/machine/client/RecipeScriptDownloadServiceClientImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2012-2016 Codenvy, S.A. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Codenvy, S.A. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.che.ide.extension.machine.client; | ||
|
||
import org.eclipse.che.api.promises.client.Promise; | ||
import org.eclipse.che.ide.extension.machine.client.machine.Machine; | ||
import org.eclipse.che.ide.rest.AsyncRequestFactory; | ||
import org.eclipse.che.ide.rest.RestContext; | ||
import org.eclipse.che.ide.rest.StringUnmarshaller; | ||
|
||
import javax.inject.Inject; | ||
|
||
/** | ||
* @author Mihail Kuznyetsov. | ||
*/ | ||
public class RecipeScriptDownloadServiceClientImpl implements RecipeScriptDownloadServiceClient { | ||
|
||
private final String restContext; | ||
private final AsyncRequestFactory asyncRequestFactory; | ||
|
||
@Inject | ||
public RecipeScriptDownloadServiceClientImpl(@RestContext String restContext, AsyncRequestFactory asyncRequestFactory) { | ||
this.restContext = restContext; | ||
this.asyncRequestFactory = asyncRequestFactory; | ||
} | ||
|
||
@Override | ||
public Promise<String> getRecipeScript(Machine machine) { | ||
return asyncRequestFactory | ||
.createGetRequest(restContext + "/recipe/script/" + machine.getId()) | ||
.send(new StringUnmarshaller()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...ver/src/main/java/org/eclipse/che/ide/ext/machine/server/RecipeScriptDownloadService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2012-2016 Codenvy, S.A. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Codenvy, S.A. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.che.ide.ext.machine.server; | ||
|
||
|
||
import org.eclipse.che.api.core.NotFoundException; | ||
import org.eclipse.che.api.core.ServerException; | ||
import org.eclipse.che.api.core.rest.Service; | ||
import org.eclipse.che.api.machine.server.MachineManager; | ||
import org.eclipse.che.api.machine.server.util.RecipeRetriever; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
/** | ||
* Service for downloading recipe script for machine. | ||
* | ||
* @author Mihail Kuznyetsov. | ||
*/ | ||
@Path("/recipe/script") | ||
public class RecipeScriptDownloadService extends Service { | ||
|
||
private final MachineManager machineManager; | ||
private final RecipeRetriever recipeRetriever; | ||
|
||
@Inject | ||
public RecipeScriptDownloadService(MachineManager machineManager, RecipeRetriever recipeRetriever) { | ||
this.machineManager = machineManager; | ||
this.recipeRetriever = recipeRetriever; | ||
} | ||
|
||
@GET | ||
@Path("/{machineId}") | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String getRecipeScript(@PathParam("machineId") String machineId) throws ServerException, NotFoundException { | ||
return recipeRetriever.getRecipe(machineManager.getMachine(machineId).getConfig()).getScript(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.