| Line 19... |
Line 19... |
| 19 |
package com.elasticgrid.rest;
|
19 |
package com.elasticgrid.rest;
|
| 20 |
|
20 |
|
| 21 |
import com.elasticgrid.cluster.ClusterManager;
|
21 |
import com.elasticgrid.cluster.ClusterManager;
|
| 22 |
import com.elasticgrid.model.Cluster;
|
22 |
import com.elasticgrid.model.Cluster;
|
| 23 |
import com.elasticgrid.model.ClusterProvisioning;
|
23 |
import com.elasticgrid.model.ClusterProvisioning;
|
| - |
|
24 |
import com.elasticgrid.model.NodeProfileInfo;
|
| - |
|
25 |
import com.elasticgrid.model.NodeProfile;
|
| - |
|
26 |
import com.elasticgrid.model.ec2.EC2NodeType;
|
| 24 |
import org.jibx.runtime.JiBXException;
|
27 |
import org.jibx.runtime.JiBXException;
|
| 25 |
import org.restlet.Context;
|
28 |
import org.restlet.Context;
|
| 26 |
import org.restlet.data.Form;
|
29 |
import org.restlet.data.Form;
|
| 27 |
import org.restlet.data.MediaType;
|
30 |
import org.restlet.data.MediaType;
|
| 28 |
import org.restlet.data.Request;
|
31 |
import org.restlet.data.Request;
|
| Line 78... |
Line 81... |
| 78 |
* Handle POST requests: update cluster.
|
81 |
* Handle POST requests: update cluster.
|
| 79 |
*/
|
82 |
*/
|
| 80 |
@Override
|
83 |
@Override
|
| 81 |
public void acceptRepresentation(Representation entity) throws ResourceException {
|
84 |
public void acceptRepresentation(Representation entity) throws ResourceException {
|
| 82 |
String clusterName = null;
|
85 |
String clusterName = null;
|
| 83 |
int numberOfMonitors = 0;
|
- |
|
| 84 |
int numberOfMonitorsAndAgents = 1;
|
- |
|
| 85 |
int numberOfAgents = 0;
|
- |
|
| - |
|
86 |
NodeProfileInfo monitorsInfo = null;
|
| - |
|
87 |
NodeProfileInfo monitorsAndAgentsInfo = null;
|
| - |
|
88 |
NodeProfileInfo agentsInfo = null;
|
| 86 |
if (MediaType.APPLICATION_XML.equals(entity.getMediaType())) {
|
89 |
if (MediaType.APPLICATION_XML.equals(entity.getMediaType())) {
|
| 87 |
try {
|
90 |
try {
|
| 88 |
JibxRepresentation<ClusterProvisioning> representation =
|
91 |
JibxRepresentation<ClusterProvisioning> representation =
|
| 89 |
new JibxRepresentation<ClusterProvisioning>(entity, ClusterProvisioning.class, "ElasticGridREST");
|
92 |
new JibxRepresentation<ClusterProvisioning>(entity, ClusterProvisioning.class, "ElasticGridREST");
|
| 90 |
ClusterProvisioning clusterProvisioning = representation.getObject();
|
93 |
ClusterProvisioning clusterProvisioning = representation.getObject();
|
| 91 |
clusterName = clusterProvisioning.getClusterName();
|
94 |
clusterName = clusterProvisioning.getClusterName();
|
| 92 |
numberOfMonitors = clusterProvisioning.getNumberOfMonitors();
|
- |
|
| 93 |
numberOfMonitorsAndAgents = clusterProvisioning.getNumberOfMonitorsAndAgents();
|
- |
|
| 94 |
numberOfAgents = clusterProvisioning.getNumberOfAgents();
|
- |
|
| - |
|
95 |
monitorsInfo = clusterProvisioning.getMonitorsInfo();
|
| - |
|
96 |
monitorsAndAgentsInfo = clusterProvisioning.getMonitorsAndAgentsInfo();
|
| - |
|
97 |
agentsInfo = clusterProvisioning.getAgentsInfo();
|
| 95 |
} catch (JiBXException e) {
|
98 |
} catch (JiBXException e) {
|
| 96 |
e.printStackTrace();
|
99 |
e.printStackTrace();
|
| 97 |
throw new ResourceException(Status.CLIENT_ERROR_UNPROCESSABLE_ENTITY, e);
|
100 |
throw new ResourceException(Status.CLIENT_ERROR_UNPROCESSABLE_ENTITY, e);
|
| 98 |
} catch (IOException e) {
|
101 |
} catch (IOException e) {
|
| 99 |
e.printStackTrace();
|
102 |
e.printStackTrace();
|
| 100 |
throw new ResourceException(Status.CLIENT_ERROR_UNPROCESSABLE_ENTITY, e);
|
103 |
throw new ResourceException(Status.CLIENT_ERROR_UNPROCESSABLE_ENTITY, e);
|
| 101 |
}
|
104 |
}
|
| 102 |
} else if (MediaType.APPLICATION_WWW_FORM.equals(entity.getMediaType())) {
|
105 |
} else if (MediaType.APPLICATION_WWW_FORM.equals(entity.getMediaType())) {
|
| 103 |
Form form = new Form(entity);
|
106 |
Form form = new Form(entity);
|
| 104 |
clusterName = form.getFirstValue("clusterName");
|
107 |
clusterName = form.getFirstValue("clusterName");
|
| 105 |
numberOfMonitors = Integer.parseInt(form.getFirstValue("numberOfMonitors"));
|
- |
|
| 106 |
numberOfMonitorsAndAgents = Integer.parseInt(form.getFirstValue("numberOfMonitorsAndAgents"));
|
- |
|
| 107 |
numberOfAgents = Integer.parseInt(form.getFirstValue("numberOfAgents"));
|
- |
|
| - |
|
108 |
monitorsInfo = new NodeProfileInfo(NodeProfile.MONITOR,
|
| - |
|
109 |
EC2NodeType.valueOf(form.getFirstValue("monitorNodeType")),
|
| - |
|
110 |
Integer.parseInt(form.getFirstValue("numberOfMonitors")));
|
| - |
|
111 |
monitorsAndAgentsInfo = new NodeProfileInfo(NodeProfile.MONITOR_AND_AGENT,
|
| - |
|
112 |
EC2NodeType.valueOf(form.getFirstValue("monitorAndAgentNodeType")),
|
| - |
|
113 |
Integer.parseInt(form.getFirstValue("numberOfMonitorsAndAgents")));
|
| - |
|
114 |
agentsInfo = new NodeProfileInfo(NodeProfile.AGENT,
|
| - |
|
115 |
EC2NodeType.valueOf(form.getFirstValue("agentNodeType")),
|
| - |
|
116 |
Integer.parseInt(form.getFirstValue("numberOfAgents")));
|
| 108 |
}
|
117 |
}
|
| 109 |
try {
|
118 |
try {
|
| 110 |
clusterManager.resizeCluster(clusterName, numberOfMonitors, numberOfMonitorsAndAgents, numberOfAgents);
|
- |
|
| - |
|
119 |
clusterManager.resizeCluster(clusterName, Arrays.asList(monitorsInfo, monitorsAndAgentsInfo, agentsInfo));
|
| 111 |
} catch (TimeoutException e) {
|
120 |
} catch (TimeoutException e) {
|
| 112 |
e.printStackTrace();
|
121 |
e.printStackTrace();
|
| 113 |
throw new ResourceException(Status.SERVER_ERROR_GATEWAY_TIMEOUT, e);
|
122 |
throw new ResourceException(Status.SERVER_ERROR_GATEWAY_TIMEOUT, e);
|
| 114 |
} catch (Exception e) {
|
123 |
} catch (Exception e) {
|
| 115 |
e.printStackTrace();
|
124 |
e.printStackTrace();
|