Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion api/src/main/java/com/cloud/hypervisor/HypervisorGuru.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.List;
import java.util.Map;

import com.cloud.storage.StoragePool;
import org.apache.cloudstack.framework.config.ConfigKey;

import com.cloud.agent.api.Command;
Expand All @@ -32,7 +33,7 @@
import com.cloud.vm.VirtualMachineProfile;

public interface HypervisorGuru extends Adapter {
static final ConfigKey<Boolean> VmwareFullClone = new ConfigKey<Boolean>("Advanced", Boolean.class, "vmware.create.full.clone", "true",
ConfigKey<Boolean> VmwareFullClone = new ConfigKey<Boolean>("Advanced", Boolean.class, "vmware.create.full.clone", "true",
"If set to true, creates guest VMs as full clones on ESX", false);
HypervisorType getHypervisorType();

Expand Down Expand Up @@ -84,4 +85,13 @@ public interface HypervisorGuru extends Adapter {
List<Command> finalizeExpungeVolumes(VirtualMachine vm);

Map<String, String> getClusterSettings(long vmId);

/**
* Will generate commands to migrate a vm to a pool. For now this will only work for stopped VMs on Vmware.
*
* @param vm the stopped vm to migrate
* @param destination the primary storage pool to migrate to
* @return a list of commands to perform for a successful migration
*/
List<Command> finalizeMigrate(VirtualMachine vm, StoragePool destination);
}
10 changes: 10 additions & 0 deletions api/src/main/java/com/cloud/storage/VolumeApiService.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,21 @@
import org.apache.cloudstack.api.command.user.volume.ResizeVolumeCmd;
import org.apache.cloudstack.api.command.user.volume.UploadVolumeCmd;
import org.apache.cloudstack.api.response.GetUploadParamsResponse;
import org.apache.cloudstack.framework.config.ConfigKey;

import com.cloud.exception.ResourceAllocationException;
import com.cloud.user.Account;

public interface VolumeApiService {

ConfigKey<Long> ConcurrentMigrationsThresholdPerDatastore = new ConfigKey<Long>("Advanced"
, Long.class
, "concurrent.migrations.per.target.datastore"
, "0"
, "Limits number of migrations that can be handled per datastore concurrently; default is 0 - unlimited"
, true // not sure if this is to be dynamic
, ConfigKey.Scope.Global);

/**
* Creates the database object for a volume based on the given criteria
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public abstract class BaseAsyncCmd extends BaseCmd {
public static final String ipAddressSyncObject = "ipaddress";
public static final String networkSyncObject = "network";
public static final String vpcSyncObject = "vpc";
public static final String migrationSyncObject = "migration";
public static final String snapshotHostSyncObject = "snapshothost";
public static final String gslbSyncObject = "globalserverloadbalancer";
private static final Logger s_logger = Logger.getLogger(BaseAsyncCmd.class.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
import com.cloud.vm.VirtualMachine;

@APICommand(name = "migrateVirtualMachine",
description = "Attempts Migration of a VM to a different host or Root volume of the vm to a different storage pool",
description = "Attempts Migration of a VM to a different host or Root volume of the vm to a different storage pool",
responseObject = UserVmResponse.class, entityType = {VirtualMachine.class},
requestHasSensitiveInfo = false,
responseHasSensitiveInfo = true)
requestHasSensitiveInfo = false,
responseHasSensitiveInfo = true)
public class MigrateVMCmd extends BaseAsyncCmd {
public static final Logger s_logger = Logger.getLogger(MigrateVMCmd.class.getName());

Expand All @@ -57,24 +57,24 @@ public class MigrateVMCmd extends BaseAsyncCmd {
/////////////////////////////////////////////////////

@Parameter(name = ApiConstants.HOST_ID,
type = CommandType.UUID,
entityType = HostResponse.class,
required = false,
description = "Destination Host ID to migrate VM to. Required for live migrating a VM from host to host")
type = CommandType.UUID,
entityType = HostResponse.class,
required = false,
description = "Destination Host ID to migrate VM to. Required for live migrating a VM from host to host")
private Long hostId;

@Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID,
type = CommandType.UUID,
entityType = UserVmResponse.class,
required = true,
description = "the ID of the virtual machine")
type = CommandType.UUID,
entityType = UserVmResponse.class,
required = true,
description = "the ID of the virtual machine")
private Long virtualMachineId;

@Parameter(name = ApiConstants.STORAGE_ID,
type = CommandType.UUID,
entityType = StoragePoolResponse.class,
required = false,
description = "Destination storage pool ID to migrate VM volumes to. Required for migrating the root disk volume")
type = CommandType.UUID,
entityType = StoragePoolResponse.class,
required = false,
description = "Destination storage pool ID to migrate VM volumes to. Required for migrating the root disk volume")
private Long storageId;

/////////////////////////////////////////////////////
Expand Down Expand Up @@ -119,13 +119,15 @@ public String getEventType() {

@Override
public String getEventDescription() {
String eventDescription;
if (getHostId() != null) {
return "Attempting to migrate VM Id: " + this._uuidMgr.getUuid(VirtualMachine.class, getVirtualMachineId()) + " to host Id: " + this._uuidMgr.getUuid(Host.class, getHostId());
eventDescription = String.format("Attempting to migrate VM id: %s to host Id: %s", getVirtualMachineId(), getHostId());
} else if (getStoragePoolId() != null) {
return "Attempting to migrate VM Id: " + this._uuidMgr.getUuid(VirtualMachine.class, getVirtualMachineId()) + " to storage pool Id: " + this._uuidMgr.getUuid(StoragePool.class, getStoragePoolId());
eventDescription = String.format("Attempting to migrate VM id: %s to storage pool Id: %s", getVirtualMachineId(), getStoragePoolId());
} else {
return "Attempting to migrate VM Id: " + this._uuidMgr.getUuid(VirtualMachine.class, getVirtualMachineId());
eventDescription = String.format("Attempting to migrate VM id: %s", getVirtualMachineId());
}
return eventDescription;
}

@Override
Expand All @@ -152,16 +154,17 @@ public void execute() {
if (destinationHost.getType() != Host.Type.Routing) {
throw new InvalidParameterValueException("The specified host(" + destinationHost.getName() + ") is not suitable to migrate the VM, please specify another one");
}
CallContext.current().setEventDetails("VM Id: " + this._uuidMgr.getUuid(VirtualMachine.class, getVirtualMachineId()) + ((getHostId() != null) ? " to host Id: " + this._uuidMgr.getUuid(Host.class, getHostId()) : "" ));
CallContext.current().setEventDetails("VM Id: " + getVirtualMachineId() + " to host Id: " + getHostId());
}

// OfflineMigration performed when this parameter is specified
StoragePool destStoragePool = null;
if (getStoragePoolId() != null) {
destStoragePool = _storageService.getStoragePool(getStoragePoolId());
if (destStoragePool == null) {
throw new InvalidParameterValueException("Unable to find the storage pool to migrate the VM");
}
CallContext.current().setEventDetails("VM Id: " + this._uuidMgr.getUuid(VirtualMachine.class, getVirtualMachineId()) + " to storage pool Id: " + this._uuidMgr.getUuid(StoragePool.class, getStoragePoolId()));
CallContext.current().setEventDetails("VM Id: " + getVirtualMachineId() + " to storage pool Id: " + getStoragePoolId());
}

try {
Expand All @@ -172,7 +175,7 @@ public void execute() {
migratedVm = _userVmService.vmStorageMigration(getVirtualMachineId(), destStoragePool);
}
if (migratedVm != null) {
UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", (UserVm)migratedVm).get(0);
UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", (UserVm) migratedVm).get(0);
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
Expand All @@ -181,15 +184,27 @@ public void execute() {
} catch (ResourceUnavailableException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
} catch (ConcurrentOperationException e) {
s_logger.warn("Exception: ", e);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
} catch (ManagementServerException e) {
s_logger.warn("Exception: ", e);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
} catch (VirtualMachineMigrationException e) {
} catch (VirtualMachineMigrationException | ConcurrentOperationException | ManagementServerException e) {
s_logger.warn("Exception: ", e);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
}
}

@Override
public String getSyncObjType() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you need to implemente these getSyncObjType and getSyncObjId? Could you explain this a little bit further?

Copy link
Contributor Author

@DaanHoogland DaanHoogland Nov 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i can, but it will be not a little bit ;)
tl;dr: limitting the number of jobs sent to vmware.
There is a mechanism to limit jobs. It checks in the sync phase of async jobs to see if the queue for those jobs exeeds a certain length. If so it return to the user to try again later. It can filter on type and entity, if it can get them. These methods are part of those mechs.

return (getSyncObjId() != null) ? BaseAsyncCmd.migrationSyncObject : null;
}

@Override
public Long getSyncObjId() {
if (getStoragePoolId() != null) {
return getStoragePoolId();
}
// OfflineVmwareMigrations: undocumented feature;
// OfflineVmwareMigrations: on implementing a maximum queue size for per storage migrations it seems counter intuitive for the user to not enforce it for hosts as well.
if (getHostId() != null) {
return getHostId();
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

@APICommand(name = "migrateVirtualMachineWithVolume",
description = "Attempts Migration of a VM with its volumes to a different host",
responseObject = UserVmResponse.class, entityType = {VirtualMachine.class},
responseObject = UserVmResponse.class, entityType = {VirtualMachine.class},
requestHasSensitiveInfo = false,
responseHasSensitiveInfo = true)
public class MigrateVirtualMachineWithVolumeCmd extends BaseAsyncCmd {
Expand Down Expand Up @@ -147,6 +147,7 @@ public void execute() {
}

Host destinationHost = _resourceService.getHost(getHostId());
// OfflineVmwareMigration: destination host would have to not be a required parameter for stopped VMs
if (destinationHost == null) {
throw new InvalidParameterValueException("Unable to find the host to migrate the VM, host id =" + getHostId());
}
Expand All @@ -163,13 +164,7 @@ public void execute() {
} catch (ResourceUnavailableException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
} catch (ConcurrentOperationException e) {
s_logger.warn("Exception: ", e);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
} catch (ManagementServerException e) {
s_logger.warn("Exception: ", e);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
} catch (VirtualMachineMigrationException e) {
} catch (ConcurrentOperationException | ManagementServerException | VirtualMachineMigrationException e) {
s_logger.warn("Exception: ", e);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,16 @@ public void execute() {
}
}

@Override
public String getSyncObjType() {
return (getSyncObjId() != null) ? BaseAsyncCmd.migrationSyncObject : null;
}

@Override
public Long getSyncObjId() {
if (getStoragePoolId() != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If getStoragePoolId() != null, then return getStoragePoolId(), otherwise return null....

You can simple call return getStoragePoolId(). The result is the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the consideration here (and the intermediate version) that other objects, like the host, could be the sync object as well so this could be extended to return that under conditions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not get your explanation. When we extend the class and then override the method, the whole implementation of getSyncObjId is changed. I do not know how a possible method override can require this code here.

return getStoragePoolId();
}
return null;
}
}
43 changes: 43 additions & 0 deletions core/src/main/java/com/cloud/agent/api/MigrateVmToPoolAnswer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you 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 com.cloud.agent.api;

import org.apache.cloudstack.storage.to.VolumeObjectTO;

import java.util.List;

public class MigrateVmToPoolAnswer extends Answer {

List<VolumeObjectTO> volumeTos;

public MigrateVmToPoolAnswer(MigrateVmToPoolCommand cmd, Exception ex) {
super(cmd, ex);
volumeTos = null;
}

public MigrateVmToPoolAnswer(MigrateVmToPoolCommand cmd, List<VolumeObjectTO> volumeTos) {
super(cmd, true, null);
this.volumeTos = volumeTos;
}

public List<VolumeObjectTO> getVolumeTos() {
return volumeTos;
}
}
70 changes: 70 additions & 0 deletions core/src/main/java/com/cloud/agent/api/MigrateVmToPoolCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you 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 com.cloud.agent.api;

import com.cloud.agent.api.to.VolumeTO;

import java.util.Collection;

/**
* used to tell the agent to migrate a vm to a different primary storage pool.
* It is for now only implemented on Vmware and is supposed to work irrespective of whether the VM is started or not.
*
*/
public class MigrateVmToPoolCommand extends Command {
private Collection<VolumeTO> volumes;
private String vmName;
private String destinationPool;
private boolean executeInSequence = false;

protected MigrateVmToPoolCommand() {
}

/**
*
* @param vmName the name of the VM to migrate
* @param volumes used to supply feedback on vmware generated names
* @param destinationPool the primary storage pool to migrate the VM to
* @param executeInSequence
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you do not have anything further to talk about a parameter, I think that you do not need to list it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't that make it part of the javadoc rendering? it seems weird to include only part of the parameter list in the javadoc.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. I do not know how it would be better now. Maybe it would have an impact if we generated the javadoc for the code, but we do not do that...

*/
public MigrateVmToPoolCommand(String vmName, Collection<VolumeTO> volumes, String destinationPool, boolean executeInSequence) {
this.vmName = vmName;
this.volumes = volumes;
this.destinationPool = destinationPool;
this.executeInSequence = executeInSequence;
}

public Collection<VolumeTO> getVolumes() {
return volumes;
}

public String getDestinationPool() {
return destinationPool;
}

public String getVmName() {
return vmName;
}

@Override
public boolean executeInSequence() {
return executeInSequence;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,19 @@
public class UnregisterVMCommand extends Command {
String vmName;
boolean cleanupVmFiles = false;
boolean executeInSequence;

public UnregisterVMCommand(String vmName) {
this(vmName, false);
}
public UnregisterVMCommand(String vmName, boolean executeInSequence) {
this.vmName = vmName;
this.executeInSequence = executeInSequence;
}

@Override
public boolean executeInSequence() {
return false;
return executeInSequence;
}

public String getVmName() {
Expand Down
Loading