Skip to content

Commit

Permalink
Fix Exceptions in vcenter-plugin in production network outage
Browse files Browse the repository at this point in the history
Closes-Bug: #1555303

Change-Id: I1fff564e50fc580e62e19543371694abc3d25513
  • Loading branch information
Andra Cismaru committed Jul 14, 2016
1 parent a20360a commit 25512ed
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 125 deletions.
11 changes: 6 additions & 5 deletions src/net/juniper/contrail/sandesh/VCenterHttpServer.java
Expand Up @@ -6,6 +6,7 @@
import org.apache.log4j.Logger;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
import com.google.common.base.Throwables;

@SuppressWarnings("restriction")
public class VCenterHttpServer implements HttpService {
Expand All @@ -14,11 +15,11 @@ public class VCenterHttpServer implements HttpService {
private final static String webRoot = "/usr/share/contrail-vcenter-plugin/webs";
private final Logger s_logger =
Logger.getLogger(VCenterHttpServer.class);

public static String getWebRoot() {
return webRoot;
}

public VCenterHttpServer(Properties configProps) {

String portStr = configProps.getProperty("introspect.port");
Expand Down Expand Up @@ -55,8 +56,8 @@ public void run() {
server.setExecutor(null); // creates a default executor
server.start();
} catch (IOException e) {
s_logger.error(" Cannot start HTTP server on port " + port);
e.printStackTrace();
s_logger.error(" Cannot start HTTP server on port " + port + " due to exception " + e);
s_logger.error(Throwables.getStackTraceAsString(e));
}

if (server == null) {
Expand All @@ -65,7 +66,7 @@ public void run() {
s_logger.info("HTTP server on port " + port + " started.");
}
}

@Override
public void registerHandler(String path, HttpHandler h) {
if (server != null) {
Expand Down
14 changes: 8 additions & 6 deletions src/net/juniper/contrail/vcenter/MainDB.java
Expand Up @@ -128,7 +128,8 @@ void sync(SortedMap<K, V> oldMap, SortedMap<K, V> newMap) {
oldEntry = oldIter.hasNext()? oldIter.next() : null;
}
} catch (Exception e) {
//s_logger.error("Cannot sync " + entry1.getKey());
s_logger.error("Cannot sync old [" + oldEntry.getKey() + ", " + oldEntry.getValue() + "] with new [" +
newEntry.getKey() + ", " + newEntry.getValue() + "]" );
}
}

Expand All @@ -137,7 +138,7 @@ void sync(SortedMap<K, V> oldMap, SortedMap<K, V> newMap) {
try {
oldEntry.getValue().delete(vncDB);
} catch (Exception e) {
//s_logger.error("Cannot delete " + entry2.getKey());
s_logger.error("Cannot delete old [" + oldEntry.getKey() + ", " + oldEntry.getValue() + "]");
}
oldEntry = oldIter.hasNext()? oldIter.next() : null;
}
Expand All @@ -147,7 +148,7 @@ void sync(SortedMap<K, V> oldMap, SortedMap<K, V> newMap) {
try {
newEntry.getValue().create(vncDB);
} catch (Exception e) {
//s_logger.error("Cannot create VN " + entry1.getKey());
s_logger.error("Cannot create new [" + newEntry.getKey() + ", " + newEntry.getValue() + "]" );
}
newEntry = newIter.hasNext()? newIter.next() : null;
}
Expand Down Expand Up @@ -176,15 +177,16 @@ void update(SortedMap<K, V> oldMap, SortedMap<K, V> newMap) {
oldEntry = oldIter.hasNext()? oldIter.next() : null;
}
} catch (Exception e) {
//s_logger.error("Cannot sync " + entry1.getKey());
s_logger.error("Cannot update old [" + oldEntry.getKey() + ", " + oldEntry.getValue() + "] with new [" +
newEntry.getKey() + ", " + newEntry.getValue() + "]" );
}
}

while (oldEntry != null) {
try {
oldEntry.getValue().delete(vncDB);
} catch (Exception e) {
//s_logger.error("Cannot delete " + entry2.getKey());
s_logger.error("Cannot delete old [" + oldEntry.getKey() + ", " + oldEntry.getValue() + "]");
}
oldEntry = oldIter.hasNext()? oldIter.next() : null;
}
Expand All @@ -193,7 +195,7 @@ void update(SortedMap<K, V> oldMap, SortedMap<K, V> newMap) {
try {
newEntry.getValue().create(vncDB);
} catch (Exception e) {
//s_logger.error("Cannot create VN " + entry1.getKey());
s_logger.error("Cannot create new [" + newEntry.getKey() + ", " + newEntry.getValue() + "]" );
}
newEntry = newIter.hasNext()? newIter.next() : null;
}
Expand Down
8 changes: 5 additions & 3 deletions src/net/juniper/contrail/vcenter/VCenterDB.java
Expand Up @@ -26,6 +26,8 @@
import com.vmware.vim25.RuntimeFault;
import com.vmware.vim25.VirtualMachineToolsRunningStatus;
import org.apache.log4j.Logger;

import com.google.common.base.Throwables;
import com.vmware.vim25.DVPortSetting;
import com.vmware.vim25.DVPortgroupConfigInfo;
import com.vmware.vim25.GuestInfo;
Expand Down Expand Up @@ -187,7 +189,7 @@ public boolean connect(int timeout) {
try{
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
s_logger.error(Throwables.getStackTraceAsString(e));
return false;
}

Expand All @@ -197,7 +199,7 @@ public boolean connect(int timeout) {
try{
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
s_logger.error(Throwables.getStackTraceAsString(e));
return false;
}

Expand Down Expand Up @@ -236,7 +238,7 @@ private boolean createServiceInstance(int timeout) {
} catch (Exception e) {
operationalStatus = "Error while connecting to vcenter: " + e.getMessage();
s_logger.error(operationalStatus);
e.printStackTrace();
s_logger.error(Throwables.getStackTraceAsString(e));
return false;
}
}
Expand Down
12 changes: 7 additions & 5 deletions src/net/juniper/contrail/vcenter/VCenterEventHandler.java
Expand Up @@ -8,6 +8,8 @@
package net.juniper.contrail.vcenter;

import org.apache.log4j.Logger;

import com.google.common.base.Throwables;
import com.vmware.vim25.DVPortgroupCreatedEvent;
import com.vmware.vim25.DVPortgroupDestroyedEvent;
import com.vmware.vim25.DVPortgroupReconfiguredEvent;
Expand Down Expand Up @@ -87,9 +89,9 @@ private void handleVmUpdateEvent() throws Exception {
try {
newVmInfo = new VirtualMachineInfo(event, vcenterDB, vncDB);
} catch (Exception e) {
e.printStackTrace();
s_logger.info("Skipping update event " + event.getClass().getName()
+" for missing VM");
+" for missing VM, due to exception " + e);
s_logger.error(Throwables.getStackTraceAsString(e));
return;
}

Expand Down Expand Up @@ -119,9 +121,9 @@ private void handleNetworkUpdateEvent() throws Exception {
try {
newVnInfo = new VirtualNetworkInfo(event, vcenterDB, vncDB);
} catch (Exception e) {
e.printStackTrace();
s_logger.info("Skipping update event " + event.getClass().getName() +
" for missing network");
" for missing network, due to exception " + e);
s_logger.error(Throwables.getStackTraceAsString(e));
return;
}

Expand All @@ -147,6 +149,6 @@ private void handleNetworkDeleteEvent() throws Exception {
}

private void handleEvent(Event event) {
s_logger.error("Need to process "+ event.getClass().getName());
s_logger.error("Event "+ event.getClass().getName() + " received, but not handled.");
}
}
13 changes: 8 additions & 5 deletions src/net/juniper/contrail/vcenter/VCenterMonitor.java
Expand Up @@ -13,6 +13,9 @@
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import org.apache.log4j.Logger;

import com.google.common.base.Throwables;

import net.juniper.contrail.sandesh.VCenterHttpServices;
import net.juniper.contrail.watchdog.TaskWatchDog;
import net.juniper.contrail.zklibrary.MasterSelection;
Expand Down Expand Up @@ -139,11 +142,11 @@ private static Properties readVcenterPluginConfigFile() {
} finally {
fileStream.close();
}
} catch (IOException ex) {
s_logger.warn("Unable to read " + _configurationFile, ex);
} catch (Exception ex) {
s_logger.error("Exception in readVcenterPluginConfigFile: " + ex);
ex.printStackTrace();
} catch (IOException e) {
s_logger.error("Unable to read " + _configurationFile, e);
} catch (Exception e) {
s_logger.error("Exception in readVcenterPluginConfigFile: " + e);
s_logger.error(Throwables.getStackTraceAsString(e));
}

return configProps;
Expand Down
50 changes: 20 additions & 30 deletions src/net/juniper/contrail/vcenter/VCenterNotify.java
Expand Up @@ -208,7 +208,8 @@ private static void unwatchManagedObject(ManagedObject mos)
pf.destroyPropertyFilter();
} catch (RemoteException e)
{
e.printStackTrace();
s_logger.error("Cannot unwatchManagedObject " + mos + " due to exception " + e);
s_logger.error(Throwables.getStackTraceAsString(e));
}
}
}
Expand Down Expand Up @@ -426,10 +427,10 @@ public void start() {
watchUpdates.start();
} catch (Exception e)
{
System.out.println("Caught Exception : " + " Name : "
s_logger.error("Caught Exception : " + " Name : "
+ e.getClass().getName() + " Message : " + e.getMessage()
+ " Trace : ");
e.printStackTrace();
s_logger.error(Throwables.getStackTraceAsString(e));
}
}

Expand All @@ -450,15 +451,12 @@ private boolean connect2vnc() {
s_logger.info("Connecting to the API server ...");
while (vncDB.Initialize() != true) {
s_logger.info("Waiting for API server ...");
Thread.sleep(1000);
Thread.sleep(5000);
}
s_logger.info("Connected to the API server ...");
} catch (Exception e) {
String stackTrace = Throwables.getStackTraceAsString(e);
s_logger.error("Error while initializing connection with the API server: "
+ e);
s_logger.error(stackTrace);
e.printStackTrace();
s_logger.error("Error while initializing connection with the API server: " + e);
s_logger.error(Throwables.getStackTraceAsString(e));
TaskWatchDog.stopMonitoring(this);
return false;
}
Expand All @@ -475,10 +473,8 @@ private void connect2vcenter() {
vCenterConnected = true;
}
} catch (Exception e) {
String stackTrace = Throwables.getStackTraceAsString(e);
s_logger.error("Error while initializing VCenter connection: " + e);
s_logger.error(stackTrace);
e.printStackTrace();
s_logger.error("Error while initializing VCenter connection: ");
s_logger.error(Throwables.getStackTraceAsString(e));
}
TaskWatchDog.stopMonitoring(this);
}
Expand All @@ -498,7 +494,7 @@ public void run()
//check if you are the master from time to time
//sometimes things don't go as planned
if (VCenterMonitor.isZookeeperLeader() == false) {
s_logger.debug("Lost zookeeper leadership. Restarting myself\n");
s_logger.warn("Lost zookeeper leadership. Restarting myself\n");
System.exit(0);
}

Expand Down Expand Up @@ -526,10 +522,8 @@ public void run()
syncNeeded = false;
} catch (Exception e) {
vCenterConnected = false;
String stackTrace = Throwables.getStackTraceAsString(e);
s_logger.error("Error in sync: " + e);
s_logger.error(stackTrace);
e.printStackTrace();
s_logger.error(Throwables.getStackTraceAsString(e));
TaskWatchDog.stopMonitoring(this);
continue;
}
Expand Down Expand Up @@ -571,17 +565,12 @@ public void run()
}
} catch (RemoteException e) {
vCenterConnected = false;
s_logger.info("Vcenter disconnected, reconnect and resync needed");
String stackTrace = Throwables.getStackTraceAsString(e);
s_logger.info(stackTrace);
e.printStackTrace();
}
catch (Exception e) {
s_logger.info("Vcenter disconnected, reconnect and resync needed: " + e);
s_logger.info(Throwables.getStackTraceAsString(e));
} catch (Exception e) {
vCenterConnected = false;
s_logger.error("Error in event handling, reconnect and resync needed");
String stackTrace = Throwables.getStackTraceAsString(e);
s_logger.error(stackTrace);
e.printStackTrace();
s_logger.error(Throwables.getStackTraceAsString(e));
}
}
} catch (Exception e)
Expand All @@ -594,8 +583,7 @@ public void run()
s_logger.error("Caught Exception : " + " Name : "
+ e.getClass().getName() + " Message : "
+ e.getMessage() + " Trace : ");
String stackTrace = Throwables.getStackTraceAsString(e);
s_logger.error(stackTrace);
s_logger.error(Throwables.getStackTraceAsString(e));
}
}
}
Expand Down Expand Up @@ -708,7 +696,8 @@ private void watchManagedObjectEvents(ManagedObject mos, String[] events)
}
} catch(Exception e)
{
e.printStackTrace();
s_logger.error("Cannot watchManagedObjectEvents for " + mos + ", exception " + e);
s_logger.error(Throwables.getStackTraceAsString(e));
throw new RuntimeException(e);
}
}
Expand All @@ -730,7 +719,8 @@ private void unwatchManagedObjectEvents(ManagedObject mos)
}
} catch (RemoteException e)
{
e.printStackTrace();
s_logger.error("Cannot unwatchManagedObjectEvents for " + mos + ", exception " + e);
s_logger.error(Throwables.getStackTraceAsString(e));
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/net/juniper/contrail/vcenter/VRouterMonitorTask.java
Expand Up @@ -18,7 +18,7 @@ public void run() {
//check if you are the master from time to time
//sometimes things don't go as planned
if (VCenterMonitor.isZookeeperLeader() == false) {
s_logger.debug("Lost zookeeper leadership. Restarting myself\n");
s_logger.warn("Lost zookeeper leadership. Restarting myself\n");
System.exit(0);
}

Expand All @@ -33,10 +33,8 @@ private void checkVroutersConnection() {
// run KeepAlive with vRouter Agent.
VRouterNotifier.vrouterAgentPeriodicConnectionCheck();
} catch (Exception e) {
String stackTrace = Throwables.getStackTraceAsString(e);
s_logger.error("Error while vrouterAgentPeriodicConnectionCheck: " + e);
s_logger.error(stackTrace);
e.printStackTrace();
s_logger.error(Throwables.getStackTraceAsString(e));
}

TaskWatchDog.stopMonitoring(this);
Expand Down
4 changes: 1 addition & 3 deletions src/net/juniper/contrail/vcenter/VRouterNotifier.java
Expand Up @@ -87,9 +87,7 @@ public static void created(VirtualMachineInterfaceInfo vmiInfo) {
} catch(Throwable e) {
s_logger.warn("vRouter " + vrouterIpAddress + " Exception in addPort for "
+ vmiInfo + ": " + e.getMessage());
String stackTrace = Throwables.getStackTraceAsString(e);
s_logger.error(stackTrace);
e.printStackTrace();
s_logger.error(Throwables.getStackTraceAsString(e));
}
}

Expand Down
6 changes: 1 addition & 5 deletions src/net/juniper/contrail/vcenter/VirtualMachineInfo.java
@@ -1,6 +1,5 @@
package net.juniper.contrail.vcenter;

import org.apache.log4j.Logger;
import com.vmware.vim25.VirtualMachinePowerState;
import com.vmware.vim25.VirtualMachineRuntimeInfo;
import com.vmware.vim25.VirtualMachineConfigInfo;
Expand Down Expand Up @@ -43,9 +42,6 @@ public class VirtualMachineInfo extends VCenterObject {
//API server objects
net.juniper.contrail.api.types.VirtualMachine apiVm;

private final Logger s_logger =
Logger.getLogger(VirtualMachineInfo.class);

public VirtualMachineInfo(String uuid) {
if (uuid == null) {
throw new IllegalArgumentException("Cannot init VM with null uuid");
Expand Down Expand Up @@ -160,7 +156,7 @@ public VirtualMachineInfo(net.juniper.contrail.api.types.VirtualMachine vm) {

public VirtualMachineInfo(VCenterDB vcenterDB,
com.vmware.vim25.mo.Datacenter dc, String dcName,
com.vmware.vim25.mo.VirtualMachine vm, Hashtable pTable,
com.vmware.vim25.mo.VirtualMachine vm, @SuppressWarnings("rawtypes") Hashtable pTable,
com.vmware.vim25.mo.HostSystem host,
String vrouterIpAddress)
throws Exception {
Expand Down

0 comments on commit 25512ed

Please sign in to comment.