Search in sources :

Example 1 with PaaSInstancePersistentResourceMonitorEvent

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);
}
Also used : PaaSInstanceStateMonitorEvent(alien4cloud.paas.model.PaaSInstanceStateMonitorEvent) PaaSInstancePersistentResourceMonitorEvent(alien4cloud.paas.model.PaaSInstancePersistentResourceMonitorEvent) InstanceInformation(alien4cloud.paas.model.InstanceInformation) Deployment(alien4cloud.model.deployment.Deployment) PaaSMessageMonitorEvent(alien4cloud.paas.model.PaaSMessageMonitorEvent) Date(java.util.Date)

Example 2 with PaaSInstancePersistentResourceMonitorEvent

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);
            }
        }
    }
}
Also used : InstanceInformation(alien4cloud.paas.model.InstanceInformation) PaaSInstancePersistentResourceMonitorEvent(alien4cloud.paas.model.PaaSInstancePersistentResourceMonitorEvent) EventResponse(org.ystia.yorc.alien4cloud.plugin.rest.Response.EventResponse) Event(org.ystia.yorc.alien4cloud.plugin.rest.Response.Event) PaaSInstancePersistentResourceMonitorEvent(alien4cloud.paas.model.PaaSInstancePersistentResourceMonitorEvent) Map(java.util.Map)

Aggregations

InstanceInformation (alien4cloud.paas.model.InstanceInformation)2 PaaSInstancePersistentResourceMonitorEvent (alien4cloud.paas.model.PaaSInstancePersistentResourceMonitorEvent)2 Deployment (alien4cloud.model.deployment.Deployment)1 PaaSInstanceStateMonitorEvent (alien4cloud.paas.model.PaaSInstanceStateMonitorEvent)1 PaaSMessageMonitorEvent (alien4cloud.paas.model.PaaSMessageMonitorEvent)1 Date (java.util.Date)1 Map (java.util.Map)1 Event (org.ystia.yorc.alien4cloud.plugin.rest.Response.Event)1 EventResponse (org.ystia.yorc.alien4cloud.plugin.rest.Response.EventResponse)1