public void remove(VMInstance vmi, Deployment target){ if(nbOfReplicats > minReplicats){ if(baseInstances.contains(vmi)){ target.getComponentInstances().onlyVMs().remove(vmi); nbOfReplicats--; }else{ throw new IllegalArgumentException("This VM is not part of the Pool"); } }else{ throw new IllegalStateException("You already reached the minimum number of replicats"); } }
public VMInstanceGroup getVmInstances() { return getDeployment().getComponentInstances().onlyVMs().whichBelongsTo(this); }
private int nbVMFromProvider(Provider p){ int n=0; for(VMInstance v: currentModel.getComponentInstances().onlyVMs()){ if(v.getType().getProvider().equals(p)) n++; } return n; }
/** * To initialise a deployment Model as the model of the current system if * the system is already RUNNING * * @param current the current Deployment model */ public void setCurrentModel(Deployment current) { this.currentModel = current; Connector jc; for (VMInstance vm : currentModel.getComponentInstances().onlyVMs()) { if (vm.getPublicAddress().equals("")) { jc = ConnectorFactory.createIaaSConnector(vm.getType().getProvider()); jc.updateVMMetadata(vm); } } }
for(VMInstance c: d.getComponentInstances().onlyVMs()){ setEnvVar(c,"MODACLOUDS_TOWER4CLOUDS_MANAGER_IP",ip); setEnvVar(c,"MODACLOUDS_TOWER4CLOUDS_MANAGER_PORT",port);
public VMInstanceGroup getInstances() { if (getOwner().isDefined()) { return getDeployment().getComponentInstances().onlyVMs().ofType(this); } else { return new VMInstanceGroup(); } }
/** * Generate the manifest file for each VM from the manifestEntry of each puppet resource and start puppet. */ private void generatePuppetManifestAndConfigure(){ for(VMInstance vmi : currentModel.getComponentInstances().onlyVMs()){ PuppetManifestGenerator pmg = new PuppetManifestGenerator(vmi, currentModel); String path=pmg.generate(); if(path != null){ managePuppet(pmg.getSkeleton(), vmi, vmi.getName(), path); } } }
VMInstanceGroup removedVMs = supportList.onlyVMs();
@Override public void handle(Snapshot command) { if (isDeploymentLoaded()) { dispatch(new Message(command, Category.INFORMATION, "Generating snapshot ...")); VMInstance vmi = deploy.getComponentInstances().onlyVMs().withID(command.getVmId()); Connector c = ConnectorFactory.createIaaSConnector(vmi.getType().getProvider()); c.createSnapshot(vmi); } else { reportNoDeploymentLoaded(command); } }
@Override public void handle(Image command) { if (isDeploymentLoaded()) { dispatch(new Message(command, Category.INFORMATION, "Generating an image ...")); VMInstance vmi = deploy.getComponentInstances().onlyVMs().withID(command.getVmId()); Connector c = ConnectorFactory.createIaaSConnector(vmi.getType().getProvider()); c.createImage(vmi); } else { reportNoDeploymentLoaded(command); } }
public void run() { VMInstance vmi = deploy.getComponentInstances().onlyVMs().withID(id); if (vmi != null) { Provider provider = vmi.getType().getProvider(); Connector c = ConnectorFactory.createIaaSConnector(provider); for(InternalComponentInstance ici : vmi.hostedComponents()){ InternalComponent ic=ici.getType(); for(Resource r : ic.getResources()){ c.execCommand(vmi.getId(),r.getStopCommand(),"ubuntu",vmi.getType().getPrivateKey()); } } c.stopVM(vmi); coordinator.updateStatus(vmi.getName(), ComponentInstance.State.STOPPED, Facade.class.getName()); c.closeConnection(); } } });
public void run() { VMInstance vmi = deploy.getComponentInstances().onlyVMs().withID(id); if (vmi != null) { Provider provider = vmi.getType().getProvider(); Connector c = ConnectorFactory.createIaaSConnector(provider); c.startVM(vmi); coordinator.updateStatus(vmi.getName(), ComponentInstance.State.RUNNING, Facade.class.getName()); for(InternalComponentInstance ici : vmi.hostedComponents()){ InternalComponent ic=ici.getType(); for(Resource r : ic.getResources()){ c.execCommand(vmi.getId(),r.getStartCommand(),"ubuntu",vmi.getType().getPrivateKey()); } } c.closeConnection(); } }}); ts.get(i).start();
private static Model getModelUpdates(ComponentInstanceGroup instances, ProviderGroup providers) { Model model = new Model(); //go top down to remove the synched ones //prepare the VMs list VMInstanceGroup VMs = instances.onlyVMs(); for (VMInstance i : VMs) { String location = i.getType().getLocation(); if(!location.isEmpty()) { model.add(fromCloudmlToModaMP(location)); } model.add(fromCloudmlToModaMP(i)); instances.remove(i); } //prepare the InternalComponents list InternalComponentInstanceGroup internalComponents = instances.onlyInternals(); for (InternalComponentInstance i : internalComponents) { model.add(fromCloudmlToModaMP(i)); instances.remove(i); } //prepare for providers list if(providers!=null){ for (Provider i : providers) { model.add(fromCloudmlToModaMP(i)); instances.remove(i); } } return model; }
@Override public void handle(ScaleOut command) { dispatch(new Message(command, Category.INFORMATION, "Scaling out VM: " + command.getVmId())); VMInstance vmi = deploy.getComponentInstances().onlyVMs().withID(command.getVmId()); if (vmi == null) { dispatch(new Message(command, Category.ERROR, "Cannot find a VM with this ID!")); } else { Boolean success=true; if(command.getNb() > 1) { success=deployer.scaleOut(vmi, command.getNb()); } else { success=deployer.scaleOut(vmi); } /*if(!success){ if (coordinator != null) { coordinator.ack("MaxVMsReached", command.getClass().getName()); } }*/ } }
@Override public void handle(Destroy command) { if (isDeploymentLoaded()) { final VMInstance instance = deploy.getComponentInstances().onlyVMs().firstNamed(command.getInstanceId()); if (instance == null) { final String text = String.format("No VM with ID=\"%s\"", command.getInstanceId()); final Message message = new Message(command, Category.ERROR, text); dispatch(message); } else { Provider p = instance.getType().getProvider(); JCloudsConnector jc = new JCloudsConnector(p.getName(), p.getCredentials().getLogin(), p.getCredentials().getPassword()); jc.destroyVM(instance.getId()); dispatch(new Message(command, Category.INFORMATION, "VM instance terminated")); } } else { reportNoDeploymentLoaded(command); } }
@Override public void handle(Burst command){ dispatch(new Message(command, Category.INFORMATION, "Bursting out External Component: " + command.getEcId()+" to "+ command.getProviderID())); VMInstance vmi = deploy.getComponentInstances().onlyVMs().withID(command.getEcId()); Provider p=deploy.getProviders().firstNamed(command.getProviderID()); if(p == null){ dispatch(new Message(command, Category.ERROR, "Cannot find a Provider with this ID!")); return; } if (vmi == null) { ExternalComponentInstance eci=deploy.getComponentInstances().onlyExternals().firstNamed(command.getEcId()); if(eci == null){ dispatch(new Message(command, Category.ERROR, "Cannot find a External component with this ID!")); }else{ deployer.scaleOut(eci,p); } } else { deployer.scaleOut(vmi,p); } }