return;
}
ProvisionMonitor remoteMonitor = (ProvisionMonitor)eventSource;
String opStringName = null;
OpStringManager opMgr;
ProvisionMonitorEvent pme = (ProvisionMonitorEvent)event;
OperationalString opString = pme.getOperationalString();
ServiceElement sElem = pme.getServiceElement();
ProvisionMonitorEvent.Action action = pme.getAction();
switch(action) {
case SERVICE_ELEMENT_UPDATED:
case SERVICE_BEAN_INCREMENTED:
case SERVICE_BEAN_DECREMENTED:
String sAction = action.toString();
if(sElem == null) {
peerLogger.debug("ProvisionMonitorPeer: {} sElem is null", sAction);
return;
}
opStringName = sElem.getOperationalStringName();
peerLogger.trace("ProvisionMonitorPeer: {}, opstring: {}", sAction, opStringName);
opMgr = opStringMangerController.getOpStringManager(opStringName);
if(opMgr == null) {
peerLogger.debug("ProvisionMonitorPeer: {} opstring [{}] not found", sAction, opStringName);
return;
}
try {
opMgr.doUpdateServiceElement(sElem);
} catch(Exception e) {
peerLogger.warn("Updating OperationalStringManager's ServiceElement", e);
}
break;
case SERVICE_ELEMENT_ADDED:
if(sElem == null) {
peerLogger.warn("ProvisionMonitorPeer: SERVICE_ELEMENT_ADDED sElem is null");
return;
}
opStringName = sElem.getOperationalStringName();
peerLogger.trace("ProvisionMonitorPeer: SERVICE_ELEMENT_ADDED, opstring: {}", opStringName);
opMgr = opStringMangerController.getOpStringManager(opStringName);
if(opMgr == null) {
peerLogger.debug("ProvisionMonitorPeer: SERVICE_ELEMENT_ADDED opstring [{}] not found" ,opStringName);
return;
}
try {
opMgr.doAddServiceElement(sElem, null);
} catch(Exception e) {
peerLogger.warn("Adding ServiceElement to OperationalStringManager", e);
}
break;
case SERVICE_ELEMENT_REMOVED:
if(sElem == null) {
peerLogger.debug("ProvisionMonitorPeer: SERVICE_ELEMENT_REMOVED sElem is null");
return;
}
opStringName = sElem.getOperationalStringName();
peerLogger.trace("ProvisionMonitorPeer: SERVICE_ELEMENT_REMOVED, opstring: {}", opStringName);
opMgr = opStringMangerController.getOpStringManager(opStringName);
if(opMgr == null) {
peerLogger.debug("ProvisionMonitorPeer: SERVICE_ELEMENT_REMOVED opstring [{}] not found",
opStringName);
return;
}
try {
opMgr.doRemoveServiceElement(sElem, false);
} catch(Exception e) {
peerLogger.warn("Removing ServiceElement from OperationalStringManager", e);
}
break;
case OPSTRING_DEPLOYED:
if(opString == null) {
peerLogger.warn("ProvisionMonitorPeer: OPSTRING_DEPLOYED opstring is null");
return;
}
DeployAdmin deployAdmin = (DeployAdmin)remoteMonitor.getAdmin();
opStringProcessor(opString, remoteMonitor, deployAdmin, pme.getRemoteRepositories());
peerLogger.trace("ProvisionMonitorPeer: OPSTRING_DEPLOYED, opstring: {}", opString.getName());
break;
case OPSTRING_UNDEPLOYED:
if(opString == null) {
peerLogger.debug("ProvisionMonitorPeer: OPSTRING_UNDEPLOYED opstring is null");
return;
}
peerLogger.trace("ProvisionMonitorPeer: OPSTRING_UNDEPLOYED, opstring: {}", opString.getName());
opMgr = opStringMangerController.getOpStringManager(opString.getName());
if(opMgr == null) {
peerLogger.debug("ProvisionMonitorPeer: OPSTRING_UNDEPLOYED for opstring [{}] not found",
opString.getName());
return;
}
opMgr.setDeploymentStatus(OperationalString.UNDEPLOYED);
opMgr.terminate(false);
synchronized(opStringTable) {
if(opStringTable.containsKey(remoteMonitor)) {
List<OpStringManager> list = opStringTable.get(remoteMonitor);
list.remove(opMgr);
opStringTable.put(remoteMonitor, list);
}
}
break;
case OPSTRING_MGR_CHANGED:
if(opString == null) {
peerLogger.debug("ProvisionMonitorPeer: OPSTRING_MGR_CHANGED opstring is null");
return;
}
peerLogger.debug("ProvisionMonitorPeer: OPSTRING_MGR_CHANGED, opstring: {}", opString.getName());
opMgr = opStringMangerController.getOpStringManager(opString.getName());
if(opMgr == null) {
peerLogger.debug("ProvisionMonitorPeer: OPSTRING_MGR_CHANGED opstring [{}] not found",
opString.getName());
return;
}
synchronized(opStringTable) {
List<OpStringManager> list;
if(opStringTable.containsKey(remoteMonitor))
list = opStringTable.get(remoteMonitor);
else
list = new ArrayList<OpStringManager>();
if(!list.contains(opMgr)) {
list.add(opMgr);
opStringTable.put(remoteMonitor, list);
peerLogger.debug("ProvisionMonitorPeer: Reset backup peer for [{}] to {}",
opString.getName(), remoteMonitor.toString());
} else {
peerLogger.debug("ProvisionMonitorPeer: Already a backup for [{}] to {}",
opString.getName(), remoteMonitor.toString());
}
}
break;
case OPSTRING_UPDATED:
if(opString == null) {
peerLogger.debug("ProvisionMonitorPeer: OPSTRING_UNDEPLOYED opstring is null");
return;
}
peerLogger.trace("ProvisionMonitorPeer: OPSTRING_UPDATED, opstring: {}", opString.getName());
opMgr = opStringMangerController.getOpStringManager(opString.getName());
if(opMgr == null) {
peerLogger.debug("ProvisionMonitorPeer: OPSTRING_UPDATED for opstring [{}] not found",
opString.getName());
return;
}
opMgr.doUpdateOperationalString(opString);
break;
case SERVICE_BEAN_INSTANCE_UPDATED:
ServiceBeanInstance instance = pme.getServiceBeanInstance();
if(instance == null) {
peerLogger.debug("ProvisionMonitorPeer: SERVICE_BEAN_INSTANCE_UPDATED instance is null");
return;
}
opStringName = pme.getOperationalStringName();
peerLogger.trace("ProvisionMonitorPeer: SERVICE_BEAN_INSTANCE_UPDATED, opstring: {}", opStringName);
opMgr = opStringMangerController.getOpStringManager(opStringName);
if(opMgr == null) {
peerLogger.debug("ProvisionMonitorPeer: SERVICE_BEAN_INSTANCE_UPDATED for opstring [{}] not found",
opStringName);
return;
}
try {
opMgr.doUpdateServiceBeanInstance(instance);
} catch(Exception e) {
peerLogger.warn("Updating OperationalStringManager's ServiceBeanInstance", e);
}
break;
case SERVICE_PROVISIONED:
instance = pme.getServiceBeanInstance();
if(instance == null) {
peerLogger.debug("ProvisionMonitorPeer: SERVICE_PROVISIONED instance is null");
return;
}
opStringName = pme.getOperationalStringName();
peerLogger.trace("ProvisionMonitorPeer: SERVICE_PROVISIONED, opstring: {}", opStringName);
opMgr = opStringMangerController.getOpStringManager(opStringName);
if(opMgr == null) {
peerLogger.debug("ProvisionMonitorPeer: SERVICE_PROVISIONED for opstring [{}] " +
"OpStringManager not found", opStringName);
return;
}
ServiceElementManager mgr = opMgr.getServiceElementManager(sElem);
if(mgr==null) {
peerLogger.debug("ProvisionMonitorPeer: SERVICE_PROVISIONED for " +
"opstring [{}] ServiceElementManager not found", opStringName);
return;
}
boolean isStarted = mgr.isStarted();
while(!isStarted) {
try {
Thread.sleep(1000);
isStarted = mgr.isStarted();
} catch(InterruptedException ignore) {
/* Ignore */
}
}
mgr.importServiceBeanInstance(instance);
ServiceChannel channel = ServiceChannel.getInstance();
channel.broadcast(new ServiceChannelEvent(this, sElem, ServiceChannelEvent.Type.PROVISIONED));
break;
case REDEPLOY_REQUEST:
opMgr = opStringMangerController.getOpStringManager(pme.getOperationalStringName());
if(opMgr == null) {
peerLogger.debug("ProvisionMonitorPeer: REDEPLOY_REQUEST opstring [{}] not found", opStringName);
return;
}
Object[] parms = pme.getRedeploymentParms();
Date redeployDate = (Date)parms[0];
boolean clean = (Boolean) parms[1];
boolean sticky = (Boolean) parms[2];
ServiceProvisionListener listener =
(ServiceProvisionListener)parms[3];
long delay = redeployDate.getTime() - System.currentTimeMillis();
if(delay <= 0) {
peerLogger.debug("ProvisionMonitorPeer: REDEPLOY_REQUEST for opstring " +
"[{}] startTime has already passed, scheduled " +
"redeployment cancelled", opStringName);
} else {
opMgr.doScheduleRedeploymentTask(delay,
pme.getServiceElement(),
pme.getServiceBeanInstance(),
clean,
sticky,
listener);
}
break;