Skip to content

Commit 5eadb10

Browse files
committed
Merge pull request #238 from fogbow/support-compute-post
Support compute post
2 parents 15e271d + adac413 commit 5eadb10

30 files changed

+2875
-486
lines changed

manager.conf.example

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,19 @@ ssh_public_key=/etc/fogbow-manager/ssh/id_rsa.pub
215215

216216
## Benchmarking (Vanilla Benchmarking Plugin)
217217
# benchmarking_class=org.fogbowcloud.manager.core.plugins.benchmarking.VanillaBenchmarkingPlugin
218+
219+
220+
## OCCI extra resources
221+
#occi_extra_resource_file_path=
222+
223+
224+
public_key; scheme="http://schemas.openstack.org/instance/credentials#"; class="mixin";
225+
org.openstack.credentials.publickey.data
226+
227+
# Request public key properties
228+
occi_extra_resource_fogbow_public_key=public_key
229+
occi_extra_resource_org.fogbowcloud.credentials.publickey.data=org.openstack.credentials.publickey.data
230+
231+
# Request userdata properties
232+
occi_extra_resource_fogbow_userdata=user_data
233+
occi_extra_resource_org.fogbowcloud.request.extra-user-data=org.openstack.compute.user_data

src/main/java/org/fogbowcloud/manager/Main.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,16 @@ public static void main(String[] args) throws Exception {
144144
LOGGER.warn("Federation user crendetail plugin not specified in properties. Using the default one.", e);
145145
}
146146

147+
String occiExtraResourcesPath = properties
148+
.getProperty(ConfigurationConstants.OCCI_EXTRA_RESOURCES_KEY_PATH);
149+
if (occiExtraResourcesPath != null && !occiExtraResourcesPath.isEmpty()) {
150+
if (properties.getProperty(ConfigurationConstants.INSTANCE_DATA_STORE_URL) == null) {
151+
LOGGER.error("If OCCI extra resources was set for supporting post-compute, you must also set instance datastore property ("
152+
+ ConfigurationConstants.INSTANCE_DATA_STORE_URL + ").");
153+
System.exit(EXIT_ERROR_CODE);
154+
}
155+
}
156+
147157
PrioritizationPlugin prioritizationPlugin = new TwoFoldPrioritizationPlugin(properties,
148158
accountingPlugin);
149159

src/main/java/org/fogbowcloud/manager/core/ConfigurationConstants.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class ConfigurationConstants {
2525
public static final String LOCAL_PREFIX = "local_";
2626
public static final String FEDERATION_PREFIX = "federation_";
2727
public static final String PREFIX_FLAVORS = "flavor_";
28+
public static final String OCCI_EXTRA_RESOURCES_PREFIX = "occi_extra_resource_";
2829

2930
// periods
3031
public static final String ORDER_BD_UPDATER_PERIOD_KEY = "order_bd_updater_period";
@@ -50,4 +51,10 @@ public class ConfigurationConstants {
5051
public static final String HTTP_PORT_KEY = "http_port";
5152

5253
public static final String PROP_MAX_WHOISALIVE_MANAGER_COUNT = "max_whoisalive_manager_count";
54+
55+
// OCCI extra resource
56+
public static final String OCCI_EXTRA_RESOURCES_KEY_PATH = "occi_extra_resource_file_path";
57+
58+
// Instance Data Store
59+
public static final String INSTANCE_DATA_STORE_URL = "instance_datastore_url";
5360
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package org.fogbowcloud.manager.occi;
2+
3+
import java.util.ArrayList;
4+
import java.util.HashMap;
5+
import java.util.List;
6+
import java.util.Map;
7+
8+
import org.fogbowcloud.manager.occi.instance.Instance.Link;
9+
import org.fogbowcloud.manager.occi.model.Category;
10+
import org.json.JSONArray;
11+
import org.json.JSONException;
12+
import org.json.JSONObject;
13+
14+
public class JSONHelper {
15+
16+
public static Map<String, String> toMap(String jsonStr) {
17+
Map<String, String> newMap = new HashMap<String, String>();
18+
jsonStr = jsonStr.replace("{", "").replace("}", "");
19+
String[] blocks = jsonStr.split(",");
20+
for (int i = 0; i < blocks.length; i++) {
21+
String block = blocks[i];
22+
int indexOfCarac = block.indexOf("=");
23+
if (indexOfCarac < 0) {
24+
continue;
25+
}
26+
String key = block.substring(0, indexOfCarac).trim();
27+
String value = block.substring(indexOfCarac + 1, block.length()).trim();
28+
newMap.put(key, value);
29+
}
30+
return newMap;
31+
}
32+
33+
public static Map<String, String> getXOCCIAttrFromJSON(String jsonStr) throws JSONException {
34+
JSONObject jsonObject = new JSONObject(jsonStr);
35+
return toMap(jsonObject.optString("xocci_attributes"));
36+
}
37+
38+
public static JSONObject mountXOCCIAttrJSON(Map<String, String> xOCCIAtt) throws JSONException {
39+
return new JSONObject().put("xocci_attributes", xOCCIAtt != null ? xOCCIAtt.toString()
40+
: null);
41+
}
42+
43+
public static List<Category> getCategoriesFromJSON(String jsonArrayString) throws JSONException {
44+
List<Category> categories = new ArrayList<Category>();
45+
JSONArray jsonArray = new JSONArray(jsonArrayString);
46+
for (int i = 0; i < jsonArray.length(); i++) {
47+
categories.add(Category.fromJSON(jsonArray.getString(i)));
48+
}
49+
50+
return categories;
51+
}
52+
53+
public static JSONArray mountCategoriesJSON(List<Category> categories) throws JSONException {
54+
List<JSONObject> categoryObj = new ArrayList<JSONObject>();
55+
for (Category category : categories != null ? categories : new ArrayList<Category>()) {
56+
categoryObj.add(category.toJSON());
57+
}
58+
return new JSONArray(categoryObj);
59+
}
60+
61+
public static JSONArray mountLinksJSON(List<Link> links) throws JSONException {
62+
List<JSONObject> linkObj = new ArrayList<JSONObject>();
63+
for (Link link : links != null ? links : new ArrayList<Link>()) {
64+
linkObj.add(link.toJSON());
65+
}
66+
return new JSONArray(linkObj);
67+
}
68+
69+
public static List<Link> getLinksFromJSON(String jsonArrayString) throws JSONException {
70+
if (jsonArrayString == null) {
71+
return null;
72+
}
73+
List<Link> links = new ArrayList<Link>();
74+
JSONArray jsonArray = new JSONArray(jsonArrayString);
75+
for (int i = 0; i < jsonArray.length(); i++) {
76+
links.add(Link.fromJSON(jsonArray.getString(i)));
77+
}
78+
return links;
79+
}
80+
}

src/main/java/org/fogbowcloud/manager/occi/OCCIApplication.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ public Restlet createInboundRoot() {
4242
router.attach("/" + RequestConstants.TERM, RequestServerResource.class);
4343
router.attach("/" + RequestConstants.TERM + "/", RequestServerResource.class);
4444
router.attach("/" + RequestConstants.TERM + "/{requestId}", RequestServerResource.class);
45-
router.attach("/compute", ComputeServerResource.class);
46-
router.attach("/compute/", ComputeServerResource.class);
47-
router.attach("/compute/{instanceId}", ComputeServerResource.class);
45+
router.attach("/" + RequestConstants.COMPUTE_TERM, ComputeServerResource.class);
46+
router.attach("/" + RequestConstants.COMPUTE_TERM + "/", ComputeServerResource.class);
47+
router.attach("/" + RequestConstants.COMPUTE_TERM + "/{instanceId}", ComputeServerResource.class);
4848
router.attach("/members", MemberServerResource.class);
4949
//TODO remove this endpoint
5050
router.attach("/token", TokenServerResource.class);
@@ -196,4 +196,8 @@ public ResourcesInfo getLocalUserQuota(String localAccessToken) {
196196
return managerFacade.getLocalUserQuota(localAccessToken);
197197
}
198198

199+
public String getUser(String authToken) {
200+
return managerFacade.getUser(authToken);
201+
}
202+
199203
}

src/main/java/org/fogbowcloud/manager/occi/OrderDataStoreHelper.java

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)