Search in sources :

Example 1 with PaaSDeploymentStatusMonitorEvent

use of alien4cloud.paas.model.PaaSDeploymentStatusMonitorEvent in project alien4cloud by alien4cloud.

the class PaaSProviderPollingMonitorTest method initEvents.

private void initEvents() throws JsonProcessingException, InterruptedException {
    // add 2 message events
    PaaSMessageMonitorEvent eventMessage = null;
    String eventJson = null;
    int i = 0;
    for (i = 0; i < 2; i++) {
        eventMessage = new PaaSMessageMonitorEvent();
        eventMessage.setOrchestratorId("CloudID");
        eventMessage.setDate(addMinutesToDate(2, new Date()).getTime());
        eventMessage.setDeploymentId("ID-XXX+" + i);
        eventMessage.setMessage("EVENT MESSAGE : " + eventMessage.getDate());
        eventJson = jsonMapper.writeValueAsString(eventMessage);
        nodeClient.prepareIndex("deploymentmonitorevents", PaaSMessageMonitorEvent.class.getSimpleName().toLowerCase()).setSource(eventJson).setRefresh(true).execute().actionGet();
    }
    // add 3 deployment status events
    PaaSDeploymentStatusMonitorEvent eventDeploymentStatus = null;
    for (i = 0; i < 3; i++) {
        eventDeploymentStatus = new PaaSDeploymentStatusMonitorEvent();
        eventDeploymentStatus.setOrchestratorId("CloudID");
        eventDeploymentStatus.setDate(addMinutesToDate(2, new Date()).getTime());
        eventDeploymentStatus.setDeploymentId("DEP_ID-" + i);
        eventDeploymentStatus.setDeploymentStatus(DeploymentStatus.DEPLOYED);
        eventJson = jsonMapper.writeValueAsString(eventDeploymentStatus);
        nodeClient.prepareIndex("deploymentmonitorevents", PaaSDeploymentStatusMonitorEvent.class.getSimpleName().toLowerCase()).setSource(eventJson).setRefresh(true).execute().actionGet();
    }
    // save the last inserted date (PaaSDeploymentStatusMonitorEvent should be generated from alien only and never from the orchestrator).
    latestEventDate = new Date(eventMessage.getDate());
    latestStatusDate = new Date(eventDeploymentStatus.getDate());
}
Also used : PaaSDeploymentStatusMonitorEvent(alien4cloud.paas.model.PaaSDeploymentStatusMonitorEvent) PaaSMessageMonitorEvent(alien4cloud.paas.model.PaaSMessageMonitorEvent) Date(java.util.Date)

Example 2 with PaaSDeploymentStatusMonitorEvent

use of alien4cloud.paas.model.PaaSDeploymentStatusMonitorEvent in project alien4cloud by alien4cloud.

the class DeploymentStatusEventHandler method eventHappened.

@Override
public void eventHappened(AbstractMonitorEvent aEvent) {
    PaaSDeploymentStatusMonitorEvent event = (PaaSDeploymentStatusMonitorEvent) aEvent;
    log.debug("Received a deployment status event for deployment {} with a new status to {}", event.getDeploymentId(), event.getDeploymentStatus());
    if (DeploymentStatus.UNDEPLOYED.equals(event.getDeploymentStatus())) {
        Deployment deployment = deploymentService.get(event.getDeploymentId());
        if (deployment == null) {
            log.error("No deployment with id {} can be found while processing status event with status update to {}.", event.getDeploymentId(), event.getDeploymentStatus());
            return;
        }
        deploymentService.markUndeployed(deployment);
        log.debug("Deployment {} end date has been updated to {} based on received UNDEPLOYED status event", event.getDeploymentId(), deployment.getEndDate());
    }
}
Also used : PaaSDeploymentStatusMonitorEvent(alien4cloud.paas.model.PaaSDeploymentStatusMonitorEvent) Deployment(alien4cloud.model.deployment.Deployment)

Example 3 with PaaSDeploymentStatusMonitorEvent

use of alien4cloud.paas.model.PaaSDeploymentStatusMonitorEvent in project alien4cloud by alien4cloud.

the class DeploymentEventHandler method send.

protected void send(AbstractMonitorEvent event) {
    String eventType = MappingBuilder.indexTypeFromClass(event.getClass());
    String topicName = TOPIC_PREFIX + '/' + event.getDeploymentId() + '/' + eventType;
    dispatchEvent(event, topicName);
    if (event instanceof PaaSDeploymentStatusMonitorEvent) {
        Deployment deployment = alienDAO.findById(Deployment.class, event.getDeploymentId());
        if (deployment != null && deployment.getEnvironmentId() != null) {
            // dispatch an event on the environment topic
            topicName = ENV_TOPIC_PREFIX + "/" + deployment.getEnvironmentId();
            dispatchEvent(event, topicName);
        }
    }
}
Also used : PaaSDeploymentStatusMonitorEvent(alien4cloud.paas.model.PaaSDeploymentStatusMonitorEvent) Deployment(alien4cloud.model.deployment.Deployment)

Example 4 with PaaSDeploymentStatusMonitorEvent

use of alien4cloud.paas.model.PaaSDeploymentStatusMonitorEvent in project alien4cloud by alien4cloud.

the class MockPaaSProvider method doChangeStatus.

@Override
protected synchronized DeploymentStatus doChangeStatus(final String deploymentPaaSId, final DeploymentStatus status) {
    MockRuntimeDeploymentInfo runtimeDeploymentInfo = runtimeDeploymentInfos.get(deploymentPaaSId);
    DeploymentStatus oldDeploymentStatus = runtimeDeploymentInfo.getStatus();
    log.info("Deployment [" + deploymentPaaSId + "] moved from status [" + oldDeploymentStatus + "] to [" + status + "]");
    runtimeDeploymentInfo.setStatus(status);
    PaaSDeploymentLog deploymentLog = new PaaSDeploymentLog();
    deploymentLog.setDeploymentId(paaSDeploymentIdToAlienDeploymentIdMap.get(deploymentPaaSId));
    deploymentLog.setContent("Change deployment status to " + status);
    deploymentLog.setDeploymentPaaSId(deploymentPaaSId);
    deploymentLog.setLevel(PaaSDeploymentLogLevel.INFO);
    deploymentLog.setTimestamp(new Date());
    deploymentLog.setType("deployment_status_change");
    deploymentLog.setWorkflowId("install");
    alienMonitorDao.getClient().admin().indices().prepareRefresh(PaaSDeploymentLog.class.getSimpleName().toLowerCase()).execute().actionGet();
    deploymentLoggingService.save(deploymentLog);
    executorService.schedule(new Runnable() {

        @Override
        public void run() {
            PaaSDeploymentStatusMonitorEvent event = new PaaSDeploymentStatusMonitorEvent();
            event.setDeploymentStatus(status);
            event.setDate((new Date()).getTime());
            event.setDeploymentId(paaSDeploymentIdToAlienDeploymentIdMap.get(deploymentPaaSId));
            toBeDeliveredEvents.add(event);
            PaaSMessageMonitorEvent messageMonitorEvent = new PaaSMessageMonitorEvent();
            messageMonitorEvent.setDate((new Date()).getTime());
            messageMonitorEvent.setDeploymentId(paaSDeploymentIdToAlienDeploymentIdMap.get(deploymentPaaSId));
            messageMonitorEvent.setMessage("APPLICATIONS.RUNTIME.EVENTS.MESSAGE_EVENT.STATUS_DEPLOYMENT_CHANGED");
            toBeDeliveredEvents.add(messageMonitorEvent);
        }
    }, 2, TimeUnit.SECONDS);
    return oldDeploymentStatus;
}
Also used : PaaSDeploymentStatusMonitorEvent(alien4cloud.paas.model.PaaSDeploymentStatusMonitorEvent) PaaSMessageMonitorEvent(alien4cloud.paas.model.PaaSMessageMonitorEvent) DeploymentStatus(alien4cloud.paas.model.DeploymentStatus) Date(java.util.Date) PaaSDeploymentLog(alien4cloud.paas.model.PaaSDeploymentLog)

Example 5 with PaaSDeploymentStatusMonitorEvent

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

the class YorcPaaSProvider method doChangeStatus.

/**
 * Actually change the status of the deployment in YorcRuntimeDeploymentInfo
 * Must be called with lock on jrdi
 * @param paasId
 * @param status
 */
public void doChangeStatus(String paasId, DeploymentStatus status) {
    YorcRuntimeDeploymentInfo jrdi = runtimeDeploymentInfos.get(paasId);
    if (jrdi == null) {
        log.error("YorcRuntimeDeploymentInfo is null for paasId " + paasId);
        return;
    }
    if (status.equals(DeploymentStatus.UNDEPLOYED)) {
        try {
            log.debug("send deployment purge request to yorc");
            restClient.undeploy("/deployments/" + paasId, true);
        } catch (YorcRestException jre) {
            // If 400 code (bad request)  is returned, we retry requesting purge during at most 5 minutes
            if (jre.getHttpStatusCode() == 400) {
                long timeout = System.currentTimeMillis() + 1000 * 60 * 5;
                long timetowait = timeout - System.currentTimeMillis();
                boolean retry = true;
                while (retry && timetowait > 0) {
                    retry = retryDeploymentPurge(paasId);
                }
            } else // 404 status code is ignored for purge failure
            if (jre.getHttpStatusCode() != 404) {
                log.error("undeploy purge returned an exception: " + jre.getMessage());
                changeStatus(paasId, DeploymentStatus.FAILURE);
                return;
            }
        } catch (Exception e) {
            log.error("undeploy purge returned an exception: " + e.getMessage());
            changeStatus(paasId, DeploymentStatus.FAILURE);
            return;
        }
    }
    DeploymentStatus oldDeploymentStatus = jrdi.getStatus();
    log.debug("Deployment [" + paasId + "] moved from status [" + oldDeploymentStatus + "] to [" + status + "]");
    jrdi.setStatus(status);
    PaaSDeploymentStatusMonitorEvent event = new PaaSDeploymentStatusMonitorEvent();
    event.setDeploymentStatus(status);
    postEvent(event, paasId);
}
Also used : PaaSDeploymentStatusMonitorEvent(alien4cloud.paas.model.PaaSDeploymentStatusMonitorEvent) MaintenanceModeException(alien4cloud.paas.exception.MaintenanceModeException) OperationExecutionException(alien4cloud.paas.exception.OperationExecutionException) YorcRestException(org.ystia.yorc.alien4cloud.plugin.rest.YorcRestException) PluginConfigurationException(alien4cloud.paas.exception.PluginConfigurationException) DeploymentStatus(alien4cloud.paas.model.DeploymentStatus) YorcRestException(org.ystia.yorc.alien4cloud.plugin.rest.YorcRestException)

Aggregations

PaaSDeploymentStatusMonitorEvent (alien4cloud.paas.model.PaaSDeploymentStatusMonitorEvent)5 Deployment (alien4cloud.model.deployment.Deployment)2 DeploymentStatus (alien4cloud.paas.model.DeploymentStatus)2 PaaSMessageMonitorEvent (alien4cloud.paas.model.PaaSMessageMonitorEvent)2 Date (java.util.Date)2 MaintenanceModeException (alien4cloud.paas.exception.MaintenanceModeException)1 OperationExecutionException (alien4cloud.paas.exception.OperationExecutionException)1 PluginConfigurationException (alien4cloud.paas.exception.PluginConfigurationException)1 PaaSDeploymentLog (alien4cloud.paas.model.PaaSDeploymentLog)1 YorcRestException (org.ystia.yorc.alien4cloud.plugin.rest.YorcRestException)1