public VMInstanceGroup whichBelongsTo(Cloud cloud) { final VMInstanceGroup selection = new VMInstanceGroup(); for (final VMInstance vm: this) { if (vm.belongsTo(cloud)) { selection.add(vm); } } return selection; }
public boolean hasAnyInstance() { return !getInstances().isEmpty(); }
public VMInstanceGroup getInstances() { if (getOwner().isDefined()) { return getDeployment().getComponentInstances().onlyVMs().ofType(this); } else { return new VMInstanceGroup(); } }
@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); } }
public VMInstanceGroup ofType(String typeName) { final ArrayList<VMInstance> selectedInstances = new ArrayList<VMInstance>(); for (VMInstance nodeInstance : this) { if (nodeInstance.getType().getName().equals(typeName)) { selectedInstances.add(nodeInstance); } } return new VMInstanceGroup(selectedInstances); }
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); }
@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(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 VMInstanceGroup ofType(VM vm) { final ArrayList<VMInstance> selectedInstances = new ArrayList<VMInstance>(); for (VMInstance instance : this) { if (instance.getType().equals(vm)) { selectedInstances.add(instance); } } return new VMInstanceGroup(selectedInstances); }
public VMInstanceGroup onlyVMs() { final VMInstanceGroup selected = new VMInstanceGroup(); for (ExternalComponentInstance<? extends ExternalComponent> instance: this) { if (instance.isVM()) { selected.add(instance.asVM()); } } return selected; }
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 VMInstanceGroup onlyVMs() { final VMInstanceGroup selection = new VMInstanceGroup(); for (final T instance: this) { if (instance.isExternal()) { final ExternalComponentInstance<? extends ExternalComponent> external = instance.asExternal(); if (external.isVM()) { selection.add(external.asVM()); } } } return selection; }
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();
@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(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); } }