Commit e04310a0 authored by Abmar Barros's avatar Abmar Barros
Browse files

deleting request and instance

parent b73350c3
......@@ -23,10 +23,12 @@ public class FogbowClient {
private String managerHost;
private Integer managerPort;
private HttpWrapper httpWrapper;
private String federationAuthToken;
public FogbowClient(String managerHost, Integer managerPort) {
public FogbowClient(String managerHost, Integer managerPort, String federationAuthToken) {
this.managerHost = managerHost;
this.managerPort = managerPort;
this.federationAuthToken = federationAuthToken;
this.httpWrapper = new HttpWrapper();
}
......@@ -35,22 +37,20 @@ public class FogbowClient {
}
public String createRequest(int minCPU, int minRAM,
String imageName, String pubKeyFilePath,
String federationAuthToken, String localAuthToken) throws Exception {
String imageName, String pubKeyFilePath, String localAuthToken) throws Exception {
return createRequests(1, true, null, "Glue2vCPU >= " + minCPU + " Glue2RAM >= " + minRAM,
imageName, pubKeyFilePath, federationAuthToken, localAuthToken);
imageName, pubKeyFilePath, localAuthToken);
}
public String createRequest(String requirements,
String imageName, String pubKeyFilePath,
String federationAuthToken, String localAuthToken) throws Exception {
String imageName, String pubKeyFilePath, String localAuthToken) throws Exception {
return createRequests(1, true, null, requirements,
imageName, pubKeyFilePath, federationAuthToken, localAuthToken);
imageName, pubKeyFilePath, localAuthToken);
}
public String createRequests(int instanceCount, boolean isOneTime, String flavour,
String requirements, String imageName, String pubKeyFilePath,
String federationAuthToken, String localAuthToken) throws Exception {
String localAuthToken) throws Exception {
String pubKey = null;
if (pubKeyFilePath != null) {
......@@ -102,16 +102,16 @@ public class FogbowClient {
return getRequestId(response);
}
public Request getRequest(String requestId, String federationAuthToken) throws Exception {
public Request getRequest(String requestId) throws Exception {
String getRequestResponse = httpWrapper.doRequest("get",
getManagerURL() + "/" + RequestConstants.TERM + "/" + requestId,
federationAuthToken, new LinkedList<Header>());
Map<String, String> attrs = parseAttributes(getRequestResponse);
String instanceId = attrs.get(FOGBOW_INSTANCE_ID_TERM);
return new Request(instanceId);
return new Request(requestId, instanceId);
}
public Instance getInstance(String instanceId, String federationAuthToken) throws Exception {
public Instance getInstance(String instanceId) throws Exception {
String instanceInfoStr = httpWrapper.doRequest(
"get", getManagerURL() + "/compute/" + instanceId,
federationAuthToken, new LinkedList<Header>());
......@@ -125,6 +125,18 @@ public class FogbowClient {
return new Instance(publicAddressSplit[0], Integer.parseInt(publicAddressSplit[1]));
}
public void deleteRequest(String requestId) throws Exception {
httpWrapper.doRequest("delete",
getManagerURL() + "/" + RequestConstants.TERM + "/" + requestId,
federationAuthToken, new LinkedList<Header>());
}
public void deleteInstance(String instanceId) throws Exception {
httpWrapper.doRequest("delete",
getManagerURL() + "/compute/" + instanceId,
federationAuthToken, new LinkedList<Header>());
}
private static String getRequestId(String createRequestResponse) {
String[] requestRes = createRequestResponse.split(":");
String[] requestId = requestRes[requestRes.length - 1].split("/");
......@@ -147,4 +159,5 @@ public class FogbowClient {
}
return atts;
}
}
......@@ -2,12 +2,18 @@ package org.fogbowcloud.cli;
public class Request {
private String id;
private String instanceId;
public Request(String instanceId) {
public Request(String id, String instanceId) {
this.id = id;
this.instanceId = instanceId;
}
public String getId() {
return id;
}
public String getInstanceId() {
return instanceId;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment