Skip to content

Commit

Permalink
vCenter vMotion not working
Browse files Browse the repository at this point in the history
Closes-Bug: #1543258

Change-Id: I2c3c731d6789a3786504214f95c08e71ad9931cf
  • Loading branch information
Andra Cismaru committed Feb 14, 2016
1 parent 206f1e0 commit cd0b13a
Show file tree
Hide file tree
Showing 9 changed files with 318 additions and 315 deletions.
58 changes: 30 additions & 28 deletions src/net/juniper/contrail/sandesh/VCenterPlugin.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
/* This class will be generated based on struct VCenterPlugin
* from vcenter.sandesh
/* This class will be generated based on struct VCenterPlugin
* from vcenter.sandesh
*/

package net.juniper.contrail.sandesh;

public class VCenterPlugin {
private boolean master;

public boolean getMaster() {
return master;
}

public void setMaster(boolean master) {
this.master = master;
}

private void writeFieldMaster(StringBuilder s, int identifier) {
s.append("<master type=\"bool\" identifier=\"")
.append(identifier)
.append("\">")
.append(master)
.append("</master>");
.append("</master>");
}

boolean pluginSessions;
public boolean getPluginSessions() {
return pluginSessions;
Expand All @@ -39,73 +39,75 @@ private void writeFieldPluginSessions(StringBuilder s, int identifier)
.append(pluginSessions)
.append("</pluginSessions>");
}

private VRouterStats vRouterStats;

public VRouterStats getVRouterStats() {
return vRouterStats;
}

public void setVRouterStats(VRouterStats vRouterStats) {
this.vRouterStats = vRouterStats;
}

private void writeFieldVRouterStats(StringBuilder s, int identifier) {
vRouterStats.writeObject(s, identifier);
}


private volatile ApiServerInfo apiServerInfo;

public ApiServerInfo getApiServerInfo() {
return apiServerInfo;
}

public void setApiServerInfo(ApiServerInfo apiServerInfo) {
this.apiServerInfo = apiServerInfo;
}

private void writeFieldApiServerInfo(StringBuilder s, int identifier) {
apiServerInfo.writeObject(s, identifier);
}

private volatile VCenterServerInfo vCenterServerInfo;

public VCenterServerInfo getVCenterServerInfo() {
return vCenterServerInfo;
}

public void setVCenterServerInfo(VCenterServerInfo vCenterServerInfo) {
this.vCenterServerInfo = vCenterServerInfo;
}

private void writeFieldVCenterServerInfo(StringBuilder s, int identifier) {
vCenterServerInfo.writeObject(s, identifier);
}

public void writeObject(StringBuilder s) {
writeObject(s, 1);
}

public VCenterPlugin() {
vRouterStats = new VRouterStats();
apiServerInfo = new ApiServerInfo();
vCenterServerInfo = new VCenterServerInfo();
}

public void writeObject(StringBuilder s, int identifier)
{
s.append("<VCenterPlugin type=\"struct\" identifier=\"")
.append(identifier)
.append("\">");
s.append("<VCenterPluginStruct>");

int inner_identifier = 1;
writeFieldMaster(s, inner_identifier++);
writeFieldPluginSessions(s, inner_identifier++);
writeFieldVRouterStats(s, inner_identifier++);
writeFieldApiServerInfo(s, inner_identifier++);
writeFieldVCenterServerInfo(s, inner_identifier++);
if (master) {
writeFieldPluginSessions(s, inner_identifier++);
writeFieldVRouterStats(s, inner_identifier++);
writeFieldApiServerInfo(s, inner_identifier++);
writeFieldVCenterServerInfo(s, inner_identifier++);
}
s.append("</VCenterPluginStruct>");
s.append("</VCenterPlugin>");
}
Expand Down
32 changes: 15 additions & 17 deletions src/net/juniper/contrail/vcenter/VCenterEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (c) 2015 Juniper Networks, Inc. All rights reserved.
*
* @author Andra Cismaru
*
*
* Handles functionality related to events received from VCenter
*/
package net.juniper.contrail.vcenter;
Expand All @@ -13,13 +13,12 @@
import com.vmware.vim25.DVPortgroupReconfiguredEvent;
import com.vmware.vim25.DVPortgroupRenamedEvent;
import com.vmware.vim25.Event;
import com.vmware.vim25.VmBeingCreatedEvent;
import com.vmware.vim25.VmCloneEvent;
import com.vmware.vim25.VmClonedEvent;
import com.vmware.vim25.VmCreatedEvent;
import com.vmware.vim25.VmDeployedEvent;
import com.vmware.vim25.VmMacAssignedEvent;
import com.vmware.vim25.VmMacChangedEvent;
import com.vmware.vim25.DrsVmMigratedEvent;
import com.vmware.vim25.VmMigratedEvent;
import com.vmware.vim25.VmPoweredOffEvent;
import com.vmware.vim25.VmPoweredOnEvent;
Expand Down Expand Up @@ -54,16 +53,15 @@ private void printEvent() {

public void handle() throws Exception {
printEvent();

if (event instanceof VmBeingCreatedEvent
|| event instanceof VmCreatedEvent

if (event instanceof VmCreatedEvent
|| event instanceof VmClonedEvent
|| event instanceof VmCloneEvent
|| event instanceof VmDeployedEvent
|| event instanceof VmReconfiguredEvent
|| event instanceof VmRenamedEvent
|| event instanceof VmMacChangedEvent
|| event instanceof VmMacAssignedEvent
|| event instanceof DrsVmMigratedEvent
|| event instanceof VmMigratedEvent
|| event instanceof VmPoweredOnEvent
|| event instanceof VmPoweredOffEvent) {
Expand All @@ -83,11 +81,11 @@ public void handle() throws Exception {

private void handleVmUpdateEvent() throws Exception {
VirtualMachineInfo newVmInfo = null;

try {
newVmInfo = new VirtualMachineInfo(event, vcenterDB, vncDB);
} catch (Exception e) {
s_logger.info("Skipping update event for deleted VM"
s_logger.info("Skipping update event for deleted VM"
+ event.getClass().getName());
return;
}
Expand All @@ -103,28 +101,28 @@ private void handleVmUpdateEvent() throws Exception {

private void handleVmDeleteEvent() throws Exception {
VirtualMachineInfo vmInfo = MainDB.getVmByName(event.getVm().getName());

if (vmInfo == null) {
return;
}

VCenterNotify.unwatchVm(vmInfo);
VCenterNotify.unwatchVm(vmInfo);
vmInfo.delete(vncDB);
}

private void handleNetworkUpdateEvent() throws Exception {
VirtualNetworkInfo newVnInfo = null;

try {
newVnInfo = new VirtualNetworkInfo(event, vcenterDB);
} catch (Exception e) {
s_logger.info("Skipping update event for deleted network"
s_logger.info("Skipping update event for deleted network"
+ event.getClass().getName());
return;
}

VirtualNetworkInfo oldVnInfo = MainDB.getVnByName(newVnInfo.getName());

if (oldVnInfo != null) {
oldVnInfo.update(newVnInfo, vncDB);
} else {
Expand All @@ -134,13 +132,13 @@ private void handleNetworkUpdateEvent() throws Exception {
}

private void handleNetworkDeleteEvent() throws Exception {

VirtualNetworkInfo vnInfo = MainDB.getVnByName(event.getNet().getName());

if (vnInfo == null) {
return;
}
VCenterNotify.unwatchVn(vnInfo);
VCenterNotify.unwatchVn(vnInfo);
vnInfo.delete(vncDB);
}

Expand Down
59 changes: 31 additions & 28 deletions src/net/juniper/contrail/vcenter/VCenterMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,29 @@ class ExecutorServiceShutdownThread extends Thread {
public ExecutorServiceShutdownThread(ExecutorService es) {
this.es = es;
}

@Override
public void run() {
es.shutdown();
try {
if (!es.awaitTermination(timeoutValue, timeoutUnit)) {
es.shutdownNow();
if (!es.awaitTermination(timeoutValue, timeoutUnit)) {
s_logger.error("ExecutorSevice: " + es +
s_logger.error("ExecutorSevice: " + es +
" did NOT terminate");
}
}
} catch (InterruptedException e) {
s_logger.error("ExecutorServiceShutdownThread: " +
Thread.currentThread() + " ExecutorService: " + e +
s_logger.error("ExecutorServiceShutdownThread: " +
Thread.currentThread() + " ExecutorService: " + e +
" interrupted : " + e);
}

}
}

public class VCenterMonitor {
private static ScheduledExecutorService scheduledTaskExecutor =
private static ScheduledExecutorService scheduledTaskExecutor =
Executors.newScheduledThreadPool(1);
private static Logger s_logger = Logger.getLogger(VCenterMonitor.class);
private static String _configurationFile = "/etc/contrail/contrail-vcenter-plugin.conf";
Expand All @@ -59,9 +59,9 @@ public class VCenterMonitor {
private static String _vcenterPassword = "Contrail123!";
private static String _vcenterDcName = "Datacenter";
private static String _vcenterDvsName = "dvSwitch";
private static String _vcenterIpFabricPg = "contrail-fab-pg";
static VCenterNotify _eventMonitor;
private static String _vcenterIpFabricPg = "contrail-fab-pg";

static VCenterNotify _eventMonitor;
private static String _apiServerAddress = "10.84.13.23";
private static int _apiServerPort = 8082;
private static String _username = "admin";
Expand All @@ -75,15 +75,15 @@ public class VCenterMonitor {
private static String _zookeeperId = "node-vcenter-plugin";

static volatile Mode mode = Mode.VCENTER_ONLY;

private static volatile MasterSelection zk_ms;
public static boolean isZookeeperLeader() {
if (mode.equals(Mode.VCENTER_AS_COMPUTE))
return true;

return zk_ms.isLeader();
}

private static Properties readVcenterPluginConfigFile() {
final Properties configProps = new Properties();
File configFile = new File(_configurationFile);
Expand Down Expand Up @@ -115,7 +115,7 @@ private static Properties readVcenterPluginConfigFile() {
}

String _mode = configProps.getProperty("mode");

if (_mode != null && _mode.equals("vcenter-as-compute")) {
mode = Mode.VCENTER_AS_COMPUTE;
String authurl = configProps.getProperty("auth_url");
Expand Down Expand Up @@ -157,7 +157,7 @@ public static void main(String[] args) throws Exception {

//Read contrail-vcenter-plugin.conf file
Properties configProps = readVcenterPluginConfigFile();
s_logger.info("Config params vcenter url: " + _vcenterURL + ", _vcenterUsername: "
s_logger.info("Config params vcenter url: " + _vcenterURL + ", _vcenterUsername: "
+ _vcenterUsername + ", api server: " + _apiServerAddress);

launchWatchDogs();
Expand All @@ -174,26 +174,29 @@ public static void main(String[] args) throws Exception {
zk_ms.waitForLeadership();
s_logger.info("Acquired zookeeper Mastership .. ");
}

// Launch the periodic VCenterMonitorTask

_eventMonitor = new VCenterNotify(_vcenterURL, _vcenterUsername, _vcenterPassword,
_vcenterDcName, _vcenterDvsName, _vcenterIpFabricPg,
_apiServerAddress, _apiServerPort, _username, _password,
_tenant,
_authtype, _authurl, mode);
VCenterMonitorTask _monitorTask = new VCenterMonitorTask(_eventMonitor,
_vcenterURL, _vcenterUsername, _vcenterPassword,
_vcenterDcName, _vcenterDvsName, _vcenterIpFabricPg);

_vcenterURL, _vcenterUsername, _vcenterPassword,
_vcenterDcName, _vcenterDvsName, _vcenterIpFabricPg);

s_logger.info("Starting the notify task.. ");
_eventMonitor.start();
s_logger.info("Notify task started.");

// Launch the periodic VCenterMonitorTask
s_logger.info("Starting periodic monitor task.. ");
scheduledTaskExecutor.scheduleWithFixedDelay(_monitorTask, 0, 8, //8 second periodic
TimeUnit.SECONDS);
s_logger.info("Periodic monitor task started.");

Runtime.getRuntime().addShutdownHook(
new ExecutorServiceShutdownThread(scheduledTaskExecutor));

s_logger.info("Starting periodic monitor Task.. ");
_eventMonitor = new VCenterNotify(_vcenterURL, _vcenterUsername, _vcenterPassword,
_vcenterDcName, _vcenterDvsName, _vcenterIpFabricPg,
_apiServerAddress, _apiServerPort, _username, _password,
_tenant,
_authtype, _authurl, mode);
_eventMonitor.start();

s_logger.info("Periodic monitor Task started.");
s_logger.info("All aboard.");
}

private static void launchWatchDogs() {
Expand Down

0 comments on commit cd0b13a

Please sign in to comment.