@Test public void migrate() { String newImageId = fakeCloudMiddleware.createVmImage(new ImageToUpload("newImage", "fakeUrl")); String idDeployedVm = fakeCloudMiddleware.deploy(new Vm("testVm", newImageId, 1, 1024, 1, null, null), "host1"); fakeCloudMiddleware.migrate(idDeployedVm, "host2"); assertEquals("host2", fakeCloudMiddleware.getVM(idDeployedVm).getHostName()); HostFake oldHost = fakeCloudMiddleware.getHost("host1"); assertTrue(oldHost.getAssignedCpus() == 0); assertTrue(oldHost.getAssignedMemoryMb() == 0); assertTrue(oldHost.getAssignedDiskGb() == 0); HostFake newHost = fakeCloudMiddleware.getHost("host2"); assertTrue(newHost.getAssignedCpus() == 1); assertTrue(newHost.getAssignedMemoryMb() == 1024); assertTrue(newHost.getAssignedDiskGb() == 1); }
@Override public void migrate(String vmId, String destinationNodeHostName) { VmDeployed vmToMigrate = getVmById(vmId); if (vmToMigrate != null) { HostFake oldHost = getHost(vmToMigrate.getHostName()); HostFake newHost = getHost(destinationNodeHostName); if (newHost != null) { vmToMigrate.setHostName(destinationNodeHostName); oldHost.updateAssignedResourcesAfterVmDeleted(vmToMigrate); newHost.updateAssignedResourcesAfterVmDeployed(vmToMigrate); } } }
FakeCloudMiddleware implements CloudMiddleware { @Override public void migrate(String vmId, String destinationNodeHostName) { VmDeployed vmToMigrate = getVmById(vmId); if (vmToMigrate != null) { HostFake oldHost = getHost(vmToMigrate.getHostName()); HostFake newHost = getHost(destinationNodeHostName); if (newHost != null) { vmToMigrate.setHostName(destinationNodeHostName); oldHost.updateAssignedResourcesAfterVmDeleted(vmToMigrate); newHost.updateAssignedResourcesAfterVmDeployed(vmToMigrate); } } } }
FakeCloudMiddleware implements CloudMiddleware { @Override public void migrate(String vmId, String destinationNodeHostName) { VmDeployed vmToMigrate = getVmById(vmId); if (vmToMigrate != null) { HostFake oldHost = getHost(vmToMigrate.getHostName()); HostFake newHost = getHost(destinationNodeHostName); if (newHost != null) { vmToMigrate.setHostName(destinationNodeHostName); oldHost.updateAssignedResourcesAfterVmDeleted(vmToMigrate); newHost.updateAssignedResourcesAfterVmDeployed(vmToMigrate); } } } FakeCloudMiddleware(List<HostFake> hosts); }
FakeCloudMiddleware implements CloudMiddleware { @Override public void migrate(String vmId, String destinationNodeHostName) { VmDeployed vmToMigrate = getVmById(vmId); if (vmToMigrate != null) { HostFake oldHost = getHost(vmToMigrate.getHostName()); HostFake newHost = getHost(destinationNodeHostName); if (newHost != null) { vmToMigrate.setHostName(destinationNodeHostName); oldHost.updateAssignedResourcesAfterVmDeleted(vmToMigrate); newHost.updateAssignedResourcesAfterVmDeployed(vmToMigrate); } } } FakeCloudMiddleware(List<HostFake> hosts); @Override String deploy(Vm vm, String hostname); @Override String deployWithVolume(Vm vm, String hostname, String isoPath); @Override void destroy(String vmId); @Override void migrate(String vmId, String destinationNodeHostName); @Override List<String> getAllVMsIds(); @Override List<String> getScheduledNonDeployedVmsIds(); @Override VmDeployed getVM(String vmId); @Override boolean existsVm(String vmId); @Override void rebootHardVm(String vmId); @Override void rebootSoftVm(String vmId); @Override void startVm(String vmId); @Override void stopVm(String vmId); @Override void suspendVm(String vmId); @Override void resumeVm(String vmId); @Override List<ImageUploaded> getVmImages(); @Override String createVmImage(ImageToUpload imageToUpload); @Override ImageUploaded getVmImage(String imageId); @Override void deleteVmImage(String id); @Override void assignFloatingIp(String vmId); void deleteAllVmImages(); HostFake getHost(String hostname); void addHost(HostFake host); }
FakeCloudMiddleware implements CloudMiddleware { @Override public void migrate(String vmId, String destinationNodeHostName) { VmDeployed vmToMigrate = getVmById(vmId); if (vmToMigrate != null) { HostFake oldHost = getHost(vmToMigrate.getHostName()); HostFake newHost = getHost(destinationNodeHostName); if (newHost != null) { vmToMigrate.setHostName(destinationNodeHostName); oldHost.updateAssignedResourcesAfterVmDeleted(vmToMigrate); newHost.updateAssignedResourcesAfterVmDeployed(vmToMigrate); } } } FakeCloudMiddleware(List<HostFake> hosts); @Override String deploy(Vm vm, String hostname); @Override String deployWithVolume(Vm vm, String hostname, String isoPath); @Override void destroy(String vmId); @Override void migrate(String vmId, String destinationNodeHostName); @Override List<String> getAllVMsIds(); @Override List<String> getScheduledNonDeployedVmsIds(); @Override VmDeployed getVM(String vmId); @Override boolean existsVm(String vmId); @Override void rebootHardVm(String vmId); @Override void rebootSoftVm(String vmId); @Override void startVm(String vmId); @Override void stopVm(String vmId); @Override void suspendVm(String vmId); @Override void resumeVm(String vmId); @Override List<ImageUploaded> getVmImages(); @Override String createVmImage(ImageToUpload imageToUpload); @Override ImageUploaded getVmImage(String imageId); @Override void deleteVmImage(String id); @Override void assignFloatingIp(String vmId); void deleteAllVmImages(); HostFake getHost(String hostname); void addHost(HostFake host);  }