-
Notifications
You must be signed in to change notification settings - Fork 1
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 #10 from msimonin/euca2ools-support
Add support for euca2ools.
- Loading branch information
Showing
5 changed files
with
199 additions
and
3 deletions.
There are no files selected for viewing
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,3 @@ | ||
export EC2_ACCESS_KEY="snooze" | ||
export EC2_SECRET_KEY="snooze" | ||
export EC2_URL=http://localhost:4001 |
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
35 changes: 35 additions & 0 deletions
35
src/main/java/org/inria/myriads/snoozeec2/communication/rest/api/SnoozeEC2API.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,35 @@ | ||
package org.inria.myriads.snoozeec2.communication.rest.api; | ||
|
||
import org.restlet.representation.Representation; | ||
import org.restlet.resource.Get; | ||
import org.restlet.resource.Post; | ||
|
||
/** | ||
* @author msimonin | ||
* | ||
*/ | ||
public interface SnoozeEC2API | ||
{ | ||
|
||
|
||
/** | ||
* | ||
* handle a get request on the api. | ||
* | ||
* @return representation of the result. | ||
*/ | ||
@Get | ||
Representation handleGet(); | ||
|
||
|
||
/** | ||
* | ||
* handle a post request. | ||
* | ||
* @param body The body representation. | ||
* @return representation of the result. | ||
*/ | ||
@Post | ||
Representation handlePost(Representation body); | ||
|
||
} |
118 changes: 118 additions & 0 deletions
118
...org/inria/myriads/snoozeec2/communication/rest/api/impl/RESTletSnoozeEC2Communicator.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,118 @@ | ||
package org.inria.myriads.snoozeec2.communication.rest.api.impl; | ||
|
||
import org.inria.myriads.snoozecommon.communication.NetworkAddress; | ||
import org.inria.myriads.snoozecommon.virtualmachineimage.VirtualMachineImageList; | ||
import org.inria.myriads.snoozeec2.communication.rest.api.SnoozeEC2API; | ||
import org.inria.myriads.snoozeimages.communication.rest.api.ImagesRepositoryAPI; | ||
import org.inria.myriads.snoozeimages.communication.rest.api.impl.RESTletImagesRepositoryCommunicator; | ||
import org.restlet.representation.Representation; | ||
import org.restlet.resource.ClientResource; | ||
import org.restlet.resource.Get; | ||
import org.restlet.resource.Post; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class RESTletSnoozeEC2Communicator implements SnoozeEC2API | ||
{ | ||
/** Define the logger. */ | ||
private static final Logger log_ = LoggerFactory.getLogger(RESTletSnoozeEC2Communicator.class); | ||
|
||
/** Address.*/ | ||
private NetworkAddress address_; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param address The image repository address. | ||
*/ | ||
public RESTletSnoozeEC2Communicator(NetworkAddress address) | ||
{ | ||
log_.debug("Initializing REST image repository communicator"); | ||
address_ = address; | ||
} | ||
|
||
/** | ||
* Creates a client resource. | ||
* | ||
* @return The client resource | ||
*/ | ||
private ClientResource createClientResource(String queryParams) | ||
{ | ||
log_.debug("Creating client resource with queryparams : " + queryParams); | ||
String address = address_.getAddress(); | ||
String port = String.valueOf(address_.getPort()); | ||
ClientResource clientResource = new ClientResource("http://" + address + ":" + port + "/?" + queryParams); | ||
|
||
return clientResource; | ||
} | ||
/** | ||
* Creates a client resource. | ||
* | ||
* @return The client resource | ||
*/ | ||
private ClientResource createClientResource() | ||
{ | ||
log_.debug("Creating client resource"); | ||
String address = address_.getAddress(); | ||
String port = String.valueOf(address_.getPort()); | ||
ClientResource clientResource = new ClientResource("http://" + address + ":" + port); | ||
return clientResource; | ||
} | ||
|
||
|
||
public Representation handleGet() | ||
{ | ||
log_.debug("handle a get request"); | ||
ClientResource clientResource = null; | ||
|
||
try | ||
{ | ||
clientResource = createClientResource(); | ||
SnoozeEC2API snoozeEc2 = clientResource.wrap(SnoozeEC2API.class); | ||
Representation result = snoozeEc2.handleGet(); | ||
return result; | ||
} | ||
catch (Exception exception) | ||
{ | ||
log_.debug("Errort while retrieving the image list"); | ||
} | ||
finally | ||
{ | ||
if (clientResource != null) | ||
{ | ||
clientResource.release(); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
|
||
@Override | ||
public Representation handlePost(Representation body) | ||
{ | ||
log_.debug("handle a post request"); | ||
ClientResource clientResource = null; | ||
|
||
try | ||
{ | ||
clientResource = createClientResource(body.getText()); | ||
SnoozeEC2API snoozeEc2 = clientResource.wrap(SnoozeEC2API.class); | ||
Representation result = snoozeEc2.handleGet(); | ||
return result; | ||
} | ||
catch (Exception exception) | ||
{ | ||
log_.debug("Error while handling post request"); | ||
exception.printStackTrace(); | ||
} | ||
finally | ||
{ | ||
if (clientResource != null) | ||
{ | ||
clientResource.release(); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
} |
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