All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aeontronix.enhancedmule.tools.runtime.HDeploymentResult Maven / Gradle / Ivy

There is a newer version: 2.0.0-alpha4
Show newest version
/*
 * Copyright (c) Aeontronix 2019
 */

package com.aeontronix.enhancedmule.tools.runtime;

import com.aeontronix.enhancedmule.tools.util.HttpException;
import com.aeontronix.commons.ThreadUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class HDeploymentResult extends DeploymentResult {
    private static final Logger logger = LoggerFactory.getLogger(HDeploymentResult.class);
    static final String DEPLOYMENT_FAILED = "DEPLOYMENT_FAILED";
    static final String STARTED = "STARTED";
    private HApplication application;

    public HDeploymentResult(HApplication application) {
        this.application = application;
    }

    @Override
    public void waitDeployed(long timeout, long retryDelay) throws HttpException, ApplicationDeploymentFailedException {
        ThreadUtils.sleep(2000);
        long expires = System.currentTimeMillis() + timeout;
        for (; ; ) {
            application = application.refresh();
            if (application.getDesiredStatus().equalsIgnoreCase("UPDATED")) {
                // app hasn't started yet
            } else if (application.isStarted()) {
                return;
            } else if (DEPLOYMENT_FAILED.equals(application.getLastReportedStatus())) {
                logger.debug("Deployment failed due to status: " + application.getLastReportedStatus());
                throw ApplicationDeploymentFailedException.create(application);
            } else {
                if (expires > System.currentTimeMillis()) {
                    ThreadUtils.sleep(retryDelay);
                } else {
                    logger.error("Deployment failed due to timeout");
                    throw ApplicationDeploymentFailedException.create(application);
                }
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy