Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
CLOUDSTACK-8612. [VMware] Make vCenter session timeout configurable f…
…or volume snapshot.

Separate out vmware vcenter session timeout config for volume snapshot backup operation.
  • Loading branch information
Likitha Shetty
Likitha Shetty committed Jul 6, 2015
commit 1093a9626e1d401ba3501882797c2ea2b0fd54c7
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,19 @@ public Pair<Boolean, Long> getCommandHostDelegation(long hostId, Command cmd) {
_cmdExecLogDao.persist(execLog);
cmd.setContextParam("execid", String.valueOf(execLog.getId()));
cmd.setContextParam("noderuninfo", String.format("%d-%d", _clusterMgr.getManagementNodeId(), _clusterMgr.getCurrentRunId()));
cmd.setContextParam("vCenterSessionTimeout", String.valueOf(_vmwareMgr.getVcenterSessionTimeout()));
if (cmd instanceof CopyCommand) { // Snapshot backup
CopyCommand cpyCommand = (CopyCommand)cmd;
DataTO srcData = cpyCommand.getSrcTO();
DataTO destData = cpyCommand.getDestTO();
if (srcData.getObjectType() == DataObjectType.SNAPSHOT && destData.getObjectType() == DataObjectType.SNAPSHOT &&
srcData.getDataStore().getRole() == DataStoreRole.Primary) {
cmd.setContextParam("vCenterSessionTimeout", String.valueOf(_vmwareMgr.getSnapshotBackupSessionTimeout()));
} else {
cmd.setContextParam("vCenterSessionTimeout", String.valueOf(_vmwareMgr.getVcenterSessionTimeout()));
}
} else {
cmd.setContextParam("vCenterSessionTimeout", String.valueOf(_vmwareMgr.getVcenterSessionTimeout()));
}

if (cmd instanceof BackupSnapshotCommand || cmd instanceof CreatePrivateTemplateFromVolumeCommand ||
cmd instanceof CreatePrivateTemplateFromSnapshotCommand || cmd instanceof CopyVolumeCommand || cmd instanceof CopyCommand ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@ public VmwareServerDiscoverer() {

VmwareContext context = null;
try {
context = VmwareContextFactory.create(url.getHost(), username, password);
int sessionTimeout = _vmwareMgr.getVcenterSessionTimeout();
context = VmwareContextFactory.create(url.getHost(), username, password, sessionTimeout);
if (privateTrafficLabel != null)
context.registerStockObject("privateTrafficLabel", privateTrafficLabel);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,7 @@ public interface VmwareManager {
boolean isLegacyZone(long dcId);

boolean hasNexusVSM(Long clusterId);

public int getSnapshotBackupSessionTimeout();

}
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
private int _additionalPortRangeSize;
private int _routerExtraPublicNics = 2;
private int _vCenterSessionTimeout = 1200000; // Timeout in milliseconds
private int _snapshotBackupSessionTimeout = 1200000; // Timeout in milliseconds

private String _rootDiskController = DiskControllerType.ide.toString();

Expand Down Expand Up @@ -283,6 +284,9 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
_vCenterSessionTimeout = NumbersUtil.parseInt(_configDao.getValue(Config.VmwareVcenterSessionTimeout.key()), 1200) * 1000;
s_logger.info("VmwareManagerImpl config - vmware.vcenter.session.timeout: " + _vCenterSessionTimeout);

_snapshotBackupSessionTimeout = NumbersUtil.parseInt(_configDao.getValue(Config.VmwareSnapshotBackupSessionTimeout.key()), 1200) * 1000;
s_logger.info("VmwareManagerImpl config - vmware.snapshot.backup.session.timeout: " + _snapshotBackupSessionTimeout);

_recycleHungWorker = _configDao.getValue(Config.VmwareRecycleHungWorker.key());
if (_recycleHungWorker == null || _recycleHungWorker.isEmpty()) {
_recycleHungWorker = "false";
Expand Down Expand Up @@ -487,6 +491,8 @@ public void setupResourceStartupParams(Map<String, Object> params) {
params.put("vmware.root.disk.controller", _rootDiskController);
params.put("vmware.recycle.hung.wokervm", _recycleHungWorker);
params.put("ports.per.dvportgroup", _portsPerDvPortGroup);
params.put("vmware.vcenter.session.timeout", _vCenterSessionTimeout);
params.put("vmware.snapshot.backup.session.timeout", _snapshotBackupSessionTimeout);
}

@Override
Expand Down Expand Up @@ -942,6 +948,11 @@ public int getVcenterSessionTimeout() {
return _vCenterSessionTimeout;
}

@Override
public int getSnapshotBackupSessionTimeout(){
return _snapshotBackupSessionTimeout;
}

@Override
public List<Class<?>> getCommands() {
List<Class<?>> cmdList = new ArrayList<Class<?>>();
Expand Down Expand Up @@ -1022,7 +1033,7 @@ public VmwareDatacenterVO addVmwareDatacenter(AddVmwareDcCmd cmd) throws Resourc
String guid;
ManagedObjectReference dcMor;
try {
context = VmwareContextFactory.create(vCenterHost, userName, password);
context = VmwareContextFactory.create(vCenterHost, userName, password, _vCenterSessionTimeout);

// Check if DC exists on vCenter
dcMo = new DatacenterMO(context, vmwareDcName);
Expand Down Expand Up @@ -1119,7 +1130,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
// Construct context
VmwareContext context = null;
try {
context = VmwareContextFactory.create(vCenterHost, userName, password);
context = VmwareContextFactory.create(vCenterHost, userName, password, _vCenterSessionTimeout);

// Check if DC exists on vCenter
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void init() {
s_clusterMgr = _clusterMgr;
}

public static VmwareContext create(String vCenterAddress, String vCenterUserName, String vCenterPassword) throws Exception {
public static VmwareContext create(String vCenterAddress, String vCenterUserName, String vCenterPassword, int sessionTimeout) throws Exception {
assert (vCenterAddress != null);
assert (vCenterUserName != null);
assert (vCenterPassword != null);
Expand All @@ -66,7 +66,7 @@ public static VmwareContext create(String vCenterAddress, String vCenterUserName
StringUtils.getMaskedPasswordForDisplay(vCenterPassword));

VmwareClient vimClient = new VmwareClient(vCenterAddress + "-" + s_seq++);
vimClient.setVcenterSessionTimeout(s_vmwareMgr.getVcenterSessionTimeout());
vimClient.setVcenterSessionTimeout(sessionTimeout);
vimClient.connect(serviceUrl, vCenterUserName, vCenterPassword);

VmwareContext context = new VmwareContext(vimClient, vCenterAddress);
Expand All @@ -76,22 +76,22 @@ public static VmwareContext create(String vCenterAddress, String vCenterUserName
context.registerStockObject("manageportgroup", s_vmwareMgr.getManagementPortGroupName());
context.registerStockObject("noderuninfo", String.format("%d-%d", s_clusterMgr.getManagementNodeId(), s_clusterMgr.getCurrentRunId()));

context.setPoolInfo(s_pool, VmwareContextPool.composePoolKey(vCenterAddress, vCenterUserName));
context.setPoolInfo(s_pool, VmwareContextPool.composePoolKey(vCenterAddress, vCenterUserName, sessionTimeout));
s_pool.registerOutstandingContext(context);

return context;
}

public static VmwareContext getContext(String vCenterAddress, String vCenterUserName, String vCenterPassword) throws Exception {
VmwareContext context = s_pool.getContext(vCenterAddress, vCenterUserName);
public static VmwareContext getContext(String vCenterAddress, String vCenterUserName, String vCenterPassword, int sessionTimeout) throws Exception {
VmwareContext context = s_pool.getContext(vCenterAddress, vCenterUserName, sessionTimeout);
if (context == null) {
context = create(vCenterAddress, vCenterUserName, vCenterPassword);
context = create(vCenterAddress, vCenterUserName, vCenterPassword, sessionTimeout);
} else {
// Validate current context and verify if vCenter session timeout value of the context matches the timeout value set by Admin
if (!context.validate() || (context.getVimClient().getVcenterSessionTimeout() != s_vmwareMgr.getVcenterSessionTimeout())) {
if (!context.validate()) {
s_logger.info("Validation of the context failed, dispose and create a new one");
context.close();
context = create(vCenterAddress, vCenterUserName, vCenterPassword);
context = create(vCenterAddress, vCenterUserName, vCenterPassword, sessionTimeout);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
protected int _portsPerDvPortGroup;
protected boolean _fullCloneFlag = false;
protected boolean _instanceNameFlag = false;

protected int _vCenterSessionTimeout = 1200000; // Timeout in milliseconds
protected boolean _recycleHungWorker = false;
protected DiskControllerType _rootDiskController = DiskControllerType.ide;

Expand Down Expand Up @@ -4983,6 +4983,10 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
_instanceNameFlag = false;
}

Integer sessionTimeout = (Integer) params.get("vmware.vcenter.session.timeout");
if (sessionTimeout != null)
_vCenterSessionTimeout = sessionTimeout.intValue();

value = (String)params.get("scripts.timeout");
int timeout = NumbersUtil.parseInt(value, 1440) * 1000;
_storageProcessor = new VmwareStorageProcessor((VmwareHostService)this, _fullCloneFlag, (VmwareStorageMount)mgr, timeout, this, _shutdownWaitMs, null);
Expand Down Expand Up @@ -5035,9 +5039,16 @@ public VmwareHypervisorHost getHyperHost(VmwareContext context) {
@Override
public VmwareContext getServiceContext(Command cmd) {
VmwareContext context = null;
int vCenterSessionTimeout;
if (cmd != null && cmd.getContextParam("vCenterSessionTimeout") != null) {
vCenterSessionTimeout = NumbersUtil.parseInt(cmd.getContextParam("vCenterSessionTimeout"), 1200000);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why not use _vCenterSessionTimeout here?

} else {
vCenterSessionTimeout = _vCenterSessionTimeout;
}

if(s_serviceContext.get() != null) {
context = s_serviceContext.get();
String poolKey = VmwareContextPool.composePoolKey(_vCenterAddress, _username);
String poolKey = VmwareContextPool.composePoolKey(_vCenterAddress, _username, vCenterSessionTimeout);
// Before re-using the thread local context, ensure it corresponds to the right vCenter API session and that it is valid to make calls.
if(context.getPoolKey().equals(poolKey)) {
if (context.validate()) {
Expand All @@ -5051,11 +5062,11 @@ public VmwareContext getServiceContext(Command cmd) {
}
} else {
// Exisitng ThreadLocal context corresponds to a different vCenter API session. Why has it not been recycled?
s_logger.warn("ThreadLocal VMware context: " + poolKey + " doesn't correspond to the right vCenter. Expected VMware context: " + context.getPoolKey());
s_logger.warn("ThreadLocal VMware context: " + poolKey + ". Expected VMware context: " + context.getPoolKey());
}
}
try {
context = VmwareContextFactory.getContext(_vCenterAddress, _username, _password);
context = VmwareContextFactory.getContext(_vCenterAddress, _username, _password, vCenterSessionTimeout);
s_serviceContext.set(context);
} catch (Exception e) {
s_logger.error("Unable to connect to vSphere server: " + _vCenterAddress, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,34 +36,34 @@ public static void initFactoryEnvironment() {
s_pool = new VmwareContextPool();
}

public static VmwareContext create(String vCenterAddress, String vCenterUserName, String vCenterPassword) throws Exception {
public static VmwareContext create(String vCenterAddress, String vCenterUserName, String vCenterPassword, int sessionTimeout) throws Exception {
assert (vCenterAddress != null);
assert (vCenterUserName != null);
assert (vCenterPassword != null);

String serviceUrl = "https://" + vCenterAddress + "/sdk/vimService";
VmwareClient vimClient = new VmwareClient(vCenterAddress + "-" + s_seq++);
vimClient.setVcenterSessionTimeout(s_vCenterSessionTimeout);
vimClient.setVcenterSessionTimeout(sessionTimeout);
vimClient.connect(serviceUrl, vCenterUserName, vCenterPassword);
VmwareContext context = new VmwareContext(vimClient, vCenterAddress);
assert (context != null);

context.setPoolInfo(s_pool, VmwareContextPool.composePoolKey(vCenterAddress, vCenterUserName));
context.setPoolInfo(s_pool, VmwareContextPool.composePoolKey(vCenterAddress, vCenterUserName, sessionTimeout));
s_pool.registerOutstandingContext(context);

return context;
}

public static VmwareContext getContext(String vCenterAddress, String vCenterUserName, String vCenterPassword) throws Exception {
VmwareContext context = s_pool.getContext(vCenterAddress, vCenterUserName);
public static VmwareContext getContext(String vCenterAddress, String vCenterUserName, String vCenterPassword, int sessionTimeout) throws Exception {
VmwareContext context = s_pool.getContext(vCenterAddress, vCenterUserName, sessionTimeout);
if (context == null) {
context = create(vCenterAddress, vCenterUserName, vCenterPassword);
context = create(vCenterAddress, vCenterUserName, vCenterPassword, sessionTimeout);
} else {
// Validate current context and verify if vCenter session timeout value of the context matches the timeout value set by Admin
if (!context.validate() || (context.getVimClient().getVcenterSessionTimeout() != s_vCenterSessionTimeout)) {
// Validate current context
if (!context.validate()) {
s_logger.info("Validation of the context faild. dispose and create a new one");
context.close();
context = create(vCenterAddress, vCenterUserName, vCenterPassword);
context = create(vCenterAddress, vCenterUserName, vCenterPassword, sessionTimeout);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost;
import com.cloud.hypervisor.vmware.mo.VmwareHypervisorHostNetworkSummary;
import com.cloud.hypervisor.vmware.util.VmwareContext;
import com.cloud.hypervisor.vmware.util.VmwareContextPool;
import com.cloud.serializer.GsonHelper;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair;
Expand Down Expand Up @@ -209,20 +210,32 @@ public VmwareContext getServiceContext(Command cmd) {
_resource.ensureOutgoingRuleForAddress(vCenterAddress);

VmwareContext context = currentContext.get();
if (context != null && !context.validate()) {
invalidateServiceContext(context);
context = null;

if (context != null) {
String poolKey = VmwareContextPool.composePoolKey(vCenterAddress, username, vCenterSessionTimeout);
// Before re-using the thread local context, ensure it corresponds to the right vCenter API session with the expected timeout and that it is valid to make calls.
if(context.getPoolKey().equals(poolKey)) {
if (context.validate()) {
if (s_logger.isTraceEnabled()) {
s_logger.trace("ThreadLocal context is still valid, just reuse");
}
} else {
s_logger.info("Validation of the context failed, dispose and use a new one");
invalidateServiceContext(context);
context = null;
}
} else {
s_logger.warn("ThreadLocal VMware context: " + poolKey + ". Expected VMware context: " + context.getPoolKey());
context = null;
}
}

if (context == null) {
s_logger.info("Open new VmwareContext. vCenter: " + vCenterAddress + ", user: " + username + ", password: " + StringUtils.getMaskedPasswordForDisplay(password));
VmwareSecondaryStorageContextFactory.setVcenterSessionTimeout(vCenterSessionTimeout);
context = VmwareSecondaryStorageContextFactory.getContext(vCenterAddress, username, password);
}
if (context != null) {
context.registerStockObject("serviceconsole", cmd.getContextParam("serviceconsole"));
context.registerStockObject("manageportgroup", cmd.getContextParam("manageportgroup"));
context.registerStockObject("noderuninfo", cmd.getContextParam("noderuninfo"));
context = VmwareSecondaryStorageContextFactory.getContext(vCenterAddress, username, password, vCenterSessionTimeout);
}
context.registerStockObject("serviceconsole", cmd.getContextParam("serviceconsole"));
context.registerStockObject("manageportgroup", cmd.getContextParam("manageportgroup"));
context.registerStockObject("noderuninfo", cmd.getContextParam("noderuninfo"));
currentContext.set(context);
return context;
} catch (Exception e) {
Expand Down
1 change: 1 addition & 0 deletions server/src/com/cloud/configuration/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,7 @@ public enum Config {
"When set to true this will enable nested virtualization when this is supported by the hypervisor",
null),
VmwareVcenterSessionTimeout("Advanced", ManagementServer.class, Long.class, "vmware.vcenter.session.timeout", "1200", "VMware client timeout in seconds", null),
VmwareSnapshotBackupSessionTimeout("Advanced", ManagementServer.class, Long.class, "vmware.snapshot.backup.session.timeout", "1200", "VMware client timeout in seconds for snapshot backup", null),

// Midonet
MidoNetAPIServerAddress(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public void unregisterOutstandingContext(VmwareContext context) {
}
}

public VmwareContext getContext(String vCenterAddress, String vCenterUserName) {
String poolKey = composePoolKey(vCenterAddress, vCenterUserName);
public VmwareContext getContext(String vCenterAddress, String vCenterUserName, int vCenterSessionTimeout) {
String poolKey = composePoolKey(vCenterAddress, vCenterUserName, vCenterSessionTimeout);
synchronized (this) {
List<VmwareContext> l = _pool.get(poolKey);
if (l == null)
Expand Down Expand Up @@ -162,9 +162,10 @@ private void doKeepAlive() {
}
}

public static String composePoolKey(String vCenterAddress, String vCenterUserName) {
public static String composePoolKey(String vCenterAddress, String vCenterUserName, int vCenterSessionTimeout) {
assert (vCenterUserName != null);
assert (vCenterAddress != null);
return vCenterUserName + "@" + vCenterAddress;
int sessionTimeoutInSeconds = vCenterSessionTimeout/1000;
return vCenterUserName + "@" + vCenterAddress + ";" + String.valueOf(sessionTimeoutInSeconds);
}
}
Loading