Search in sources :

Example 11 with InstanceInformation

use of alien4cloud.paas.model.InstanceInformation 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)

Example 12 with InstanceInformation

use of alien4cloud.paas.model.InstanceInformation in project yorc-a4c-plugin by ystia.

the class YorcPaaSProvider method switchInstanceMaintenanceMode.

/**
 * Switch the maintenance mode for a given node instance of this deployed topology.
 *
 * @param ctx the deployment context
 * @param node
 * @param instance
 * @param mode
 * @throws MaintenanceModeException
 */
@Override
public void switchInstanceMaintenanceMode(PaaSDeploymentContext ctx, String node, String instance, boolean mode) throws MaintenanceModeException {
    String paasId = ctx.getDeploymentPaaSId();
    YorcRuntimeDeploymentInfo jrdi = runtimeDeploymentInfos.get(paasId);
    log.debug(paasId + " switchInstanceMaintenanceMode");
    if (jrdi == null) {
        log.error(paasId + " switchInstanceMaintenanceMode: No Deployment Information");
        throw new MaintenanceModeException("No Deployment Information");
    }
    final Map<String, Map<String, InstanceInformation>> existingInformations = jrdi.getInstanceInformations();
    if (existingInformations != null && existingInformations.containsKey(node) && existingInformations.get(node).containsKey(instance)) {
        InstanceInformation iinfo = existingInformations.get(node).get(instance);
        doSwitchInstanceMaintenanceMode(paasId, node, instance, iinfo, mode);
    }
}
Also used : MaintenanceModeException(alien4cloud.paas.exception.MaintenanceModeException) InstanceInformation(alien4cloud.paas.model.InstanceInformation) Map(java.util.Map)

Aggregations

InstanceInformation (alien4cloud.paas.model.InstanceInformation)12 Map (java.util.Map)11 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)5 Topology (org.alien4cloud.tosca.model.templates.Topology)4 Deployment (alien4cloud.model.deployment.Deployment)2 MaintenanceModeException (alien4cloud.paas.exception.MaintenanceModeException)2 PaaSInstancePersistentResourceMonitorEvent (alien4cloud.paas.model.PaaSInstancePersistentResourceMonitorEvent)2 NodeType (org.alien4cloud.tosca.model.types.NodeType)2 Application (alien4cloud.model.application.Application)1 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)1 OrchestratorDisabledException (alien4cloud.paas.exception.OrchestratorDisabledException)1 DeploymentStatus (alien4cloud.paas.model.DeploymentStatus)1 PaaSInstanceStateMonitorEvent (alien4cloud.paas.model.PaaSInstanceStateMonitorEvent)1 PaaSMessageMonitorEvent (alien4cloud.paas.model.PaaSMessageMonitorEvent)1 PaaSNodeTemplate (alien4cloud.paas.model.PaaSNodeTemplate)1 RestResponse (alien4cloud.rest.model.RestResponse)1 ApiOperation (io.swagger.annotations.ApiOperation)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1