Skip to content

Commit 82ffddc

Browse files
author
Vijayendra Bhamidipati
committed
CS-15055: DB exception when creating n1kv VSM when adding a cluster via the latest management server GUI.
Description: Adding an optional flag to the addCluster command, "addvsmflag". If this is set to true, the API will throw an exception if any VSM parameter is missed out. The above bug was running into a DB exception because the vCenter ipaddress wasn't passed in and the API didn't catch it.
1 parent ed0ba1a commit 82ffddc

3 files changed

Lines changed: 53 additions & 40 deletions

File tree

‎api/src/com/cloud/api/ApiConstants.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ public class ApiConstants {
354354
public static final String VSM_CONFIG_MODE = "vsmconfigmode";
355355
public static final String VSM_CONFIG_STATE = "vsmconfigstate";
356356
public static final String VSM_DEVICE_STATE = "vsmdevicestate";
357+
public static final String ADD_VSM_FLAG = "addvsmflag";
357358

358359
public enum HostDetails {
359360
all, capacity, events, stats, min;

‎api/src/com/cloud/api/commands/AddClusterCmd.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ public class AddClusterCmd extends BaseCmd {
8181
@Parameter(name = ApiConstants.VCENTER_DC_NAME, type = CommandType.STRING, required = false, description = "the name of the vCenter Data Center the VSM associated with this cluster will serve")
8282
private String vcenterdcname;
8383

84+
@Parameter(name = ApiConstants.ADD_VSM_FLAG, type = CommandType.STRING, required = false, description = "flag that indicates a Cisco Nexus 1000v VSM is being associated with this cluster")
85+
private String addVSMFlag;
86+
87+
public String getAddVSMFlag() {
88+
return addVSMFlag;
89+
}
90+
8491
public String getvCenterDCName() {
8592
return vcenterdcname;
8693
}

‎server/src/com/cloud/resource/ResourceManagerImpl.java‎

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -430,48 +430,53 @@ public List<? extends Cluster> discoverCluster(AddClusterCmd cmd) throws Illegal
430430
}
431431
clusterId = cluster.getId();
432432
result.add(cluster);
433-
434-
String vsmIp = cmd.getVSMIpaddress();
435-
String vsmUser = cmd.getVSMUsername();
436-
String vsmPassword = cmd.getVSMPassword();
437-
String vCenterIpaddr = cmd.getvCenterIPAddr();
438-
String vCenterDcName = cmd.getvCenterDCName();
439-
440-
if (vsmIp != null && vsmUser != null && vsmPassword != null) {
441-
NetconfHelper netconfClient;
442-
try {
443-
netconfClient = new NetconfHelper(vsmIp, vsmUser, vsmPassword);
444-
netconfClient.disconnect();
445-
} catch (CloudRuntimeException e) {
446-
String msg = "Invalid credentials supplied for user " + vsmUser + " for Cisco Nexus 1000v VSM at " + vsmIp;
447-
s_logger.error(msg);
448-
throw new CloudRuntimeException(msg);
449-
}
450-
// persist credentials in database
451-
CiscoNexusVSMDeviceVO vsm = new CiscoNexusVSMDeviceVO(vsmIp, vsmUser, vsmPassword, vCenterIpaddr, vCenterDcName);
433+
434+
if (cmd.getAddVSMFlag().equalsIgnoreCase("true")) {
435+
436+
String vsmIp = cmd.getVSMIpaddress();
437+
String vsmUser = cmd.getVSMUsername();
438+
String vsmPassword = cmd.getVSMPassword();
439+
String vCenterIpaddr = cmd.getvCenterIPAddr();
440+
String vCenterDcName = cmd.getvCenterDCName();
441+
442+
if (vsmIp != null && vsmUser != null && vsmPassword != null && vCenterIpaddr != null && vCenterDcName != null) {
443+
NetconfHelper netconfClient;
444+
try {
445+
netconfClient = new NetconfHelper(vsmIp, vsmUser, vsmPassword);
446+
netconfClient.disconnect();
447+
} catch (CloudRuntimeException e) {
448+
String msg = "Invalid credentials supplied for user " + vsmUser + " for Cisco Nexus 1000v VSM at " + vsmIp;
449+
s_logger.error(msg);
450+
throw new CloudRuntimeException(msg);
451+
}
452+
// persist credentials in database
453+
CiscoNexusVSMDeviceVO vsm = new CiscoNexusVSMDeviceVO(vsmIp, vsmUser, vsmPassword, vCenterIpaddr, vCenterDcName);
452454

453-
Transaction txn = Transaction.currentTxn();
454-
try {
455-
txn.start();
456-
vsm = _vsmDao.persist(vsm);
457-
txn.commit();
458-
} catch (Exception e) {
459-
txn.rollback();
460-
s_logger.error("Failed to persist VSM details to database. Exception: " + e.getMessage());
461-
throw new CloudRuntimeException(e.getMessage());
462-
}
455+
Transaction txn = Transaction.currentTxn();
456+
try {
457+
txn.start();
458+
vsm = _vsmDao.persist(vsm);
459+
txn.commit();
460+
} catch (Exception e) {
461+
txn.rollback();
462+
s_logger.error("Failed to persist VSM details to database. Exception: " + e.getMessage());
463+
throw new CloudRuntimeException(e.getMessage());
464+
}
463465

464-
ClusterVSMMapVO connectorObj = new ClusterVSMMapVO(clusterId, vsm.getId());
465-
txn = Transaction.currentTxn();
466-
try {
467-
txn.start();
468-
_clusterVSMDao.persist(connectorObj);
469-
txn.commit();
470-
} catch (Exception e) {
471-
txn.rollback();
472-
s_logger.error("Failed to associate VSM with cluster: " + clusterName + ". Exception: " + e.getMessage());
473-
throw new CloudRuntimeException(e.getMessage());
474-
}
466+
ClusterVSMMapVO connectorObj = new ClusterVSMMapVO(clusterId, vsm.getId());
467+
txn = Transaction.currentTxn();
468+
try {
469+
txn.start();
470+
_clusterVSMDao.persist(connectorObj);
471+
txn.commit();
472+
} catch (Exception e) {
473+
txn.rollback();
474+
s_logger.error("Failed to associate VSM with cluster: " + clusterName + ". Exception: " + e.getMessage());
475+
throw new CloudRuntimeException(e.getMessage());
476+
}
477+
} else {
478+
throw new CloudRuntimeException("All required parameters for VSM not specified");
479+
}
475480
}
476481

477482
if (clusterType == Cluster.ClusterType.CloudManaged) {

0 commit comments

Comments
 (0)