class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin {

    @Override
    public StackInfo queryStack(String cloudSiteId, String cloudOwner, String tenantId, String instanceId)
            throws MsoException {
        if (logger.isDebugEnabled()) {
            logger.debug(String.format("Query multicloud HEAT stack: %s in tenant %s", instanceId, tenantId));
        }
        String stackName = null;
        String stackId = null;
        boolean byName = false;
        int offset = instanceId.indexOf('/');
        if (offset > 0 && offset < (instanceId.length() - 1)) {
            stackName = instanceId.substring(0, offset);
            stackId = instanceId.substring(offset + 1);
        } else {
            stackName = instanceId;
            stackId = instanceId;
            byName = true;
        }

        StackInfo returnInfo = new StackInfo();
        returnInfo.setName(stackName);

        String multicloudEndpoint = getMulticloudEndpoint(cloudSiteId, cloudOwner, stackId, byName);
        RestClient multicloudClient = getMulticloudClient(multicloudEndpoint, tenantId);

        if (multicloudClient != null) {
            Response response = multicloudClient.get();
            if (logger.isDebugEnabled()) {
                logger.debug(String.format("Multicloud GET Response: %s", response.toString()));
            }

            MulticloudQueryResponse responseBody = null;
            if (response.getStatus() == Response.Status.NOT_FOUND.getStatusCode()) {
                returnInfo.setStatus(HeatStatus.NOTFOUND);
                returnInfo.setStatusMessage(response.getStatusInfo().getReasonPhrase());
            } else if (response.getStatus() == Response.Status.OK.getStatusCode() && response.hasEntity()) {
                responseBody = getQueryBody((java.io.InputStream) response.getEntity());
                if (responseBody != null) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Multicloud Create Response Body: {}", responseBody);
                    }
                    Stack workloadStack = getWorkloadStack(responseBody.getWorkloadStatusReason());
                    if (workloadStack != null && !responseBody.getWorkloadStatus().equals("GET_FAILED")
                            && !responseBody.getWorkloadStatus().contains("UPDATE")) {
                        returnInfo = new StackInfoMapper(workloadStack).map();
                    } else {
                        returnInfo.setCanonicalName(stackName + "/" + responseBody.getWorkloadId());
                        returnInfo.setStatus(getHeatStatus(responseBody.getWorkloadStatus()));
                        returnInfo.setStatusMessage(responseBody.getWorkloadStatus());
                    }
                } else {
                    returnInfo.setName(stackName);
                    if (!byName)
                        returnInfo.setCanonicalName(instanceId);
                    returnInfo.setStatus(HeatStatus.FAILED);
                    returnInfo.setStatusMessage(MULTICLOUD_QUERY_BODY_NULL);
                }
            } else {
                returnInfo.setName(stackName);
                if (!byName)
                    returnInfo.setCanonicalName(instanceId);
                returnInfo.setStatus(HeatStatus.FAILED);
                returnInfo.setStatusMessage(response.getStatusInfo().getReasonPhrase());
            }
        }

        return returnInfo;
    }

}