Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public final class ClientConstants {
public static final String CONTENT_TYPE_TEXT = "text/plain";
public static final String CONTENT_TYPE_TEXT_HTML = "text/html";
public static final String CONTENT_TYPE_IMAGE_V2_PATCH = "application/openstack-images-v2.1-json-patch";

public static final String X_OPENSTACK_REQUEST_ID = "x-openstack-request-id";
public static final String X_COMPUTE_REQUEST_ID = "X-Compute-Request-Id";


// Paths
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ public class BaseOpenStackService {

ServiceType serviceType = ServiceType.IDENTITY;
Function<String, String> endpointFunc;

private static ThreadLocal<String> reqIdContainer = new ThreadLocal<String>();

public String getXOpenstackRequestId() {
return reqIdContainer.get();
}

protected BaseOpenStackService() {
}
Expand Down Expand Up @@ -190,7 +196,19 @@ public R execute() {
public R execute(ExecutionOptions<R> options) {
header(HEADER_USER_AGENT, USER_AGENT);
HttpRequest<R> request = req.build();
return HttpExecutor.create().execute(request).getEntity(request.getReturnType(), options);
HttpResponse res = HttpExecutor.create().execute(request);

reqIdContainer.remove();

String reqId = null;
if(res.headers().containsKey(ClientConstants.X_COMPUTE_REQUEST_ID)) {
reqId = res.header(ClientConstants.X_COMPUTE_REQUEST_ID);
} else {
reqId = res.header(ClientConstants.X_OPENSTACK_REQUEST_ID);
}

reqIdContainer.set(reqId);
return res.getEntity(request.getReturnType(), options);
}

public HttpResponse executeWithResponse() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,18 @@ private static OSClientV3 authenticateV3(KeystoneAuth auth, SessionInfo info, Co
}
}

if (!info.reLinkToExistingSession)
return OSClientSessionV3.createSession(token, info.perspective, info.provider, config);
String reqId = response.header(ClientConstants.X_OPENSTACK_REQUEST_ID);

if (!info.reLinkToExistingSession) {
OSClientSessionV3 v3 = OSClientSessionV3.createSession(token, info.perspective, info.provider, config);
v3.reqId = reqId;
return v3;
}

OSClientSessionV3 current = (OSClientSessionV3) OSClientSessionV3.getCurrent();
current.token = token;

current.reqId = reqId;
return current;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ public Set<ServiceType> getSupportedServices() {
public static class OSClientSessionV3 extends OSClientSession<OSClientSessionV3, OSClientV3> implements OSClientV3 {

Token token;

protected String reqId;

private OSClientSessionV3(Token token, String endpoint, Facing perspective, CloudProvider provider, Config config) {
this.token = token;
Expand All @@ -407,6 +409,10 @@ public static OSClientSessionV3 createSession(Token token) {
public static OSClientSessionV3 createSession(Token token, Facing perspective, CloudProvider provider, Config config) {
return new OSClientSessionV3(token, token.getEndpoint(), perspective, provider, config);
}

public String getXOpenstackRequestId() {
return reqId;
}

@Override
public Token getToken() {
Expand Down