Permalink
Browse files

support to EC2 requestSpotInstances

  • Loading branch information...
pauloricardomg committed Aug 5, 2010
1 parent a666110 commit a61859c0b582a97291f41b1de0e77f79bcfef771
Showing with 523 additions and 20 deletions.
  1. +10 −1 messaging/gt4.0-elastic/java/msgbridge/etc/elastic/other/main.conflocator.xml
  2. +16 −0 messaging/gt4.0-elastic/java/msgbridge/etc/elastic/other/main.xml
  3. +14 −2 ...4.0-elastic/java/msgbridge/src/org/nimbustools/messaging/gt4_0_elastic/v2008_05_05/ServiceRM.java
  4. +4 −1 ...sgbridge/src/org/nimbustools/messaging/gt4_0_elastic/v2008_05_05/general/ResourceAllocations.java
  5. +22 −3 .../nimbustools/messaging/gt4_0_elastic/v2008_05_05/general/defaults/DefaultResourceAllocations.java
  6. +5 −1 ...0-elastic/java/msgbridge/src/org/nimbustools/messaging/gt4_0_elastic/v2008_05_05/rm/Describe.java
  7. +56 −0 ...-elastic/java/msgbridge/src/org/nimbustools/messaging/gt4_0_elastic/v2008_05_05/rm/RequestSI.java
  8. +0 −1 .../gt4.0-elastic/java/msgbridge/src/org/nimbustools/messaging/gt4_0_elastic/v2008_05_05/rm/Run.java
  9. +50 −0 ...stic/java/msgbridge/src/org/nimbustools/messaging/gt4_0_elastic/v2008_05_05/rm/ServiceRMImpl.java
  10. +13 −8 ...sgbridge/src/org/nimbustools/messaging/gt4_0_elastic/v2008_05_05/rm/defaults/DefaultDescribe.java
  11. +289 −0 ...gbridge/src/org/nimbustools/messaging/gt4_0_elastic/v2008_05_05/rm/defaults/DefaultRequestSI.java
  12. +3 −2 ...ava/msgbridge/src/org/nimbustools/messaging/gt4_0_elastic/v2008_05_05/rm/defaults/DefaultRun.java
  13. +16 −1 ...idge/src/org/nimbustools/messaging/gt4_0_elastic/v2008_05_05/service/UnimplementedOperations.java
  14. +8 −0 messaging/query/java/source/etc/query/other/main.conflocator.xml
  15. +17 −0 messaging/query/java/source/etc/query/other/main.xml
@@ -51,10 +51,19 @@
<property name="placeholderPrefix" value="$OTHER_ELASTIC{" />
</bean>
- <bean id="querySettings"
+ <bean id="querySettings"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="$NIMBUS_HOME/services/etc/nimbus/query/query.conf" />
<property name="placeholderPrefix" value="$QUERY{" />
</bean>
+ <bean id="siSettings"
+ class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
+
+ <property name="location"
+ value="$NIMBUS_HOME/services/etc/nimbus/workspace-service/spotinstances.conf" />
+ <property name="placeholderPrefix"
+ value="$SI{" />
+ </bean>
+
</beans>
@@ -18,6 +18,7 @@
<constructor-arg ref="nimbus-elastic.rm.terminate" />
<constructor-arg ref="nimbus-elastic.rm.reboot" />
<constructor-arg ref="nimbus-elastic.rm.describe" />
+ <constructor-arg ref="nimbus-elastic.rm.requestSI" />
<constructor-arg ref="nimbus-elastic.rm.containerInterface" />
<constructor-arg ref="nimbus-elastic.rm.modulelocator" />
@@ -37,6 +38,20 @@
</bean>
+ <bean id="nimbus-elastic.rm.requestSI"
+ class="org.nimbustools.messaging.gt4_0_elastic.v2008_05_05.rm.defaults.DefaultRequestSI">
+
+ <constructor-arg ref="nimbus-elastic.general.ra" />
+ <constructor-arg ref="nimbus-elastic.general.networks" />
+ <constructor-arg ref="nimbus-elastic.rm.idmappings" />
+ <constructor-arg ref="nimbus-elastic.rm.describe" />
+ <constructor-arg ref="nimbus-elastic.rm.containerInterface" />
+ <constructor-arg ref="nimbus-elastic.security.sshkeys" />
+ <constructor-arg ref="nimbus-elastic.image.repository" />
+ <constructor-arg ref="nimbus-elastic.rm.modulelocator" />
+
+ </bean>
+
<bean id="nimbus-elastic.rm.terminate"
class="org.nimbustools.messaging.gt4_0_elastic.v2008_05_05.rm.defaults.DefaultTerminate">
@@ -106,6 +121,7 @@
<property name="cpuArch" value="$OTHER_ELASTIC{cpu.arch}" />
<property name="vmmType" value="$OTHER_ELASTIC{vmm.type}" />
<property name="vmmVersion" value="$OTHER_ELASTIC{vmm.version}" />
+ <property name="siType" value="$SI{si.instancetype}" />
</bean>
@@ -43,10 +43,22 @@ public DescribeInstancesResponseType describeInstances(
throws RemoteException;
public MonitorInstancesResponseType monitorInstances(
- MonitorInstancesType monitorInstancesRequestMsg)
+ MonitorInstancesType monitorInstancesRequestMsg)
throws RemoteException;
public MonitorInstancesResponseType unmonitorInstances(
- MonitorInstancesType unmonitorInstancesRequestMsg)
+ MonitorInstancesType unmonitorInstancesRequestMsg)
+ throws RemoteException;
+
+ // -------------------------------------------------------------------------
+ // SI OPERATIONS
+ // -------------------------------------------------------------------------
+
+ public RequestSpotInstancesResponseType requestSpotInstances(
+ RequestSpotInstancesType requestSpotInstancesMsg)
+ throws RemoteException;
+
+ public CancelSpotInstanceRequestsResponseType cancelSpotInstanceRequests(
+ CancelSpotInstanceRequestsType cancelSpotInstancesMsg)
throws RemoteException;
}
@@ -47,11 +47,14 @@ public String getMatchingName(ResourceAllocation ra)
*/
public ResourceAllocation getMatchingRA(String name,
int minNumNodes,
- int maxNumNodes)
+ int maxNumNodes,
+ boolean spot)
throws CannotTranslateException;
/**
* @return vmm to request
*/
public RequiredVMM getRequiredVMM();
+
+ public String getSpotInstanceType();
}
@@ -46,7 +46,7 @@
// -------------------------------------------------------------------------
protected final ReprFactory repr;
-
+
protected int smallMemory;
protected int largeMemory;
protected int xlargeMemory;
@@ -62,6 +62,8 @@
protected String vmmVersion;
protected RequiredVMM requestThisVMM;
+
+ protected String siType;
// -------------------------------------------------------------------------
@@ -167,11 +169,19 @@ public void setVmmType(String vmmType) {
public void setVmmVersion(String vmmVersion) {
this.vmmVersion = vmmVersion;
}
+
+ public void setSiType(String siType) {
+ this.siType = siType;
+ }
// -------------------------------------------------------------------------
// implements ResourceAllocations
// -------------------------------------------------------------------------
+ public String getSpotInstanceType(){
+ return this.siType;
+ }
+
public String getSmallName() {
return this.smallName;
}
@@ -221,7 +231,8 @@ public String getMatchingName(ResourceAllocation ra)
public ResourceAllocation getMatchingRA(String name,
int minNumNodes,
- int maxNumNodes)
+ int maxNumNodes,
+ boolean spot)
throws CannotTranslateException {
final String cmpName;
@@ -235,6 +246,12 @@ public ResourceAllocation getMatchingRA(String name,
final _ResourceAllocation ra = this.repr._newResourceAllocation();
ra.setNodeNumber(minNumNodes); // only respecting min at the moment
+ if(spot && !cmpName.equals(siType)){
+ throw new CannotTranslateException(
+ "Unsupported spot instance type: '" + name + "'." +
+ " Currently supported SI type: " + siType);
+ }
+
if (cmpName.equals(this.getSmallName())) {
ra.setMemory(this.smallMemory);
} else if (cmpName.equals(this.getLargeName())) {
@@ -245,7 +262,9 @@ public ResourceAllocation getMatchingRA(String name,
throw new CannotTranslateException(
"Unknown instance type '" + name + "'");
}
-
+
+ ra.setPreemptable(spot);
+
ra.setArchitecture(this.cpuArch);
return ra;
@@ -18,8 +18,10 @@
import org.nimbustools.api.repr.CannotTranslateException;
import org.nimbustools.api.repr.vm.VM;
+import org.nimbustools.api.repr.vm.VMFile;
import org.nimbustools.messaging.gt4_0_elastic.generated.v2010_06_15.DescribeInstancesResponseType;
import org.nimbustools.messaging.gt4_0_elastic.generated.v2010_06_15.DescribeInstancesType;
+import org.nimbustools.messaging.gt4_0_elastic.generated.v2010_06_15.PlacementRequestType;
import org.nimbustools.messaging.gt4_0_elastic.generated.v2010_06_15.PlacementResponseType;
import org.nimbustools.messaging.gt4_0_elastic.generated.v2010_06_15.InstanceStateType;
@@ -40,11 +42,13 @@ public DescribeInstancesResponseType translate(VM[] vms,
public String getReason(VM vm) throws CannotTranslateException;
- public String getImageID(VM vm) throws CannotTranslateException;
+ public String getImageID(VMFile[] vmFiles) throws CannotTranslateException;
public String getInstanceType(VM vm) throws CannotTranslateException;
public PlacementResponseType getPlacement();
+
+ public PlacementRequestType getPlacementReq();
public Calendar getLaunchTime(VM vm) throws CannotTranslateException;
}
@@ -0,0 +1,56 @@
+/*
+ * Copyright 1999-2010 University of Chicago
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.nimbustools.messaging.gt4_0_elastic.v2008_05_05.rm;
+
+import org.nimbustools.api.repr.Caller;
+import org.nimbustools.api.repr.CannotTranslateException;
+import org.nimbustools.api.repr.SpotCreateRequest;
+import org.nimbustools.api.repr.SpotRequestInfo;
+import org.nimbustools.messaging.gt4_0_elastic.generated.v2010_06_15.RequestSpotInstancesResponseType;
+import org.nimbustools.messaging.gt4_0_elastic.generated.v2010_06_15.RequestSpotInstancesType;
+
+import java.rmi.RemoteException;
+
+public interface RequestSI {
+
+ /**
+ * Translate request spot instances
+ * into something the Manager understands.
+ *
+ * @param req given SI request
+ * @param caller caller object
+ * @return valid create request for manager
+ * @throws RemoteException unexpected error
+ * @throws CannotTranslateException invalid request or configuration
+ */
+ public SpotCreateRequest translateReqSpotInstances(RequestSpotInstancesType req,
+ Caller caller)
+ throws RemoteException, CannotTranslateException;
+
+ /**
+ * Translate Manager's SpotRequestInfo into something the elastic clients
+ * understand.
+ *
+ * @param result valid result from Manager
+ * @param caller caller object
+ * @return valid elastic response
+ * @throws Exception problem (will require backout)
+ */
+ public RequestSpotInstancesResponseType translateSpotInfo(SpotRequestInfo result,
+ Caller caller)
+ throws Exception;
+}
@@ -21,7 +21,6 @@
import org.nimbustools.api.repr.CannotTranslateException;
import org.nimbustools.api.repr.CreateResult;
import org.nimbustools.messaging.gt4_0_elastic.generated.v2010_06_15.RunInstancesType;
-import org.nimbustools.messaging.gt4_0_elastic.generated.v2010_06_15.ReservationInfoType;
import org.nimbustools.messaging.gt4_0_elastic.generated.v2010_06_15.RunInstancesResponseType;
import java.rmi.RemoteException;
@@ -25,6 +25,8 @@
import org.nimbustools.api.repr.CreateRequest;
import org.nimbustools.api.repr.CreateResult;
import org.nimbustools.api.repr.ReprFactory;
+import org.nimbustools.api.repr.SpotCreateRequest;
+import org.nimbustools.api.repr.SpotRequestInfo;
import org.nimbustools.api.repr.vm.VM;
import org.nimbustools.api.services.metadata.MetadataServer;
import org.nimbustools.api.services.rm.ManageException;
@@ -62,6 +64,7 @@
protected final Reboot reboot;
protected final Describe describe;
protected final ContainerInterface container;
+ protected final RequestSI reqSI;
// -------------------------------------------------------------------------
@@ -72,6 +75,7 @@ public ServiceRMImpl(Run runImpl,
Terminate terminateImpl,
Reboot rebootImpl,
Describe describeImpl,
+ RequestSI reqSIImpl,
ContainerInterface containerImpl,
ModuleLocator locator) throws Exception {
@@ -94,6 +98,11 @@ public ServiceRMImpl(Run runImpl,
throw new IllegalArgumentException("describeImpl may not be null");
}
this.describe = describeImpl;
+
+ if (reqSIImpl == null) {
+ throw new IllegalArgumentException("reqSIImpl may not be null");
+ }
+ this.reqSI = reqSIImpl;
if (containerImpl == null) {
throw new IllegalArgumentException("containerImpl may not be null");
@@ -208,4 +217,45 @@ public TerminateInstancesResponseType terminateInstances(
final Caller caller = this.container.getCaller();
return this.terminate.terminate(req, caller, this.manager);
}
+
+
+ // -------------------------------------------------------------------------
+ // SI OPERATIONS
+ // -------------------------------------------------------------------------
+
+ public RequestSpotInstancesResponseType requestSpotInstances(
+ RequestSpotInstancesType req)
+ throws RemoteException {
+
+ if (req == null) {
+ throw new RemoteException("requestSpotInstances request is missing");
+ }
+
+ final Caller caller = this.container.getCaller();
+
+ final SpotRequestInfo result;
+ try {
+ SpotCreateRequest creq =
+ this.reqSI.translateReqSpotInstances(req, caller);
+ AddCustomizations.addAll((_CreateRequest)creq,
+ this.repr, this.mdServer);
+ result = this.manager.requestSpotInstances(creq, caller);
+
+ } catch (Exception e) {
+ throw new RemoteException(e.getMessage(), e);
+ }
+
+ try {
+ return this.reqSI.translateSpotInfo(result, caller);
+ } catch (Exception e) {
+ final String err = "Problem translating valid request spot instances " +
+ "result into elastic protocol. Backout required. " +
+ " Error: " + e.getMessage();
+ logger.error(err, e);
+ //this.terminate.backOutCreateResult(result, caller, this.manager);
+ // gets caught by Throwable hook:
+ throw new RuntimeException(err, e);
+ }
+
+ }
}
@@ -338,7 +338,7 @@ protected RunningInstancesItemType getInstanceItemType(VM vm,
final RunningInstancesItemType riit = new RunningInstancesItemType();
riit.setInstanceId(elasticID);
- riit.setImageId(this.getImageID(vm));
+ riit.setImageId(this.getImageID(vm.getVMFiles()));
riit.setInstanceState(this.getState(vm));
riit.setReason(this.getReason(vm));
this.addNICs(vm.getNics(), riit);
@@ -380,6 +380,17 @@ public PlacementResponseType getPlacement() {
return prt;
}
+ public PlacementRequestType getPlacementReq() {
+ final PlacementRequestType prt = new PlacementRequestType();
+ final String[] availabilityZones = this.zones.getAvailabilityZones();
+ if (availabilityZones == null || availabilityZones.length == 0) {
+ prt.setAvailabilityZone("UNKNOWN");
+ } else {
+ prt.setAvailabilityZone(availabilityZones[0]);
+ }
+ return prt;
+ }
+
public Calendar getLaunchTime(VM vm) throws CannotTranslateException {
if (vm == null) {
@@ -471,13 +482,7 @@ private static String recurseForSomeString(Throwable thr) {
}
}
- public String getImageID(VM vm) throws CannotTranslateException {
-
- if (vm == null) {
- throw new CannotTranslateException("vm is missing");
- }
-
- final VMFile[] vmFiles = vm.getVMFiles();
+ public String getImageID(VMFile[] vmFiles) throws CannotTranslateException {
final String UNKNOWN = "UNKNOWN";
Oops, something went wrong.

0 comments on commit a61859c

Please sign in to comment.