Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

support to EC2 requestSpotInstances

  • Loading branch information...
commit a61859c0b582a97291f41b1de0e77f79bcfef771 1 parent a666110
@pauloricardomg pauloricardomg authored
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 messaging/gt4.0-elastic/java/msgbridge/src/org/nimbustools/messaging/gt4_0_elastic/v2008_05_05/ServiceRM.java
  4. +4 −1 ...tic/java/msgbridge/src/org/nimbustools/messaging/gt4_0_elastic/v2008_05_05/general/ResourceAllocations.java
  5. +22 −3 ...ge/src/org/nimbustools/messaging/gt4_0_elastic/v2008_05_05/general/defaults/DefaultResourceAllocations.java
  6. +5 −1 ...aging/gt4.0-elastic/java/msgbridge/src/org/nimbustools/messaging/gt4_0_elastic/v2008_05_05/rm/Describe.java
  7. +56 −0 ...ging/gt4.0-elastic/java/msgbridge/src/org/nimbustools/messaging/gt4_0_elastic/v2008_05_05/rm/RequestSI.java
  8. +0 −1  messaging/gt4.0-elastic/java/msgbridge/src/org/nimbustools/messaging/gt4_0_elastic/v2008_05_05/rm/Run.java
  9. +50 −0 .../gt4.0-elastic/java/msgbridge/src/org/nimbustools/messaging/gt4_0_elastic/v2008_05_05/rm/ServiceRMImpl.java
  10. +13 −8 ...tic/java/msgbridge/src/org/nimbustools/messaging/gt4_0_elastic/v2008_05_05/rm/defaults/DefaultDescribe.java
  11. +289 −0 ...ic/java/msgbridge/src/org/nimbustools/messaging/gt4_0_elastic/v2008_05_05/rm/defaults/DefaultRequestSI.java
  12. +3 −2 ...-elastic/java/msgbridge/src/org/nimbustools/messaging/gt4_0_elastic/v2008_05_05/rm/defaults/DefaultRun.java
  13. +16 −1 ...java/msgbridge/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
View
11 messaging/gt4.0-elastic/java/msgbridge/etc/elastic/other/main.conflocator.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>
View
16 messaging/gt4.0-elastic/java/msgbridge/etc/elastic/other/main.xml
@@ -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>
View
16 ...tic/java/msgbridge/src/org/nimbustools/messaging/gt4_0_elastic/v2008_05_05/ServiceRM.java
@@ -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;
}
View
5 .../src/org/nimbustools/messaging/gt4_0_elastic/v2008_05_05/general/ResourceAllocations.java
@@ -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();
}
View
25 ...ools/messaging/gt4_0_elastic/v2008_05_05/general/defaults/DefaultResourceAllocations.java
@@ -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;
View
6 ...c/java/msgbridge/src/org/nimbustools/messaging/gt4_0_elastic/v2008_05_05/rm/Describe.java
@@ -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;
}
View
56 .../java/msgbridge/src/org/nimbustools/messaging/gt4_0_elastic/v2008_05_05/rm/RequestSI.java
@@ -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;
+}
View
1  ...lastic/java/msgbridge/src/org/nimbustools/messaging/gt4_0_elastic/v2008_05_05/rm/Run.java
@@ -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;
View
50 ...a/msgbridge/src/org/nimbustools/messaging/gt4_0_elastic/v2008_05_05/rm/ServiceRMImpl.java
@@ -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);
+ }
+
+ }
}
View
21 .../src/org/nimbustools/messaging/gt4_0_elastic/v2008_05_05/rm/defaults/DefaultDescribe.java
@@ -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";
View
289 ...src/org/nimbustools/messaging/gt4_0_elastic/v2008_05_05/rm/defaults/DefaultRequestSI.java
@@ -0,0 +1,289 @@
+/*
+ * 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.defaults;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.globus.util.Base64;
+import org.nimbustools.api._repr._CustomizationRequest;
+import org.nimbustools.api._repr._SpotCreateRequest;
+import org.nimbustools.api.brain.ModuleLocator;
+import org.nimbustools.api.repr.Caller;
+import org.nimbustools.api.repr.CannotTranslateException;
+import org.nimbustools.api.repr.CreateRequest;
+import org.nimbustools.api.repr.CustomizationRequest;
+import org.nimbustools.api.repr.SpotCreateRequest;
+import org.nimbustools.api.repr.SpotRequestInfo;
+import org.nimbustools.api.repr.vm.NIC;
+import org.nimbustools.api.repr.vm.RequiredVMM;
+import org.nimbustools.api.repr.vm.ResourceAllocation;
+import org.nimbustools.api.repr.vm.State;
+import org.nimbustools.api.repr.vm.VMFile;
+import org.nimbustools.messaging.gt4_0_elastic.generated.v2010_06_15.*;
+import org.nimbustools.messaging.gt4_0_elastic.v2008_05_05.general.Networks;
+import org.nimbustools.messaging.gt4_0_elastic.v2008_05_05.general.ResourceAllocations;
+import org.nimbustools.messaging.gt4_0_elastic.v2008_05_05.image.Repository;
+import org.nimbustools.messaging.gt4_0_elastic.v2008_05_05.rm.ContainerInterface;
+import org.nimbustools.messaging.gt4_0_elastic.v2008_05_05.rm.Describe;
+import org.nimbustools.messaging.gt4_0_elastic.v2008_05_05.rm.IDMappings;
+import org.nimbustools.messaging.gt4_0_elastic.v2008_05_05.rm.RequestSI;
+import org.nimbustools.messaging.gt4_0_elastic.v2008_05_05.security.SSHKey;
+import org.nimbustools.messaging.gt4_0_elastic.v2008_05_05.security.SSHKeys;
+
+import java.rmi.RemoteException;
+
+public class DefaultRequestSI extends DefaultRun implements RequestSI {
+
+ // -------------------------------------------------------------------------
+ // STATIC VARIABLES
+ // -------------------------------------------------------------------------
+
+ private static final Log logger =
+ LogFactory.getLog(DefaultRequestSI.class.getName());
+ protected static final String PERSISTENT = "persistent";
+ protected static final String ONE_TIME = "one-time";
+
+ // -------------------------------------------------------------------------
+ // CONSTRUCTORS
+ // -------------------------------------------------------------------------
+
+ public DefaultRequestSI(ResourceAllocations rasImpl,
+ Networks networksImpl,
+ Repository repoImpl,
+ IDMappings idsImpl,
+ Describe describeImpl,
+ ContainerInterface containerImpl,
+ SSHKeys sshKeysImpl,
+ ModuleLocator locator) throws Exception {
+
+ super(rasImpl, networksImpl, repoImpl, idsImpl, describeImpl, containerImpl, locator);
+ }
+
+ public DefaultRequestSI(ResourceAllocations rasImpl,
+ Networks networksImpl,
+ Repository repoImpl,
+ IDMappings idsImpl,
+ Describe describeImpl,
+ ContainerInterface containerImpl,
+ ModuleLocator locator) throws Exception {
+ this(rasImpl, networksImpl, repoImpl,
+ idsImpl, describeImpl, containerImpl, null, locator);
+ }
+
+ // -------------------------------------------------------------------------
+ // implements Run
+ // -------------------------------------------------------------------------
+
+ public SpotCreateRequest translateReqSpotInstances(
+ RequestSpotInstancesType req, Caller caller)
+ throws RemoteException, CannotTranslateException {
+
+ final String ownerID;
+ try {
+ ownerID = this.container.getOwnerID(caller);
+ } catch (CannotTranslateException e) {
+ throw new RemoteException(e.getMessage(), e);
+ }
+
+ LaunchSpecificationRequestType launchSpec = req.getLaunchSpecification();
+
+ final String imageID = launchSpec.getImageId();
+ if (imageID == null) {
+ throw new RemoteException("Request is missing image ID");
+ }
+
+ // currently ignored: groupSet, placement, kernel, ramdiskid,
+ // blockDeviceMapping
+
+ final _CustomizationRequest cust;
+ final String keyname = launchSpec.getKeyName();
+ if (keyname != null && this.sshKeys != null) {
+ cust = this.repr._newCustomizationRequest();
+ final SSHKey key = this.sshKeys.findKey(ownerID, keyname);
+ if (key == null) {
+ throw new RemoteException("There is no key '" + keyname +
+ "' registered for you to use");
+ }
+ cust.setContent(key.getPubKeyValue());
+ cust.setPathOnVM("/root/.ssh/authorized_keys");
+ } else {
+ cust = null;
+ }
+
+ final CustomizationRequest[] custRequests;
+ if (cust != null) {
+ custRequests = new CustomizationRequest[1];
+ custRequests[0] = cust;
+ } else {
+ custRequests = null;
+ }
+
+ final NIC[] nics = this.getNICs();
+ final String raType = launchSpec.getInstanceType();
+ final ResourceAllocation ra = this.RAs.getMatchingRA(raType,
+ req.getInstanceCount().intValue(),
+ req.getInstanceCount().intValue(),
+ true);
+
+ final RequiredVMM reqVMM = this.RAs.getRequiredVMM();
+
+ String userData = null;
+ final UserDataType t_userData = launchSpec.getUserData();
+ if (t_userData != null) {
+ final String base64Encoded = t_userData.getData();
+ if (base64Encoded != null) {
+ if (!Base64.isBase64(base64Encoded)) {
+ throw new RemoteException("userdata does not appear to " +
+ "be base64 encoded?");
+ }
+ final byte[] bytes = Base64.decode(base64Encoded.getBytes());
+ userData = new String(bytes);
+ }
+ }
+
+ final VMFile[] files =
+ this.repository.constructFileRequest(imageID, ra, caller);
+
+ final Double spotPrice;
+ try{
+ spotPrice = new Double(req.getSpotPrice());
+ } catch (NumberFormatException e){
+ throw new RemoteException("Error in spot price conversion.");
+ }
+
+ boolean persistent = PERSISTENT.equals(req.getType());
+
+ final _SpotCreateRequest screq = this.repr._newSpotCreateRequest();
+
+ screq.setContext(null);
+ screq.setCoScheduleDone(false);
+ screq.setCoScheduleID(null);
+ screq.setCoScheduleMember(false);
+ screq.setCustomizationRequests(custRequests);
+ screq.setInitialStateRequest(State.STATE_Running);
+ screq.setName(imageID);
+ screq.setRequestedKernel(null); // todo
+ screq.setRequestedNics(nics);
+ screq.setRequestedRA(ra);
+ screq.setRequestedSchedule(null); // ask for default
+ screq.setRequiredVMM(reqVMM);
+ screq.setShutdownType(CreateRequest.SHUTDOWN_TYPE_TRASH);
+ screq.setVMFiles(files);
+ screq.setMdUserData(userData);
+ screq.setSshKeyName(keyname);
+
+ screq.setPersistent(persistent);
+ screq.setSpotPrice(spotPrice);
+
+ return screq;
+
+ }
+
+
+ // -------------------------------------------------------------------------
+ // RESULT
+ // -------------------------------------------------------------------------
+
+ public RequestSpotInstancesResponseType translateSpotInfo(
+ SpotRequestInfo result, Caller caller) throws Exception {
+
+ if (result == null) {
+ throw new CannotTranslateException("spot request info is missing");
+ }
+
+ Integer instanceCount = result.getInstanceCount();
+ if (instanceCount == null || instanceCount == 0) {
+ throw new CannotTranslateException("instance count is empty?");
+ }
+
+ final String groupid = result.getGroupID();
+
+ if (groupid == null && instanceCount != 1) {
+ throw new CannotTranslateException("expecting a groupID if " +
+ "more than one VM was created");
+ }
+
+ String vmidWhenJustOne = null;
+ String resID = null;
+ if (groupid == null && result.getVMIds().length == 1) {
+ vmidWhenJustOne = result.getVMIds()[0];
+ resID = this.ids.newGrouplessInstanceID(vmidWhenJustOne,
+ result.getSshKeyName());
+ logger.info("New reservation ID '" + resID + "' for Single VM '" +
+ vmidWhenJustOne +"'.");
+ } else if (groupid != null && result.getVMIds().length > 0) {
+ vmidWhenJustOne = null;
+ resID = this.ids.newGroupReservationID(groupid);
+ logger.info("New reservation ID '" + resID + "' for VM group '" +
+ groupid +"'.");
+ }
+
+ String instID = null;
+ if (vmidWhenJustOne != null) {
+ // mapping already created:
+ instID = this.ids.managerInstanceToElasticInstance(vmidWhenJustOne);
+ logger.info("id-" + vmidWhenJustOne + "='" + instID + "'.");
+ } else if(resID != null){
+ String vmId = result.getVMIds()[0];
+ instID = this.ids.newInstanceID(vmId, resID, result.getSshKeyName());
+ logger.info("id-" + vmId + "='" + instID + "'.");
+ }
+
+ LaunchSpecificationResponseType launchSpec = getLaunchSpec(result);
+ String type = result.isPersistent()? PERSISTENT : ONE_TIME;
+
+ SpotInstanceRequestSetItemType sirsi = new SpotInstanceRequestSetItemType();
+
+ sirsi.setLaunchSpecification(launchSpec);
+ sirsi.setType(type);
+ sirsi.setSpotPrice(result.getSpotPrice().toString());
+ sirsi.setSpotInstanceRequestId(result.getRequestID());
+ sirsi.setState(result.getState().getStateStr());
+ sirsi.setCreateTime(result.getCreationTime());
+ if(instID != null){
+ sirsi.setInstanceId(instID);
+ }
+
+ SpotInstanceRequestSetType sirs = new SpotInstanceRequestSetType();
+ sirs.setItem(0, sirsi);
+
+ final RequestSpotInstancesResponseType rsirt = new RequestSpotInstancesResponseType();
+ rsirt.setSpotInstanceRequestSet(sirs);
+
+ return rsirt;
+ }
+
+ protected LaunchSpecificationResponseType getLaunchSpec(SpotRequestInfo reqInfo)
+ throws CannotTranslateException {
+
+ if (reqInfo == null) {
+ throw new IllegalArgumentException("instID may not be null");
+ }
+
+ LaunchSpecificationResponseType launchSpec = new LaunchSpecificationResponseType();
+
+ launchSpec.setGroupSet(this.getGroupStub());
+ launchSpec.setPlacement(this.describe.getPlacementReq());
+ launchSpec.setImageId(this.describe.getImageID(reqInfo.getVMFiles()));
+ launchSpec.setInstanceType(this.RAs.getSpotInstanceType());
+ launchSpec.setKeyName(reqInfo.getSshKeyName());
+ launchSpec.setKernelId("default"); // todo
+
+ return launchSpec;
+ }
+
+}
View
5 ...ridge/src/org/nimbustools/messaging/gt4_0_elastic/v2008_05_05/rm/defaults/DefaultRun.java
@@ -184,7 +184,8 @@ public CreateRequest translateRunInstances(RunInstancesType req,
final String raType = req.getInstanceType();
final ResourceAllocation ra = this.RAs.getMatchingRA(raType,
req.getMinCount(),
- req.getMaxCount());
+ req.getMaxCount(),
+ false);
final RequiredVMM reqVMM = this.RAs.getRequiredVMM();
@@ -393,7 +394,7 @@ protected RunningInstancesItemType getOneCreatedVM(VM vm,
riit.setInstanceState(this.describe.getState(vm));
riit.setReason(this.describe.getReason(vm));
riit.setPlacement(this.describe.getPlacement());
- riit.setImageId(this.describe.getImageID(vm));
+ riit.setImageId(this.describe.getImageID(vm.getVMFiles()));
riit.setInstanceType(this.describe.getInstanceType(vm));
riit.setLaunchTime(this.describe.getLaunchTime(vm));
View
17 .../org/nimbustools/messaging/gt4_0_elastic/v2008_05_05/service/UnimplementedOperations.java
@@ -54,7 +54,22 @@ public DescribeInstancesResponseType describeInstances(
throw new RemoteException(UNIMPLEMENTED + "describeInstances");
}
-
+ // -------------------------------------------------------------------------
+ // SI OPERATIONS
+ // -------------------------------------------------------------------------
+
+ public RequestSpotInstancesResponseType requestSpotInstances(
+ RequestSpotInstancesType requestSpotInstancesMsg)
+ throws RemoteException {
+ throw new RemoteException(UNIMPLEMENTED + "requestSpotInstances");
+ }
+
+ public CancelSpotInstanceRequestsResponseType cancelSpotInstanceRequests(
+ CancelSpotInstanceRequestsType cancelSpotInstancesMsg)
+ throws RemoteException {
+ throw new RemoteException(UNIMPLEMENTED + "cancelSpotInstanceRequests");
+ }
+
// -------------------------------------------------------------------------
// IMAGE RELATED
// -------------------------------------------------------------------------
View
8 messaging/query/java/source/etc/query/other/main.conflocator.xml
@@ -57,4 +57,12 @@
<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>
View
17 messaging/query/java/source/etc/query/other/main.xml
@@ -107,6 +107,7 @@ http://cxf.apache.org/schemas/jaxrs.xsd">
<constructor-arg ref="nimbus-query.rm.terminate" />
<constructor-arg ref="nimbus-query.rm.reboot" />
<constructor-arg ref="nimbus-query.rm.describe" />
+ <constructor-arg ref="nimbus-query.rm.requestSI" />
<constructor-arg ref="nimbus-query.rm.containerInterface" />
<constructor-arg ref="nimbus-query.rm.modulelocator" />
@@ -126,6 +127,21 @@ http://cxf.apache.org/schemas/jaxrs.xsd">
</bean>
+ <bean id="nimbus-query.rm.requestSI"
+ class="org.nimbustools.messaging.gt4_0_elastic.v2008_05_05.rm.defaults.DefaultRequestSI">
+
+ <constructor-arg ref="nimbus-query.general.ra" />
+ <constructor-arg ref="nimbus-query.general.networks" />
+ <constructor-arg ref="nimbus-query.rm.idmappings" />
+ <constructor-arg ref="nimbus-query.rm.describe" />
+ <constructor-arg ref="nimbus-query.rm.containerInterface" />
+ <constructor-arg ref="nimbus-query.security.sshkeys" />
+ <constructor-arg ref="nimbus-query.image.repository" />
+ <constructor-arg ref="nimbus-query.rm.modulelocator" />
+
+ </bean>
+
+
<bean id="nimbus-query.rm.terminate"
class="org.nimbustools.messaging.gt4_0_elastic.v2008_05_05.rm.defaults.DefaultTerminate">
@@ -192,6 +208,7 @@ http://cxf.apache.org/schemas/jaxrs.xsd">
<property name="largeName" value="$OTHER_ELASTIC{ra.name.large}" />
<property name="xlargeName" value="$OTHER_ELASTIC{ra.name.xlarge}" />
<property name="unknownString" value="$OTHER_ELASTIC{ra.name.unknown}" />
+ <property name="siType" value="$SI{si.instancetype}" />
<property name="cpuArch" value="$OTHER_ELASTIC{cpu.arch}" />
<property name="vmmType" value="$OTHER_ELASTIC{vmm.type}" />
Please sign in to comment.
Something went wrong with that request. Please try again.