Search in sources :

Example 1 with ITException

use of alien4cloud.it.exception.ITException in project alien4cloud by alien4cloud.

the class ApplicationsDeploymentStepDefinitions method checkStatus.

@SuppressWarnings("rawtypes")
private void checkStatus(String applicationName, String deploymentId, DeploymentStatus expectedStatus, Set<DeploymentStatus> pendingStatus, long timeout, String applicationEnvironmentName, boolean failover) throws Throwable {
    String statusRequest = null;
    String applicationEnvironmentId = null;
    String applicationId = applicationName != null ? Context.getInstance().getApplicationId(applicationName) : null;
    if (deploymentId != null) {
        statusRequest = "/rest/v1/deployments/" + deploymentId + "/status";
    } else if (applicationId != null) {
        applicationEnvironmentId = applicationEnvironmentName != null ? Context.getInstance().getApplicationEnvironmentId(applicationName, applicationEnvironmentName) : Context.getInstance().getDefaultApplicationEnvironmentId(applicationName);
        statusRequest = "/rest/v1/applications/" + applicationId + "/environments/" + applicationEnvironmentId + "/status";
    } else {
        throw new ITException("Expected at least application ID OR deployment ID to check the status.");
    }
    long now = System.currentTimeMillis();
    while (true) {
        if (System.currentTimeMillis() - now > timeout) {
            if (failover) {
                log.warn("Expected deployment to be [" + expectedStatus + "] but Test has timeouted");
                return;
            } else {
                throw new ITException("Expected deployment to be [" + expectedStatus + "] but Test has timeouted");
            }
        }
        // get the current status
        String restResponseText = Context.getRestClientInstance().get(statusRequest);
        RestResponse<String> statusResponse = JsonUtil.read(restResponseText, String.class);
        assertNull(statusResponse.getError());
        DeploymentStatus deploymentStatus = DeploymentStatus.valueOf(statusResponse.getData());
        if (deploymentStatus.equals(expectedStatus)) {
            if (applicationId != null) {
                String restInfoResponseText = Context.getRestClientInstance().get("/rest/v1/applications/" + applicationId + "/environments/" + applicationEnvironmentId + "/deployment/informations");
                RestResponse<?> infoResponse = JsonUtil.read(restInfoResponseText);
                assertNull(infoResponse.getError());
            }
            return;
        } else if (pendingStatus.contains(deploymentStatus)) {
            Thread.sleep(1000L);
        } else {
            if (applicationId != null) {
                if (failover) {
                    log.warn("Expected deployment of app [" + applicationId + "] to be [" + expectedStatus + "] but was [" + deploymentStatus + "]");
                    return;
                } else {
                    throw new ITException("Expected deployment of app [" + applicationId + "] to be [" + expectedStatus + "] but was [" + deploymentStatus + "]");
                }
            } else {
                if (failover) {
                    log.warn("Expected deployment [" + deploymentId + "] to be [" + expectedStatus + "] but was [" + deploymentStatus + "]");
                    return;
                } else {
                    throw new ITException("Expected deployment [" + deploymentId + "] to be [" + expectedStatus + "] but was [" + deploymentStatus + "]");
                }
            }
        }
    }
}
Also used : ITException(alien4cloud.it.exception.ITException) DeploymentStatus(alien4cloud.paas.model.DeploymentStatus)

Example 2 with ITException

use of alien4cloud.it.exception.ITException in project alien4cloud by alien4cloud.

the class WebSocketClientHandler method messageReceived.

@Override
public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception {
    // The first message must be authentication response
    if (this.authenticationUrl != null && (this.cookies == null || this.cookies.isEmpty())) {
        HttpResponse response = (HttpResponse) msg;
        CharSequence cookieData = response.headers().get(new AsciiString("set-cookie"));
        if (cookieData != null) {
            this.cookies = ServerCookieDecoder.decode(cookieData.toString());
            if (this.cookies == null || this.cookies.isEmpty()) {
                throw new WebSocketAuthenticationFailureException("Could not authenticate");
            }
            if (log.isDebugEnabled()) {
                for (Cookie cookie : this.cookies) {
                    log.debug("Server says must set cookie with name {} and value {}", cookie.name(), cookie.value());
                }
            }
        } else {
            throw new ITException("Could not authenticate");
        }
        if (log.isDebugEnabled()) {
            log.debug("Authentication succeeded for user {}", this.user);
        }
        handShaker.handshake(ctx.channel());
        return;
    }
    // The second one must be the response for web socket handshake
    if (!handShaker.isHandshakeComplete()) {
        handShaker.finishHandshake(ctx.channel(), (FullHttpResponse) msg);
        if (log.isDebugEnabled()) {
            log.debug("Web socket client connected for user {}", this.user);
        }
        handshakeFuture.setSuccess();
        return;
    }
    // Take the byte buff and send it up to Stomp decoder
    if (msg instanceof WebSocketFrame) {
        if (log.isDebugEnabled()) {
            if (msg instanceof TextWebSocketFrame) {
                log.debug("Received text frame {}", ((TextWebSocketFrame) msg).text());
            }
        }
        ReferenceCountUtil.retain(msg);
        ctx.fireChannelRead(((WebSocketFrame) msg).content());
    }
}
Also used : ITException(alien4cloud.it.exception.ITException) AsciiString(io.netty.handler.codec.AsciiString) TextWebSocketFrame(io.netty.handler.codec.http.websocketx.TextWebSocketFrame) WebSocketFrame(io.netty.handler.codec.http.websocketx.WebSocketFrame) TextWebSocketFrame(io.netty.handler.codec.http.websocketx.TextWebSocketFrame)

Aggregations

ITException (alien4cloud.it.exception.ITException)2 DeploymentStatus (alien4cloud.paas.model.DeploymentStatus)1 AsciiString (io.netty.handler.codec.AsciiString)1 TextWebSocketFrame (io.netty.handler.codec.http.websocketx.TextWebSocketFrame)1 WebSocketFrame (io.netty.handler.codec.http.websocketx.WebSocketFrame)1