Permalink
Browse files

add provider specific type as a new runtime information

  • Loading branch information...
nicolasferry committed Aug 12, 2015
1 parent c96ea55 commit 682085bbe04fe3ecaba3b04226fed2056788f7cd
@@ -28,6 +28,7 @@
import com.google.inject.Module;
import org.apache.commons.io.FileUtils;
import org.cloudml.core.ComponentInstance;
import org.cloudml.core.Property;
import org.cloudml.core.VM;
import org.cloudml.core.VMInstance;
import org.jclouds.ContextBuilder;
@@ -199,7 +200,7 @@ private String readSshKey(String keyPath){
org.jclouds.cloudsigma2.domain.ServerInfo serverToCreate = new org.jclouds.cloudsigma2.domain.ServerInfo.Builder()
.name(a.getName())
.memory(BigInteger.valueOf(vm.getMinRam()).multiply(BigInteger.valueOf(1024*1024)))
.memory(BigInteger.valueOf(vm.getMinRam()).multiply(BigInteger.valueOf(1024 * 1024)))
.vncPassword("cloudml")
.cpu(vm.getMinCores() * 2600)
.nics(ImmutableList.of(nic))
@@ -240,7 +241,6 @@ private String readSshKey(String keyPath){
}
}
runtimeInformation.put("status", state);
return runtimeInformation;
}
@@ -188,18 +188,18 @@ public FlexiantConnector(String endPoint, String login, String secretKey) throws
template.getDisks().add(d);
//TODO: Add disk
Job job=service.createServer(template, sshKeyList, null);
service.waitForJob(job.getResourceUUID(), false);
a.getProperties().add(new Property("ProviderInstanceType",template.getProductOfferName()));
a.getProperties().add(new Property("ProviderSpecificInstanceType", findProductName(((double) vm.getMinRam()), vm.getMinCores())));
a.setProviderSpecificType(findProductName(((double) vm.getMinRam()), vm.getMinCores()));
a.setId(findResourceByName(a.getName(), ResourceType.SERVER));
/*Job nicJob=service.createNetworkInterface(n, null);
service.waitForJob(nicJob.getResourceUUID(), false);
service.attachNetworkInterface(job.getItemUUID(), nicJob.getItemUUID(), 0, null);*/
journal.log(Level.INFO, ">> vm type: "+ template.getProductOfferName() + " named " + template.getResourceName());
journal.log(Level.INFO, ">> vm type: "+ findProductName(((double) vm.getMinRam()), vm.getMinCores()) + " named " + template.getResourceName());
Job startJob=service.changeServerStatus(a.getId(), ServerStatus.RUNNING, true, null, null);
service.waitForJob(startJob.getResourceUUID(), false);
@@ -357,6 +357,58 @@ public Object findObjectResourceByID(String id, ResourceType t){
}
}
public String findProductName(double ram, int CPU){
try {
// Create an FQL filter and a filter condition
SearchFilter sf = new SearchFilter();
FilterCondition fc = new FilterCondition();
// the field to be matched
fc.setField("ResourceName");
// set the condition type
fc.setCondition(Condition.CONTAINS);
// Add the filter condition to the query
sf.getFilterConditions().add(fc);
// and a list of values
fc.getValue().add(CPU+" CPU");
// Set a limit to the number of results
QueryLimit lim = new QueryLimit();
lim.setMaxRecords(50);
// Call the service to execute the query
ListResult result = service.listResources(sf,lim, ResourceType.PRODUCTOFFER);
if(result.getList().size() > 0){
ProductOffer p=(ProductOffer)result.getList().get(0);
Double min=5000.0;
for(Object o : result.getList()) {
ProductOffer s = ((ProductOffer)o);
for(ProductComponent t : s.getComponentConfig()){
for(Value v: t.getProductConfiguredValues()){
if(v.getKey().equals("ram")){
double productRam=Double.parseDouble(v.getValue()); //RAM value
if(productRam >= ram && productRam <= min){
min=productRam;
p=s;
}
}
}
}
}
return p.getResourceName();
}
return "";
} catch (Exception e) {
journal.log(Level.SEVERE, e.getMessage());
return "";
}
}
public String findProduct(double ram, int CPU){
try {
// Create an FQL filter and a filter condition
@@ -309,7 +309,8 @@ public void updateVMMetadata(VMInstance a){
template = templateBuilder.build();
journal.log(Level.INFO, ">> vm type: "+template.getHardware().getId()+" on location: "+template.getLocation().getId());
a.getProperties().add(new Property("ProviderInstanceType", template.getHardware().getId()));
a.getProperties().add(new Property("ProviderSpecificInstanceType", template.getHardware().getId()));
a.setProviderSpecificType(template.getHardware().getId());
a.getProperties().add(new Property("location", template.getLocation().getId()));
if(provider.equals("aws-ec2")){
@@ -436,7 +436,8 @@ public Image checkIfImageExist(String name){
a.setCore((int)nodeInstance.getHardware().getProcessors().iterator().next().getCores());
a.setId(nodeInstance.getId());
a.getProperties().add(new Property("ProviderSpecificType", nodeInstance.getHardware().getId()));
a.setProviderSpecificType(template.getHardware().getId());
state = ComponentInstance.State.RUNNING;
}
runtimeInformation.put("status",state);
@@ -32,6 +32,16 @@
public int core=0;
public String getProviderSpecificType() {
return providerSpecificType;
}
public void setProviderSpecificType(String providerSpecificType) {
this.providerSpecificType = providerSpecificType;
}
private String providerSpecificType="";
public VMInstance(VM type) {
this(NamedElement.DEFAULT_NAME, type);
}

0 comments on commit 682085b

Please sign in to comment.