use of alien4cloud.paas.model.PaaSInstancePersistentResourceMonitorEvent in project alien4cloud by alien4cloud.
the class MockPaaSProvider method notifyInstanceStateChanged.
private void notifyInstanceStateChanged(final String deploymentPaaSId, final String nodeId, final String instanceId, final InstanceInformation information, long delay) {
final InstanceInformation cloned = new InstanceInformation();
cloned.setAttributes(information.getAttributes());
cloned.setInstanceStatus(information.getInstanceStatus());
cloned.setRuntimeProperties(information.getRuntimeProperties());
cloned.setState(information.getState());
executorService.schedule(new Runnable() {
@Override
public void run() {
final MockRuntimeDeploymentInfo deploymentInfo = runtimeDeploymentInfos.get(deploymentPaaSId);
Deployment deployment = deploymentInfo.getDeploymentContext().getDeployment();
PaaSInstanceStateMonitorEvent event;
event = new PaaSInstanceStateMonitorEvent();
event.setInstanceId(instanceId.toString());
event.setInstanceState(cloned.getState());
event.setInstanceStatus(cloned.getInstanceStatus());
event.setNodeTemplateId(nodeId);
event.setDate((new Date()).getTime());
event.setDeploymentId(paaSDeploymentIdToAlienDeploymentIdMap.get(deploymentPaaSId));
event.setRuntimeProperties(cloned.getRuntimeProperties());
event.setAttributes(cloned.getAttributes());
toBeDeliveredEvents.add(event);
if (deployment.getSourceName().equals(BLOCKSTORAGE_APPLICATION) && cloned.getState().equalsIgnoreCase("created")) {
PaaSInstancePersistentResourceMonitorEvent prme = new PaaSInstancePersistentResourceMonitorEvent(nodeId, instanceId.toString(), MapUtil.newHashMap(new String[] { NormativeBlockStorageConstants.VOLUME_ID }, new Object[] { UUID.randomUUID().toString() }));
prme.setDeploymentId(deployment.getId());
toBeDeliveredEvents.add(prme);
}
PaaSMessageMonitorEvent messageMonitorEvent = new PaaSMessageMonitorEvent();
messageMonitorEvent.setDate((new Date()).getTime());
messageMonitorEvent.setDeploymentId(paaSDeploymentIdToAlienDeploymentIdMap.get(deploymentPaaSId));
messageMonitorEvent.setMessage("APPLICATIONS.RUNTIME.EVENTS.MESSAGE_EVENT.INSTANCE_STATE_CHANGED");
toBeDeliveredEvents.add(messageMonitorEvent);
}
}, delay, TimeUnit.SECONDS);
}
use of alien4cloud.paas.model.PaaSInstancePersistentResourceMonitorEvent in project yorc-a4c-plugin by ystia.
the class EventListenerTask method run.
public void run() {
int prevIndex = 1;
while (true) {
try {
log.debug("Get events from Yorc from index " + prevIndex);
EventResponse eventResponse = restClient.getEventFromYorc(prevIndex);
if (eventResponse != null) {
prevIndex = eventResponse.getLast_index();
if (eventResponse.getEvents() != null) {
for (Event event : eventResponse.getEvents()) {
String paasId = event.getDeployment_id();
YorcRuntimeDeploymentInfo jrdi = orchestrator.getDeploymentInfo(paasId);
if (jrdi == null) {
log.error("listenYorcEvents: no YorcRuntimeDeploymentInfo for " + paasId);
continue;
}
Map<String, Map<String, InstanceInformation>> instanceInfo = jrdi.getInstanceInformations();
paasId = event.getDeployment_id();
// Check type of Event sent by Yorc and process it
String eState = event.getStatus();
String eMessage = paasId + " - Yorc Event: ";
if (event.getType() == null) {
log.warn("Yorc version is obsolete. Please use a newer version");
event.setType(EVT_INSTANCE);
}
switch(event.getType()) {
case EVT_INSTANCE:
String eNode = event.getNode();
String eInstance = event.getInstance();
eMessage += "instance " + eNode + ":" + eInstance + ":" + eState;
log.debug("Received Event from Yorc <<< " + eMessage);
Map<String, InstanceInformation> ninfo = instanceInfo.get(eNode);
if (ninfo == null) {
// Add a new Node in YorcRuntimeDeploymentInfo
log.debug("Add a node in YorcRuntimeDeploymentInfo: " + eNode);
ninfo = Maps.newHashMap();
instanceInfo.put(eNode, ninfo);
}
InstanceInformation iinfo = ninfo.get(eInstance);
if (iinfo == null) {
// Add a new Instance for this node in YorcRuntimeDeploymentInfo
log.debug("Add an instance in YorcRuntimeDeploymentInfo: " + eInstance);
iinfo = orchestrator.newInstance(new Integer(eInstance));
ninfo.put(eInstance, iinfo);
}
orchestrator.updateInstanceState(paasId, eNode, eInstance, iinfo, eState);
switch(eState) {
case "initial":
case "creating":
case "deleting":
case "starting":
case "stopping":
case "configured":
case "configuring":
case "created":
break;
case "deleted":
ninfo.remove(eInstance);
break;
case "stopped":
orchestrator.updateInstanceAttributes(paasId, iinfo, eNode, eInstance);
break;
case "started":
orchestrator.updateInstanceAttributes(paasId, iinfo, eNode, eInstance);
// persist BS Id
String source = jrdi.getDeploymentContext().getDeployment().getSourceName();
if (source.equals("BLOCKSTORAGE_APPLICATION")) {
PaaSInstancePersistentResourceMonitorEvent prme = new PaaSInstancePersistentResourceMonitorEvent(eNode, eInstance, MapUtil.newHashMap(new String[] { NormativeBlockStorageConstants.VOLUME_ID }, new Object[] { UUID.randomUUID().toString() }));
orchestrator.postEvent(prme, paasId);
}
break;
case "error":
log.warn("Error instance status");
break;
default:
log.warn("Unknown instance status: " + eState);
break;
}
break;
case EVT_DEPLOYMENT:
case EVT_OPERATION:
case EVT_SCALING:
case EVT_WORKFLOW:
eMessage += event.getType() + ":" + eState;
log.debug("Received Event from Yorc <<< " + eMessage);
synchronized (jrdi) {
if (jrdi.getLastEvent() != null) {
log.debug("Event not taken, forgot it: " + jrdi.getLastEvent());
}
jrdi.setLastEvent(event);
jrdi.notifyAll();
}
break;
default:
log.warn("Unknown event type received from Yorc <<< " + event.getType());
break;
}
}
}
}
} catch (Exception e) {
log.error("listenDeploymentEvent Failed", e);
try {
// We will sleep for 2sec in order to limit logs flood if the yorc server went down
Thread.sleep(2000L);
} catch (InterruptedException ex) {
log.error("listenDeploymentEvent wait interrupted", ex);
}
}
}
}
Aggregations